Merge pull request #18660 from roidelapluie/roidelapluie/histogram-stats-schema

promql: set Schema in HistogramStatsIterator to detect schema mix
This commit is contained in:
Bartlomiej Plotka 2026-05-11 13:11:40 +02:00 committed by GitHub
commit 4b3323e413
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View file

@ -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,
}

View file

@ -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.)