Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase Sentry retry to 30s from Sidecar Injector #7508

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/injector/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,11 @@ func Run() {
if err != nil {
return rerr
}
requester := sentry.New(sentry.Options{
requester, derr := sentry.New(ctx, sentry.Options{
SentryAddress: cfg.SentryAddress,
SentryID: sentryID,
Security: sec,
})
derr := requester.DialSentryConnection(ctx)
if derr != nil {
return derr
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/injector/sentry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,20 @@ type Requester struct {
}

// New returns a new instance of the Requester.
func New(opts Options) *Requester {
func New(ctx context.Context, opts Options) (*Requester, error) {
_, kubeMode := os.LookupEnv("KUBERNETES_SERVICE_HOST")
return &Requester{
r := &Requester{
sentryAddress: opts.SentryAddress,
sentryID: opts.SentryID,
sec: opts.Security,
kubernetesMode: kubeMode,
}

return r, r.dialSentryConnection(ctx)
}

// DialSentryConnection creates the gRPC connection to the Sentry service and blocks for 1 minute.
func (r *Requester) DialSentryConnection(ctx context.Context) error {
// dialSentryConnection creates the gRPC connection to the Sentry service and blocks for 1 minute.
func (r *Requester) dialSentryConnection(ctx context.Context) error {
connCtx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()

Expand Down Expand Up @@ -109,7 +111,7 @@ func (r *Requester) RequestCertificateFromSentry(ctx context.Context, namespace
Token: token,
Namespace: namespace,
TokenValidator: tokenValidator,
}, grpcRetry.WithMax(3), grpcRetry.WithPerRetryTimeout(time.Second*3))
}, grpcRetry.WithMax(10), grpcRetry.WithPerRetryTimeout(time.Second*3))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then do we need to set a "WithMax"? Could we just abort on when the context was canceled, which happens automatically?

Suggested change
}, grpcRetry.WithMax(10), grpcRetry.WithPerRetryTimeout(time.Second*3))
}, grpcRetry.WithPerRetryTimeout(2*time.Second))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WithMax is required to enable retries. Only having WithPerRetryTimeout will not enable it. Context cancellation will not retry the request, it will serve as a 30s timeout for a single request.

if err != nil {
return nil, nil, fmt.Errorf("error from sentry SignCertificate: %w", err)
}
Expand Down