summaryrefslogtreecommitdiff
path: root/lib/chef/data_collector.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-07-24 15:23:57 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-07-24 18:33:51 -0700
commit81f8d729edcd5237aaad19c351dae46fd8e7c0d6 (patch)
treed22cac0e13faa3349e7921a27ee29c1d89266de3 /lib/chef/data_collector.rb
parent303282f31ea20ff5dcdefe42e19c0bb8a42f4178 (diff)
downloadchef-81f8d729edcd5237aaad19c351dae46fd8e7c0d6.tar.gz
Tweak data collector exception handling
This isn't Java and Net::HTTP can throw a billion things, so just rescue (nearly) everything. I have a hard time imagining that there's a failure here that we wouldn't want to ignore, other than the ones like OOM thrown by Exception that indicate internal failures. Also only throw the "this is normal" info message on 404s, other responses like 500s should be warns even if it is set to ignore failures (people with data collectors correctly setup need to know about 500s even if we keep going, since that is abnormal). This also fixes a bug in handling exceptions like Timeout::Error which do not have a response.code at all which would throw NoMethodError. closes #8749 Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/data_collector.rb')
-rw-r--r--lib/chef/data_collector.rb23
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/chef/data_collector.rb b/lib/chef/data_collector.rb
index aac864f485..47d329b2b6 100644
--- a/lib/chef/data_collector.rb
+++ b/lib/chef/data_collector.rb
@@ -177,14 +177,17 @@ class Chef
@http ||= setup_http_client(Chef::Config[:data_collector][:server_url])
@http.post(nil, message, headers)
- rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
- Errno::ECONNREFUSED, EOFError, Net::HTTPBadResponse,
- Net::HTTPHeaderSyntaxError, Net::ProtocolError, OpenSSL::SSL::SSLError,
- Errno::EHOSTDOWN => e
+ rescue => e
# Do not disable data collector reporter if additional output_locations have been specified
events.unregister(self) unless Chef::Config[:data_collector][:output_locations]
- code = e&.response&.code&.to_s || "Exception Code Empty"
+ begin
+ code = e&.response&.code&.to_s
+ rescue
+ # i really dont care
+ end
+
+ code ||= "No HTTP Code"
msg = "Error while reporting run start to Data Collector. URL: #{Chef::Config[:data_collector][:server_url]} Exception: #{code} -- #{e.message} "
@@ -192,9 +195,13 @@ class Chef
Chef::Log.error(msg)
raise
else
- # Make the message non-scary for folks who don't have automate:
- msg << " (This is normal if you do not have #{Chef::Dist::AUTOMATE})"
- Chef::Log.info(msg)
+ if code == "404"
+ # Make the message non-scary for folks who don't have automate:
+ msg << " (This is normal if you do not have #{Chef::Dist::AUTOMATE})"
+ Chef::Log.info(msg)
+ else
+ Chef::Log.warn(msg)
+ end
end
end