capabilities

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 16 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 capabilities provides auto-detection and manual override of sqi-worker host capabilities reported to sqi-server at registration time.

Design

Hardware queries are abstracted behind the Probe interface so tests can inject controlled return values without touching real OS APIs. The default production implementation ([DefaultProbe]) calls the real syscalls via platform-specific files (probe_linux.go, probe_darwin.go, probe_windows.go).

Usage

caps := capabilities.Detect(nil)               // nil → DefaultProbe
caps.MergeManualTags(cfg.Worker.CapabilityTags)
// caps is now ready to embed in a protocol.RegisterMsg

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateTagKeys

func ValidateTagKeys(tags map[string]string) error

ValidateTagKeys returns an error if any two capability tag keys collide case-insensitively. Tag keys are the trailing segment of an OpenJD capability name (attr.worker.tag.<key>), which the spec defines as case-insensitive, so two keys differing only in case are the same capability and would match ambiguously. Rejecting them at registration keeps the advertised tag set unambiguous.

Types

type Capabilities

type Capabilities struct {
	// OS is the operating system name as reported by runtime.GOOS:
	// "linux", "darwin", or "windows".
	OS string

	// OSVersion is the human-readable OS release string, e.g. "22.04" on
	// Ubuntu or "14.5" on macOS.  Empty if detection fails.
	OSVersion string

	// Arch is the CPU architecture as reported by runtime.GOARCH: "amd64",
	// "arm64", and so on. Advertised at registration so the scheduler can
	// satisfy OpenJD's reserved attr.worker.cpu.arch host requirement, whose
	// values are the specification's tokens ("x86_64", "arm64") rather than
	// Go's. The worker reports GOARCH verbatim and the server translates, as
	// for OS and os.family.
	Arch string

	// CPUCount is the number of logical (hardware-thread) CPUs available.
	CPUCount int

	// RAMMb is total installed physical RAM in mebibytes.
	// 0 if detection fails.
	RAMMb int

	// GPU describes the GPU(s) installed on the host.  Zero value means no
	// GPU was detected or detection is not supported on this platform.
	GPU GPUInfo

	// Tags holds arbitrary string capability tags merged from auto-detection
	// and any manual overrides supplied via WorkerConfig.Worker.CapabilityTags.
	// The map value is "true" for a detector's tag and for a bare manual entry
	// (e.g. "maya_2025"), and the right-hand side of the entry for a key=value
	// tag (e.g. "maya=false" → Tags["maya"] = "false"). See [MergeManualTags].
	//
	// Auto-detected entries seeded by [Detect]:
	//   "os"         → Capabilities.OS
	//   "os_version" → Capabilities.OSVersion  (omitted when empty)
	Tags map[string]string
}

Capabilities holds the merged set of auto-detected and manually overridden worker host capabilities.

func BuildWorkerCapabilities added in v0.2.0

func BuildWorkerCapabilities(cfg CapabilitiesConfig, manualTags []string, env CheckEnv) (Capabilities, error)

BuildWorkerCapabilities detects host capabilities, applies built-in + custom detectors, merges manual tags (which win), and validates the tag key set.

func Detect

func Detect(p Probe) Capabilities

Detect auto-detects host capabilities using p. If p is nil, DefaultProbe is used. The returned Capabilities.Tags map is always non-nil and pre-populated with the "os" tag and, when non-empty, the "os_version" tag.

func (*Capabilities) ApplyConfiguredCommands added in v0.4.0

func (c *Capabilities) ApplyConfiguredCommands(detectors []Detector, mapped func(name string) (path string, ok bool)) []string

ApplyConfiguredCommands advertises the tag of every detector whose command the operator mapped in worker.commands, and returns the tags it added, sorted.

A worker.commands entry says where the software is, so it is as good a signal as a glob match: without it, an operator whose install the globs do not search would have to add the tag by hand as well. mapped resolves a command name to the path the operator gave, and reports false when there is no entry or its target does not exist on this host — a mapping to something missing advertises nothing.

A tag already present, whatever its value, is left alone, and the detector's version tag with it: capability_tags: ["maya=false"] is how an operator turns a tag off, and a mapping must not turn it back on.

func (*Capabilities) ApplyDetectors added in v0.2.0

func (c *Capabilities) ApplyDetectors(detectors []Detector, env CheckEnv)

ApplyDetectors evaluates each detector against env and records emitted tags with value "true" (matching the manual `tag=true` convention used by the scheduler's attribute matcher) without overwriting keys already present.

func (*Capabilities) MergeManualTags

func (c *Capabilities) MergeManualTags(tags []string)

MergeManualTags merges manual capability tags from WorkerConfig.Worker.CapabilityTags into c.Tags. Each entry is either:

  • a bare tag, stored with the value "true" as a detector's tag is, so an attr.worker.tag.<key> requirement of anyOf ["true"] matches it (e.g. "maya_2025", "gpu", "highram"); or
  • a "key=value" pair, split on the first "=" (e.g. "maya=false" sets Tags["maya"] = "false"; a value may itself contain "=", e.g. "a=b=c" sets Tags["a"] = "b=c"; a trailing "=" with nothing after it, e.g. "maya=", sets Tags["maya"] = "", which no requirement matches).

An entry with an empty key (starting with "=", e.g. "=true") is skipped rather than stored verbatim, since an empty tag key can never be matched by an OpenJD attr.worker.tag.<key> requirement.

Manual tags always overwrite any auto-detected tag with the same key, so operators can suppress or replace an auto-detected value if needed.

type CapabilitiesConfig added in v0.2.0

type CapabilitiesConfig struct {
	Detect  []Detector `yaml:"detect"`
	Disable []string   `yaml:"disable"`
}

CapabilitiesConfig is the worker's capability-detection configuration.

type Check added in v0.2.0

type Check struct {
	Exe      string   `yaml:"exe"`
	PathGlob string   `yaml:"path_glob"`
	Env      EnvCheck `yaml:"env"`
	Registry string   `yaml:"registry"`
	OS       string   `yaml:"os"`
}

Check is a single declarative probe. Exactly one of Exe/PathGlob/Env/Registry must be set. OS optionally gates the check to one platform.

type CheckEnv added in v0.2.0

type CheckEnv interface {
	LookPath(file string) (string, bool)
	Glob(pattern string) []string
	Getenv(key string) (string, bool)
	RegistryExists(key string) bool
	GOOS() string
}

CheckEnv abstracts the host queries a detector needs, so tests inject fakes.

func OSCheckEnv added in v0.2.0

func OSCheckEnv() CheckEnv

OSCheckEnv returns the production CheckEnv backed by real OS queries.

type CommandGlob added in v0.4.0

type CommandGlob struct {
	PathGlob string `yaml:"path_glob"`
	OS       string `yaml:"os"`
}

CommandGlob locates the executable of detected software, optionally on one platform only.

type CommandSpec added in v0.4.0

type CommandSpec struct {
	// Name is the command name a job runs, as written in the preset.
	Name string `yaml:"name"`
	// Globs match the executable itself, not the install directory: on macOS
	// that is inside the .app bundle.
	Globs []CommandGlob `yaml:"globs"`
	// Version, when set, is used instead of the detector's own version regex
	// to read a version from each match. It only chooses the newest install and
	// labels the result: it never adds a version tag. A detector whose tag is
	// presence only (Blender) uses it to pick between installs.
	Version VersionSpec `yaml:"version"`
	// Args are arguments the application's own invocation requires on an OS,
	// keyed by GOOS (linux, darwin or windows), put before the arguments a job
	// supplies: a flag without which the program opens a window or waits for
	// input on a headless worker. They are literal strings, not format strings.
	// They must never be a license flag: which license a worker holds is the
	// operator's to state in worker.commands.
	Args map[string][]string `yaml:"args"`
}

CommandSpec says how to run the software a detector finds: the command name the presets use, and where its executable lives.

A tag only says the software is installed. The presets run a bare command ("nuke"), and an install often has no command of that name: Nuke is Nuke17.1.exe, and the installer adds nothing to PATH. A CommandSpec lets the worker fill that gap with the newest install it finds, unless the operator or the host already provides the command.

type DetectedCommand added in v0.4.0

type DetectedCommand struct {
	Name string
	// Path is empty when the detector has arguments for this OS but no install
	// was found: the arguments still apply to a command the host provides.
	Path string
	// Args are the detector's arguments for this OS; see [CommandSpec.Args].
	Args []string
	// Version is read from Path by the detector's version regex; empty when it
	// has none or Path does not carry one.
	Version string
}

DetectedCommand is an executable a detector found for a command name.

func DetectCommands added in v0.4.0

func DetectCommands(cfg CapabilitiesConfig, env CheckEnv) ([]DetectedCommand, error)

DetectCommands returns the commands the active detectors (see LoadDetectors) found on env, one per command name, sorted by name. When two detectors name the same command, the first (a built-in) wins, with one exception: an earlier result that found no install (an empty Path, reported only for its arguments) is filled by the first later detector that did find one. Otherwise a built-in that knows only the application's arguments (the silhouette detector's sfxcmd -nogui on Linux) would hide a studio's custom detector for the same command at a non-standard path, and the worker would lose its default for that command.

The merged entry takes the later detector's Path and Version. Its Args are the later detector's own when it declares any for this OS, and otherwise the earlier detector's: the arguments describe the application, not the install, so a custom detector written only to locate the executable keeps them.

type Detector added in v0.2.0

type Detector struct {
	Tag     string      `yaml:"tag"`
	Checks  []Check     `yaml:"checks"`
	Version VersionSpec `yaml:"version"`
	// Command, when set, says how to run the detected software, so the worker
	// can supply a default for the command name its presets use. See
	// [CommandSpec].
	Command *CommandSpec `yaml:"command"`
	Origin  string       `yaml:"-"` // "builtin:<name>" or "custom"; for diagnostics
}

Detector emits a presence tag (and versioned variants) when any check matches.

func BuiltinDetectors added in v0.2.0

func BuiltinDetectors() ([]Detector, error)

BuiltinDetectors parses and validates the embedded built-in detectors.

func LoadDetectors added in v0.2.0

func LoadDetectors(cfg CapabilitiesConfig) ([]Detector, error)

LoadDetectors returns the active detectors: built-ins not named in cfg.Disable, followed by validated custom detectors from cfg.Detect.

func (Detector) Evaluate added in v0.2.0

func (d Detector) Evaluate(env CheckEnv) []string

Evaluate runs the detector's checks against env and returns the presence tags to advertise: the bare Tag if any check matched, plus Tag_<version> for each distinct version captured. Results are de-duplicated and sorted.

Evaluate assumes d has already passed Validate (in particular that Version.From and every check's Env.Matches compile); callers (the capability-detection loaders) validate detectors before evaluating them.

func (Detector) FindCommand added in v0.4.0

func (d Detector) FindCommand(env CheckEnv) (DetectedCommand, bool)

FindCommand returns the executable to run for the detector's command: the newest version among the installs its globs match on env's platform. Two installs of one version (Nuke's 17.1v1 and 17.1v2 both run as Nuke17.1) are ordered by path, so the later release directory wins. It reports false when the detector has no command, or nothing matches and it has no arguments for this platform. With arguments and no match it reports them with an empty Path.

func (Detector) Validate added in v0.2.0

func (d Detector) Validate() error

Validate reports the first structural problem with the detector.

type EnvCheck added in v0.2.0

type EnvCheck struct {
	Name    string `yaml:"name"`
	Matches string `yaml:"matches"`
}

EnvCheck matches an environment variable by presence and optional value regex.

func (*EnvCheck) UnmarshalYAML added in v0.2.0

func (e *EnvCheck) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML accepts either a bare string (env: HFS) or a mapping (env: {name: HFS, matches: "..."}).

type GPUInfo

type GPUInfo struct {
	Vendor string
	Model  string
	// VRAMMb is the total VRAM of the first / primary GPU in mebibytes.
	VRAMMb int
	Count  int
}

GPUInfo describes GPU hardware available on a worker host. It mirrors [protocol.GPUInfo] so callers can convert directly; defined here to avoid an import cycle between the capabilities and protocol packages.

type Probe

type Probe interface {
	// OS returns the operating system identifier (runtime.GOOS equivalent).
	OS() string
	// Arch returns the CPU architecture identifier (runtime.GOARCH equivalent).
	Arch() string
	// OSVersion returns a human-readable OS release string. Returns an empty
	// string when version detection is not supported or fails.
	OSVersion() string
	// CPUCount returns the number of logical CPUs.
	CPUCount() int
	// RAMMb returns total physical RAM in mebibytes. Returns 0 on failure.
	RAMMb() int
	// GPUInfo returns GPU hardware information. Returns a zero GPUInfo when no
	// GPU is detected or detection is not supported.
	GPUInfo() GPUInfo
}

Probe abstracts OS-level hardware queries so tests can inject fake values. All methods must be safe to call concurrently.

type VersionSpec added in v0.2.0

type VersionSpec struct {
	From string `yaml:"from"`
}

VersionSpec extracts a version string from a matched signal via a regex whose named group "v" (or first capturing group) is the version.

Jump to

Keyboard shortcuts

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