Skip to content

Commit

Permalink
Add additional metrics to record compactor start and stop duration in…
Browse files Browse the repository at this point in the history
… seconds

Signed-off-by: Alex Le <[email protected]>
  • Loading branch information
alexqyle committed Nov 28, 2023
1 parent 7f8d194 commit 89fb608
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/compactor/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 89fb608

Please sign in to comment.