Skip to content

Commit

Permalink
Merge pull request #397 from DataDog/quentin/tags-blacklist-regex
Browse files Browse the repository at this point in the history
[handler] tags blacklist regex feature
  • Loading branch information
olivielpeau authored Jan 23, 2017
2 parents 2a7e914 + 465e2bb commit 00961b5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
7 changes: 7 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
# Collect EC2 tags, set to 'yes' to collect
default['datadog']['collect_ec2_tags'] = nil

# Set this regex to exclude some Chef node tags from the host tags that the datadog handler sends to Datadog
# https://github.com/DataDog/chef-handler-datadog/issues/85
# This means that all the metrics and service checks coming from the
# host/Agent would also stop being tagged with these excluded tags.
# EX: 'app_.*' allows all tags except those which look like app_.*
default['datadog']['tags_blacklist_regex'] = nil

# Autorestart agent
default['datadog']['autorestart'] = false

Expand Down
3 changes: 2 additions & 1 deletion recipes/dd-handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
:use_ec2_instance_id => node['datadog']['use_ec2_instance_id'],
:tag_prefix => node['datadog']['tag_prefix'],
:url => node['datadog']['url'],
:extra_endpoints => extra_endpoints
:extra_endpoints => extra_endpoints,
:tags_blacklist_regex => node['datadog']['tags_blacklist_regex']
}

unless node['datadog']['use_ec2_instance_id']
Expand Down
26 changes: 23 additions & 3 deletions spec/dd-handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
end
end

shared_examples 'a chef-handler-datadog runner' do |extra_endpoints|
shared_examples 'a chef-handler-datadog runner' do |extra_endpoints, tags_blacklist_regex|
it 'runs the handler' do
handler_config = {
api_key: 'somethingnotnil',
application_key: 'somethingnotnil2',
use_ec2_instance_id: true,
tag_prefix: 'tag:',
url: 'https://app.datadoghq.com',
extra_endpoints: extra_endpoints || []
extra_endpoints: extra_endpoints || [],
tags_blacklist_regex: tags_blacklist_regex
}

expect(chef_run).to enable_chef_handler('Chef::Handler::Datadog').with(
Expand Down Expand Up @@ -90,7 +91,7 @@

it_behaves_like 'a chef-handler-datadog installer'

it_behaves_like 'a chef-handler-datadog runner', extra_endpoints
it_behaves_like 'a chef-handler-datadog runner', extra_endpoints, nil
end
context 'multiple endpoints disabled' do
cached(:chef_run) do
Expand All @@ -112,4 +113,23 @@

it_behaves_like 'a chef-handler-datadog runner'
end

context 'tags_blacklist_regex set' do
cached(:chef_run) do
ChefSpec::SoloRunner.new(
platform: 'ubuntu',
version: '14.04'
) do |node|
node.set['datadog']['api_key'] = 'somethingnotnil'
node.set['datadog']['application_key'] = 'somethingnotnil2'
node.set['datadog']['chef_handler_enable'] = true
node.set['datadog']['use_ec2_instance_id'] = true
node.set['datadog']['tags_blacklist_regex'] = 'tags.*'
end.converge described_recipe
end

it_behaves_like 'a chef-handler-datadog installer'

it_behaves_like 'a chef-handler-datadog runner', nil, 'tags.*'
end
end

0 comments on commit 00961b5

Please sign in to comment.