nodes

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 8 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 nodes tracks live node state (§5.6). Heartbeats and metrics stay in memory; only status transitions are written to SQLite (D5).

Index

Constants

View Source
const (
	HeartbeatInterval = 5 * time.Second
	SuspectAfter      = 20 * time.Second
	NotReadyAfter     = 60 * time.Second
)

Thresholds from §5.6.

View Source
const TopicNode = "node.updated"

TopicNode carries a View on every status change and heartbeat.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	Hostname      string `json:"hostname"`
	OS            string `json:"os"`
	Kernel        string `json:"kernel"`
	Arch          string `json:"arch"`
	CPUCores      int    `json:"cpuCores"`
	MemoryBytes   uint64 `json:"memoryBytes"`
	DiskBytes     uint64 `json:"diskBytes"`
	DockerVersion string `json:"dockerVersion"`
	AgentVersion  string `json:"agentVersion"`
}

type Metrics

type Metrics struct {
	CPUPercent       float64 `json:"cpuPercent"`
	MemoryUsedBytes  uint64  `json:"memoryUsedBytes"`
	MemoryTotalBytes uint64  `json:"memoryTotalBytes"`
	DiskUsedBytes    uint64  `json:"diskUsedBytes"`
	DiskTotalBytes   uint64  `json:"diskTotalBytes"`
	Load1            float64 `json:"load1"`
	Load5            float64 `json:"load5"`
	Load15           float64 `json:"load15"`
	NetRxBytes       uint64  `json:"netRxBytes"`
	NetTxBytes       uint64  `json:"netTxBytes"`
	UptimeSeconds    int64   `json:"uptimeSeconds"`
}

type Registry

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

func NewRegistry

func NewRegistry(st *store.Store, bus *events.Bus, log *slog.Logger) *Registry

func (*Registry) Added

func (r *Registry) Added(n store.Node)

Added registers a freshly joined node.

func (*Registry) Connected

func (r *Registry) Connected(ctx context.Context, id string, info Info)

Connected records an agent stream opening with its Hello info.

func (*Registry) Disconnected

func (r *Registry) Disconnected(ctx context.Context, id string)

func (*Registry) Get

func (r *Registry) Get(id string) (View, bool)

Get returns one node's view.

func (*Registry) Heartbeat

func (r *Registry) Heartbeat(ctx context.Context, id string, m Metrics)

func (*Registry) List

func (r *Registry) List() []View

func (*Registry) Load

func (r *Registry) Load(ctx context.Context) error

Load fills the registry from SQLite at startup. Every node starts disconnected; heartbeat timeouts then apply from each node's last-seen time, so nodes that don't reconnect go Suspect and then Not ready. The stored last-seen time is only written on transitions, and agents need a moment to reconnect, so timeouts count from the controller's start at the earliest: restarting the controller never reschedules tasks.

func (*Registry) Removed

func (r *Registry) Removed(id string)

func (*Registry) Run

func (r *Registry) Run(ctx context.Context)

Run applies the heartbeat timeouts until ctx ends.

func (*Registry) SetPool

func (r *Registry) SetPool(ctx context.Context, id, poolID string, protected bool)

SetPool records a node's pool membership.

func (*Registry) SetSchedulable

func (r *Registry) SetSchedulable(ctx context.Context, id string, on, draining bool)

List returns all nodes sorted by name. SetSchedulable updates the live view after the store changed.

type View

type View struct {
	ID         string     `json:"id"`
	Name       string     `json:"name"`
	Status     string     `json:"status"`
	StatusAt   time.Time  `json:"statusAt"`
	Connected  bool       `json:"connected"`
	LastSeenAt *time.Time `json:"lastSeenAt"`
	CreatedAt  time.Time  `json:"createdAt"`
	Info       Info       `json:"info"`
	Metrics    *Metrics   `json:"metrics"`
	// Schedulable allows new tasks (§6.4: off for the controller by default).
	Schedulable bool `json:"schedulable"`
	// Draining moves the node's tasks to other nodes.
	Draining bool `json:"draining"`
	// PoolID is the node's pool ("" outside any pool, §6.5).
	PoolID           string `json:"poolId"`
	ScaleInProtected bool   `json:"scaleInProtected"`
}

View is a node as the API and dashboard see it.

Jump to

Keyboard shortcuts

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