From 6f7415e4813fdbbe795935bda1c184f08c1e9677 Mon Sep 17 00:00:00 2001 From: iamzili Date: Thu, 13 Feb 2025 09:12:13 +0100 Subject: [PATCH] VPA: Revert ConfidenceMultiplier tests --- .../pkg/recommender/logic/estimator_test.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/vertical-pod-autoscaler/pkg/recommender/logic/estimator_test.go b/vertical-pod-autoscaler/pkg/recommender/logic/estimator_test.go index 8df6dea340f5..4a8798f4218b 100644 --- a/vertical-pod-autoscaler/pkg/recommender/logic/estimator_test.go +++ b/vertical-pod-autoscaler/pkg/recommender/logic/estimator_test.go @@ -83,6 +83,30 @@ func TestConfidenceMultiplier(t *testing.T) { // Expect testedEstimator2 to return zero. assert.Equal(t, model.ResourceAmount(0), testedEstimator2.GetResourceEstimation(s)[model.ResourceCPU]) + + timestamp := anyTime + testedCPU3 := WithCPUConfidenceMultiplier(0.1, 2.0, baseCPUEstimator) + testedMemory3 := WithMemoryConfidenceMultiplier(0.1, 2.0, baseMemoryEstimator) + testedEstimator3 := NewCombinedEstimator(testedCPU3, testedMemory3) + + for i := 1; i <= 9; i++ { + s.AddSample(&model.ContainerUsageSample{ + MeasureStart: timestamp, + Usage: model.CPUAmountFromCores(1.0), + Resource: model.ResourceCPU, + }) + timestamp = timestamp.Add(time.Minute * 2) + } + + // Expected confidence = 9/(60*24) = 0.00625. + assert.Equal(t, 0.00625, getConfidence(s)) + // Expected CPU estimation = 3.14 * (1 + multiplier/confidence)^exponent = + // 3.14 * (1 + 0.1/0.00625)^2 = 907.46. + // Expected Memory estimation = + // 3140000000 * (1 + 0.1/0.00625)^2 = 907460000000 + resourceEstimation := testedEstimator3.GetResourceEstimation(s) + assert.Equal(t, 907.46, model.CoresFromCPUAmount(resourceEstimation[model.ResourceCPU])) + assert.Equal(t, 9.0746e+11, model.BytesFromMemoryAmount(resourceEstimation[model.ResourceMemory])) } // Verifies that the confidenceMultiplier works for the case of no