From 9e66a8a0293d99aade924a013a4547d1bb14dfa3 Mon Sep 17 00:00:00 2001 From: Fabian Holler Date: Mon, 2 Dec 2024 17:17:22 +0100 Subject: [PATCH] autoupdater: use different logfield than operation for retryer Do not use the event logfield to assign a name for the operation that the retryer runs. It can already be in reuse, resulting in 2 event fields. Use a new logfield called "operation" instead. Also fix an issue where logfields got appended to a passed logfields slice in updatePRWithBase. This can cause that the wrong logfields are displayed in some messages. --- internal/autoupdate/ci.go | 2 +- internal/autoupdate/queue.go | 7 ++++--- internal/logfields/logfields.go | 7 +++++++ 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 internal/logfields/logfields.go diff --git a/internal/autoupdate/ci.go b/internal/autoupdate/ci.go index 7fec347..f8fad83 100644 --- a/internal/autoupdate/ci.go +++ b/internal/autoupdate/ci.go @@ -23,7 +23,7 @@ func (c *CI) RunAll(ctx context.Context, retryer Retryer, pr *PullRequest) error logfields := append( []zap.Field{ - logfields.Event("triggering_ci_job"), + logfields.Operation("triggering_ci_job"), logfields.CIJob(job.String()), }, pr.LogFields..., diff --git a/internal/autoupdate/queue.go b/internal/autoupdate/queue.go index 411f226..c548c20 100644 --- a/internal/autoupdate/queue.go +++ b/internal/autoupdate/queue.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "maps" + "slices" "strings" "sync" "sync/atomic" @@ -717,8 +718,6 @@ func (q *queue) updatePR(ctx context.Context, pr *PullRequest, task Task) { // TODO: passing logger and loggingFields as parameters is redundant, only pass one of them func (q *queue) updatePRWithBase(ctx context.Context, pr *PullRequest, logger *zap.Logger, loggingFields []zapcore.Field) (changed bool, headCommit string, updateBranchErr error) { - loggingFields = append(loggingFields, logfields.Event("update_branch")) - updateBranchErr = q.retryer.Run(ctx, func(ctx context.Context) error { result, err := q.ghClient.UpdateBranch( ctx, @@ -747,7 +746,9 @@ func (q *queue) updatePRWithBase(ctx context.Context, pr *PullRequest, logger *z headCommit = result.HeadCommitID return nil - }, loggingFields) + }, + append([]zapcore.Field{logfields.Operation("update_branch")}, loggingFields...), + ) if updateBranchErr != nil { if isPRIsClosedErr(updateBranchErr) { diff --git a/internal/logfields/logfields.go b/internal/logfields/logfields.go new file mode 100644 index 0000000..02644bc --- /dev/null +++ b/internal/logfields/logfields.go @@ -0,0 +1,7 @@ +package logfields + +import "go.uber.org/zap" + +func Operation(val string) zap.Field { + return zap.String("operation", val) +}