diff --git a/promql/histogram_stats_iterator.go b/promql/histogram_stats_iterator.go index 87cc5acfbd..f6afb50b61 100644 --- a/promql/histogram_stats_iterator.go +++ b/promql/histogram_stats_iterator.go @@ -86,10 +86,14 @@ func (*HistogramStatsIterator) AtHistogram(*histogram.Histogram) (int64, *histog // performs a counter reset detection on the fly. It will return an explicit // hint (not UnknownCounterReset) if the previous sample has been accessed with // the same iterator. +// +// The returned histogram contains only Count, Sum, CounterResetHint, and Schema. +// Bucket data is intentionally omitted. func (hsi *HistogramStatsIterator) AtFloatHistogram(fh *histogram.FloatHistogram) (int64, *histogram.FloatHistogram) { populateFH := func(src *histogram.FloatHistogram, detectReset bool) { h := histogram.FloatHistogram{ CounterResetHint: src.CounterResetHint, + Schema: src.Schema, Count: src.Count, Sum: src.Sum, } diff --git a/promql/promqltest/testdata/native_histograms.test b/promql/promqltest/testdata/native_histograms.test index 88ba36c86b..ce473dc69a 100644 --- a/promql/promqltest/testdata/native_histograms.test +++ b/promql/promqltest/testdata/native_histograms.test @@ -1118,6 +1118,13 @@ eval instant at 1m30s rate(some_metric[1m30s]) expect warn msg: PromQL warning: vector contains a mix of histograms with exponential and custom buckets schemas for metric name "some_metric" # Should produce no results. +# histogram_count(rate()) must also warn when the schema mix falls inside the stats-only +# path (HistogramStatsIterator). Without Schema being set in that iterator, all histograms +# appear as Schema=0 and the custom-bucket mismatch is silently missed. +eval instant at 1m histogram_count(rate(some_metric[1m30s])) + expect warn msg: PromQL warning: vector contains a mix of histograms with exponential and custom buckets schemas for metric name "some_metric" + # Should produce no results. + # Start with custom, end with exponential. Return the exponential histogram divided by 48. # (The 1st sample is the NHCB with count:1. It is mostly ignored with the exception of the # count, which means the rate calculation extrapolates until the count hits 0.)