Skip to content
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

Increment cortex_compactor_runs_failed_total if compactor fails to compact a single tenant #4094

Merged
merged 1 commit into from
Apr 21, 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 @@ -56,6 +56,7 @@
* [BUGFIX] Ruler: Rule group limit enforcement should now allow the same number of rules in a group as the limit. #3615
* [BUGFIX] Frontend, Query-scheduler: allow querier to notify about shutdown without providing any authentication. #4066
* [BUGFIX] Querier: fixed race condition causing queries to fail right after querier startup with the "empty ring" error. #4068
* [BUGFIX] Compactor: Increment `cortex_compactor_runs_failed_total` if compactor failed compact a single tenant. #4094

## Blocksconvert

Expand Down
4 changes: 3 additions & 1 deletion pkg/compactor/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,12 @@ func (c *Compactor) running(ctx context.Context) error {

func (c *Compactor) compactUsers(ctx context.Context) {
succeeded := false
compactionErrorCount := 0

c.compactionRunsStarted.Inc()

defer func() {
if succeeded {
if succeeded && compactionErrorCount == 0 {
c.compactionRunsCompleted.Inc()
c.compactionRunsLastSuccess.SetToCurrentTime()
} else {
Expand Down Expand Up @@ -526,6 +527,7 @@ func (c *Compactor) compactUsers(ctx context.Context) {

if err = c.compactUserWithRetries(ctx, userID); err != nil {
c.compactionRunFailedTenants.Inc()
compactionErrorCount++
level.Error(c.logger).Log("msg", "failed to compact user blocks", "user", userID, "err", err)
continue
}
Expand Down
44 changes: 44 additions & 0 deletions pkg/compactor/compactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,50 @@ func TestCompactor_ShouldRetryCompactionOnFailureWhileDiscoveringUsersFromBucket
))
}

func TestCompactor_ShouldIncrementCompactionErrorIfFailedToCompactASingleTenant(t *testing.T) {
t.Parallel()

userID := "test-user"
bucketClient := &bucket.ClientMock{}
bucketClient.MockIter("", []string{userID}, nil)
bucketClient.MockIter(userID+"/", []string{userID + "/01DTVP434PA9VFXSW2JKB3392D"}, nil)
bucketClient.MockIter(userID+"/markers/", nil, nil)
bucketClient.MockExists(path.Join(userID, cortex_tsdb.TenantDeletionMarkPath), false, nil)
bucketClient.MockGet(userID+"/01DTVP434PA9VFXSW2JKB3392D/meta.json", mockBlockMetaJSON("01DTVP434PA9VFXSW2JKB3392D"), nil)
bucketClient.MockGet(userID+"/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json", "", nil)
bucketClient.MockGet(userID+"/bucket-index.json.gz", "", nil)
bucketClient.MockUpload(userID+"/bucket-index.json.gz", nil)

c, _, tsdbPlannerMock, _, registry := prepare(t, prepareConfig(), bucketClient)
tsdbPlannerMock.On("Plan", mock.Anything, mock.Anything).Return([]*metadata.Meta{}, errors.New("Failed to plan"))
require.NoError(t, services.StartAndAwaitRunning(context.Background(), c))

// Wait until all retry attempts have completed.
cortex_testutil.Poll(t, time.Second, 1.0, func() interface{} {
return prom_testutil.ToFloat64(c.compactionRunsFailed)
})

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

assert.NoError(t, prom_testutil.GatherAndCompare(registry, strings.NewReader(`
# TYPE cortex_compactor_runs_started_total counter
# HELP cortex_compactor_runs_started_total Total number of compaction runs started.
cortex_compactor_runs_started_total 1

# TYPE cortex_compactor_runs_completed_total counter
# HELP cortex_compactor_runs_completed_total Total number of compaction runs successfully completed.
cortex_compactor_runs_completed_total 0

# TYPE cortex_compactor_runs_failed_total counter
# HELP cortex_compactor_runs_failed_total Total number of compaction runs failed.
cortex_compactor_runs_failed_total 1
`),
"cortex_compactor_runs_started_total",
"cortex_compactor_runs_completed_total",
"cortex_compactor_runs_failed_total",
))
}

func TestCompactor_ShouldIterateOverUsersAndRunCompaction(t *testing.T) {
t.Parallel()

Expand Down