Skip to content

Commit d62d8c7

Browse files
committed
Increment cortex_compactor_runs_failed_total if compactor fails to compact a single tenant
Signed-off-by: Roy Chiang <[email protected]>
1 parent 6660a5e commit d62d8c7

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
* [BUGFIX] Ruler: Rule group limit enforcement should now allow the same number of rules in a group as the limit. #3615
5757
* [BUGFIX] Frontend, Query-scheduler: allow querier to notify about shutdown without providing any authentication. #4066
5858
* [BUGFIX] Querier: fixed race condition causing queries to fail right after querier startup with the "empty ring" error. #4068
59+
* [BUGFIX] Compactor: Increment `cortex_compactor_runs_failed_total` if compactor failed compact a single tenant. #4094
5960

6061
## Blocksconvert
6162

pkg/compactor/compactor.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,12 @@ func (c *Compactor) running(ctx context.Context) error {
455455

456456
func (c *Compactor) compactUsers(ctx context.Context) {
457457
succeeded := false
458+
compactionErrorCount := 0
458459

459460
c.compactionRunsStarted.Inc()
460461

461462
defer func() {
462-
if succeeded {
463+
if succeeded && compactionErrorCount == 0 {
463464
c.compactionRunsCompleted.Inc()
464465
c.compactionRunsLastSuccess.SetToCurrentTime()
465466
} else {
@@ -526,6 +527,7 @@ func (c *Compactor) compactUsers(ctx context.Context) {
526527

527528
if err = c.compactUserWithRetries(ctx, userID); err != nil {
528529
c.compactionRunFailedTenants.Inc()
530+
compactionErrorCount++
529531
level.Error(c.logger).Log("msg", "failed to compact user blocks", "user", userID, "err", err)
530532
continue
531533
}

pkg/compactor/compactor_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,50 @@ func TestCompactor_ShouldRetryCompactionOnFailureWhileDiscoveringUsersFromBucket
414414
))
415415
}
416416

417+
func TestCompactor_ShouldIncrementCompactionErrorIfFailedToCompactASingleTenant(t *testing.T) {
418+
t.Parallel()
419+
420+
userID := "test-user"
421+
bucketClient := &bucket.ClientMock{}
422+
bucketClient.MockIter("", []string{userID}, nil)
423+
bucketClient.MockIter(userID+"/", []string{userID + "/01DTVP434PA9VFXSW2JKB3392D"}, nil)
424+
bucketClient.MockIter(userID+"/markers/", nil, nil)
425+
bucketClient.MockExists(path.Join(userID, cortex_tsdb.TenantDeletionMarkPath), false, nil)
426+
bucketClient.MockGet(userID+"/01DTVP434PA9VFXSW2JKB3392D/meta.json", mockBlockMetaJSON("01DTVP434PA9VFXSW2JKB3392D"), nil)
427+
bucketClient.MockGet(userID+"/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json", "", nil)
428+
bucketClient.MockGet(userID+"/bucket-index.json.gz", "", nil)
429+
bucketClient.MockUpload(userID+"/bucket-index.json.gz", nil)
430+
431+
c, _, tsdbPlannerMock, _, registry := prepare(t, prepareConfig(), bucketClient)
432+
tsdbPlannerMock.On("Plan", mock.Anything, mock.Anything).Return([]*metadata.Meta{}, errors.New("Failed to plan"))
433+
require.NoError(t, services.StartAndAwaitRunning(context.Background(), c))
434+
435+
// Wait until all retry attempts have completed.
436+
cortex_testutil.Poll(t, time.Second, 1.0, func() interface{} {
437+
return prom_testutil.ToFloat64(c.compactionRunsFailed)
438+
})
439+
440+
require.NoError(t, services.StopAndAwaitTerminated(context.Background(), c))
441+
442+
assert.NoError(t, prom_testutil.GatherAndCompare(registry, strings.NewReader(`
443+
# TYPE cortex_compactor_runs_started_total counter
444+
# HELP cortex_compactor_runs_started_total Total number of compaction runs started.
445+
cortex_compactor_runs_started_total 1
446+
447+
# TYPE cortex_compactor_runs_completed_total counter
448+
# HELP cortex_compactor_runs_completed_total Total number of compaction runs successfully completed.
449+
cortex_compactor_runs_completed_total 0
450+
451+
# TYPE cortex_compactor_runs_failed_total counter
452+
# HELP cortex_compactor_runs_failed_total Total number of compaction runs failed.
453+
cortex_compactor_runs_failed_total 1
454+
`),
455+
"cortex_compactor_runs_started_total",
456+
"cortex_compactor_runs_completed_total",
457+
"cortex_compactor_runs_failed_total",
458+
))
459+
}
460+
417461
func TestCompactor_ShouldIterateOverUsersAndRunCompaction(t *testing.T) {
418462
t.Parallel()
419463

0 commit comments

Comments
 (0)