diff --git a/pkg/compactor/compactor.go b/pkg/compactor/compactor.go index 5473c3d6a7..19f34aeccd 100644 --- a/pkg/compactor/compactor.go +++ b/pkg/compactor/compactor.go @@ -321,6 +321,8 @@ type Compactor struct { ringSubservicesWatcher *services.FailureWatcher // Metrics. + CompactorStartDurationSeconds prometheus.Gauge + CompactorStopDurationSeconds prometheus.Gauge compactionRunsStarted prometheus.Counter compactionRunsInterrupted prometheus.Counter compactionRunsCompleted prometheus.Counter @@ -403,6 +405,14 @@ func newCompactor( blocksCompactorFactory: blocksCompactorFactory, allowedTenants: util.NewAllowedTenants(compactorCfg.EnabledTenants, compactorCfg.DisabledTenants), + CompactorStartDurationSeconds: promauto.With(registerer).NewGauge(prometheus.GaugeOpts{ + Name: "cortex_compactor_start_duration_seconds", + Help: "Time in seconds spent by compactor running start function", + }), + CompactorStopDurationSeconds: promauto.With(registerer).NewGauge(prometheus.GaugeOpts{ + Name: "cortex_compactor_stop_duration_seconds", + Help: "Time in seconds spent by compactor running stop function", + }), compactionRunsStarted: promauto.With(registerer).NewCounter(prometheus.CounterOpts{ Name: "cortex_compactor_runs_started_total", Help: "Total number of compaction runs started.", @@ -485,6 +495,11 @@ func newCompactor( // Start the compactor. func (c *Compactor) starting(ctx context.Context) error { + begin := time.Now() + defer func() { + c.CompactorStartDurationSeconds.Set(time.Since(begin).Seconds()) + }() + var err error // Create bucket client. @@ -581,6 +596,11 @@ func (c *Compactor) starting(ctx context.Context) error { } func (c *Compactor) stopping(_ error) error { + begin := time.Now() + defer func() { + c.CompactorStopDurationSeconds.Set(time.Since(begin).Seconds()) + }() + ctx := context.Background() services.StopAndAwaitTerminated(ctx, c.blocksCleaner) //nolint:errcheck