Class: Chef::DataCollector::Reporter

Inherits:
EventDispatch::Base show all
Includes:
ErrorHandlers
Defined in:
lib/chef/data_collector.rb

Overview

The DataCollector is mode-agnostic reporting tool which can be used with server-based and solo-based clients. It can report to a file, to an authenticated Chef Automate reporting endpoint, or to a user-supplied webhook. It sends two messages: one at the start of the run and one at the end of the run. Most early failures in the actual Chef::Client itself are reported, but parsing of the client.rb must have succeeded and some code in Chef::Application could throw so early as to prevent reporting. If exceptions are thrown both run-start and run-end messages are still sent in pairs.

Instance Attribute Summary collapse

Attributes included from ErrorHandlers

#node_name

Instance Method Summary collapse

Methods included from ErrorHandlers

#cookbook_resolution_failed, #cookbook_sync_failed, #error_description, #file_load_failed, #node_load_failed, #recipe_not_found, #registration_failed, #resource_failed, #run_list_expand_failed

Methods inherited from EventDispatch::Base

#attribute_changed, #attribute_file_load_failed, #attribute_file_loaded, #attribute_load_complete, #attribute_load_start, #converge_complete, #converge_failed, #converge_start, #cookbook_clean_complete, #cookbook_clean_start, #cookbook_compilation_complete, #cookbook_compilation_start, #cookbook_gem_failed, #cookbook_gem_finished, #cookbook_gem_installing, #cookbook_gem_start, #cookbook_gem_using, #cookbook_resolution_complete, #cookbook_resolution_failed, #cookbook_resolution_start, #cookbook_sync_complete, #cookbook_sync_failed, #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_after_state_loaded, #resource_bypassed, #resource_completed, #resource_current_state_load_bypassed, #resource_current_state_loaded, #resource_failed, #resource_failed_retriable, #resource_skipped, #resource_up_to_date, #resource_update_applied, #resource_update_progress, #resource_updated, #run_list_expand_failed, #skipping_registration, #stream_closed, #stream_opened, #stream_output, #synchronized_cookbook, #updated_cookbook_file, #whyrun_assumption

Constructor Details

#initialize(events) ⇒ Reporter

Returns a new instance of Reporter.

Parameters:


65
66
67
68
69
# File 'lib/chef/data_collector.rb', line 65

def initialize(events)
  @events = events
  @expanded_run_list = {}
  @deprecations = Set.new
end

Instance Attribute Details

#action_collectionChef::ActionCollection (readonly)

Returns the action collection object.

Returns:


59
60
61
# File 'lib/chef/data_collector.rb', line 59

def action_collection
  @action_collection
end

#deprecationsSet<Hash> (readonly)

Returns the accumulated list of deprecation warnings.

Returns:

  • (Set<Hash>)

    the accumulated list of deprecation warnings


56
57
58
# File 'lib/chef/data_collector.rb', line 56

def deprecations
  @deprecations
end

#eventsChef::EventDispatch::Dispatcher (readonly)

Returns the event dispatcher.

Returns:


62
63
64
# File 'lib/chef/data_collector.rb', line 62

def events
  @events
end

#expanded_run_listChef::RunList::RunListExpansion (readonly)

Returns the expanded run list.

Returns:


47
48
49
# File 'lib/chef/data_collector.rb', line 47

def expanded_run_list
  @expanded_run_list
end

#nodeChef::Node (readonly)

Returns the chef node.

Returns:


53
54
55
# File 'lib/chef/data_collector.rb', line 53

def node
  @node
end

#run_statusChef::RunStatus (readonly)

Returns the run status.

Returns:


50
51
52
# File 'lib/chef/data_collector.rb', line 50

def run_status
  @run_status
end

Instance Method Details

#action_collection_registration(action_collection) ⇒ Object

Hook event to register with the action_collection if we are still enabled.

This is also how we wire up to the action_collection since it passes itself as the argument.

(see EventDispatch::Base#action_collection_registration)


105
106
107
# File 'lib/chef/data_collector.rb', line 105

def action_collection_registration(action_collection)
  @action_collection = action_collection
end

#deprecation(message, location = caller(2..2)[0]) ⇒ Object

Hook event to accumulating deprecation messages

(see EventDispatch::Base#deprecation)


127
128
129
# File 'lib/chef/data_collector.rb', line 127

def deprecation(message, location = caller(2..2)[0])
  @deprecations << { message: message.message, url: message.url, location: message.location }
end

#node_load_success(node) ⇒ Object

Hook to grab the node object after it has been successfully loaded

(see EventDispatch::Base#node_load_success)


86
87
88
# File 'lib/chef/data_collector.rb', line 86

def node_load_success(node)
  @node = node
end

#run_completed(node) ⇒ Object

Hook to send the run completion message with a status of success

(see EventDispatch::Base#run_completed)


135
136
137
# File 'lib/chef/data_collector.rb', line 135

def run_completed(node)
  send_run_completion("success")
end

#run_failed(exception) ⇒ Object

Hook to send the run completion message with a status of failed

(see EventDispatch::Base#run_failed)


143
144
145
# File 'lib/chef/data_collector.rb', line 143

def run_failed(exception)
  send_run_completion("failure")
end

#run_list_expanded(run_list_expansion) ⇒ Object

The expanded run list is stored for later use by the run_completed event and message.

(see EventDispatch::Base#run_list_expanded)


95
96
97
# File 'lib/chef/data_collector.rb', line 95

def run_list_expanded(run_list_expansion)
  @expanded_run_list = run_list_expansion
end

#run_start(chef_version, run_status) ⇒ Object

Hook to grab the run_status. We also make the decision to run or not run here (our config has been parsed so we should know if we need to run, we unregister if we do not want to run).

(see EventDispatch::Base#run_start)


77
78
79
80
# File 'lib/chef/data_collector.rb', line 77

def run_start(chef_version, run_status)
  events.unregister(self) unless Chef::DataCollector::ConfigValidation.should_be_enabled?
  @run_status = run_status
end

#run_started(run_status) ⇒ Object

  • Creates and writes our NodeUUID back to the node object
  • Sanity checks the data collector
  • Sends the run start message
  • If the run_start message fails, this may disable the rest of data collection or fail hard

(see EventDispatch::Base#run_started)


116
117
118
119
120
121
# File 'lib/chef/data_collector.rb', line 116

def run_started(run_status)
  Chef::DataCollector::ConfigValidation.validate_server_url!
  Chef::DataCollector::ConfigValidation.validate_output_locations!

  send_run_start
end