Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #249 from kurochan/docker-daemon
[docker-daemon] Add recipe and tests
- Loading branch information
Showing
3 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
include_recipe 'datadog::dd-agent' | ||
|
||
# Build a data structure with configuration. | ||
# @see https://www.datadoghq.com/2014/06/monitor-docker-datadog/ | ||
# @example | ||
# node.override['datadog']['docker_daemon']['init_config'] = [ | ||
# { | ||
# docker_root: '/', | ||
# socket_timeout: 10, | ||
# tls: false, | ||
# tls_client_cert: '/path/to/client-cert.pem', | ||
# tls_client_key: '/path/to/client-key.pem', | ||
# tls_cacert: '/path/to/ca.pem', | ||
# tls_verify: true | ||
# } | ||
# ] | ||
# node.override['datadog']['docker_daemon']['instances'] = [ | ||
# { | ||
# url: 'unix://var/run/docker.sock', | ||
# tags: [ | ||
# 'toto', | ||
# 'tata' | ||
# ], | ||
# include: [ | ||
# 'docker_image:ubuntu', | ||
# 'docker_image:debian' | ||
# ], | ||
# exclude: [ | ||
# '.*' | ||
# ], | ||
# performance_tags: [ | ||
# 'container_name', | ||
# 'image_name', | ||
# 'image_tag', | ||
# 'docker_image' | ||
# ], | ||
# container_tags: [ | ||
# 'image_name', | ||
# 'image_tag', | ||
# 'docker_image' | ||
# ], | ||
# collect_labels_as_tags: [ | ||
# 'com.docker.compose.service', | ||
# 'com.docker.compose.project' | ||
# ], | ||
# ecs_tags: true, | ||
# collect_events: true, | ||
# collect_container_size: false, | ||
# collect_image_size: false, | ||
# collect_images_stats: false | ||
# } | ||
# ] | ||
|
||
datadog_monitor 'docker_daemon' do | ||
init_config node['datadog']['docker_daemon']['init_config'] | ||
instances node['datadog']['docker_daemon']['instances'] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
describe 'datadog::docker_daemon' do | ||
expected_yaml = <<-EOF | ||
init_config: | ||
docker_root: / | ||
timeout: 10 | ||
tls: false | ||
tls_client_cert: /path/to/client-cert.pem | ||
tls_client_key: /path/to/client-key.pem | ||
tls_cacert: /path/to/ca.pem | ||
tls_verify: true | ||
instances: | ||
- url: unix://var/run/docker.sock | ||
tags: | ||
- toto | ||
- tata | ||
include: | ||
- docker_image:ubuntu | ||
- docker_image:debian | ||
exclude: | ||
- .* | ||
performance_tags: | ||
- container_name | ||
- image_name | ||
- image_tag | ||
- docker_image | ||
container_tags: | ||
- image_name | ||
- image_tag | ||
- docker_image | ||
collect_labels_as_tags: | ||
- com.docker.compose.service | ||
- com.docker.compose.project | ||
ecs_tags: true | ||
collect_events: true | ||
collect_container_size: false | ||
collect_image_size: false | ||
collect_images_stats: false | ||
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', | ||
'docker_daemon' => { | ||
init_config: { | ||
docker_root: '/', | ||
timeout: 10, | ||
tls: false, | ||
tls_client_cert: '/path/to/client-cert.pem', | ||
tls_client_key: '/path/to/client-key.pem', | ||
tls_cacert: '/path/to/ca.pem', | ||
tls_verify: true | ||
}, | ||
instances: [ | ||
{ | ||
url: 'unix://var/run/docker.sock', | ||
tags: [ | ||
'toto', | ||
'tata' | ||
], | ||
include: [ | ||
'docker_image:ubuntu', | ||
'docker_image:debian' | ||
], | ||
exclude: [ | ||
'.*' | ||
], | ||
performance_tags: [ | ||
'container_name', | ||
'image_name', | ||
'image_tag', | ||
'docker_image' | ||
], | ||
container_tags: [ | ||
'image_name', | ||
'image_tag', | ||
'docker_image' | ||
], | ||
collect_labels_as_tags: [ | ||
'com.docker.compose.service', | ||
'com.docker.compose.project' | ||
], | ||
ecs_tags: true, | ||
collect_events: true, | ||
collect_container_size: false, | ||
collect_image_size: false, | ||
collect_images_stats: false | ||
} | ||
] | ||
} | ||
} | ||
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('docker_daemon') } | ||
|
||
it 'renders expected YAML config file' do | ||
expect(chef_run).to render_file('/etc/dd-agent/conf.d/docker_daemon.yaml').with_content { |content| | ||
expect(YAML.load(content).to_json).to be_json_eql(YAML.load(expected_yaml).to_json) | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Generated by Chef, local modifications will be overwritten | ||
|
||
<%= JSON.parse(({ 'init_config' => @init_config, 'instances' => @instances}).to_json).to_yaml %> |