Skip to content

Commit

Permalink
Graphite scaler should use latest datapoint, not earliest, returned (#…
Browse files Browse the repository at this point in the history
…2365)

Signed-off-by: Brandon Pinske <brandon.pinske@crowdstrike.com>
  • Loading branch information
bpinske authored Dec 1, 2021
1 parent 1cdb887 commit 8e4f201
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

### Improvements

- Graphite Scaler: use the latest datapoint returned, not the earliest (https://github.com/kedacore/keda/pull/2365)

- TODO ([#XXX](https://github.com/kedacore/keda/pull/XXX))

### Breaking Changes
Expand Down
7 changes: 6 additions & 1 deletion pkg/scalers/graphite_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ func (s *graphiteScaler) ExecuteGrapQuery(ctx context.Context) (float64, error)
}

// https://graphite-api.readthedocs.io/en/latest/api.html#json
datapoint := result[0].Datapoints[0][0]
if len(result[0].Datapoints) == 0 {
return 0, nil
}

latestDatapoint := len(result[0].Datapoints) - 1
datapoint := result[0].Datapoints[latestDatapoint][0]

return datapoint, nil
}
Expand Down

0 comments on commit 8e4f201

Please sign in to comment.