Skip to content

Make maxLimit configurable per tenant for the /cardinality/label_names and /cardinality/label_values endpoints. #11456

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

zhuoyuan-liu
Copy link

@zhuoyuan-liu zhuoyuan-liu commented May 14, 2025

What this PR does

This PR introduces a new configurable parameter cardinality_api_max_series_limit to make the maximum number of series returned by cardinality API requests ( /cardinality/label_names and /cardinality/label_values ) configurable on a per-tenant basis.

The changes include:

  1. Adding a new field CardinalityAPIMaxSeriesLimit to the Limits struct in the cardinality section
  2. Registering a new flag querier.cardinality-api-max-series-limit with a default value of 500 (which was the previous hard-coded value)
  3. Adding a getter method CardinalityAPIMaxSeriesLimit to the Overrides struct
  4. Modifying the cardinality handlers to pass the tenant ID and overrides to the request decoders
  5. Updating the extractLimit function to use the tenant-specific limit instead of the hard-coded value

This PR is based on the feedback from #11025 (review)

Which issue(s) this PR fixes or relates to

Fixes #10328

Checklist

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

@zhuoyuan-liu zhuoyuan-liu requested review from tacole02 and a team as code owners May 14, 2025 12:47
@zhuoyuan-liu
Copy link
Author

Hi @narqo @pracucci , could you please take a look at this PR? This PR is based on the feedback from #11025 (review)

@LasseHels
Copy link
Contributor

@narqo @pracucci @dimitarvdimitrov Any chance of a review on this? We're eager to get this change out so we can proceed with our cardinality work internally.

@LasseHels
Copy link
Contributor

@narqo @pracucci @dimitarvdimitrov Bump. We'd be happy to get a review of this ❤️

@LasseHels
Copy link
Contributor

@narqo @npazosmendez @56quarters Bump. Any chance of a review on this?

Copy link
Contributor

@56quarters 56quarters left a comment

Choose a reason for hiding this comment

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

LGTM with some small changes. Thanks!

@@ -203,6 +203,7 @@ type Limits struct {
CardinalityAnalysisEnabled bool `yaml:"cardinality_analysis_enabled" json:"cardinality_analysis_enabled"`
LabelNamesAndValuesResultsMaxSizeBytes int `yaml:"label_names_and_values_results_max_size_bytes" json:"label_names_and_values_results_max_size_bytes"`
LabelValuesMaxCardinalityLabelNamesPerRequest int `yaml:"label_values_max_cardinality_label_names_per_request" json:"label_values_max_cardinality_label_names_per_request"`
CardinalityAPIMaxSeriesLimit int `yaml:"cardinality_api_max_series_limit" json:"cardinality_api_max_series_limit"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add an experimental tag here so that we can make changes before finalizing this setting?

@@ -203,6 +203,7 @@ type Limits struct {
CardinalityAnalysisEnabled bool `yaml:"cardinality_analysis_enabled" json:"cardinality_analysis_enabled"`
LabelNamesAndValuesResultsMaxSizeBytes int `yaml:"label_names_and_values_results_max_size_bytes" json:"label_names_and_values_results_max_size_bytes"`
LabelValuesMaxCardinalityLabelNamesPerRequest int `yaml:"label_values_max_cardinality_label_names_per_request" json:"label_values_max_cardinality_label_names_per_request"`
CardinalityAPIMaxSeriesLimit int `yaml:"cardinality_api_max_series_limit" json:"cardinality_api_max_series_limit"`
Copy link
Contributor

Choose a reason for hiding this comment

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

The limit isn't really limiting the number of series returned. Can you change the setting (and CLI flag, and methods) to cardinality_analysis_max_results.

}

// DecodeLabelValuesRequestFromValuesWithUser is like DecodeLabelValuesRequestFromValues but also accepts the userID and overrides.
func DecodeLabelValuesRequestFromValuesWithUser(values url.Values, userID string, overrides *validation.Overrides) (*LabelValuesRequest, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

here can we just take a limit instead of accepting the overrides? the limit we take will be the upper bound of the limit in the request. Same with DecodeLabelValuesRequest

@dimitarvdimitrov
Copy link
Contributor

you also need to run make reference-help doc to fix some of the unit tests and the linter. The integration test is a flake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Idea: Make it possible to analyse all values of a label with the /api/v1/cardinality/label_values endpoint
5 participants