capabilities

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: AGPL-3.0 Imports: 7 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

	// 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 always the empty string for list-style tags (e.g.
	// "maya-2025") and a non-empty string for key=value tags if callers choose
	// to use that convention.
	//
	// 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 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) MergeManualTags

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

MergeManualTags merges manual capability tags from WorkerConfig.Worker.CapabilityTags into c.Tags. Each tag string is stored as a map key with an empty value, signaling presence (e.g. "maya-2025", "gpu", "highram").

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

Jump to

Keyboard shortcuts

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