From 0cef66b12a0a0e2d9d84cd8e9781250a68d8290f Mon Sep 17 00:00:00 2001 From: beorn7 Date: Thu, 4 Sep 2025 13:45:24 +0200 Subject: [PATCH] promql: Forget lastFH in HistogramStatsIterator after Seek After an effective Seek, the lastFH isn't the lastFH anymore, so we should nil it out. In practice, this should only matter is sub-queries, because we are otherwise not interested in a counter reset of the first sample returned after a Seek. Sub-queries, on the other hand, always do their own counter reset detection. (For that, they would prefer to see the whole histogram, so that's another problem for another commit.) Signed-off-by: beorn7 --- promql/histogram_stats_iterator.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/promql/histogram_stats_iterator.go b/promql/histogram_stats_iterator.go index bb8c610964..408b3cfa6d 100644 --- a/promql/histogram_stats_iterator.go +++ b/promql/histogram_stats_iterator.go @@ -61,6 +61,11 @@ func (hsi *HistogramStatsIterator) Next() chunkenc.ValueType { // Seek mostly relays to the underlying iterator, but changes a ValHistogram // return into a ValFloatHistogram return. func (hsi *HistogramStatsIterator) Seek(t int64) chunkenc.ValueType { + // If the Seek is going to move the iterator, we have to forget the + // lastFH. + if t > hsi.AtT() { + hsi.lastFH = nil + } vt := hsi.Iterator.Seek(t) if vt == chunkenc.ValHistogram { return chunkenc.ValFloatHistogram