Skip to content

Commit 7131ffe

Browse files
authored
[service discovery] Allow Service Discovery configuration (DataDog#281)
* Allow Service Discovery configuration * [service_discovery] fixing typo. * [service_discovery] add spec tests.
1 parent 1412666 commit 7131ffe

3 files changed

Lines changed: 104 additions & 1 deletion

File tree

manifests/init.pp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@
230230
$pup_log_file = '',
231231
$syslog_host = '',
232232
$syslog_port = '',
233+
$service_discovery_backend = '',
234+
$sd_config_backend = '',
235+
$sd_backend_host = '',
236+
$sd_backend_port = 0,
237+
$sd_template_dir = '',
238+
$consul_token = '',
233239
$conf_dir = $datadog_agent::params::conf_dir,
234240
$service_name = $datadog_agent::params::service_name,
235241
$package_name = $datadog_agent::params::package_name,
@@ -288,6 +294,12 @@
288294
validate_string($pup_log_file)
289295
validate_string($syslog_host)
290296
validate_string($syslog_port)
297+
validate_string($service_discovery_backend)
298+
validate_string($sd_config_backend)
299+
validate_string($sd_backend_host)
300+
validate_integer($sd_backend_port)
301+
validate_string($sd_template_dir)
302+
validate_string($consul_token)
291303

292304
if $hiera_tags {
293305
$local_tags = hiera_array('datadog_agent::tags')

spec/classes/datadog_agent_spec.rb

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,28 @@
177177
)}
178178
it { should contain_file('/etc/dd-agent/datadog.conf').with(
179179
'content' => /^# syslog_port:\n/,
180-
)}
180+
)}
181+
end
182+
183+
context 'for service_discovery' do
184+
it { should contain_file('/etc/dd-agent/datadog.conf').without(
185+
'content' => /^service_discovery_backend:\n/,
186+
)}
187+
it { should contain_file('/etc/dd-agent/datadog.conf').without(
188+
'content' => /^sd_config_backend:\n/,
189+
)}
190+
it { should contain_file('/etc/dd-agent/datadog.conf').without(
191+
'content' => /^sd_backend_host:\n/,
192+
)}
193+
it { should contain_file('/etc/dd-agent/datadog.conf').without(
194+
'content' => /^sd_backend_port:\n/,
195+
)}
196+
it { should contain_file('/etc/dd-agent/datadog.conf').without(
197+
'content' => /^sd_template_dir:\n/,
198+
)}
199+
it { should contain_file('/etc/dd-agent/datadog.conf').without(
200+
'content' => /^consul_token:\n/,
201+
)}
181202
end
182203
end
183204

@@ -476,6 +497,26 @@
476497
'content' => /^syslog_port: 8080\n/,
477498
)}
478499
end
500+
context 'with service_discovery enabled' do
501+
let(:params) {
502+
{:service_discovery_backend => 'docker',
503+
:sd_config_backend => 'etcd',
504+
:sd_backend_host => 'localhost',
505+
:sd_backend_port => '8080',
506+
}}
507+
it { should contain_file('/etc/dd-agent/datadog.conf').with(
508+
'content' => /^service_discovery_backend: docker\n/,
509+
)}
510+
it { should contain_file('/etc/dd-agent/datadog.conf').with(
511+
'content' => /^sd_config_backend: etcd\n/,
512+
)}
513+
it { should contain_file('/etc/dd-agent/datadog.conf').with(
514+
'content' => /^sd_backend_host: localhost\n/,
515+
)}
516+
it { should contain_file('/etc/dd-agent/datadog.conf').with(
517+
'content' => /^sd_backend_port: 8080\n/,
518+
)}
519+
end
479520
end
480521
end
481522

templates/datadog.conf.erb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,57 @@ syslog_host: <%= @syslog_host %>
346346
syslog_port: <%= @syslog_port %>
347347
<% end -%>
348348

349+
350+
# ========================================================================== #
351+
# Service Discovery
352+
# ========================================================================== #
353+
354+
# For now only docker is supported so you just need to un-comment this line.
355+
<% if @service_discovery_backend.empty? -%>
356+
# service_discovery_backend: docker
357+
<% else -%>
358+
service_discovery_backend: <%= @service_discovery_backend %>
359+
<% end -%>
360+
361+
# Define which key/value store must be used to look for configuration templates.
362+
# Default is etcd. Consul is also supported.
363+
<% if @sd_config_backend.empty? -%>
364+
# sd_config_backend: etcd
365+
<% else -%>
366+
sd_config_backend: <%= @sd_config_backend %>
367+
<% end -%>
368+
369+
# Settings for connecting to the backend. These are the default, edit them if you run a different config.
370+
<% if @sd_backend_host.empty? -%>
371+
# sd_backend_host: 127.0.0.1
372+
<% else -%>
373+
sd_backend_host: <%= @sd_backend_host %>
374+
<% end -%>
375+
<% if @sd_backend_port.to_i < 1 -%>
376+
# sd_backend_port: 4001
377+
<% else -%>
378+
sd_backend_port: <%= @sd_backend_port %>
379+
<% end -%>
380+
381+
# By default, the agent will look for the configuration templates under the
382+
# `/datadog/check_configs` key in the back-end.
383+
# If you wish otherwise, uncomment this option and modify its value.
384+
<% if @sd_template_dir.empty? -%>
385+
# sd_template_dir: /datadog/check_configs
386+
<% else -%>
387+
sd_template_dir: <%= @sd_template_dir %>
388+
<% end -%>
389+
390+
# If you Consul store requires token authentication for service discovery, you can define that token here.
391+
<% if @consul_token.empty? -%>
392+
# consul_token: f45cbd0b-5022-samp-le00-4eaa7c1f40f1
393+
<% else -%>
394+
consul_token: <%= @consul_token %>
395+
<% end -%>
396+
397+
349398
<% if not @extra_template.empty? -%>
399+
350400
# ========================================================================== #
351401
# Custom Templates from Puppet #
352402
# ========================================================================== #

0 commit comments

Comments
 (0)