From 520ab7dc5374d6dd17ba194ccb67aae97ec063c0 Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Tue, 18 Dec 2018 13:24:56 +0300 Subject: [PATCH] re-add the missing prometheus_tsdb_wal_corruptions_total (#473) closes https://github.com/prometheus/tsdb/issues/471 after implementing the new WAL this metric was missing so adding it again. Also added it in a test to make sure it works as expected. Signed-off-by: Krasi Georgiev --- head.go | 8 +++++++- head_test.go | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/head.go b/head.go index a3e23c03a..eba1f2dc4 100644 --- a/head.go +++ b/head.go @@ -89,6 +89,7 @@ type headMetrics struct { maxTime prometheus.GaugeFunc samplesAppended prometheus.Counter walTruncateDuration prometheus.Summary + walCorruptionsTotal prometheus.Counter headTruncateFail prometheus.Counter headTruncateTotal prometheus.Counter checkpointDeleteFail prometheus.Counter @@ -152,6 +153,10 @@ func newHeadMetrics(h *Head, r prometheus.Registerer) *headMetrics { Name: "prometheus_tsdb_wal_truncate_duration_seconds", Help: "Duration of WAL truncation.", }) + m.walCorruptionsTotal = prometheus.NewCounter(prometheus.CounterOpts{ + Name: "prometheus_tsdb_wal_corruptions_total", + Help: "Total number of WAL corruptions.", + }) m.samplesAppended = prometheus.NewCounter(prometheus.CounterOpts{ Name: "prometheus_tsdb_head_samples_appended_total", Help: "Total number of appended samples.", @@ -195,6 +200,7 @@ func newHeadMetrics(h *Head, r prometheus.Registerer) *headMetrics { m.maxTime, m.gcDuration, m.walTruncateDuration, + m.walCorruptionsTotal, m.samplesAppended, m.headTruncateFail, m.headTruncateTotal, @@ -480,10 +486,10 @@ func (h *Head) Init(minValidTime int64) error { return nil } level.Warn(h.logger).Log("msg", "encountered WAL error, attempting repair", "err", err) + h.metrics.walCorruptionsTotal.Inc() if err := h.wal.Repair(err); err != nil { return errors.Wrap(err, "repair corrupted WAL") } - return nil } diff --git a/head_test.go b/head_test.go index 9e56319e8..ca2c49365 100644 --- a/head_test.go +++ b/head_test.go @@ -22,6 +22,7 @@ import ( "sort" "testing" + prom_testutil "github.com/prometheus/client_golang/prometheus/testutil" "github.com/prometheus/tsdb/chunkenc" "github.com/prometheus/tsdb/chunks" "github.com/prometheus/tsdb/index" @@ -927,7 +928,9 @@ func TestWalRepair(t *testing.T) { h, err := NewHead(nil, nil, w, 1) testutil.Ok(t, err) + testutil.Equals(t, 0.0, prom_testutil.ToFloat64(h.metrics.walCorruptionsTotal)) testutil.Ok(t, h.Init(math.MinInt64)) + testutil.Equals(t, 1.0, prom_testutil.ToFloat64(h.metrics.walCorruptionsTotal)) sr, err := wal.NewSegmentsReader(dir) testutil.Ok(t, err)