Skip to content

Commit b40c259

Browse files
committed
(PE-40346) Ensure additional_metrics requests return Array
This commit adds a guard clause to the `retrieve_additional_metrics` function in `pe_metrics.rb` that ensures the data returned from the `/metrics` API is of type Array. Non-conforming data is logged to stderr along with the URL queried as non-Array responses typically contain error messages that inform why the request failed.
1 parent 5d3f21a commit b40c259

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

files/pe_metrics.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ def post_endpoint(url, body)
8080

8181
def retrieve_additional_metrics(url, _metrics_type, metrics)
8282
metrics_output = post_endpoint(url, metrics.to_json)
83+
84+
unless metrics_output.is_a?(Array)
85+
STDERR.puts('ERROR request to %{url} returned data non-Array data of type %{class}: %{output}' %
86+
{ url: url,
87+
class: metrics_output.class,
88+
output: metrics_output.to_s })
89+
return []
90+
end
91+
8392
return [] if metrics_output.empty?
8493

8594
# For a status other than 200 or 404, add the HTTP code to the error array

0 commit comments

Comments
 (0)