Implemented the autoscaling steps to be proportions of the max replicas.

Introduced an new label to set the scaling factor that is used to calculate th proportions, setting it to 0 also allows to disable scaling.
Updated the tests to reflect the changes and added a new test which shows that setting the scaling factor to 0 indeed does disable scaling.
Ensured that the scaling factor is always between [0 and 100].

Signed-off-by: Simon Pelczer <templum.dev@gmail.com>
This commit is contained in:
Simon Pelczer
2018-03-23 22:13:07 +01:00
committed by Alex Ellis
parent a3cbe0b4a4
commit 7fe67d7af6
4 changed files with 85 additions and 23 deletions

View File

@ -86,13 +86,15 @@ func (s ExternalServiceQuery) GetReplicas(serviceName string) (handlers.ServiceQ
}
maxReplicas := uint64(handlers.DefaultMaxReplicas)
minReplicas := uint64(1)
minReplicas := uint64(handlers.DefaultMinReplicas)
scalingFactor := uint64(handlers.DefaultScalingFactor)
availableReplicas := function.AvailableReplicas
if function.Labels != nil {
labels := *function.Labels
minScale := labels[handlers.MinScaleLabel]
maxScale := labels[handlers.MaxScaleLabel]
scaleFactor := labels[handlers.ScalingFactorLabel]
if len(minScale) > 0 {
labelValue, err := strconv.Atoi(minScale)
@ -111,12 +113,28 @@ func (s ExternalServiceQuery) GetReplicas(serviceName string) (handlers.ServiceQ
maxReplicas = uint64(labelValue)
}
}
if len(scaleFactor) > 0 {
labelValue, err := strconv.Atoi(scaleFactor)
if err != nil {
log.Printf("Bad Scaling Factor: %s, should be uint", scaleFactor)
} else {
var temp = uint64(labelValue)
if temp >= 0 && temp <= 100 {
scalingFactor = temp
} else {
log.Printf("Bad Scaling Factor: %s, is in range [0 - 100]", temp)
}
}
}
}
return handlers.ServiceQueryResponse{
Replicas: function.Replicas,
MaxReplicas: maxReplicas,
MinReplicas: minReplicas,
ScalingFactor: scalingFactor,
AvailableReplicas: availableReplicas,
}, err
}
@ -153,4 +171,4 @@ func (s ExternalServiceQuery) SetReplicas(serviceName string, count uint64) erro
}
return err
}
}