helper

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package helper is the node side of tops: it runs as root on a node, reads one request and writes one response.

Index

Constants

View Source
const (
	ExitOK         = 0 // the response says ok
	ExitNotOK      = 1 // the response says why not
	ExitBadRequest = 2 // the request did not decode, or helper is not root
)

Exit codes of tops node <op>

Variables

View Source
var System = Host{Root: "/", Proc: "/proc", Cgroup: cgroupMount, Etc: "/etc", Affinity: pid1Affinity, Clock: clockSynced, Systemd: systemBus}

System is the machine the helper runs on.

Functions

func Run

func Run(ctx context.Context, op wire.Op, env Env) int

Run executes one op: it reads one request from stdin, writes one response to stdout, logs one record, and returns the process's exit code.

Types

type Env

type Env struct {
	Host    Host
	Root    bool   // effective UID 0
	Version string // tops' own version, reported by hello
	Exe     string // this binary, whose sha256 hello reports
	Stdin   io.Reader
	Stdout  io.Writer
	Log     *slog.Logger
}

Env is what Run needs from the process. cmd/tops passes the real ones; tests fake them.

type Host

type Host struct {
	Root     string
	Proc     string
	Cgroup   string
	Etc      string
	Affinity func() (int, error)
	Clock    func() (bool, error)
	Systemd  func(ctx context.Context) (Systemd, error)
}

Host is where the helper reads a machine: its root filesystem, /proc, the cgroup v2 mount, /etc, the number of CPUs PID 1 may run on, and whether the kernel clock is synchronised, and systemd.

func (Host) Cores

func (h Host) Cores() (wire.Detected, error)

Cores returns the effective cores: the CPUs PID 1 may run on, lowered by the cpuset.cpus.effective and the cpu.max quota of PID 1's cgroup or of any ancestor visible from here. A quota makes it fractional. "150000 100000" is 1.5.

func (Host) Facts

func (h Host) Facts(ctx context.Context, args wire.FactsArgs) (wire.Facts, error)

Facts reads the files tops would write, the tops-owned directories, and the installed releases, and Temporal's systemd units.

func (Host) Hello

func (h Host) Hello(version string) (wire.Hello, error)

Hello describes the machine: who it is, what it runs, and its effective size. version is the helper's own, the same as the workstation's tops.

func (Host) Listeners

func (h Host) Listeners() ([]wire.Listener, error)

Listeners returns every listening TCP socket, IPv4 and IPv6, with the processes that hold it, sorted by port and address.

func (Host) Memory

func (h Host) Memory() (wire.Detected, error)

Memory returns the effective memory in bytes: MemTotal, lowered by the memory.max of PID 1's cgroup or of any ancestor visible from here.

type Systemd

type Systemd interface {
	ListUnitsByPatternsContext(ctx context.Context, states, patterns []string) ([]dbus.UnitStatus, error)
	GetUnitPropertiesContext(ctx context.Context, unit string) (map[string]any, error)
	GetUnitTypePropertiesContext(ctx context.Context, unit, unitType string) (map[string]any, error)
	Close()
}

Systemd is the part of systemd's D-Bus API the helper reads. *dbus.Conn has it; tests fake it.

Jump to

Keyboard shortcuts

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