rightsizing

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package rightsizing is a deterministic, pure-Go engine that turns an app's historical CPU/memory usage into a resource-limit suggestion. It is a read-and-suggest layer on top of the platform API, per this project's AI design rule: it never calls an external model, never writes to any resource, and its output is never applied automatically. Every recommendation is backed by literal samples or a literal OOM signal it was given; when there isn't enough history yet, Recommend says so rather than guessing.

Index

Constants

View Source
const (
	ConfidenceHigh   = "high"
	ConfidenceMedium = "medium"
	ConfidenceLow    = "low"
)

Confidence levels a DimensionRecommendation can carry.

View Source
const (
	ActionRaise = "raise"
	ActionLower = "lower"
	ActionKeep  = "keep"
)

Actions a DimensionRecommendation can suggest.

Variables

This section is empty.

Functions

func FormatCPU added in v0.2.0

func FormatCPU(nanoCPUs int64) string

FormatCPU renders nano-CPUs as cores.

func FormatMemory added in v0.2.0

func FormatMemory(bytes int64) string

FormatMemory renders bytes as MiB or GiB.

func HumanDuration added in v0.2.0

func HumanDuration(d time.Duration) string

HumanDuration renders a duration in whole days, hours or minutes.

func HumanWindow added in v0.2.0

func HumanWindow(d time.Duration) string

HumanWindow renders a lookback as "last 7 days" rather than "168h0m0s".

func RoundCPUUp added in v0.2.0

func RoundCPUUp(nanoCPUs float64) int64

RoundCPUUp rounds nano-CPUs up to the next suggested step, never below 0.1 core.

func RoundMemoryUp added in v0.2.0

func RoundMemoryUp(bytes float64) int64

RoundMemoryUp rounds a byte count up to the next suggested memory step.

Types

type DimensionRecommendation

type DimensionRecommendation struct {
	Dimension      string
	SampleCount    int
	DataSufficient bool
	Confidence     string
	CurrentLimit   int64
	P95Usage       float64
	P99Usage       float64
	SuggestedLimit int64
	// Action is "" when there isn't enough data, or no limit is
	// currently set, to responsibly suggest raising or lowering one.
	Action string
	Reason string
}

DimensionRecommendation is one resource dimension's (memory or CPU) suggestion.

type Input

type Input struct {
	ServiceName        string
	Now                time.Time
	LookbackWindow     time.Duration
	MemorySamples      []Sample
	CPUPercentSamples  []Sample
	CurrentMemoryBytes int64
	CurrentNanoCPUs    int64
	OOM                *OOMEvidence
	// Tuning overrides the default thresholds; a zero field keeps its default.
	Tuning Tuning
}

Input bundles one app's usage history and current limits. CPUPercentSamples is Docker's own 0-100-per-core convention (internal/docker.ContainerStats. CPUPercent's own doc comment): a container fully using 2 cores reads 200, converted internally to nano-CPUs to compare against CurrentNanoCPUs.

type OOMEvidence

type OOMEvidence struct {
	DetectedAt time.Time
	Excerpt    string
}

OOMEvidence is a genuinely observed OOM-kill signal (a log line matching a known OOM pattern; see internal/diagnose.OOMLogPatterns), never fabricated from usage numbers alone.

type Result

type Result struct {
	ServiceName    string
	LookbackWindow time.Duration
	Memory         DimensionRecommendation
	CPU            DimensionRecommendation
	OOM            *OOMEvidence
}

Result is Recommend's output: one recommendation per dimension, plus whatever OOM evidence fed into the memory one.

func Recommend

func Recommend(in Input) Result

Recommend synthesizes in's usage history and current limits into a deterministic suggestion per dimension. The same Input always produces the same Result.

type Sample

type Sample struct {
	Timestamp time.Time
	Value     float64
}

Sample is one raw (timestamp, value) reading, the shape internal/telemetry.Sample already has trimmed to what this package needs, kept local so this package doesn't depend on internal/telemetry.

type Tuning added in v0.2.0

type Tuning struct {
	MemoryMargin float64
	CPUMargin    float64
	RaiseAt      float64
	LowerAt      float64
	MinCoverage  time.Duration
}

Tuning holds the thresholds Recommend uses, so callers can source them from env.

Jump to

Keyboard shortcuts

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