diff options
author | danielsdeleo <dan@chef.io> | 2016-10-24 18:13:24 -0700 |
---|---|---|
committer | danielsdeleo <dan@chef.io> | 2016-11-02 08:06:38 -0700 |
commit | bc596e0e0e3302dd013565943b1aa91f17fffc8f (patch) | |
tree | 25671021adf88f092c25c7f588dd824573219d79 | |
parent | b95fce9f28693aa09dd0d37742063027596f6847 (diff) | |
download | chef-bc596e0e0e3302dd013565943b1aa91f17fffc8f.tar.gz |
Enable the data collector automatically
Signed-off-by: Daniel DeLeo <dan@chef.io>
-rw-r--r-- | chef-config/lib/chef-config/config.rb | 2 | ||||
-rw-r--r-- | chef-config/spec/unit/config_spec.rb | 14 | ||||
-rw-r--r-- | lib/chef/data_collector.rb | 7 | ||||
-rw-r--r-- | spec/support/shared/context/client.rb | 15 | ||||
-rw-r--r-- | spec/unit/data_collector_spec.rb | 4 |
5 files changed, 35 insertions, 7 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index 2fe59c8350..df14c81bc3 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -857,7 +857,7 @@ module ChefConfig # Full URL to the endpoint that will receive our data. If nil, the # data collector will not run. # Ex: http://my-data-collector.mycompany.com/ingest - default :server_url, nil + default(:server_url) { File.join(config_parent.chef_server_url, "/data_collector") } # An optional pre-shared token to pass as an HTTP header (x-data-collector-token) # that can be used to determine whether or not the poster of this diff --git a/chef-config/spec/unit/config_spec.rb b/chef-config/spec/unit/config_spec.rb index 2cdf9af78f..e15a5a6023 100644 --- a/chef-config/spec/unit/config_spec.rb +++ b/chef-config/spec/unit/config_spec.rb @@ -1127,4 +1127,18 @@ RSpec.describe ChefConfig::Config do end + describe "data collector URL" do + + context "when using default settings" do + + it "configures the data collector URL as a relative path to the Chef Server URL" do + ChefConfig::Config[:chef_server_url] = "https://chef.example/organizations/myorg" + expect(ChefConfig::Config[:data_collector][:server_url]).to eq("https://chef.example/organizations/myorg/data_collector") + + end + + end + + end + end diff --git a/lib/chef/data_collector.rb b/lib/chef/data_collector.rb index f07f81c846..5d947d0ee8 100644 --- a/lib/chef/data_collector.rb +++ b/lib/chef/data_collector.rb @@ -32,6 +32,9 @@ class Chef # == Chef::DataCollector # Provides methods for determinine whether a reporter should be registered. class DataCollector + + # TODO: this probably should be false if running chef-solo and the user has + # not set a server_url, but maybe it will behave ok with the default? def self.register_reporter? Chef::Config[:data_collector][:server_url] && !Chef::Config[:why_run] && @@ -271,7 +274,9 @@ class Chef Chef::Log.error(msg) raise else - Chef::Log.warn(msg) + # Make the message non-scary for folks who don't have automate: + msg << " (This is normal if you do not have Chef Automate)" + Chef::Log.info(msg) end end diff --git a/spec/support/shared/context/client.rb b/spec/support/shared/context/client.rb index b0530ab497..295bd6ce5f 100644 --- a/spec/support/shared/context/client.rb +++ b/spec/support/shared/context/client.rb @@ -68,9 +68,10 @@ shared_context "a client run" do let(:api_client_exists?) { false } let(:enable_fork) { false } - let(:http_cookbook_sync) { double("Chef::ServerAPI (cookbook sync)") } - let(:http_node_load) { double("Chef::ServerAPI (node)") } - let(:http_node_save) { double("Chef::ServerAPI (node save)") } + let(:http_data_collector) { double("Chef::ServerAPI (data collector)") } + let(:http_cookbook_sync) { double("Chef::ServerAPI (cookbook sync)") } + let(:http_node_load) { double("Chef::ServerAPI (node)") } + let(:http_node_save) { double("Chef::ServerAPI (node save)") } let(:reporting_rest_client) { double("Chef::ServerAPI (reporting client)") } let(:runner) { instance_double("Chef::Runner") } @@ -92,6 +93,13 @@ shared_context "a client run" do end end + def stub_for_data_collector_init + expect(Chef::ServerAPI).to receive(:new). + with(Chef::Config[:data_collector][:server_url]). + exactly(:once). + and_return(http_data_collector) + end + def stub_for_node_load # Client.register will then turn around create another # Chef::ServerAPI object, this time with the client key it got from the @@ -154,6 +162,7 @@ shared_context "a client run" do stub_rest_clean stub_for_register + stub_for_data_collector_init stub_for_node_load stub_for_sync_cookbooks stub_for_converge diff --git a/spec/unit/data_collector_spec.rb b/spec/unit/data_collector_spec.rb index 25de91864a..3d79c386fe 100644 --- a/spec/unit/data_collector_spec.rb +++ b/spec/unit/data_collector_spec.rb @@ -557,9 +557,9 @@ describe Chef::DataCollector::Reporter do end context "when raise-on-failure is disabled" do - it "logs a warning and does not raise an exception" do + it "logs an info message and does not raise an exception" do Chef::Config[:data_collector][:raise_on_failure] = false - expect(Chef::Log).to receive(:warn) + expect(Chef::Log).to receive(:info) expect { reporter.send(:disable_reporter_on_error) { raise exception_class.new("bummer") } }.not_to raise_error end end |