Merge pull request #117845 from ctripcloud/fix-hpa-plain-calc
fix HPA plain metric calculate
This commit is contained in:
		@@ -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}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user