Skip to content

Commit

Permalink
Add unique execution ID for each compaction cycle in log for easy deb…
Browse files Browse the repository at this point in the history
…ugging

Signed-off-by: Alex Le <[email protected]>
  • Loading branch information
alexqyle committed Jul 18, 2024
1 parent 1ba4bca commit d89a4ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/compactor/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package compactor

import (
"context"
crypto_rand "crypto/rand"
"flag"
"fmt"
"hash/fnv"
Expand All @@ -13,6 +14,7 @@ import (

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/oklog/ulid"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
Expand Down Expand Up @@ -810,6 +812,7 @@ func (c *Compactor) compactUser(ctx context.Context, userID string) error {
defer c.syncerMetrics.gatherThanosSyncerMetrics(reg)

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

// Filters out duplicate blocks that can be formed from two or more overlapping
// blocks that fully submatches the source blocks of the older blocks.
Expand Down
4 changes: 4 additions & 0 deletions pkg/compactor/compactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1629,13 +1629,17 @@ func removeIgnoredLogs(input []string) []string {

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

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

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

// Remove any execution_id from logs.
log = executionIDRe.ReplaceAllString(log, "")

if strings.Contains(log, "block.MetaFetcher") || strings.Contains(log, "block.BaseFetcher") {
continue
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/log/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ func WithTraceID(traceID string, l log.Logger) log.Logger {
return log.With(l, "traceID", traceID)
}

// WithExecutionID returns a Logger that has information about the execution id in
// its details.
func WithExecutionID(executionID string, l log.Logger) log.Logger {
return log.With(l, "execution_id", executionID)
}

// WithContext returns a Logger that has information about the current user in
// its details.
//
Expand Down

0 comments on commit d89a4ed

Please sign in to comment.