@@ -26,13 +26,14 @@ import (
26
26
)
27
27
28
28
type QueryAPI struct {
29
- queryable storage.SampleAndChunkQueryable
30
- queryEngine engine.BaseEngine
31
- now func () time.Time
32
- statsRenderer v1.StatsRenderer
33
- logger log.Logger
34
- codecs []v1.Codec
35
- CORSOrigin * regexp.Regexp
29
+ queryable storage.SampleAndChunkQueryable
30
+ queryEngine engine.BaseEngine
31
+ now func () time.Time
32
+ statsRenderer v1.StatsRenderer
33
+ logger log.Logger
34
+ codecs []v1.Codec
35
+ CORSOrigin * regexp.Regexp
36
+ distributedExecEnabled bool
36
37
}
37
38
38
39
func NewQueryAPI (
@@ -42,15 +43,17 @@ func NewQueryAPI(
42
43
logger log.Logger ,
43
44
codecs []v1.Codec ,
44
45
CORSOrigin * regexp.Regexp ,
46
+ distributedExecEnabled bool ,
45
47
) * QueryAPI {
46
48
return & QueryAPI {
47
- queryEngine : qe ,
48
- queryable : q ,
49
- statsRenderer : statsRenderer ,
50
- logger : logger ,
51
- codecs : codecs ,
52
- CORSOrigin : CORSOrigin ,
53
- now : time .Now ,
49
+ queryEngine : qe ,
50
+ queryable : q ,
51
+ statsRenderer : statsRenderer ,
52
+ logger : logger ,
53
+ codecs : codecs ,
54
+ CORSOrigin : CORSOrigin ,
55
+ now : time .Now ,
56
+ distributedExecEnabled : distributedExecEnabled ,
54
57
}
55
58
}
56
59
@@ -104,19 +107,27 @@ func (q *QueryAPI) RangeQueryHandler(r *http.Request) (result apiFuncResult) {
104
107
ctx = querier .AddBlockStoreTypeToContext (ctx , r .Header .Get (querier .BlockStoreTypeHeader ))
105
108
106
109
var qry promql.Query
107
- byteLP , err := io .ReadAll (r .Body )
108
- if err != nil {
109
- return apiFuncResult {nil , & apiError {errorBadData , err }, nil , nil }
110
- }
111
110
112
- if len ( byteLP ) != 0 {
113
- logicalPlan , err := logicalplan . Unmarshal ( byteLP )
111
+ if q . distributedExecEnabled {
112
+ byteLP , err := io . ReadAll ( r . Body )
114
113
if err != nil {
115
114
return apiFuncResult {nil , & apiError {errorBadData , err }, nil , nil }
116
115
}
117
- qry , err = q .queryEngine .MakeRangeQueryFromPlan (ctx , q .queryable , opts , logicalPlan , convertMsToTime (start ), convertMsToTime (end ), convertMsToDuration (step ), r .FormValue ("query" ))
118
- if err != nil {
119
- return invalidParamError (httpgrpc .Errorf (http .StatusBadRequest , "%s" , err .Error ()), "query" )
116
+
117
+ if len (byteLP ) != 0 {
118
+ logicalPlan , err := logicalplan .Unmarshal (byteLP )
119
+ if err != nil {
120
+ return apiFuncResult {nil , & apiError {errorBadData , err }, nil , nil }
121
+ }
122
+ qry , err = q .queryEngine .MakeRangeQueryFromPlan (ctx , q .queryable , opts , logicalPlan , convertMsToTime (start ), convertMsToTime (end ), convertMsToDuration (step ), r .FormValue ("query" ))
123
+ if err != nil {
124
+ return invalidParamError (httpgrpc .Errorf (http .StatusBadRequest , "%s" , err .Error ()), "query" )
125
+ }
126
+ } else {
127
+ qry , err = q .queryEngine .NewRangeQuery (ctx , q .queryable , opts , r .FormValue ("query" ), convertMsToTime (start ), convertMsToTime (end ), convertMsToDuration (step ))
128
+ if err != nil {
129
+ return invalidParamError (httpgrpc .Errorf (http .StatusBadRequest , "%s" , err .Error ()), "query" )
130
+ }
120
131
}
121
132
} else {
122
133
qry , err = q .queryEngine .NewRangeQuery (ctx , q .queryable , opts , r .FormValue ("query" ), convertMsToTime (start ), convertMsToTime (end ), convertMsToDuration (step ))
@@ -179,19 +190,26 @@ func (q *QueryAPI) InstantQueryHandler(r *http.Request) (result apiFuncResult) {
179
190
ctx = querier .AddBlockStoreTypeToContext (ctx , r .Header .Get (querier .BlockStoreTypeHeader ))
180
191
181
192
var qry promql.Query
182
- byteLP , err := io .ReadAll (r .Body )
183
- if err != nil {
184
- return apiFuncResult {nil , & apiError {errorBadData , err }, nil , nil }
185
- }
186
-
187
- if len (byteLP ) != 0 {
188
- logicalPlan , err := logicalplan .Unmarshal (byteLP )
193
+ if q .distributedExecEnabled {
194
+ byteLP , err := io .ReadAll (r .Body )
189
195
if err != nil {
190
196
return apiFuncResult {nil , & apiError {errorBadData , err }, nil , nil }
191
197
}
192
- qry , err = q .queryEngine .MakeInstantQueryFromPlan (ctx , q .queryable , opts , logicalPlan , convertMsToTime (ts ), r .FormValue ("query" ))
193
- if err != nil {
194
- return invalidParamError (httpgrpc .Errorf (http .StatusBadRequest , "%s" , err .Error ()), "query" )
198
+
199
+ if len (byteLP ) != 0 {
200
+ logicalPlan , err := logicalplan .Unmarshal (byteLP )
201
+ if err != nil {
202
+ return apiFuncResult {nil , & apiError {errorBadData , err }, nil , nil }
203
+ }
204
+ qry , err = q .queryEngine .MakeInstantQueryFromPlan (ctx , q .queryable , opts , logicalPlan , convertMsToTime (ts ), r .FormValue ("query" ))
205
+ if err != nil {
206
+ return invalidParamError (httpgrpc .Errorf (http .StatusBadRequest , "%s" , err .Error ()), "query" )
207
+ }
208
+ } else {
209
+ qry , err = q .queryEngine .NewInstantQuery (ctx , q .queryable , opts , r .FormValue ("query" ), convertMsToTime (ts ))
210
+ if err != nil {
211
+ return invalidParamError (httpgrpc .Errorf (http .StatusBadRequest , "%s" , err .Error ()), "query" )
212
+ }
195
213
}
196
214
} else {
197
215
qry , err = q .queryEngine .NewInstantQuery (ctx , q .queryable , opts , r .FormValue ("query" ), convertMsToTime (ts ))
0 commit comments