Documentation
¶
Index ¶
- type AlertDestination
- type AlertEmitter
- type AlertEvaluator
- type AlertMonitor
- type AlertOption
- func WithAlertThresholds(thresholds []int) AlertOption
- func WithAutoDisableFailureCount(count int) AlertOption
- func WithDeploymentID(deploymentID string) AlertOption
- func WithDisabler(disabler DestinationDisabler) AlertOption
- func WithEvaluator(evaluator AlertEvaluator) AlertOption
- func WithExhaustedRetriesIdempotence(idemp idempotence.Idempotence) AlertOption
- func WithLogger(logger *logging.Logger) AlertOption
- func WithStore(store AlertStore) AlertOption
- type AlertStore
- type ConsecutiveFailureData
- type ConsecutiveFailures
- type DeliveryAttempt
- type DestinationDisabledData
- type DestinationDisabler
- type ExhaustedRetriesData
Constants ¶
This section is empty.
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 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 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) (int, 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 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.