Skip to content

Comments

util: add native histogram support to SendSumOfHistograms#7178

Open
siddarth2810 wants to merge 3 commits intocortexproject:masterfrom
siddarth2810:support-native-histograms
Open

util: add native histogram support to SendSumOfHistograms#7178
siddarth2810 wants to merge 3 commits intocortexproject:masterfrom
siddarth2810:support-native-histograms

Conversation

@siddarth2810
Copy link
Contributor

Extend HistogramData struct with native histogram fields. Convert input spans+deltas to map[int]int64 for aggregation. On output, MustNewConstNativeHistogram calls makeBucketsFromMap() to reconstruct spans+deltas for wire format.

What this PR does:

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

Checklist

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

Extend HistogramData struct with native histogram fields. Convert input
spans+deltas to map[int]int64 for aggregation. On output, MustNewConstNativeHistogram calls makeBucketsFromMap()
to reconstruct spans+deltas for wire format.

Signed-off-by: Siddarth Gundu <siddarthg0910@gmail.com>
Signed-off-by: Siddarth Gundu <siddarthg0910@gmail.com>
isNative() treated any Histogram with a non-zero ZeroThreshold as native, even
when classic buckets were present.

In the alertmanager tests the incoming histograms have classic buckets and
native histogram fields like `ZeroThreshold` but no spans/deltas, so AddHistogram()
routed them to the native path, causing validateCount panic when bucket
population != sampleCount.

Signed-off-by: Siddarth Gundu <siddarthg0910@gmail.com>
@siddarth2810 siddarth2810 force-pushed the support-native-histograms branch from f335ae6 to 03942b1 Compare February 17, 2026 11:58
@friedrichg friedrichg self-requested a review February 17, 2026 17:40
Copy link
Member

@friedrichg friedrichg 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 PR,

Looking at

cortex_bucket_store_indexheader_lazy_load_duration_seconds_bucket{le="0.01"} 0
cortex_bucket_store_indexheader_lazy_load_duration_seconds_bucket{le="0.02"} 0
cortex_bucket_store_indexheader_lazy_load_duration_seconds_bucket{le="0.05"} 0
cortex_bucket_store_indexheader_lazy_load_duration_seconds_bucket{le="0.1"} 0
cortex_bucket_store_indexheader_lazy_load_duration_seconds_bucket{le="0.2"} 0
cortex_bucket_store_indexheader_lazy_load_duration_seconds_bucket{le="0.5"} 0
cortex_bucket_store_indexheader_lazy_load_duration_seconds_bucket{le="1"} 3
cortex_bucket_store_indexheader_lazy_load_duration_seconds_bucket{le="2"} 3
cortex_bucket_store_indexheader_lazy_load_duration_seconds_bucket{le="5"} 3
cortex_bucket_store_indexheader_lazy_load_duration_seconds_bucket{le="+Inf"} 3
cortex_bucket_store_indexheader_lazy_load_duration_seconds_sum 1.9500000000000002
cortex_bucket_store_indexheader_lazy_load_duration_seconds_count 3

I think we need a TestBucketStoreNativeHistogramMetrics. do you agree?. We want to check what it is returning after this change. right?.


classic := len(histo.GetBucket()) > 0

return native && !classic
Copy link
Contributor

Choose a reason for hiding this comment

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

You mentioned that this is for the alertmanager test. But can we reproduce it in a unit test in metrics_helper_test.go? I feel this is unlikely to have hybrid histograms.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nvm I got it now. As long as we define histogram to be available as NH then every observation will add to both classic histogram bucket as well as NH buckets

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.

The usecase of having SendSumOfHistograms to support native histogram is for this metrics aggregation continues to work if the underlying data is NH.

I wonder if it is possible to use a real metric like from Prometheus and we aggregate it via SendSumOfHistograms and make sure it is working properly. But it is not a blocker

len(h.GetNegativeSpan()) > 0 ||
h.GetZeroCount() > 0 ||
h.GetZeroThreshold() > 0,
"expected a native histogram output (spans/zero bucket present)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we assert on detailed fields of NH to make sure the generated data is correct? Instead of simply checking it is a native histogram

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.

SendSumOfHistograms should support native histograms

3 participants