Documentation
¶
Overview ¶
Package alert tracks delivery health per destination: consecutive-failure counting, alert thresholds, and retry exhaustion. It is a pure tracker — it returns signals as data and performs no side effects outside its own state. Acting on the signals (operator events, auto-disable, replay dedup) is the caller's job.
Index ¶
Constants ¶
const ( DefaultConsecutiveFailureCount = 100 DefaultExhaustedRetriesWindowSeconds = 3600 )
Default alert values, applied when the corresponding config value is unset.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlertStore ¶
type AlertStore interface {
// RecordConsecutiveFailure records a failed attempt and returns the
// destination's current consecutive-failure count. Recording is idempotent
// per attempt ID, so replays never double-count.
//
// Once the count reaches maxFailures, the first attempt to get there
// becomes the streak's max-failure holder; isMaxHolder is true for that
// attempt only, including its replays.
RecordConsecutiveFailure(ctx context.Context, tenantID, destinationID, attemptID string, maxFailures int) (count int, isMaxHolder bool, err error)
ResetConsecutiveFailureCount(ctx context.Context, tenantID, destinationID string) error
}
AlertStore persists the tracker's own state: the consecutive-failure streak per destination.
func NewRedisAlertStore ¶
func NewRedisAlertStore(client redis.Cmdable, deploymentID string) AlertStore
NewRedisAlertStore creates a new Redis-backed alert store
type Attempt ¶ added in v1.1.0
type Attempt struct {
TenantID string
DestinationID string
AttemptID string
Number int // 1-indexed attempt number
Success bool
EligibleForRetry bool
// AttemptMax is the attempt count the delivery was allowed (retries + 1);
// 0 uses the evaluator's retry limit.
AttemptMax int
// NonRetryable: no further automatic retry follows this failed attempt.
NonRetryable bool
// SkipFailureCount keeps a failed attempt out of the consecutive-failure
// count: it neither increments nor resets it.
SkipFailureCount bool
}
Attempt is the tracker's input: the identity and outcome of one delivery attempt, nothing more.
type ConsecutiveFailureSetting ¶ added in v1.0.6
ConsecutiveFailureSetting controls consecutive-failure alerting. When Enabled is false the monitor never tracks or alerts on consecutive failures, and therefore never auto-disables a destination regardless of AutoDisableDestination.
type ConsecutiveFailureSignal ¶ added in v1.1.0
type ConsecutiveFailureSignal struct {
Failures int // current consecutive-failure count
Max int // configured 100%-threshold failure count
Level int // crossed threshold's percentage (e.g. 50/70/90/100)
}
ConsecutiveFailureSignal reports a crossed consecutive-failure threshold.
type Evaluation ¶ added in v1.1.0
type Evaluation struct {
// ConsecutiveFailure is non-nil when this attempt's consecutive-failure
// count crossed an alert threshold. Each threshold is reported once per
// failure streak.
ConsecutiveFailure *ConsecutiveFailureSignal
// RetriesExhausted reports that this attempt exceeded the retry budget for
// a retry-eligible event.
RetriesExhausted bool
}
Evaluation is the tracker's verdict on one attempt: one field per signal kind, nil/false when that kind has nothing to report. An attempt can carry several signals at once. Zero value = nothing to report (success, or a failure that crossed no threshold and exhausted no retries).
type Evaluator ¶ added in v1.1.0
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator evaluates delivery attempts against the destination's failure history and returns the resulting signals as data.
func NewEvaluator ¶ added in v1.1.0
func NewEvaluator(store AlertStore, retryMaxLimit int, opts ...Option) *Evaluator
NewEvaluator creates a new alert evaluator on the given store.
func (*Evaluator) SignalsEnabled ¶ added in v1.1.0
SignalsEnabled reports whether any signal can ever fire: consecutive-failure tracking, or exhausted-retries with a positive retry limit (global, or per attempt). When false, Evaluate never touches the store and always returns an empty verdict.
type ExhaustedRetriesSetting ¶ added in v1.0.6
ExhaustedRetriesSetting controls exhausted-retries alerting. When Enabled is false the monitor never emits exhausted_retries alerts. WindowSeconds is the suppression window for duplicate alerts; 0 means no suppression (alert on every exhaustion).
type Option ¶ added in v1.1.0
type Option func(*Evaluator)
Option configures an evaluator.
func WithAlertThresholds ¶
WithAlertThresholds sets the percentage thresholds at which alerts fire.
func WithAutoDisableFailureCount ¶
WithAutoDisableFailureCount sets the consecutive-failure count that means 100% — the denominator for threshold math.
func WithConsecutiveFailureEnabled ¶ added in v1.0.6
WithConsecutiveFailureEnabled toggles consecutive-failure tracking. When set to false the evaluator never tracks failures or crosses thresholds. Defaults to true.
func WithExhaustedRetriesEnabled ¶ added in v1.0.6
WithExhaustedRetriesEnabled toggles the retry-exhaustion signal. Defaults to true.
func WithPerAttemptRetryLimits ¶ added in v1.9.0
func WithPerAttemptRetryLimits() Option
WithPerAttemptRetryLimits declares that attempts carry their own retry limit (Attempt.AttemptMax), so exhausted retries can fire even when the global retry limit is 0.
type Settings ¶ added in v1.0.6
type Settings struct {
ConsecutiveFailure ConsecutiveFailureSetting
ExhaustedRetries ExhaustedRetriesSetting
AutoDisableDestination bool
}
Settings is the resolved, operational alert configuration consumed by the service builder. The config package produces it from raw env/yaml values via AlertConfig.ToConfig, so the rest of the codebase never deals with the raw unset / empty / value strings.