sysalert

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 13 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 sysalert evaluates the system alerts of the cluster (FA-OBS-01, FA-REP-05, FA-REP-06, FA-PKI-06, ADR 0025). The leader reads the signals of every voter from the GetStatus rounds, decides the transitions with hysteresis and proposes only the changes through Raft. The state lives in the replicated system_alerts table, so a leader change is no change.

Index

Constants

View Source
const (
	// DefaultInterval is the evaluation period of the leader.
	DefaultInterval = 30 * time.Second
	// DefaultReplicationLag is REPLICATION_LAG_ALERT.
	DefaultReplicationLag = 5 * time.Minute
	// DefaultClockSkew is CLOCK_SKEW_ALERT.
	DefaultClockSkew = 2 * time.Second
	// DefaultDiskFree is DISK_FREE_ALERT.
	DefaultDiskFree = 0.15
	// DefaultWALSize is WAL_SIZE_ALERT, 512 MiB.
	DefaultWALSize int64 = 512 << 20
	// DefaultProbeOffline is PROBE_OFFLINE_ALERT.
	DefaultProbeOffline = 5 * time.Minute
)

Defaults of the collector (ADR 0025, section 3).

View Source
const (
	KindVoterOffline   = "voter_offline"
	KindNodeImpaired   = "node_impaired"
	KindReplicationLag = "replication_lag"
	KindClockSkew      = "clock_skew"
	KindDiskLow        = "disk_low"
	KindWALLarge       = "wal_large"
	KindRaftStale      = "raft_stale"
	KindCertExpiry     = "cert_expiry"
	KindIncarnation    = "incarnation_changed"
	KindFingerprint    = "fingerprint_mismatch"
	KindMixedVersions  = "mixed_versions"
	KindProbeOffline   = "probe_offline"
	KindQuorum         = "quorum"
)

Kinds of system alerts (ADR 0025, section 3). The quorum kind is raised by the degraded package, the others by the Collector.

View Source
const (
	SubjectCluster = "cluster"
	SubjectCA      = "ca"
)

Subjects that are not node IDs.

View Source
const (
	// StaleApplyGap is the number of log entries a voter may lag behind the
	// leader's commit index.
	StaleApplyGap = 1000
	// StaleLastContact is the time since the last contact with the leader from
	// which a voter counts as stale. It equals the health threshold of ADR 0017.
	StaleLastContact = 10 * time.Second
)

Stale thresholds of a voter (ADR 0025, kind raft_stale). ADR 0012 A9 asks for a threshold but names no value, and no code decides the stale state yet, so these are the values of this package.

View Source
const DefaultCheckpointInterval = time.Hour

DefaultCheckpointInterval is the period of the FSM checkpoints (ADR 0025, section 4).

Variables

Kinds lists every kind, so that the metrics export a zero for each kind without an active alert.

Functions

func RaftStale

func RaftStale(s Signals, leaderCommit uint64) bool

RaftStale reports whether a voter is stale: it lags behind the leader's commit index by more than StaleApplyGap entries, or its last contact with the leader is older than StaleLastContact.

Types

type Applier

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

Applier proposes Raft commands. *cluster.Node satisfies it.

type Collector

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

Collector evaluates the system alerts on the leader (ADR 0025, section 3). It runs in one goroutine; only the Run loop touches its fields.

func New

func New(opts Options) *Collector

New creates a Collector with defaults applied to opts.

func (*Collector) Run

func (c *Collector) Run(ctx context.Context)

Run evaluates every Interval until ctx ends.

func (*Collector) Tick

func (c *Collector) Tick(ctx context.Context)

Tick runs one evaluation if this node leads and the leadership has lasted a full interval. The first evaluation of a leadership waits for one full round of GetStatus answers, as in ADR 0022.

type JobOptions

type JobOptions struct {
	IsLeader     func() bool
	CommandLevel func(ctx context.Context) (uint32, error)
	State        TenantState
	Cluster      Applier
	// CheckpointInterval is the period of the checkpoints; zero means DefaultCheckpointInterval.
	CheckpointInterval time.Duration
	// Now is the clock of this node; nil means time.Now.
	Now    func() time.Time
	Logger *slog.Logger
}

JobOptions configure Jobs. IsLeader, CommandLevel, State and Cluster are required.

type Jobs

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

Jobs are the leader's housekeeping for the system alerts (ADR 0025): the reserved system tenant, which is created once per leadership at command level 6, and the hourly FSM checkpoint, which changes no data.

func NewJobs

func NewJobs(opts JobOptions) *Jobs

NewJobs creates the leader jobs with defaults applied to opts.

func (*Jobs) Run

func (j *Jobs) Run(ctx context.Context)

Run ticks until ctx ends.

func (*Jobs) Tick

func (j *Jobs) Tick(ctx context.Context)

Tick does the work that is due: on a leader at command level 6 the system tenant once per leadership, and a checkpoint if the last one is an interval old or none was proposed yet.

type Options

type Options struct {
	NodeID string
	// IsLeader reports whether this node leads. Only the leader evaluates.
	IsLeader func() bool
	State    State
	// CommandLevel returns the command level of the cluster; below
	// cluster.SystemAlertCommandLevel the collector only logs.
	CommandLevel func(ctx context.Context) (uint32, error)
	Cluster      Applier
	// Self returns the signals of this node. The collector stamps AnsweredAt.
	Self func() Signals
	// Peers returns the signals of the peer voters by node ID (see
	// clusterhost.Host.PeerSignals).
	Peers func() map[string]Signals
	// ClockOffsets returns the clock offset of each peer in milliseconds,
	// positive when the peer is ahead (ADR 0020). Nil means none.
	ClockOffsets func() map[string]int64
	Thresholds   Thresholds
	// Interval is the evaluation period; zero means DefaultInterval.
	Interval time.Duration
	// Now is the clock of this node (ADR 0020); nil means time.Now.
	Now    func() time.Time
	Logger *slog.Logger
}

Options configure a Collector. NodeID, IsLeader, State, CommandLevel, Cluster, Self and Peers are required.

type Signals

type Signals struct {
	NodeID string
	// AnsweredAt is the local time of the answer.
	AnsweredAt    time.Time
	RaftState     string
	LeaderID      string
	AppliedIndex  uint64
	CommitIndex   uint64
	LastContactMs int64
	// Incarnation is the incarnation of metrics.db; empty for older nodes.
	Incarnation string
	// DiskFreeRatio is the free share of the data directory; negative if unknown.
	DiskFreeRatio   float64
	StateWALBytes   int64
	MetricsWALBytes int64
	// CertNotAfter is the expiry of the node certificate; zero if unknown.
	CertNotAfter time.Time
	// ReplicationLagMs is the largest lag to a connected peer, -1 if a connected
	// peer never caught up.
	ReplicationLagMs int64
	// FingerprintIndex and Fingerprint describe the last FSM checkpoint.
	FingerprintIndex uint64
	Fingerprint      string
}

Signals are the signals of one voter as its last GetStatus answer reported them (ADR 0025, section 2). They come from the cluster host's polling.

func FromStatus

func FromStatus(nodeID string, st *pb.GetStatusResponse, answeredAt time.Time) Signals

FromStatus converts a GetStatus answer of the node nodeID.

func (Signals) HasSystemFields

func (s Signals) HasSystemFields() bool

HasSystemFields reports whether the node sends the fields of ADR 0025. Every node with them has an incarnation, so an empty one marks an older node. Its zero values must not read as a signal (disk full, no lag, no certificate).

type State

type State interface {
	ListNodes(ctx context.Context) ([]store.Node, error)
	ListSystemAlerts(ctx context.Context, activeOnly bool) ([]store.SystemAlert, error)
	ListAllProbeAlerts(ctx context.Context, activeOnly bool) ([]store.ProbeAlert, error)
	ListNodeIncarnations(ctx context.Context) ([]store.NodeIncarnation, error)
	ListClusterCAs(ctx context.Context) ([]store.ClusterCA, error)
}

State is the replicated state the collector reads.

type TenantState

type TenantState interface {
	GetTenant(ctx context.Context, id string) (store.Tenant, error)
}

TenantState reads a tenant (store.State satisfies it).

type Thresholds

type Thresholds struct {
	ReplicationLag time.Duration
	ClockSkew      time.Duration
	DiskFree       float64
	WALSize        int64
	ProbeOffline   time.Duration
}

Thresholds of the signal alerts. The zero value means the defaults.

Jump to

Keyboard shortcuts

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