alerting

package
v0.0.1-dev.137 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package alerting is the RuneSight alerter: it evaluates stored alert rules against the cluster's LogStore on a rolling cadence, drives the ok → pending → firing → resolved state machine, and notifies on transitions (a Rune event always; the rule's channels on firing/resolved).

Rules are Core-tier by construction — a LogQL log selector counted over a window and compared to a threshold — so alerting behaves identically on the embedded, Loki, and ClickHouse backends. Absence/heartbeat alerts are the `== 0` (or `< 1`) case of the same shape.

Status is held in memory: a restart re-evaluates every rule within one interval, which is the operationally correct recovery anyway. Transitions are also recorded as Rune events, so history survives in the event log.

Index

Constants

View Source
const (
	// DefaultInterval is the evaluation cadence for rules that don't set one.
	DefaultInterval = 60 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Alerter

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

Alerter evaluates rules and dispatches notifications.

func New

func New(opts Options) *Alerter

New constructs an Alerter. Call Start to begin the loop; Tick is exposed for tests and embedded callers.

func (*Alerter) Start

func (a *Alerter) Start(ctx context.Context)

Start runs the evaluation loop until Stop. Non-blocking.

func (*Alerter) Statuses

func (a *Alerter) Statuses() []Status

Statuses returns a snapshot of every known rule status, sorted by rule name.

func (*Alerter) Stop

func (a *Alerter) Stop()

Stop halts the loop. Safe to call multiple times.

func (*Alerter) Tick

func (a *Alerter) Tick(ctx context.Context)

Tick evaluates every due rule once. Exposed for tests.

type ChannelSource

type ChannelSource interface {
	Get(ctx context.Context, name string) (*types.Channel, error)
}

ChannelSource resolves channel names (implemented by repos.ChannelRepo).

type EventSink

type EventSink interface {
	Emit(ctx context.Context, e types.Event) error
}

EventSink receives alert-transition events (implemented by events.EventLog).

type Options

type Options struct {
	Store    observe.LogStore
	Rules    RuleSource
	Channels ChannelSource
	Events   EventSink
	Secrets  SecretLookup
	Logger   log.Logger
	// Now lets tests inject a clock.
	Now func() time.Time
}

Options configures the Alerter. Store and Rules are required; the rest are optional (nil EventSink/SecretLookup degrade gracefully).

type RuleSource

type RuleSource interface {
	List(ctx context.Context) ([]*types.AlertRule, error)
}

RuleSource lists the alert rules to evaluate (implemented by repos.AlertRuleRepo).

type SecretLookup

type SecretLookup func(ctx context.Context, namespace, name, key string) (string, error)

SecretLookup resolves ${secret:namespace/name/key} references in channel URLs and headers at send time. Mirrors driverparams.SecretLookup.

type Status

type Status struct {
	Rule  string
	State string // ok | pending | firing
	// Value is the last evaluated windowed count.
	Value float64
	// Since is when the current State began.
	Since time.Time
	// LastEval is the last evaluation time.
	LastEval time.Time
	// LastError is the last evaluation or delivery error ("" when healthy).
	LastError string
}

Status is a rule's live evaluation state.

Jump to

Keyboard shortcuts

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