From ff49406cbab6c3155d8bf4b19aa7b8d5b1017d38 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Tue, 14 Oct 2025 00:52:23 +0200 Subject: [PATCH 1/2] promql: Expose bug of not checking 1st histogram for CRH avg_over_time already correctly checked the counter reset hint fo all histograms, but in sum_over_time, the 1st histogram was missed in the loop. This commit exposes the bug in a test. Signed-off-by: beorn7 --- promql/promqltest/testdata/native_histograms.test | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/promql/promqltest/testdata/native_histograms.test b/promql/promqltest/testdata/native_histograms.test index 9ec222c17c..986b8de04f 100644 --- a/promql/promqltest/testdata/native_histograms.test +++ b/promql/promqltest/testdata/native_histograms.test @@ -1709,6 +1709,18 @@ eval instant at 14m histogram_count(avg_over_time(mixed[10m])) expect no_info {} 9.3 +# In the following two tests, the first sample has hint "not_reset" +# and the second has "reset". This tests if the conflict is detected +# between the first two samples, too. +eval instant at 11m histogram_count(sum_over_time(mixed[2m])) + expect warn msg:PromQL warning: conflicting counter resets during histogram aggregation + expect no_info + {} 21 + +eval instant at 11m histogram_count(avg_over_time(mixed[2m])) + expect warn msg:PromQL warning: conflicting counter resets during histogram aggregation + expect no_info + {} 10.5 # Test histogram_quantile annotations. load 1m From e80a3e1b2173da30981a722a3b462e4c3c03328a Mon Sep 17 00:00:00 2001 From: beorn7 Date: Tue, 14 Oct 2025 00:56:07 +0200 Subject: [PATCH 2/2] promql: Check 1st histogram's CRH in sum_over_time avg_over_time already correctly checked the counter reset hint fo all histograms, but in sum_over_time, the 1st histogram was missed. In both cases, the 1st histogram is processed outside the loop. Signed-off-by: beorn7 --- promql/functions.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/promql/functions.go b/promql/functions.go index 2d9d26dfb1..35420a8098 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -1092,6 +1092,15 @@ func funcSumOverTime(_ []Vector, matrixVal Matrix, args parser.Expressions, enh vec, err := aggrHistOverTime(matrixVal, enh, func(s Series) (*histogram.FloatHistogram, error) { var counterResetSeen, notCounterResetSeen bool + trackCounterReset := func(h *histogram.FloatHistogram) { + switch h.CounterResetHint { + case histogram.CounterReset: + counterResetSeen = true + case histogram.NotCounterReset: + notCounterResetSeen = true + } + } + defer func() { if counterResetSeen && notCounterResetSeen { annos.Add(annotations.NewHistogramCounterResetCollisionWarning(args[0].PositionRange(), annotations.HistogramAgg)) @@ -1099,13 +1108,9 @@ func funcSumOverTime(_ []Vector, matrixVal Matrix, args parser.Expressions, enh }() sum := s.Histograms[0].H.Copy() + trackCounterReset(sum) for _, h := range s.Histograms[1:] { - switch h.H.CounterResetHint { - case histogram.CounterReset: - counterResetSeen = true - case histogram.NotCounterReset: - notCounterResetSeen = true - } + trackCounterReset(h.H) _, _, err := sum.Add(h.H) if err != nil { return sum, err