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

Identify recoverable errors and add retry mechanisms for failures #707

Open
m-Peter opened this issue Dec 15, 2024 · 1 comment
Open

Identify recoverable errors and add retry mechanisms for failures #707

m-Peter opened this issue Dec 15, 2024 · 1 comment

Comments

@m-Peter
Copy link
Collaborator

m-Peter commented Dec 15, 2024

Related discord thread: https://discord.com/channels/613813861610684416/1167476806333513800/1317243233431982120

@bjartek
Copy link

bjartek commented Dec 17, 2024

grpc retry could be used to just do a general retry.

this is some example code we use at .find

func CreateFlowClientFromConfig(cfg Config, logger *zap.Logger, opt ...overflow.OverflowOption) (overflow.OverflowClient, error) {
	interceptors := []grpc.UnaryClientInterceptor{}

	// if we have grpc logging enable we add the grpc logging interceptor
	if cfg.FlowGrpcLogging {

		opts := []logging.Option{
			logging.WithLogOnEvents(logging.StartCall, logging.FinishCall),
			logging.WithFieldsFromContext(logging.ExtractFields),
		}

		unaryLoggingInterceptor := logging.UnaryClientInterceptor(InterceptorLogger(logger), opts...)
		interceptors = append(interceptors, unaryLoggingInterceptor)
	}

	// if we have retry set to anything greater then 0 then we retry grpc calls
	if cfg.FlowGrpcRetryMax > 0 {

		retryCallback := func(_ context.Context, attempt uint, err error) {
			logger.Debug("retry", zap.Uint("attempt", attempt), zap.Error(err))
		}

		opts := []retry.CallOption{
			retry.WithMax(cfg.FlowGrpcRetryMax),
			retry.WithPerRetryTimeout(cfg.FlowGrpcRetryTimeout),
			retry.WithBackoff(retry.BackoffExponential(cfg.FlowGrpcRetryExponentialBackoff)),
			retry.WithOnRetryCallback(retryCallback),
		}

		retryInterceptor := retry.UnaryClientInterceptor(opts...)
		interceptors = append(interceptors, retryInterceptor)
	}

	if cfg.FlowGrpcGlobalTimeout > 0 {
		timeoutInterceptor := timeout.UnaryClientInterceptor(cfg.FlowGrpcGlobalTimeout)
		interceptors = append(interceptors, timeoutInterceptor)
	}

	overflowOptions := []overflow.OverflowOption{
		overflow.WithNetwork(cfg.FlowNetwork),
		overflow.WithNetworkHost(cfg.FlowAccessNode),
		overflow.WithLogNone(),
		overflow.WithReturnErrors(),
		overflow.WithEmbedFS(efs),
		overflow.WithBasePath(""),
	}

	if len(interceptors) > 0 {
		unaryOpt := grpc.WithChainUnaryInterceptor(interceptors...)
		overflowOptions = append(overflowOptions, overflow.WithGrpcDialOption(unaryOpt))
	}

	overflowOptions = append(overflowOptions, opt...)

	o := overflow.Overflow(overflowOptions...)
	if o.Error != nil {
		return nil, o.Error
	}
	return o, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants