Skip to content

Commit

Permalink
Not all grpc connections need metrics
Browse files Browse the repository at this point in the history
GRPC client connection that node register makes as such doesn't need
metrics and hence allow connections to be made without metrics
  • Loading branch information
gnufied committed Aug 11, 2023
1 parent b6ca620 commit 0d6f2a3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func Connect(address string, metricsManager metrics.CSIMetricsManager, options .
return connect(address, metricsManager, []grpc.DialOption{grpc.WithTimeout(time.Second * 30)}, options)
}

// ConnectWithoutMetrics behaves exactly like Connect except no metrics are recorded.
func ConnectWithoutMetrics(address string, options ...Option) (*grpc.ClientConn, error) {
return connect(address, nil, []grpc.DialOption{grpc.WithTimeout(time.Second * 30)}, options)
}

// Option is the type of all optional parameters for Connect.
type Option func(o *options)

Expand Down Expand Up @@ -118,11 +123,14 @@ func connect(
grpc.WithInsecure(), // Don't use TLS, it's usually local Unix domain socket in a container.
grpc.WithBackoffMaxDelay(time.Second), // Retry every second after failure.
grpc.WithBlock(), // Block until connection succeeds.
grpc.WithChainUnaryInterceptor(
LogGRPC, // Log all messages.
ExtendedCSIMetricsManager{metricsManager}.RecordMetricsClientInterceptor, // Record metrics for each gRPC call.
),
)

interceptors := []grpc.UnaryClientInterceptor{LogGRPC}
if metricsManager != nil {
interceptors = append(interceptors, ExtendedCSIMetricsManager{metricsManager}.RecordMetricsClientInterceptor)
}
dialOptions = append(dialOptions, grpc.WithChainUnaryInterceptor(interceptors...))

unixPrefix := "unix://"
if strings.HasPrefix(address, "/") {
// It looks like filesystem path.
Expand Down

0 comments on commit 0d6f2a3

Please sign in to comment.