From cef1025ea80a1a901cf0e2bbe7b589563dd16a8e Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Fri, 15 Mar 2024 10:11:04 +0100 Subject: [PATCH] tsdb/wlog.Checkpoint: Fix counting of histogram samples Signed-off-by: Arve Knudsen --- tsdb/wlog/checkpoint.go | 4 ++-- tsdb/wlog/checkpoint_test.go | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tsdb/wlog/checkpoint.go b/tsdb/wlog/checkpoint.go index 4ad1bb236..5491d9718 100644 --- a/tsdb/wlog/checkpoint.go +++ b/tsdb/wlog/checkpoint.go @@ -224,8 +224,8 @@ func Checkpoint(logger log.Logger, w *WL, from, to int, keep func(id chunks.Head if len(repl) > 0 { buf = enc.HistogramSamples(repl, buf) } - stats.TotalSamples += len(samples) - stats.DroppedSamples += len(samples) - len(repl) + stats.TotalSamples += len(histogramSamples) + stats.DroppedSamples += len(histogramSamples) - len(repl) case record.Tombstones: tstones, err = dec.Tombstones(rec, tstones) diff --git a/tsdb/wlog/checkpoint_test.go b/tsdb/wlog/checkpoint_test.go index 142a5a9d4..0d2217176 100644 --- a/tsdb/wlog/checkpoint_test.go +++ b/tsdb/wlog/checkpoint_test.go @@ -220,12 +220,14 @@ func TestCheckpoint(t *testing.T) { } require.NoError(t, w.Close()) - _, err = Checkpoint(log.NewNopLogger(), w, 100, 106, func(x chunks.HeadSeriesRef) bool { + stats, err := Checkpoint(log.NewNopLogger(), w, 100, 106, func(x chunks.HeadSeriesRef) bool { return x%2 == 0 }, last/2) require.NoError(t, err) require.NoError(t, w.Truncate(107)) require.NoError(t, DeleteCheckpoints(w.Dir(), 106)) + require.Equal(t, histogramsInWAL+samplesInWAL, stats.TotalSamples) + require.Greater(t, stats.DroppedSamples, 0) // Only the new checkpoint should be left. files, err := os.ReadDir(dir)