diff --git a/tsdb/db_test.go b/tsdb/db_test.go index 6b16203ef..f68c6c40a 100644 --- a/tsdb/db_test.go +++ b/tsdb/db_test.go @@ -1169,7 +1169,7 @@ func TestSizeRetention(t *testing.T) { // Create a WAL checkpoint, and compare sizes. first, last, err := db.Head().wal.Segments() testutil.Ok(t, err) - _, err = wal.Checkpoint(db.Head().wal, first, last-1, func(x uint64) bool { return false }, 0) + _, err = wal.Checkpoint(log.NewNopLogger(), db.Head().wal, first, last-1, func(x uint64) bool { return false }, 0) testutil.Ok(t, err) blockSize = int64(prom_testutil.ToFloat64(db.metrics.blocksBytes)) // Use the actual internal metrics. walSize, err = db.Head().wal.Size() diff --git a/tsdb/head.go b/tsdb/head.go index de052571c..4269d3f8a 100644 --- a/tsdb/head.go +++ b/tsdb/head.go @@ -835,7 +835,7 @@ func (h *Head) Truncate(mint int64) (err error) { return ok } h.metrics.checkpointCreationTotal.Inc() - if _, err = wal.Checkpoint(h.wal, first, last, keep, mint); err != nil { + if _, err = wal.Checkpoint(h.logger, h.wal, first, last, keep, mint); err != nil { h.metrics.checkpointCreationFail.Inc() if _, ok := errors.Cause(err).(*wal.CorruptionErr); ok { h.metrics.walCorruptionsTotal.Inc() diff --git a/tsdb/wal/checkpoint.go b/tsdb/wal/checkpoint.go index d205c6121..e8aa4326d 100644 --- a/tsdb/wal/checkpoint.go +++ b/tsdb/wal/checkpoint.go @@ -25,6 +25,8 @@ import ( "strconv" "strings" + "github.com/go-kit/kit/log" + "github.com/go-kit/kit/log/level" "github.com/pkg/errors" tsdb_errors "github.com/prometheus/prometheus/tsdb/errors" "github.com/prometheus/prometheus/tsdb/fileutil" @@ -87,10 +89,12 @@ const checkpointPrefix = "checkpoint." // segmented format as the original WAL itself. // This makes it easy to read it through the WAL package and concatenate // it with the original WAL. -func Checkpoint(w *WAL, from, to int, keep func(id uint64) bool, mint int64) (*CheckpointStats, error) { +func Checkpoint(logger log.Logger, w *WAL, from, to int, keep func(id uint64) bool, mint int64) (*CheckpointStats, error) { stats := &CheckpointStats{} var sgmReader io.ReadCloser + level.Info(logger).Log("msg", "Creating checkpoint", "from_segment", from, "to_segment", to, "mint", mint) + { var sgmRange []SegmentRange diff --git a/tsdb/wal/checkpoint_test.go b/tsdb/wal/checkpoint_test.go index 3930b548b..327de1d7c 100644 --- a/tsdb/wal/checkpoint_test.go +++ b/tsdb/wal/checkpoint_test.go @@ -16,6 +16,7 @@ package wal import ( "fmt" + "github.com/go-kit/kit/log" "io/ioutil" "os" "path/filepath" @@ -177,7 +178,7 @@ func TestCheckpoint(t *testing.T) { } testutil.Ok(t, w.Close()) - _, err = Checkpoint(w, 100, 106, func(x uint64) bool { + _, err = Checkpoint(log.NewNopLogger(), w, 100, 106, func(x uint64) bool { return x%2 == 0 }, last/2) testutil.Ok(t, err) @@ -236,7 +237,7 @@ func TestCheckpointNoTmpFolderAfterError(t *testing.T) { w.Close() // Run the checkpoint and since the wal contains an invalid records this should return an error. - _, err = Checkpoint(w, 0, 1, nil, 0) + _, err = Checkpoint(log.NewNopLogger(), w, 0, 1, nil, 0) testutil.NotOk(t, err) // Walk the wal dir to make sure there are no tmp folder left behind after the error. diff --git a/tsdb/wal/watcher_test.go b/tsdb/wal/watcher_test.go index 482d96551..e4615eff4 100644 --- a/tsdb/wal/watcher_test.go +++ b/tsdb/wal/watcher_test.go @@ -14,6 +14,7 @@ package wal import ( "fmt" + "github.com/go-kit/kit/log" "io/ioutil" "math/rand" "os" @@ -275,7 +276,7 @@ func TestReadToEndWithCheckpoint(t *testing.T) { } } - Checkpoint(w, 0, 1, func(x uint64) bool { return true }, 0) + Checkpoint(log.NewNopLogger(), w, 0, 1, func(x uint64) bool { return true }, 0) w.Truncate(1) // Write more records after checkpointing. @@ -360,7 +361,7 @@ func TestReadCheckpoint(t *testing.T) { testutil.Ok(t, w.Log(sample)) } } - Checkpoint(w, 30, 31, func(x uint64) bool { return true }, 0) + Checkpoint(log.NewNopLogger(), w, 30, 31, func(x uint64) bool { return true }, 0) w.Truncate(32) // Start read after checkpoint, no more data written. @@ -520,7 +521,7 @@ func TestCheckpointSeriesReset(t *testing.T) { }) testutil.Equals(t, seriesCount, wt.checkNumLabels()) - _, err = Checkpoint(w, 2, 4, func(x uint64) bool { return true }, 0) + _, err = Checkpoint(log.NewNopLogger(), w, 2, 4, func(x uint64) bool { return true }, 0) testutil.Ok(t, err) err = w.Truncate(5)