Skip to content

Commit

Permalink
connection: restore ConnectWithoutMetrics
Browse files Browse the repository at this point in the history
To not break the interface for existing clients using the function.
  • Loading branch information
Fricounet committed Aug 24, 2023
1 parent 2eb6147 commit c487210
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions connection/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,23 @@ 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") {
assert.Equal(t, connectivity.Ready, conn.GetState(), "connection ready")
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) {
Expand Down

0 comments on commit c487210

Please sign in to comment.