Skip to content

Commit caa762e

Browse files
authored
Merge pull request #6097 from alexqyle/compactor-execution-id
Add unique execution ID for each compaction cycle in log for easy debugging
2 parents d2a0b02 + 50e6611 commit caa762e

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* [ENHANCEMENT] Ingester: Add link to renew 10% of the ingesters tokens in the admin page. #6063
2626
* [ENHANCEMENT] Ruler: Add support for filtering by `state` and `health` field on Rules API. #6040
2727
* [ENHANCEMENT] Ruler: Add support for filtering by `match` field on Rules API. #6083
28+
* [ENHANCEMENT] Compactor: Add unique execution ID for each compaction cycle in log for easy debugging. #6097
2829
* [BUGFIX] Configsdb: Fix endline issue in db password. #5920
2930
* [BUGFIX] Ingester: Fix `user` and `type` labels for the `cortex_ingester_tsdb_head_samples_appended_total` TSDB metric. #5952
3031
* [BUGFIX] Querier: Enforce max query length check for `/api/v1/series` API even though `ignoreMaxQueryLength` is set to true. #6018

pkg/compactor/compactor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package compactor
22

33
import (
44
"context"
5+
crypto_rand "crypto/rand"
56
"flag"
67
"fmt"
78
"hash/fnv"
@@ -13,6 +14,7 @@ import (
1314

1415
"github.com/go-kit/log"
1516
"github.com/go-kit/log/level"
17+
"github.com/oklog/ulid"
1618
"github.com/pkg/errors"
1719
"github.com/prometheus/client_golang/prometheus"
1820
"github.com/prometheus/client_golang/prometheus/promauto"
@@ -810,6 +812,7 @@ func (c *Compactor) compactUser(ctx context.Context, userID string) error {
810812
defer c.syncerMetrics.gatherThanosSyncerMetrics(reg)
811813

812814
ulogger := util_log.WithUserID(userID, c.logger)
815+
ulogger = util_log.WithExecutionID(ulid.MustNew(ulid.Now(), crypto_rand.Reader).String(), ulogger)
813816

814817
// Filters out duplicate blocks that can be formed from two or more overlapping
815818
// blocks that fully submatches the source blocks of the older blocks.

pkg/compactor/compactor_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,13 +1629,17 @@ func removeIgnoredLogs(input []string) []string {
16291629

16301630
out := make([]string, 0, len(input))
16311631
durationRe := regexp.MustCompile(`\s?duration(_ms)?=\S+`)
1632+
executionIDRe := regexp.MustCompile(`\s?execution_id=\S+`)
16321633

16331634
for i := 0; i < len(input); i++ {
16341635
log := input[i]
16351636

16361637
// Remove any duration from logs.
16371638
log = durationRe.ReplaceAllString(log, "")
16381639

1640+
// Remove any execution_id from logs.
1641+
log = executionIDRe.ReplaceAllString(log, "")
1642+
16391643
if strings.Contains(log, "block.MetaFetcher") || strings.Contains(log, "block.BaseFetcher") {
16401644
continue
16411645
}

pkg/util/log/wrappers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ func WithTraceID(traceID string, l log.Logger) log.Logger {
2525
return log.With(l, "traceID", traceID)
2626
}
2727

28+
// WithExecutionID returns a Logger that has information about the execution id in
29+
// its details.
30+
func WithExecutionID(executionID string, l log.Logger) log.Logger {
31+
return log.With(l, "execution_id", executionID)
32+
}
33+
2834
// WithContext returns a Logger that has information about the current user in
2935
// its details.
3036
//

0 commit comments

Comments
 (0)