Skip to content

Add a metric for the compaction interval config value. #4040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* [ENHANCEMENT] Put metric before label value in the "label value too long" error message. #4018
* [ENHANCEMENT] Allow use of `y|w|d` suffixes for duration related limits and per-tenant limits. #4044
* [ENHANCEMENT] Query-frontend: Small optimization on top of PR #3968 to avoid unnecessary Extents merging. #4026
* [ENHANCEMENT] Add a metric `cortex_compactor_compaction_interval_seconds` for the compaction interval config value. #4040
* [BUGFIX] Ruler-API: fix bug where `/api/v1/rules/<namespace>/<group_name>` endpoint return `400` instead of `404`. #4013
* [BUGFIX] Distributor: reverted changes done to rate limiting in #3825. #3948
* [BUGFIX] Ingester: Fix race condition when opening and closing tsdb concurrently. #3959
Expand Down
8 changes: 8 additions & 0 deletions pkg/compactor/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ type Compactor struct {
compactionRunSkippedTenants prometheus.Gauge
compactionRunSucceededTenants prometheus.Gauge
compactionRunFailedTenants prometheus.Gauge
compactionRunInterval prometheus.Gauge
blocksMarkedForDeletion prometheus.Counter
garbageCollectedBlocks prometheus.Counter

Expand Down Expand Up @@ -304,6 +305,10 @@ func newCompactor(
Name: "cortex_compactor_tenants_processing_failed",
Help: "Number of tenants failed processing during the current compaction run. Reset to 0 when compactor is idle.",
}),
compactionRunInterval: promauto.With(registerer).NewGauge(prometheus.GaugeOpts{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be a good candidate for a GaugeFunc metric?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I supposed it would be if we currently, or plan to, support live reloading of this config value (and others obviously) on the compactor. If not, would GaugeFunc get us anything over the way I'm doing it here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No big preference, but I would set the metric value here in newCompactor() and not at the end of starting(). If I'm not missing anything, metrics can be scraped while starting as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No preference here either, I don't think a GaugeFunc would buy you anything beyond the config reload thing you mentioned. My thinking was really just to remove the call to set the value of the gauge which seemed a bit far away from the place the metric was defined 👍

Name: "cortex_compactor_compaction_interval_seconds",
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.",
}),
blocksMarkedForDeletion: promauto.With(registerer).NewCounter(prometheus.CounterOpts{
Name: blocksMarkedForDeletionName,
Help: blocksMarkedForDeletionHelp,
Expand Down Expand Up @@ -335,6 +340,9 @@ func newCompactor(

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

// The last successful compaction run metric is exposed as seconds since epoch, so we need to use seconds for this metric.
c.compactionRunInterval.Set(c.compactorCfg.CompactionInterval.Seconds())

return c, nil
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/compactor/compactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func TestCompactor_ShouldDoNothingOnNoUserBlocks(t *testing.T) {
// No user blocks stored in the bucket.
bucketClient := &bucket.ClientMock{}
bucketClient.MockIter("", []string{}, nil)

c, _, _, logs, registry := prepare(t, prepareConfig(), bucketClient)
cfg := prepareConfig()
c, _, _, logs, registry := prepare(t, cfg, bucketClient)
require.NoError(t, services.StartAndAwaitRunning(context.Background(), c))

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

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

assert.Equal(t, prom_testutil.ToFloat64(c.compactionRunInterval), cfg.CompactionInterval.Seconds())

assert.Equal(t, []string{
`level=info component=cleaner msg="started blocks cleanup and maintenance"`,
`level=info component=cleaner msg="successfully completed blocks cleanup and maintenance"`,
Expand Down