mirror of
https://github.com/prometheus/prometheus
synced 2024-12-28 09:42:22 +00:00
promql: set CounterResetHint after rate and sum
Signed-off-by: Trevor Whitney <trevorjwhitney@gmail.com>
This commit is contained in:
parent
2d588725c1
commit
dd94ebb87b
@ -192,6 +192,8 @@ func (h *FloatHistogram) Scale(factor float64) *FloatHistogram {
|
|||||||
//
|
//
|
||||||
// This method returns a pointer to the receiving histogram for convenience.
|
// This method returns a pointer to the receiving histogram for convenience.
|
||||||
func (h *FloatHistogram) Add(other *FloatHistogram) *FloatHistogram {
|
func (h *FloatHistogram) Add(other *FloatHistogram) *FloatHistogram {
|
||||||
|
// TODO(trevorwhitney): If other.CounterResetHint != h.CounterResetHint then
|
||||||
|
// we should return some warning.
|
||||||
otherZeroCount := h.reconcileZeroBuckets(other)
|
otherZeroCount := h.reconcileZeroBuckets(other)
|
||||||
h.ZeroCount += otherZeroCount
|
h.ZeroCount += otherZeroCount
|
||||||
h.Count += other.Count
|
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
|
// information can be read directly from there rather than be detected each time
|
||||||
// again.
|
// again.
|
||||||
func (h *FloatHistogram) DetectReset(previous *FloatHistogram) bool {
|
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 {
|
if h.Count < previous.Count {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -3155,8 +3155,7 @@ func TestNativeHistogramRate(t *testing.T) {
|
|||||||
require.Len(t, vector, 1)
|
require.Len(t, vector, 1)
|
||||||
actualHistogram := vector[0].H
|
actualHistogram := vector[0].H
|
||||||
expectedHistogram := &histogram.FloatHistogram{
|
expectedHistogram := &histogram.FloatHistogram{
|
||||||
// TODO(beorn7): This should be GaugeType. Change it once supported by PromQL.
|
CounterResetHint: histogram.GaugeType,
|
||||||
CounterResetHint: histogram.NotCounterReset,
|
|
||||||
Schema: 1,
|
Schema: 1,
|
||||||
ZeroThreshold: 0.001,
|
ZeroThreshold: 0.001,
|
||||||
ZeroCount: 1. / 15.,
|
ZeroCount: 1. / 15.,
|
||||||
@ -3200,8 +3199,7 @@ func TestNativeFloatHistogramRate(t *testing.T) {
|
|||||||
require.Len(t, vector, 1)
|
require.Len(t, vector, 1)
|
||||||
actualHistogram := vector[0].H
|
actualHistogram := vector[0].H
|
||||||
expectedHistogram := &histogram.FloatHistogram{
|
expectedHistogram := &histogram.FloatHistogram{
|
||||||
// TODO(beorn7): This should be GaugeType. Change it once supported by PromQL.
|
CounterResetHint: histogram.GaugeType,
|
||||||
CounterResetHint: histogram.NotCounterReset,
|
|
||||||
Schema: 1,
|
Schema: 1,
|
||||||
ZeroThreshold: 0.001,
|
ZeroThreshold: 0.001,
|
||||||
ZeroCount: 1. / 15.,
|
ZeroCount: 1. / 15.,
|
||||||
|
@ -187,6 +187,7 @@ func histogramRate(points []Point, isCounter bool) *histogram.FloatHistogram {
|
|||||||
if curr == nil {
|
if curr == nil {
|
||||||
return nil // Range contains a mix of histograms and floats.
|
return nil // Range contains a mix of histograms and floats.
|
||||||
}
|
}
|
||||||
|
// TODO(trevorwhitney): Check if isCounter is consistent with curr.CounterResetHint.
|
||||||
if !isCounter {
|
if !isCounter {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -208,6 +209,8 @@ func histogramRate(points []Point, isCounter bool) *histogram.FloatHistogram {
|
|||||||
prev = curr
|
prev = curr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.CounterResetHint = histogram.GaugeType
|
||||||
return h.Compact(0)
|
return h.Compact(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user