Skip to content

Commit

Permalink
fix(analysis): graphite metric provider - nil pointer dereference
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsjip committed Apr 30, 2023
1 parent 96f164f commit efe0e91
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions metricproviders/graphite/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 9 additions & 0 deletions metricproviders/graphite/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit efe0e91

Please sign in to comment.