Documentation
¶
Overview ¶
Package serverlesshttp provides an http.RoundTripper that retries 429 Too Many Requests responses from the Elastic Cloud Serverless API.
Only 429 is retried. The Serverless API does not document a Retry-After header, so retries use self-paced exponential backoff with jitter. All other responses (including 5xx) are returned to the caller untouched, which avoids any idempotency concerns around retrying write methods.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*RetryTransport)
Option configures a RetryTransport.
func WithBaseBackoff ¶
WithBaseBackoff sets the initial backoff duration.
func WithMaxAttempts ¶
WithMaxAttempts sets the total number of attempts including the first.
func WithMaxBackoff ¶
WithMaxBackoff caps the backoff duration.
func WithNext ¶
func WithNext(next http.RoundTripper) Option
WithNext sets the underlying transport.
type RetryTransport ¶
type RetryTransport struct {
// Next is the underlying transport. Defaults to http.DefaultTransport.
Next http.RoundTripper
// MaxAttempts is the total number of attempts including the first. A
// value of 1 disables retries. Defaults to 5.
MaxAttempts int
// BaseBackoff is the initial backoff duration. Defaults to 1 second.
BaseBackoff time.Duration
// MaxBackoff caps the backoff duration. Defaults to 30 seconds.
MaxBackoff time.Duration
}
RetryTransport retries 429 Too Many Requests responses with bounded exponential backoff and jitter.
func New ¶
func New(opts ...Option) *RetryTransport
New returns a RetryTransport wrapping the given transport (or http.DefaultTransport if next is nil) with sensible defaults.