Documentation ¶
Overview ¶
Package autoscaler calculates the number of pods necessary for the desired level of concurrency per pod (stableConcurrencyPerPod). It operates in two modes, stable mode and panic mode.
Stable mode calculates the average concurrency observed over the last 60 seconds and adjusts the observed pod count to achieve the target value. Current observed pod count is the number of unique pod names which show up in the last 60 seconds.
Panic mode calculates the average concurrency observed over the last 6 seconds and adjusts the observed pod count to achieve the stable target value. Panic mode is engaged when the observed 6 second average concurrency reaches 2x the target stable concurrency. Panic mode will last at least 60 seconds--longer if the 2x threshold is repeatedly breached. During panic mode the number of pods is never decreased in order to prevent flapping.
Package autoscaler supports both single-tenant (one autoscaler per revision) and multitenant (one autoscaler for all revisions) autoscalers; config/controller.yaml determines which kind of autoscaler is used.
Index ¶
- Constants
- func NewMetricKey(namespace string, name string) string
- type Autoscaler
- type Config
- type DynamicConfig
- type Measurement
- type Metric
- type MetricSpec
- type MetricStatus
- type MultiScaler
- func (m *MultiScaler) Create(ctx context.Context, metric *Metric) (*Metric, error)
- func (m *MultiScaler) Delete(ctx context.Context, namespace, name string) error
- func (m *MultiScaler) Get(ctx context.Context, namespace, name string) (*Metric, error)
- func (m *MultiScaler) Inform(event string) bool
- func (m *MultiScaler) RecordStat(key string, stat Stat)
- func (m *MultiScaler) Update(ctx context.Context, metric *Metric) (*Metric, error)
- func (m *MultiScaler) Watch(fn func(string))
- type Reporter
- type Stat
- type StatMessage
- type StatsReporter
- type UniScaler
- type UniScalerFactory
Constants ¶
const ( // ActivatorPodName defines the pod name of the activator // as defined in the metrics it sends. ActivatorPodName string = "activator" )
const (
// ConfigName is the name of the config map of the autoscaler.
ConfigName = "config-autoscaler"
)
Variables ¶
This section is empty.
Functions ¶
func NewMetricKey ¶ added in v0.3.0
NewMetricKey identifies a UniScaler in the multiscaler. Stats send in are identified and routed via this key.
Types ¶
type Autoscaler ¶
type Autoscaler struct { *DynamicConfig // contains filtered or unexported fields }
Autoscaler stores current state of an instance of an autoscaler
func New ¶
func New(dynamicConfig *DynamicConfig, target float64, reporter StatsReporter) *Autoscaler
New creates a new instance of autoscaler
func (*Autoscaler) Record ¶
func (a *Autoscaler) Record(ctx context.Context, stat Stat)
Record a data point.
func (*Autoscaler) Scale ¶
Scale calculates the desired scale based on current statistics given the current time.
func (*Autoscaler) Update ¶ added in v0.3.0
func (a *Autoscaler) Update(spec MetricSpec) error
Update reconfigures the UniScaler according to the MetricSpec.
type Config ¶
type Config struct { // Feature flags. EnableScaleToZero bool EnableVPA bool // Target concurrency knobs for different container concurrency configurations. ContainerConcurrencyTargetPercentage float64 ContainerConcurrencyTargetDefault float64 // General autoscaler algorithm configuration. MaxScaleUpRate float64 StableWindow time.Duration PanicWindow time.Duration TickInterval time.Duration ScaleToZeroGracePeriod time.Duration }
Config defines the tunable autoscaler parameters +k8s:deepcopy-gen=true
func NewConfigFromConfigMap ¶
NewConfigFromConfigMap creates a Config from the supplied ConfigMap
func NewConfigFromMap ¶
NewConfigFromMap creates a Config from the supplied map
func (*Config) DeepCopy ¶ added in v0.2.0
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Config.
func (*Config) DeepCopyInto ¶ added in v0.2.0
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (*Config) TargetConcurrency ¶
func (c *Config) TargetConcurrency(concurrency v1alpha1.RevisionContainerConcurrencyType) float64
TargetConcurrency calculates the target concurrency for a given container-concurrency taking the container-concurrency-target-percentage into account.
type DynamicConfig ¶ added in v0.2.0
type DynamicConfig struct {
// contains filtered or unexported fields
}
func NewDynamicConfig ¶ added in v0.2.0
func NewDynamicConfig(config *Config, logger *zap.SugaredLogger) *DynamicConfig
func NewDynamicConfigFromMap ¶ added in v0.2.0
func NewDynamicConfigFromMap(rawConfig map[string]string, logger *zap.SugaredLogger) (*DynamicConfig, error)
func (*DynamicConfig) Current ¶ added in v0.2.0
func (dc *DynamicConfig) Current() *Config
func (*DynamicConfig) Update ¶ added in v0.2.0
func (dc *DynamicConfig) Update(configMap *corev1.ConfigMap)
type Measurement ¶
type Measurement int
Measurement represents the type of the autoscaler metric to be reported
const ( // DesiredPodCountM is used for the pod count that autoscaler wants DesiredPodCountM Measurement = iota // RequestedPodCountM is used for the requested pod count from kubernetes RequestedPodCountM // ActualPodCountM is used for the actual number of pods we have ActualPodCountM // ObservedPodCountM is used for the observed number of pods we have ObservedPodCountM // StableRequestConcurrencyM is the average of requests count per observed pod in each stable window (default 60 seconds) StableRequestConcurrencyM // PanicRequestConcurrencyM is the average of requests count per observed pod in each panic window (default 6 seconds) PanicRequestConcurrencyM // TargetConcurrencyM is the desired number of concurrent requests for each pod TargetConcurrencyM // PanicM is used as a flag to indicate if autoscaler is in panic mode or not PanicM )
type Metric ¶ added in v0.2.0
type Metric struct { metav1.ObjectMeta Spec MetricSpec Status MetricStatus }
Metric is a resource which observes the request load of a Revision and recommends a number of replicas to run. +k8s:deepcopy-gen=true
func (*Metric) DeepCopy ¶ added in v0.3.0
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Metric.
func (*Metric) DeepCopyInto ¶ added in v0.3.0
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
type MetricSpec ¶ added in v0.3.0
type MetricSpec struct {
TargetConcurrency float64
}
MetricSpec is the parameters in which the Revision should scaled.
type MetricStatus ¶ added in v0.3.0
type MetricStatus struct {
DesiredScale int32
}
MetricStatus is the current scale recommendation.
type MultiScaler ¶ added in v0.2.0
type MultiScaler struct {
// contains filtered or unexported fields
}
MultiScaler maintains a collection of Uniscalers.
func NewMultiScaler ¶ added in v0.2.0
func NewMultiScaler(dynConfig *DynamicConfig, stopCh <-chan struct{}, uniScalerFactory UniScalerFactory, logger *zap.SugaredLogger) *MultiScaler
NewMultiScaler constructs a MultiScaler.
func (*MultiScaler) Delete ¶ added in v0.2.0
func (m *MultiScaler) Delete(ctx context.Context, namespace, name string) error
Delete stops and removes a Metric.
func (*MultiScaler) Inform ¶ added in v0.3.0
func (m *MultiScaler) Inform(event string) bool
Inform sends an update to the registered watcher function, if it is set.
func (*MultiScaler) RecordStat ¶ added in v0.2.0
func (m *MultiScaler) RecordStat(key string, stat Stat)
RecordStat records some statistics for the given Metric.
func (*MultiScaler) Update ¶ added in v0.3.0
Update applied the desired MetricSpec to a currently running Metric.
func (*MultiScaler) Watch ¶ added in v0.2.0
func (m *MultiScaler) Watch(fn func(string))
Watch registers a singleton function to call when MetricStatus is updated.
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter holds cached metric objects to report autoscaler metrics
type Stat ¶
type Stat struct { // The time the data point was collected on the pod. Time *time.Time // The unique identity of this pod. Used to count how many pods // are contributing to the metrics. PodName string // Average number of requests currently being handled by this pod. AverageConcurrentRequests float64 // Number of requests received since last Stat (approximately QPS). RequestCount int32 // Lameduck indicates this Pod has received a shutdown signal. LameDuck bool }
Stat defines a single measurement at a point in time
type StatMessage ¶
StatMessage wraps a Stat with identifying information so it can be routed to the correct receiver.
type StatsReporter ¶
type StatsReporter interface {
Report(m Measurement, v float64) error
}
StatsReporter defines the interface for sending autoscaler metrics
type UniScaler ¶ added in v0.2.0
type UniScaler interface { // Record records the given statistics. Record(context.Context, Stat) // Scale either proposes a number of replicas or skips proposing. The proposal is requested at the given time. // The returned boolean is true if and only if a proposal was returned. Scale(context.Context, time.Time) (int32, bool) // Update reconfigures the UniScaler according to the MetricSpec. Update(MetricSpec) error }
UniScaler records statistics for a particular Metric and proposes the scale for the Metric's target based on those statistics.
type UniScalerFactory ¶ added in v0.2.0
type UniScalerFactory func(*Metric, *DynamicConfig) (UniScaler, error)
UniScalerFactory creates a UniScaler for a given PA using the given dynamic configuration.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package statserver provides a WebSocket server which receives autoscaler statistics, typically from queue proxy sidecar containers, and sends them to a channel.
|
Package statserver provides a WebSocket server which receives autoscaler statistics, typically from queue proxy sidecar containers, and sends them to a channel. |