alert

package
v0.1.0-alpha.10 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert interface {
	json.Marshaler
}

Alert represents any alert that can be sent

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.Client, opts ...AlertOption) AlertMonitor

NewAlertMonitor creates a new alert monitor with default implementations

type AlertNotifier

type AlertNotifier interface {
	// Notify sends an alert to the configured callback URL
	Notify(ctx context.Context, alert Alert) error
}

AlertNotifier sends alerts to configured destinations

func NewHTTPAlertNotifier

func NewHTTPAlertNotifier(callbackURL string, opts ...NotifierOption) AlertNotifier

NewHTTPAlertNotifier creates a new HTTP-based alert notifier

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 WithDisabler

func WithDisabler(disabler DestinationDisabler) AlertOption

WithDisabler sets the destination disabler for the monitor

func WithEvaluator

func WithEvaluator(evaluator AlertEvaluator) AlertOption

WithEvaluator sets the alert evaluator for the monitor

func WithLogger

func WithLogger(logger *logging.Logger) AlertOption

WithLogger sets the logger for the monitor

func WithNotifier

func WithNotifier(notifier AlertNotifier) AlertOption

WithNotifier sets the alert notifier 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 string) (int, error)
	ResetConsecutiveFailureCount(ctx context.Context, tenantID, destinationID string) error
}

AlertStore manages alert-related data persistence

func NewRedisAlertStore

func NewRedisAlertStore(client *redis.Client) AlertStore

NewRedisAlertStore creates a new Redis-backed alert store

type ConsecutiveFailureAlert

type ConsecutiveFailureAlert struct {
	Topic     string                 `json:"topic"`
	Timestamp time.Time              `json:"timestamp"`
	Data      ConsecutiveFailureData `json:"data"`
}

ConsecutiveFailureAlert represents an alert for consecutive failures

func NewConsecutiveFailureAlert

func NewConsecutiveFailureAlert(data ConsecutiveFailureData) ConsecutiveFailureAlert

NewConsecutiveFailureAlert creates a new consecutive failure alert with defaults

func (ConsecutiveFailureAlert) MarshalJSON

func (a ConsecutiveFailureAlert) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

type ConsecutiveFailureData

type ConsecutiveFailureData struct {
	MaxConsecutiveFailures int                    `json:"max_consecutive_failures"`
	ConsecutiveFailures    int                    `json:"consecutive_failures"`
	WillDisable            bool                   `json:"will_disable"`
	Destination            *models.Destination    `json:"destination"`
	Data                   map[string]interface{} `json:"data"`
}

ConsecutiveFailureData represents the data needed for a consecutive failure alert

type DeliveryAttempt

type DeliveryAttempt struct {
	Success       bool
	DeliveryEvent *models.DeliveryEvent
	Destination   *models.Destination
	Timestamp     time.Time
	Data          map[string]interface{}
}

DeliveryAttempt represents a single delivery attempt

type DestinationDisabler

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

DestinationDisabler handles disabling destinations

type NotifierOption

type NotifierOption func(n *httpAlertNotifier)

NotifierOption configures an AlertNotifier

func NotifierWithBearerToken

func NotifierWithBearerToken(token string) NotifierOption

func NotifierWithTimeout

func NotifierWithTimeout(timeout time.Duration) NotifierOption

NotifierWithTimeout sets the timeout for alert notifications. If timeout is 0, it defaults to 30 seconds.

Jump to

Keyboard shortcuts

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