From e2946c5b87f7452fe2a8baea655abc9ae324f9dd Mon Sep 17 00:00:00 2001 From: mdsjip <2284562+mdsjip@users.noreply.github.com> Date: Fri, 26 Aug 2022 13:13:56 +0200 Subject: [PATCH] fix(analysis): graphite metric provider - index out of range [0] with length 0 Signed-off-by: mdsjip <2284562+mdsjip@users.noreply.github.com> --- metricproviders/graphite/api.go | 4 ++++ metricproviders/graphite/api_test.go | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/metricproviders/graphite/api.go b/metricproviders/graphite/api.go index b296295152..fc304395b1 100644 --- a/metricproviders/graphite/api.go +++ b/metricproviders/graphite/api.go @@ -68,6 +68,10 @@ func (api APIClient) Query(quer string) ([]dataPoint, error) { return []dataPoint{}, err } + if len(result) == 0 { + return []dataPoint{}, nil + } + return result[0].DataPoints, nil } diff --git a/metricproviders/graphite/api_test.go b/metricproviders/graphite/api_test.go index ce947da92f..bca62bbae2 100644 --- a/metricproviders/graphite/api_test.go +++ b/metricproviders/graphite/api_test.go @@ -82,6 +82,15 @@ func TestQuery(t *testing.T) { } ]`, value, timestamp), 200, + }, { + "graphite response with empty array", + query, + targetQuery, + fromQuery, + []dataPoint{}, + nil, + `[]`, + 200, }, { "graphite response body with invalid JSON", query,