Skip to content

Commit

Permalink
chore: remove duplicate UUID from the logs (#4223)
Browse files Browse the repository at this point in the history
Since controller-runtime adds their own `reconcileID`, adding a uuid field
is not needed anymore.

Partially closes: #2206

Signed-off-by: Jonathan Gonzalez V <jonathan.gonzalez@enterprisedb.com>
  • Loading branch information
sxd authored and leonardoce committed Apr 6, 2024
1 parent d76c029 commit b01ad14
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 22 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 0 additions & 21 deletions pkg/management/log/log.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down

0 comments on commit b01ad14

Please sign in to comment.