@@ -26,14 +26,15 @@ import (
26
26
)
27
27
28
28
type QueryAPI struct {
29
- queryable storage.SampleAndChunkQueryable
30
- queryEngine engine.QueryEngine
31
- queryResultCache * distributed_execution.QueryResultCache
32
- now func () time.Time
33
- statsRenderer v1.StatsRenderer
34
- logger log.Logger
35
- codecs []v1.Codec
36
- CORSOrigin * regexp.Regexp
29
+ queryable storage.SampleAndChunkQueryable
30
+ queryEngine engine.QueryEngine
31
+ queryResultCache * distributed_execution.QueryResultCache
32
+ now func () time.Time
33
+ statsRenderer v1.StatsRenderer
34
+ logger log.Logger
35
+ codecs []v1.Codec
36
+ CORSOrigin * regexp.Regexp
37
+ distributedExecEnabled bool
37
38
}
38
39
39
40
func NewQueryAPI (
@@ -44,16 +45,18 @@ func NewQueryAPI(
44
45
logger log.Logger ,
45
46
codecs []v1.Codec ,
46
47
CORSOrigin * regexp.Regexp ,
48
+ distributedExecEnabled bool ,
47
49
) * QueryAPI {
48
50
return & QueryAPI {
49
- queryEngine : qe ,
50
- queryResultCache : queryResultCache ,
51
- queryable : q ,
52
- statsRenderer : statsRenderer ,
53
- logger : logger ,
54
- codecs : codecs ,
55
- CORSOrigin : CORSOrigin ,
56
- now : time .Now ,
51
+ queryEngine : qe ,
52
+ queryResultCache : queryResultCache ,
53
+ queryable : q ,
54
+ statsRenderer : statsRenderer ,
55
+ logger : logger ,
56
+ codecs : codecs ,
57
+ CORSOrigin : CORSOrigin ,
58
+ now : time .Now ,
59
+ distributedExecEnabled : distributedExecEnabled ,
57
60
}
58
61
}
59
62
@@ -139,11 +142,12 @@ func (q *QueryAPI) RangeQueryHandler(r *http.Request) (result apiFuncResult) {
139
142
140
143
ctx = httputil .ContextFromRequest (ctx , r )
141
144
142
- // TODO: if distributed exec enabled
143
- isRoot , queryID , fragmentID , _ , _ := distributed_execution .ExtractFragmentMetaData (ctx )
144
- if ! isRoot {
145
- key := distributed_execution .MakeFragmentKey (queryID , fragmentID )
146
- q .queryResultCache .InitWriting (* key )
145
+ if q .distributedExecEnabled {
146
+ isRoot , queryID , fragmentID , _ , _ := distributed_execution .ExtractFragmentMetaData (ctx )
147
+ if ! isRoot {
148
+ key := distributed_execution .MakeFragmentKey (queryID , fragmentID )
149
+ q .queryResultCache .InitWriting (* key )
150
+ }
147
151
}
148
152
149
153
res := qry .Exec (ctx )
@@ -188,11 +192,14 @@ func (q *QueryAPI) InstantQueryHandler(r *http.Request) (result apiFuncResult) {
188
192
ctx = engine .AddEngineTypeToContext (ctx , r )
189
193
ctx = querier .AddBlockStoreTypeToContext (ctx , r .Header .Get (querier .BlockStoreTypeHeader ))
190
194
191
- // TODO: if distributed exec enabled
192
- isRoot , queryID , fragmentID , _ , _ := distributed_execution .ExtractFragmentMetaData (ctx )
193
- if ! isRoot {
194
- key := distributed_execution .MakeFragmentKey (queryID , fragmentID )
195
- q .queryResultCache .InitWriting (* key )
195
+ var isRoot bool
196
+ var queryID , fragmentID uint64
197
+ if q .distributedExecEnabled {
198
+ isRoot , queryID , fragmentID , _ , _ = distributed_execution .ExtractFragmentMetaData (ctx )
199
+ if ! isRoot {
200
+ key := distributed_execution .MakeFragmentKey (queryID , fragmentID )
201
+ q .queryResultCache .InitWriting (* key )
202
+ }
196
203
}
197
204
198
205
var qry promql.Query
@@ -202,9 +209,11 @@ func (q *QueryAPI) InstantQueryHandler(r *http.Request) (result apiFuncResult) {
202
209
if len (byteLP ) != 0 {
203
210
logicalPlan , err := distributed_execution .Unmarshal (byteLP )
204
211
if err != nil {
205
- if ! isRoot {
206
- key := distributed_execution .MakeFragmentKey (queryID , fragmentID )
207
- q .queryResultCache .SetError (* key )
212
+ if q .distributedExecEnabled {
213
+ if ! isRoot {
214
+ key := distributed_execution .MakeFragmentKey (queryID , fragmentID )
215
+ q .queryResultCache .SetError (* key )
216
+ }
208
217
}
209
218
return apiFuncResult {nil , & apiError {errorInternal , fmt .Errorf ("invalid logical plan: %v" , err )}, nil , nil }
210
219
}
@@ -264,17 +273,18 @@ func (q *QueryAPI) Wrap(f apiFunc) http.HandlerFunc {
264
273
}
265
274
266
275
if result .data != nil {
267
- // TODO: if distributed exec enabled
268
276
ctx := httputil .ContextFromRequest (r .Context (), r )
269
- isRoot , queryID , fragmentID , _ , _ := distributed_execution .ExtractFragmentMetaData (ctx )
270
- if ! isRoot {
271
- key := distributed_execution .MakeFragmentKey (queryID , fragmentID )
272
- result := distributed_execution.FragmentResult {
273
- Data : result .data ,
274
- Expiration : time .Now ().Add (time .Hour ),
277
+ if q .distributedExecEnabled {
278
+ isRoot , queryID , fragmentID , _ , _ := distributed_execution .ExtractFragmentMetaData (ctx )
279
+ if ! isRoot {
280
+ key := distributed_execution .MakeFragmentKey (queryID , fragmentID )
281
+ result := distributed_execution.FragmentResult {
282
+ Data : result .data ,
283
+ Expiration : time .Now ().Add (time .Hour ),
284
+ }
285
+ q .queryResultCache .SetComplete (* key , result )
286
+ return
275
287
}
276
- q .queryResultCache .SetComplete (* key , result )
277
- return
278
288
}
279
289
q .respond (w , r , result .data , result .warnings , r .FormValue ("query" ))
280
290
return
0 commit comments