From 617f35c1b7b034e598096a28e0b2227def17e671 Mon Sep 17 00:00:00 2001 From: brandon <32846221+bpinske@users.noreply.github.com> Date: Wed, 1 Dec 2021 03:19:31 -0800 Subject: [PATCH] Graphite scaler should use latest datapoint, not earliest, returned (#2365) Signed-off-by: Brandon Pinske --- CHANGELOG.md | 2 ++ pkg/scalers/graphite_scaler.go | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) 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 }