autoscaler

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2019 License: Apache-2.0 Imports: 30 Imported by: 61

README

Scaling documentation has moved to the docs folder.

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

View Source
const (
	// ConfigName is the name of the config map of the autoscaler.
	ConfigName = "config-autoscaler"

	// Default values for several key autoscaler settings.
	DefaultStableWindow           = 60 * time.Second
	DefaultScaleToZeroGracePeriod = 30 * time.Second
)

Variables

This section is empty.

Functions

func NewMetricKey added in v0.3.0

func NewMetricKey(namespace string, name string) string

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,
	namespace string,
	revisionService string,
	endpointsInformer corev1informers.EndpointsInformer,
	target float64,
	reporter StatsReporter) (*Autoscaler, error)

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

func (a *Autoscaler) Scale(ctx context.Context, now time.Time) (int32, bool)

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 DeciderSpec) error

Update reconfigures the UniScaler according to the DeciderSpec.

type Config

type Config struct {
	// Feature flags.
	EnableScaleToZero 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

func NewConfigFromConfigMap(configMap *corev1.ConfigMap) (*Config, error)

NewConfigFromConfigMap creates a Config from the supplied ConfigMap

func NewConfigFromMap

func NewConfigFromMap(data map[string]string) (*Config, error)

NewConfigFromMap creates a Config from the supplied map

func (*Config) DeepCopy added in v0.2.0

func (in *Config) DeepCopy() *Config

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Config.

func (*Config) DeepCopyInto added in v0.2.0

func (in *Config) DeepCopyInto(out *Config)

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 Decider added in v0.5.0

type Decider struct {
	metav1.ObjectMeta
	Spec   DeciderSpec
	Status DeciderStatus
}

Decider is a resource which observes the request load of a Revision and recommends a number of replicas to run. +k8s:deepcopy-gen=true

func (*Decider) DeepCopy added in v0.5.0

func (in *Decider) DeepCopy() *Decider

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Decider.

func (*Decider) DeepCopyInto added in v0.5.0

func (in *Decider) DeepCopyInto(out *Decider)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type DeciderSpec added in v0.5.0

type DeciderSpec struct {
	TargetConcurrency float64
}

DeciderSpec is the parameters in which the Revision should scaled.

type DeciderStatus added in v0.5.0

type DeciderStatus struct {
	DesiredScale int32
}

DeciderStatus is the current scale recommendation.

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 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{},
	statsCh chan<- *StatMessage,
	uniScalerFactory UniScalerFactory,
	statsScraperFactory StatsScraperFactory,
	logger *zap.SugaredLogger) *MultiScaler

NewMultiScaler constructs a MultiScaler.

func (*MultiScaler) Create added in v0.2.0

func (m *MultiScaler) Create(ctx context.Context, metric *Decider) (*Decider, error)

Create instantiates the desired Decider.

func (*MultiScaler) Delete added in v0.2.0

func (m *MultiScaler) Delete(ctx context.Context, namespace, name string) error

Delete stops and removes a Decider.

func (*MultiScaler) Get added in v0.2.0

func (m *MultiScaler) Get(ctx context.Context, namespace, name string) (*Decider, error)

Get return the current Decider.

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 Decider.

func (*MultiScaler) Update added in v0.3.0

func (m *MultiScaler) Update(ctx context.Context, decider *Decider) (*Decider, error)

Update applied the desired DeciderSpec to a currently running Decider.

func (*MultiScaler) Watch added in v0.2.0

func (m *MultiScaler) Watch(fn func(string))

Watch registers a singleton function to call when DeciderStatus is updated.

type Reporter

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

Reporter holds cached metric objects to report autoscaler metrics

func NewStatsReporter

func NewStatsReporter(podNamespace string, service string, config string, revision string) (*Reporter, error)

NewStatsReporter creates a reporter that collects and reports autoscaler metrics

func (*Reporter) ReportActualPodCount added in v0.4.0

func (r *Reporter) ReportActualPodCount(v int64) error

ReportActualPodCount captures value v for actual pod count measure.

func (*Reporter) ReportDesiredPodCount added in v0.4.0

func (r *Reporter) ReportDesiredPodCount(v int64) error

ReportDesiredPodCount captures value v for desired pod count measure.

func (*Reporter) ReportObservedPodCount added in v0.4.0

func (r *Reporter) ReportObservedPodCount(v float64) error

ReportObservedPodCount captures value v for observed pod count measure.

func (*Reporter) ReportPanic added in v0.4.0

func (r *Reporter) ReportPanic(v int64) error

ReportPanic captures value v for panic mode measure.

func (*Reporter) ReportPanicRequestConcurrency added in v0.4.0

func (r *Reporter) ReportPanicRequestConcurrency(v float64) error

ReportPanicRequestConcurrency captures value v for panic request concurrency measure.

func (*Reporter) ReportRequestedPodCount added in v0.4.0

func (r *Reporter) ReportRequestedPodCount(v int64) error

ReportRequestedPodCount captures value v for requested pod count measure.

func (*Reporter) ReportStableRequestConcurrency added in v0.4.0

func (r *Reporter) ReportStableRequestConcurrency(v float64) error

ReportStableRequestConcurrency captures value v for stable request concurrency measure.

func (*Reporter) ReportTargetRequestConcurrency added in v0.4.0

func (r *Reporter) ReportTargetRequestConcurrency(v float64) error

ReportTargetRequestConcurrency captures value v for target request concurrency measure.

type ServiceScraper added in v0.4.0

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

ServiceScraper scrapes Revision metrics via a K8S service by sampling. Which pod to be picked up to serve the request is decided by K8S. Please see https://kubernetes.io/docs/concepts/services-networking/network-policies/ for details.

func NewServiceScraper added in v0.4.0

func NewServiceScraper(decider *Decider, endpointsLister corev1listers.EndpointsLister) (*ServiceScraper, error)

NewServiceScraper creates a new StatsScraper for the Revision which the given Metric is responsible for.

func (*ServiceScraper) Scrape added in v0.4.0

func (s *ServiceScraper) Scrape() (*StatMessage, error)

Scrape call the destination service then send it to the given stats chanel

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

	// Part of AverageConcurrentRequests, for requests going through a proxy.
	AverageProxiedConcurrentRequests float64

	// Number of requests received since last Stat (approximately QPS).
	RequestCount int32

	// Part of RequestCount, for requests going through a proxy.
	ProxiedRequestCount int32
}

Stat defines a single measurement at a point in time

type StatMessage

type StatMessage struct {
	Key  string
	Stat Stat
}

StatMessage wraps a Stat with identifying information so it can be routed to the correct receiver.

type StatsReporter

type StatsReporter interface {
	ReportDesiredPodCount(v int64) error
	ReportRequestedPodCount(v int64) error
	ReportActualPodCount(v int64) error
	ReportObservedPodCount(v float64) error
	ReportStableRequestConcurrency(v float64) error
	ReportPanicRequestConcurrency(v float64) error
	ReportTargetRequestConcurrency(v float64) error
	ReportPanic(v int64) error
}

StatsReporter defines the interface for sending autoscaler metrics

type StatsScraper added in v0.4.0

type StatsScraper interface {
	// Scrape scrapes the Revision queue metric endpoint.
	Scrape() (*StatMessage, error)
}

StatsScraper defines the interface for collecting Revision metrics

type StatsScraperFactory added in v0.5.0

type StatsScraperFactory func(*Decider) (StatsScraper, error)

StatsScraperFactory creates a StatsScraper for a given PA using the given dynamic configuration.

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 DeciderSpec.
	Update(DeciderSpec) error
}

UniScaler records statistics for a particular Decider and proposes the scale for the Decider's target based on those statistics.

type UniScalerFactory added in v0.2.0

type UniScalerFactory func(*Decider, *DynamicConfig) (UniScaler, error)

UniScalerFactory creates a UniScaler for a given PA using the given dynamic configuration.

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.

Jump to

Keyboard shortcuts

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