@@ -7,15 +7,18 @@ import (
7
7
"sort"
8
8
"time"
9
9
10
- "github.com/cortexproject/cortex/pkg/chunk/cache"
11
- "github.com/cortexproject/cortex/pkg/util"
12
- "github.com/cortexproject/cortex/pkg/util/validation"
13
10
"github.com/go-kit/kit/log/level"
14
11
"github.com/gogo/protobuf/proto"
15
12
opentracing "github.com/opentracing/opentracing-go"
16
13
otlog "github.com/opentracing/opentracing-go/log"
17
14
"github.com/prometheus/common/model"
15
+ "github.com/uber/jaeger-client-go"
18
16
"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"
19
22
)
20
23
21
24
// ResultsCacheConfig is the config for the results cache.
@@ -97,6 +100,7 @@ func (s resultsCache) handleMiss(ctx context.Context, r *QueryRangeRequest) (*AP
97
100
Start : r .Start ,
98
101
End : r .End ,
99
102
Response : response ,
103
+ TraceId : jaegerTraceID (ctx ),
100
104
},
101
105
}
102
106
return response , extents , nil
@@ -107,6 +111,8 @@ func (s resultsCache) handleHit(ctx context.Context, r *QueryRangeRequest, exten
107
111
reqResps []requestResponse
108
112
err error
109
113
)
114
+ log , ctx := spanlogger .New (ctx , "handleHit" )
115
+ defer log .Finish ()
110
116
111
117
requests , responses := partition (r , extents )
112
118
if len (requests ) == 0 {
@@ -126,6 +132,7 @@ func (s resultsCache) handleHit(ctx context.Context, r *QueryRangeRequest, exten
126
132
Start : reqResp .req .Start ,
127
133
End : reqResp .req .End ,
128
134
Response : reqResp .resp ,
135
+ TraceId : jaegerTraceID (ctx ),
129
136
})
130
137
}
131
138
sort .Slice (extents , func (i , j int ) bool {
@@ -141,6 +148,9 @@ func (s resultsCache) handleHit(ctx context.Context, r *QueryRangeRequest, exten
141
148
continue
142
149
}
143
150
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 )
144
154
accumulator .End = extents [i ].End
145
155
accumulator .Response , err = mergeAPIResponses ([]* APIResponse {accumulator .Response , extents [i ].Response })
146
156
if err != nil {
@@ -238,3 +248,13 @@ func (s resultsCache) put(ctx context.Context, key string, extents []Extent) {
238
248
239
249
s .cache .Store (ctx , []string {cache .HashKey (key )}, [][]byte {buf })
240
250
}
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
+ }
0 commit comments