Skip to content

Commit c487210

Browse files
committed
connection: restore ConnectWithoutMetrics
To not break the interface for existing clients using the function.
1 parent 2eb6147 commit c487210

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

connection/connection.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ func Connect(address string, metricsManager metrics.CSIMetricsManager, options .
7979
return connect(address, options)
8080
}
8181

82+
// ConnectWithoutMetrics behaves exactly like Connect except no metrics are recorded.
83+
// This function is deprecated, prefer using Connect with `nil` as the metricsManager.
84+
func ConnectWithoutMetrics(address string, options ...Option) (*grpc.ClientConn, error) {
85+
// Prepend default options
86+
options = append([]Option{WithTimeout(time.Second * 30)}, options...)
87+
return connect(address, options)
88+
}
89+
8290
// Option is the type of all optional parameters for Connect.
8391
type Option func(o *options)
8492

connection/connection_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,23 @@ func TestConnectWithoutMetrics(t *testing.T) {
139139
addr, stopServer := startServer(t, tmp, nil, nil, nil)
140140
defer stopServer()
141141

142+
// With Connect
142143
conn, err := Connect("unix:///"+addr, nil)
143144
if assert.NoError(t, err, "connect with unix:/// prefix") &&
144145
assert.NotNil(t, conn, "got a connection") {
145146
assert.Equal(t, connectivity.Ready, conn.GetState(), "connection ready")
146147
err = conn.Close()
147148
assert.NoError(t, err, "closing connection")
148149
}
150+
151+
// With ConnectWithoutMetics
152+
conn, err = ConnectWithoutMetrics("unix:///" + addr)
153+
if assert.NoError(t, err, "connect with unix:/// prefix") &&
154+
assert.NotNil(t, conn, "got a connection") {
155+
assert.Equal(t, connectivity.Ready, conn.GetState(), "connection ready")
156+
err = conn.Close()
157+
assert.NoError(t, err, "closing connection")
158+
}
149159
}
150160

151161
func TestConnectWithOtelTracing(t *testing.T) {

0 commit comments

Comments
 (0)