From b2cd0faf325cb61bf30e0b889ad6c695219946d8 Mon Sep 17 00:00:00 2001 From: Charlie Sharpsteen Date: Wed, 12 Feb 2025 17:01:19 -0500 Subject: [PATCH 1/2] Revert "(SUP-5232) Added error handling to JSON conversion of metrics" Conversion to JSON prior to making a HTTP request was not the error reported in SUP-5232. JSON responses that did not contain Array bodies were the cause of the issue. This reverts commit 05cf01be3b6587e1e861b4ca616cd1416f2abc9d. --- files/pe_metrics.rb | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/files/pe_metrics.rb b/files/pe_metrics.rb index fc0c1f3e..a61c37c9 100644 --- a/files/pe_metrics.rb +++ b/files/pe_metrics.rb @@ -79,16 +79,7 @@ def post_endpoint(url, body) end def retrieve_additional_metrics(url, _metrics_type, metrics) - begin - json_data = metrics.to_json - rescue StandardError => e - STDERR.puts 'Failed to convert metrics to JSON.' - STDERR.puts "Error: #{e.message}" - STDERR.puts e.backtrace - return [] - end - - metrics_output = post_endpoint(url, json_data) + metrics_output = post_endpoint(url, metrics.to_json) return [] if metrics_output.empty? # For a status other than 200 or 404, add the HTTP code to the error array From 137a00c62b2fa56e74ba8f8b543815ce25fc0c15 Mon Sep 17 00:00:00 2001 From: Charlie Sharpsteen Date: Wed, 12 Feb 2025 17:13:21 -0500 Subject: [PATCH 2/2] (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. --- files/pe_metrics.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/files/pe_metrics.rb b/files/pe_metrics.rb index a61c37c9..65137a0d 100644 --- a/files/pe_metrics.rb +++ b/files/pe_metrics.rb @@ -80,6 +80,15 @@ def post_endpoint(url, body) def retrieve_additional_metrics(url, _metrics_type, metrics) metrics_output = post_endpoint(url, metrics.to_json) + + unless metrics_output.is_a?(Array) + STDERR.puts('ERROR request to %{url} returned data non-Array data of type %{class}: %{output}' % + { url: url, + class: metrics_output.class, + output: metrics_output.to_s }) + return [] + end + return [] if metrics_output.empty? # For a status other than 200 or 404, add the HTTP code to the error array