From 8317b087a219d6e59e334d37787fb93acc83711d Mon Sep 17 00:00:00 2001 From: Francis Guimond Date: Thu, 4 Nov 2021 13:51:27 -0400 Subject: [PATCH 1/3] The init command does not return SSL errors The SSL or other connection error is now logged as part of the context error. Signed-off-by: Francis Guimond --- backend/backend.go | 12 ++++++------ backend/cmd/init.go | 6 +++--- backend/etcd/etcd.go | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/backend/backend.go b/backend/backend.go index 9eee1d8952..b3d6b857e4 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -199,7 +199,7 @@ func newClient(ctx context.Context, config *Config, backend *Backend) (*clientv3 Password: config.EtcdClientPassword, TLS: tlsConfig, DialOptions: []grpc.DialOption{ - grpc.WithBlock(), + grpc.WithReturnConnectionError(), }, } } else { @@ -208,7 +208,7 @@ func newClient(ctx context.Context, config *Config, backend *Backend) (*clientv3 DialTimeout: 5 * time.Second, TLS: tlsConfig, DialOptions: []grpc.DialOption{ - grpc.WithBlock(), + grpc.WithReturnConnectionError(), }, } } @@ -538,11 +538,11 @@ func Initialize(ctx context.Context, config *Config) (*Backend, error) { // Prepare the authentication providers authenticator := &authentication.Authenticator{} - basic := &basic.Provider{ + provider := &basic.Provider{ ObjectMeta: corev2.ObjectMeta{Name: basic.Type}, Store: b.Store, } - authenticator.AddProvider(basic) + authenticator.AddProvider(provider) var clusterVersion string // only retrieve the cluster version if etcd is embedded @@ -625,7 +625,7 @@ func Initialize(ctx context.Context, config *Config) (*Backend, error) { func (b *Backend) runOnce() error { eCloser := b.StoreUpdater.(closer) - defer eCloser.Close() + defer func() { _ = eCloser.Close() }() var derr error @@ -682,7 +682,7 @@ func (b *Backend) runOnce() error { if err != nil { logger.WithError(err).Error("unable to open platform metrics log file") } else { - defer metricsLogWriter.Close() + defer func() { _ = metricsLogWriter.Close() }() metricsBridge, err := metrics.NewInfluxBridge(&metrics.InfluxBridgeConfig{ Writer: metricsLogWriter, Interval: b.Cfg.PlatformMetricsLoggingInterval, diff --git a/backend/cmd/init.go b/backend/cmd/init.go index 5a9fe652d4..90a1cb6ab9 100644 --- a/backend/cmd/init.go +++ b/backend/cmd/init.go @@ -201,13 +201,13 @@ func InitCommand() *cobra.Command { Username: etcdClientUsername, Password: etcdClientPassword, TLS: tlsConfig, - DialOptions: []grpc.DialOption{grpc.WithBlock()}, + DialOptions: []grpc.DialOption{grpc.WithReturnConnectionError()}, } } else { clientConfig = clientv3.Config{ Endpoints: []string{url}, TLS: tlsConfig, - DialOptions: []grpc.DialOption{grpc.WithBlock()}, + DialOptions: []grpc.DialOption{grpc.WithReturnConnectionError()}, } } err := initializeStore(clientConfig, initConfig, url) @@ -254,7 +254,7 @@ func initializeStore(clientConfig clientv3.Config, initConfig initConfig, endpoi if err != nil { return fmt.Errorf("error connecting to etcd endpoint: %w", err) } - defer client.Close() + defer func() { _ = client.Close() }() // Check if etcd endpoint is reachable if _, err := client.Status(ctx, endpoint); err != nil { diff --git a/backend/etcd/etcd.go b/backend/etcd/etcd.go index 8f602382f9..bb6afb4b73 100644 --- a/backend/etcd/etcd.go +++ b/backend/etcd/etcd.go @@ -15,12 +15,12 @@ import ( "time" "github.com/sensu/sensu-go/util/path" - "go.etcd.io/etcd/client/v3" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc" "go.etcd.io/etcd/client/pkg/v3/logutil" "go.etcd.io/etcd/client/pkg/v3/transport" etcdTypes "go.etcd.io/etcd/client/pkg/v3/types" + "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/server/v3/embed" + "go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc" "go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter" zapcore "go.uber.org/zap/zapcore" "google.golang.org/grpc" @@ -285,7 +285,7 @@ func (e *Etcd) NewClientContext(ctx context.Context) (*clientv3.Client, error) { DialTimeout: 60 * time.Second, TLS: tlsConfig, DialOptions: []grpc.DialOption{ - grpc.WithBlock(), + grpc.WithReturnConnectionError(), }, Context: ctx, }) From cda7ba7526ba9edb62f00990a69cec08a079b70f Mon Sep 17 00:00:00 2001 From: Francis Guimond Date: Thu, 4 Nov 2021 13:58:48 -0400 Subject: [PATCH 2/3] The init command does not return SSL errors CHANGELOG.md entry Signed-off-by: Francis Guimond --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10da6a50f3..b2929fceb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ Versioning](http://semver.org/spec/v2.0.0.html). ## Unreleased +### Fixed +- In addition to the context error print the connection error when sensu-go can't connect to etcd. + ## [6.5.3, 6.5.4] - 2021-10-29 ### Added From 681da00cd128a9b22aa7ab13c667c12cae5a4d51 Mon Sep 17 00:00:00 2001 From: Francis Guimond Date: Thu, 4 Nov 2021 15:19:14 -0400 Subject: [PATCH 3/3] The init command does not return SSL errors Explicitly specify WithBlock dial option for etcd Signed-off-by: Francis Guimond --- backend/backend.go | 2 ++ backend/cmd/init.go | 22 ++++++++++++++-------- backend/etcd/etcd.go | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/backend/backend.go b/backend/backend.go index b3d6b857e4..7abc842dbb 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -200,6 +200,7 @@ func newClient(ctx context.Context, config *Config, backend *Backend) (*clientv3 TLS: tlsConfig, DialOptions: []grpc.DialOption{ grpc.WithReturnConnectionError(), + grpc.WithBlock(), }, } } else { @@ -209,6 +210,7 @@ func newClient(ctx context.Context, config *Config, backend *Backend) (*clientv3 TLS: tlsConfig, DialOptions: []grpc.DialOption{ grpc.WithReturnConnectionError(), + grpc.WithBlock(), }, } } diff --git a/backend/cmd/init.go b/backend/cmd/init.go index 90a1cb6ab9..1cbf4a4147 100644 --- a/backend/cmd/init.go +++ b/backend/cmd/init.go @@ -197,17 +197,23 @@ func InitCommand() *cobra.Command { if etcdClientUsername != "" && etcdClientPassword != "" { clientConfig = clientv3.Config{ - Endpoints: []string{url}, - Username: etcdClientUsername, - Password: etcdClientPassword, - TLS: tlsConfig, - DialOptions: []grpc.DialOption{grpc.WithReturnConnectionError()}, + Endpoints: []string{url}, + Username: etcdClientUsername, + Password: etcdClientPassword, + TLS: tlsConfig, + DialOptions: []grpc.DialOption{ + grpc.WithReturnConnectionError(), + grpc.WithBlock(), + }, } } else { clientConfig = clientv3.Config{ - Endpoints: []string{url}, - TLS: tlsConfig, - DialOptions: []grpc.DialOption{grpc.WithReturnConnectionError()}, + Endpoints: []string{url}, + TLS: tlsConfig, + DialOptions: []grpc.DialOption{ + grpc.WithReturnConnectionError(), + grpc.WithBlock(), + }, } } err := initializeStore(clientConfig, initConfig, url) diff --git a/backend/etcd/etcd.go b/backend/etcd/etcd.go index bb6afb4b73..e4dcec160f 100644 --- a/backend/etcd/etcd.go +++ b/backend/etcd/etcd.go @@ -286,6 +286,7 @@ func (e *Etcd) NewClientContext(ctx context.Context) (*clientv3.Client, error) { TLS: tlsConfig, DialOptions: []grpc.DialOption{ grpc.WithReturnConnectionError(), + grpc.WithBlock(), }, Context: ctx, })