footprint

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package footprint bounds and measures the control plane's idle cost: a default memory limit, a registry of background loops, and process stats.

Index

Constants

View Source
const (
	EnvMemLimit        = "GOMEMLIMIT"
	EnvMemLimitPercent = "APP_GOMEMLIMIT_PERCENT"
	DefaultPercent     = 80
)

Env vars read by ApplyMemoryLimit.

Variables

This section is empty.

Functions

func Every

func Every(ctx context.Context, name string, interval time.Duration, logger *slog.Logger, tick func(context.Context) error) error

Every runs tick on interval until ctx ends. The first tick is delayed by a random jitter of up to a tenth of the interval so loops do not wake together, and each tick is recorded.

func LimitFor

func LimitFor(total int64, percent int) int64

LimitFor returns percent of total bytes, or 0 when the result would be too small to be safe.

func Percent

func Percent(getenv func(string) string) int

Percent reads APP_GOMEMLIMIT_PERCENT; 0 disables the default limit.

Types

type Loop

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

Loop records the runs of one background loop.

func Track

func Track(name string, interval time.Duration) *Loop

Track returns the registry entry for name, creating it on first use.

func (*Loop) Active

func (l *Loop) Active() func()

Active marks the loop running and returns the func that marks it stopped.

func (*Loop) Observe

func (l *Loop) Observe(start time.Time, err error)

Observe records one finished run that began at start.

type LoopInfo

type LoopInfo struct {
	Name         string    `json:"name"`
	IntervalSecs float64   `json:"interval_seconds"`
	Runs         int64     `json:"runs"`
	Errors       int64     `json:"errors"`
	LastRunAt    time.Time `json:"last_run_at"`
	LastDuration float64   `json:"last_duration_ms"`
	BusyMS       float64   `json:"busy_ms_total"`
	CostPercent  float64   `json:"cost_percent"`
	Running      bool      `json:"running"`
	LastError    string    `json:"last_error,omitempty"`
	// contains filtered or unexported fields
}

LoopInfo is the observable state of one background loop.

func Loops

func Loops() []LoopInfo

Loops returns every registered loop, busiest first.

type MemoryLimit

type MemoryLimit struct {
	LimitBytes int64  `json:"limit_bytes"`
	Source     string `json:"source"`
	Percent    int    `json:"percent"`
}

MemoryLimit describes what ApplyMemoryLimit decided.

func ApplyMemoryLimit

func ApplyMemoryLimit(getenv func(string) string, logger *slog.Logger) MemoryLimit

ApplyMemoryLimit sets a soft Go memory limit from the container or host memory unless GOMEMLIMIT is already set.

func CurrentMemoryLimit

func CurrentMemoryLimit() MemoryLimit

CurrentMemoryLimit returns what the last ApplyMemoryLimit call decided.

type Proc

type Proc struct {
	RSSBytes   uint64  `json:"rss_bytes"`
	HeapBytes  uint64  `json:"heap_bytes"`
	Goroutines int     `json:"goroutines"`
	Threads    int     `json:"threads"`
	OpenFDs    int     `json:"open_fds"`
	CPUSeconds float64 `json:"cpu_seconds"`
	CPUPercent float64 `json:"cpu_percent"`
}

Proc is a point in time reading of the process footprint.

func ReadProc

func ReadProc() Proc

ReadProc samples the process. CPUPercent is relative to the previous call (or process start for the first).

Jump to

Keyboard shortcuts

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