promql: set CounterResetHint after rate and sum

Signed-off-by: Trevor Whitney <trevorjwhitney@gmail.com>
This commit is contained in:
Trevor Whitney 2023-02-15 05:49:51 -07:00
parent 2d588725c1
commit dd94ebb87b
No known key found for this signature in database
GPG Key ID: 78F930867F302694
3 changed files with 16 additions and 4 deletions

View File

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

View File

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

View File

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