diff --git a/CHANGELOG.md b/CHANGELOG.md index d8a13d722a5..15289cd44a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pkg/scalers/graphite_scaler.go b/pkg/scalers/graphite_scaler.go index 854fa4b9483..597d34d9678 100644 --- a/pkg/scalers/graphite_scaler.go +++ b/pkg/scalers/graphite_scaler.go @@ -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 }