Class: Chef::DataCollector::Reporter
- Inherits:
-
EventDispatch::Base
- Object
- EventDispatch::Base
- Chef::DataCollector::Reporter
- Defined in:
- lib/chef/data_collector.rb
Overview
Chef::DataCollector::Reporter
Provides an event handler that can be registered to report on Chef run data. Unlike the existing Chef::ResourceReporter event handler, the DataCollector handler is not tied to a Chef Server / Chef Reporting and exports its data through a webhook-like mechanism to a configured endpoint.
Instance Attribute Summary collapse
-
#all_resource_reports ⇒ Object
readonly
Returns the value of attribute all_resource_reports.
-
#current_resource_report ⇒ Object
readonly
Returns the value of attribute current_resource_report.
-
#deprecations ⇒ Object
readonly
Returns the value of attribute deprecations.
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#error_descriptions ⇒ Object
readonly
Returns the value of attribute error_descriptions.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#expanded_run_list ⇒ Object
readonly
Returns the value of attribute expanded_run_list.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#run_context ⇒ Object
readonly
Returns the value of attribute run_context.
-
#run_status ⇒ Object
readonly
Returns the value of attribute run_status.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#converge_complete ⇒ Object
see EventDispatch::Base#converge_complete At the end of the converge, we add any unprocessed resources to our report list.
-
#converge_failed(exception) ⇒ Object
see EventDispatch::Base#converge_failed At the end of the converge, we add any unprocessed resources to our report list.
-
#converge_start(run_context) ⇒ Object
see EventDispatch::Base#converge_start Upon receipt, we stash the run_context for use at the end of the run in order to determine what resource+action combinations have not yet fired so we can report on unprocessed resources.
-
#cookbook_resolution_failed(expanded_run_list, exception) ⇒ Object
see EventDispatch::Base#cookbook_resolution_failed The run error text is updated with the output of the appropriate formatter.
-
#cookbook_sync_failed(cookbooks, exception) ⇒ Object
see EventDispatch::Base#cookbook_sync_failed The run error text is updated with the output of the appropriate formatter.
-
#deprecation(message, location = ) ⇒ Object
see EventDispatch::Base#deprecation Append a received deprecation to the list of deprecations.
-
#initialize ⇒ Reporter
constructor
A new instance of Reporter.
-
#resource_completed(new_resource) ⇒ Object
see EventDispatch::Base#resource_completed Mark the ResourceReport instance as finished (for timing details).
-
#resource_current_state_loaded(new_resource, action, current_resource) ⇒ Object
see EventDispatch::Base#resource_current_state_loaded Create a new ResourceReport instance that we’ll use to track the state of this resource during the run.
-
#resource_failed(new_resource, action, exception) ⇒ Object
see EventDispatch::Base#resource_failed Flag the current ResourceReport as failed and supply the exception as long as it’s a top-level resource, and update the run error text with the proper Formatter.
-
#resource_skipped(new_resource, action, conditional) ⇒ Object
see EventDispatch::Base#resource_skipped If this is a top-level resource, we create a ResourceReport instance (because a skipped resource does not trigger the resource_current_state_loaded event), and flag it as skipped.
-
#resource_up_to_date(new_resource, action) ⇒ Object
see EventDispatch::Base#resource_up_to_date Mark our ResourceReport status accordingly.
-
#resource_updated(new_resource, action) ⇒ Object
see EventDispatch::Base#resource_updated Flag the current ResourceReport instance as updated (as long as it’s a top-level resource).
-
#run_completed(node) ⇒ Object
see EventDispatch::Base#run_completed Upon receipt, we will send our run completion message to the configured DataCollector endpoint.
-
#run_failed(exception) ⇒ Object
see EventDispatch::Base#run_failed.
-
#run_list_expand_failed(node, exception) ⇒ Object
see EventDispatch::Base#run_list_expand_failed The run error text is updated with the output of the appropriate formatter.
-
#run_list_expanded(run_list_expansion) ⇒ Object
see EventDispatch::Base#run_list_expanded The expanded run list is stored for later use by the run_completed event and message.
-
#run_started(current_run_status) ⇒ Object
see EventDispatch::Base#run_started Upon receipt, we will send our run start message to the configured DataCollector endpoint.
Methods inherited from EventDispatch::Base
#attribute_changed, #attribute_file_load_failed, #attribute_file_loaded, #attribute_load_complete, #attribute_load_start, #audit_phase_complete, #audit_phase_failed, #audit_phase_start, #control_example_failure, #control_example_success, #control_group_started, #cookbook_clean_complete, #cookbook_clean_start, #cookbook_gem_failed, #cookbook_gem_finished, #cookbook_gem_installing, #cookbook_gem_start, #cookbook_gem_using, #cookbook_resolution_complete, #cookbook_resolution_start, #cookbook_sync_complete, #cookbook_sync_start, #definition_file_load_failed, #definition_file_loaded, #definition_load_complete, #definition_load_start, #handler_executed, #handlers_completed, #handlers_start, #library_file_load_failed, #library_file_loaded, #library_load_complete, #library_load_start, #lwrp_file_load_failed, #lwrp_file_loaded, #lwrp_load_complete, #lwrp_load_start, #msg, #node_load_completed, #node_load_failed, #node_load_start, #ohai_completed, #ohai_plugin_file_load_failed, #ohai_plugin_file_loaded, #ohai_plugin_load_complete, #ohai_plugin_load_start, #policyfile_loaded, #provider_requirement_failed, #recipe_file_load_failed, #recipe_file_loaded, #recipe_load_complete, #recipe_load_start, #recipe_not_found, #registration_completed, #registration_failed, #registration_start, #removed_cookbook_file, #resource_action_start, #resource_bypassed, #resource_current_state_load_bypassed, #resource_failed_retriable, #resource_update_applied, #resource_update_progress, #run_start, #skipping_registration, #stream_closed, #stream_opened, #stream_output, #synchronized_cookbook, #updated_cookbook_file, #whyrun_assumption
Constructor Details
#initialize ⇒ Reporter
Returns a new instance of Reporter.
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/chef/data_collector.rb', line 105 def initialize validate_data_collector_server_url! @all_resource_reports = [] @current_resource_loaded = nil @error_descriptions = {} = {} @deprecations = Set.new @enabled = true @http = setup_http_client end |
Instance Attribute Details
#all_resource_reports ⇒ Object (readonly)
Returns the value of attribute all_resource_reports.
101 102 103 |
# File 'lib/chef/data_collector.rb', line 101 def all_resource_reports @all_resource_reports end |
#current_resource_report ⇒ Object (readonly)
Returns the value of attribute current_resource_report.
101 102 103 |
# File 'lib/chef/data_collector.rb', line 101 def current_resource_report @current_resource_report end |
#deprecations ⇒ Object (readonly)
Returns the value of attribute deprecations.
101 102 103 |
# File 'lib/chef/data_collector.rb', line 101 def deprecations @deprecations end |
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
101 102 103 |
# File 'lib/chef/data_collector.rb', line 101 def enabled @enabled end |
#error_descriptions ⇒ Object (readonly)
Returns the value of attribute error_descriptions.
101 102 103 |
# File 'lib/chef/data_collector.rb', line 101 def error_descriptions @error_descriptions end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
101 102 103 |
# File 'lib/chef/data_collector.rb', line 101 def exception @exception end |
#expanded_run_list ⇒ Object (readonly)
Returns the value of attribute expanded_run_list.
101 102 103 |
# File 'lib/chef/data_collector.rb', line 101 def end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
101 102 103 |
# File 'lib/chef/data_collector.rb', line 101 def http @http end |
#run_context ⇒ Object (readonly)
Returns the value of attribute run_context.
101 102 103 |
# File 'lib/chef/data_collector.rb', line 101 def run_context @run_context end |
#run_status ⇒ Object (readonly)
Returns the value of attribute run_status.
101 102 103 |
# File 'lib/chef/data_collector.rb', line 101 def run_status @run_status end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
101 102 103 |
# File 'lib/chef/data_collector.rb', line 101 def status @status end |
Instance Method Details
#converge_complete ⇒ Object
see EventDispatch::Base#converge_complete At the end of the converge, we add any unprocessed resources to our report list.
159 160 161 |
# File 'lib/chef/data_collector.rb', line 159 def converge_complete detect_unprocessed_resources end |
#converge_failed(exception) ⇒ Object
see EventDispatch::Base#converge_failed At the end of the converge, we add any unprocessed resources to our report list
166 167 168 |
# File 'lib/chef/data_collector.rb', line 166 def converge_failed(exception) detect_unprocessed_resources end |
#converge_start(run_context) ⇒ Object
see EventDispatch::Base#converge_start Upon receipt, we stash the run_context for use at the end of the run in order to determine what resource+action combinations have not yet fired so we can report on unprocessed resources.
152 153 154 |
# File 'lib/chef/data_collector.rb', line 152 def converge_start(run_context) @run_context = run_context end |
#cookbook_resolution_failed(expanded_run_list, exception) ⇒ Object
see EventDispatch::Base#cookbook_resolution_failed The run error text is updated with the output of the appropriate formatter.
255 256 257 258 259 260 261 262 |
# File 'lib/chef/data_collector.rb', line 255 def cookbook_resolution_failed(, exception) update_error_description( Formatters::ErrorMapper.cookbook_resolution_failed( , exception ).for_json ) end |
#cookbook_sync_failed(cookbooks, exception) ⇒ Object
see EventDispatch::Base#cookbook_sync_failed The run error text is updated with the output of the appropriate formatter.
267 268 269 270 271 272 273 274 |
# File 'lib/chef/data_collector.rb', line 267 def cookbook_sync_failed(cookbooks, exception) update_error_description( Formatters::ErrorMapper.cookbook_sync_failed( cookbooks, exception ).for_json ) end |
#deprecation(message, location = ) ⇒ Object
see EventDispatch::Base#deprecation Append a received deprecation to the list of deprecations
278 279 280 |
# File 'lib/chef/data_collector.rb', line 278 def deprecation(, location = caller(2..2)[0]) add_deprecation(., .url, location) end |
#resource_completed(new_resource) ⇒ Object
see EventDispatch::Base#resource_completed Mark the ResourceReport instance as finished (for timing details). This marks the end of this resource during this run.
225 226 227 228 229 230 231 |
# File 'lib/chef/data_collector.rb', line 225 def resource_completed(new_resource) if current_resource_report && !nested_resource?(new_resource) current_resource_report.finish add_resource_report(current_resource_report) clear_current_resource_report end end |
#resource_current_state_loaded(new_resource, action, current_resource) ⇒ Object
see EventDispatch::Base#resource_current_state_loaded Create a new ResourceReport instance that we’ll use to track the state of this resource during the run. Nested resources are ignored as they are assumed to be an inline resource of a custom resource, and we only care about tracking top-level resources.
175 176 177 178 |
# File 'lib/chef/data_collector.rb', line 175 def resource_current_state_loaded(new_resource, action, current_resource) return if nested_resource?(new_resource) initialize_resource_report_if_needed(new_resource, action, current_resource) end |
#resource_failed(new_resource, action, exception) ⇒ Object
see EventDispatch::Base#resource_failed Flag the current ResourceReport as failed and supply the exception as long as it’s a top-level resource, and update the run error text with the proper Formatter.
210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/chef/data_collector.rb', line 210 def resource_failed(new_resource, action, exception) initialize_resource_report_if_needed(new_resource, action) current_resource_report.failed(exception) unless nested_resource?(new_resource) update_error_description( Formatters::ErrorMapper.resource_failed( new_resource, action, exception ).for_json ) end |
#resource_skipped(new_resource, action, conditional) ⇒ Object
see EventDispatch::Base#resource_skipped If this is a top-level resource, we create a ResourceReport instance (because a skipped resource does not trigger the resource_current_state_loaded event), and flag it as skipped.
191 192 193 194 195 196 |
# File 'lib/chef/data_collector.rb', line 191 def resource_skipped(new_resource, action, conditional) return if nested_resource?(new_resource) initialize_resource_report_if_needed(new_resource, action) current_resource_report.skipped(conditional) end |
#resource_up_to_date(new_resource, action) ⇒ Object
see EventDispatch::Base#resource_up_to_date Mark our ResourceReport status accordingly
182 183 184 185 |
# File 'lib/chef/data_collector.rb', line 182 def resource_up_to_date(new_resource, action) initialize_resource_report_if_needed(new_resource, action) current_resource_report.up_to_date unless nested_resource?(new_resource) end |
#resource_updated(new_resource, action) ⇒ Object
see EventDispatch::Base#resource_updated Flag the current ResourceReport instance as updated (as long as it’s a top-level resource).
201 202 203 204 |
# File 'lib/chef/data_collector.rb', line 201 def resource_updated(new_resource, action) initialize_resource_report_if_needed(new_resource, action) current_resource_report.updated unless nested_resource?(new_resource) end |
#run_completed(node) ⇒ Object
see EventDispatch::Base#run_completed Upon receipt, we will send our run completion message to the configured DataCollector endpoint.
138 139 140 |
# File 'lib/chef/data_collector.rb', line 138 def run_completed(node) send_run_completion(status: "success") end |
#run_failed(exception) ⇒ Object
see EventDispatch::Base#run_failed
143 144 145 |
# File 'lib/chef/data_collector.rb', line 143 def run_failed(exception) send_run_completion(status: "failure") end |
#run_list_expand_failed(node, exception) ⇒ Object
see EventDispatch::Base#run_list_expand_failed The run error text is updated with the output of the appropriate formatter.
243 244 245 246 247 248 249 250 |
# File 'lib/chef/data_collector.rb', line 243 def (node, exception) update_error_description( Formatters::ErrorMapper.( node, exception ).for_json ) end |
#run_list_expanded(run_list_expansion) ⇒ Object
see EventDispatch::Base#run_list_expanded The expanded run list is stored for later use by the run_completed event and message.
236 237 238 |
# File 'lib/chef/data_collector.rb', line 236 def (run_list_expansion) = run_list_expansion end |
#run_started(current_run_status) ⇒ Object
see EventDispatch::Base#run_started Upon receipt, we will send our run start message to the configured DataCollector endpoint. Depending on whether the user has configured raise_on_failure, if we cannot send the message, we will either disable the DataCollector Reporter for the duration of this run, or we’ll raise an exception.
125 126 127 128 129 130 131 132 133 |
# File 'lib/chef/data_collector.rb', line 125 def run_started(current_run_status) update_run_status(current_run_status) disable_reporter_on_error do send_to_data_collector( Chef::DataCollector::Messages.(current_run_status) ) end end |