Skip to content

Commit d89a4ed

Browse files
committed
Add unique execution ID for each compaction cycle in log for easy debugging
Signed-off-by: Alex Le <[email protected]>
1 parent 1ba4bca commit d89a4ed

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

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)