fix HPA plain metric calculate

fix inconsistency in plain metric replica calculator when usageRatio == 1.0, keep same with resource replicas
This commit is contained in:
zach593 2023-05-10 11:14:29 +08:00
parent 6aa68d6a8b
commit e3d5feb76c
2 changed files with 16 additions and 1 deletions

View File

@ -214,7 +214,7 @@ func (c *ReplicaCalculator) calcPlainMetricReplicas(metrics metricsclient.PodMet
for podName := range missingPods { for podName := range missingPods {
metrics[podName] = metricsclient.PodMetric{Value: targetUsage} metrics[podName] = metricsclient.PodMetric{Value: targetUsage}
} }
} else { } else if usageRatio > 1.0 {
// on a scale-up, treat missing pods as using 0% of the resource request // on a scale-up, treat missing pods as using 0% of the resource request
for podName := range missingPods { for podName := range missingPods {
metrics[podName] = metricsclient.PodMetric{Value: 0} metrics[podName] = metricsclient.PodMetric{Value: 0}

View File

@ -1322,6 +1322,21 @@ func TestReplicaCalcEmptyCPURequest(t *testing.T) {
tc.runTest(t) tc.runTest(t)
} }
func TestPlainMetricReplicaCalcMissingMetricsNoChangeEq(t *testing.T) {
tc := replicaCalcTestCase{
currentReplicas: 5,
expectedReplicas: 5,
metric: &metricInfo{
name: "qps",
levels: []int64{20000, 19000, 21000},
targetUsage: 20000,
expectedUsage: 20000,
metricType: podMetric,
},
}
tc.runTest(t)
}
func TestReplicaCalcMissingMetricsNoChangeEq(t *testing.T) { func TestReplicaCalcMissingMetricsNoChangeEq(t *testing.T) {
tc := replicaCalcTestCase{ tc := replicaCalcTestCase{
currentReplicas: 2, currentReplicas: 2,