Add support for custom metrics for HPA (#2423)
* Add support for custom metrics for HPA * Cleanup TargetCPUPercent references from possible places * HPA v2beta has 80% default cpu limit if not set Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
@@ -21,12 +21,14 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
asv2beta2 "k8s.io/api/autoscaling/v2beta2"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
ferror "github.com/fission/fission/pkg/error"
|
||||
"github.com/fission/fission/pkg/executor/util/hpa"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd/httptrigger"
|
||||
@@ -38,9 +40,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
DEFAULT_MIN_SCALE = 1
|
||||
DEFAULT_TARGET_CPU_PERCENTAGE = 80
|
||||
DEFAULT_CONCURRENCY = 500
|
||||
DEFAULT_MIN_SCALE = 1
|
||||
DEFAULT_CONCURRENCY = 500
|
||||
)
|
||||
|
||||
type CreateSubCommand struct {
|
||||
@@ -463,13 +464,6 @@ func getExecutionStrategy(fnExecutor fv1.ExecutorType, input cli.Input) (strateg
|
||||
SpecializationTimeout: specializationTimeout,
|
||||
}
|
||||
} else {
|
||||
targetCPU := DEFAULT_TARGET_CPU_PERCENTAGE
|
||||
if input.IsSet(flagkey.RuntimeTargetcpu) {
|
||||
targetCPU, err = getTargetCPU(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
minScale := DEFAULT_MIN_SCALE
|
||||
if input.IsSet(flagkey.ReplicasMinscale) {
|
||||
@@ -494,9 +488,16 @@ func getExecutionStrategy(fnExecutor fv1.ExecutorType, input cli.Input) (strateg
|
||||
ExecutorType: fnExecutor,
|
||||
MinScale: minScale,
|
||||
MaxScale: maxScale,
|
||||
TargetCPUPercent: targetCPU,
|
||||
SpecializationTimeout: specializationTimeout,
|
||||
}
|
||||
|
||||
if input.IsSet(flagkey.RuntimeTargetcpu) {
|
||||
targetCPU, err := getTargetCPU(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
strategy.Metrics = []asv2beta2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(int32(targetCPU))}
|
||||
}
|
||||
}
|
||||
|
||||
return strategy, nil
|
||||
@@ -547,27 +548,14 @@ func updateExecutionStrategy(input cli.Input, existingExecutionStrategy *fv1.Exe
|
||||
SpecializationTimeout: specializationTimeout,
|
||||
}
|
||||
} else {
|
||||
targetCPU := existingExecutionStrategy.TargetCPUPercent
|
||||
minScale := existingExecutionStrategy.MinScale
|
||||
maxScale := existingExecutionStrategy.MaxScale
|
||||
|
||||
if fnExecutor != oldExecutor { // from poolmanager to newdeploy
|
||||
targetCPU = DEFAULT_TARGET_CPU_PERCENTAGE
|
||||
minScale = DEFAULT_MIN_SCALE
|
||||
maxScale = minScale
|
||||
}
|
||||
|
||||
if input.IsSet(flagkey.RuntimeTargetcpu) {
|
||||
targetCPU, err = getTargetCPU(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if targetCPU <= 0 || targetCPU > 100 {
|
||||
targetCPU = DEFAULT_TARGET_CPU_PERCENTAGE
|
||||
}
|
||||
}
|
||||
|
||||
if input.IsSet(flagkey.ReplicasMinscale) {
|
||||
minScale = input.Int(flagkey.ReplicasMinscale)
|
||||
}
|
||||
@@ -593,9 +581,17 @@ func updateExecutionStrategy(input cli.Input, existingExecutionStrategy *fv1.Exe
|
||||
ExecutorType: fnExecutor,
|
||||
MinScale: minScale,
|
||||
MaxScale: maxScale,
|
||||
TargetCPUPercent: targetCPU,
|
||||
SpecializationTimeout: specializationTimeout,
|
||||
}
|
||||
|
||||
if input.IsSet(flagkey.RuntimeTargetcpu) {
|
||||
targetCPU, err := getTargetCPU(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
strategy.Metrics = []asv2beta2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(int32(targetCPU))}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return strategy, nil
|
||||
|
||||
@@ -21,8 +21,10 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
asv2beta2 "k8s.io/api/autoscaling/v2beta2"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
"github.com/fission/fission/pkg/executor/util/hpa"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/dummy"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
)
|
||||
@@ -71,7 +73,6 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: DEFAULT_MIN_SCALE,
|
||||
MaxScale: DEFAULT_MIN_SCALE,
|
||||
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
|
||||
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
|
||||
},
|
||||
},
|
||||
@@ -92,7 +93,6 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: DEFAULT_MIN_SCALE,
|
||||
MaxScale: DEFAULT_MIN_SCALE,
|
||||
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
|
||||
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
|
||||
},
|
||||
},
|
||||
@@ -107,7 +107,6 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: DEFAULT_MIN_SCALE,
|
||||
MaxScale: DEFAULT_MIN_SCALE,
|
||||
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
|
||||
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
|
||||
},
|
||||
},
|
||||
@@ -134,7 +133,6 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: 2,
|
||||
MaxScale: 3,
|
||||
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
|
||||
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
|
||||
},
|
||||
},
|
||||
@@ -164,7 +162,6 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: 5,
|
||||
MaxScale: 5,
|
||||
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
|
||||
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
|
||||
},
|
||||
},
|
||||
@@ -183,7 +180,6 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: DEFAULT_MIN_SCALE,
|
||||
MaxScale: 3,
|
||||
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
|
||||
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
|
||||
},
|
||||
},
|
||||
@@ -211,7 +207,6 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: 2,
|
||||
MaxScale: 5,
|
||||
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
|
||||
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
|
||||
},
|
||||
},
|
||||
@@ -230,7 +225,6 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: 2,
|
||||
MaxScale: 5,
|
||||
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
|
||||
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
|
||||
},
|
||||
},
|
||||
@@ -240,7 +234,6 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: 2,
|
||||
MaxScale: 9,
|
||||
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
|
||||
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
|
||||
},
|
||||
},
|
||||
@@ -257,7 +250,6 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: 2,
|
||||
MaxScale: 5,
|
||||
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
|
||||
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
|
||||
},
|
||||
},
|
||||
@@ -267,7 +259,6 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: 2,
|
||||
MaxScale: 5,
|
||||
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
|
||||
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
|
||||
},
|
||||
},
|
||||
@@ -286,7 +277,7 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: DEFAULT_MIN_SCALE,
|
||||
MaxScale: DEFAULT_MIN_SCALE,
|
||||
TargetCPUPercent: 50,
|
||||
Metrics: []asv2beta2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(50)},
|
||||
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
|
||||
},
|
||||
},
|
||||
@@ -304,7 +295,7 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: 2,
|
||||
MaxScale: 5,
|
||||
TargetCPUPercent: 88,
|
||||
Metrics: []asv2beta2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(88)},
|
||||
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
|
||||
},
|
||||
},
|
||||
@@ -314,7 +305,7 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: 2,
|
||||
MaxScale: 5,
|
||||
TargetCPUPercent: 20,
|
||||
Metrics: []asv2beta2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(20)},
|
||||
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
|
||||
},
|
||||
},
|
||||
@@ -329,10 +320,9 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
existingInvokeStrategy: &fv1.InvokeStrategy{
|
||||
StrategyType: fv1.StrategyTypeExecution,
|
||||
ExecutionStrategy: fv1.ExecutionStrategy{
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: 2,
|
||||
MaxScale: 5,
|
||||
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
|
||||
ExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
MinScale: 2,
|
||||
MaxScale: 5,
|
||||
},
|
||||
},
|
||||
expectedResult: &fv1.InvokeStrategy{
|
||||
@@ -342,7 +332,6 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
MinScale: 2,
|
||||
MaxScale: 5,
|
||||
SpecializationTimeout: 200,
|
||||
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
|
||||
},
|
||||
},
|
||||
expectError: false,
|
||||
|
||||
@@ -47,7 +47,7 @@ func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
||||
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n", "NAME", "ENV", "EXECUTORTYPE", "MINSCALE", "MAXSCALE", "MINCPU", "MAXCPU", "MINMEMORY", "MAXMEMORY", "TARGETCPU", "SECRETS", "CONFIGMAPS")
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n", "NAME", "ENV", "EXECUTORTYPE", "MINSCALE", "MAXSCALE", "MINCPU", "MAXCPU", "MINMEMORY", "MAXMEMORY", "SECRETS", "CONFIGMAPS")
|
||||
for _, f := range fns {
|
||||
secrets := f.Spec.Secrets
|
||||
configMaps := f.Spec.ConfigMaps
|
||||
@@ -59,7 +59,7 @@ func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
configMapList = append(configMapList, configMap.Name)
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n",
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n",
|
||||
f.ObjectMeta.Name, f.Spec.Environment.Name,
|
||||
f.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType,
|
||||
f.Spec.InvokeStrategy.ExecutionStrategy.MinScale,
|
||||
@@ -68,7 +68,6 @@ func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
f.Spec.Resources.Limits.Cpu().String(),
|
||||
f.Spec.Resources.Requests.Memory().String(),
|
||||
f.Spec.Resources.Limits.Memory().String(),
|
||||
f.Spec.InvokeStrategy.ExecutionStrategy.TargetCPUPercent,
|
||||
strings.Join(secretsList, ","),
|
||||
strings.Join(configMapList, ","))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user