connection

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 14 Imported by: 58

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(ctx context.Context, address string, metricsManager metrics.CSIMetricsManager, options ...Option) (*grpc.ClientConn, error)

Connect opens insecure gRPC connection to a CSI driver. Address must be either absolute path to UNIX domain socket file or have format '<protocol>://', following gRPC name resolution mechanism at https://github.com/grpc/grpc/blob/master/doc/naming.md.

The function tries to connect for 30 seconds, and returns an error if no connection has been established at that point. The connection has zero idle timeout, i.e. it is never closed because of inactivity. The function automatically disables TLS and adds interceptor for logging of all gRPC messages at level 5. If the metricsManager is 'nil', no metrics will be recorded on the gRPC calls. The function behaviour can be tweaked with options.

For a connection to a Unix Domain socket, the behavior after loosing the connection is configurable. The default is to log the connection loss and reestablish a connection. Applications which need to know about a connection loss can be notified by passing a callback with OnConnectionLoss and in that callback can decide what to do: - exit the application with os.Exit - invalidate cached information - disable the reconnect, which will cause all gRPC method calls to fail with status.Unavailable

For other connections, the default behavior from gRPC is used and loss of connection is not detected reliably.

func ConnectWithoutMetrics added in v0.15.0

func ConnectWithoutMetrics(ctx context.Context, address string, options ...Option) (*grpc.ClientConn, error)

ConnectWithoutMetrics behaves exactly like Connect except no metrics are recorded. This function is deprecated, prefer using Connect with `nil` as the metricsManager.

func ExitOnConnectionLoss added in v0.3.1

func ExitOnConnectionLoss() func(context.Context) bool

ExitOnConnectionLoss returns callback for OnConnectionLoss() that writes an error to /dev/termination-log and exits.

func LogGRPC

func LogGRPC(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error

LogGRPC is gPRC unary interceptor for logging of CSI messages at level 5. It removes any secrets from the message.

func SetMaxGRPCLogLength added in v0.13.0

func SetMaxGRPCLogLength(characterCount int)

SetMaxGRPCLogLength set the maximum character count for GRPC logging. If characterCount is set to anything smaller than or equal to 0 then there's no limit on log length. The default log length limit is unlimited.

Types

type AdditionalInfo added in v0.9.1

type AdditionalInfo struct {
	Migrated string
}

type AdditionalInfoKeyType added in v0.9.1

type AdditionalInfoKeyType struct{}
var AdditionalInfoKey AdditionalInfoKeyType

type ExtendedCSIMetricsManager added in v0.8.0

type ExtendedCSIMetricsManager struct {
	metrics.CSIMetricsManager
}

func (ExtendedCSIMetricsManager) RecordMetricsClientInterceptor added in v0.8.0

func (cmm ExtendedCSIMetricsManager) RecordMetricsClientInterceptor(
	ctx context.Context,
	method string,
	req, reply interface{},
	cc *grpc.ClientConn,
	invoker grpc.UnaryInvoker,
	opts ...grpc.CallOption) error

RecordMetricsClientInterceptor is a gPRC unary interceptor for recording metrics for CSI operations in a gRPC client.

func (ExtendedCSIMetricsManager) RecordMetricsServerInterceptor added in v0.8.0

func (cmm ExtendedCSIMetricsManager) RecordMetricsServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

RecordMetricsServerInterceptor is a gPRC unary interceptor for recording metrics for CSI operations in a gRCP server.

type Option

type Option func(o *options)

Option is the type of all optional parameters for Connect.

func OnConnectionLoss

func OnConnectionLoss(reconnect func(context.Context) bool) Option

OnConnectionLoss registers a callback that will be invoked when the connection got lost. If that callback returns true, the connection is reestablished. Otherwise the connection is left as it is and all future gRPC calls using it will fail with status.Unavailable.

func WithMetrics added in v0.15.0

func WithMetrics(metricsManager metrics.CSIMetricsManager) Option

WithMetrics enables the recording of metrics on the gRPC calls with the provided CSIMetricsManager.

func WithOtelTracing added in v0.15.0

func WithOtelTracing() Option

WithOtelTracing enables the recording of traces on the gRPC calls with opentelemetry gRPC interceptor.

func WithTimeout added in v0.15.0

func WithTimeout(timeout time.Duration) Option

WithTimeout adds a configurable timeout on the gRPC calls. Note that this timeout also prevents all attempts to reconnect because it uses context.WithTimeout internally.

For more details, see https://github.com/grpc/grpc-go/issues/133 and https://github.com/kubernetes-csi/csi-lib-utils/pull/149#discussion_r1574707477

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL