Documentation
¶
Index ¶
- Constants
- type CapacityProvider
- type Collector
- func (c *Collector) MarkSandboxStopped(target sandbox.MetricsTarget)
- func (c *Collector) SetCgroupStatsReader(reader func(string) (cgroupmanager.Stats, error))
- func (c *Collector) SetParentMemoryReader(reader func() (cgroupmanager.ParentMemoryStats, error))
- func (c *Collector) SetSandboxMetricsSource(source SandboxMetricsSource)
- func (c *Collector) Shutdown(ctx context.Context) error
- type Module
- func (m *Module) Capacity() (int64, int64)
- func (m *Module) Healthy() bool
- func (m *Module) MarkSandboxStopped(target sandbox.MetricsTarget)
- func (m *Module) ReleaseTransientMemory(owner string)
- func (m *Module) ReserveTransientMemory(owner string, bytes int64) (func(), bool)
- func (m *Module) SetCgroupStatsReader(reader func(string) (cgroupmanager.Stats, error))
- func (m *Module) SetEphemeralStorageProvider(provider ephemeralStorageProvider)
- func (m *Module) SetMemoryLimit(root string, maxBytes int64) error
- func (m *Module) SetParentMemoryReader(reader func() (cgroupmanager.ParentMemoryStats, error))
- func (m *Module) SetSandboxMetricsSource(source SandboxMetricsSource)
- func (m *Module) SetXPUProvider(provider xpuProvider)
- func (m *Module) Start() error
- func (m *Module) Stop()
- type NodeResourceManager
- type SandboxMetricsSource
Constants ¶
const ( ProviderKubernetes = "kubernetes" ProviderCgroup = "cgroup" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CapacityProvider ¶
CapacityProvider reports the node's currently-available (schedulable) CPU (millicores) and memory (bytes) as computed by the resource manager and served over the /resource socket. It is satisfied by resourcemanager.Module; declared locally to avoid an import cycle. Returns (0, 0) before the first refresh, which callbacks treat as "no data" and skip.
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector reports node CPU, memory, and disk metrics via OTel.
func NewCollector ¶
func NewCollector(ctx context.Context, capacity CapacityProvider) (*Collector, error)
NewCollector creates a Collector that exports metrics to the local OTel collector over HTTP (port 4318).
func (*Collector) MarkSandboxStopped ¶
func (c *Collector) MarkSandboxStopped(target sandbox.MetricsTarget)
MarkSandboxStopped records an explicit terminal value without performing network I/O. The regular metrics callback exports running=0 for several collection cycles and then discards the copied labels.
func (*Collector) SetCgroupStatsReader ¶
func (c *Collector) SetCgroupStatsReader( reader func(string) (cgroupmanager.Stats, error), )
SetCgroupStatsReader connects the collector to the already-selected CgroupManager backend. This keeps node, sandbox, and gRPC stats on the same detected cgroup version.
func (*Collector) SetParentMemoryReader ¶
func (c *Collector) SetParentMemoryReader( reader func() (cgroupmanager.ParentMemoryStats, error), )
SetParentMemoryReader connects parent memory metrics to the same managed cgroup and selected memory controller used by CgroupManager. Passing nil disables observations until another reader is supplied.
func (*Collector) SetSandboxMetricsSource ¶
func (c *Collector) SetSandboxMetricsSource(source SandboxMetricsSource)
SetSandboxMetricsSource connects the collector to the sandbox manager after the manager has finished initialization.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module owns node-resource reporting in either cgroup or Kubernetes watch mode. It runs the periodic refresh loop and serves the Unix-domain `/resource` endpoint consumed by an external scheduler.
Lifecycle:
- NewModule constructs the underlying NodeResourceManager.
- Start launches the refresh loop and HTTP listener on sockPath.
- Stop closes the listener and drains the background loops.
- Healthy reports whether at least one successful refresh has occurred within the staleness window.
func NewModule ¶
NewModule constructs the configured node-resource module. sockPath is the Unix socket exposed to the external collector.
func (*Module) Capacity ¶
Capacity returns the node's currently-available CPU (millicores) and memory (bytes) — the same figure the refresh loop computes via GetAvailableResource and serves over the /resource socket. It satisfies metrics.CapacityProvider so node.cpu.limit / node.memory.total report exactly what the resource manager tells the proxy is schedulable, rather than a static box size.
Reading the cached values here (instead of calling GetAvailableResource again) keeps the metric in lockstep with the socket and avoids re-triggering the underlying computation's smoothing/state side effects. availCpu is stored in cores (the refresh loop already divided by 1000), so scale back to millicores to match the CapacityProvider contract. Returns (0, 0) before the first successful refresh, which the collector treats as "no data yet" and skips.
func (*Module) Healthy ¶
Healthy reports whether the latest provider refresh was within the staleness window.
func (*Module) MarkSandboxStopped ¶
func (m *Module) MarkSandboxStopped(target sandbox.MetricsTarget)
MarkSandboxStopped records a terminal sandbox state for asynchronous export.
func (*Module) ReleaseTransientMemory ¶
ReleaseTransientMemory returns a short-lived reservation to advertised node capacity. It is idempotent so both the operation and a later sandbox delete can safely release the same owner.
func (*Module) ReserveTransientMemory ¶
ReserveTransientMemory atomically removes short-lived runtime overhead from the node capacity advertised to the scheduler. It fails when the refreshed available capacity cannot cover the request. The returned release function is idempotent so callers can use it on every terminal path.
func (*Module) SetCgroupStatsReader ¶
func (m *Module) SetCgroupStatsReader( reader func(string) (cgroupmanager.Stats, error), )
SetCgroupStatsReader routes all cgroup-backed OTel metrics through the CgroupManager's auto-selected v1/v2 implementation.
func (*Module) SetEphemeralStorageProvider ¶
func (m *Module) SetEphemeralStorageProvider(provider ephemeralStorageProvider)
SetEphemeralStorageProvider adds filestore writable-layer capacity and its capability marker to /resource. The first refresh is synchronous so a scheduler querying immediately after sandboxd startup sees a complete node resource snapshot.
func (*Module) SetMemoryLimit ¶
SetMemoryLimit clips each refreshed provider capacity to the parent maxBytes. For the cgroup provider, root is the managed cgroup name within its visible memory-controller mount. CPU capacity continues to use sandboxd's own group. Other providers retain their existing policies before the capacity is clipped. Call this before Start, after the managed root's limit has been applied.
func (*Module) SetParentMemoryReader ¶
func (m *Module) SetParentMemoryReader( reader func() (cgroupmanager.ParentMemoryStats, error), )
SetParentMemoryReader routes parent memory metrics through the managed CgroupManager's selected memory controller and configured parent cgroup.
func (*Module) SetSandboxMetricsSource ¶
func (m *Module) SetSandboxMetricsSource(source SandboxMetricsSource)
SetSandboxMetricsSource connects the node metrics collector to sandbox lifecycle state once the sandbox manager is ready.
func (*Module) SetXPUProvider ¶
func (m *Module) SetXPUProvider(provider xpuProvider)
SetXPUProvider adds the node-local accelerator inventory to /resource.
func (*Module) Start ¶
Start launches the refresh loop and HTTP server. It returns once the listener is bound so external collectors can use the socket immediately.
func (*Module) Stop ¶
func (m *Module) Stop()
Stop closes the unix listener and waits for the refresh loop to drain. Safe to call from any goroutine; idempotent. The previous select+close pattern races on concurrent callers (two goroutines can both pass the default branch and double-close stopCh, panicking). sync.Once gives a true single-shot close; wg.Wait stays outside so every caller blocks until the background loops have actually exited, not just until the first caller observed stopCh as closed.
type NodeResourceManager ¶
func NewNodeResourceManager ¶
func NewNodeResourceManager(provider string) (NodeResourceManager, error)
NewNodeResourceManager constructs the configured CPU and memory capacity source. Kubernetes remains the default for backward compatibility; cgroup is the read-only provider used by standalone deployments.
type SandboxMetricsSource ¶
type SandboxMetricsSource interface {
SandboxMetricsTargets() []sandbox.MetricsTarget
}
SandboxMetricsSource supplies immutable snapshots of running sandboxes.