Skip to content

Add native histogram max sample size limit validation #6834

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

PaurushGarg
Copy link
Contributor

@PaurushGarg PaurushGarg commented Jun 20, 2025

What this PR does:
Add native histogram max sample size bytes limit validation.
This is added b/c native histogram can have infinite buckets for a given schema increasing the size of a nh sample. Size of a NH sample can also grow due to other factors like Spans. Although max_bucket_count limit reduces resolution of NH samples, but this limit is added to discard samples if the sample size is excessive and can load Distributors.
This limit is not added as per-user override.

Which issue(s) this PR fixes:
Fixes #

Checklist

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

@PaurushGarg PaurushGarg changed the title Add sample size limit validation for native histograms samples Add native histograms max sample size limit validation Jun 20, 2025
@PaurushGarg PaurushGarg marked this pull request as ready for review June 20, 2025 19:24
@pull-request-size pull-request-size bot added size/L and removed size/M labels Jun 20, 2025
Copy link
Contributor

@harry671003 harry671003 left a comment

Choose a reason for hiding this comment

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

Overall looks good. One nit.

MaxLabelValueLength int `yaml:"max_label_value_length" json:"max_label_value_length"`
MaxLabelNamesPerSeries int `yaml:"max_label_names_per_series" json:"max_label_names_per_series"`
MaxLabelsSizeBytes int `yaml:"max_labels_size_bytes" json:"max_labels_size_bytes"`
MaxNativeHistogramsSampleSizeBytes int `yaml:"max_native_histograms_sample_size_bytes" json:"max_native_histograms_sample_size_bytes"`
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: MaxNativeHistogramSampleSizeBytes

This is for a single sample. Not like the labels limit which is for all the labels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Updated.

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.

Thanks. Just some nits. Rest LGTM

@@ -262,6 +262,26 @@ func (e *nativeHistogramSchemaInvalidError) Error() string {
return fmt.Sprintf("invalid native histogram schema %d for metric: %.200q. supported schema from %d to %d", e.receivedSchema, formatLabelSet(e.series), histogram.ExponentialSchemaMin, histogram.ExponentialSchemaMax)
}

// nativeHistogramSchemaInvalidError is a ValidationError implementation for samples with native histogram
// exceeding the valid schema range.
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to update the comment. Not nativeHistogramSchemaInvalidError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Updated.

@@ -339,6 +340,13 @@ func ValidateMetadata(validateMetrics *ValidateMetrics, cfg *Limits, userID stri

func ValidateNativeHistogram(validateMetrics *ValidateMetrics, limits *Limits, userID string, ls []cortexpb.LabelAdapter, histogramSample cortexpb.Histogram) (cortexpb.Histogram, error) {

// sample size validation for native histogram
nhSampleSize := histogramSample.Size()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: we can only calculate the sample size if the limit is > 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Updated.

@PaurushGarg PaurushGarg changed the title Add native histograms max sample size limit validation Add native histogram max sample size limit validation Jun 24, 2025
@PaurushGarg PaurushGarg force-pushed the native-histograms-sample-size-limit branch from ec63c2b to e33587b Compare June 24, 2025 17:09
@pull-request-size pull-request-size bot added size/M and removed size/L labels Jun 24, 2025
Signed-off-by: Paurush Garg <[email protected]>
@yeya24 yeya24 merged commit bd2bebf into cortexproject:master Jun 24, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants