Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 KCP: stop recreating logger for etcd client #11664

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading