Documentation ¶
Overview ¶
Package retry defines a general library to handle errors and retries for various Azure clients.
Index ¶
- Constants
- Variables
- func DoExponentialBackoffRetry(backoff *Backoff) autorest.SendDecorator
- func DoFilterOutNonRetriableError(shouldRetry func(rerr *Error) bool) autorest.SendDecorator
- func GetVMSSMetadataByRawError(err *Error) (string, string, error)
- func HasStatusForbiddenOrIgnoredError(err error) bool
- func IsErrorRetriable(err error) bool
- func IsInHTTPStatusCodeSet(rerr *Error, httpStatusCodes []int) bool
- type Backoff
- type Error
- func GetError(resp *http.Response, err error) *Error
- func GetRateLimitError(isWrite bool, opName string) *Error
- func GetRetriableError(err error) *Error
- func GetStatusNotFoundAndForbiddenIgnoredError(resp *http.Response, err error) *Error
- func GetThrottlingError(operation, reason string, retryAfter time.Time) *Error
- func NewError(retriable bool, err error) *Error
- func NewErrorOrNil(retriable bool, err error) *Error
- type PartialUpdateError
- type ServiceRawError
Constants ¶
const ( // OperationNotAllowed is an umbrella errrfor a lot of errors OperationNotAllowed string = "OperationNotAllowed" // QuotaExceeded falls under OperationNotAllowed error code but we make it more specific here QuotaExceeded string = "QuotaExceeded" )
const RateLimited = "rate limited"
RateLimited error string
Variables ¶
var ( // StatusCodesForRetry are a defined group of status code for which the client will retry. StatusCodesForRetry = []int{ http.StatusRequestTimeout, http.StatusInternalServerError, http.StatusBadGateway, http.StatusServiceUnavailable, http.StatusGatewayTimeout, } )
Functions ¶
func DoExponentialBackoffRetry ¶
func DoExponentialBackoffRetry(backoff *Backoff) autorest.SendDecorator
DoExponentialBackoffRetry represents an autorest.SendDecorator with backoff retry.
func DoFilterOutNonRetriableError ¶ added in v1.24.3
func DoFilterOutNonRetriableError(shouldRetry func(rerr *Error) bool) autorest.SendDecorator
DoFilterOutNonRetriableError decorator works with autorest.DoRetryForAttempts
func GetVMSSMetadataByRawError ¶ added in v0.7.3
GetVMSSMetadataByRawError gets the vmss name by parsing the error message
func HasStatusForbiddenOrIgnoredError ¶
HasStatusForbiddenOrIgnoredError return true if the given error code is part of the error message This should only be used when trying to delete resources
func IsErrorRetriable ¶
IsErrorRetriable returns true if the error is retriable.
func IsInHTTPStatusCodeSet ¶ added in v1.24.3
IsInHTTPStatusCodeSet return true when status code falls in the status code list It is used with doBackoffRetry to retry on some HTTPStatusCodes.
Types ¶
type Backoff ¶
type Backoff struct { // The initial duration. Duration time.Duration // Duration is multiplied by factor each iteration, if factor is not zero // and the limits imposed by Steps and Cap have not been reached. // Should not be negative. // The jitter does not contribute to the updates to the duration parameter. Factor float64 // The sleep at each iteration is the duration plus an additional // amount chosen uniformly at random from the interval between // zero and `jitter*duration`. Jitter float64 // The remaining number of iterations in which the duration // parameter may change (but progress can be stopped earlier by // hitting the cap). If not positive, the duration is not // changed. Used for exponential backoff in combination with // Factor and Cap. Steps int // A limit on revised values of the duration parameter. If a // multiplication by the factor parameter would make the duration // exceed the cap then the duration is set to the cap and the // steps parameter is set to zero. Cap time.Duration // The errors indicate that the request shouldn't do more retrying. NonRetriableErrors []string // The RetriableHTTPStatusCodes indicates that the HTTPStatusCode should do more retrying. RetriableHTTPStatusCodes []int }
Backoff holds parameters applied to a Backoff function.
func NewBackoff ¶
func NewBackoff(duration time.Duration, factor float64, jitter float64, steps int, cap time.Duration) *Backoff
NewBackoff creates a new Backoff.
func (*Backoff) Step ¶
Step (1) returns an amount of time to sleep determined by the original Duration and Jitter and (2) mutates the provided Backoff to update its Steps and Duration.
func (*Backoff) WithNonRetriableErrors ¶
WithNonRetriableErrors returns a new *Backoff with NonRetriableErrors assigned.
func (*Backoff) WithRetriableHTTPStatusCodes ¶
WithRetriableHTTPStatusCodes returns a new *Backoff with RetriableHTTPStatusCode assigned.
type Error ¶
type Error struct { // Retriable indicates whether the request is retriable. Retriable bool // HTTPStatusCode indicates the response HTTP status code. HTTPStatusCode int // RetryAfter indicates the time when the request should retry after throttling. // A throttled request is retriable. RetryAfter time.Time // RetryAfter indicates the raw error from API. RawError error }
Error indicates an error returned by Azure APIs.
func GetRateLimitError ¶
GetRateLimitError creates a new error for rate limiting.
func GetRetriableError ¶
GetRetriableError gets new retriable Error.
func GetStatusNotFoundAndForbiddenIgnoredError ¶
GetStatusNotFoundAndForbiddenIgnoredError gets an error with StatusNotFound and StatusForbidden ignored. It is only used in DELETE operations.
func GetThrottlingError ¶
GetThrottlingError creates a new error for throttling.
func NewErrorOrNil ¶ added in v1.0.13
NewError creates a new Error. Returns nil if err is nil
func (*Error) Error ¶
Error returns the error. Note that Error doesn't implement error interface because (nil *Error) != (nil error).
func (*Error) IsNotFound ¶
IsNotFound returns true the if the requested object wasn't found
func (*Error) IsThrottled ¶
IsThrottled returns true the if the request is being throttled.
func (*Error) ServiceErrorCode ¶ added in v1.0.13
ServiceErrorCode returns the code associated with the autorest.ServiceError body
func (*Error) ServiceErrorMessage ¶ added in v1.0.13
ServiceErrorMessage returns the message associated with the autorest.ServiceError body
type PartialUpdateError ¶ added in v1.27.0
type PartialUpdateError struct {
// contains filtered or unexported fields
}
PartialUpdateError implements error interface. It is meant to be returned for errors with http status code of 2xx
func NewPartialUpdateError ¶ added in v1.27.0
func NewPartialUpdateError(msg string) *PartialUpdateError
func (*PartialUpdateError) Error ¶ added in v1.27.0
func (e *PartialUpdateError) Error() string
type ServiceRawError ¶ added in v1.0.13
type ServiceRawError struct {
ServiceError *azure.ServiceError `json:"error,omitempty"`
}
ServiceRawError wraps the RawError field satisfying autorest.ServiceError