Skip to content

Query ingesters only for GetLabelNames and GetLabelValues if start time parameter is not specified #6618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 19, 2025
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* [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
* [FEATURE] Update prometheus alertmanager version to v0.28.0 and add new integration msteamsv2, jira, and rocketchat. #6590
* [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
* [ENHANCEMENT] Querier: limit label APIs to query only ingesters if `start` param is not been specified. #6618
* [ENHANCEMENT] Alertmanager: Add new limits `-alertmanager.max-silences-count` and `-alertmanager.max-silences-size-bytes` for limiting silences per tenant. #6605
* [ENHANCEMENT] Update prometheus version to v3.1.0. #6583
* [ENHANCEMENT] Add `compactor.auto-forget-delay` for compactor to auto forget compactors after X minutes without heartbeat. #6533
Expand Down
4 changes: 2 additions & 2 deletions docs/api/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ GET,POST <prometheus-http-prefix>/api/v1/labels
GET,POST <legacy-http-prefix>/api/v1/labels
```

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.
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.

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

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

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.
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.

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

Expand Down
16 changes: 14 additions & 2 deletions pkg/querier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func (q querier) Select(ctx context.Context, sortSeries bool, sp *storage.Select

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

// For label values queries without specifying the start time, we prefer to
// only query ingesters and not to query maxQueryLength to avoid OOM kill.
if mint == 0 {
return metadataQuerier.LabelValues(ctx, name, hints, matchers...)
}

startTime := model.Time(mint)
endTime := model.Time(maxt)

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

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

// For label names queries without specifying the start time, we prefer to
// only query ingesters and not to query maxQueryLength to avoid OOM kill.
if mint == 0 {
return metadataQuerier.LabelNames(ctx, hints, matchers...)
}

startTime := model.Time(mint)
endTime := model.Time(maxt)

Expand Down
Loading