Skip to content

Commit 606a535

Browse files
authored
Add trace IDs to cached extents to help track down query gaps. (#1541)
Signed-off-by: Tom Wilkie <[email protected]>
1 parent 1ca4ad0 commit 606a535

File tree

4 files changed

+140
-63
lines changed

4 files changed

+140
-63
lines changed

pkg/querier/frontend/frontend.pb.go

Lines changed: 110 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/querier/frontend/frontend.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,5 @@ message Extent {
6363
int64 start = 1 [(gogoproto.jsontag) = "start"];
6464
int64 end = 2 [(gogoproto.jsontag) = "end"];
6565
APIResponse response = 3 [(gogoproto.jsontag) = "response"];
66+
string trace_id = 4 [(gogoproto.jsontag) = "-"];
6667
}

pkg/querier/frontend/results_cache.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ import (
77
"sort"
88
"time"
99

10-
"github.com/cortexproject/cortex/pkg/chunk/cache"
11-
"github.com/cortexproject/cortex/pkg/util"
12-
"github.com/cortexproject/cortex/pkg/util/validation"
1310
"github.com/go-kit/kit/log/level"
1411
"github.com/gogo/protobuf/proto"
1512
opentracing "github.com/opentracing/opentracing-go"
1613
otlog "github.com/opentracing/opentracing-go/log"
1714
"github.com/prometheus/common/model"
15+
"github.com/uber/jaeger-client-go"
1816
"github.com/weaveworks/common/user"
17+
18+
"github.com/cortexproject/cortex/pkg/chunk/cache"
19+
"github.com/cortexproject/cortex/pkg/util"
20+
"github.com/cortexproject/cortex/pkg/util/spanlogger"
21+
"github.com/cortexproject/cortex/pkg/util/validation"
1922
)
2023

2124
// ResultsCacheConfig is the config for the results cache.
@@ -97,6 +100,7 @@ func (s resultsCache) handleMiss(ctx context.Context, r *QueryRangeRequest) (*AP
97100
Start: r.Start,
98101
End: r.End,
99102
Response: response,
103+
TraceId: jaegerTraceID(ctx),
100104
},
101105
}
102106
return response, extents, nil
@@ -107,6 +111,8 @@ func (s resultsCache) handleHit(ctx context.Context, r *QueryRangeRequest, exten
107111
reqResps []requestResponse
108112
err error
109113
)
114+
log, ctx := spanlogger.New(ctx, "handleHit")
115+
defer log.Finish()
110116

111117
requests, responses := partition(r, extents)
112118
if len(requests) == 0 {
@@ -126,6 +132,7 @@ func (s resultsCache) handleHit(ctx context.Context, r *QueryRangeRequest, exten
126132
Start: reqResp.req.Start,
127133
End: reqResp.req.End,
128134
Response: reqResp.resp,
135+
TraceId: jaegerTraceID(ctx),
129136
})
130137
}
131138
sort.Slice(extents, func(i, j int) bool {
@@ -141,6 +148,9 @@ func (s resultsCache) handleHit(ctx context.Context, r *QueryRangeRequest, exten
141148
continue
142149
}
143150

151+
log.Log("msg", "merging extent", "start", accumulator.Start, "old_end", accumulator.End, "new_end", extents[i].End, "from_trace", accumulator.TraceId, "with_trace", accumulator.TraceId)
152+
153+
accumulator.TraceId = jaegerTraceID(ctx)
144154
accumulator.End = extents[i].End
145155
accumulator.Response, err = mergeAPIResponses([]*APIResponse{accumulator.Response, extents[i].Response})
146156
if err != nil {
@@ -238,3 +248,13 @@ func (s resultsCache) put(ctx context.Context, key string, extents []Extent) {
238248

239249
s.cache.Store(ctx, []string{cache.HashKey(key)}, [][]byte{buf})
240250
}
251+
252+
func jaegerTraceID(ctx context.Context) string {
253+
span := opentracing.SpanFromContext(ctx)
254+
if span == nil {
255+
return ""
256+
}
257+
258+
spanContext := span.Context().(jaeger.SpanContext)
259+
return spanContext.TraceID().String()
260+
}

vendor/modules.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,8 @@ github.com/tinylib/msgp/msgp
386386
# github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5
387387
github.com/tmc/grpc-websocket-proxy/wsproxy
388388
# github.com/uber/jaeger-client-go v2.16.0+incompatible
389-
github.com/uber/jaeger-client-go/config
390389
github.com/uber/jaeger-client-go
391-
github.com/uber/jaeger-client-go/internal/baggage/remote
392-
github.com/uber/jaeger-client-go/internal/throttler/remote
393-
github.com/uber/jaeger-client-go/rpcmetrics
394-
github.com/uber/jaeger-client-go/transport
390+
github.com/uber/jaeger-client-go/config
395391
github.com/uber/jaeger-client-go/internal/baggage
396392
github.com/uber/jaeger-client-go/internal/spanlog
397393
github.com/uber/jaeger-client-go/internal/throttler
@@ -401,8 +397,12 @@ github.com/uber/jaeger-client-go/thrift-gen/jaeger
401397
github.com/uber/jaeger-client-go/thrift-gen/sampling
402398
github.com/uber/jaeger-client-go/thrift-gen/zipkincore
403399
github.com/uber/jaeger-client-go/utils
404-
github.com/uber/jaeger-client-go/thrift-gen/baggage
400+
github.com/uber/jaeger-client-go/internal/baggage/remote
401+
github.com/uber/jaeger-client-go/internal/throttler/remote
402+
github.com/uber/jaeger-client-go/rpcmetrics
403+
github.com/uber/jaeger-client-go/transport
405404
github.com/uber/jaeger-client-go/thrift-gen/agent
405+
github.com/uber/jaeger-client-go/thrift-gen/baggage
406406
# github.com/uber/jaeger-lib v2.0.0+incompatible
407407
github.com/uber/jaeger-lib/metrics/prometheus
408408
github.com/uber/jaeger-lib/metrics

0 commit comments

Comments
 (0)