Documentation
¶
Overview ¶
Package nodeinsight holds the pure logic behind the node health timeline, the agent doctor extras and the agent version skew report, so the API, the CLI and the dashboard all render one definition.
Index ¶
- Constants
- func CanaryWait(selfIsCanary bool, canaries []CanaryNode, target string) string
- func ChannelAllows(channel, current, target string) bool
- func Classify(agent, controlPlane string) string
- func EffectiveWaveSize(size, percent, total int) int
- func ExtraChecks(f DoctorFacts, now time.Time) []nodepreflight.Check
- func OfflineSince(events []Event, since time.Time) int
- func WaveIDs(ids []string, size int) []string
- type CanaryNode
- type DoctorFacts
- type DrainInput
- type DrainMove
- type DrainProgress
- type Event
- type NodeSkew
- type NodeVersion
- type OfflineBuffer
- type PlanStep
- type Rollout
- type RolloutControl
- type RolloutHalt
- type Sample
- type Segment
- type SkewReport
- type Timeline
- type UpdateDecision
- type UpdateFacts
- type UpdatePolicy
- type VersionHealth
- type VersionTracker
- type WaveDecision
- type WaveNode
- type WaveOptions
- type Window
Constants ¶
const ( CheckCert = "cert" CheckHeartbeat = "heartbeat" CheckAgentVersion = "agent_version" CheckSchedulable = "schedulable" )
Extra check IDs the doctor adds to the preflight set.
const ( DrainRunning = "running" DrainDone = "done" DrainPartial = "partial" DrainFailed = "failed" DrainStalled = "stalled" DrainNotFound = "none" )
Drain progress states, stable so the dashboard and CLI can translate them.
const ( RolloutStaged = "staged" RolloutPaused = "paused" RolloutAborted = "aborted" RolloutResumed = "resumed" )
Rollout states an operator or an automatic halt can put a target in.
const ( UpdateNone = "none" UpdateInstall = "update" UpdateRollback = "rollback" UpdateHold = "hold" )
Agent update actions, stable for the agent and the dashboard.
const ( SkewCurrent = "current" SkewBehind = "behind" SkewAhead = "ahead" SkewUnknown = "unknown" )
Skew classes, stable so the dashboard can translate them.
const ( ChannelStable = "stable" ChannelHoldMinor = "hold-minor" )
Agent update channels. stable follows the control plane; hold-minor only auto applies patch releases, so minor and major jumps wait for an operator.
const LabelAgentCanary = "levelrail.io/agent-canary"
LabelAgentCanary marks nodes whose agents update first; every other node waits until all of them run the target version and are online.
Variables ¶
This section is empty.
Functions ¶
func CanaryWait ¶
func CanaryWait(selfIsCanary bool, canaries []CanaryNode, target string) string
CanaryWait says why a non-canary node must wait for the canaries, or "" when it may update. Canary nodes themselves never wait on each other.
func ChannelAllows ¶
ChannelAllows reports whether the channel lets target apply automatically over current. Unparseable versions never block: the decision falls back to the stable behavior so nobody is stuck on a odd tag.
func EffectiveWaveSize ¶
EffectiveWaveSize is the larger of a fixed count and a percent of the fleet.
func ExtraChecks ¶
func ExtraChecks(f DoctorFacts, now time.Time) []nodepreflight.Check
ExtraChecks judges the control plane side of a node. The agent side (docker, disk, clock, ports) comes from nodepreflight.Evaluate.
func OfflineSince ¶
OfflineSince counts transitions to offline at or after since, but only after the node has reported online in that window. An offline event with no handshake before it is a control plane restart or a flap, not a bad version.
Types ¶
type CanaryNode ¶
CanaryNode is one canary node's update state.
type DoctorFacts ¶
type DoctorFacts struct {
Online bool
LastSeen *time.Time
CertState string
CertDaysLeft *int
AgentVersion string
ControlPlane string
Schedulable bool
HasPreflight bool
LocalControlRow bool
}
DoctorFacts is what the control plane holds about a node besides the agent's own preflight report.
type DrainInput ¶
type DrainInput struct {
Status string
Blocked int
Moves []DrainMove
StartedAt string
UpdatedAt string
// StallAfter marks a running drain with no update for this long as stalled.
StallAfter time.Duration
}
DrainInput is what the store knows about a drain.
type DrainProgress ¶
type DrainProgress struct {
State string `json:"state"`
Total int `json:"total"`
Succeeded int `json:"succeeded"`
Failed int `json:"failed"`
RolledBack int `json:"rolled_back"`
Running int `json:"running"`
Blocked int `json:"blocked"`
Percent int `json:"percent"`
// EtaSeconds is a rough estimate from finished moves, 0 when unknown.
EtaSeconds int `json:"eta_seconds,omitempty"`
}
DrainProgress is the summary shown beside a drain.
func BuildDrainProgress ¶
func BuildDrainProgress(in DrainInput, now time.Time) DrainProgress
BuildDrainProgress counts moves, estimates the time left from the mean duration of finished moves and flags a drain that stopped updating.
type NodeSkew ¶
type NodeSkew struct {
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version,omitempty"`
OS string `json:"os,omitempty"`
Arch string `json:"arch,omitempty"`
Online bool `json:"online"`
Class string `json:"class"`
NeedsUpdate bool `json:"needs_update"`
}
NodeSkew is one node's position against the control plane version.
type NodeVersion ¶
NodeVersion is what the control plane knows about one agent.
type OfflineBuffer ¶
type OfflineBuffer struct {
// contains filtered or unexported fields
}
OfflineBuffer holds reports while the control plane is unreachable. It is bounded by count and bytes, dropping the oldest first so a long outage keeps the most recent picture instead of growing without limit.
func NewOfflineBuffer ¶
func NewOfflineBuffer(maxItems, maxBytes int) *OfflineBuffer
NewOfflineBuffer builds a buffer. A limit of 0 or less disables buffering.
func (*OfflineBuffer) Add ¶
func (b *OfflineBuffer) Add(s Sample) bool
Add stores a sample, evicting the oldest as needed. It reports whether the sample was kept.
func (*OfflineBuffer) Replay ¶
func (b *OfflineBuffer) Replay(send func(Sample) error) int
Replay sends buffered samples oldest first through send and stops at the first error, keeping the unsent rest. It returns how many were delivered.
func (*OfflineBuffer) SetLimits ¶
func (b *OfflineBuffer) SetLimits(maxItems, maxBytes int)
SetLimits applies new limits live and trims to fit.
func (*OfflineBuffer) Stats ¶
func (b *OfflineBuffer) Stats() (items, bytes, dropped int)
Stats reports queued samples, bytes and how many were dropped so far.
type PlanStep ¶
type PlanStep struct {
Order int `json:"order"`
NodeID string `json:"node_id"`
Name string `json:"name"`
From string `json:"from,omitempty"`
To string `json:"to"`
Note string `json:"note,omitempty"`
}
PlanStep is one node in the suggested upgrade order.
type Rollout ¶
type Rollout struct {
WaveSize int `json:"wave_size"`
// Waves is how many waves the fleet is cut into; 0 when staging is off.
Waves int `json:"waves,omitempty"`
// State is staged, paused, aborted or resumed; empty when staging is off.
State string `json:"state,omitempty"`
// CurrentWave is the first wave not yet fully on the target, counted from 1.
CurrentWave int `json:"current_wave,omitempty"`
OnTarget int `json:"on_target,omitempty"`
Total int `json:"total,omitempty"`
Halted bool `json:"halted"`
Target string `json:"target,omitempty"`
FailedNode string `json:"failed_node,omitempty"`
Reason string `json:"reason,omitempty"`
At time.Time `json:"at,omitempty"`
}
Rollout is the staged rollout state shown in the update status.
func BuildRollout ¶
func BuildRollout(o WaveOptions, nodes []WaveNode, target string) Rollout
BuildRollout summarizes staging for the status surface.
type RolloutControl ¶
type RolloutControl struct {
State string `json:"state"`
Target string `json:"target"`
Node string `json:"node,omitempty"`
Reason string `json:"reason,omitempty"`
By string `json:"by,omitempty"`
At time.Time `json:"at"`
}
RolloutControl is the saved pause, abort or resume for one target version.
func ParseRolloutControl ¶
func ParseRolloutControl(s string) RolloutControl
ParseRolloutControl reads the saved value; bad or empty input means no control.
func (RolloutControl) Encode ¶
func (c RolloutControl) Encode() string
Encode is the string stored in the runtime setting.
func (RolloutControl) For ¶
func (c RolloutControl) For(target string) RolloutControl
For returns the control only while it names target, so a new release starts clean.
func (RolloutControl) Transition ¶
func (c RolloutControl) Transition(action, target, by string, now time.Time) (RolloutControl, bool)
Transition returns the control after an operator action, or false when the action makes no sense now (resuming a rollout that is not stopped).
type RolloutHalt ¶
type RolloutHalt struct {
// contains filtered or unexported fields
}
RolloutHalt remembers the latest halt per control plane process.
func (*RolloutHalt) Current ¶
func (h *RolloutHalt) Current(target string) Rollout
Current returns the halt for target, or an empty Rollout when the target moved on.
func (*RolloutHalt) Peek ¶
func (h *RolloutHalt) Peek() Rollout
Peek returns the stored halt whatever the target.
type Segment ¶
type Segment struct {
State string `json:"state"`
From time.Time `json:"from"`
To time.Time `json:"to"`
Seconds int64 `json:"seconds"`
}
Segment is a stretch of time a node spent in one state.
type SkewReport ¶
type SkewReport struct {
ControlPlaneVersion string `json:"control_plane_version"`
Nodes []NodeSkew `json:"nodes"`
Current int `json:"current"`
Behind int `json:"behind"`
Ahead int `json:"ahead"`
Unknown int `json:"unknown"`
Plan []PlanStep `json:"plan"`
// AutoUpdate mirrors the nodes.agent_auto_update runtime setting.
AutoUpdate bool `json:"auto_update"`
// Rollout is the staged update state; WaveSize 0 means staging is off.
Rollout Rollout `json:"rollout"`
}
SkewReport is the fleet view plus the upgrade plan.
func BuildSkew ¶
func BuildSkew(controlPlane string, nodes []NodeVersion) SkewReport
BuildSkew classifies every node and orders the upgrades: cordoned nodes first (no live placements to disturb), then online ones, offline last because they cannot take the new agent until they reconnect.
type Timeline ¶
type Timeline struct {
From time.Time `json:"from"`
To time.Time `json:"to"`
Segments []Segment `json:"segments"`
Transitions int `json:"transitions"`
UptimePercent *float64 `json:"uptime_percent,omitempty"`
}
Timeline is a node's state over a window. UptimePercent is nil when the node was never online or offline inside the window (for example pending).
type UpdateDecision ¶
type UpdateDecision struct {
Action string `json:"action"`
Channel string `json:"channel"`
Target string `json:"target_version,omitempty"`
Reason string `json:"reason"`
// AutoApply mirrors the nodes.agent_auto_update runtime setting: when true
// the agent restarts into the new version without an operator flag.
AutoApply bool `json:"auto_apply"`
// Waiting says why a pending update is not applying on its own (window,
// hold, channel, automatic updates off); empty when nothing waits.
Waiting string `json:"waiting,omitempty"`
// Held is true when this node has a per-node hold.
Held bool `json:"held,omitempty"`
}
UpdateDecision is the answer to an agent update check. The agent only ever installs a signed release it fetches itself; this never carries a command.
func DecideUpdate ¶
func DecideUpdate(f UpdateFacts) UpdateDecision
DecideUpdate keeps agents on the control plane version of the control plane channel and rolls back to the last good version when health keeps failing.
type UpdateFacts ¶
type UpdateFacts struct {
Channel string
ControlPlane string
AgentVersion string
AgentOnline bool
PreviousGood string
// RolledBackFrom holds the control plane version this node was rolled back from.
RolledBackFrom string
HealthFailures int
// MaxHealthFailures is the runtime setting after which an update is undone.
MaxHealthFailures int
}
UpdateFacts is what the control plane knows when an agent asks for its target.
type UpdatePolicy ¶
type UpdatePolicy struct {
Auto bool
WindowText string
Channel string
Held bool
// Override applies this one decision regardless of the gates. It never
// changes the Auto setting and never skips signature checks or rollback.
Override bool
}
UpdatePolicy is everything that gates an automatic apply for one node.
type VersionHealth ¶
type VersionHealth struct {
Current string `json:"current"`
LastGood string `json:"last_good,omitempty"`
Failures int `json:"failures"`
Since time.Time `json:"since"`
// RolledBackFrom is the version this node was returned from; it is not
// offered again until the target changes or the hold is cleared.
RolledBackFrom string `json:"rolled_back_from,omitempty"`
}
VersionHealth remembers which agent version last proved healthy, so a bad update can name the version to go back to.
func LoadVersionHealth ¶
func LoadVersionHealth(path string) (VersionHealth, error)
LoadVersionHealth reads the state file; a missing file is an empty state.
func (*VersionHealth) Observe ¶
func (h *VersionHealth) Observe(version string, now time.Time)
Observe records the running version. A version change resets the failure count and keeps the previous version as the rollback target, unless that one was itself failing (then the older good version stays).
func (*VersionHealth) RecordFailure ¶
func (h *VersionHealth) RecordFailure()
RecordFailure counts one failed health check or short-lived session.
func (*VersionHealth) RecordStable ¶
func (h *VersionHealth) RecordStable()
RecordStable marks the current version good after a healthy stretch.
func (VersionHealth) Save ¶
func (h VersionHealth) Save(path string) error
Save writes the state atomically so a crash never leaves half a file.
type VersionTracker ¶
type VersionTracker struct {
// contains filtered or unexported fields
}
VersionTracker keeps one VersionHealth per node on the control plane. The zero value is ready; it is in memory and relearns after a restart.
func (*VersionTracker) ClearRolledBack ¶
func (t *VersionTracker) ClearRolledBack(id string)
ClearRolledBack lifts the hold for a node so the version can be offered again.
func (*VersionTracker) Observe ¶
func (t *VersionTracker) Observe(id, version string, now time.Time) VersionHealth
Observe records a node's version and returns its state.
func (*VersionTracker) Snapshot ¶
func (t *VersionTracker) Snapshot(id string) VersionHealth
Snapshot returns a node's version state without recording an observation.
type WaveDecision ¶
type WaveDecision struct {
// Wait is why the node must wait; empty when it may update.
Wait string
// Halted is true when a wave node failed on the target, so nobody else is tried.
Halted bool
// FailedNode names the wave node that failed.
FailedNode string
// Paused is true while an operator or an automatic halt holds the rollout.
Paused bool
}
WaveDecision says whether a node may update now in a staged rollout.
func WaveCheck ¶
func WaveCheck(selfID string, size int, nodes []WaveNode, target string) WaveDecision
WaveCheck is the single first-wave gate: size nodes go first, then the rest.
func WaveCheckWith ¶
func WaveCheckWith(selfID string, o WaveOptions, nodes []WaveNode, target string) WaveDecision
WaveCheckWith holds a node until every earlier wave runs the target, is online and has soaked. It stops for good while a node rolled back from the target, and while the rollout is paused or aborted. Resuming skips the nodes that rolled back.
type WaveNode ¶
type WaveNode struct {
ID string
Online bool
// Version is the agent version the node reports.
Version string
// RolledBackFrom is the version the node was returned from after failing health.
RolledBackFrom string
// Since is when the node first reported its current version.
Since time.Time
}
WaveNode is one node's update state for staged rollouts.
type WaveOptions ¶
type WaveOptions struct {
// Size is the nodes per wave; 0 turns staging off.
Size int
// Waves is how many waves the fleet is cut into; the last one takes the
// remainder. Anything below 2 means two: the first wave, then everyone else.
Waves int
// Soak is how long a wave must run the target before the next one starts.
Soak time.Duration
Now time.Time
Control RolloutControl
}
WaveOptions tunes a staged rollout.
type Window ¶
type Window = updatewindow.Window
Window is a daily local time range for automatic updates; see updatewindow.
func ParseWindow ¶
ParseWindow reads "HH:MM-HH:MM"; empty means any time.