diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-09-25 10:09:34 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-09-26 14:11:36 +0300 |
commit | 9612641f50ee5e58f16ceb390eb6fed87c702075 (patch) | |
tree | 3fd7b8b94e438a869b9d8f70153fe0138a244e5e /internal | |
parent | 531d5205acec6b5160d862ea687c157c07cbcff1 (diff) |
log: Drop `Debugf()` function from `Logger` interface
Next to `Debug()` and related functions our `Logger` interface also
provides `Debugf()` and related functions that takes a formatting string
as well as a set of arguments for it. There are multiple reasons though
why we don't want to expose these functions:
- They do not exist in the `slog` package, which thus causes our own
internal interface to diverge from our desired target solution.
- It is discouraged to put variable data into the message itself.
Instead, callsites are encouraged to add any variable data as
structured log data.
- It often gets abused in contexts where it's not required at all to
call the formatting variant as all we pass in is a static string.
- We have a pending addition of logging functions that also take a
context parameter as input. The formatting family would cause us
to require four more functions that take such a context as input.
Let's remove `Debugf()` in favor of `Debug()`. Most of the existing
callsites are converted to instead use structured logging data.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/cli/praefect/subcmd_list_untracked_repositories.go | 8 | ||||
-rw-r--r-- | internal/cli/praefect/subcmd_track_repository.go | 7 | ||||
-rw-r--r-- | internal/gitaly/storage/storagemgr/database.go | 6 | ||||
-rw-r--r-- | internal/limiter/adaptive_calculator.go | 2 | ||||
-rw-r--r-- | internal/log/logger.go | 6 | ||||
-rw-r--r-- | internal/praefect/coordinator.go | 2 |
6 files changed, 20 insertions, 11 deletions
diff --git a/internal/cli/praefect/subcmd_list_untracked_repositories.go b/internal/cli/praefect/subcmd_list_untracked_repositories.go index 289ede89f..af356deba 100644 --- a/internal/cli/praefect/subcmd_list_untracked_repositories.go +++ b/internal/cli/praefect/subcmd_list_untracked_repositories.go @@ -77,7 +77,7 @@ func listUntrackedRepositoriesAction(appCtx *cli.Context) error { ctx = metadata.AppendToOutgoingContext(ctx, "client_name", appCtx.Command.Name) logger = logger.WithField("correlation_id", correlation.ExtractFromContext(ctx)) - logger.Debugf("starting %s command", appCtx.App.Name) + logger.Debug(fmt.Sprintf("starting %s command", appCtx.App.Name)) logger.Debug("dialing to gitaly nodes...") nodeSet, err := dialGitalyStorages(ctx, conf, defaultDialTimeout) @@ -107,7 +107,11 @@ func listUntrackedRepositoriesAction(appCtx *cli.Context) error { } for _, vs := range conf.VirtualStorages { for _, node := range vs.Nodes { - logger.Debugf("check %q/%q storage repositories", vs.Name, node.Storage) + logger.WithFields(log.Fields{ + "virtual_storage": vs.Name, + "storage_node": node.Storage, + }).Debug("checking storage repositories") + if err := walker.ExecOnRepositories(ctx, vs.Name, node.Storage, reporter.Report); err != nil { return fmt.Errorf("exec on %q/%q: %w", vs.Name, node.Storage, err) } diff --git a/internal/cli/praefect/subcmd_track_repository.go b/internal/cli/praefect/subcmd_track_repository.go index 98bb40fcc..207d89542 100644 --- a/internal/cli/praefect/subcmd_track_repository.go +++ b/internal/cli/praefect/subcmd_track_repository.go @@ -336,7 +336,12 @@ func (req *trackRepositoryRequest) authoritativeRepositoryExists(ctx context.Con for _, node := range vs.Nodes { if node.Storage == nodeName { - logger.Debugf("check if repository %q exists on gitaly %q at %q", req.ReplicaPath, node.Storage, node.Address) + logger.WithFields(log.Fields{ + "replica_path": req.ReplicaPath, + "storage_node": node.Storage, + "node_address": node.Address, + }).Debug("check if repository exists on Gitaly node") + repo := &gitalypb.Repository{ StorageName: node.Storage, RelativePath: req.ReplicaPath, diff --git a/internal/gitaly/storage/storagemgr/database.go b/internal/gitaly/storage/storagemgr/database.go index 526c7eda6..66913f846 100644 --- a/internal/gitaly/storage/storagemgr/database.go +++ b/internal/gitaly/storage/storagemgr/database.go @@ -1,6 +1,8 @@ package storagemgr import ( + "fmt" + "github.com/dgraph-io/badger/v4" "gitlab.com/gitlab-org/gitaly/v16/internal/log" ) @@ -20,6 +22,10 @@ type badgerLogger struct { log.Logger } +func (l badgerLogger) Debugf(msg string, args ...any) { + l.Debug(fmt.Sprintf(msg, args...)) +} + func (l badgerLogger) Warningf(msg string, args ...any) { l.Warnf(msg, args...) } diff --git a/internal/limiter/adaptive_calculator.go b/internal/limiter/adaptive_calculator.go index ebb7526e0..97a273c2a 100644 --- a/internal/limiter/adaptive_calculator.go +++ b/internal/limiter/adaptive_calculator.go @@ -259,7 +259,7 @@ func (c *AdaptiveCalculator) calibrateLimits(ctx context.Context) { logger.WithFields(map[string]interface{}{ "previous_limit": limit.Current(), "new_limit": newLimit, - }).Debugf("Additive increase") + }).Debug("Additive increase") } else { // Multiplicative decrease newLimit = int(math.Floor(float64(limit.Current()) * setting.BackoffFactor)) diff --git a/internal/log/logger.go b/internal/log/logger.go index a1baac5c8..9fafeaa1c 100644 --- a/internal/log/logger.go +++ b/internal/log/logger.go @@ -18,7 +18,6 @@ type Logger interface { WithFields(fields Fields) Logger WithError(err error) Logger - Debugf(format string, args ...any) Infof(format string, args ...any) Warnf(format string, args ...any) Errorf(format string, args ...any) @@ -66,11 +65,6 @@ func (l LogrusLogger) WithError(err error) Logger { return LogrusLogger{entry: l.entry.WithError(err)} } -// Debugf writes a formatted log message at debug level. -func (l LogrusLogger) Debugf(format string, args ...any) { - l.entry.Debugf(format, args...) -} - // Infof writes a formatted log message at info level. func (l LogrusLogger) Infof(format string, args ...any) { l.entry.Infof(format, args...) diff --git a/internal/praefect/coordinator.go b/internal/praefect/coordinator.go index a95bab79b..e2a8875e4 100644 --- a/internal/praefect/coordinator.go +++ b/internal/praefect/coordinator.go @@ -665,7 +665,7 @@ func streamParametersContext(ctx context.Context) context.Context { func (c *Coordinator) StreamDirector(ctx context.Context, fullMethodName string, peeker proxy.StreamPeeker) (*proxy.StreamParameters, error) { // For phase 1, we need to route messages based on the storage location // to the appropriate Gitaly node. - log.FromContext(ctx).Debugf("Stream director received method %s", fullMethodName) + log.FromContext(ctx).WithField("method", fullMethodName).Debug("Stream director received method") mi, err := c.registry.LookupMethod(fullMethodName) if err != nil { |