inventory

package
v1.0.29 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package inventory keeps each host's cached instance inventory warm by refreshing it on a schedule, so UI/API reads are served without a live podman sweep and an unreachable host never stalls a request.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EffectiveStatsTimeout added in v1.0.29

func EffectiveStatsTimeout(d time.Duration) time.Duration

EffectiveStatsTimeout maps a configured stats timeout to the value the poller will actually spend: anything <= 0 means defaultStatsTimeout, never "no timeout" (tick blocks the ticker, so an unbounded stats call would hang the whole poll loop) and never "expire instantly".

Exported because the zero-defaulting is not an internal detail: anything reasoning about the per-host budget from the outside — server's startup check that Timeout+StatsTimeout stays under Interval — has to reason about the same effective value, or a bare -container-stats-timeout=0 passes a check the poller then violates by 5s.

Types

type Poller

type Poller struct {
	Svc      Refresher
	Interval time.Duration
	Timeout  time.Duration

	// Stats, when non-nil, samples container resource usage on every tick,
	// alongside the inventory refresh. Its failures are logged and otherwise
	// ignored: reachability is the inventory refresh's to decide, and the
	// Grafana alert rules all gate on podman_api_host_reachable.
	Stats StatsRefresher

	// StatsTimeout bounds one host's stats sample, independently of Timeout.
	// Zero means defaultStatsTimeout — never "no timeout", so a caller that
	// forgets to set it cannot hand the sampler an unbounded call. See tick for
	// why this is a separate budget rather than a share of Timeout (#212).
	StatsTimeout time.Duration
	// contains filtered or unexported fields
}

Poller periodically refreshes every host's inventory into the service cache. It mirrors internal/prune.Scheduler: an immediate first pass so a fresh start warms within one cycle, per-tick panic recovery, a per-host timeout so one hung host can't bleed into the next cycle, and Wait() for clean shutdown.

func (*Poller) Start

func (p *Poller) Start(ctx context.Context, hostsFn func() []string)

Start launches the ticker loop until ctx is cancelled. hostsFn returns the current host ids on each tick (so SIGHUP host reloads are picked up).

func (*Poller) StartVolumeUsage added in v1.0.28

func (p *Poller) StartVolumeUsage(ctx context.Context, hostsFn func() []string, r VolumeUsageRefresher, interval, timeout time.Duration)

StartVolumeUsage runs a separate, much slower loop that sizes each host's volumes. It is deliberately NOT part of tick(): podman's system df walks the whole store and can take minutes, so it must never delay an inventory refresh. Failures leave the previous sizing in place; staleness surfaces as podman_api_volume_usage_age_seconds rather than as a gap. It touches no reachability state, for the same reason the stats sampler doesn't.

func (*Poller) Wait

func (p *Poller) Wait()

Wait blocks until the poller goroutine has exited after ctx cancellation.

type Refresher

type Refresher interface {
	RefreshHost(ctx context.Context, host string) error
}

Refresher refreshes one host's cached inventory. Implemented by *instance.Service.RefreshHost.

type StatsRefresher added in v1.0.28

type StatsRefresher interface {
	RefreshHostStats(ctx context.Context, host string) error
	// DropHostStats discards the host's cached samples. Called when the host is
	// not going to be sampled at all. No context: it does no I/O.
	DropHostStats(host string)
}

StatsRefresher samples one host's container resource usage, or retires the samples it already holds. Implemented by *instance.Service.

Both methods are required, not optional: a sampler that can be skipped but not retired freezes a down host's series at their last value. Keeping them on one interface makes that a compile error rather than a silent metrics bug.

type VolumeUsageRefresher added in v1.0.28

type VolumeUsageRefresher interface {
	RefreshHostVolumeUsage(ctx context.Context, host string) error
}

VolumeUsageRefresher sizes one host's volumes. Implemented by *instance.Service.RefreshHostVolumeUsage.

Jump to

Keyboard shortcuts

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