Skip to content

Commit

Permalink
Added logs configuration (DataDog#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajacquemot authored Jun 15, 2018
1 parent 7ca91cb commit 05cdd26
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ Here are some of the other variables that be set in the datadog_agent class to c
| process_enabled | boolean to enable the process agent; defaults to true |
| scrub_args | boolean to enable the process cmdline scrubbing; defaults to true |
| custom_sensitive_words| an array to add more words beyond the default ones used by the scrubbing feature; defaults to [] |
| agent6_extra_options | hash to provide additional configuration options to agent6. |
| logs_enabled | boolean to enable the logs agent; defaults to false |
| container_collect_all | boolean to enable logs collection for all containers |
| agent6_extra_options | hash to provide additional configuration options to agent6 |

_NOTE: `agent6_extra_options` may be used to provide a fine grain control of additional agent6 config options. A deep merge is performed that may override options provided in the `datadog_agent` class parameters_

Expand Down
14 changes: 14 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@
# $custom_sensitive_words
# Array to add more words to be used on the process cdmline scrubbing by the process-agent
# Array. Default: []
# $logs_enabled
# Boolean to enable or disable the logs agent
# Boolean. Default: false
# $container_collect_all
# Boolean to enable logs collection for all containers
# Boolean. Default: false
#
# Actions:
#
Expand Down Expand Up @@ -273,6 +279,8 @@
$process_enabled = $datadog_agent::params::process_default_enabled,
$scrub_args = $datadog_agent::params::process_default_scrub_args,
$custom_sensitive_words = $datadog_agent::params::process_default_custom_words,
$logs_enabled = $datadog_agent::params::logs_enabled,
$container_collect_all = $datadog_agent::params::container_collect_all,
Hash[String[1], Data] $agent6_extra_options = {},
$agent5_repo_uri = $datadog_agent::params::agent5_default_repo,
$agent6_repo_uri = $datadog_agent::params::agent6_default_repo,
Expand Down Expand Up @@ -355,6 +363,8 @@
validate_legacy(Boolean, 'validate_bool', $process_enabled)
validate_legacy(Boolean, 'validate_bool', $scrub_args)
validate_legacy(Array, 'validate_array', $custom_sensitive_words)
validate_legacy(Boolean, 'validate_bool', $logs_enabled)
validate_legacy(Boolean, 'validate_bool', $container_collect_all)
validate_legacy(String, 'validate_string', $agent5_repo_uri)
validate_legacy(String, 'validate_string', $agent6_repo_uri)
validate_legacy(String, 'validate_string', $apt_release)
Expand Down Expand Up @@ -528,6 +538,10 @@
'scrub_args' => $scrub_args,
'custom_sensitive_words' => $custom_sensitive_words,
},
'logs_enabled' => $logs_enabled,
'logs_config' => {
'container_collect_all' => $container_collect_all,
},
}
$extra_config = deep_merge($base_extra_config, $agent6_extra_options)

Expand Down
56 changes: 56 additions & 0 deletions manifests/integrations/logs.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Class: datadog_agent::integrations::logs
#
# This class will install the necessary configuration for the logs integration.
#
# Parameters:
# $logs:
# array of log sources.
#
# Log Source:
# $type
# Type of log input source (tcp / udp / file / docker / journald / windows_event).
# $service
# Optional name of the service owning the log.
# $source
# Optional attribute that defines which integration is sending the logs.
# $tags
# Optional tags that are added to each log collected.
# $log_processing_rules
# Optional array of processing rules.
#
# Sample Usage:
#
# class { 'datadog_agent::integrations::logs' :
# logs => [
# {
# 'type' => 'file',
# 'path' => '/var/log/afile.log',
# },
# {
# 'type' => 'docker',
# },
# ],
# }
#
# Documentation:
# https://docs.datadoghq.com/logs/log_collection
#

class datadog_agent::integrations::logs(
Array $logs = [],
) inherits datadog_agent::params {
unless $::datadog_agent::agent5_enable {
include datadog_agent
validate_legacy('Array', 'validate_array', $logs)

file { "${datadog_agent::conf6_dir}/logs.yaml":
ensure => file,
owner => $datadog_agent::params::dd_user,
group => $datadog_agent::params::dd_group,
mode => '0600',
content => template('datadog_agent/agent-conf.d/logs.yaml.erb'),
require => Package[$datadog_agent::params::package_name],
notify => Service[$datadog_agent::params::service_name]
}
}
}
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
$process_default_enabled = false
$process_default_scrub_args = true
$process_default_custom_words = []
$logs_enabled = false
$container_collect_all = false

case $::operatingsystem {
'Ubuntu','Debian' : {
Expand Down
38 changes: 38 additions & 0 deletions spec/classes/datadog_agent_integrations_logs_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'spec_helper'

describe 'datadog_agent::integrations::logs' do
context 'supported agents - v6' do
let(:pre_condition) { "class {'::datadog_agent': agent5_enable => false}" }
let(:facts) {{
operatingsystem: 'Ubuntu',
}}
let(:conf_dir) { '/etc/datadog-agent/conf.d' }
let(:dd_user) { 'dd-agent' }
let(:dd_group) { 'root' }
let(:dd_package) { 'datadog-agent' }
let(:dd_service) { 'datadog-agent' }
let(:conf_file) { "#{conf_dir}/logs.yaml" }

context 'with default parameters' do
it { should compile }
end

context 'with parameters set' do
let(:params) {{
logs: [
{
'type' => 'file',
'path' => 'apath.log',
},
{
'type' => 'docker',
},
],
}}
it { should contain_file(conf_file).with_content(%r{logs:}) }
it { should contain_file(conf_file).with_content(%r{- type: file}) }
it { should contain_file(conf_file).with_content(%r{path: apath.log}) }
it { should contain_file(conf_file).with_content(%r{- type: docker}) }
end
end
end
15 changes: 15 additions & 0 deletions spec/classes/datadog_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,10 @@
it { should contain_file('/etc/datadog-agent/datadog.yaml').with(
'content' => /^\ \ custom_sensitive_words: \[\]\n/,
)}
it { should contain_file('/etc/datadog-agent/datadog.yaml').with(
'content' => /^logs_enabled: false\n/,
'content' => /^\ \ container_collect_all: false\n/,
)}
end
end

Expand Down Expand Up @@ -1038,8 +1042,19 @@
it { should contain_file('/etc/datadog-agent/datadog.yaml').with(
'content' => /^\ \ -\ dd_key\n/,
)}
end

context 'with logs enabled' do
let(:params) {{
:logs_enabled => true,
:container_collect_all => true
}}
it { should contain_file('/etc/datadog-agent/datadog.yaml').with(
'content' => /^logs_enabled: true\n/,
'content' => /^\ \ container_collect_all: true\n/,
)}
end

end
end
end
Expand Down
5 changes: 5 additions & 0 deletions templates/agent-conf.d/logs.yaml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%
require 'yaml'
%>

<%= {'logs'=>@logs}.to_yaml %>

0 comments on commit 05cdd26

Please sign in to comment.