model

package
v0.0.0-...-e8de369 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OOMBumpUpRatio specifies how much memory will be added after observing OOM.
	OOMBumpUpRatio float64 = 1.2
	// OOMMinBumpUp specifies minimal increase of memory after observing OOM.
	OOMMinBumpUp float64 = 100 * 1024 * 1024 // 100MB
)
View Source
const (
	// SupportedCheckpointVersion is the tag of the supported version of serialized checkpoints.
	// Version id should be incremented on every non incompatible change, i.e. if the new
	// version of the recommender binary can't initialize from the old checkpoint format or the the
	// previous version of the recommender binary can't initialize from the new checkpoint format.
	SupportedCheckpointVersion = "v1"
)

Variables

View Source
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()
	// HistogramBucketSizeGrowth defines the growth rate of the histogram buckets.
	// Each bucket is wider than the previous one by this fraction.
	HistogramBucketSizeGrowth = 0.05 // Make each bucket 5% larger than the previous one.
	// 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 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 is a distribution of all CPU samples.
	AggregateCPUUsage util.Histogram
	// AggregateMemoryPeaks is a distribution of memory peaks from all containers:
	// each container should add one peak per memory aggregation interval (e.g. once every 24h).
	AggregateMemoryPeaks util.Histogram
	// Note: first/last sample timestamps as well as the sample count are based only on CPU samples.
	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. The CPU and memory distributions use decaying histograms by default (see NewAggregateContainerState()). Implements ContainerStateAggregator interface.

func NewAggregateContainerState

func NewAggregateContainerState() *AggregateContainerState

NewAggregateContainerState returns a new, empty AggregateContainerState.

func (*AggregateContainerState) AddSample

func (a *AggregateContainerState) AddSample(sample *ContainerUsageSample)

AddSample aggregates a single usage sample.

func (*AggregateContainerState) LoadFromCheckpoint

LoadFromCheckpoint deserializes data from VerticalPodAutoscalerCheckpointStatus into the AggregateContainerState.

func (*AggregateContainerState) MergeContainerState

func (a *AggregateContainerState) MergeContainerState(other *AggregateContainerState)

MergeContainerState merges two AggregateContainerStates.

func (*AggregateContainerState) SaveToCheckpoint

SaveToCheckpoint serializes AggregateContainerState as VerticalPodAutoscalerCheckpointStatus. The serialization may result in loss of precission of the histograms.

func (*AggregateContainerState) SubtractSample

func (a *AggregateContainerState) SubtractSample(sample *ContainerUsageSample)

SubtractSample removes a single usage sample from an aggregation. The subtracted sample should be equal to some sample that was aggregated with AddSample() in the past. Only memory samples can be subtracted at the moment. Support for CPU could be added if necessary.

type AggregateStateKey

type AggregateStateKey interface {
	Namespace() string
	ContainerName() string
	Labels() labels.Labels
}

AggregateStateKey determines the set of containers for which the usage samples are kept aggregated in the model.

type ClusterState

type ClusterState struct {
	// Pods in the cluster.
	Pods map[PodID]*PodState
	// VPA objects in the cluster.
	Vpas map[VpaID]*Vpa
	// contains filtered or unexported fields
}

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.

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 updates 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 containers and the aggregations.

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 aggregations 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)

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) MakeAggregateStateKey

func (cluster *ClusterState) MakeAggregateStateKey(pod *PodState, containerName string) AggregateStateKey

MakeAggregateStateKey returns the AggregateStateKey that should be used to aggregate usage samples from a container with the given name in a given pod.

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 artificial memory sample.

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 ContainerNameToAggregateStateMap

type ContainerNameToAggregateStateMap map[string]*AggregateContainerState

ContainerNameToAggregateStateMap maps a container name to AggregateContainerState that aggregates state of containers with that name.

func AggregateStateByContainerName

func AggregateStateByContainerName(aggregateContainerStateMap aggregateContainerStatesMap) ContainerNameToAggregateStateMap

AggregateStateByContainerName takes a set of AggregateContainerStates and merge them grouping by the container name. The result is a map from the container name to the aggregation from all input containers with the given name.

type ContainerState

type ContainerState struct {
	// Current request.
	Request Resources
	// Start of the latest CPU usage sample that was aggregated.
	LastCPUSampleStart time.Time
	// Max memory usage observed in the current aggregation interval.
	MemoryPeak ResourceAmount
	// End time of the current memory aggregation interval (not inclusive).
	WindowEnd time.Time
	// contains filtered or unexported fields
}

ContainerState stores information about a single container instance. Each ContainerState has a pointer to the aggregation that is used for aggregating its usage samples. It holds the recent history of CPU and memory utilization.

Note: samples are added to intervals based on their start timestamps.

func NewContainerState

func NewContainerState(request Resources, aggregator ContainerStateAggregator) *ContainerState

NewContainerState returns a new 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 artificial memory sample.

type ContainerStateAggregator

type ContainerStateAggregator interface {
	// AddSample aggregates a single usage sample.
	AddSample(sample *ContainerUsageSample)
	// SubtractSample removes a single usage sample. The subtracted sample
	// should be equal to some sample that was aggregated with AddSample()
	// in the past.
	SubtractSample(sample *ContainerUsageSample)
}

ContainerStateAggregator is an interface for objects that consume and aggregate container usage samples.

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
	// CPU or memory request at the time of measurment.
	Request 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.

func NewKeyError

func NewKeyError(key interface{}) KeyError

NewKeyError returns a new KeyError.

func (KeyError) Error

func (e KeyError) Error() string

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

	// Containers that belong to the Pod, keyed by the container name.
	Containers map[string]*ContainerState
	// PodPhase describing current life cycle phase of the Pod.
	Phase apiv1.PodPhase
	// contains filtered or unexported fields
}

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 ResourceAmountMax

func ResourceAmountMax(amount1, amount2 ResourceAmount) ResourceAmount

ResourceAmountMax returns the larger of two resource amounts.

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

	// Pod Resource Policy provided in the VPA API object. Can be nil.
	ResourcePolicy *vpa_types.PodResourcePolicy
	// Initial checkpoints of AggregateContainerStates for containers.
	// The key is container name.
	ContainersInitialAggregateState ContainerNameToAggregateStateMap
	// contains filtered or unexported fields
}

Vpa (Vertical Pod Autoscaler) object is responsible for vertical scaling of Pods matching a given label selector.

func NewVpa

func NewVpa(id VpaID, selector labels.Selector) *Vpa

NewVpa returns a new Vpa with a given ID and pod selector. Doesn't set the links to the matched aggregations.

func (*Vpa) AggregateStateByContainerName

func (vpa *Vpa) AggregateStateByContainerName() ContainerNameToAggregateStateMap

AggregateStateByContainerName returns a map from container name to the aggregated state of all containers with that name, belonging to pods matched by the VPA.

func (*Vpa) MergeCheckpointedState

func (vpa *Vpa) MergeCheckpointedState(aggregateContainerStateMap ContainerNameToAggregateStateMap)

MergeCheckpointedState adds checkpointed VPA aggregations to the given aggregateStateMap.

func (*Vpa) UseAggregationIfMatching

func (vpa *Vpa) UseAggregationIfMatching(aggregationKey AggregateStateKey, aggregation *AggregateContainerState)

UseAggregationIfMatching checks if the given aggregation matches (contributes to) this VPA and adds it to the set of VPA's aggregations if that is the case.

func (*Vpa) UsesAggregation

func (vpa *Vpa) UsesAggregation(aggregationKey AggregateStateKey) bool

UsesAggregation returns true iff an aggregation with the given key contributes to the VPA.

type VpaID

type VpaID struct {
	Namespace string
	VpaName   string
}

VpaID contains information needed to identify a VPA API object within a cluster.

Jump to

Keyboard shortcuts

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