Skip to content

Implement metadata api query params #6681

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

Conversation

SungJin1212
Copy link
Member

@SungJin1212 SungJin1212 commented Apr 1, 2025

This PR implements the Prometheus metadata API query parameters (limit, limit_per_metric, and metric) on the Cortex to allow user to limit metadata to return.

Which issue(s) this PR fixes:
Fixes #6679

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@SungJin1212 SungJin1212 force-pushed the Implement-metadata-api-query-params branch 4 times, most recently from 9895799 to 3279526 Compare April 1, 2025 05:16
}

// MetadataHandler returns metric metadata held by Cortex for a given tenant.
// It is kept and returned as a set.
func MetadataHandler(m MetadataQuerier) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
resp, err := m.MetricsMetadata(r.Context())
limit := -1
if s := r.FormValue("limit"); s != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two parts are copy/paste - maybe worth converting into a func?

Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an integration test?

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
@SungJin1212 SungJin1212 force-pushed the Implement-metadata-api-query-params branch from 3279526 to 7a34129 Compare April 7, 2025 05:11
@pull-request-size pull-request-size bot added size/XL and removed size/L labels Apr 7, 2025
@SungJin1212 SungJin1212 requested review from GiedriusS and yeya24 April 7, 2025 07:24
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 12, 2025
@yeya24 yeya24 merged commit 8668b1c into cortexproject:master Apr 15, 2025
17 checks passed
mm.mtx.RLock()
defer mm.mtx.RUnlock()
r := make([]*cortexpb.MetricMetadata, 0, len(mm.metricToMetadata))
if req.Limit == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not backwards/forwards compatiable right?

For example, during a deployment, querier and ingesters can be using different version of Cortex. If querier is on an older version and ingesters on a newer version, then querier will invoke the ingester rpc without passing a limit.
In this case, ingesters will return empty metadata. Ideally we want the 0 value to be treated as limit is disabled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. We should put this behind a feature flag to do 2 phase rollout

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for letting me know. I will add flags and an e2e test for that scenario.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we want the 0 value to be treated as limit is disabled.

prometheus/prometheus#12862 There is an issue here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a feature flag here #6744.

Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add metadata API to the backward compatibility test to catch the problem earlier.

mm.mtx.RLock()
defer mm.mtx.RUnlock()
r := make([]*cortexpb.MetricMetadata, 0, len(mm.metricToMetadata))
if req.Limit == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. We should put this behind a feature flag to do 2 phase rollout

Limit: int64(limit),
LimitPerMetric: int64(limitPerMetric),
Metric: metric,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If limit is set to 0, do we still need to send the request to Ingester? There is no result anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/distributor component/querier lgtm This PR has been approved by a maintainer size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement metadata API query parameter (limit, limit_per_metric and metric)
5 participants