fix(promql): do not loose information about buckets when doing the detect

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
This commit is contained in:
György Krajcsovits 2025-06-04 10:24:50 +02:00
parent df94ecebab
commit bccb1d6459
No known key found for this signature in database
GPG Key ID: 47A8F9CE80FD7C7F
2 changed files with 18 additions and 17 deletions

View File

@ -126,17 +126,15 @@ func (f *histogramStatsIterator) getFloatResetHint(hint histogram.CounterResetHi
if hint != histogram.UnknownCounterReset { if hint != histogram.UnknownCounterReset {
return hint return hint
} }
if f.lastFH == nil { prevFH := f.lastFH
// If there was no previous histogram, this will not be used, if prevFH == nil {
// and if there was a previous integer histogram, this will if f.lastH == nil {
// force a reset detection. The later can happen if we used the // We don't know if there's a counter reset.
// iterator to read integer histograms before, but switched to return histogram.UnknownCounterReset
// float histograms for whatever reason. }
// https://github.com/prometheus/prometheus/issues/16681 prevFH = f.lastH.ToFloat(nil)
return histogram.UnknownCounterReset
} }
if f.currentFH.DetectReset(prevFH) {
if f.currentFH.DetectReset(f.lastFH) {
return histogram.CounterReset return histogram.CounterReset
} }
return histogram.NotCounterReset return histogram.NotCounterReset
@ -146,14 +144,17 @@ func (f *histogramStatsIterator) getResetHint(h *histogram.Histogram) histogram.
if h.CounterResetHint != histogram.UnknownCounterReset { if h.CounterResetHint != histogram.UnknownCounterReset {
return h.CounterResetHint return h.CounterResetHint
} }
var prevFH *histogram.FloatHistogram
if f.lastH == nil { if f.lastH == nil {
// If there was no previous histogram, this will not be used, if f.lastFH == nil {
// and if there was a previous float histogram, this will // We don't know if there's a counter reset.
// force a reset detection. return histogram.UnknownCounterReset
return histogram.UnknownCounterReset }
prevFH = f.lastFH
} else {
prevFH = f.lastH.ToFloat(nil)
} }
fh := h.ToFloat(nil)
fh, prevFH := h.ToFloat(nil), f.lastH.ToFloat(nil)
if fh.DetectReset(prevFH) { if fh.DetectReset(prevFH) {
return histogram.CounterReset return histogram.CounterReset
} }

View File

@ -156,7 +156,7 @@ func TestHistogramStatsMixedUse(t *testing.T) {
expectedHints := []histogram.CounterResetHint{ expectedHints := []histogram.CounterResetHint{
histogram.UnknownCounterReset, histogram.UnknownCounterReset,
histogram.NotCounterReset, histogram.NotCounterReset,
histogram.UnknownCounterReset, histogram.CounterReset,
} }
actualHints := make([]histogram.CounterResetHint, 3) actualHints := make([]histogram.CounterResetHint, 3)
typ := statsIterator.Next() typ := statsIterator.Next()