From c4872109e67c43da7afa7508de69c88838b6a4c7 Mon Sep 17 00:00:00 2001 From: Baptiste Girard-Carrabin Date: Thu, 24 Aug 2023 16:08:45 +0200 Subject: [PATCH] connection: restore ConnectWithoutMetrics To not break the interface for existing clients using the function. --- connection/connection.go | 8 ++++++++ connection/connection_test.go | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/connection/connection.go b/connection/connection.go index 8c311284f..5990b759e 100644 --- a/connection/connection.go +++ b/connection/connection.go @@ -79,6 +79,14 @@ func Connect(address string, metricsManager metrics.CSIMetricsManager, options . return connect(address, options) } +// ConnectWithoutMetrics behaves exactly like Connect except no metrics are recorded. +// This function is deprecated, prefer using Connect with `nil` as the metricsManager. +func ConnectWithoutMetrics(address string, options ...Option) (*grpc.ClientConn, error) { + // Prepend default options + options = append([]Option{WithTimeout(time.Second * 30)}, options...) + return connect(address, options) +} + // Option is the type of all optional parameters for Connect. type Option func(o *options) diff --git a/connection/connection_test.go b/connection/connection_test.go index d4ca3c7b1..7340a7108 100644 --- a/connection/connection_test.go +++ b/connection/connection_test.go @@ -139,6 +139,7 @@ func TestConnectWithoutMetrics(t *testing.T) { addr, stopServer := startServer(t, tmp, nil, nil, nil) defer stopServer() + // With Connect conn, err := Connect("unix:///"+addr, nil) if assert.NoError(t, err, "connect with unix:/// prefix") && assert.NotNil(t, conn, "got a connection") { @@ -146,6 +147,15 @@ func TestConnectWithoutMetrics(t *testing.T) { err = conn.Close() assert.NoError(t, err, "closing connection") } + + // With ConnectWithoutMetics + conn, err = ConnectWithoutMetrics("unix:///" + addr) + if assert.NoError(t, err, "connect with unix:/// prefix") && + assert.NotNil(t, conn, "got a connection") { + assert.Equal(t, connectivity.Ready, conn.GetState(), "connection ready") + err = conn.Close() + assert.NoError(t, err, "closing connection") + } } func TestConnectWithOtelTracing(t *testing.T) {