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

Signed-off-by: Andrew Hall <andrew.hall@grafana.com>
pull/17620/head
Andrew Hall 3 weeks ago committed by GitHub
parent e7999528fa
commit 7bb95d548c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      promql/functions.go
  2. 15
      promql/functions_internal_test.go

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

@ -19,8 +19,23 @@ import (
"testing" "testing"
"github.com/stretchr/testify/require" "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) { func TestKahanSumInc(t *testing.T) {
testCases := map[string]struct { testCases := map[string]struct {
first float64 first float64

Loading…
Cancel
Save