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 ¶
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).
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.
const ( SubjectCluster = "cluster" SubjectCA = "ca" )
Subjects that are not node IDs.
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.
const DefaultCheckpointInterval = time.Hour
DefaultCheckpointInterval is the period of the FSM checkpoints (ADR 0025, section 4).
Variables ¶
var Kinds = []string{ KindVoterOffline, KindNodeImpaired, KindReplicationLag, KindClockSkew, KindDiskLow, KindWALLarge, KindRaftStale, KindCertExpiry, KindIncarnation, KindFingerprint, KindMixedVersions, KindProbeOffline, KindQuorum, }
Kinds lists every kind, so that the metrics export a zero for each kind without an active alert.
Functions ¶
Types ¶
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.
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.
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 ¶
FromStatus converts a GetStatus answer of the node nodeID.
func (Signals) HasSystemFields ¶
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 ¶
TenantState reads a tenant (store.State satisfies it).