Skip to content

Commit

Permalink
handle case of empty tag; update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flyinprogrammer committed Dec 16, 2017
1 parent e7a8125 commit e9b39c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions spec/classes/datadog_agent_integrations_docker_daemon_spec.rb
Expand Up @@ -47,7 +47,7 @@
let(:params) {{
tags: %w{ foo bar baz },
}}
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) }
it { should contain_file(conf_file).with_content(%r{tags: \["foo", "bar", "baz"\]}) }
end

context 'with tags parameter with an empty tag' do
Expand All @@ -59,23 +59,23 @@
tags: [ 'foo', '', 'baz' ]
}}

it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- baz\s*?[^-]/m) }
it { should contain_file(conf_file).with_content(%r{tags: \["foo", "baz"\]}) }
end

context 'single element array of an empty string' do
let(:params) {{
tags: [''],
}}

skip("undefined behavior")
it { should contain_file(conf_file).with_content(%r{tags: \[\]}) }
end

context 'single value empty string' do
let(:params) {{
tags: '',
}}

skip("doubly undefined behavior")
it { should contain_file(conf_file).with_content(%r{tags: \[\]}) }
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions templates/agent-conf.d/docker_daemon.yaml.erb
Expand Up @@ -75,15 +75,15 @@ instances:
#
# Default: include all containers

exclude: [<%= @exclude && !@exclude.empty? ? '"' + @exclude.join('", "') + '"' : nil %>]
include: [<%= @include && !@include.empty? ? '"' + @include.join('", "') + '"' : nil %>]
exclude: [<%= @exclude && !@exclude.empty? ? '"' + @exclude.reject(&:empty?).join('", "') + '"' : nil %>]
include: [<%= @include && !@include.empty? ? '"' + @include.reject(&:empty?).join('", "') + '"' : nil %>]

## Tagging
##
# You can add extra tags to your Docker metrics with the tags list option.
# Example: ["extra_tag", "env:testing"]
#
tags: [<%= @tags && !@tags.empty? ? '"' + @tags.join('", "') + '"' : nil %>]
tags: [<%= @tags && !@tags.empty? ? '"' + @tags.reject(&:empty?).join('", "') + '"' : nil %>]

# If the agent is running in an Amazon ECS task, tags container metrics with the ECS task name and version.
# Default: true
Expand All @@ -102,14 +102,14 @@ instances:
# - container_name: Name of the container (example: "boring_euclid")
# - container_command: Command ran by the container (example: "echo 1")
#
performance_tags: [<%= @performance_tags && !@performance_tags.empty? ? '"' + @performance_tags.join('", "') + '"' : nil %>]
performance_tags: [<%= @performance_tags && !@performance_tags.empty? ? '"' + @performance_tags.reject(&:empty?).join('", "') + '"' : nil %>]

# Tags for containers count metrics.
# Available: ["image_name", "image_tag", "docker_image", "container_command"]
#
container_tags: [<%= @container_tags && !@container_tags.empty? ? '"' + @container_tags.join('", "') + '"' : nil %>]
container_tags: [<%= @container_tags && !@container_tags.empty? ? '"' + @container_tags.reject(&:empty?).join('", "') + '"' : nil %>]

# List of container label names that should be collected and sent as tags.
# Default to None
# Example:
collect_labels_as_tags: [<%= @collect_labels_as_tags && !@collect_labels_as_tags.empty? ? '"' + @collect_labels_as_tags.join('", "') + '"' : nil %>]
collect_labels_as_tags: [<%= @collect_labels_as_tags && !@collect_labels_as_tags.empty? ? '"' + @collect_labels_as_tags.reject(&:empty?).join('", "') + '"' : nil %>]

0 comments on commit e9b39c8

Please sign in to comment.