types

package
v0.5.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AutoscalingLabelPrefix is the prefix for all autoscaling annotation keys
	AutoscalingLabelPrefix = "autoscaling.aibrix.ai/"

	// MaxScaleUpRateLabel controls the maximum rate at which to scale up
	// Value: float (e.g., "2.0" means can double replicas in one step)
	MaxScaleUpRateLabel = AutoscalingLabelPrefix + "max-scale-up-rate"

	// MaxScaleDownRateLabel controls the maximum rate at which to scale down
	// Value: float (e.g., "2.0" means can halve replicas in one step)
	MaxScaleDownRateLabel = AutoscalingLabelPrefix + "max-scale-down-rate"

	// ScaleUpToleranceLabel sets tolerance for upward metric fluctuations
	// Value: float (e.g., "0.1" means 10% tolerance before scaling up)
	ScaleUpToleranceLabel = AutoscalingLabelPrefix + "scale-up-tolerance"

	// ScaleDownToleranceLabel sets tolerance for downward metric fluctuations
	// Value: float (e.g., "0.1" means 10% tolerance before scaling down)
	ScaleDownToleranceLabel = AutoscalingLabelPrefix + "scale-down-tolerance"

	// PanicThresholdLabel sets the threshold for entering panic mode (KPA only)
	// Value: float (e.g., "2.0" means panic when short-term exceeds 2x long-term average)
	PanicThresholdLabel = AutoscalingLabelPrefix + "panic-threshold"

	// ScaleUpCooldownWindowLabel sets the cooldown window for scale-up decisions
	// Value: duration (e.g., "0s", "60s")
	ScaleUpCooldownWindowLabel = AutoscalingLabelPrefix + "scale-up-cooldown-window"

	// ScaleDownCooldownWindowLabel sets the cooldown window for scale-down decisions
	// Value: duration (e.g., "300s", "5m")
	ScaleDownCooldownWindowLabel = AutoscalingLabelPrefix + "scale-down-cooldown-window"

	// ScaleToZeroLabel enables/disables scaling to zero replicas
	// Value: bool (e.g., "true", "false")
	ScaleToZeroLabel = AutoscalingLabelPrefix + "scale-to-zero"
)

Annotation keys for PodAutoscaler configuration These constants define the annotation keys used to configure autoscaling behavior

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregatedMetrics

type AggregatedMetrics struct {
	MetricKey    MetricKey
	CurrentValue float64
	StableValue  float64
	PanicValue   float64
	Trend        float64
	Confidence   float64
	LastUpdated  time.Time
}

AggregatedMetrics contains processed metrics data

type CollectionSpec

type CollectionSpec struct {
	Namespace    string // Target namespace
	TargetName   string // Target resource name
	MetricName   string // Name of the metric
	MetricSource autoscalingv1alpha1.MetricSource
	Pods         []corev1.Pod
	Timestamp    time.Time
}

CollectionSpec defines what metrics to collect

type MetricHistory

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

MetricHistory tracks historical metrics for trend analysis

func NewMetricHistory

func NewMetricHistory(maxAge time.Duration) *MetricHistory

NewMetricHistory creates a new metric history tracker

func (*MetricHistory) Add

func (h *MetricHistory) Add(value float64, timestamp time.Time)

Add adds a new metric point to history

func (*MetricHistory) GetStats

func (h *MetricHistory) GetStats(now time.Time) WindowStats

GetStats calculates statistics for the history

type MetricKey

type MetricKey struct {
	Namespace  string // Target workload namespace
	Name       string // Target workload name
	MetricName string // Metric name (e.g., "concurrency", "qps")
	// PodAutoscaler identification for multi-tenancy
	PaNamespace string // PodAutoscaler namespace
	PaName      string // PodAutoscaler name
}

MetricKey identifies a specific metric for a PodAutoscaler

func (MetricKey) String

func (m MetricKey) String() string

String returns a unique string identifier for this metric key

type MetricPoint

type MetricPoint struct {
	Timestamp time.Time
	Value     float64
}

MetricPoint represents a single metric measurement

type MetricSnapshot

type MetricSnapshot struct {
	Namespace  string
	TargetName string
	MetricName string
	Values     []float64 // TODO(Jeffwan): Prefill/Decode case needs extension
	Timestamp  time.Time
	Source     string
	Error      error
}

MetricSnapshot contains collected raw metrics

type ScaleRequest

type ScaleRequest struct {
	PodAutoscaler   autoscalingv1alpha1.PodAutoscaler
	CurrentReplicas int32
	Pods            []corev1.Pod
	Timestamp       time.Time
}

ScaleRequest contains everything needed for scaling

type ScaleResult

type ScaleResult struct {
	DesiredPodCount     int32
	ExcessBurstCapacity int32
	ScaleValid          bool
	Reason              string
	Algorithm           string
	Metadata            map[string]interface{}
}

ScaleResult contains scaling outcome - extends existing ScaleResult

type ScaleTarget

type ScaleTarget struct {
	Namespace  string
	Name       string
	Kind       string
	APIVersion string
	MetricKey  MetricKey
}

ScaleTarget represents what to scale

type ScalingConstraints

type ScalingConstraints struct {
	MinReplicas int32
	MaxReplicas int32
}

ScalingConstraints defines scaling limits

type TimeWindow

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

TimeWindow manages a sliding window of metric values

func NewTimeWindow

func NewTimeWindow(duration, granularity time.Duration) *TimeWindow

NewTimeWindow creates a new time window

func (*TimeWindow) Avg

func (tw *TimeWindow) Avg() (float64, error)

Avg returns the average value in the window

func (*TimeWindow) Max

func (tw *TimeWindow) Max() (float64, error)

Max returns the maximum value in the window

func (*TimeWindow) Min

func (tw *TimeWindow) Min() (float64, error)

Min returns the minimum value in the window

func (*TimeWindow) Record

func (tw *TimeWindow) Record(timestamp time.Time, value float64)

Record adds a value to the time window

func (*TimeWindow) Size

func (tw *TimeWindow) Size() int

Size returns the number of data points in the window

func (*TimeWindow) String

func (tw *TimeWindow) String() string

String returns a string representation of the time window

func (*TimeWindow) Values

func (tw *TimeWindow) Values() []float64

Values returns all values in the window in chronological order

type WindowStats

type WindowStats struct {
	DataPoints  int
	Mean        float64
	Variance    float64
	StdDev      float64
	Min         float64
	Max         float64
	LastUpdate  time.Time
	WindowStart time.Time
	WindowEnd   time.Time
}

WindowStats represents statistics about a time window

Jump to

Keyboard shortcuts

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