Skip to content

Commit c2cb4e1

Browse files
authored
Add a metric for the compaction interval config value. (#4040)
* Add a metric for the compaction interval config value. Signed-off-by: Callum Styan <callumstyan@gmail.com> * Update compaction interval metric name and where the metric value is set based on review comments. Signed-off-by: Callum Styan <callumstyan@gmail.com> * Add changelog entry for new metric. Signed-off-by: Callum Styan <callumstyan@gmail.com>
1 parent f2194ff commit c2cb4e1

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* [ENHANCEMENT] Put metric before label value in the "label value too long" error message. #4018
2727
* [ENHANCEMENT] Allow use of `y|w|d` suffixes for duration related limits and per-tenant limits. #4044
2828
* [ENHANCEMENT] Query-frontend: Small optimization on top of PR #3968 to avoid unnecessary Extents merging. #4026
29+
* [ENHANCEMENT] Add a metric `cortex_compactor_compaction_interval_seconds` for the compaction interval config value. #4040
2930
* [BUGFIX] Ruler-API: fix bug where `/api/v1/rules/<namespace>/<group_name>` endpoint return `400` instead of `404`. #4013
3031
* [BUGFIX] Distributor: reverted changes done to rate limiting in #3825. #3948
3132
* [BUGFIX] Ingester: Fix race condition when opening and closing tsdb concurrently. #3959

pkg/compactor/compactor.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ type Compactor struct {
219219
compactionRunSkippedTenants prometheus.Gauge
220220
compactionRunSucceededTenants prometheus.Gauge
221221
compactionRunFailedTenants prometheus.Gauge
222+
compactionRunInterval prometheus.Gauge
222223
blocksMarkedForDeletion prometheus.Counter
223224
garbageCollectedBlocks prometheus.Counter
224225

@@ -304,6 +305,10 @@ func newCompactor(
304305
Name: "cortex_compactor_tenants_processing_failed",
305306
Help: "Number of tenants failed processing during the current compaction run. Reset to 0 when compactor is idle.",
306307
}),
308+
compactionRunInterval: promauto.With(registerer).NewGauge(prometheus.GaugeOpts{
309+
Name: "cortex_compactor_compaction_interval_seconds",
310+
Help: "The configured interval on which compaction is run in seconds. Useful when compared to the last successful run metric to accurately detect multiple failed compaction runs.",
311+
}),
307312
blocksMarkedForDeletion: promauto.With(registerer).NewCounter(prometheus.CounterOpts{
308313
Name: blocksMarkedForDeletionName,
309314
Help: blocksMarkedForDeletionHelp,
@@ -335,6 +340,9 @@ func newCompactor(
335340

336341
c.Service = services.NewBasicService(c.starting, c.running, c.stopping)
337342

343+
// The last successful compaction run metric is exposed as seconds since epoch, so we need to use seconds for this metric.
344+
c.compactionRunInterval.Set(c.compactorCfg.CompactionInterval.Seconds())
345+
338346
return c, nil
339347
}
340348

pkg/compactor/compactor_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ func TestCompactor_ShouldDoNothingOnNoUserBlocks(t *testing.T) {
129129
// No user blocks stored in the bucket.
130130
bucketClient := &bucket.ClientMock{}
131131
bucketClient.MockIter("", []string{}, nil)
132-
133-
c, _, _, logs, registry := prepare(t, prepareConfig(), bucketClient)
132+
cfg := prepareConfig()
133+
c, _, _, logs, registry := prepare(t, cfg, bucketClient)
134134
require.NoError(t, services.StartAndAwaitRunning(context.Background(), c))
135135

136136
// Wait until a run has completed.
@@ -140,6 +140,8 @@ func TestCompactor_ShouldDoNothingOnNoUserBlocks(t *testing.T) {
140140

141141
require.NoError(t, services.StopAndAwaitTerminated(context.Background(), c))
142142

143+
assert.Equal(t, prom_testutil.ToFloat64(c.compactionRunInterval), cfg.CompactionInterval.Seconds())
144+
143145
assert.Equal(t, []string{
144146
`level=info component=cleaner msg="started blocks cleanup and maintenance"`,
145147
`level=info component=cleaner msg="successfully completed blocks cleanup and maintenance"`,

0 commit comments

Comments
 (0)