diff --git a/pkg/ensurance/analyzer/analyzer.go b/pkg/ensurance/analyzer/analyzer.go index 64fed0781..f36892e35 100644 --- a/pkg/ensurance/analyzer/analyzer.go +++ b/pkg/ensurance/analyzer/analyzer.go @@ -291,7 +291,7 @@ func (s *AnomalyAnalyzer) computeActionContext(aboveThreshold bool, key string, s.restored[key] = uint64(object.RestoreThreshold) } // only do restore action after trigger x times and restore y times - if s.triggered[key] >= uint64(object.AvoidanceThreshold) && + if (s.triggered[key] >= uint64(object.AvoidanceThreshold) || s.triggered[key] == 0) && s.restored[key] >= uint64(object.RestoreThreshold) { // reset trigger count when restored s.triggered[key] = 0 diff --git a/pkg/ensurance/executor/watermark.go b/pkg/ensurance/executor/watermark.go index 5200fb8ba..1ba887165 100644 --- a/pkg/ensurance/executor/watermark.go +++ b/pkg/ensurance/executor/watermark.go @@ -215,21 +215,19 @@ func calculateGaps(stateMap map[string][]common.TimeSeries, throttleDownWatermark, throttleDownExist := throttleExecutor.ThrottleDownWatermark[m.Name] throttleUpWatermark, throttleUpExist := throttleExecutor.ThrottleUpWatermark[m.Name] - // If a metric does not exist in ThrottleDownWatermark, throttleDownGapToWatermarks of this metric will can't be calculated - if !throttleDownExist { - delete(result, m.Name) - } else { + if throttleDownExist && throttleUpExist { + // Wrong case: throttleUpExist && throttleDownExist won't co-exist + klog.Warningf("throttleUpExist && throttleDownExist won't co-exist: For metrics %s, maxUsed is %f, watermark is %f", m.Name, maxUsed, float64(throttleDownWatermark.PopSmallest().Value())) + continue + } else if throttleDownExist { klog.V(6).Infof("BuildThrottleDownWatermarkGap: For metrics %s, maxUsed is %f, watermark is %f", m.Name, maxUsed, float64(throttleDownWatermark.PopSmallest().Value())) result[m.Name] = (1 + executeExcessPercent) * (maxUsed - float64(throttleDownWatermark.PopSmallest().Value())) - } - - // If metric not exist in ThrottleUpWatermark, throttleUpGapToWatermarks of metric will can't be calculated - if !throttleUpExist { - delete(result, m.Name) - } else { + } else if throttleUpExist { klog.V(6).Infof("BuildThrottleUpWatermarkGap: For metrics %s, maxUsed is %f, watermark is %f", m.Name, maxUsed, float64(throttleUpWatermark.PopSmallest().Value())) // Attention: different with throttleDown and evict, use watermark - used - result[m.Name] = (1 + executeExcessPercent) * (float64(throttleUpWatermark.PopSmallest().Value()) - maxUsed) + result[m.Name] = (1 - executeExcessPercent) * (float64(throttleUpWatermark.PopSmallest().Value()) - maxUsed) + } else { + delete(result, m.Name) } } }