rightsizing

package
v0.2.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: Apache-2.0 Imports: 4 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

This section is empty.

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
}

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.

Jump to

Keyboard shortcuts

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