Documentation ¶
Index ¶
- Variables
- func BuildAggregateContainerStateMap(vpa *Vpa, mergePolicy ContainerMergePolicy, now time.Time) map[string]*AggregateContainerState
- func BytesFromMemoryAmount(memoryAmount ResourceAmount) float64
- func CoresFromCPUAmount(cpuAmount ResourceAmount) float64
- func QuantityFromCPUAmount(cpuAmount ResourceAmount) resource.Quantity
- func QuantityFromMemoryAmount(memoryAmount ResourceAmount) resource.Quantity
- func ResourcesAsResourceList(resources Resources) apiv1.ResourceList
- type AggregateContainerState
- func (a *AggregateContainerState) DeepCopy() *AggregateContainerState
- func (a *AggregateContainerState) LoadFromCheckpoint(checkpoint *vpa_types.VerticalPodAutoscalerCheckpointStatus) error
- func (a *AggregateContainerState) MergeContainerState(container *ContainerState, mergePolicy ContainerMergePolicy, now time.Time)
- func (a *AggregateContainerState) SaveToCheckpoint() (*vpa_types.VerticalPodAutoscalerCheckpointStatus, error)
- type ClusterState
- func (cluster *ClusterState) AddOrUpdateContainer(containerID ContainerID, request Resources) error
- func (cluster *ClusterState) AddOrUpdatePod(podID PodID, newLabels labels.Set, phase apiv1.PodPhase)
- func (cluster *ClusterState) AddOrUpdateVpa(apiObject *vpa_types.VerticalPodAutoscaler) error
- func (cluster *ClusterState) AddSample(sample *ContainerUsageSampleWithKey) error
- func (cluster *ClusterState) DeletePod(podID PodID) error
- func (cluster *ClusterState) DeleteVpa(vpaID VpaID) error
- func (cluster *ClusterState) GetContainer(containerID ContainerID) *ContainerState
- func (cluster *ClusterState) RecordOOM(containerID ContainerID, timestamp time.Time, requestedMemory ResourceAmount) error
- func (cluster *ClusterState) SetVpaCheckpoint(checkpoint *vpa_types.VerticalPodAutoscalerCheckpoint) error
- type ContainerID
- type ContainerMergePolicy
- type ContainerState
- type ContainerUsageSample
- type ContainerUsageSampleWithKey
- type KeyError
- type PodID
- type PodState
- type ResourceAmount
- type ResourceName
- type Resources
- type Vpa
- type VpaID
Constants ¶
This section is empty.
Variables ¶
var ( // MemoryAggregationWindowLength is the length of the memory usage history // aggregated by VPA, which is 8 days. MemoryAggregationWindowLength = time.Hour * 8 * 24 // MemoryAggregationInterval is the length of a single interval, for // which the peak memory usage is computed. // Memory usage peaks are aggregated in daily intervals. In other words // there is one memory usage sample per day (the maximum usage over that // day). // Note: AggregationWindowLength must be integrally divisible by this value. MemoryAggregationInterval = time.Hour * 24 // CPUHistogramOptions are options to be used by histograms that store // CPU measures expressed in cores. CPUHistogramOptions = cpuHistogramOptions() // MemoryHistogramOptions are options to be used by histograms that // store memory measures expressed in bytes. MemoryHistogramOptions = memoryHistogramOptions() // HistogramBucketSizeRatio is the relative size of the histogram buckets // (the ratio between the upper and the lower bound of the bucket). HistogramBucketSizeRatio = 0.05 // HistogramRelativeError is the maximum relative error introduced by // the histogram (except for the boundary buckets). HistogramRelativeError = HistogramBucketSizeRatio / 2. // MemoryHistogramDecayHalfLife is the amount of time it takes a historical // memory usage sample to lose half of its weight. In other words, a fresh // usage sample is twice as 'important' as one with age equal to the half // life period. MemoryHistogramDecayHalfLife = time.Hour * 24 // CPUHistogramDecayHalfLife is the amount of time it takes a historical // CPU usage sample to lose half of its weight. CPUHistogramDecayHalfLife = time.Hour * 24 )
Functions ¶
func BuildAggregateContainerStateMap ¶
func BuildAggregateContainerStateMap(vpa *Vpa, mergePolicy ContainerMergePolicy, now time.Time) map[string]*AggregateContainerState
BuildAggregateContainerStateMap takes a set of pods and groups their containers by name. If checkpoint data is available it is incorporated into AggregateContainerState
func BytesFromMemoryAmount ¶
func BytesFromMemoryAmount(memoryAmount ResourceAmount) float64
BytesFromMemoryAmount converts ResourceAmount to number of bytes expressed as float64.
func CoresFromCPUAmount ¶
func CoresFromCPUAmount(cpuAmount ResourceAmount) float64
CoresFromCPUAmount converts ResourceAmount to number of cores expressed as float64.
func QuantityFromCPUAmount ¶
func QuantityFromCPUAmount(cpuAmount ResourceAmount) resource.Quantity
QuantityFromCPUAmount converts CPU ResourceAmount to a resource.Quantity.
func QuantityFromMemoryAmount ¶
func QuantityFromMemoryAmount(memoryAmount ResourceAmount) resource.Quantity
QuantityFromMemoryAmount converts memory ResourceAmount to a resource.Quantity.
func ResourcesAsResourceList ¶
func ResourcesAsResourceList(resources Resources) apiv1.ResourceList
ResourcesAsResourceList converts internal Resources representation to ResourcesList.
Types ¶
type AggregateContainerState ¶
type AggregateContainerState struct { AggregateCPUUsage util.Histogram AggregateMemoryPeaks util.Histogram FirstSampleStart time.Time LastSampleStart time.Time TotalSamplesCount int }
AggregateContainerState holds input signals aggregated from a set of containers. It can be used as an input to compute the recommendation.
func NewAggregateContainerState ¶
func NewAggregateContainerState() *AggregateContainerState
NewAggregateContainerState returns a new, empty AggregateContainerState.
func (*AggregateContainerState) DeepCopy ¶
func (a *AggregateContainerState) DeepCopy() *AggregateContainerState
DeepCopy returns a copy of the AggregateContainerState
func (*AggregateContainerState) LoadFromCheckpoint ¶
func (a *AggregateContainerState) LoadFromCheckpoint(checkpoint *vpa_types.VerticalPodAutoscalerCheckpointStatus) error
LoadFromCheckpoint deserializes data from VerticalPodAutoscalerCheckpointStatus into the AggregateContainerState.
func (*AggregateContainerState) MergeContainerState ¶
func (a *AggregateContainerState) MergeContainerState(container *ContainerState, mergePolicy ContainerMergePolicy, now time.Time)
MergeContainerState merges the state of an individual container into AggregateContainerState.
func (*AggregateContainerState) SaveToCheckpoint ¶
func (a *AggregateContainerState) SaveToCheckpoint() (*vpa_types.VerticalPodAutoscalerCheckpointStatus, error)
SaveToCheckpoint serializes AggregateContainerState as VerticalPodAutoscalerCheckpointStatus. The serialization may result in loss of precission of the histograms.
type ClusterState ¶
type ClusterState struct { // Pods in the cluster. Pods map[PodID]*PodState // VPA objects in the cluster. Vpas map[VpaID]*Vpa }
ClusterState holds all runtime information about the cluster required for the VPA operations, i.e. configuration of resources (pods, containers, VPA objects), aggregated utilization of compute resources (CPU, memory) and events (container OOMs). All input to the VPA Recommender algorithm lives in this structure. TODO(kgrygiel): Limit the ClusterState object to a single namespace.
func NewClusterState ¶
func NewClusterState() *ClusterState
NewClusterState returns a new ClusterState with no pods.
func (*ClusterState) AddOrUpdateContainer ¶
func (cluster *ClusterState) AddOrUpdateContainer(containerID ContainerID, request Resources) error
AddOrUpdateContainer creates a new container with the given ContainerID and adds it to the parent pod in the ClusterState object, if not yet present. Requires the pod to be added to the ClusterState first. Otherwise an error is returned.
func (*ClusterState) AddOrUpdatePod ¶
func (cluster *ClusterState) AddOrUpdatePod(podID PodID, newLabels labels.Set, phase apiv1.PodPhase)
AddOrUpdatePod udpates the state of the pod with a given PodID, if it is present in the cluster object. Otherwise a new pod is created and added to the Cluster object. If the labels of the pod have changed, it updates the links between the pod and the matching Vpa.
func (*ClusterState) AddOrUpdateVpa ¶
func (cluster *ClusterState) AddOrUpdateVpa(apiObject *vpa_types.VerticalPodAutoscaler) error
AddOrUpdateVpa adds a new VPA with a given ID to the ClusterState if it didn't yet exist. If the VPA already existed but had a different pod selector, the pod selector is updated. Updates the links between the VPA and all pods it matches.
func (*ClusterState) AddSample ¶
func (cluster *ClusterState) AddSample(sample *ContainerUsageSampleWithKey) error
AddSample adds a new usage sample to the proper container in the ClusterState object. Requires the container as well as the parent pod to be added to the ClusterState first. Otherwise an error is returned.
func (*ClusterState) DeletePod ¶
func (cluster *ClusterState) DeletePod(podID PodID) error
DeletePod removes an existing pod from the cluster.
func (*ClusterState) DeleteVpa ¶
func (cluster *ClusterState) DeleteVpa(vpaID VpaID) error
DeleteVpa removes a VPA with the given ID from the ClusterState.
func (*ClusterState) GetContainer ¶
func (cluster *ClusterState) GetContainer(containerID ContainerID) *ContainerState
GetContainer returns the ContainerState object for a given ContainerID or null if it's not present in the model.
func (*ClusterState) RecordOOM ¶
func (cluster *ClusterState) RecordOOM(containerID ContainerID, timestamp time.Time, requestedMemory ResourceAmount) error
RecordOOM adds info regarding OOM event in the model as an artifical memory sample.
func (*ClusterState) SetVpaCheckpoint ¶
func (cluster *ClusterState) SetVpaCheckpoint(checkpoint *vpa_types.VerticalPodAutoscalerCheckpoint) error
SetVpaCheckpoint stores container's checkoint data in the cluster's VPA object.
type ContainerID ¶
type ContainerID struct { PodID // ContainerName is the name of the container, unique within a pod. ContainerName string }
ContainerID contains information needed to identify a Container within a cluster.
type ContainerMergePolicy ¶
type ContainerMergePolicy bool
ContainerMergePolicy contorls how MergeContainerState cobines samples.
const ( // SupportedCheckpointVersion is the tag of the supported version of serialized checkpoints. SupportedCheckpointVersion = "v1" // MergeForRecommendation means that all samples are combined during MergeContainerState call. MergeForRecommendation ContainerMergePolicy = true // MergeForCheckpoint controls that MergeContainerState call will omit last peak memory // sample if it would result in positive feedback loop during crash loop. MergeForCheckpoint ContainerMergePolicy = false )
type ContainerState ¶
type ContainerState struct { // Current request. Request Resources // Distribution of CPU usage. The measurement unit is 1 CPU core. CPUUsage util.Histogram // Start of the latest CPU usage sample that was aggregated. LastCPUSampleStart time.Time // Start of the first CPU usage sample that was aggregated. FirstCPUSampleStart time.Time // Number of CPU samples that were aggregated. CPUSamplesCount int // Memory peaks stored in the intervals belonging to the aggregation window // (one value per interval). The measurement unit is a byte. MemoryUsagePeaks util.FloatSlidingWindow // End time of the most recent interval covered by the aggregation window. WindowEnd time.Time // contains filtered or unexported fields }
ContainerState stores information about a single container instance. It holds the recent history of CPU and memory utilization.
- CPU is stored in form of a distribution (histogram). Currently we're using fixed weight samples in the CPU histogram (i.e. old and fresh samples are equally important). Old samples are never deleted. TODO: Add exponential decaying of weights over time to address this.
- Memory is stored for the period of length MemoryAggregationWindowLength in the form of usage peaks, one value per MemoryAggregationInterval. For example if window legth is one week and aggregation interval is one day it will store 7 peaks, one per day, for the last week. Note: samples are added to intervals based on their start timestamps.
func NewContainerState ¶
func NewContainerState(request Resources) *ContainerState
NewContainerState returns a new, empty ContainerState.
func (*ContainerState) AddSample ¶
func (container *ContainerState) AddSample(sample *ContainerUsageSample) bool
AddSample adds a usage sample to the given ContainerState. Requires samples for a single resource to be passed in chronological order (i.e. in order of growing MeasureStart). Invalid samples (out of order or measure out of legal range) are discarded. Returns true if the sample was aggregated, false if it was discarded. Note: usage samples don't hold their end timestamp / duration. They are implicitly assumed to be disjoint when aggregating.
func (*ContainerState) RecordOOM ¶
func (container *ContainerState) RecordOOM(timestamp time.Time, requestedMemory ResourceAmount) error
RecordOOM adds info regarding OOM event in the model as an artifical memory sample.
type ContainerUsageSample ¶
type ContainerUsageSample struct { // Start of the measurement interval. MeasureStart time.Time // Average CPU usage in cores or memory usage in bytes. Usage ResourceAmount // Which resource is this sample for. Resource ResourceName }
ContainerUsageSample is a measure of resource usage of a container over some interval.
type ContainerUsageSampleWithKey ¶
type ContainerUsageSampleWithKey struct { ContainerUsageSample Container ContainerID }
ContainerUsageSampleWithKey holds a ContainerUsageSample together with the ID of the container it belongs to.
type KeyError ¶
type KeyError struct {
// contains filtered or unexported fields
}
KeyError is returned when the mapping key was not found.
type PodID ¶
type PodID struct { // Namespaces where the Pod is defined. Namespace string // PodName is the name of the pod unique within a namespace. PodName string }
PodID contains information needed to identify a Pod within a cluster.
type PodState ¶
type PodState struct { // Unique id of the Pod. ID PodID // Set of labels attached to the Pod. Labels labels.Set // Containers that belong to the Pod, keyed by the container name. Containers map[string]*ContainerState // All VPA objects that match this Pod. While it is incorrect to let // multiple VPA objects match the same pod, the model has no means to // prevent such situation. In such case the pod is controlled by one of the // matching VPAs. MatchingVpas map[VpaID]*Vpa // PodPhase describing current life cycle phase of the Pod. Phase apiv1.PodPhase }
PodState holds runtime information about a single Pod.
type ResourceAmount ¶
type ResourceAmount int64
ResourceAmount represents quantity of a certain resource within a container. Note this keeps CPU in millicores (which is not a standard unit in APIs) and memory in bytes. Allowed values are in the range from 0 to MaxResourceAmount.
func CPUAmountFromCores ¶
func CPUAmountFromCores(cores float64) ResourceAmount
CPUAmountFromCores converts CPU cores to a ResourceAmount.
func MemoryAmountFromBytes ¶
func MemoryAmountFromBytes(bytes float64) ResourceAmount
MemoryAmountFromBytes converts memory bytes to a ResourceAmount.
func RoundResourceAmount ¶
func RoundResourceAmount(amount, unit ResourceAmount) ResourceAmount
RoundResourceAmount returns the given resource amount rounded down to the whole multiple of another resource amount (unit).
func ScaleResource ¶
func ScaleResource(amount ResourceAmount, factor float64) ResourceAmount
ScaleResource returns the resource amount multiplied by a given factor.
type ResourceName ¶
type ResourceName string
ResourceName represents the name of the resource monitored by recommender.
const ( // ResourceCPU represents CPU in millicores (1core = 1000millicores). ResourceCPU ResourceName = "cpu" // ResourceMemory represents memory, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024). ResourceMemory ResourceName = "memory" // MaxResourceAmount is the maximum allowed value of resource amount. MaxResourceAmount = ResourceAmount(1e14) )
type Resources ¶
type Resources map[ResourceName]ResourceAmount
Resources is a map from resource name to the corresponding ResourceAmount.
type Vpa ¶
type Vpa struct { ID VpaID // Labels selector that determines which Pods are controlled by this VPA // object. Can be nil, in which case no Pod is matched. PodSelector labels.Selector // Map of the status conditions (keys are condition types). Conditions vpaConditionsMap // Most recently computed recommendation. Can be nil. Recommendation *vpa_types.RecommendedPodResources // Pods controlled by this VPA object. Pods map[PodID]*PodState // Value of the Status.LastUpdateTime fetched from the VPA API object. LastUpdateTime time.Time // Initial checkpoints of AggregateContainerStates for containers. ContainerCheckpoints map[string]*AggregateContainerState }
Vpa (Vertical Pod Autoscaler) object is responsible for vertical scaling of Pods matching a given label selector.
func NewVpa ¶
NewVpa returns a new Vpa with a given ID and pod selector. Doesn't set the links to the matched pods.
func (*Vpa) MatchesPod ¶
MatchesPod returns true iff a given pod is matched by the Vpa pod selector.
func (*Vpa) UpdatePodLink ¶
UpdatePodLink marks the Pod as controlled or not-controlled by the VPA depending on whether the pod labels match the Vpa pod selector. If multiple VPAs match the same Pod, only one of them will effectively control the Pod.