Documentation
¶
Overview ¶
Package alerts delivers gateway alerts to their destinations: the generic signed JSON webhook, and the alert sinks a distribution registers.
Index ¶
Constants ¶
const ( // HeaderEvent carries the alert type, HeaderDelivery the alert ID. HeaderEvent = "X-GoModel-Event" HeaderDelivery = "X-GoModel-Delivery" // HeaderSignature carries "t=<unix seconds>,v1=<hex>": the time of the // attempt, and the hex HMAC-SHA256 of "<t>.<body>" keyed with the webhook // secret. Signing the time lets a receiver reject a replayed delivery // without parsing the body. A later scheme adds another "v<n>=" pair, so // receivers ignore pairs they do not know. It is sent only when a secret // is set. HeaderSignature = "X-GoModel-Signature" )
Headers of a webhook delivery.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Webhooks []WebhookConfig
Sinks []ext.AlertSink
// Timeout bounds one webhook attempt; MaxRetries is how often a failed
// one is tried again.
Timeout time.Duration
MaxRetries int
}
Config lists where alerts go.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher delivers alerts asynchronously. Notify never blocks on a destination.
func New ¶
func New(cfg Config) (*Dispatcher, error)
New starts a dispatcher for the configured destinations. It returns nil when there are none, so callers can skip alert evaluation entirely.
func (*Dispatcher) Close ¶
func (d *Dispatcher) Close() error
Close stops accepting alerts and gives queued ones drainTimeout to be delivered. It then cancels the deliveries in flight and abandons the rest of every queue; each alert it gives up on is logged and counted as a delivery failure. Those alerts were already claimed, so delivery is at most once. It is safe to call repeatedly.
Close always returns: a webhook attempt ends with its context, and a sink that does not is given up on after sinkReturnGrace, so Close takes at most drainTimeout plus sinkReturnGrace.
func (*Dispatcher) Notify ¶
func (d *Dispatcher) Notify(event ext.AlertEvent)
Notify queues event for every destination and returns at once.
type WebhookConfig ¶
WebhookConfig is one generic JSON webhook.