alerts

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package alerts derives bounded alert inputs from validated operational snapshots without delivering notifications or storing time series. Evaluate borrows one validated tenant snapshot and explicit Policy, returning independent alert values in input/category order. Unsupported measurements are not evidence of zero. NewTelemetryExporter borrows a synchronous meter; callers own scheduling, provider blocking/concurrency and exporter shutdown.

Index

Constants

View Source
const (
	// MaxWorkers bounds one evaluation pass.
	MaxWorkers = 10_000
	// MaxCommands bounds one evaluation pass.
	MaxCommands = 1_000
)
View Source
const (
	// MaxAlertBatch bounds one synchronous telemetry export call.
	MaxAlertBatch = 12_000
)

Variables

View Source
var (
	// ErrInvalidInput reports malformed or unbounded operational input.
	ErrInvalidInput = errors.New("alerts: invalid input")
	// ErrInvalidPolicy reports an impossible alert threshold.
	ErrInvalidPolicy = errors.New("alerts: invalid policy")
)
View Source
var (
	// ErrInvalidTelemetryConfiguration reports an unusable metric provider.
	ErrInvalidTelemetryConfiguration = errors.New("alerts: invalid telemetry configuration")
	// ErrInvalidAlertBatch reports malformed, empty, canceled, or unbounded export input.
	ErrInvalidAlertBatch = errors.New("alerts: invalid alert batch")
)

Functions

This section is empty.

Types

type Alert

type Alert struct {
	// Kind selects a supported public alert category.
	Kind Kind `json:"kind"`
	// TenantID is scoped attribution retained for platform consumers, but
	// omitted from TelemetryExporter labels.
	TenantID string `json:"tenant_id"`
	// Resource identifies the breached queue/worker/command or aggregate count
	// category.
	Resource string `json:"resource"`
	// Value is a nonnegative observed count or seconds value; large uint64
	// counts may round in float64.
	Value float64 `json:"value"`
	// Threshold is the strict upper count/seconds threshold; status alerts use
	// zero.
	Threshold float64 `json:"threshold"`
	// ObservedAt is the UTC source/command/input observation time appropriate
	// to the category.
	ObservedAt time.Time `json:"observed_at"`
}

Alert is a backend-neutral threshold breach suitable for telemetry export.

func Evaluate

func Evaluate(input Input, policy Policy) ([]Alert, error)

Evaluate returns deterministic alert inputs for enabled threshold breaches.

type Input

type Input struct {
	// TenantID is required bounded scope and must match all supplied
	// worker/command records.
	TenantID string
	// ObservedAt is required observation time for count and stale-worker
	// alerts.
	ObservedAt time.Time
	// Queues is a validated bounded queue-status page; unsupported age
	// measurements produce no alert.
	Queues queue.QueueStatusPage
	// Workers contains at most MaxWorkers validated scoped reports with derived
	// state.
	Workers fleet.RegistrySnapshot
	// Failures is an optional supported aggregate count; unsupported data is
	// not treated as zero evidence.
	Failures queue.Measurement[uint64]
	// DeadLetters is an optional supported aggregate dead-letter count.
	DeadLetters queue.Measurement[uint64]
	// Commands contains at most MaxCommands validated scoped outcomes; slices
	// remain caller-owned during Evaluate.
	Commands []controlplane.CommandResult
}

Input is one tenant's bounded current operational snapshot.

type Kind

type Kind string

Kind identifies a stable platform alert input.

const (
	// KindQueueWait identifies supported oldest-age measurements strictly above
	// the configured duration.
	KindQueueWait Kind = "queue_wait"
	// KindFailureCount identifies supported failure counts strictly above the
	// configured count.
	KindFailureCount Kind = "failure_count"
	// KindStaleWorker identifies a derived stale worker when that category is
	// enabled.
	KindStaleWorker Kind = "stale_worker"
	// KindDeadLetterCount identifies supported dead-letter counts strictly
	// above the configured count.
	KindDeadLetterCount Kind = "dead_letter_count"
	// KindCommandFailure identifies failed or unknown command results, not
	// every unsuccessful status.
	KindCommandFailure Kind = "command_failure"
)

type Policy

type Policy struct {
	// MaxQueueWait enables supported oldest-age alerts when positive; zero
	// disables and negative values fail.
	MaxQueueWait time.Duration
	// MaxFailures enables strictly greater supported count alerts when nonzero.
	MaxFailures uint64
	// MaxDeadLetters enables strictly greater supported dead-letter count
	// alerts when nonzero.
	MaxDeadLetters uint64
	// StaleWorkers enables one alert per derived stale worker.
	StaleWorkers bool
	// CommandFailures enables one alert per failed or unknown command.
	CommandFailures bool
}

Policy enables alert categories and declares strict upper thresholds. Zero count or duration thresholds disable the corresponding category.

type TelemetryExporter

type TelemetryExporter struct {
	// contains filtered or unexported fields
}

TelemetryExporter emits fixed-cardinality alert counts through the caller's telemetry meter. Tenant and resource identities are intentionally absent.

func NewTelemetryExporter

func NewTelemetryExporter(meter metric.Meter) (*TelemetryExporter, error)

NewTelemetryExporter creates the bounded platform alert metric bridge.

func (*TelemetryExporter) Export

func (e *TelemetryExporter) Export(ctx context.Context, alerts []Alert) error

Export validates one bounded evaluation result and increments only stable kind labels. Delivery and scheduling remain owned by the platform caller.

Jump to

Keyboard shortcuts

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