@@ -345,7 +345,11 @@ func (q *blocksStoreQuerier) LabelNames(ctx context.Context, hints *storage.Labe
345
345
spanLog , spanCtx := spanlogger .New (ctx , "blocksStoreQuerier.LabelNames" )
346
346
defer spanLog .Span .Finish ()
347
347
348
- minT , maxT := q .minT , q .maxT
348
+ minT , maxT , limit := q .minT , q .maxT , int64 (0 )
349
+
350
+ if hints != nil {
351
+ limit = int64 (hints .Limit )
352
+ }
349
353
350
354
var (
351
355
resMtx sync.Mutex
@@ -355,7 +359,7 @@ func (q *blocksStoreQuerier) LabelNames(ctx context.Context, hints *storage.Labe
355
359
)
356
360
357
361
queryFunc := func (clients map [BlocksStoreClient ][]ulid.ULID , minT , maxT int64 ) ([]ulid.ULID , error , error ) {
358
- nameSets , warnings , queriedBlocks , err , retryableError := q .fetchLabelNamesFromStore (spanCtx , userID , clients , minT , maxT , convertedMatchers )
362
+ nameSets , warnings , queriedBlocks , err , retryableError := q .fetchLabelNamesFromStore (spanCtx , userID , clients , minT , maxT , limit , convertedMatchers )
359
363
if err != nil {
360
364
return nil , err , retryableError
361
365
}
@@ -372,6 +376,7 @@ func (q *blocksStoreQuerier) LabelNames(ctx context.Context, hints *storage.Labe
372
376
return nil , nil , err
373
377
}
374
378
379
+ // TODO(johrry): pass limit when merging.
375
380
return strutil .MergeSlices (resNameSets ... ), resWarnings , nil
376
381
}
377
382
@@ -384,7 +389,11 @@ func (q *blocksStoreQuerier) LabelValues(ctx context.Context, name string, hints
384
389
spanLog , spanCtx := spanlogger .New (ctx , "blocksStoreQuerier.LabelValues" )
385
390
defer spanLog .Span .Finish ()
386
391
387
- minT , maxT := q .minT , q .maxT
392
+ minT , maxT , limit := q .minT , q .maxT , int64 (0 )
393
+
394
+ if hints != nil {
395
+ limit = int64 (hints .Limit )
396
+ }
388
397
389
398
var (
390
399
resValueSets = [][]string {}
@@ -394,7 +403,7 @@ func (q *blocksStoreQuerier) LabelValues(ctx context.Context, name string, hints
394
403
)
395
404
396
405
queryFunc := func (clients map [BlocksStoreClient ][]ulid.ULID , minT , maxT int64 ) ([]ulid.ULID , error , error ) {
397
- valueSets , warnings , queriedBlocks , err , retryableError := q .fetchLabelValuesFromStore (spanCtx , userID , name , clients , minT , maxT , matchers ... )
406
+ valueSets , warnings , queriedBlocks , err , retryableError := q .fetchLabelValuesFromStore (spanCtx , userID , name , clients , minT , maxT , limit , matchers ... )
398
407
if err != nil {
399
408
return nil , err , retryableError
400
409
}
@@ -411,6 +420,7 @@ func (q *blocksStoreQuerier) LabelValues(ctx context.Context, name string, hints
411
420
return nil , nil , err
412
421
}
413
422
423
+ // TODO(johrry): pass limit when merging.
414
424
return strutil .MergeSlices (resValueSets ... ), resWarnings , nil
415
425
}
416
426
@@ -427,9 +437,9 @@ func (q *blocksStoreQuerier) selectSorted(ctx context.Context, sp *storage.Selec
427
437
spanLog , spanCtx := spanlogger .New (ctx , "blocksStoreQuerier.selectSorted" )
428
438
defer spanLog .Span .Finish ()
429
439
430
- minT , maxT := q .minT , q .maxT
440
+ minT , maxT , limit := q .minT , q .maxT , int64 ( 0 )
431
441
if sp != nil {
432
- minT , maxT = sp .Start , sp .End
442
+ minT , maxT , limit = sp .Start , sp .End , int64 ( sp . Limit )
433
443
}
434
444
435
445
var (
@@ -443,7 +453,7 @@ func (q *blocksStoreQuerier) selectSorted(ctx context.Context, sp *storage.Selec
443
453
)
444
454
445
455
queryFunc := func (clients map [BlocksStoreClient ][]ulid.ULID , minT , maxT int64 ) ([]ulid.ULID , error , error ) {
446
- seriesSets , queriedBlocks , warnings , numChunks , err , retryableError := q .fetchSeriesFromStores (spanCtx , sp , userID , clients , minT , maxT , matchers , maxChunksLimit , leftChunksLimit )
456
+ seriesSets , queriedBlocks , warnings , numChunks , err , retryableError := q .fetchSeriesFromStores (spanCtx , sp , userID , clients , minT , maxT , limit , matchers , maxChunksLimit , leftChunksLimit )
447
457
if err != nil {
448
458
return nil , err , retryableError
449
459
}
@@ -471,6 +481,7 @@ func (q *blocksStoreQuerier) selectSorted(ctx context.Context, sp *storage.Selec
471
481
storage .EmptySeriesSet ()
472
482
}
473
483
484
+ // TODO(johrry): pass limit when merging.
474
485
return series .NewSeriesSetWithWarnings (
475
486
storage .NewMergeSeriesSet (resSeriesSets , storage .ChainedSeriesMerge ),
476
487
resWarnings )
@@ -593,6 +604,7 @@ func (q *blocksStoreQuerier) fetchSeriesFromStores(
593
604
clients map [BlocksStoreClient ][]ulid.ULID ,
594
605
minT int64 ,
595
606
maxT int64 ,
607
+ limit int64 ,
596
608
matchers []* labels.Matcher ,
597
609
maxChunksLimit int ,
598
610
leftChunksLimit int ,
@@ -635,7 +647,7 @@ func (q *blocksStoreQuerier) fetchSeriesFromStores(
635
647
seriesQueryStats := & hintspb.QueryStats {}
636
648
skipChunks := sp != nil && sp .Func == "series"
637
649
638
- req , err := createSeriesRequest (minT , maxT , convertedMatchers , shardingInfo , skipChunks , blockIDs , defaultAggrs )
650
+ req , err := createSeriesRequest (minT , maxT , limit , convertedMatchers , shardingInfo , skipChunks , blockIDs , defaultAggrs )
639
651
if err != nil {
640
652
return errors .Wrapf (err , "failed to create series request" )
641
653
}
@@ -825,6 +837,7 @@ func (q *blocksStoreQuerier) fetchLabelNamesFromStore(
825
837
clients map [BlocksStoreClient ][]ulid.ULID ,
826
838
minT int64 ,
827
839
maxT int64 ,
840
+ limit int64 ,
828
841
matchers []storepb.LabelMatcher ,
829
842
) ([][]string , annotations.Annotations , []ulid.ULID , error , error ) {
830
843
var (
@@ -846,7 +859,7 @@ func (q *blocksStoreQuerier) fetchLabelNamesFromStore(
846
859
blockIDs := blockIDs
847
860
848
861
g .Go (func () error {
849
- req , err := createLabelNamesRequest (minT , maxT , blockIDs , matchers )
862
+ req , err := createLabelNamesRequest (minT , maxT , limit , blockIDs , matchers )
850
863
if err != nil {
851
864
return errors .Wrapf (err , "failed to create label names request" )
852
865
}
@@ -927,6 +940,7 @@ func (q *blocksStoreQuerier) fetchLabelValuesFromStore(
927
940
clients map [BlocksStoreClient ][]ulid.ULID ,
928
941
minT int64 ,
929
942
maxT int64 ,
943
+ limit int64 ,
930
944
matchers ... * labels.Matcher ,
931
945
) ([][]string , annotations.Annotations , []ulid.ULID , error , error ) {
932
946
var (
@@ -948,7 +962,7 @@ func (q *blocksStoreQuerier) fetchLabelValuesFromStore(
948
962
blockIDs := blockIDs
949
963
950
964
g .Go (func () error {
951
- req , err := createLabelValuesRequest (minT , maxT , name , blockIDs , matchers ... )
965
+ req , err := createLabelValuesRequest (minT , maxT , limit , name , blockIDs , matchers ... )
952
966
if err != nil {
953
967
return errors .Wrapf (err , "failed to create label values request" )
954
968
}
@@ -1025,7 +1039,7 @@ func (q *blocksStoreQuerier) fetchLabelValuesFromStore(
1025
1039
return valueSets , warnings , queriedBlocks , nil , merr .Err ()
1026
1040
}
1027
1041
1028
- func createSeriesRequest (minT , maxT int64 , matchers []storepb.LabelMatcher , shardingInfo * storepb.ShardInfo , skipChunks bool , blockIDs []ulid.ULID , aggrs []storepb.Aggr ) (* storepb.SeriesRequest , error ) {
1042
+ func createSeriesRequest (minT , maxT , limit int64 , matchers []storepb.LabelMatcher , shardingInfo * storepb.ShardInfo , skipChunks bool , blockIDs []ulid.ULID , aggrs []storepb.Aggr ) (* storepb.SeriesRequest , error ) {
1029
1043
// Selectively query only specific blocks.
1030
1044
hints := & hintspb.SeriesRequestHints {
1031
1045
BlockMatchers : []storepb.LabelMatcher {
@@ -1046,6 +1060,7 @@ func createSeriesRequest(minT, maxT int64, matchers []storepb.LabelMatcher, shar
1046
1060
return & storepb.SeriesRequest {
1047
1061
MinTime : minT ,
1048
1062
MaxTime : maxT ,
1063
+ Limit : limit ,
1049
1064
Matchers : matchers ,
1050
1065
PartialResponseStrategy : storepb .PartialResponseStrategy_ABORT ,
1051
1066
Hints : anyHints ,
@@ -1057,10 +1072,11 @@ func createSeriesRequest(minT, maxT int64, matchers []storepb.LabelMatcher, shar
1057
1072
}, nil
1058
1073
}
1059
1074
1060
- func createLabelNamesRequest (minT , maxT int64 , blockIDs []ulid.ULID , matchers []storepb.LabelMatcher ) (* storepb.LabelNamesRequest , error ) {
1075
+ func createLabelNamesRequest (minT , maxT , limit int64 , blockIDs []ulid.ULID , matchers []storepb.LabelMatcher ) (* storepb.LabelNamesRequest , error ) {
1061
1076
req := & storepb.LabelNamesRequest {
1062
1077
Start : minT ,
1063
1078
End : maxT ,
1079
+ Limit : limit ,
1064
1080
Matchers : matchers ,
1065
1081
}
1066
1082
@@ -1085,10 +1101,11 @@ func createLabelNamesRequest(minT, maxT int64, blockIDs []ulid.ULID, matchers []
1085
1101
return req , nil
1086
1102
}
1087
1103
1088
- func createLabelValuesRequest (minT , maxT int64 , label string , blockIDs []ulid.ULID , matchers ... * labels.Matcher ) (* storepb.LabelValuesRequest , error ) {
1104
+ func createLabelValuesRequest (minT , maxT , limit int64 , label string , blockIDs []ulid.ULID , matchers ... * labels.Matcher ) (* storepb.LabelValuesRequest , error ) {
1089
1105
req := & storepb.LabelValuesRequest {
1090
1106
Start : minT ,
1091
1107
End : maxT ,
1108
+ Limit : limit ,
1092
1109
Label : label ,
1093
1110
Matchers : convertMatchersToLabelMatcher (matchers ),
1094
1111
}
0 commit comments