Merge pull request #371 from zalando-incubator/scaling-chunks

Use 10 buckets on ScalingSchedule ramp-up/down
This commit is contained in:
Jonathan Juares Beber 2021-10-01 10:39:57 +02:00 committed by GitHub
commit e04cd10bfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 9 deletions

View File

@ -334,7 +334,14 @@ func scaledValue(timestamp time.Time, startTime time.Time, scalingWindowDuration
if scalingWindowDuration == 0 {
return 0
}
return int64(math.Ceil(math.Abs(float64(timestamp.Sub(startTime))) / float64(scalingWindowDuration) * float64(value)))
// The HPA has a rule to do not scale up or down if the change in
// the metric is less than 10% of the current value. We will use 10
// buckets of time using the floor of each. This value might be
// flexible one day, but for now it's fixed.
const steps float64 = 10
requiredPercentage := math.Abs(float64(timestamp.Sub(startTime))) / float64(scalingWindowDuration)
return int64(math.Floor(requiredPercentage*steps) * (float64(value) / steps))
}
func between(timestamp, start, end time.Time) bool {

View File

@ -86,7 +86,7 @@ func TestScalingScheduleCollector(t *testing.T) {
expectedValue: 100,
},
{
msg: "Return the scaled value (67) for one time config - 20 seconds before starting",
msg: "Return the scaled value (60) for one time config - 20 seconds before starting",
schedules: []schedule{
{
date: nowTime.Add(time.Second * 20).Format(time.RFC3339),
@ -95,10 +95,10 @@ func TestScalingScheduleCollector(t *testing.T) {
value: 100,
},
},
expectedValue: 67,
expectedValue: 60,
},
{
msg: "Return the scaled value (67) for one time config - 20 seconds after",
msg: "Return the scaled value (60) for one time config - 20 seconds after",
schedules: []schedule{
{
date: nowTime.Add(-time.Minute * 45).Add(-time.Second * 20).Format(time.RFC3339),
@ -107,10 +107,10 @@ func TestScalingScheduleCollector(t *testing.T) {
value: 100,
},
},
expectedValue: 67,
expectedValue: 60,
},
{
msg: "Return the scaled value (95) for one time config with a custom scaling window - 30 seconds before starting",
msg: "Return the scaled value (90) for one time config with a custom scaling window - 30 seconds before starting",
scalingWindowDurationMinutes: &tenMinutes,
schedules: []schedule{
{
@ -120,10 +120,10 @@ func TestScalingScheduleCollector(t *testing.T) {
value: 100,
},
},
expectedValue: 95,
expectedValue: 90,
},
{
msg: "Return the scaled value (95) for one time config with a custom scaling window - 30 seconds after",
msg: "Return the scaled value (90) for one time config with a custom scaling window - 30 seconds after",
scalingWindowDurationMinutes: &tenMinutes,
schedules: []schedule{
{
@ -133,7 +133,7 @@ func TestScalingScheduleCollector(t *testing.T) {
value: 100,
},
},
expectedValue: 95,
expectedValue: 90,
},
{
msg: "Return the default value (0) for one time config not started yet (20 minutes before)",