mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 03:56:37 +00:00
Round up value of newReplicas
Signed-off-by: Gede Wahyu <tokekbesi@gmail.com>
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/openfaas/faas/gateway/requests"
|
"github.com/openfaas/faas/gateway/requests"
|
||||||
@ -97,7 +98,7 @@ func scaleService(alert requests.PrometheusInnerAlert, service scaling.ServiceQu
|
|||||||
// CalculateReplicas decides what replica count to set depending on current/desired amount
|
// CalculateReplicas decides what replica count to set depending on current/desired amount
|
||||||
func CalculateReplicas(status string, currentReplicas uint64, maxReplicas uint64, minReplicas uint64, scalingFactor uint64) uint64 {
|
func CalculateReplicas(status string, currentReplicas uint64, maxReplicas uint64, minReplicas uint64, scalingFactor uint64) uint64 {
|
||||||
newReplicas := currentReplicas
|
newReplicas := currentReplicas
|
||||||
step := uint64((float64(maxReplicas) / 100) * float64(scalingFactor))
|
step := uint64(math.Ceil(float64(maxReplicas) / 100 * float64(scalingFactor)))
|
||||||
|
|
||||||
if status == "firing" && step > 0 {
|
if status == "firing" && step > 0 {
|
||||||
if currentReplicas+step > maxReplicas {
|
if currentReplicas+step > maxReplicas {
|
||||||
|
@ -110,3 +110,14 @@ func TestScaledUpFrom1(t *testing.T) {
|
|||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestScaledUpWithSmallParam(t *testing.T) {
|
||||||
|
currentReplicas := uint64(1)
|
||||||
|
maxReplicas := uint64(4)
|
||||||
|
scalingFactor := uint64(1)
|
||||||
|
newReplicas := CalculateReplicas("firing", currentReplicas, maxReplicas, scaling.DefaultMinReplicas, scalingFactor)
|
||||||
|
if newReplicas == currentReplicas {
|
||||||
|
t.Log("Expected newReplicas > currentReplica")
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user