Skip to content

Conversation

@SungJin1212
Copy link
Member

This PR adds count validation for NH in Distributor side.

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

Checklist

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

}

// copy from https://github.com/prometheus/prometheus/blob/v3.6.0/model/histogram/generic.go#L399-L420
func checkHistogramBuckets[BC histogram.BucketCount, IBC histogram.InternalBucketCount](buckets []IBC, count *BC, deltas bool) (float64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we have to maintain this function and validation ourselves instead of reusing the validation function in Prometheus https://github.com/prometheus/prometheus/blob/main/model/histogram/histogram.go#L425C21-L425C29?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah we could utilize it. If we do that, it seems like we should return a single error type for these different causes.

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've updated to use Prometheus's Validate function and moved the check for invalid NH before the limit check to ensure we return a 400 error for them.

Signed-off-by: SungJin1212 <[email protected]>
Signed-off-by: SungJin1212 <[email protected]>
Signed-off-by: SungJin1212 <[email protected]>
@SungJin1212 SungJin1212 force-pushed the Add-NH-count-validation branch from 940f1bd to 2602c78 Compare November 3, 2025 08:48
Signed-off-by: SungJin1212 <[email protected]>
Signed-off-by: SungJin1212 <[email protected]>
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 for the fix!


if histogramSample.IsFloatHistogram() {
// Initial check to see if the bucket limit is exceeded or not. If not, we can avoid type casting.
fh := cortexpb.FloatHistogramProtoToFloatHistogram(histogramSample)
Copy link
Contributor

Choose a reason for hiding this comment

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

For next PR, consider adding sync pool here to reduce allocation.

@yeya24 yeya24 merged commit 30ee547 into cortexproject:master Nov 3, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PRW2 accepts invalid histograms instead of rejecting them

2 participants