From c35d3a65bd8971950dce22dc66e86d6a814a69f4 Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Thu, 28 Sep 2017 12:49:34 +0530 Subject: [PATCH] Add levels to all log lines. Signed-off-by: Goutham Veeramachaneni --- compact.go | 3 ++- db.go | 11 ++++++----- head.go | 9 +++++---- wal.go | 15 ++++++++------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/compact.go b/compact.go index 17a4da041..bed6606c1 100644 --- a/compact.go +++ b/compact.go @@ -22,6 +22,7 @@ import ( "github.com/coreos/etcd/pkg/fileutil" "github.com/go-kit/kit/log" + "github.com/go-kit/kit/log/level" "github.com/oklog/ulid" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -356,7 +357,7 @@ func (w *instrumentedChunkWriter) WriteChunks(chunks ...ChunkMeta) error { // write creates a new block that is the union of the provided blocks into dir. // It cleans up all files of the old blocks after completing successfully. func (c *LeveledCompactor) write(dest string, meta *BlockMeta, blocks ...BlockReader) (err error) { - c.logger.Log("msg", "compact blocks", "count", len(blocks), "mint", meta.MinTime, "maxt", meta.MaxTime) + level.Info(c.logger).Log("msg", "compact blocks", "count", len(blocks), "mint", meta.MinTime, "maxt", meta.MaxTime) defer func(t time.Time) { if err != nil { diff --git a/db.go b/db.go index 23e4364f6..70b0297d7 100644 --- a/db.go +++ b/db.go @@ -32,6 +32,7 @@ import ( "github.com/coreos/etcd/pkg/fileutil" "github.com/go-kit/kit/log" + "github.com/go-kit/kit/log/level" "github.com/nightlyone/lockfile" "github.com/oklog/ulid" "github.com/pkg/errors" @@ -251,12 +252,12 @@ func (db *DB) run() { _, err1 := db.retentionCutoff() if err1 != nil { - db.logger.Log("msg", "retention cutoff failed", "err", err1) + level.Error(db.logger).Log("msg", "retention cutoff failed", "err", err1) } _, err2 := db.compact() if err2 != nil { - db.logger.Log("msg", "compaction failed", "err", err2) + level.Error(db.logger).Log("msg", "compaction failed", "err", err2) } if err1 != nil || err2 != nil { @@ -558,7 +559,7 @@ func (db *DB) DisableCompactions() { defer db.cmtx.Unlock() db.compactionsEnabled = false - db.logger.Log("msg", "compactions disabled") + level.Info(db.logger).Log("msg", "compactions disabled") } // EnableCompactions enables compactions. @@ -567,7 +568,7 @@ func (db *DB) EnableCompactions() { defer db.cmtx.Unlock() db.compactionsEnabled = true - db.logger.Log("msg", "compactions enabled") + level.Info(db.logger).Log("msg", "compactions enabled") } // Snapshot writes the current data to the directory. @@ -586,7 +587,7 @@ func (db *DB) Snapshot(dir string) error { defer db.mtx.RUnlock() for _, b := range db.blocks { - db.logger.Log("msg", "snapshotting block", "block", b) + level.Info(db.logger).Log("msg", "snapshotting block", "block", b) if err := b.Snapshot(dir); err != nil { return errors.Wrap(err, "error snapshotting headblock") diff --git a/head.go b/head.go index 72973c46c..00f51e007 100644 --- a/head.go +++ b/head.go @@ -21,6 +21,7 @@ import ( "time" "github.com/go-kit/kit/log" + "github.com/go-kit/kit/log/level" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/tsdb/chunks" @@ -235,7 +236,7 @@ func (h *Head) ReadWAL() error { } if unknownRefs > 0 { - h.logger.Log("msg", "unknown series references in WAL samples", "count", unknownRefs) + level.Warn(h.logger).Log("msg", "unknown series references in WAL samples", "count", unknownRefs) } if err := r.Read(seriesFunc, samplesFunc, deletesFunc); err != nil { @@ -270,7 +271,7 @@ func (h *Head) Truncate(mint int64) error { start := time.Now() h.gc() - h.logger.Log("msg", "head GC completed", "duration", time.Since(start)) + level.Info(h.logger).Log("msg", "head GC completed", "duration", time.Since(start)) h.metrics.gcDuration.Observe(time.Since(start).Seconds()) start = time.Now() @@ -279,9 +280,9 @@ func (h *Head) Truncate(mint int64) error { return h.series.getByID(id) != nil } if err := h.wal.Truncate(mint, keep); err == nil { - h.logger.Log("msg", "WAL truncation completed", "duration", time.Since(start)) + level.Info(h.logger).Log("msg", "WAL truncation completed", "duration", time.Since(start)) } else { - h.logger.Log("msg", "WAL truncation failed", "err", err, "duration", time.Since(start)) + level.Error(h.logger).Log("msg", "WAL truncation failed", "err", err, "duration", time.Since(start)) } h.metrics.walTruncateDuration.Observe(time.Since(start).Seconds()) diff --git a/wal.go b/wal.go index c52bca86d..2f6bb35bc 100644 --- a/wal.go +++ b/wal.go @@ -29,6 +29,7 @@ import ( "github.com/coreos/etcd/pkg/fileutil" "github.com/go-kit/kit/log" + "github.com/go-kit/kit/log/level" "github.com/pkg/errors" "github.com/prometheus/tsdb/labels" ) @@ -228,7 +229,7 @@ func (r *repairingWALReader) Read(series SeriesCB, samples SamplesCB, deletes De // truncate the WAL after the last valid entry. func (w *SegmentWAL) truncate(err error, file int, lastOffset int64) error { - w.logger.Log("msg", "WAL corruption detected; truncating", + level.Error(w.logger).Log("msg", "WAL corruption detected; truncating", "err", err, "file", w.files[file].Name(), "pos", lastOffset) // Close and delete all files after the current one. @@ -527,16 +528,16 @@ func (w *SegmentWAL) cut() error { go func() { off, err := hf.Seek(0, os.SEEK_CUR) if err != nil { - w.logger.Log("msg", "finish old segment", "segment", hf.Name(), "err", err) + level.Error(w.logger).Log("msg", "finish old segment", "segment", hf.Name(), "err", err) } if err := hf.Truncate(off); err != nil { - w.logger.Log("msg", "finish old segment", "segment", hf.Name(), "err", err) + level.Error(w.logger).Log("msg", "finish old segment", "segment", hf.Name(), "err", err) } if err := hf.Sync(); err != nil { - w.logger.Log("msg", "finish old segment", "segment", hf.Name(), "err", err) + level.Error(w.logger).Log("msg", "finish old segment", "segment", hf.Name(), "err", err) } if err := hf.Close(); err != nil { - w.logger.Log("msg", "finish old segment", "segment", hf.Name(), "err", err) + level.Error(w.logger).Log("msg", "finish old segment", "segment", hf.Name(), "err", err) } }() } @@ -552,7 +553,7 @@ func (w *SegmentWAL) cut() error { go func() { if err = w.dirFile.Sync(); err != nil { - w.logger.Log("msg", "sync WAL directory", "err", err) + level.Error(w.logger).Log("msg", "sync WAL directory", "err", err) } }() @@ -629,7 +630,7 @@ func (w *SegmentWAL) run(interval time.Duration) { return case <-tick: if err := w.Sync(); err != nil { - w.logger.Log("msg", "sync failed", "err", err) + level.Error(w.logger).Log("msg", "sync failed", "err", err) } } }