promql: Fix counter reset detection in subqueries with histograms

Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
beorn7 2025-02-06 14:54:37 +01:00
parent 6518941d73
commit 14bb63c467

View File

@ -1548,6 +1548,28 @@ func (ev *evaluator) evalSubquery(ctx context.Context, subq *parser.SubqueryExpr
VectorSelector: vs,
}
for _, s := range mat {
// Set any "NotCounterReset" and "CounterReset" hints in native
// histograms to "UnknownCounterReset" because we might
// otherwise miss a counter reset happening in samples not
// returned by the subquery, or we might over-detect counter
// resets if the sample with a counter reset is returned
// multiple times by a high-res subquery. This intentionally
// does not attempt to be clever (like detecting if we are
// really missing underlying samples or returning underlying
// samples multiple times) because subqueries on counters are
// inherently problematic WRT counter reset handling, so we
// cannot really solve the problem for good. We only want to
// avoid problems that happen due to the explicitly set counter
// reset hints and go back to the behavior we already know from
// float samples.
for i, hp := range s.Histograms {
switch hp.H.CounterResetHint {
case histogram.NotCounterReset, histogram.CounterReset:
h := *hp.H // Shallow copy is sufficient, we only change CounterResetHint.
h.CounterResetHint = histogram.UnknownCounterReset
s.Histograms[i].H = &h
}
}
vs.Series = append(vs.Series, NewStorageSeries(s))
}
return ms, mat.TotalSamples(), ws