obs

package
v1.0.28 Latest Latest
Warning

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

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

Documentation

Overview

Package obs holds the observability primitives: structured audit log middleware and Prometheus metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAuditMiddleware

func NewAuditMiddleware(w io.Writer) func(http.Handler) http.Handler

NewAuditMiddleware writes one JSON line per state-changing request to w. It logs nothing for safe methods (GET/HEAD/OPTIONS).

Types

type InventoryCollector added in v1.0.23

type InventoryCollector struct {
	// contains filtered or unexported fields
}

InventoryCollector renders per-container and per-host state from the warm inventory cache at scrape time.

It is a collector rather than a set of pushed gauges for two reasons: it does no podman I/O, so a scrape can never block behind an unreachable host; and it renders present state, so a deleted or renamed instance's series disappear on the next poll instead of freezing at their last value forever.

func NewInventoryCollector added in v1.0.23

func NewInventoryCollector(reg prometheus.Registerer, src InventorySource, hosts func() []string) *InventoryCollector

NewInventoryCollector builds the collector and registers it on reg.

hosts must be the same host-list function the inventory poller uses. A host that has never been polled then still reports podman_api_host_reachable 0 rather than vanishing from the metric set, which would read as "fine".

func (*InventoryCollector) Collect added in v1.0.23

func (c *InventoryCollector) Collect(ch chan<- prometheus.Metric)

func (*InventoryCollector) Describe added in v1.0.23

func (c *InventoryCollector) Describe(ch chan<- *prometheus.Desc)

type InventorySource added in v1.0.23

type InventorySource interface {
	InventorySnapshot() map[string]instance.HostInventory
}

InventorySource supplies the current warm-cache inventory snapshot. Implemented by *instance.Service.

type JobMetrics

type JobMetrics struct {
	// contains filtered or unexported fields
}

JobMetrics implements jobs.Metrics with Prometheus collectors. Created with an explicit Registerer so production registers on the default registry (NewJobMetrics(prometheus.DefaultRegisterer)) and tests use a private one.

func NewJobMetrics

func NewJobMetrics(reg prometheus.Registerer) *JobMetrics

NewJobMetrics builds and registers the collectors on reg.

func (*JobMetrics) ChildFailure

func (m *JobMetrics) ChildFailure(kind string)

ChildFailure records an evacuate child migration failure.

func (*JobMetrics) JobEnqueued

func (m *JobMetrics) JobEnqueued(kind string)

JobEnqueued records a new job being enqueued.

func (*JobMetrics) JobFinished

func (m *JobMetrics) JobFinished(kind, result string)

JobFinished records a terminal job outcome (succeeded/failed/canceled).

func (*JobMetrics) JobStarted

func (m *JobMetrics) JobStarted(kind string)

JobStarted records a job being claimed and started.

When JobEnqueued is wired at dispatch sites, restore m.enqueued.Dec() here so the queue-depth gauge increments on enqueue and decrements on start.

func (*JobMetrics) ObserveDuration

func (m *JobMetrics) ObserveDuration(kind string, d time.Duration)

ObserveDuration records a job handler's wall-clock duration.

func (*JobMetrics) Rollback

func (m *JobMetrics) Rollback(kind string)

Rollback records a migrate rollback event.

type Metrics

type Metrics struct {
	// contains filtered or unexported fields
}

Metrics holds the Prometheus collectors. New() registers them with the default registry; call Handler() to expose /metrics.

func New

func New() *Metrics

func (*Metrics) Handler

func (m *Metrics) Handler() http.Handler

Handler is the http.Handler for the /metrics endpoint.

func (*Metrics) Middleware

func (m *Metrics) Middleware() func(http.Handler) http.Handler

Middleware returns an HTTP middleware that records request count and duration. The route label uses r.Pattern (the registered mux pattern, available in Go 1.22+) to avoid label cardinality explosion from path parameters. Falls back to "_other" when the pattern is not populated.

type PruneMetrics

type PruneMetrics struct {
	// contains filtered or unexported fields
}

PruneMetrics implements the prune.Metrics interface (structurally — obs must not import prune) with Prometheus counters. Created with an explicit Registerer so production registers on the default registry (NewPruneMetrics(prometheus.DefaultRegisterer)) and tests use a private one.

func NewPruneMetrics

func NewPruneMetrics(reg prometheus.Registerer) *PruneMetrics

NewPruneMetrics builds and registers the prune collectors on reg.

func (*PruneMetrics) Reclaimed

func (m *PruneMetrics) Reclaimed(host, scope string, bytes int64)

Reclaimed adds reclaimed bytes for a scope.

func (*PruneMetrics) RunDone

func (m *PruneMetrics) RunDone(host, result string)

RunDone records one finished prune run.

type StatsCollector added in v1.0.28

type StatsCollector struct {
	// contains filtered or unexported fields
}

StatsCollector renders per-container resource samples at scrape time.

Like InventoryCollector it does no podman I/O — it reads two cached snapshots. The inventory snapshot is what supplies template/slug: podman reports stats by container name only, so a sample whose container is not in the inventory is dropped rather than emitted under a guessed identity.

func NewStatsCollector added in v1.0.28

func NewStatsCollector(reg prometheus.Registerer, stats StatsSource, inv InventorySource, hosts func() []string) *StatsCollector

NewStatsCollector builds the collector and registers it on reg.

hosts must be the same host-list function the inventory poller and InventoryCollector use, and it — not the cache maps — is what Collect enumerates. Neither cache is pruned when a host leaves hosts/*.yaml on SIGHUP, so iterating a snapshot would re-emit that host's last sample on every scrape forever: cumulative counters frozen mid-flight read as idle containers, and the documented mitigation (gate on podman_api_host_reachable == 1) is unavailable because InventoryCollector has already stopped emitting that series for the departed host.

func (*StatsCollector) Collect added in v1.0.28

func (c *StatsCollector) Collect(ch chan<- prometheus.Metric)

func (*StatsCollector) Describe added in v1.0.28

func (c *StatsCollector) Describe(ch chan<- *prometheus.Desc)

type StatsSource added in v1.0.28

type StatsSource interface {
	StatsSnapshot() map[string]instance.HostStats
}

StatsSource supplies the latest per-host container resource samples. Implemented by *instance.Service.

type VolumeUsageCollector added in v1.0.28

type VolumeUsageCollector struct {
	// contains filtered or unexported fields
}

VolumeUsageCollector renders volume sizes at scrape time, attributing each volume to its instance via the inventory snapshot. Does no podman I/O.

func NewVolumeUsageCollector added in v1.0.28

func NewVolumeUsageCollector(reg prometheus.Registerer, src VolumeUsageSource, inv InventorySource, hosts func() []string) *VolumeUsageCollector

NewVolumeUsageCollector builds the collector and registers it on reg.

hosts must be the same host-list function the inventory poller and InventoryCollector use, and it — not the cache map — is what Collect enumerates. volumeUsageCache deliberately keeps a host's last sizing through a failed walk and has no drop path at all, so iterating a snapshot would leave a host removed on SIGHUP reporting frozen sizes and an ever-climbing podman_api_volume_usage_age_seconds forever.

func (*VolumeUsageCollector) Collect added in v1.0.28

func (c *VolumeUsageCollector) Collect(ch chan<- prometheus.Metric)

func (*VolumeUsageCollector) Describe added in v1.0.28

func (c *VolumeUsageCollector) Describe(ch chan<- *prometheus.Desc)

type VolumeUsageSource added in v1.0.28

type VolumeUsageSource interface {
	VolumeUsageSnapshot() map[string]instance.HostVolumeUsage
}

VolumeUsageSource supplies the latest per-host volume sizing. Implemented by *instance.Service.

Jump to

Keyboard shortcuts

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