mirror of
https://github.com/zalando-incubator/kube-metrics-adapter.git
synced 2024-12-22 11:06:04 +00:00
Merge pull request #371 from zalando-incubator/scaling-chunks
Use 10 buckets on ScalingSchedule ramp-up/down
This commit is contained in:
commit
e04cd10bfc
@ -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 {
|
||||
|
@ -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)",
|
||||
|
Loading…
x
Reference in New Issue
Block a user