Skip to content

Commit 268f089

Browse files
authored
Query ingesters only for GetLabelNames and GetLabelValues if start time parameter is not specified (#6618)
* truncate getLabels and getSeries to max range if no start-end time provided Signed-off-by: Ahmed Hassan <[email protected]> * use prometheus api helper function for millisecond conversion Signed-off-by: Ahmed Hassan <[email protected]> * Revert "use prometheus api helper function for millisecond conversion" This reverts commit 4301baf. Signed-off-by: Ahmed Hassan <[email protected]> * Revert "truncate getLabels and getSeries to max range if no start-end time provided" This reverts commit 700b1c2. Signed-off-by: Ahmed Hassan <[email protected]> * label requests query ingesters only if start time not specified Signed-off-by: Ahmed Hassan <[email protected]> * update api docs Signed-off-by: Ahmed Hassan <[email protected]> * rerun tests Signed-off-by: Ahmed Hassan <[email protected]> * update changelog Signed-off-by: Ahmed Hassan <[email protected]> --------- Signed-off-by: Ahmed Hassan <[email protected]> Signed-off-by: Ahmed Hassan <[email protected]>
1 parent f92e3fa commit 268f089

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [FEATURE] Querier/Ruler: Add `query_partial_data` and `rules_partial_data` limits to allow queries/rules to be evaluated with data from a single zone, if other zones are not available. #6526
77
* [FEATURE] Update prometheus alertmanager version to v0.28.0 and add new integration msteamsv2, jira, and rocketchat. #6590
88
* [FEATURE] Ingester: Add a `-ingester.enable-ooo-native-histograms` flag to enable out-of-order native histogram ingestion per tenant. It only takes effect when `-blocks-storage.tsdb.enable-native-histograms=true` and `-ingester.out-of-order-time-window` > 0. It is applied after the restart if it is changed at runtime through the runtime config. #6626
9+
* [ENHANCEMENT] Querier: limit label APIs to query only ingesters if `start` param is not been specified. #6618
910
* [ENHANCEMENT] Alertmanager: Add new limits `-alertmanager.max-silences-count` and `-alertmanager.max-silences-size-bytes` for limiting silences per tenant. #6605
1011
* [ENHANCEMENT] Update prometheus version to v3.1.0. #6583
1112
* [ENHANCEMENT] Add `compactor.auto-forget-delay` for compactor to auto forget compactors after X minutes without heartbeat. #6533

docs/api/_index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ GET,POST <prometheus-http-prefix>/api/v1/labels
390390
GET,POST <legacy-http-prefix>/api/v1/labels
391391
```
392392

393-
Get label names of ingested series. Starting from release v1.18.0, Cortex by default honors the `start` and `end` request parameters and fetches label names from either ingester, store gateway or both.
393+
Get label names of ingested series. Starting from release v1.18.0, Cortex by default honors the `start` and `end` request parameters and fetches label names from either ingester, store gateway or both. The special case is that if `start` param is not specified, Cortex currently fetches labels from data stored in the ingesters.
394394

395395
_For more information, please check out the Prometheus [get label names](https://prometheus.io/docs/prometheus/latest/querying/api/#getting-label-names) documentation._
396396

@@ -405,7 +405,7 @@ GET <prometheus-http-prefix>/api/v1/label/{name}/values
405405
GET <legacy-http-prefix>/api/v1/label/{name}/values
406406
```
407407

408-
Get label values for a given label name. Starting from release v1.18.0, Cortex by default honors the `start` and `end` request parameters and fetches label values from either ingester, store gateway or both.
408+
Get label values for a given label name. Starting from release v1.18.0, Cortex by default honors the `start` and `end` request parameters and fetches label values from either ingester, store gateway or both. The special case is that if `start` param is not specified, Cortex currently fetches label values from data stored in the ingesters.
409409

410410
_For more information, please check out the Prometheus [get label values](https://prometheus.io/docs/prometheus/latest/querying/api/#querying-label-values) documentation._
411411

pkg/querier/querier.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ func (q querier) Select(ctx context.Context, sortSeries bool, sp *storage.Select
431431

432432
// LabelValues implements storage.Querier.
433433
func (q querier) LabelValues(ctx context.Context, name string, hints *storage.LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error) {
434-
ctx, stats, userID, mint, maxt, _, queriers, err := q.setupFromCtx(ctx)
434+
ctx, stats, userID, mint, maxt, metadataQuerier, queriers, err := q.setupFromCtx(ctx)
435435
if err == errEmptyTimeRange {
436436
return nil, nil, nil
437437
} else if err != nil {
@@ -442,6 +442,12 @@ func (q querier) LabelValues(ctx context.Context, name string, hints *storage.La
442442
stats.AddQueryStorageWallTime(time.Since(startT))
443443
}()
444444

445+
// For label values queries without specifying the start time, we prefer to
446+
// only query ingesters and not to query maxQueryLength to avoid OOM kill.
447+
if mint == 0 {
448+
return metadataQuerier.LabelValues(ctx, name, hints, matchers...)
449+
}
450+
445451
startTime := model.Time(mint)
446452
endTime := model.Time(maxt)
447453

@@ -494,7 +500,7 @@ func (q querier) LabelValues(ctx context.Context, name string, hints *storage.La
494500
}
495501

496502
func (q querier) LabelNames(ctx context.Context, hints *storage.LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error) {
497-
ctx, stats, userID, mint, maxt, _, queriers, err := q.setupFromCtx(ctx)
503+
ctx, stats, userID, mint, maxt, metadataQuerier, queriers, err := q.setupFromCtx(ctx)
498504
if err == errEmptyTimeRange {
499505
return nil, nil, nil
500506
} else if err != nil {
@@ -505,6 +511,12 @@ func (q querier) LabelNames(ctx context.Context, hints *storage.LabelHints, matc
505511
stats.AddQueryStorageWallTime(time.Since(startT))
506512
}()
507513

514+
// For label names queries without specifying the start time, we prefer to
515+
// only query ingesters and not to query maxQueryLength to avoid OOM kill.
516+
if mint == 0 {
517+
return metadataQuerier.LabelNames(ctx, hints, matchers...)
518+
}
519+
508520
startTime := model.Time(mint)
509521
endTime := model.Time(maxt)
510522

0 commit comments

Comments
 (0)