Merge pull request #118857 from dims/better-backoff-delays-and-connection-timeout-talking-to-containerd

Better back off delays and connection timeout to talk to containerd
This commit is contained in:
Kubernetes Prow Robot 2023-06-25 16:53:08 -07:00 committed by GitHub
commit 6cb0308dbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 10 deletions

View File

@ -56,11 +56,7 @@ func NewRemoteImageService(endpoint string, connectionTimeout time.Duration, tp
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout) ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
defer cancel() defer cancel()
dialOpts := []grpc.DialOption{ var dialOpts []grpc.DialOption
grpc.WithConnectParams(grpc.ConnectParams{
Backoff: backoff.DefaultConfig,
}),
}
dialOpts = append(dialOpts, dialOpts = append(dialOpts,
grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithContextDialer(dialer), grpc.WithContextDialer(dialer),
@ -77,6 +73,16 @@ func NewRemoteImageService(endpoint string, connectionTimeout time.Duration, tp
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(tracingOpts...))) grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(tracingOpts...)))
} }
connParams := grpc.ConnectParams{
Backoff: backoff.DefaultConfig,
}
connParams.MinConnectTimeout = minConnectionTimeout
connParams.Backoff.BaseDelay = baseBackoffDelay
connParams.Backoff.MaxDelay = maxBackoffDelay
dialOpts = append(dialOpts,
grpc.WithConnectParams(connParams),
)
conn, err := grpc.DialContext(ctx, addr, dialOpts...) conn, err := grpc.DialContext(ctx, addr, dialOpts...)
if err != nil { if err != nil {
klog.ErrorS(err, "Connect remote image service failed", "address", addr) klog.ErrorS(err, "Connect remote image service failed", "address", addr)

View File

@ -56,6 +56,11 @@ type remoteRuntimeService struct {
const ( const (
// How frequently to report identical errors // How frequently to report identical errors
identicalErrorDelay = 1 * time.Minute identicalErrorDelay = 1 * time.Minute
// connection parameters
maxBackoffDelay = 3 * time.Second
baseBackoffDelay = 100 * time.Millisecond
minConnectionTimeout = 5 * time.Second
) )
// CRIVersion is the type for valid Container Runtime Interface (CRI) API // CRIVersion is the type for valid Container Runtime Interface (CRI) API
@ -80,11 +85,7 @@ func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration, t
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout) ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
defer cancel() defer cancel()
dialOpts := []grpc.DialOption{ var dialOpts []grpc.DialOption
grpc.WithConnectParams(grpc.ConnectParams{
Backoff: backoff.DefaultConfig,
}),
}
dialOpts = append(dialOpts, dialOpts = append(dialOpts,
grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithContextDialer(dialer), grpc.WithContextDialer(dialer),
@ -100,6 +101,17 @@ func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration, t
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor(tracingOpts...)), grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor(tracingOpts...)),
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(tracingOpts...))) grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(tracingOpts...)))
} }
connParams := grpc.ConnectParams{
Backoff: backoff.DefaultConfig,
}
connParams.MinConnectTimeout = minConnectionTimeout
connParams.Backoff.BaseDelay = baseBackoffDelay
connParams.Backoff.MaxDelay = maxBackoffDelay
dialOpts = append(dialOpts,
grpc.WithConnectParams(connParams),
)
conn, err := grpc.DialContext(ctx, addr, dialOpts...) conn, err := grpc.DialContext(ctx, addr, dialOpts...)
if err != nil { if err != nil {
klog.ErrorS(err, "Connect remote runtime failed", "address", addr) klog.ErrorS(err, "Connect remote runtime failed", "address", addr)