Source File
retry.go
Belonging Package
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/retry
// Code generated by gotmpl. DO NOT MODIFY.// source: internal/shared/otlp/retry/retry.go.tmpl// Copyright The OpenTelemetry Authors// SPDX-License-Identifier: Apache-2.0// Package retry provides request retry functionality that can perform// configurable exponential backoff for transient errors and honor any// explicit throttle responses received.package retry // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/retry"import ()// DefaultConfig are the recommended defaults to use.var DefaultConfig = Config{Enabled: true,InitialInterval: 5 * time.Second,MaxInterval: 30 * time.Second,MaxElapsedTime: time.Minute,}// Config defines configuration for retrying batches in case of export failure// using an exponential backoff.type Config struct {// Enabled indicates whether to not retry sending batches in case of// export failure.Enabled bool// InitialInterval the time to wait after the first failure before// retrying.InitialInterval time.Duration// MaxInterval is the upper bound on backoff interval. Once this value is// reached the delay between consecutive retries will always be// `MaxInterval`.MaxInterval time.Duration// MaxElapsedTime is the maximum amount of time (including retries) spent// trying to send a request/batch. Once this value is reached, the data// is discarded.MaxElapsedTime time.Duration}// RequestFunc wraps a request with retry logic.type RequestFunc func(context.Context, func(context.Context) error) error// EvaluateFunc returns if an error is retry-able and if an explicit throttle// duration should be honored that was included in the error.//// The function must return true if the error argument is retry-able,// otherwise it must return false for the first return parameter.//// The function must return a non-zero time.Duration if the error contains// explicit throttle duration that should be honored, otherwise it must return// a zero valued time.Duration.type EvaluateFunc func(error) (bool, time.Duration)// RequestFunc returns a RequestFunc using the evaluate function to determine// if requests can be retried and based on the exponential backoff// configuration of c.func ( Config) ( EvaluateFunc) RequestFunc {if !.Enabled {return func( context.Context, func(context.Context) error) error {return ()}}return func( context.Context, func(context.Context) error) error {// Do not use NewExponentialBackOff since it calls Reset and the code here// must call Reset after changing the InitialInterval (this saves an// unnecessary call to Now).:= &backoff.ExponentialBackOff{InitialInterval: .InitialInterval,RandomizationFactor: backoff.DefaultRandomizationFactor,Multiplier: backoff.DefaultMultiplier,MaxInterval: .MaxInterval,}.Reset():= .MaxElapsedTime:= time.Now()for {:= ()if == nil {return nil}, := ()if ! {return}if != 0 && time.Since() > {return fmt.Errorf("max retry time elapsed: %w", )}// Wait for the greater of the backoff or throttle delay.:= .NextBackOff():= max(, ):= time.Since()if != 0 && + > {return fmt.Errorf("max retry time would elapse: %w", )}if := waitFunc(, ); != nil {return fmt.Errorf("%w: %w", , )}}}}// Allow override for testing.var waitFunc = wait// wait takes the caller's context, and the amount of time to wait. It will// return nil if the timer fires before or at the same time as the context's// deadline. This indicates that the call can be retried.func wait( context.Context, time.Duration) error {:= time.NewTimer()defer .Stop()select {case <-.Done():// Handle the case where the timer and context deadline end// simultaneously by prioritizing the timer expiration nil value// response.select {case <-.C:default:return context.Cause()}case <-.C:}return nil}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |