Skip to content

Add unique execution ID for each compaction cycle in log for easy debugging #6097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* [ENHANCEMENT] Ingester: Add link to renew 10% of the ingesters tokens in the admin page. #6063
* [ENHANCEMENT] Ruler: Add support for filtering by `state` and `health` field on Rules API. #6040
* [ENHANCEMENT] Ruler: Add support for filtering by `match` field on Rules API. #6083
* [ENHANCEMENT] Compactor: Add unique execution ID for each compaction cycle in log for easy debugging. #6097
* [BUGFIX] Configsdb: Fix endline issue in db password. #5920
* [BUGFIX] Ingester: Fix `user` and `type` labels for the `cortex_ingester_tsdb_head_samples_appended_total` TSDB metric. #5952
* [BUGFIX] Querier: Enforce max query length check for `/api/v1/series` API even though `ignoreMaxQueryLength` is set to true. #6018
Expand Down
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
Loading