resourcemanager

package
v0.0.0-...-13d8f12 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 38 Imported by: 1 module, 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

Index

Constants

View Source
const (
	ProviderKubernetes = "kubernetes"
	ProviderCgroup     = "cgroup"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CapacityProvider

type CapacityProvider interface {
	Capacity() (int64, int64)
}

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.

func (*Collector) Shutdown

func (c *Collector) Shutdown(ctx context.Context) error

Shutdown flushes pending metrics and closes the exporter connection.

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

func NewModule(sockPath, provider string) (*Module, error)

NewModule constructs the configured node-resource module. sockPath is the Unix socket exposed to the external collector.

func (*Module) Capacity

func (m *Module) Capacity() (int64, int64)

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

func (m *Module) Healthy() bool

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

func (m *Module) ReleaseTransientMemory(owner string)

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

func (m *Module) ReserveTransientMemory(owner string, bytes int64) (func(), bool)

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

func (m *Module) SetMemoryLimit(root string, maxBytes int64) error

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

func (m *Module) Start() error

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

type NodeResourceManager interface {
	GetAvailableResource() (int64, int64, error)
	Stop()
}

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.

Jump to

Keyboard shortcuts

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