diff --git a/model/histogram/float_histogram.go b/model/histogram/float_histogram.go index 256679a8c..6b823f7d3 100644 --- a/model/histogram/float_histogram.go +++ b/model/histogram/float_histogram.go @@ -192,6 +192,8 @@ func (h *FloatHistogram) Scale(factor float64) *FloatHistogram { // // This method returns a pointer to the receiving histogram for convenience. func (h *FloatHistogram) Add(other *FloatHistogram) *FloatHistogram { + // TODO(trevorwhitney): If other.CounterResetHint != h.CounterResetHint then + // we should return some warning. otherZeroCount := h.reconcileZeroBuckets(other) h.ZeroCount += otherZeroCount h.Count += other.Count @@ -438,6 +440,15 @@ func (h *FloatHistogram) Compact(maxEmptyBuckets int) *FloatHistogram { // information can be read directly from there rather than be detected each time // again. func (h *FloatHistogram) DetectReset(previous *FloatHistogram) bool { + if h.CounterResetHint == CounterReset { + return true + } + if h.CounterResetHint == NotCounterReset { + return false + } + // In all other cases of CounterResetHint, we go on as we would otherwise. + // Even in the GaugeHistogram case, we pretend this is a counter histogram + // for consistency. if h.Count < previous.Count { return true } diff --git a/promql/engine_test.go b/promql/engine_test.go index e2e209849..d1c4570ea 100644 --- a/promql/engine_test.go +++ b/promql/engine_test.go @@ -3155,8 +3155,7 @@ func TestNativeHistogramRate(t *testing.T) { require.Len(t, vector, 1) actualHistogram := vector[0].H expectedHistogram := &histogram.FloatHistogram{ - // TODO(beorn7): This should be GaugeType. Change it once supported by PromQL. - CounterResetHint: histogram.NotCounterReset, + CounterResetHint: histogram.GaugeType, Schema: 1, ZeroThreshold: 0.001, ZeroCount: 1. / 15., @@ -3200,8 +3199,7 @@ func TestNativeFloatHistogramRate(t *testing.T) { require.Len(t, vector, 1) actualHistogram := vector[0].H expectedHistogram := &histogram.FloatHistogram{ - // TODO(beorn7): This should be GaugeType. Change it once supported by PromQL. - CounterResetHint: histogram.NotCounterReset, + CounterResetHint: histogram.GaugeType, Schema: 1, ZeroThreshold: 0.001, ZeroCount: 1. / 15., diff --git a/promql/functions.go b/promql/functions.go index c5922002b..3da38ea0f 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -187,6 +187,7 @@ func histogramRate(points []Point, isCounter bool) *histogram.FloatHistogram { if curr == nil { return nil // Range contains a mix of histograms and floats. } + // TODO(trevorwhitney): Check if isCounter is consistent with curr.CounterResetHint. if !isCounter { continue } @@ -208,6 +209,8 @@ func histogramRate(points []Point, isCounter bool) *histogram.FloatHistogram { prev = curr } } + + h.CounterResetHint = histogram.GaugeType return h.Compact(0) }