summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@opscode.com>2012-10-19 16:06:28 -0700
committerBryan McLellan <btm@opscode.com>2012-10-19 16:57:17 -0700
commit508ee1b85798234abad655963131609684bdedaf (patch)
treea0a9cb8fc8fd38a2c754b0c4ca9f617158f26484
parent1f8bf2fc7b435fc4ca5f774f2b04c12d6b3a7299 (diff)
downloadchef-508ee1b85798234abad655963131609684bdedaf.tar.gz
Save reporting data to disk on HTTP failure
For debugging and support use
-rw-r--r--chef/lib/chef/resource_reporter.rb31
1 files changed, 20 insertions, 11 deletions
diff --git a/chef/lib/chef/resource_reporter.rb b/chef/lib/chef/resource_reporter.rb
index fe28f26d73..f9ad5e1cb9 100644
--- a/chef/lib/chef/resource_reporter.rb
+++ b/chef/lib/chef/resource_reporter.rb
@@ -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.")