summaryrefslogtreecommitdiff
path: root/lib/chef/resource_reporter.rb
diff options
context:
space:
mode:
authorBryan McLellan <btm@opscode.com>2012-10-30 13:44:23 -0700
committerBryan McLellan <btm@opscode.com>2012-10-30 13:44:23 -0700
commit40bb09b6605852b362875ec99438f22af6c35676 (patch)
tree932e28c75bcccc5a18a86d1371612b0fcdd9429c /lib/chef/resource_reporter.rb
parent7c757e2281e862a26c22795ffd957e6048da02b1 (diff)
parent6668c614b3762ded59595241f4719dbec98eaa1f (diff)
downloadchef-40bb09b6605852b362875ec99438f22af6c35676.tar.gz
Merge branch '10-stable'
Conflicts: chef-expander/lib/chef/expander/version.rb chef-server-api/lib/chef-server-api/version.rb chef-server-webui/lib/chef-server-webui/version.rb chef-server/lib/chef-server/version.rb chef-solr/lib/chef/solr/version.rb chef/lib/chef/node/attribute.rb lib/chef/node.rb
Diffstat (limited to 'lib/chef/resource_reporter.rb')
-rw-r--r--lib/chef/resource_reporter.rb39
1 files changed, 24 insertions, 15 deletions
diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb
index 3d10c1e961..f9ad5e1cb9 100644
--- a/lib/chef/resource_reporter.rb
+++ b/lib/chef/resource_reporter.rb
@@ -116,15 +116,15 @@ class Chef
Chef::Log.info("Chef server generated run history id: #{@run_id}")
@summary_only = server_response["summary_only"]
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
- if !e.response || e.response.code.to_s != 404
+ if !e.response || e.response.code.to_s != "404"
if Chef::Config[:enable_reporting_url_fatals]
- Chef::Log.error("Received exception attempting to generate run history id (URL Path: #{resource_history_url}), and enable_reporting_url_fatals is set, aborting run.")
+ Chef::Log.error("Received exception #{"(" + e.response.code + ") " if e.response.code}attempting to generate run history id (URL Path: #{resource_history_url}), and enable_reporting_url_fatals is set, aborting run.")
raise
else
- Chef::Log.info("Received exception attempting to generate run history id (URL Path: #{resource_history_url}), disabling reporting for this run.")
+ Chef::Log.info("Received exception #{"(" + e.response.code + ") " if e.response.code}attempting to generate run history id (URL Path: #{resource_history_url}), disabling reporting for this run.")
end
else
- Chef::Log.debug("Received 404 attempting to generate run history id (URL Path: #{resource_history_url}), assuming feature is not supported.")
+ Chef::Log.debug("Received 404 attempting to generate run history id (URL Path: #{resource_history_url}), assuming feature is not supported on server.")
end
@reporting_enabled = false
end
@@ -187,17 +187,26 @@ class Chef
Chef::Log.info("Sending resource update report (run-id: #{@run_id})")
Chef::Log.debug run_data.inspect
compressed_data = encode_gzip(run_data.to_json)
- #if summary only is enabled send the uncompressed run_data excluding the run_data["resources"] and some additional metrics.
- if @summary_only
- run_data = report_summary(run_data, compressed_data)
- Chef::Log.info("run_data_summary: #{run_data}")
- @rest_client.post_rest(resource_history_url, run_data)
- else
- Chef::Log.debug("Sending Compressed Run Data...")
- # Since we're posting compressed data we can not directly call
- # post_rest which expects JSON
- reporting_url = @rest_client.create_url(resource_history_url)
- @rest_client.raw_http_request(:POST, reporting_url, {'Content-Encoding' => 'gzip'}, compressed_data)
+ begin
+ #if summary only is enabled send the uncompressed run_data excluding the run_data["resources"] and some additional metrics.
+ if @summary_only
+ run_data = report_summary(run_data, compressed_data)
+ Chef::Log.info("run_data_summary: #{run_data}")
+ @rest_client.post_rest(resource_history_url, run_data)
+ else
+ Chef::Log.debug("Sending compressed run data...")
+ # Since we're posting compressed data we can not directly call
+ # post_rest which expects JSON
+ reporting_url = @rest_client.create_url(resource_history_url)
+ @rest_client.raw_http_request(:POST, reporting_url, {'Content-Encoding' => 'gzip'}, compressed_data)
+ end
+ rescue Net::HTTPServerException => e
+ if e.response.code.to_s == "400"
+ Chef::FileCache.store("failed-reporting-data.json", Chef::JSONCompat.to_json_pretty(run_data), 0640)
+ Chef::Log.error("Failed to post reporting data to server (HTTP 400), saving to #{Chef::FileCache.load("failed-reporting-data.json", false)}")
+ else
+ Chef::Log.error("Failed to post reporting data to server (HTTP #{e.response.code.to_s})")
+ end
end
else
Chef::Log.debug("Server doesn't support resource history, skipping resource report.")