@@ -96,6 +96,14 @@ func (o Opts) getLogicalOptimizers() []logicalplan.Optimizer {
96
96
return optimizers
97
97
}
98
98
99
+ // QueryOpts implements promql.QueryOpts but allows to override more engine default options.
100
+ type QueryOpts struct {
101
+ promql.QueryOpts
102
+
103
+ // DecodingConcurrency can be used to override the DecodingConcurrency engine setting.
104
+ DecodingConcurrency int
105
+ }
106
+
99
107
// New creates a new query engine with the given options. The query engine will
100
108
// use the storage passed in NewInstantQuery and NewRangeQuery for retrieving
101
109
// data when executing queries.
@@ -239,31 +247,12 @@ func (e *Engine) NewInstantQuery(ctx context.Context, q storage.Queryable, opts
239
247
if err != nil {
240
248
return nil , err
241
249
}
242
-
243
- if opts == nil {
244
- opts = promql .NewPrometheusQueryOpts (false , e .lookbackDelta )
245
- }
246
- if opts .LookbackDelta () <= 0 {
247
- opts = promql .NewPrometheusQueryOpts (opts .EnablePerStepStats (), e .lookbackDelta )
248
- }
249
-
250
250
// determine sorting order before optimizers run, we do this by looking for "sort"
251
251
// and "sort_desc" and optimize them away afterwards since they are only needed at
252
252
// the presentation layer and not when computing the results.
253
253
resultSort := newResultSort (expr )
254
254
255
- qOpts := & query.Options {
256
- Start : ts ,
257
- End : ts ,
258
- Step : 0 ,
259
- StepsBatch : stepsBatch ,
260
- LookbackDelta : opts .LookbackDelta (),
261
- EnablePerStepStats : e .enablePerStepStats && opts .EnablePerStepStats (),
262
- ExtLookbackDelta : e .extLookbackDelta ,
263
- EnableAnalysis : e .enableAnalysis ,
264
- NoStepSubqueryIntervalFn : e .noStepSubqueryIntervalFn ,
265
- DecodingConcurrency : e .decodingConcurrency ,
266
- }
255
+ qOpts := e .makeQueryOpts (ts , ts , 0 , opts )
267
256
if qOpts .StepsBatch > 64 {
268
257
return nil , ErrStepsBatchTooLarge
269
258
}
@@ -308,13 +297,6 @@ func (e *Engine) NewInstantQueryFromPlan(ctx context.Context, q storage.Queryabl
308
297
}
309
298
defer e .activeQueryTracker .Delete (idx )
310
299
311
- if opts == nil {
312
- opts = promql .NewPrometheusQueryOpts (false , e .lookbackDelta )
313
- }
314
- if opts .LookbackDelta () <= 0 {
315
- opts = promql .NewPrometheusQueryOpts (opts .EnablePerStepStats (), e .lookbackDelta )
316
- }
317
-
318
300
qOpts := e .makeQueryOpts (ts , ts , 0 , opts )
319
301
if qOpts .StepsBatch > 64 {
320
302
return nil , ErrStepsBatchTooLarge
@@ -371,12 +353,6 @@ func (e *Engine) NewRangeQuery(ctx context.Context, q storage.Queryable, opts pr
371
353
if expr .Type () != parser .ValueTypeVector && expr .Type () != parser .ValueTypeScalar {
372
354
return nil , errors .Newf ("invalid expression type %q for range query, must be Scalar or instant Vector" , parser .DocumentedType (expr .Type ()))
373
355
}
374
- if opts == nil {
375
- opts = promql .NewPrometheusQueryOpts (false , e .lookbackDelta )
376
- }
377
- if opts .LookbackDelta () <= 0 {
378
- opts = promql .NewPrometheusQueryOpts (opts .EnablePerStepStats (), e .lookbackDelta )
379
- }
380
356
qOpts := e .makeQueryOpts (start , end , step , opts )
381
357
if qOpts .StepsBatch > 64 {
382
358
return nil , ErrStepsBatchTooLarge
@@ -420,12 +396,6 @@ func (e *Engine) NewRangeQueryFromPlan(ctx context.Context, q storage.Queryable,
420
396
}
421
397
defer e .activeQueryTracker .Delete (idx )
422
398
423
- if opts == nil {
424
- opts = promql .NewPrometheusQueryOpts (false , e .lookbackDelta )
425
- }
426
- if opts .LookbackDelta () <= 0 {
427
- opts = promql .NewPrometheusQueryOpts (opts .EnablePerStepStats (), e .lookbackDelta )
428
- }
429
399
qOpts := e .makeQueryOpts (start , end , step , opts )
430
400
if qOpts .StepsBatch > 64 {
431
401
return nil , ErrStepsBatchTooLarge
@@ -462,19 +432,38 @@ func (e *Engine) NewRangeQueryFromPlan(ctx context.Context, q storage.Queryable,
462
432
}
463
433
464
434
func (e * Engine ) makeQueryOpts (start time.Time , end time.Time , step time.Duration , opts promql.QueryOpts ) * query.Options {
465
- qOpts := & query.Options {
435
+ res := & query.Options {
466
436
Start : start ,
467
437
End : end ,
468
438
Step : step ,
469
439
StepsBatch : stepsBatch ,
470
- LookbackDelta : opts . LookbackDelta () ,
471
- EnablePerStepStats : e .enablePerStepStats && opts . EnablePerStepStats () ,
440
+ LookbackDelta : e . lookbackDelta ,
441
+ EnablePerStepStats : e .enablePerStepStats ,
472
442
ExtLookbackDelta : e .extLookbackDelta ,
473
443
EnableAnalysis : e .enableAnalysis ,
474
444
NoStepSubqueryIntervalFn : e .noStepSubqueryIntervalFn ,
475
445
DecodingConcurrency : e .decodingConcurrency ,
476
446
}
477
- return qOpts
447
+ if opts == nil {
448
+ return res
449
+ }
450
+
451
+ if opts .LookbackDelta () > 0 {
452
+ res .LookbackDelta = opts .LookbackDelta ()
453
+ }
454
+ if opts .EnablePerStepStats () {
455
+ res .EnablePerStepStats = opts .EnablePerStepStats ()
456
+ }
457
+
458
+ extOpts , ok := opts .(* QueryOpts )
459
+ if ! ok {
460
+ return res
461
+ }
462
+
463
+ if extOpts .DecodingConcurrency != 0 {
464
+ res .DecodingConcurrency = extOpts .DecodingConcurrency
465
+ }
466
+ return res
478
467
}
479
468
480
469
func (e * Engine ) storageScanners (queryable storage.Queryable , qOpts * query.Options , lplan logicalplan.Plan ) (engstorage.Scanners , error ) {
0 commit comments