alert

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

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 AlertDestination added in v0.2.1

type AlertDestination struct {
	ID         string        `json:"id" redis:"id"`
	TenantID   string        `json:"tenant_id" redis:"-"`
	Type       string        `json:"type" redis:"type"`
	Topics     models.Topics `json:"topics" redis:"-"`
	Config     models.Config `json:"config" redis:"-"`
	CreatedAt  time.Time     `json:"created_at" redis:"created_at"`
	DisabledAt *time.Time    `json:"disabled_at" redis:"disabled_at"`
}

AlertDestination is the destination data included in alert event payloads.

func AlertDestinationFromDestination added in v0.16.0

func AlertDestinationFromDestination(d *models.Destination) *AlertDestination

AlertDestinationFromDestination converts a models.Destination to an AlertDestination.

type AlertEmitter added in v0.16.0

type AlertEmitter interface {
	Emit(ctx context.Context, topic string, tenantID string, data any) error
}

AlertEmitter is the interface for emitting alert events. Satisfied by opevents.Emitter.

type AlertEvaluator

type AlertEvaluator interface {
	// ShouldAlert determines if an alert should be sent and returns the alert level
	ShouldAlert(failures int) (level int, shouldAlert bool)
}

AlertEvaluator determines when alerts should be triggered

func NewAlertEvaluator

func NewAlertEvaluator(thresholds []int, autoDisableFailureCount int) AlertEvaluator

NewAlertEvaluator creates a new alert evaluator

type AlertMonitor

type AlertMonitor interface {
	HandleAttempt(ctx context.Context, attempt DeliveryAttempt) error
}

AlertMonitor is the main interface for handling delivery attempt alerts

func NewAlertMonitor

func NewAlertMonitor(logger *logging.Logger, redisClient redis.Cmdable, emitter AlertEmitter, retryMaxLimit int, opts ...AlertOption) AlertMonitor

NewAlertMonitor creates a new alert monitor. Emitter and retryMaxLimit are required — callers that don't need alerts should pass nil AlertMonitor to consumers instead.

type AlertOption

type AlertOption func(*alertMonitor)

AlertOption is a function that configures an AlertConfig

func WithAlertThresholds

func WithAlertThresholds(thresholds []int) AlertOption

WithAlertThresholds sets the percentage thresholds at which to send alerts

func WithAutoDisableFailureCount

func WithAutoDisableFailureCount(count int) AlertOption

WithAutoDisableFailureCount sets the number of consecutive failures before auto-disabling

func WithConsecutiveFailureEnabled added in v1.0.6

func WithConsecutiveFailureEnabled(enabled bool) AlertOption

WithConsecutiveFailureEnabled toggles consecutive-failure alerting. When set to false the monitor never tracks or alerts on consecutive failures (and therefore never auto-disables). Defaults to true.

func WithDeploymentID added in v0.7.0

func WithDeploymentID(deploymentID string) AlertOption

WithDeploymentID sets the deployment ID for the monitor

func WithDisabler

func WithDisabler(disabler DestinationDisabler) AlertOption

WithDisabler sets the destination disabler for the monitor. When set, destinations are auto-disabled at the 100% failure threshold.

func WithEvaluator

func WithEvaluator(evaluator AlertEvaluator) AlertOption

WithEvaluator sets the alert evaluator for the monitor

func WithExhaustedRetriesEnabled added in v1.0.6

func WithExhaustedRetriesEnabled(enabled bool) AlertOption

WithExhaustedRetriesEnabled toggles exhausted_retries alerting. When set to false the monitor never emits exhausted_retries alerts. Defaults to true.

func WithExhaustedRetriesIdempotence added in v0.16.0

func WithExhaustedRetriesIdempotence(idemp idempotence.Idempotence) AlertOption

WithExhaustedRetriesIdempotence sets the idempotence instance for exhausted_retries suppression. When set, only the first exhaustion per destination within the TTL window emits an alert.

func WithLogger

func WithLogger(logger *logging.Logger) AlertOption

WithLogger sets the logger for the monitor

func WithStore

func WithStore(store AlertStore) AlertOption

WithStore sets the alert store for the monitor

type AlertStore

type AlertStore interface {
	IncrementConsecutiveFailureCount(ctx context.Context, tenantID, destinationID, attemptID string) (FailureCountResult, error)
	// MarkAttemptEvaluated records that an attempt's alert evaluation fully
	// completed, so replays (MQ redelivery, producer re-publish) can skip
	// re-evaluating it.
	MarkAttemptEvaluated(ctx context.Context, tenantID, destinationID, attemptID string) error
	ResetConsecutiveFailureCount(ctx context.Context, tenantID, destinationID string) error
}

AlertStore manages alert-related data persistence

func NewRedisAlertStore

func NewRedisAlertStore(client redis.Cmdable, deploymentID string) AlertStore

NewRedisAlertStore creates a new Redis-backed alert store

type ConsecutiveFailureData

type ConsecutiveFailureData struct {
	TenantID            string              `json:"tenant_id"`
	Event               *models.Event       `json:"event"`
	Attempt             *models.Attempt     `json:"attempt"`
	Destination         *AlertDestination   `json:"destination"`
	ConsecutiveFailures ConsecutiveFailures `json:"consecutive_failures"`
}

ConsecutiveFailureData is the data payload for alert.destination.consecutive_failure events.

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 ConsecutiveFailures added in v0.16.0

type ConsecutiveFailures struct {
	Current   int `json:"current"`
	Max       int `json:"max"`
	Threshold int `json:"threshold"`
}

ConsecutiveFailures represents the nested consecutive failure state.

type DeliveryAttempt

type DeliveryAttempt struct {
	Event       *models.Event
	Destination *AlertDestination
	Attempt     *models.Attempt
}

DeliveryAttempt represents a single delivery attempt

type DestinationDisabledData added in v0.16.0

type DestinationDisabledData struct {
	TenantID    string            `json:"tenant_id"`
	Destination *AlertDestination `json:"destination"`
	DisabledAt  time.Time         `json:"disabled_at"`
	Reason      string            `json:"reason"`
	Event       *models.Event     `json:"event"`
	Attempt     *models.Attempt   `json:"attempt"`
}

DestinationDisabledData is the data payload for alert.destination.disabled events.

type DestinationDisabler

type DestinationDisabler interface {
	DisableDestination(ctx context.Context, tenantID, destinationID string) error
}

DestinationDisabler handles disabling destinations.

type ExhaustedRetriesData added in v0.16.0

type ExhaustedRetriesData struct {
	TenantID    string            `json:"tenant_id"`
	Event       *models.Event     `json:"event"`
	Attempt     *models.Attempt   `json:"attempt"`
	Destination *AlertDestination `json:"destination"`
}

ExhaustedRetriesData is the data payload for alert.attempt.exhausted_retries events.

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 FailureCountResult added in v1.0.5

type FailureCountResult struct {
	Count            int  // current consecutive failure count
	NewlyCounted     bool // attempt was not previously counted (first delivery of this attempt)
	AlreadyEvaluated bool // attempt was fully evaluated before (marked via MarkAttemptEvaluated)
}

FailureCountResult reports the state of consecutive-failure tracking after recording an attempt.

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