Skip to content

Commit d93db7e

Browse files
authored
Fix compactor test (#5690)
Signed-off-by: Alex Le <[email protected]>
1 parent 31655c5 commit d93db7e

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

pkg/compactor/compactor_test.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,12 @@ func TestCompactor_ShouldDoNothingOnNoUserBlocks(t *testing.T) {
211211

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

214-
assert.Equal(t, []string{
214+
assert.ElementsMatch(t, []string{
215215
`level=info component=cleaner msg="started blocks cleanup and maintenance"`,
216216
`level=info component=cleaner msg="successfully completed blocks cleanup and maintenance"`,
217217
`level=info component=compactor msg="compactor started"`,
218218
`level=info component=compactor msg="discovering users from bucket"`,
219219
`level=info component=compactor msg="discovered users from bucket" users=0`,
220-
`level=info component=compactor msg="compactor stopped"`,
221220
}, removeIgnoredLogs(strings.Split(strings.TrimSpace(logs.String()), "\n")))
222221

223222
assert.NoError(t, prom_testutil.GatherAndCompare(registry, strings.NewReader(`
@@ -364,13 +363,12 @@ func TestCompactor_ShouldRetryCompactionOnFailureWhileDiscoveringUsersFromBucket
364363
// Ensure the bucket iteration has been retried the configured number of times.
365364
bucketClient.AssertNumberOfCalls(t, "Iter", 1+3)
366365

367-
assert.Equal(t, []string{
366+
assert.ElementsMatch(t, []string{
368367
`level=info component=cleaner msg="started blocks cleanup and maintenance"`,
369368
`level=error component=cleaner msg="failed to run blocks cleanup and maintenance" err="failed to discover users from bucket: failed to iterate the bucket"`,
370369
`level=info component=compactor msg="compactor started"`,
371370
`level=info component=compactor msg="discovering users from bucket"`,
372371
`level=error component=compactor msg="failed to discover users from bucket" err="failed to iterate the bucket"`,
373-
`level=info component=compactor msg="compactor stopped"`,
374372
}, removeIgnoredLogs(strings.Split(strings.TrimSpace(logs.String()), "\n")))
375373

376374
assert.NoError(t, prom_testutil.GatherAndCompare(registry, strings.NewReader(`
@@ -680,7 +678,6 @@ func TestCompactor_ShouldIterateOverUsersAndRunCompaction(t *testing.T) {
680678
`level=info component=compactor org_id=user-2 msg="start of compactions"`,
681679
`level=info component=compactor org_id=user-2 msg="compaction iterations done"`,
682680
`level=info component=compactor msg="successfully compacted user blocks" user=user-2`,
683-
`level=info component=compactor msg="compactor stopped"`,
684681
}, removeIgnoredLogs(strings.Split(strings.TrimSpace(logs.String()), "\n")))
685682

686683
// Instead of testing for shipper metrics, we only check our metrics here.
@@ -809,7 +806,6 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForDeletion(t *testing.T) {
809806
`level=info component=compactor org_id=user-1 msg="start of compactions"`,
810807
`level=info component=compactor org_id=user-1 msg="compaction iterations done"`,
811808
`level=info component=compactor msg="successfully compacted user blocks" user=user-1`,
812-
`level=info component=compactor msg="compactor stopped"`,
813809
}, removeIgnoredLogs(strings.Split(strings.TrimSpace(logs.String()), "\n")))
814810

815811
// Instead of testing for shipper metrics, we only check our metrics here.
@@ -998,7 +994,6 @@ func TestCompactor_ShouldNotCompactBlocksForUsersMarkedForDeletion(t *testing.T)
998994
`level=info component=compactor msg="discovering users from bucket"`,
999995
`level=info component=compactor msg="discovered users from bucket" users=1`,
1000996
`level=debug component=compactor msg="skipping user because it is marked for deletion" user=user-1`,
1001-
`level=info component=compactor msg="compactor stopped"`,
1002997
}, removeIgnoredLogs(strings.Split(strings.TrimSpace(logs.String()), "\n")))
1003998

1004999
// Instead of testing for shipper metrics, we only check our metrics here.
@@ -1203,7 +1198,6 @@ func TestCompactor_ShouldCompactAllUsersOnShardingEnabledButOnlyOneInstanceRunni
12031198
`level=info component=compactor org_id=user-2 msg="start of compactions"`,
12041199
`level=info component=compactor org_id=user-2 msg="compaction iterations done"`,
12051200
`level=info component=compactor msg="successfully compacted user blocks" user=user-2`,
1206-
`level=info component=compactor msg="compactor stopped"`,
12071201
}, removeIgnoredLogs(strings.Split(strings.TrimSpace(logs.String()), "\n")))
12081202
}
12091203

@@ -1607,14 +1601,18 @@ func removeIgnoredLogs(input []string) []string {
16071601
`level=info component=compactor msg="instance removed from the KV store" ring=compactor`: {},
16081602
`level=info component=compactor msg="observing tokens before going ACTIVE" ring=compactor`: {},
16091603
`level=info component=compactor msg="lifecycler entering final sleep before shutdown" final_sleep=0s`: {},
1604+
`level=info component=compactor msg="compactor stopped"`: {},
16101605
}
16111606

16121607
out := make([]string, 0, len(input))
1613-
durationRe := regexp.MustCompile(`\s?duration=\S+`)
1614-
durationMsRe := regexp.MustCompile(`\s?duration_ms=\S+`)
1608+
durationRe := regexp.MustCompile(`\s?duration(_ms)?=\S+`)
16151609

16161610
for i := 0; i < len(input); i++ {
16171611
log := input[i]
1612+
1613+
// Remove any duration from logs.
1614+
log = durationRe.ReplaceAllString(log, "")
1615+
16181616
if strings.Contains(log, "block.MetaFetcher") || strings.Contains(log, "block.BaseFetcher") {
16191617
continue
16201618
}
@@ -1623,10 +1621,6 @@ func removeIgnoredLogs(input []string) []string {
16231621
continue
16241622
}
16251623

1626-
// Remove any duration from logs.
1627-
log = durationRe.ReplaceAllString(log, "")
1628-
log = durationMsRe.ReplaceAllString(log, "")
1629-
16301624
out = append(out, log)
16311625
}
16321626

0 commit comments

Comments
 (0)