Documentation
¶
Overview ¶
Package retry provides utilities for retrying AWS API calls with exponential backoff.
Index ¶
- func DefaultBackoff() wait.Backoff
- func DefaultRetryableErrors(err error) bool
- func WithCategorizedRetry(ctx context.Context, logger logr.Logger, operation string, fn RetryableFunc) error
- func WithExponentialBackoff(ctx context.Context, logger logr.Logger, operation string, fn RetryableFunc, ...) error
- type CircuitBreaker
- type CircuitBreakerConfig
- type CircuitBreakerState
- type ErrorCategorizer
- type ErrorCategory
- type LegacyErrorCategorizer
- type RetryableFunc
- type Strategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultBackoff ¶
DefaultBackoff returns the default backoff configuration
func DefaultRetryableErrors ¶
DefaultRetryableErrors checks if an error is a retryable AWS error (legacy function)
func WithCategorizedRetry ¶ added in v1.3.3
func WithCategorizedRetry( ctx context.Context, logger logr.Logger, operation string, fn RetryableFunc, ) error
WithCategorizedRetry retries a function with category-specific backoff strategies
func WithExponentialBackoff ¶
func WithExponentialBackoff( ctx context.Context, logger logr.Logger, operation string, fn RetryableFunc, isRetryable LegacyErrorCategorizer, backoff wait.Backoff, ) error
WithExponentialBackoff retries a function with exponential backoff (legacy function)
Types ¶
type CircuitBreaker ¶ added in v1.3.3
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker implements the circuit breaker pattern for AWS operations
func NewCircuitBreaker ¶ added in v1.3.3
func NewCircuitBreaker(config *CircuitBreakerConfig, logger logr.Logger) *CircuitBreaker
NewCircuitBreaker creates a new circuit breaker
func (*CircuitBreaker) Execute ¶ added in v1.3.3
Execute executes a function with circuit breaker protection
func (*CircuitBreaker) GetState ¶ added in v1.3.3
func (cb *CircuitBreaker) GetState() CircuitBreakerState
GetState returns the current state of the circuit breaker
func (*CircuitBreaker) GetStats ¶ added in v1.3.3
func (cb *CircuitBreaker) GetStats() map[string]interface{}
GetStats returns statistics about the circuit breaker
func (*CircuitBreaker) IsOperationAllowed ¶ added in v1.3.3
func (cb *CircuitBreaker) IsOperationAllowed() bool
IsOperationAllowed checks if an operation would be allowed without executing it
func (*CircuitBreaker) Reset ¶ added in v1.3.3
func (cb *CircuitBreaker) Reset()
Reset resets the circuit breaker to closed state
type CircuitBreakerConfig ¶ added in v1.3.3
type CircuitBreakerConfig struct { // FailureThreshold is the number of consecutive failures before opening the circuit FailureThreshold int // SuccessThreshold is the number of consecutive successes needed to close the circuit from half-open SuccessThreshold int // Timeout is how long to wait before transitioning from open to half-open Timeout time.Duration // MaxConcurrentRequests is the maximum number of requests allowed in half-open state MaxConcurrentRequests int }
CircuitBreakerConfig holds configuration for the circuit breaker
func DefaultCircuitBreakerConfig ¶ added in v1.3.3
func DefaultCircuitBreakerConfig() *CircuitBreakerConfig
DefaultCircuitBreakerConfig returns a default circuit breaker configuration
type CircuitBreakerState ¶ added in v1.3.3
type CircuitBreakerState int
CircuitBreakerState represents the state of the circuit breaker
const ( // CircuitBreakerClosed - normal operation, requests are allowed CircuitBreakerClosed CircuitBreakerState = iota // CircuitBreakerOpen - circuit is open, requests are rejected CircuitBreakerOpen // CircuitBreakerHalfOpen - testing if the service has recovered CircuitBreakerHalfOpen )
type ErrorCategorizer ¶
type ErrorCategorizer func(error) ErrorCategory
ErrorCategorizer categorizes errors into different categories
type ErrorCategory ¶ added in v1.3.3
type ErrorCategory int
ErrorCategory represents different categories of errors
const ( // ErrorCategoryNonRetryable - errors that should not be retried ErrorCategoryNonRetryable ErrorCategory = iota // ErrorCategoryThrottling - rate limiting errors (long backoff) ErrorCategoryThrottling // ErrorCategoryTransient - temporary errors (medium backoff) ErrorCategoryTransient // ErrorCategoryNetwork - network-related errors (short backoff) ErrorCategoryNetwork // ErrorCategoryResource - resource-related errors (medium backoff) ErrorCategoryResource )
func CategorizeError ¶ added in v1.3.3
func CategorizeError(err error) ErrorCategory
CategorizeError categorizes an AWS error into appropriate retry category
type LegacyErrorCategorizer ¶ added in v1.3.3
LegacyErrorCategorizer categorizes errors as retryable or not (for backward compatibility)
type RetryableFunc ¶
RetryableFunc is a function that can be retried
func WithContext ¶
func WithContext(ctx context.Context, fn RetryableFunc) RetryableFunc
WithContext wraps a RetryableFunc with context cancellation
func WithLogging ¶
func WithLogging(logger logr.Logger, operation string, fn RetryableFunc) RetryableFunc
WithLogging wraps a RetryableFunc with logging
type Strategy ¶ added in v1.3.3
type Strategy struct { Category ErrorCategory Backoff wait.Backoff MaxAttempts int }
Strategy defines retry behavior for different error categories
func GetRetryStrategy ¶ added in v1.3.3
func GetRetryStrategy(category ErrorCategory) Strategy
GetRetryStrategy returns the appropriate retry strategy for an error category