algorithm

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: 9 Imported by: 0

Documentation

Overview

Package algorithm provides scaling algorithms for different autoscaling strategies. Each strategy (KPA, APA, HPA) has its own algorithm implementation that computes target replicas based on metrics and scaling context.

Index

Constants

View Source
const (
	MinScaleRate     = 1.0
	DefaultTolerance = 0.0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APAAlgorithm

type APAAlgorithm struct{}

APAAlgorithm implements Application-specific Pod Autoscaling This is a stateless struct that can be safely reused across goroutines

func (*APAAlgorithm) ComputeRecommendation

func (a *APAAlgorithm) ComputeRecommendation(ctx context.Context, request ScalingRequest) (*ScalingRecommendation, error)

ComputeRecommendation calculates desired replica count for APA strategy

func (*APAAlgorithm) GetAlgorithmType

func (a *APAAlgorithm) GetAlgorithmType() string

GetAlgorithmType returns the algorithm type

type HPAAlgorithm

type HPAAlgorithm struct{}

HPAAlgorithm is a placeholder for HPA strategy (actual HPA is handled by K8s HPA resources) This is a stateless struct that can be safely reused across goroutines

func (*HPAAlgorithm) ComputeRecommendation

func (a *HPAAlgorithm) ComputeRecommendation(ctx context.Context, request ScalingRequest) (*ScalingRecommendation, error)

ComputeRecommendation for HPA just returns current replicas as HPA is managed by K8s

func (*HPAAlgorithm) GetAlgorithmType

func (a *HPAAlgorithm) GetAlgorithmType() string

GetAlgorithmType returns the algorithm type

type KPAAlgorithm

type KPAAlgorithm struct{}

KPAAlgorithm implements Knative-style Pod Autoscaling with panic and stable windows This is a stateless struct that can be safely reused across goroutines

func (*KPAAlgorithm) ComputeRecommendation

func (a *KPAAlgorithm) ComputeRecommendation(ctx context.Context, request ScalingRequest) (*ScalingRecommendation, error)

ComputeRecommendation calculates desired replica count for KPA strategy

func (*KPAAlgorithm) GetAlgorithmType

func (a *KPAAlgorithm) GetAlgorithmType() string

GetAlgorithmType returns the algorithm type

type ScalingAlgorithm

type ScalingAlgorithm interface {
	// ComputeRecommendation calculates desired replica count based on aggregated metrics
	// All configuration is passed via the request to keep the algorithm stateless
	ComputeRecommendation(ctx context.Context, request ScalingRequest) (*ScalingRecommendation, error)

	// GetAlgorithmType returns the algorithm type (kpa, apa, hpa)
	GetAlgorithmType() string
}

ScalingAlgorithm computes target replicas based on metrics and context Implementations must be stateless and thread-safe for concurrent use

func NewScalingAlgorithm

func NewScalingAlgorithm(strategy autoscalingv1alpha1.ScalingStrategyType) ScalingAlgorithm

NewScalingAlgorithm creates a stateless algorithm instance for the given strategy Instances can be safely cached and reused across goroutines

type ScalingRecommendation

type ScalingRecommendation struct {
	DesiredReplicas int32
	Confidence      float64
	Reason          string
	Algorithm       string
	ScaleValid      bool
	Metadata        map[string]interface{}
}

ScalingRecommendation contains the scaling decision

type ScalingRequest

type ScalingRequest struct {
	Target            types.ScaleTarget
	CurrentReplicas   int32
	AggregatedMetrics *types.AggregatedMetrics
	ScalingContext    scalingctx.ScalingContext
	Timestamp         time.Time
}

ScalingRequest contains all data needed for scaling decision

Jump to

Keyboard shortcuts

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