Skip to content

Commit 54f46b4

Browse files
authored
Merge pull request #11664 from sbueringer/pr-kcp-etcd-logger
🌱 KCP: stop recreating logger for etcd client
2 parents e89268d + 707b9fa commit 54f46b4

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

controlplane/kubeadm/internal/etcd/etcd.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import (
2424

2525
"github.com/pkg/errors"
2626
"go.etcd.io/etcd/api/v3/etcdserverpb"
27+
"go.etcd.io/etcd/client/pkg/v3/logutil"
2728
clientv3 "go.etcd.io/etcd/client/v3"
29+
"go.uber.org/zap/zapcore"
2830
"google.golang.org/grpc"
2931
kerrors "k8s.io/apimachinery/pkg/util/errors"
3032

@@ -138,6 +140,12 @@ type ClientConfiguration struct {
138140
CallTimeout time.Duration
139141
}
140142

143+
var (
144+
// Create the etcdClientLogger only once. Otherwise every call of clientv3.New
145+
// would create its own logger which leads to a lot of memory allocations.
146+
etcdClientLogger, _ = logutil.CreateDefaultZapLogger(zapcore.InfoLevel)
147+
)
148+
141149
// NewClient creates a new etcd client with the given configuration.
142150
func NewClient(ctx context.Context, config ClientConfiguration) (*Client, error) {
143151
dialer, err := proxy.NewDialer(config.Proxy)
@@ -151,7 +159,8 @@ func NewClient(ctx context.Context, config ClientConfiguration) (*Client, error)
151159
DialOptions: []grpc.DialOption{
152160
grpc.WithContextDialer(dialer.DialContextWithAddr),
153161
},
154-
TLS: config.TLSConfig,
162+
TLS: config.TLSConfig,
163+
Logger: etcdClientLogger,
155164
})
156165
if err != nil {
157166
return nil, errors.Wrap(err, "unable to create etcd client")

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ require (
3232
github.com/spf13/viper v1.19.0
3333
github.com/valyala/fastjson v1.6.4
3434
go.etcd.io/etcd/api/v3 v3.5.17
35+
go.etcd.io/etcd/client/pkg/v3 v3.5.17
3536
go.etcd.io/etcd/client/v3 v3.5.17
37+
go.uber.org/zap v1.27.0
3638
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
3739
golang.org/x/oauth2 v0.24.0
3840
golang.org/x/text v0.21.0
@@ -125,7 +127,6 @@ require (
125127
github.com/subosito/gotenv v1.6.0 // indirect
126128
github.com/vincent-petithory/dataurl v1.0.0 // indirect
127129
github.com/x448/float16 v0.8.4 // indirect
128-
go.etcd.io/etcd/client/pkg/v3 v3.5.17 // indirect
129130
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
130131
go.opentelemetry.io/otel v1.28.0 // indirect
131132
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
@@ -135,7 +136,6 @@ require (
135136
go.opentelemetry.io/otel/trace v1.28.0 // indirect
136137
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
137138
go.uber.org/multierr v1.11.0 // indirect
138-
go.uber.org/zap v1.27.0 // indirect
139139
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
140140
golang.org/x/crypto v0.31.0 // indirect
141141
golang.org/x/net v0.33.0 // indirect

0 commit comments

Comments
 (0)