promql: Ensure that rate/increase/delta of histograms results in a gauge histogram. (#17608)

Signed-off-by: Andrew Hall <andrew.hall@grafana.com>
This commit is contained in:
Andrew Hall 2025-11-27 01:18:01 +08:00 committed by GitHub
parent e7999528fa
commit 7bb95d548c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -400,6 +400,7 @@ func histogramRate(points []HPoint, isCounter bool, metricName string, pos posra
annos.Add(annotations.NewNativeHistogramNotGaugeWarning(metricName, pos))
}
h.CounterResetHint = histogram.GaugeType
return h.Compact(0), annos
}

View File

@ -19,8 +19,23 @@ import (
"testing"
"github.com/stretchr/testify/require"
"github.com/prometheus/prometheus/model/histogram"
"github.com/prometheus/prometheus/promql/parser/posrange"
)
func TestHistogramRateCounterResetHint(t *testing.T) {
points := []HPoint{
{T: 0, H: &histogram.FloatHistogram{CounterResetHint: histogram.CounterReset, Count: 5, Sum: 5}},
{T: 1, H: &histogram.FloatHistogram{CounterResetHint: histogram.UnknownCounterReset, Count: 10, Sum: 10}},
}
fh, _ := histogramRate(points, false, "foo", posrange.PositionRange{})
require.Equal(t, histogram.GaugeType, fh.CounterResetHint)
fh, _ = histogramRate(points, true, "foo", posrange.PositionRange{})
require.Equal(t, histogram.GaugeType, fh.CounterResetHint)
}
func TestKahanSumInc(t *testing.T) {
testCases := map[string]struct {
first float64