diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ed4d7a3a53..6548993e10a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,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 diff --git a/pkg/scalers/graphite_scaler.go b/pkg/scalers/graphite_scaler.go index 8976aedfc53..54708298268 100644 --- a/pkg/scalers/graphite_scaler.go +++ b/pkg/scalers/graphite_scaler.go @@ -191,7 +191,12 @@ func (s *graphiteScaler) ExecuteGrapQuery() (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 }