Skip to content

Commit

Permalink
Merge pull request #7819 from iamzili/vpa-cpu-sample-fix
Browse files Browse the repository at this point in the history
VPA: Remove obsolete comment and a few lines of code from addCPUSample
  • Loading branch information
k8s-ci-robot authored Feb 11, 2025
2 parents 08e7250 + ca812b3 commit ce71abf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ package model

import (
"fmt"
"math"
"time"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -207,12 +206,8 @@ func (a *AggregateContainerState) SubtractSample(sample *ContainerUsageSample) {

func (a *AggregateContainerState) addCPUSample(sample *ContainerUsageSample) {
cpuUsageCores := CoresFromCPUAmount(sample.Usage)
cpuRequestCores := CoresFromCPUAmount(sample.Request)
// Samples are added with the weight equal to the current request. This means that
// whenever the request is increased, the history accumulated so far effectively decays,
// which helps react quickly to CPU starvation.
a.AggregateCPUUsage.AddSample(
cpuUsageCores, math.Max(cpuRequestCores, minSampleWeight), sample.MeasureStart)
cpuUsageCores, minSampleWeight, sample.MeasureStart)
if sample.MeasureStart.After(a.LastSampleStart) {
a.LastSampleStart = sample.MeasureStart
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func TestAggregateContainerUsageSamples(t *testing.T) {
// Verify that CPU measures are added to the CPU histogram.
// The weight should be equal to the current request.
timeStep := memoryAggregationInterval / 2
test.mockCPUHistogram.On("AddSample", 3.14, 2.3, testTimestamp)
test.mockCPUHistogram.On("AddSample", 6.28, 2.3, testTimestamp.Add(timeStep))
test.mockCPUHistogram.On("AddSample", 1.57, 2.3, testTimestamp.Add(2*timeStep))
test.mockCPUHistogram.On("AddSample", 3.14, minSampleWeight, testTimestamp)
test.mockCPUHistogram.On("AddSample", 6.28, minSampleWeight, testTimestamp.Add(timeStep))
test.mockCPUHistogram.On("AddSample", 1.57, minSampleWeight, testTimestamp.Add(2*timeStep))
// Verify that memory peaks are added to the memory peaks histogram.
memoryAggregationWindowEnd := testTimestamp.Add(memoryAggregationInterval)
test.mockMemoryHistogram.On("AddSample", 5.0, 1.0, memoryAggregationWindowEnd)
Expand Down

0 comments on commit ce71abf

Please sign in to comment.