nodehealth

package
v1.3.2 Latest Latest
Warning

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

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

Documentation

Overview

Package nodehealth implements the node health check: the reconcile.Controller that converges a node's observed heartbeat (internal/store's last_seen_at, kept fresh by internal/agent.Server's periodic touch loop while a node's gRPC session stays open) against its recorded Status, the same architectural pattern internal/reconcile/application and internal/reconcile/database already establish (level-triggered, a narrow store interface for testability, one controller instance per resource), applied to a node instead of a service or database.

This exists specifically because internal/agent.Server.Session already flips a node's Status to Offline synchronously when its gRPC stream ends (a graceful disconnect), but a stream that never ends cleanly (a hard process kill, a severed network link with no TCP FIN) leaves Status stuck at Online forever with nothing to notice otherwise. This controller is that "otherwise": every reconcile pass re-reads LastSeenAt fresh from the store (never cached) and compares it against a timeout, the same level-triggered principle required of every controller in this codebase, so a hung connection is discovered on the very next resync tick rather than staying silently wrong until someone happens to look.

Index

Constants

View Source
const ConditionType = "Heartbeat"

ConditionType is the Type of the single condition this controller reports. Exported so internal/api's handleGetNodeHealth (and any future caller reading internal/store.GetConditions results) can name it without duplicating the string.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

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

Controller converges one named node's observed heartbeat (read fresh from Store on every Reconcile, never cached) against its Status.

func New

func New(nodeID string, st Store, timeout time.Duration, opts ...Option) *Controller

New builds a Controller for nodeID. timeout is how long since LastSeenAt is treated as stale; callers read it from an env var, per the house rule against hardcoded thresholds, and this package itself has no opinion on a default.

func (*Controller) Name

func (c *Controller) Name() string

Name implements reconcile.Controller.

func (*Controller) Reconcile

func (c *Controller) Reconcile(ctx context.Context) (reconcile.Result, error)

Reconcile implements reconcile.Controller.

type Option

type Option func(*Controller)

Option configures optional Controller behavior.

func WithClock

func WithClock(now func() time.Time) Option

WithClock overrides the controller's notion of "now", for deterministic tests. Without one configured, time.Now is used.

func WithPendingExpiry

func WithPendingExpiry(d time.Duration) Option

WithPendingExpiry frees the name and placement of a node that never connected within d.

type Store

type Store interface {
	GetNode(ctx context.Context, id string) (*store.Node, error)
	UpdateNodeStatus(ctx context.Context, id string, status store.NodeStatus) error
}

Store is the narrow surface this controller needs from internal/store, so tests can fake it without a real database. *store.DB satisfies this structurally.

Jump to

Keyboard shortcuts

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