summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Leff <adam@leff.co>2016-10-28 15:43:34 -0700
committerAdam Leff <adam@leff.co>2016-10-28 21:13:36 -0700
commit3a4442b96ba2005a9616e0f3137f651580a06ee7 (patch)
tree54cf6b7960e61a38b9e3d169dc0b00461135cd79
parentaa9bbabde662a58c581ed4d87707eac5534bc292 (diff)
downloadchef-adamleff/deprecations-to-data-collector.tar.gz
Add deprecations to Data Collector competion messageadamleff/deprecations-to-data-collector
By adding deprecation warnings to Data Collector, receivers of Data Collector messages can easily identify nodes that would need attention to their versions/cookbooks before a major version Chef upgrade would be successful. Signed-off-by: Adam Leff <adam@leff.co>
-rw-r--r--lib/chef/data_collector.rb17
-rw-r--r--lib/chef/data_collector/messages.rb3
-rw-r--r--spec/unit/data_collector/messages_spec.rb2
3 files changed, 19 insertions, 3 deletions
diff --git a/lib/chef/data_collector.rb b/lib/chef/data_collector.rb
index dbb0b3771a..2aad0d74b0 100644
--- a/lib/chef/data_collector.rb
+++ b/lib/chef/data_collector.rb
@@ -23,6 +23,7 @@ require "chef/event_dispatch/base"
require "chef/data_collector/messages"
require "chef/data_collector/resource_report"
require "ostruct"
+require "set"
class Chef
@@ -54,7 +55,7 @@ class Chef
class Reporter < EventDispatch::Base
attr_reader :all_resource_reports, :status, :exception, :error_descriptions,
:expanded_run_list, :run_context, :run_status, :http,
- :current_resource_report, :enabled
+ :current_resource_report, :enabled, :deprecations
def initialize
validate_data_collector_server_url!
@@ -63,6 +64,7 @@ class Chef
@current_resource_loaded = nil
@error_descriptions = {}
@expanded_run_list = {}
+ @deprecations = Set.new
@http = Chef::HTTP.new(data_collector_server_url)
@enabled = true
end
@@ -223,6 +225,12 @@ class Chef
)
end
+ # see EventDispatch::Base#deprecation
+ # Append a received deprecation to the list of deprecations
+ def deprecation(message, location = caller(2..2)[0])
+ add_deprecation(message, location)
+ end
+
private
#
@@ -288,7 +296,8 @@ class Chef
expanded_run_list: expanded_run_list,
resources: all_resource_reports,
status: opts[:status],
- error_descriptions: error_descriptions
+ error_descriptions: error_descriptions,
+ deprecations: deprecations.to_a
).to_json
)
end
@@ -340,6 +349,10 @@ class Chef
@error_descriptions = discription_hash
end
+ def add_deprecation(message, location)
+ @deprecations << { message: message, location: location }
+ end
+
def create_resource_report(new_resource, action, current_resource = nil)
Chef::DataCollector::ResourceReport.new(
new_resource,
diff --git a/lib/chef/data_collector/messages.rb b/lib/chef/data_collector/messages.rb
index 8c2a84b580..e0dfd6cb67 100644
--- a/lib/chef/data_collector/messages.rb
+++ b/lib/chef/data_collector/messages.rb
@@ -66,7 +66,7 @@ class Chef
"entity_uuid" => node_uuid,
"expanded_run_list" => reporter_data[:expanded_run_list],
"id" => run_status.run_id,
- "message_version" => "1.0.0",
+ "message_version" => "1.1.0",
"message_type" => "run_converge",
"node" => run_status.node,
"node_name" => run_status.node.name,
@@ -80,6 +80,7 @@ class Chef
"status" => reporter_data[:status],
"total_resource_count" => reporter_data[:resources].count,
"updated_resource_count" => reporter_data[:resources].select { |r| r.report_data["status"] == "updated" }.count,
+ "deprecations" => reporter_data[:deprecations],
}
message["error"] = {
diff --git a/spec/unit/data_collector/messages_spec.rb b/spec/unit/data_collector/messages_spec.rb
index 394f18dce0..5c6ec8736c 100644
--- a/spec/unit/data_collector/messages_spec.rb
+++ b/spec/unit/data_collector/messages_spec.rb
@@ -113,6 +113,7 @@ describe Chef::DataCollector::Messages do
status
total_resource_count
updated_resource_count
+ deprecations
}
end
let(:optional_fields) { %w{error} }
@@ -164,6 +165,7 @@ describe Chef::DataCollector::Messages do
status
total_resource_count
updated_resource_count
+ deprecations
}
end
let(:optional_fields) { [] }