alert

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

View Source
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 {
	// IncrementConsecutiveFailureCount records a failed attempt and returns the
	// destination's current consecutive-failure count. Recording is idempotent
	// per attempt ID, so replays never double-count.
	IncrementConsecutiveFailureCount(ctx context.Context, tenantID, destinationID, attemptID string) (int, error)
	ResetConsecutiveFailureCount(ctx context.Context, tenantID, destinationID string) error
}

AlertStore persists the tracker's own state: the consecutive-failure count 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
}

Attempt is the tracker's input: the identity and outcome of one delivery attempt, nothing more.

type ConsecutiveFailureSetting added in v1.0.6

type ConsecutiveFailureSetting struct {
	Enabled bool
	Count   int
}

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.
	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) Evaluate added in v1.1.0

func (e *Evaluator) Evaluate(ctx context.Context, attempt Attempt) (Evaluation, error)

func (*Evaluator) SignalsEnabled added in v1.1.0

func (e *Evaluator) SignalsEnabled() bool

SignalsEnabled reports whether any signal can ever fire: consecutive-failure tracking, or exhausted-retries with a positive retry limit. When false, Evaluate never touches the store and always returns an empty verdict.

type ExhaustedRetriesSetting added in v1.0.6

type ExhaustedRetriesSetting struct {
	Enabled       bool
	WindowSeconds int
}

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

func WithAlertThresholds(thresholds []int) Option

WithAlertThresholds sets the percentage thresholds at which alerts fire.

func WithAutoDisableFailureCount

func WithAutoDisableFailureCount(count int) Option

WithAutoDisableFailureCount sets the consecutive-failure count that means 100% — the denominator for threshold math.

func WithConsecutiveFailureEnabled added in v1.0.6

func WithConsecutiveFailureEnabled(enabled bool) Option

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

func WithExhaustedRetriesEnabled(enabled bool) Option

WithExhaustedRetriesEnabled toggles the retry-exhaustion signal. Defaults to true.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL