autoscale

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package autoscale is target tracking for services (§5.5): every 15s it reads each policy's metric from VictoriaMetrics and moves the desired task count towards the number that brings the metric back to its target, quickly out and conservatively in.

Index

Constants

View Source
const (
	// Interval between evaluations.
	Interval = 15 * time.Second
	// TopicEvent carries a store.ScalingEvent when the autoscaler scales.
	TopicEvent = "scaling.event"
	// Actor is who the autoscaler's changes are attributed to.
	Actor = "autoscaler"
)

Variables

View Source
var Metrics = map[string]string{
	"cpu":     "% of reserved CPU",
	"memory":  "% of reserved memory",
	"rps":     "requests/s per task",
	"latency": "ms p95",
}

Metrics the policies can track and their units.

Functions

func Validate

func Validate(p *store.ScalingPolicy) error

Validate checks a policy and fills in defaults.

Types

type Current

type Current struct {
	Value       *float64   `json:"value"` // nil: no data
	EvaluatedAt *time.Time `json:"evaluatedAt"`
}

Current is the latest measurement of a service's policy metric.

type Decision

type Decision struct {
	Desired int
	Reason  string
}

Decision is what one evaluation concluded.

func Decide

func Decide(p store.ScalingPolicy, current, running int, value float64, ok bool) Decision

Decide computes the desired count for a measurement. current is the desired count, running the running tasks; it changes no state.

type ErrInvalid

type ErrInvalid struct{ Err error }

ErrInvalid wraps validation errors.

func (ErrInvalid) Error

func (e ErrInvalid) Error() string

type Manager

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

func New

func New(st *store.Store, wl *workload.Manager, m Querier, bus *events.Bus, log *slog.Logger) *Manager

func (*Manager) CurrentValue

func (m *Manager) CurrentValue(serviceID string) Current

CurrentValue returns what the last evaluation measured.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context)

Run evaluates every policy each Interval until ctx ends.

type Querier

type Querier interface {
	Instant(ctx context.Context, q string) ([]metrics.Sample, error)
	Import(ctx context.Context, text string) error
}

Querier reads metrics (metrics.Store).

Jump to

Keyboard shortcuts

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