Skip to content

Commit

Permalink
Merge pull request #249 from kurochan/docker-daemon
Browse files Browse the repository at this point in the history
[docker-daemon] Add recipe and tests
  • Loading branch information
miketheman committed Oct 27, 2015
2 parents 2110418 + 07ade25 commit 10a9bfc
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 0 deletions.
57 changes: 57 additions & 0 deletions recipes/docker_daemon.rb
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
110 changes: 110 additions & 0 deletions spec/integrations/docker_daemon_spec.rb
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
3 changes: 3 additions & 0 deletions templates/default/docker_daemon.yaml.erb
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 %>

0 comments on commit 10a9bfc

Please sign in to comment.