Fix autoscaler metrics trigger scale direction problem
@@ -753,6 +753,21 @@ func (w *Watcher) checkMetricsTrigger(
}
if isAboveThreshold {
+ delta := w.AutoScaler.Delta(trigger, roomCount)
+
+ // As Delta() is generic (works for both up and down scheduling)
+ // it is necessary to check if the direction of scaling is coherent with
+ // the delta signal, as it may occur that values lower than the up trigger usage
+ // give us a negative delta or vice-versa.
+ //
+ // Example:
+ // Current usage = 70%
+ // Up trigger usage = 75%
+ // Down trigger usage = 60%
+ //
+ // resulting in delta = -1 when checking up trigger
+ //
+ if (isDown && delta < 0) || (!isDown && delta > 0) {
scaling.InSync = false
if scheduler.State != unbalancedState {
scaling.ChangedState = true
@@ -762,8 +777,7 @@ func (w *Watcher) checkMetricsTrigger(
// not in cooldown window
if nowTimestamp-scheduler.LastScaleOpAt > int64(scalingPolicy.Cooldown) {
- scaling.Delta = w.AutoScaler.Delta(trigger, roomCount)
-
+ scaling.Delta = delta
l := w.Logger.WithFields(logrus.Fields{
"scheduler": scheduler.Name,
"currentUsage": currentUsage,
@@ -780,11 +794,12 @@ func (w *Watcher) checkMetricsTrigger(
"currentUsage": currentUsage,
"targetUsage": usage,
"triggerType": trigger.Type,
- "delta": scaling.Delta,
+ "delta": delta,
})
l.Info("Still in cooldown period")
}
}
+ }
return scaling, nil
}
