@@ -73,6 +73,11 @@ func Connect(address string, metricsManager metrics.CSIMetricsManager, options .
7373 return connect (address , metricsManager , []grpc.DialOption {grpc .WithTimeout (time .Second * 30 )}, options )
7474}
7575
76+ // ConnectWithoutMetrics behaves exactly like Connect except no metrics are recorded.
77+ func ConnectWithoutMetrics (address string , options ... Option ) (* grpc.ClientConn , error ) {
78+ return connect (address , nil , []grpc.DialOption {grpc .WithTimeout (time .Second * 30 )}, options )
79+ }
80+
7681// Option is the type of all optional parameters for Connect.
7782type Option func (o * options )
7883
@@ -118,11 +123,14 @@ func connect(
118123 grpc .WithInsecure (), // Don't use TLS, it's usually local Unix domain socket in a container.
119124 grpc .WithBackoffMaxDelay (time .Second ), // Retry every second after failure.
120125 grpc .WithBlock (), // Block until connection succeeds.
121- grpc .WithChainUnaryInterceptor (
122- LogGRPC , // Log all messages.
123- ExtendedCSIMetricsManager {metricsManager }.RecordMetricsClientInterceptor , // Record metrics for each gRPC call.
124- ),
125126 )
127+
128+ interceptors := []grpc.UnaryClientInterceptor {LogGRPC }
129+ if metricsManager != nil {
130+ interceptors = append (interceptors , ExtendedCSIMetricsManager {metricsManager }.RecordMetricsClientInterceptor )
131+ }
132+ dialOptions = append (dialOptions , grpc .WithChainUnaryInterceptor (interceptors ... ))
133+
126134 unixPrefix := "unix://"
127135 if strings .HasPrefix (address , "/" ) {
128136 // It looks like filesystem path.
0 commit comments