Skip to content

Commit

Permalink
patch: KCP: stop recreating logger for etcd client
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer [email protected]
  • Loading branch information
sbueringer committed Jan 10, 2025
1 parent 7f2a8cd commit a15718e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion controlplane/kubeadm/internal/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import (

"github.com/pkg/errors"
"go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/client/pkg/v3/logutil"
clientv3 "go.etcd.io/etcd/client/v3"
"go.uber.org/zap/zapcore"
"google.golang.org/grpc"
kerrors "k8s.io/apimachinery/pkg/util/errors"

Expand Down Expand Up @@ -138,6 +140,12 @@ type ClientConfiguration struct {
CallTimeout time.Duration
}

var (
// Create the etcdClientLogger only once. Otherwise every call of clientv3.New
// would create its own logger which leads to a lot of memory allocations.
etcdClientLogger, _ = logutil.CreateDefaultZapLogger(zapcore.InfoLevel)
)

// NewClient creates a new etcd client with the given configuration.
func NewClient(ctx context.Context, config ClientConfiguration) (*Client, error) {
dialer, err := proxy.NewDialer(config.Proxy)
Expand All @@ -151,7 +159,8 @@ func NewClient(ctx context.Context, config ClientConfiguration) (*Client, error)
DialOptions: []grpc.DialOption{
grpc.WithContextDialer(dialer.DialContextWithAddr),
},
TLS: config.TLSConfig,
TLS: config.TLSConfig,
Logger: etcdClientLogger,
})
if err != nil {
return nil, errors.Wrap(err, "unable to create etcd client")
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ require (
github.com/spf13/viper v1.19.0
github.com/valyala/fastjson v1.6.4
go.etcd.io/etcd/api/v3 v3.5.17
go.etcd.io/etcd/client/pkg/v3 v3.5.17
go.etcd.io/etcd/client/v3 v3.5.17
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
golang.org/x/oauth2 v0.24.0
golang.org/x/text v0.21.0
Expand Down Expand Up @@ -125,7 +127,6 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
github.com/vincent-petithory/dataurl v1.0.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.17 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
Expand All @@ -135,7 +136,6 @@ require (
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
Expand Down

0 comments on commit a15718e

Please sign in to comment.