nodeinsight

package
v1.5.8 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

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

View Source
const (
	CheckCert         = "cert"
	CheckHeartbeat    = "heartbeat"
	CheckAgentVersion = "agent_version"
	CheckSchedulable  = "schedulable"
)

Extra check IDs the doctor adds to the preflight set.

View Source
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.

View Source
const (
	UpdateNone     = "none"
	UpdateInstall  = "update"
	UpdateRollback = "rollback"
	UpdateHold     = "hold"
)

Agent update actions, stable for the agent and the dashboard.

View Source
const (
	SkewCurrent = "current"
	SkewBehind  = "behind"
	SkewAhead   = "ahead"
	SkewUnknown = "unknown"
)

Skew classes, stable so the dashboard can translate them.

View Source
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.

Variables

This section is empty.

Functions

func ChannelAllows

func ChannelAllows(channel, current, target string) bool

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 Classify

func Classify(agent, controlPlane string) string

Classify compares an agent version with the control plane version.

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

func OfflineSince(events []Event, since time.Time) int

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 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 DrainMove

type DrainMove struct {
	Status     string
	StartedAt  string
	FinishedAt string
}

DrainMove is one resource move inside 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 Event

type Event struct {
	From, To string
	At       time.Time
}

Event is one recorded status transition.

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

type NodeVersion struct {
	ID, Name, Version, OS, Arch string
	Online, Schedulable         bool
	Local                       bool
}

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 Sample

type Sample struct {
	Kind    string
	Payload []byte
}

Sample is one buffered agent report (a metrics point or an event).

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"`
}

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).

func BuildTimeline

func BuildTimeline(events []Event, current string, window time.Duration, now time.Time) Timeline

BuildTimeline turns transitions into contiguous segments over [now-window, now]. current is the node's state now and fills the span when there are no events.

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.

func (UpdatePolicy) Evaluate

func (p UpdatePolicy) Evaluate(current, target string, now time.Time) (bool, string)

Evaluate says whether the agent may apply target now, or why it waits.

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.

type Window

type Window = updatewindow.Window

Window is a daily local time range for automatic updates; see updatewindow.

func ParseWindow

func ParseWindow(s string) (Window, error)

ParseWindow reads "HH:MM-HH:MM"; empty means any time.

Jump to

Keyboard shortcuts

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