From b01ad1457c66467d781a886c21c8ff5134696004 Mon Sep 17 00:00:00 2001 From: Jonathan Gonzalez V Date: Sat, 6 Apr 2024 18:59:40 +0200 Subject: [PATCH] chore: remove duplicate UUID from the logs (#4223) Since controller-runtime adds their own `reconcileID`, adding a uuid field is not needed anymore. Partially closes: #2206 Signed-off-by: Jonathan Gonzalez V --- go.mod | 2 +- pkg/management/log/log.go | 21 --------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/go.mod b/go.mod index c34a2785bb..d0ad5748ed 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,6 @@ require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/go-logr/logr v1.4.1 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 - github.com/google/uuid v1.6.0 github.com/jackc/pgx/v5 v5.5.5 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/kubernetes-csi/external-snapshotter/client/v7 v7.0.0 @@ -65,6 +64,7 @@ require ( github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect github.com/imdario/mergo v0.3.12 // indirect diff --git a/pkg/management/log/log.go b/pkg/management/log/log.go index aab2d93575..38b2bc0c1f 100644 --- a/pkg/management/log/log.go +++ b/pkg/management/log/log.go @@ -25,7 +25,6 @@ import ( "runtime" "github.com/go-logr/logr" - "github.com/google/uuid" "go.uber.org/zap/zapcore" ctrl "sigs.k8s.io/controller-runtime" ctrlLog "sigs.k8s.io/controller-runtime/pkg/log" @@ -63,8 +62,6 @@ const ( DefaultLevel = InfoLevel ) -type uuidKey struct{} - // Logger wraps a logr.Logger, hiding parts of its APIs type logger struct { logr.Logger @@ -208,11 +205,6 @@ func FromContext(ctx context.Context) Logger { l = &logger{Logger: ctrlLog.FromContext(ctx)} } - uuid, ok := ctx.Value(uuidKey{}).(uuid.UUID) - if ok { - l = l.WithValues("uuid", uuid) - } - return l } @@ -221,21 +213,8 @@ func IntoContext(ctx context.Context, log Logger) context.Context { return ctrlLog.IntoContext(ctx, log.GetLogger()) } -// AddUUID wraps a given context to inject a new uuid -func AddUUID(ctx context.Context) (context.Context, error) { - id, err := uuid.NewUUID() - if err != nil { - return ctx, err - } - return context.WithValue(ctx, uuidKey{}, id), nil -} - // SetupLogger sets up the logger from a given context, wrapping it with a new uuid, and any given name func SetupLogger(ctx context.Context) (Logger, context.Context) { - if newCtx, err := AddUUID(ctx); err == nil { - ctx = newCtx - } - // The only error that we can have calling FromContext() is a not found // in which case we will have an empty not nil value for newLogger which // still useful when setting up the logger