Skip to content

Commit d8f40d8

Browse files
cwoodtruthbk
authored andcommitted
Make tags there own resourced, allow hiera created integrations, setup check_feq (#261)
* Make a generic define for creating modules There is one already but only allows one since its a class we can not do a bunch of integrations and replace the class with this. Also this will allow you to write ruby, or hiera and put it in the config you need. * Remove unused template * Add support for init_config if passed * Update to remove the empty string. * Adding logic to handle tags as arrays. * Allow support for integrations from hiera * Fix some typos * Add check_freq setting * Allow the ability to purge unsued configs * Notify the service * Setup a spec test * Set recurse to true * Set force to true if purge is true * Allow tags to be there own define. * Fix name * Allow looking up facts to tags * Fix unless issue * If a array call itself and add the fragment * Check if is_array * Remove map and use map() * Migrate tags to its own array * Prefix everything with the tag * Make tags its own thing * Only run if not a tag * Add a begining new line * Only add if we have a value * [service_discovery][dogstatsd] adding relevant SD and dogstatsd to the relevant fragments. * [apm] adding apm tests. * [datadog-agent][spec] check fragment contents instead. * [spec] fix ports as integers for new concat templates. * [templates] removing global template, we now use concat templates. * [main] dogstatsd should also allow string and integer ports - like other params. * [init] remove check_freq, undocumented.
1 parent 2b3248a commit d8f40d8

9 files changed

Lines changed: 283 additions & 199 deletions

File tree

.fixtures.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ fixtures:
33
stdlib:
44
repo: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
55
ref: "4.12.0"
6+
concat: "git://github.com/puppetlabs/puppetlabs-concat.git"
67
ruby: "git://github.com/puppetlabs/puppetlabs-ruby.git"
78
remote_file: "git://github.com/lwf/puppet-remote_file.git"
89
symlinks:

manifests/init.pp

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@
183183
$collect_ec2_tags = false,
184184
$collect_instance_metadata = true,
185185
$tags = [],
186+
$integrations = {},
187+
$hiera_integrations = false,
186188
$hiera_tags = false,
187189
$facts_to_tags = [],
188190
$puppet_run_reports = false,
@@ -239,6 +241,7 @@
239241
$sd_jmx_enable = false,
240242
$consul_token = '',
241243
$conf_dir = $datadog_agent::params::conf_dir,
244+
$conf_dir_purge = $datadog_agent::params::conf_dir_purge,
242245
$service_name = $datadog_agent::params::service_name,
243246
$package_name = $datadog_agent::params::package_name,
244247
$dd_user = $datadog_agent::params::dd_user,
@@ -249,6 +252,7 @@
249252

250253
# Allow ports to be passed as integers or strings.
251254
# lint:ignore:only_variable_string
255+
$_dogstatsd_port = "${dogstatsd_port}"
252256
$_statsd_forward_port = "${statsd_forward_port}"
253257
$_proxy_port = "${proxy_port}"
254258
$_graphite_listen_port = "${graphite_listen_port}"
@@ -271,7 +275,7 @@
271275
validate_bool($log_to_syslog)
272276
validate_bool($manage_repo)
273277
validate_string($log_level)
274-
validate_integer($dogstatsd_port)
278+
validate_re($_dogstatsd_port, '^\d*$')
275279
validate_string($statsd_histogram_percentiles)
276280
validate_re($_statsd_forward_port, '^\d*$')
277281
validate_string($proxy_host)
@@ -324,6 +328,17 @@
324328
$local_tags = $tags
325329
}
326330

331+
if $hiera_integrations {
332+
$local_integrations = hiera_hash('datadog_agent::integrations')
333+
} else {
334+
$local_integrations = $integrations
335+
}
336+
337+
datadog_agent::tag{$local_tags: }
338+
datadog_agent::tag{$facts_to_tags:
339+
lookup_fact => true,
340+
}
341+
327342
include datadog_agent::params
328343
case upcase($log_level) {
329344
'CRITICAL': { $_loglevel = 'CRITICAL' }
@@ -354,26 +369,49 @@
354369
require => Package['datadog-agent'],
355370
}
356371

357-
# main agent config file
358-
# content
359-
if ($extra_template != '') {
360-
$agent_conf_content = template(
361-
'datadog_agent/datadog.conf.erb',
362-
$extra_template
363-
)
364-
} else {
365-
$agent_conf_content = template('datadog_agent/datadog.conf.erb')
372+
file { $conf_dir:
373+
ensure => directory,
374+
purge => $conf_dir_purge,
375+
recurse => true,
376+
force => $conf_dir_purge,
377+
owner => $dd_user,
378+
group => $dd_group,
379+
notify => Service['datadog-agent']
366380
}
367-
file { '/etc/dd-agent/datadog.conf':
368-
ensure => file,
369-
content => $agent_conf_content,
381+
382+
concat {'/etc/dd-agent/datadog.conf':
370383
owner => $datadog_agent::params::dd_user,
371384
group => $datadog_agent::params::dd_group,
372385
mode => '0640',
373386
notify => Service[$datadog_agent::params::service_name],
374387
require => File['/etc/dd-agent'],
375388
}
376389

390+
concat::fragment{ 'datadog header':
391+
target => '/etc/dd-agent/datadog.conf',
392+
content => template('datadog_agent/datadog_header.conf.erb'),
393+
order => '01',
394+
}
395+
396+
concat::fragment{ 'datadog tags':
397+
target => '/etc/dd-agent/datadog.conf',
398+
content => 'tags: ',
399+
order => '02',
400+
}
401+
402+
concat::fragment{ 'datadog footer':
403+
target => '/etc/dd-agent/datadog.conf',
404+
content => template('datadog_agent/datadog_footer.conf.erb'),
405+
order => '05',
406+
}
407+
408+
concat::fragment{ 'datadog apm footer':
409+
target => '/etc/dd-agent/datadog.conf',
410+
content => template('datadog_agent/datadog_apm_footer.conf.erb'),
411+
order => '06',
412+
}
413+
414+
377415
if $puppet_run_reports {
378416
class { 'datadog_agent::reports':
379417
api_key => $api_key,
@@ -383,4 +421,6 @@
383421
hostname_extraction_regex => $hostname_extraction_regex,
384422
}
385423
}
424+
425+
create_resources('datadog_agent::integration', $local_integrations)
386426
}

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
$package_name = 'datadog-agent'
2222
$service_name = 'datadog-agent'
2323
$dogapi_version = 'installed'
24+
$conf_dir_purge = false
2425

2526
case $::operatingsystem {
2627
'Ubuntu','Debian' : {

manifests/tag.pp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Allow custom tags via a define
2+
define datadog_agent::tag(
3+
$tag = $name,
4+
$lookup_fact = false,
5+
){
6+
7+
if $lookup_fact{
8+
$value = getvar($tag)
9+
10+
if is_array($value){
11+
$tags = prefix($value, "${tag}:")
12+
datadog_agent::tag{$tags: }
13+
} else {
14+
if $value {
15+
concat::fragment{ "datadog tag ${tag}:${value}":
16+
target => '/etc/dd-agent/datadog.conf',
17+
content => "${tag}:${value}, ",
18+
order => '03',
19+
}
20+
}
21+
}
22+
} else {
23+
concat::fragment{ "datadog tag ${tag}":
24+
target => '/etc/dd-agent/datadog.conf',
25+
content => "${tag}, ",
26+
order => '03',
27+
}
28+
}
29+
30+
}

0 commit comments

Comments
 (0)