aggregator

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0 Imports: 14 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 aggregator derives the consensus status of the monitors from the heartbeats of all responsible nodes and records status changes and incidents via Raft (FA-CON-01/02/03/05/06, FA-INC-01, ADR 0021).

Every voter runs an Aggregator, but only the leader evaluates: it evaluates each check round (slot) of a monitor exactly once, when all responsible nodes reported or at the deadline. A new leader waits for a grace period, then rebuilds the streaks from the stored heartbeats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregator

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

Aggregator evaluates the rounds of all monitors while it is the leader.

func New

func New(opts Options) *Aggregator

New creates an Aggregator; call Run to start it.

func (*Aggregator) ClearHandOvers

func (a *Aggregator) ClearHandOvers()

ClearHandOvers drops all recorded handover points (a new gap job run starts).

func (*Aggregator) Deviation

func (a *Aggregator) Deviation(sinceMs int64) map[string]DeviationStats

Deviation returns the deviation statistics of every node for the slots that start at or after sinceMs (ADR 0022). Only the leader counts; a node that has no counted slot is absent from the map. sinceMs may reach back at most deviationWindow.

func (*Aggregator) HandOver

func (a *Aggregator) HandOver(tenantID, monitorID string, toMs int64)

HandOver records toMs as the end of the window the gap job re-evaluated for a monitor (ADR 0033). The next rebuild of that monitor replays the slots from toMs on, even if they lie before the usual lookback, so that no slot between the gap job and the live evaluation stays unevaluated. It is used once. A loss of leadership keeps it, because the gap job of the next leadership may record it before this aggregator noticed the loss; the gap job drops stale points with ClearHandOvers when its leadership starts.

func (*Aggregator) Observe

func (a *Aggregator) Observe(hbs []store.Heartbeat)

Observe passes heartbeats that were stored (local, replicated or by anti-entropy). It never blocks: a batch that does not fit into the queue is dropped, and the round deadline covers it.

func (*Aggregator) ReevaluateGap

func (a *Aggregator) ReevaluateGap(ctx context.Context, m store.Monitor, from store.MonitorStatus, fromMs, toMs int64) ([]Change, error)

ReevaluateGap loads the heartbeats that the slots of m in [fromMs, toMs) need and replays them with Reevaluate. It is for the leader job that corrects the history after a quorum returned (FA-UPT-07). It reads the registry and the heartbeats but changes no aggregator state, so it may run next to Run.

func (*Aggregator) Run

func (a *Aggregator) Run(ctx context.Context)

Run evaluates until ctx ends. It handles observed heartbeats as they come, and checks the deadlines every tick.

func (*Aggregator) Sync

func (a *Aggregator) Sync(monitors []store.Monitor)

Sync sets the monitors of all tenants. Monitors that no longer exist are forgotten; a changed revision or interval restarts the evaluation of the monitor from its stored state. The reconciler calls it.

type Applier

type Applier interface {
	Apply(ctx context.Context, cmd *pb.Command) (cluster.ApplyResult, error)
}

Applier proposes Raft commands.

type Change

type Change struct {
	SinceMs int64
	Status  store.MonitorStatus
	// Incident is set for a change to DOWN.
	Incident *store.Incident
	// Reporters are the sorted, unique IDs of the nodes that reported in the
	// deciding slot.
	Reporters []string
}

Change is one status change found by Reevaluate (FA-UPT-07, ADR 0024).

func Reevaluate

func Reevaluate(m store.Monitor, from store.MonitorStatus, fromMs, toMs int64, hbs []store.Heartbeat, responsible []string, maintenance func(at time.Time) bool, unit time.Duration) []Change

Reevaluate replays the slots of m whose start lies in [fromMs, toMs) with the rules of the live evaluation (consensus policy, retries, recovery threshold, slot window k-1 and k, responsible nodes), starting from the status from with empty streaks. hbs are the stored heartbeats of m in the window read by ReevaluateGap; heartbeats of other monitors or tenants are ignored.

Slots inside a maintenance window (maintenance may be nil) reset the streaks and are skipped, as in the live evaluation; the first slot after such a window starts from PENDING, as the maintenance controller sets it when the window ends. PAUSED and MAINTENANCE are never produced. The result holds the changes in slot order. A non-positive interval yields none.

Incident IDs are derived from the monitor and the start of the DOWN episode, so the same input gives the same result (see incidentID).

type DeviationStats

type DeviationStats struct {
	// Slots is the number of slots in which the node reported and at least one
	// other node reported UP or DEGRADED for the same monitor.
	Slots int
	// Down is the number of those slots in which the node reported DOWN.
	Down int
}

DeviationStats counts the check slots in which the leader compared one node with its peers (ADR 0022).

type Options

type Options struct {
	State   store.State
	Metrics store.Metrics
	Cluster Applier
	// NodeID is this node. It is the only responsible node while the registry
	// is empty (single voter before registration).
	NodeID string
	// IsLeader reports whether this node leads. Only the leader proposes
	// status changes. Nil means never.
	IsLeader func() bool
	// Registry returns the node registry (ADR 0017). Nil means empty.
	Registry func(ctx context.Context) ([]store.Node, error)
	// Assigner decides the responsible nodes of a monitor (ADR 0017).
	Assigner scheduler.Assigner
	// Exclude removes a node from the responsible nodes, e.g. a node that
	// reports itself unhealthy (FA-CON-04, AP-3.2). Nil means none.
	Exclude func(nodeID string) bool
	// Maintenance reports whether m is in a maintenance window at the start of
	// a round. Such rounds are not evaluated (FA-MNT-02). Nil means none.
	Maintenance func(m store.Monitor, at time.Time) bool
	// Now is the clock for all decisions (ADR 0020). Nil means time.Now.
	Now func() time.Time
	// LeaderGrace is how long a new leader waits before it evaluates, so that
	// anti-entropy can deliver the heartbeats of the previous leader.
	// Zero means 10 s.
	LeaderGrace time.Duration
	// ReportDelay is added to the timeout for the deadline of a round. Zero
	// means 5 s (FA-CON-05).
	ReportDelay time.Duration
	// Unit is the length of one interval second; tests shrink it. Zero means
	// one second, the same as the scheduler.
	Unit   time.Duration
	Logger *slog.Logger
}

Options configure an Aggregator.

Jump to

Keyboard shortcuts

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