alerts

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package alerts delivers gateway alerts to their destinations: the generic signed JSON webhook, and the alert sinks a distribution registers.

Index

Constants

View Source
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

func Sign

func Sign(secret []byte, t time.Time, body []byte) string

Sign returns the HeaderSignature value of body sent at t: "t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<body>" keyed with secret>".

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

type WebhookConfig struct {
	URL string
	// Secret signs each delivery when set.
	Secret string
}

WebhookConfig is one generic JSON webhook.

Jump to

Keyboard shortcuts

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