summaryrefslogtreecommitdiff
path: root/lib/chef/data_collector
diff options
context:
space:
mode:
authorAdam Leff <adam@leff.co>2016-06-22 23:14:55 -0400
committerAdam Leff <adam@leff.co>2016-06-24 14:48:42 -0400
commitbb56a100caf7de9b7f0bbcb1377ba7f7cae05f90 (patch)
tree030b846f3032a7f77fb0e9fb0e18fa04614f0c91 /lib/chef/data_collector
parent20774deff25b952ff24d6e6d100007713dcbf005 (diff)
downloadchef-bb56a100caf7de9b7f0bbcb1377ba7f7cae05f90.tar.gz
Expand data_collector resource list to include all resources
Historically when a Chef run fails, the event handlers only report on resources that have been processed during the run. This change allows the Data Collector to report those resources in the resource collection that have not yet been processed so users can better ascertain how much of their run was completed, and specifically what resources were not processed as a result of the Chef failure. Instead of building up a list of resources as they are processed, this change instead creates a resource report for each resource+action in the resource collection and then modifies each of those reports once the resource is processed.
Diffstat (limited to 'lib/chef/data_collector')
-rw-r--r--lib/chef/data_collector/messages.rb6
-rw-r--r--lib/chef/data_collector/resource_report.rb17
2 files changed, 16 insertions, 7 deletions
diff --git a/lib/chef/data_collector/messages.rb b/lib/chef/data_collector/messages.rb
index e23262c9e4..89bad9f9f9 100644
--- a/lib/chef/data_collector/messages.rb
+++ b/lib/chef/data_collector/messages.rb
@@ -70,15 +70,15 @@ class Chef
"message_type" => "run_converge",
"node_name" => run_status.node.name,
"organization_name" => organization,
- "resources" => reporter_data[:completed_resources].map(&:for_json),
+ "resources" => reporter_data[:resources].map(&:report_data),
"run_id" => run_status.run_id,
"run_list" => run_status.node.run_list.for_json,
"start_time" => run_status.start_time.utc.iso8601,
"end_time" => run_status.end_time.utc.iso8601,
"source" => collector_source,
"status" => reporter_data[:status],
- "total_resource_count" => reporter_data[:completed_resources].count,
- "updated_resource_count" => reporter_data[:completed_resources].select { |r| r.status == "updated" }.count,
+ "total_resource_count" => reporter_data[:resources].count,
+ "updated_resource_count" => reporter_data[:resources].select { |r| r.report_data["status"] == "updated" }.count,
}
message["error"] = {
diff --git a/lib/chef/data_collector/resource_report.rb b/lib/chef/data_collector/resource_report.rb
index 1793fe2c9d..89b6d26706 100644
--- a/lib/chef/data_collector/resource_report.rb
+++ b/lib/chef/data_collector/resource_report.rb
@@ -22,13 +22,14 @@ class Chef
class DataCollector
class ResourceReport
- attr_reader :action, :current_resource, :elapsed_time, :new_resource, :status
- attr_accessor :conditional, :exception
+ attr_reader :action, :elapsed_time, :new_resource, :status
+ attr_accessor :conditional, :current_resource, :exception
def initialize(new_resource, action, current_resource = nil)
@new_resource = new_resource
@action = action
@current_resource = current_resource
+ @status = "unprocessed"
end
def skipped(conditional)
@@ -54,6 +55,14 @@ class Chef
@elapsed_time = new_resource.elapsed_time
end
+ def elapsed_time_in_milliseconds
+ elapsed_time.nil? ? nil : (elapsed_time * 1000).to_i
+ end
+
+ def potentially_changed?
+ %w{updated failed}.include?(status)
+ end
+
def to_hash
hash = {
"type" => new_resource.resource_name.to_sym,
@@ -61,8 +70,8 @@ class Chef
"id" => new_resource.identity.to_s,
"after" => new_resource.state_for_resource_reporter,
"before" => current_resource ? current_resource.state_for_resource_reporter : {},
- "duration" => (elapsed_time * 1000).to_i.to_s,
- "delta" => new_resource.respond_to?(:diff) ? new_resource.diff : "",
+ "duration" => elapsed_time_in_milliseconds.to_s,
+ "delta" => new_resource.respond_to?(:diff) && potentially_changed? ? new_resource.diff : "",
"result" => action.to_s,
"status" => status,
}