Documentation
¶
Overview ¶
Package forgeerr is the forge-neutral retry policy for forge requests that fail. A Failure is a classified forge error (the forge client produces it; for GitHub that is ghclient.Classify, reached through forge.Classify). Policy turns consecutive failures of one operation into the v1alpha1.ForgeError a controller records on its object: when to try again, with exponential backoff, and when to stop and wait for a human retry. It stops at once for a permanent failure, and when the retry window closes for a temporary one. Hint says what an operator should change before retrying.
The package is pure: it reads no clock of its own and talks to nothing. Rate limits are not its concern. They are known waits that controllers hold for (ghclient.LimitOf) without spending attempts.
Index ¶
Constants ¶
const ( WindowFlag = "forge-retry-window" WindowUsage = "how long a forge request failing for a temporary reason (a 5xx, a timeout) " + "is retried with backoff before it waits for a human retry; permanent failures " + "(a ruleset, a missing permission, an archived repository) wait at once" )
WindowFlag and WindowUsage define the --forge-retry-window flag every controller that calls the forge registers.
const ( // DefaultWindow is how long a temporary failure is retried before the // operation stalls for a human retry. DefaultWindow = time.Hour )
Retry policy defaults.
Variables ¶
This section is empty.
Functions ¶
func Backoff ¶
Backoff is the wait after the given number of consecutive failures: 30s, doubling, at most 10m.
func Hint ¶
Hint is what an operator should change before retrying operation after a failure of the given reason. exhausted marks a temporary failure whose retry window has closed. The wording follows the operation: what permission it needs, and how a person tries it again (a Retry on the finding, a new backfill, or cleaning up by hand after a demo reset).
func Tally ¶
Tally folds one more failed object into list, the summary of an operation's failures by reason (v1alpha1.ForgeErrorSummary): it adds to the entry for (operation, reason), or starts one. The list stays bounded however many objects fail: an entry keeps a count, the first message and at most MaxForgeErrorSamples distinct object names, and a list holds at most MaxForgeErrorSummaries entries (a failure of a new kind past that is left out; the caller's log line still names it). A tallied failure is one patchy will not retry, so a temporary one gets the exhausted hint.
Types ¶
type Failure ¶
type Failure struct {
// Reason is a v1alpha1.ForgeReason* constant.
Reason string
// Permanent marks a failure retrying cannot fix by itself.
Permanent bool
// Message is the forge's explanation, with its detail.
Message string
}
Failure is one classified forge error.
type Policy ¶
type Policy struct {
// Window bounds how long a temporary failure is retried, from its first
// failure. Zero means DefaultWindow.
Window time.Duration
}
Policy decides when a failing forge operation is tried again, and when it stops.
func (Policy) Record ¶
func (p Policy) Record(prev *v1alpha1.ForgeError, operation string, f Failure, now time.Time) v1alpha1.ForgeError
Record folds one more failure of operation into prev (the operation's current record, or nil) and returns the record to write. A failure of a different operation, or one after a stall a human has since cleared, starts a new run of attempts. The result has RetryAt set while the controller should try again by itself, and StalledAt set once it should not.
func (Policy) RetryWindow ¶
RetryWindow is how long a temporary failure is retried: Window, or DefaultWindow when it is unset.