Browse Source

promql: set CounterResetHint after rate and sum

Signed-off-by: Trevor Whitney <trevorjwhitney@gmail.com>
pull/11978/head
Trevor Whitney 2 years ago
parent
commit
dd94ebb87b
No known key found for this signature in database
GPG Key ID: 78F930867F302694
  1. 11
      model/histogram/float_histogram.go
  2. 6
      promql/engine_test.go
  3. 3
      promql/functions.go

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

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

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

Loading…
Cancel
Save