Add levels to all log lines.

Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
Goutham Veeramachaneni 2017-09-28 12:49:34 +05:30
parent 87c01dd5fb
commit c35d3a65bd
No known key found for this signature in database
GPG Key ID: F1C217E8E9023CAD
4 changed files with 21 additions and 17 deletions

View File

@ -22,6 +22,7 @@ import (
"github.com/coreos/etcd/pkg/fileutil" "github.com/coreos/etcd/pkg/fileutil"
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/oklog/ulid" "github.com/oklog/ulid"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus" "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. // 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. // It cleans up all files of the old blocks after completing successfully.
func (c *LeveledCompactor) write(dest string, meta *BlockMeta, blocks ...BlockReader) (err error) { 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) { defer func(t time.Time) {
if err != nil { if err != nil {

11
db.go
View File

@ -32,6 +32,7 @@ import (
"github.com/coreos/etcd/pkg/fileutil" "github.com/coreos/etcd/pkg/fileutil"
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/nightlyone/lockfile" "github.com/nightlyone/lockfile"
"github.com/oklog/ulid" "github.com/oklog/ulid"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -251,12 +252,12 @@ func (db *DB) run() {
_, err1 := db.retentionCutoff() _, err1 := db.retentionCutoff()
if err1 != nil { 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() _, err2 := db.compact()
if err2 != nil { 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 { if err1 != nil || err2 != nil {
@ -558,7 +559,7 @@ func (db *DB) DisableCompactions() {
defer db.cmtx.Unlock() defer db.cmtx.Unlock()
db.compactionsEnabled = false db.compactionsEnabled = false
db.logger.Log("msg", "compactions disabled") level.Info(db.logger).Log("msg", "compactions disabled")
} }
// EnableCompactions enables compactions. // EnableCompactions enables compactions.
@ -567,7 +568,7 @@ func (db *DB) EnableCompactions() {
defer db.cmtx.Unlock() defer db.cmtx.Unlock()
db.compactionsEnabled = true 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. // Snapshot writes the current data to the directory.
@ -586,7 +587,7 @@ func (db *DB) Snapshot(dir string) error {
defer db.mtx.RUnlock() defer db.mtx.RUnlock()
for _, b := range db.blocks { 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 { if err := b.Snapshot(dir); err != nil {
return errors.Wrap(err, "error snapshotting headblock") return errors.Wrap(err, "error snapshotting headblock")

View File

@ -21,6 +21,7 @@ import (
"time" "time"
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/tsdb/chunks" "github.com/prometheus/tsdb/chunks"
@ -235,7 +236,7 @@ func (h *Head) ReadWAL() error {
} }
if unknownRefs > 0 { 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 { if err := r.Read(seriesFunc, samplesFunc, deletesFunc); err != nil {
@ -270,7 +271,7 @@ func (h *Head) Truncate(mint int64) error {
start := time.Now() start := time.Now()
h.gc() 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()) h.metrics.gcDuration.Observe(time.Since(start).Seconds())
start = time.Now() start = time.Now()
@ -279,9 +280,9 @@ func (h *Head) Truncate(mint int64) error {
return h.series.getByID(id) != nil return h.series.getByID(id) != nil
} }
if err := h.wal.Truncate(mint, keep); err == 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 { } 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()) h.metrics.walTruncateDuration.Observe(time.Since(start).Seconds())

15
wal.go
View File

@ -29,6 +29,7 @@ import (
"github.com/coreos/etcd/pkg/fileutil" "github.com/coreos/etcd/pkg/fileutil"
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prometheus/tsdb/labels" "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. // truncate the WAL after the last valid entry.
func (w *SegmentWAL) truncate(err error, file int, lastOffset int64) error { 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) "err", err, "file", w.files[file].Name(), "pos", lastOffset)
// Close and delete all files after the current one. // Close and delete all files after the current one.
@ -527,16 +528,16 @@ func (w *SegmentWAL) cut() error {
go func() { go func() {
off, err := hf.Seek(0, os.SEEK_CUR) off, err := hf.Seek(0, os.SEEK_CUR)
if err != nil { 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 { 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 { 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 { 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() { go func() {
if err = w.dirFile.Sync(); err != nil { 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 return
case <-tick: case <-tick:
if err := w.Sync(); err != nil { if err := w.Sync(); err != nil {
w.logger.Log("msg", "sync failed", "err", err) level.Error(w.logger).Log("msg", "sync failed", "err", err)
} }
} }
} }