From f9f7ea807a6b36e57cb7e7d2ed1a56e655110475 Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Wed, 21 Oct 2020 15:21:59 +0530 Subject: [PATCH] add a metric in compactor to record timestamp of last successful run --- pkg/storage/stores/shipper/compactor/compactor.go | 1 + pkg/storage/stores/shipper/compactor/metrics.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/pkg/storage/stores/shipper/compactor/compactor.go b/pkg/storage/stores/shipper/compactor/compactor.go index 6a18b696b472b..752f77f2e4f89 100644 --- a/pkg/storage/stores/shipper/compactor/compactor.go +++ b/pkg/storage/stores/shipper/compactor/compactor.go @@ -95,6 +95,7 @@ func (c *Compactor) Run(ctx context.Context) error { c.metrics.compactTablesOperationTotal.WithLabelValues(status).Inc() if status == statusSuccess { c.metrics.compactTablesOperationDurationSeconds.Set(time.Since(start).Seconds()) + c.metrics.compactTablesOperationLastSuccess.SetToCurrentTime() } }() diff --git a/pkg/storage/stores/shipper/compactor/metrics.go b/pkg/storage/stores/shipper/compactor/metrics.go index d190f5eabf09a..fdb304b7897b9 100644 --- a/pkg/storage/stores/shipper/compactor/metrics.go +++ b/pkg/storage/stores/shipper/compactor/metrics.go @@ -13,6 +13,7 @@ const ( type metrics struct { compactTablesOperationTotal *prometheus.CounterVec compactTablesOperationDurationSeconds prometheus.Gauge + compactTablesOperationLastSuccess prometheus.Gauge } func newMetrics(r prometheus.Registerer) *metrics { @@ -27,6 +28,11 @@ func newMetrics(r prometheus.Registerer) *metrics { Name: "compact_tables_operation_duration_seconds", Help: "Time (in seconds) spent in compacting all the tables", }), + compactTablesOperationLastSuccess: promauto.With(r).NewGauge(prometheus.GaugeOpts{ + Namespace: "loki_boltdb_shipper", + Name: "compact_tables_operation_last_successful_run_timestamp_seconds", + Help: "Unix timestamp of the last successful compaction run", + }), } return &m