Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce activationThreshold/minMetricValue for Metrics API Scaler #3402

Merged
merged 2 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: clustertriggerauthentications.keda.sh
spec:
Expand Down Expand Up @@ -218,9 +217,3 @@ spec:
served: true
storage: true
subresources: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
29 changes: 11 additions & 18 deletions config/crd/bases/keda.sh_scaledjobs.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: scaledjobs.keda.sh
spec:
Expand Down Expand Up @@ -5860,8 +5859,8 @@ spec:
constraint. - DoNotSchedule (default) tells the
scheduler not to schedule it. - ScheduleAnyway
tells the scheduler to schedule the pod in any
location, but giving higher precedence to topologies
that would help reduce the skew. A constraint
location, but giving higher precedence to topologies
that would help reduce the skew. A constraint
is considered "Unsatisfiable" for an incoming
pod if and only if every possible node assignment
for that pod would violate "MaxSkew" on some topology.
Expand Down Expand Up @@ -6329,12 +6328,12 @@ spec:
deleted when the pod is removed. \n Use this if:
a) the volume is only needed while the pod runs,
b) features of normal volumes like restoring from
snapshot or capacity tracking are needed, c)
the storage driver is specified through a storage
snapshot or capacity tracking are needed, c) the
storage driver is specified through a storage
class, and d) the storage driver supports dynamic
volume provisioning through a PersistentVolumeClaim
(see EphemeralVolumeSource for more information
on the connection between this volume type and
volume provisioning through a PersistentVolumeClaim
(see EphemeralVolumeSource for more information
on the connection between this volume type and
PersistentVolumeClaim). \n Use PersistentVolumeClaim
or one of the vendor-specific APIs for volumes
that persist for longer than the lifecycle of
Expand Down Expand Up @@ -6449,13 +6448,13 @@ spec:
differences between DataSource and
DataSourceRef: * While DataSource
only allows two specific types of
objects, DataSourceRef allows any
objects, DataSourceRef allows any
non-core object, as well as PersistentVolumeClaim
objects. * While DataSource ignores
disallowed values (dropping them),
DataSourceRef preserves all values,
DataSourceRef preserves all values,
and generates an error if a disallowed
value is specified. (Alpha) Using
value is specified. (Alpha) Using
this field requires the AnyVolumeDataSource
feature gate to be enabled.'
properties:
Expand Down Expand Up @@ -7701,9 +7700,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
16 changes: 5 additions & 11 deletions config/crd/bases/keda.sh_scaledobjects.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: scaledobjects.keda.sh
spec:
Expand Down Expand Up @@ -138,10 +139,9 @@ spec:
type: object
scaleUp:
description: 'scaleUp is scaling policy for scaling Up.
If not set, the default value is the higher of: *
increase no more than 4 pods per 60 seconds * double
the number of pods per 60 seconds No stabilization is
used.'
If not set, the default value is the higher of: * increase
no more than 4 pods per 60 seconds * double the number
of pods per 60 seconds No stabilization is used.'
properties:
policies:
description: policies is a list of potential scaling
Expand Down Expand Up @@ -370,9 +370,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
9 changes: 1 addition & 8 deletions config/crd/bases/keda.sh_triggerauthentications.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: triggerauthentications.keda.sh
spec:
Expand Down Expand Up @@ -217,9 +216,3 @@ spec:
served: true
storage: true
subresources: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
1 change: 0 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down
18 changes: 14 additions & 4 deletions pkg/scalers/metrics_api_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ type metricsAPIScaler struct {
}

type metricsAPIScalerMetadata struct {
targetValue float64
url string
valueLocation string
targetValue float64
activationTargetValue float64
url string
valueLocation string

// apiKeyAuth
enableAPIKeyAuth bool
Expand Down Expand Up @@ -108,6 +109,15 @@ func parseMetricsAPIMetadata(config *ScalerConfig) (*metricsAPIScalerMetadata, e
return nil, fmt.Errorf("no targetValue given in metadata")
}

meta.activationTargetValue = 0
if val, ok := config.TriggerMetadata["activationTargetValue"]; ok {
activationTargetValue, err := strconv.ParseFloat(val, 64)
if err != nil {
return nil, fmt.Errorf("targetValue parsing error %s", err.Error())
}
meta.activationTargetValue = activationTargetValue
}

if val, ok := config.TriggerMetadata["url"]; ok {
meta.url = val
} else {
Expand Down Expand Up @@ -246,7 +256,7 @@ func (s *metricsAPIScaler) IsActive(ctx context.Context) (bool, error) {
return false, err
}

return v > 0.0, nil
return v > s.metadata.activationTargetValue, nil
}

// GetMetricSpecForScaling returns the MetricSpec for the Horizontal Pod Autoscaler
Expand Down
2 changes: 2 additions & 0 deletions pkg/scalers/metrics_api_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var testMetricsAPIMetadata = []metricsAPIMetadataTestData{
{metadata: map[string]string{"url": "http://dummy:1230/api/v1/", "valueLocation": "metric.test", "targetValue": "42"}, raisesError: false},
// Target not an int
{metadata: map[string]string{"url": "http://dummy:1230/api/v1/", "valueLocation": "metric", "targetValue": "aa"}, raisesError: true},
// Activation target not an int
{metadata: map[string]string{"url": "http://dummy:1230/api/v1/", "valueLocation": "metric", "targetValue": "1", "activationTargetValue": "aa"}, raisesError: true},
// Missing metric name
{metadata: map[string]string{"url": "http://dummy:1230/api/v1/", "targetValue": "aa"}, raisesError: true},
// Missing url
Expand Down
Loading