Restore stale series count from chunk snapshots

Signed-off-by: Ganesh Vernekar <ganesh.vernekar@reddit.com>
This commit is contained in:
Ganesh Vernekar 2025-08-06 16:22:58 -07:00 committed by SuperQ
parent c3789ff547
commit b98cc631a2
No known key found for this signature in database
GPG Key ID: C646B23C9E3245F1
2 changed files with 11 additions and 1 deletions

View File

@ -6988,6 +6988,10 @@ func TestHead_NumStaleSeries(t *testing.T) {
appendFloatHistogram(series5, 400, staleFH)
restartHeadAndVerifySeriesCounts(3, 5)
// This will test restarting with snapshot.
head.opts.EnableMemorySnapshotOnShutdown = true
restartHeadAndVerifySeriesCounts(3, 5)
// Test garbage collection behavior - stale series should be decremented when GC'd.
// Force a garbage collection by truncating old data.
require.NoError(t, head.Truncate(300))

View File

@ -16,7 +16,6 @@ package tsdb
import (
"errors"
"fmt"
"github.com/prometheus/prometheus/model/value"
"maps"
"math"
"os"
@ -33,6 +32,7 @@ import (
"github.com/prometheus/prometheus/model/histogram"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/metadata"
"github.com/prometheus/prometheus/model/value"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/tsdb/chunkenc"
"github.com/prometheus/prometheus/tsdb/chunks"
@ -1607,6 +1607,12 @@ func (h *Head) loadChunkSnapshot() (int, int, map[chunks.HeadSeriesRef]*memSerie
series.lastHistogramValue = csr.lastHistogramValue
series.lastFloatHistogramValue = csr.lastFloatHistogramValue
if value.IsStaleNaN(series.lastValue) ||
(series.lastHistogramValue != nil && value.IsStaleNaN(series.lastHistogramValue.Sum)) ||
(series.lastFloatHistogramValue != nil && value.IsStaleNaN(series.lastFloatHistogramValue.Sum)) {
h.numStaleSeries.Inc()
}
app, err := series.headChunks.chunk.Appender()
if err != nil {
errChan <- err