@@ -273,7 +273,7 @@ func TestDistributedAggregations(t *testing.T) {
273
273
completeSeriesSet := storageWithSeries (mergeWithSampleDedup (allSeries )... )
274
274
t .Run (test .name , func (t * testing.T ) {
275
275
for _ , lookbackDelta := range lookbackDeltas {
276
- localOpts := engine.Opts {
276
+ opts := engine.Opts {
277
277
EngineOpts : promql.EngineOpts {
278
278
Timeout : 1 * time .Hour ,
279
279
MaxSamples : 1e10 ,
@@ -285,7 +285,7 @@ func TestDistributedAggregations(t *testing.T) {
285
285
286
286
for _ , s := range test .seriesSets {
287
287
remoteEngines = append (remoteEngines , engine .NewRemoteEngine (
288
- localOpts ,
288
+ opts ,
289
289
storageWithMockSeries (s .series ... ),
290
290
s .mint (),
291
291
s .maxt (),
@@ -294,25 +294,24 @@ func TestDistributedAggregations(t *testing.T) {
294
294
}
295
295
if len (test .timeOverlap .series ) > 0 {
296
296
remoteEngines = append (remoteEngines , engine .NewRemoteEngine (
297
- localOpts ,
297
+ opts ,
298
298
storageWithMockSeries (test .timeOverlap .series ... ),
299
299
test .timeOverlap .mint (),
300
300
test .timeOverlap .maxt (),
301
301
test .timeOverlap .extLset ,
302
302
))
303
303
}
304
-
304
+ endpoints := api . NewStaticEndpoints ( remoteEngines )
305
305
for _ , queryOpts := range allQueryOpts {
306
306
ctx := context .Background ()
307
- distOpts := localOpts
308
307
for _ , instantTS := range instantTSs {
309
308
t .Run (fmt .Sprintf ("instant/ts=%d" , instantTS .Unix ()), func (t * testing.T ) {
310
- distEngine := engine .NewDistributedEngine (distOpts , api . NewStaticEndpoints ( remoteEngines ) )
311
- distQry , err := distEngine .NewInstantQuery (ctx , completeSeriesSet , queryOpts , query .query , instantTS )
309
+ distEngine := engine .NewDistributedEngine (opts )
310
+ distQry , err := distEngine .MakeInstantQuery (ctx , completeSeriesSet , endpoints , queryOpts , query .query , instantTS )
312
311
testutil .Ok (t , err )
313
312
314
313
distResult := distQry .Exec (ctx )
315
- promEngine := promql .NewEngine (localOpts .EngineOpts )
314
+ promEngine := promql .NewEngine (opts .EngineOpts )
316
315
promQry , err := promEngine .NewInstantQuery (ctx , completeSeriesSet , queryOpts , query .query , instantTS )
317
316
testutil .Ok (t , err )
318
317
promResult := promQry .Exec (ctx )
@@ -328,12 +327,12 @@ func TestDistributedAggregations(t *testing.T) {
328
327
if test .rangeEnd == (time.Time {}) {
329
328
test .rangeEnd = rangeEnd
330
329
}
331
- distEngine := engine .NewDistributedEngine (distOpts , api . NewStaticEndpoints ( remoteEngines ) )
332
- distQry , err := distEngine .NewRangeQuery (ctx , completeSeriesSet , queryOpts , query .query , query .rangeStart , test .rangeEnd , rangeStep )
330
+ distEngine := engine .NewDistributedEngine (opts )
331
+ distQry , err := distEngine .MakeRangeQuery (ctx , completeSeriesSet , endpoints , queryOpts , query .query , query .rangeStart , test .rangeEnd , rangeStep )
333
332
testutil .Ok (t , err )
334
333
335
334
distResult := distQry .Exec (ctx )
336
- promEngine := promql .NewEngine (localOpts .EngineOpts )
335
+ promEngine := promql .NewEngine (opts .EngineOpts )
337
336
promQry , err := promEngine .NewRangeQuery (ctx , completeSeriesSet , queryOpts , query .query , query .rangeStart , test .rangeEnd , rangeStep )
338
337
testutil .Ok (t , err )
339
338
promResult := promQry .Exec (ctx )
@@ -350,73 +349,27 @@ func TestDistributedAggregations(t *testing.T) {
350
349
351
350
func TestDistributedEngineWarnings (t * testing.T ) {
352
351
t .Parallel ()
353
- querier := & storage.MockQueryable {
354
- MockQuerier : & storage.MockQuerier {
355
- SelectMockFunction : func (sortSeries bool , hints * storage.SelectHints , matchers ... * labels.Matcher ) storage.SeriesSet {
356
- return newWarningsSeriesSet (annotations .New ().Add (errors .New ("test warning" )))
357
- },
358
- },
359
- }
360
352
361
353
opts := engine.Opts {
362
354
EngineOpts : promql.EngineOpts {
363
355
MaxSamples : math .MaxInt64 ,
364
356
Timeout : 1 * time .Minute ,
365
357
},
366
358
}
367
- remote := engine .NewRemoteEngine (opts , querier , math .MinInt64 , math .MaxInt64 , nil )
368
- ng := engine .NewDistributedEngine (opts , api .NewStaticEndpoints ([]api.RemoteEngine {remote }))
369
- var (
370
- start = time .UnixMilli (0 )
371
- end = time .UnixMilli (600 )
372
- step = 30 * time .Second
373
- )
374
- q , err := ng .NewRangeQuery (context .Background (), querier , nil , "test" , start , end , step )
375
- testutil .Ok (t , err )
376
359
377
- res := q .Exec (context .Background ())
378
- testutil .Equals (t , 1 , len (res .Warnings ))
379
- }
380
-
381
- func TestDistributedEnginePartialResponses (t * testing.T ) {
382
- t .Parallel ()
383
-
384
- querierErr := & storage.MockQueryable {
360
+ querier := & storage.MockQueryable {
385
361
MockQuerier : & storage.MockQuerier {
386
362
SelectMockFunction : func (sortSeries bool , hints * storage.SelectHints , matchers ... * labels.Matcher ) storage.SeriesSet {
387
- return newErrorSeriesSet ( errors .New ("test error" ))
363
+ return newWarningsSeriesSet ( annotations . New (). Add ( errors .New ("test warning" ) ))
388
364
},
389
365
},
390
366
}
391
- querierOk := storageWithMockSeries (newMockSeries ([]string {labels .MetricName , "foo" , "zone" , "west" }, []int64 {0 , 30 , 60 , 90 }, []float64 {0 , 3 , 4 , 5 }))
392
- querierNoop := & storage.MockQueryable {MockQuerier : storage .NoopQuerier ()}
393
-
394
- opts := engine.Opts {
395
- EnablePartialResponses : true ,
396
- EngineOpts : promql.EngineOpts {
397
- MaxSamples : math .MaxInt64 ,
398
- Timeout : 1 * time .Minute ,
399
- },
400
- }
401
-
402
- remoteErr := engine .NewRemoteEngine (opts , querierErr , math .MinInt64 , math .MaxInt64 , []labels.Labels {labels .FromStrings ("zone" , "east" )})
403
- remoteOk := engine .NewRemoteEngine (opts , querierOk , math .MinInt64 , math .MaxInt64 , []labels.Labels {labels .FromStrings ("zone" , "west" )})
404
- ng := engine .NewDistributedEngine (opts , api .NewStaticEndpoints ([]api.RemoteEngine {remoteErr , remoteOk }))
405
- var (
406
- start = time .UnixMilli (0 )
407
- end = time .UnixMilli (600 * 1000 )
408
- step = 30 * time .Second
409
- )
410
- q , err := ng .NewRangeQuery (context .Background (), querierNoop , nil , "sum by (zone) (foo)" , start , end , step )
367
+ remote := engine .NewRemoteEngine (opts , querier , math .MinInt64 , math .MaxInt64 , nil )
368
+ endpoints := api .NewStaticEndpoints ([]api.RemoteEngine {remote })
369
+ ng := engine .NewDistributedEngine (opts )
370
+ q , err := ng .MakeInstantQuery (context .Background (), querier , endpoints , nil , "test" , time .UnixMilli (0 ))
411
371
testutil .Ok (t , err )
412
372
413
373
res := q .Exec (context .Background ())
414
- testutil .Ok (t , res .Err )
415
374
testutil .Equals (t , 1 , len (res .Warnings ))
416
- testutil .Equals (t , `remote exec error [[{zone="east"}]]: test error` , res .Warnings .AsErrors ()[0 ].Error ())
417
-
418
- m , err := res .Matrix ()
419
- testutil .Ok (t , err )
420
- testutil .Equals (t , 1 , m .Len ())
421
- testutil .Equals (t , labels .FromStrings ("zone" , "west" ), m [0 ].Metric )
422
375
}
0 commit comments