Skip to content

Commit d0f253c

Browse files
authored
StoreGateway: Implement metadata API limit in queryable (#6195)
1 parent bc69e73 commit d0f253c

File tree

3 files changed

+160
-19
lines changed

3 files changed

+160
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
* [ENHANCEMENT] Ingester/Ring: New `READONLY` status on ring to be used by Ingester. New ingester API to change mode of ingester #6163
1010
* [ENHANCEMENT] Ruler: Add query statistics metrics when --ruler.query-stats-enabled=true. #6173
1111
* [ENHANCEMENT] Ingester: Add new API `/ingester/all_user_stats` which shows loaded blocks, active timeseries and ingestion rate for a specific ingester. #6178
12-
* [ENHANCEMENT] Distributor: Add new `cortex_reduced_resolution_histogram_samples_total` metric to to track the number of histogram samples which resolution was reduced. #6182
12+
* [ENHANCEMENT] Distributor: Add new `cortex_reduced_resolution_histogram_samples_total` metric to track the number of histogram samples which resolution was reduced. #6182
13+
* [ENHANCEMENT] StoreGateway: Implement metadata API limit in queryable. #6195
1314

1415
## 1.18.0 2024-09-03
1516

pkg/querier/blocks_store_queryable.go

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,11 @@ func (q *blocksStoreQuerier) LabelNames(ctx context.Context, hints *storage.Labe
345345
spanLog, spanCtx := spanlogger.New(ctx, "blocksStoreQuerier.LabelNames")
346346
defer spanLog.Span.Finish()
347347

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+
}
349353

350354
var (
351355
resMtx sync.Mutex
@@ -355,7 +359,7 @@ func (q *blocksStoreQuerier) LabelNames(ctx context.Context, hints *storage.Labe
355359
)
356360

357361
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)
359363
if err != nil {
360364
return nil, err, retryableError
361365
}
@@ -372,6 +376,7 @@ func (q *blocksStoreQuerier) LabelNames(ctx context.Context, hints *storage.Labe
372376
return nil, nil, err
373377
}
374378

379+
// TODO(johrry): pass limit when merging.
375380
return strutil.MergeSlices(resNameSets...), resWarnings, nil
376381
}
377382

@@ -384,7 +389,11 @@ func (q *blocksStoreQuerier) LabelValues(ctx context.Context, name string, hints
384389
spanLog, spanCtx := spanlogger.New(ctx, "blocksStoreQuerier.LabelValues")
385390
defer spanLog.Span.Finish()
386391

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+
}
388397

389398
var (
390399
resValueSets = [][]string{}
@@ -394,7 +403,7 @@ func (q *blocksStoreQuerier) LabelValues(ctx context.Context, name string, hints
394403
)
395404

396405
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...)
398407
if err != nil {
399408
return nil, err, retryableError
400409
}
@@ -411,6 +420,7 @@ func (q *blocksStoreQuerier) LabelValues(ctx context.Context, name string, hints
411420
return nil, nil, err
412421
}
413422

423+
// TODO(johrry): pass limit when merging.
414424
return strutil.MergeSlices(resValueSets...), resWarnings, nil
415425
}
416426

@@ -427,9 +437,9 @@ func (q *blocksStoreQuerier) selectSorted(ctx context.Context, sp *storage.Selec
427437
spanLog, spanCtx := spanlogger.New(ctx, "blocksStoreQuerier.selectSorted")
428438
defer spanLog.Span.Finish()
429439

430-
minT, maxT := q.minT, q.maxT
440+
minT, maxT, limit := q.minT, q.maxT, int64(0)
431441
if sp != nil {
432-
minT, maxT = sp.Start, sp.End
442+
minT, maxT, limit = sp.Start, sp.End, int64(sp.Limit)
433443
}
434444

435445
var (
@@ -443,7 +453,7 @@ func (q *blocksStoreQuerier) selectSorted(ctx context.Context, sp *storage.Selec
443453
)
444454

445455
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)
447457
if err != nil {
448458
return nil, err, retryableError
449459
}
@@ -471,6 +481,7 @@ func (q *blocksStoreQuerier) selectSorted(ctx context.Context, sp *storage.Selec
471481
storage.EmptySeriesSet()
472482
}
473483

484+
// TODO(johrry): pass limit when merging.
474485
return series.NewSeriesSetWithWarnings(
475486
storage.NewMergeSeriesSet(resSeriesSets, storage.ChainedSeriesMerge),
476487
resWarnings)
@@ -593,6 +604,7 @@ func (q *blocksStoreQuerier) fetchSeriesFromStores(
593604
clients map[BlocksStoreClient][]ulid.ULID,
594605
minT int64,
595606
maxT int64,
607+
limit int64,
596608
matchers []*labels.Matcher,
597609
maxChunksLimit int,
598610
leftChunksLimit int,
@@ -635,7 +647,7 @@ func (q *blocksStoreQuerier) fetchSeriesFromStores(
635647
seriesQueryStats := &hintspb.QueryStats{}
636648
skipChunks := sp != nil && sp.Func == "series"
637649

638-
req, err := createSeriesRequest(minT, maxT, convertedMatchers, shardingInfo, skipChunks, blockIDs, defaultAggrs)
650+
req, err := createSeriesRequest(minT, maxT, limit, convertedMatchers, shardingInfo, skipChunks, blockIDs, defaultAggrs)
639651
if err != nil {
640652
return errors.Wrapf(err, "failed to create series request")
641653
}
@@ -825,6 +837,7 @@ func (q *blocksStoreQuerier) fetchLabelNamesFromStore(
825837
clients map[BlocksStoreClient][]ulid.ULID,
826838
minT int64,
827839
maxT int64,
840+
limit int64,
828841
matchers []storepb.LabelMatcher,
829842
) ([][]string, annotations.Annotations, []ulid.ULID, error, error) {
830843
var (
@@ -846,7 +859,7 @@ func (q *blocksStoreQuerier) fetchLabelNamesFromStore(
846859
blockIDs := blockIDs
847860

848861
g.Go(func() error {
849-
req, err := createLabelNamesRequest(minT, maxT, blockIDs, matchers)
862+
req, err := createLabelNamesRequest(minT, maxT, limit, blockIDs, matchers)
850863
if err != nil {
851864
return errors.Wrapf(err, "failed to create label names request")
852865
}
@@ -927,6 +940,7 @@ func (q *blocksStoreQuerier) fetchLabelValuesFromStore(
927940
clients map[BlocksStoreClient][]ulid.ULID,
928941
minT int64,
929942
maxT int64,
943+
limit int64,
930944
matchers ...*labels.Matcher,
931945
) ([][]string, annotations.Annotations, []ulid.ULID, error, error) {
932946
var (
@@ -948,7 +962,7 @@ func (q *blocksStoreQuerier) fetchLabelValuesFromStore(
948962
blockIDs := blockIDs
949963

950964
g.Go(func() error {
951-
req, err := createLabelValuesRequest(minT, maxT, name, blockIDs, matchers...)
965+
req, err := createLabelValuesRequest(minT, maxT, limit, name, blockIDs, matchers...)
952966
if err != nil {
953967
return errors.Wrapf(err, "failed to create label values request")
954968
}
@@ -1025,7 +1039,7 @@ func (q *blocksStoreQuerier) fetchLabelValuesFromStore(
10251039
return valueSets, warnings, queriedBlocks, nil, merr.Err()
10261040
}
10271041

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) {
10291043
// Selectively query only specific blocks.
10301044
hints := &hintspb.SeriesRequestHints{
10311045
BlockMatchers: []storepb.LabelMatcher{
@@ -1046,6 +1060,7 @@ func createSeriesRequest(minT, maxT int64, matchers []storepb.LabelMatcher, shar
10461060
return &storepb.SeriesRequest{
10471061
MinTime: minT,
10481062
MaxTime: maxT,
1063+
Limit: limit,
10491064
Matchers: matchers,
10501065
PartialResponseStrategy: storepb.PartialResponseStrategy_ABORT,
10511066
Hints: anyHints,
@@ -1057,10 +1072,11 @@ func createSeriesRequest(minT, maxT int64, matchers []storepb.LabelMatcher, shar
10571072
}, nil
10581073
}
10591074

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) {
10611076
req := &storepb.LabelNamesRequest{
10621077
Start: minT,
10631078
End: maxT,
1079+
Limit: limit,
10641080
Matchers: matchers,
10651081
}
10661082

@@ -1085,10 +1101,11 @@ func createLabelNamesRequest(minT, maxT int64, blockIDs []ulid.ULID, matchers []
10851101
return req, nil
10861102
}
10871103

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) {
10891105
req := &storepb.LabelValuesRequest{
10901106
Start: minT,
10911107
End: maxT,
1108+
Limit: limit,
10921109
Label: label,
10931110
Matchers: convertMatchersToLabelMatcher(matchers),
10941111
}

0 commit comments

Comments
 (0)