From c1be2132fc89b8193c6178d744d1afd6ffa04d84 Mon Sep 17 00:00:00 2001 From: Greg Swallow Date: Tue, 17 Oct 2017 11:10:01 -0400 Subject: [PATCH 1/2] Add couchbase recipe. --- .kitchen.yml | 12 ++++++ recipes/couchbase.rb | 23 ++++++++++ spec/integrations/couchbase_spec.rb | 42 +++++++++++++++++++ templates/default/couchbase.yaml.erb | 7 ++++ .../serverspec/couchbase_spec.rb | 30 +++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 recipes/couchbase.rb create mode 100644 spec/integrations/couchbase_spec.rb create mode 100644 templates/default/couchbase.yaml.erb create mode 100644 test/integration/datadog_couchbase/serverspec/couchbase_spec.rb diff --git a/.kitchen.yml b/.kitchen.yml index 12e4cf35..277a842d 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -153,6 +153,18 @@ suites: password: somepass process_name_regex: .*cassandra.* +- name: datadog_couchbase + run_list: + - recipe[datadog::couchbase] + attributes: + datadog: + <<: *DATADOG + couchbase: + instances: + - server: http://localhost:8091 + username: Administrator + password: default + - name: datadog_couchdb run_list: - recipe[datadog::couchdb] diff --git a/recipes/couchbase.rb b/recipes/couchbase.rb new file mode 100644 index 00000000..104e579d --- /dev/null +++ b/recipes/couchbase.rb @@ -0,0 +1,23 @@ +include_recipe 'datadog::dd-agent' + +# Monitor couchDB +# +# Assuming you have 2 instances on the same host +# you need to set up the following attributes. +# Each instance's metric will be tagged with "instance:server_url". +# to help you differentiate between instances. +# NOTE the "couch" instead of "couchdb" attribute. +# +# node['datadog']['couch']['instances'] = [ +# { +# server: 'http://localhost:1234' +# }, +# { +# server: 'http://localhost:4567' +# } +# ] + +datadog_monitor 'couchbase' do + init_config nil + instances node['datadog']['couchbase']['instances'] +end diff --git a/spec/integrations/couchbase_spec.rb b/spec/integrations/couchbase_spec.rb new file mode 100644 index 00000000..0e40e313 --- /dev/null +++ b/spec/integrations/couchbase_spec.rb @@ -0,0 +1,42 @@ +describe 'datadog::couchbase' do + expected_yaml = <<-EOF + init_config: + + instances: + - server: http://localhost:8091 + user: Administrator + password: default + EOF + + cached(:chef_run) do + ChefSpec::SoloRunner.new(step_into: ['datadog_monitor']) do |node| + node.automatic['languages'] = { 'python' => { 'version' => '2.7.2' } } + node.set['datadog'] = { + api_key: 'someapikey', + couchbase: { + instances: [ + { + server: 'http://localhost:8091' + username: 'Administrator', + password: 'default' + } + ] + } + } + end.converge(described_recipe) + end + + subject { chef_run } + + it_behaves_like 'datadog-agent' + + it { is_expected.to include_recipe('datadog::dd-agent') } + + it { is_expected.to add_datadog_monitor('couchbase') } + + it 'renders expected YAML config file' do + expect(chef_run).to(render_file('/etc/dd-agent/conf.d/couchbase.yaml').with_content { |content| + expect(YAML.safe_load(content).to_json).to be_json_eql(YAML.safe_load(expected_yaml).to_json) + }) + end +end diff --git a/templates/default/couchbase.yaml.erb b/templates/default/couchbase.yaml.erb new file mode 100644 index 00000000..9d381159 --- /dev/null +++ b/templates/default/couchbase.yaml.erb @@ -0,0 +1,7 @@ +instances: +<% @instances.each do |i| -%> + - server: <%= i['server'] %> + user: <%= @node.fetch('couchbase', {}).fetch('server', {}).fetch('username', i.fetch('username', 'Administrator')) %> + password: <%= @node.fetch('couchbase', {}).fetch('server', {}).fetch('password', i.fetch('password', '')) %> +<% end %> +init_config: diff --git a/test/integration/datadog_couchbase/serverspec/couchbase_spec.rb b/test/integration/datadog_couchbase/serverspec/couchbase_spec.rb new file mode 100644 index 00000000..be365528 --- /dev/null +++ b/test/integration/datadog_couchbase/serverspec/couchbase_spec.rb @@ -0,0 +1,30 @@ +# Encoding: utf-8 + +require 'spec_helper' + +AGENT_CONFIG = File.join(@agent_config_dir, 'conf.d/couchbase.yaml') + +describe service(@agent_service_name) do + it { should be_running } +end + +describe file(AGENT_CONFIG) do + it { should be_a_file } + + it 'is valid yaml matching input values' do + generated = YAML.load_file(AGENT_CONFIG) + + expected = { + 'instances' => [ + { + 'server' => 'http://localhost:8091', + 'user' => 'Administrator', + 'password' => 'default' + } + ], + 'init_config' => nil + } + + expect(generated.to_json).to be_json_eql expected.to_json + end +end From 9e7730b0d26229ac94c17066e44590188b2f452d Mon Sep 17 00:00:00 2001 From: Olivier Vielpeau Date: Thu, 30 Nov 2017 12:16:46 +0100 Subject: [PATCH 2/2] Minor changes * remove integration test * update comments * fix CI --- .kitchen.yml | 12 -------- recipes/couchbase.rb | 20 ++++++------- spec/integrations/couchbase_spec.rb | 2 +- .../serverspec/couchbase_spec.rb | 30 ------------------- 4 files changed, 10 insertions(+), 54 deletions(-) delete mode 100644 test/integration/datadog_couchbase/serverspec/couchbase_spec.rb diff --git a/.kitchen.yml b/.kitchen.yml index 277a842d..12e4cf35 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -153,18 +153,6 @@ suites: password: somepass process_name_regex: .*cassandra.* -- name: datadog_couchbase - run_list: - - recipe[datadog::couchbase] - attributes: - datadog: - <<: *DATADOG - couchbase: - instances: - - server: http://localhost:8091 - username: Administrator - password: default - - name: datadog_couchdb run_list: - recipe[datadog::couchdb] diff --git a/recipes/couchbase.rb b/recipes/couchbase.rb index 104e579d..37fad393 100644 --- a/recipes/couchbase.rb +++ b/recipes/couchbase.rb @@ -1,23 +1,21 @@ include_recipe 'datadog::dd-agent' -# Monitor couchDB +# Monitor couchbase # # Assuming you have 2 instances on the same host # you need to set up the following attributes. # Each instance's metric will be tagged with "instance:server_url". # to help you differentiate between instances. -# NOTE the "couch" instead of "couchdb" attribute. # -# node['datadog']['couch']['instances'] = [ -# { -# server: 'http://localhost:1234' -# }, -# { -# server: 'http://localhost:4567' -# } -# ] +# node['datadog']['couchbase']['instances'] = [ +# { +# server: 'http://localhost:1234' +# }, +# { +# server: 'http://localhost:4567' +# } +# ] datadog_monitor 'couchbase' do - init_config nil instances node['datadog']['couchbase']['instances'] end diff --git a/spec/integrations/couchbase_spec.rb b/spec/integrations/couchbase_spec.rb index 0e40e313..abbfe194 100644 --- a/spec/integrations/couchbase_spec.rb +++ b/spec/integrations/couchbase_spec.rb @@ -16,7 +16,7 @@ couchbase: { instances: [ { - server: 'http://localhost:8091' + server: 'http://localhost:8091', username: 'Administrator', password: 'default' } diff --git a/test/integration/datadog_couchbase/serverspec/couchbase_spec.rb b/test/integration/datadog_couchbase/serverspec/couchbase_spec.rb deleted file mode 100644 index be365528..00000000 --- a/test/integration/datadog_couchbase/serverspec/couchbase_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -# Encoding: utf-8 - -require 'spec_helper' - -AGENT_CONFIG = File.join(@agent_config_dir, 'conf.d/couchbase.yaml') - -describe service(@agent_service_name) do - it { should be_running } -end - -describe file(AGENT_CONFIG) do - it { should be_a_file } - - it 'is valid yaml matching input values' do - generated = YAML.load_file(AGENT_CONFIG) - - expected = { - 'instances' => [ - { - 'server' => 'http://localhost:8091', - 'user' => 'Administrator', - 'password' => 'default' - } - ], - 'init_config' => nil - } - - expect(generated.to_json).to be_json_eql expected.to_json - end -end