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
- Variables
- type Autoscaler
- type Collector
- type Config
- type Decider
- type DeciderSpec
- type DeciderStatus
- type MetricClient
- type MetricCollector
- func (c *MetricCollector) CreateOrUpdate(metric *av1alpha1.Metric) error
- func (c *MetricCollector) Delete(namespace, name string) error
- func (c *MetricCollector) Record(key types.NamespacedName, stat Stat)
- func (c *MetricCollector) StableAndPanicConcurrency(key types.NamespacedName, now time.Time) (float64, float64, error)
- func (c *MetricCollector) StableAndPanicOPS(key types.NamespacedName, now time.Time) (float64, float64, error)
- type MetricProvider
- func (p *MetricProvider) GetMetricByName(name types.NamespacedName, info provider.CustomMetricInfo) (*cmetrics.MetricValue, error)
- func (p *MetricProvider) GetMetricBySelector(namespace string, selector labels.Selector, info provider.CustomMetricInfo) (*cmetrics.MetricValueList, error)
- func (p *MetricProvider) ListAllMetrics() []provider.CustomMetricInfo
- type MultiScaler
- func (m *MultiScaler) Create(ctx context.Context, decider *Decider) (*Decider, error)
- func (m *MultiScaler) Delete(ctx context.Context, namespace, name string) error
- func (m *MultiScaler) Get(ctx context.Context, namespace, name string) (*Decider, error)
- func (m *MultiScaler) Inform(event string) bool
- func (m *MultiScaler) Poke(key types.NamespacedName, stat Stat)
- func (m *MultiScaler) Update(ctx context.Context, decider *Decider) (*Decider, error)
- func (m *MultiScaler) Watch(fn func(string))
- type Reporter
- func (r *Reporter) ReportActualPodCount(v int64) error
- func (r *Reporter) ReportDesiredPodCount(v int64) error
- func (r *Reporter) ReportExcessBurstCapacity(v float64) error
- func (r *Reporter) ReportPanic(v int64) error
- func (r *Reporter) ReportPanicRequestConcurrency(v float64) error
- func (r *Reporter) ReportRequestedPodCount(v int64) error
- func (r *Reporter) ReportStableRequestConcurrency(v float64) error
- func (r *Reporter) ReportTargetRequestConcurrency(v float64) error
- type ServiceScraper
- type Stat
- type StatMessage
- type StatsReporter
- type StatsScraper
- type StatsScraperFactory
- type UniScaler
- type UniScalerFactory
Constants ¶
const ( // BucketSize is the size of the buckets of stats we create. BucketSize = 2 * time.Second )
const (
// ConfigName is the name of the config map of the autoscaler.
ConfigName = "config-autoscaler"
)
Variables ¶
var ( // ErrNoData denotes that the collector could not calculate data. ErrNoData = errors.New("no data available") // ErrNotScraping denotes that the collector is not collecting metrics for the given resource. ErrNotScraping = errors.New("the requested resource is not being scraped") )
Functions ¶
This section is empty.
Types ¶
type Autoscaler ¶
type Autoscaler struct {
// contains filtered or unexported fields
}
Autoscaler stores current state of an instance of an autoscaler.
func New ¶
func New( namespace string, revision string, metricClient MetricClient, podCounter resources.ReadyPodCounter, deciderSpec DeciderSpec, reporter StatsReporter) (*Autoscaler, error)
New creates a new instance of autoscaler
func (*Autoscaler) Scale ¶
func (a *Autoscaler) Scale(ctx context.Context, now time.Time) (desiredPodCount int32, excessBC int32, validScale bool)
Scale calculates the desired scale based on current statistics given the current time. desiredPodCount is the calculated pod count the autoscaler would like to set. validScale signifies whether the desiredPodCount should be applied or not.
func (*Autoscaler) Update ¶ added in v0.3.0
func (a *Autoscaler) Update(deciderSpec DeciderSpec) error
Update reconfigures the UniScaler according to the DeciderSpec.
type Collector ¶ added in v0.8.0
type Collector interface { // CreateOrUpdate either creates a collection for the given metric or update it, should // it already exist. CreateOrUpdate(*av1alpha1.Metric) error // Record allows stats to be captured that came from outside the Collector. Record(key types.NamespacedName, stat Stat) // Delete deletes a Metric and halts collection. Delete(string, string) error }
Collector starts and stops metric collection for a given entity.
type Config ¶
type Config struct { // Feature flags. EnableScaleToZero bool // Target concurrency knobs for different container concurrency configurations. ContainerConcurrencyTargetFraction float64 ContainerConcurrencyTargetDefault float64 // NB: most of our computations are in floats, so this is float to avoid casting. TargetBurstCapacity float64 // General autoscaler algorithm configuration. MaxScaleUpRate float64 StableWindow time.Duration PanicWindowPercentage float64 PanicThresholdPercentage float64 // Deprecated in favor of PanicWindowPercentage. 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.
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
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Decider.
func (*Decider) DeepCopyInto ¶ added in v0.5.0
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 { TickInterval time.Duration MaxScaleUpRate float64 // The concurrency per pod that we target to maintain. // TargetConcurrency <= TotalConcurency. TargetConcurrency float64 // The total concurrency that a pod can maintain. TotalConcurrency float64 // The burst capacity that user wants to maintain without queing at the POD level. // Note, that queueing still might happen due to the non-ideal load balancing. TargetBurstCapacity float64 PanicThreshold float64 // StableWindow is needed to determine when to exit panicmode. StableWindow time.Duration // The name of the k8s service for pod information. ServiceName string }
DeciderSpec is the parameters in which the Revision should scaled.
type DeciderStatus ¶ added in v0.5.0
type DeciderStatus struct { // DesiredScale is the target number of instances that autoscaler // this revision needs. DesiredScale int32 // ExcessBurstCapacity is the difference between spare capacity // (how many more concurrent requests the pods in the revision // deployment can serve) and the configured target burst capacity. // If this number is negative: Activator will be threaded in // the request path by the PodAutoscaler controller. ExcessBurstCapacity int32 }
DeciderStatus is the current scale recommendation.
type MetricClient ¶ added in v0.6.0
type MetricClient interface { // StableAndPanicConcurrency returns both the stable and the panic concurrency // for the given replica as of the given time. StableAndPanicConcurrency(key types.NamespacedName, now time.Time) (float64, float64, error) // StableAndPanicOPS returns both the stable and the panic OPS // for the given replica as of the given time. StableAndPanicOPS(key types.NamespacedName, now time.Time) (float64, float64, error) }
MetricClient surfaces the metrics that can be obtained via the collector.
type MetricCollector ¶ added in v0.6.0
type MetricCollector struct {
// contains filtered or unexported fields
}
MetricCollector manages collection of metrics for many entities.
func NewMetricCollector ¶ added in v0.6.0
func NewMetricCollector(statsScraperFactory StatsScraperFactory, logger *zap.SugaredLogger) *MetricCollector
NewMetricCollector creates a new metric collector.
func (*MetricCollector) CreateOrUpdate ¶ added in v0.8.0
func (c *MetricCollector) CreateOrUpdate(metric *av1alpha1.Metric) error
CreateOrUpdate either creates a collection for the given metric or update it, should it already exist. Map access optimized via double-checked locking.
func (*MetricCollector) Delete ¶ added in v0.6.0
func (c *MetricCollector) Delete(namespace, name string) error
Delete deletes a Metric and halts collection.
func (*MetricCollector) Record ¶ added in v0.6.0
func (c *MetricCollector) Record(key types.NamespacedName, stat Stat)
Record records a stat that's been generated outside of the metric collector.
func (*MetricCollector) StableAndPanicConcurrency ¶ added in v0.6.0
func (c *MetricCollector) StableAndPanicConcurrency(key types.NamespacedName, now time.Time) (float64, float64, error)
StableAndPanicConcurrency returns both the stable and the panic concurrency. It may truncate metric buckets as a side-effect.
func (*MetricCollector) StableAndPanicOPS ¶ added in v0.8.0
func (c *MetricCollector) StableAndPanicOPS(key types.NamespacedName, now time.Time) (float64, float64, error)
StableAndPanicOPS returns both the stable and the panic OPS. It may truncate metric buckets as a side-effect.
type MetricProvider ¶ added in v0.7.0
type MetricProvider struct {
// contains filtered or unexported fields
}
MetricProvider is a provider to back a custom-metrics API implementation.
func NewMetricProvider ¶ added in v0.7.0
func NewMetricProvider(metricClient MetricClient) *MetricProvider
NewMetricProvider creates a new MetricProvider.
func (*MetricProvider) GetMetricByName ¶ added in v0.7.0
func (p *MetricProvider) GetMetricByName(name types.NamespacedName, info provider.CustomMetricInfo) (*cmetrics.MetricValue, error)
GetMetricByName implements the interface.
func (*MetricProvider) GetMetricBySelector ¶ added in v0.7.0
func (p *MetricProvider) GetMetricBySelector(namespace string, selector labels.Selector, info provider.CustomMetricInfo) (*cmetrics.MetricValueList, error)
GetMetricBySelector implements the interface.
func (*MetricProvider) ListAllMetrics ¶ added in v0.7.0
func (p *MetricProvider) ListAllMetrics() []provider.CustomMetricInfo
ListAllMetrics implements the interface.
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( 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 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) Poke ¶ added in v0.6.0
func (m *MultiScaler) Poke(key types.NamespacedName, stat Stat)
Poke checks if the autoscaler needs to be run immediately.
func (*MultiScaler) Update ¶ added in v0.3.0
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
ReportActualPodCount captures value v for actual pod count measure.
func (*Reporter) ReportDesiredPodCount ¶ added in v0.4.0
ReportDesiredPodCount captures value v for desired pod count measure.
func (*Reporter) ReportExcessBurstCapacity ¶ added in v0.8.0
ReportExcessBurstCapacity captures value v for excess target burst capacity.
func (*Reporter) ReportPanic ¶ added in v0.4.0
ReportPanic captures value v for panic mode measure.
func (*Reporter) ReportPanicRequestConcurrency ¶ added in v0.4.0
ReportPanicRequestConcurrency captures value v for panic request concurrency measure.
func (*Reporter) ReportRequestedPodCount ¶ added in v0.4.0
ReportRequestedPodCount captures value v for requested pod count measure.
func (*Reporter) ReportStableRequestConcurrency ¶ added in v0.4.0
ReportStableRequestConcurrency captures value v for stable request concurrency measure.
func (*Reporter) ReportTargetRequestConcurrency ¶ added in v0.4.0
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(metric *av1alpha1.Metric, counter resources.ReadyPodCounter) (*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 calls the destination service then sends it to the given stats channel.
type Stat ¶
type Stat struct { // The time the data point was received by autoscaler. 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 float64 // Part of RequestCount, for requests going through a proxy. ProxiedRequestCount float64 }
Stat defines a single measurement at a point in time
type StatMessage ¶
type StatMessage struct { Key types.NamespacedName 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 ReportStableRequestConcurrency(v float64) error ReportPanicRequestConcurrency(v float64) error ReportTargetRequestConcurrency(v float64) error ReportExcessBurstCapacity(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(*av1alpha1.Metric) (StatsScraper, error)
StatsScraperFactory creates a StatsScraper for a given Metric.
type UniScaler ¶ added in v0.2.0
type UniScaler interface { // Scale either proposes a number of replicas and available excess burst capacity, // 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, 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
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. |