Skip to content

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

}

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

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
Signed-off-by: Paurush Garg <paurushg@amazon.com>
@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 <paurushg@amazon.com>
@yeya24 yeya24 merged commit bd2bebf into cortexproject:master Jun 24, 2025
17 checks passed
bogdan-st pushed a commit to bogdan-st/cortex that referenced this pull request Jun 30, 2025
…6834)

* Add sample size limit validation for native histograms samples

Signed-off-by: Paurush Garg <paurushg@amazon.com>

* Fixing Rebase

Signed-off-by: Paurush Garg <paurushg@amazon.com>

---------

Signed-off-by: Paurush Garg <paurushg@amazon.com>
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