Skip to content

Commit

Permalink
Don't arbitrarily choose the largest datapoint
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon Pinske <brandon.pinske@crowdstrike.com>
  • Loading branch information
Brandon Pinske committed Sep 10, 2021
1 parent 0321b01 commit 95fcb43
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CREATE-NEW-SCALER.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ The constructor should have the following parameters:
## Lifecycle of a scaler

The scaler is created and closed everytime KEDA or HPA wants to call `GetMetrics`, and everytime a new ScaledObject is created or updated that has a trigger for that scaler. Thus, a developer of a scaler should not assume that the scaler will maintain any state between these calls.

## Note
The scaler code is embedded into the two separate binaries comprising keda, the operator and the custom metrics server component. The metrics server must be occasionally rebuilt published and deployed to k8s for it to have the same code as your operator.

GetMetricSpecForScaling() is executed by the operator for the purposes of scaling up to and down to 0 replicas.
GetMetrics() is executed by the custom metrics server in response to a calls against the external metrics api, whether by the HPA loop or by curl

12 changes: 3 additions & 9 deletions pkg/scalers/graphite_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,10 @@ func (s *graphiteScaler) ExecuteGrapQuery() (float64, error) {
return -1, fmt.Errorf("graphite query %s returned multiple series", s.metadata.query)
}

var v float64 = -1
for _, datapoints := range result[0].Datapoints {
if strconv.FormatFloat(datapoints[0], 'f', -1, 64) != "" {
if datapoints[0] > v {
v = datapoints[0]
}
}
}
// https://graphite-api.readthedocs.io/en/latest/api.html#json
datapoint := result[0].Datapoints[0][0]

return v, nil
return datapoint, nil
}

func (s *graphiteScaler) GetMetrics(ctx context.Context, metricName string, metricSelector labels.Selector) ([]external_metrics.ExternalMetricValue, error) {
Expand Down

0 comments on commit 95fcb43

Please sign in to comment.