[windows] Fix default datadog.yaml template for Windows
And add a spec test
MODIFY
spec/dd-agent_spec.rb
spec/dd-agent_spec.rb
@@ -797,6 +797,7 @@ describe 'datadog::dd-agent' do
describe 'the datadog.yaml config file' do
context 'with default attribute values' do
+ context 'on Ubuntu' do
cached(:chef_run) do
ChefSpec::SoloRunner.new(
platform: 'ubuntu',
@@ -842,6 +843,54 @@ describe 'datadog::dd-agent' do
})
end
end
+
+ context 'on Windows' do
+ cached(:chef_run) do
+ set_env_var('ProgramData', 'C:\ProgramData')
+ ChefSpec::SoloRunner.new(
+ platform: 'windows',
+ version: '2012R2'
+ ) do |node|
+ node.name 'chef-nodename' # expected to be used as the hostname in `datadog.yaml`
+ node.set['datadog'] = { 'api_key' => 'somethingnotnil', 'agent6' => true }
+ end.converge described_recipe
+ end
+
+ it 'is created' do
+ expect(chef_run).to create_template('C:\ProgramData/Datadog/datadog.yaml')
+ end
+
+ it 'contains expected YAML configuration' do
+ expected_yaml = <<-EOF
+ api_key: somethingnotnil
+ dd_url: https://app.datadoghq.com
+ tags: []
+ use_dogstatsd: true
+ additional_endpoints: {}
+ histogram_aggregates:
+ - "max"
+ - "median"
+ - "avg"
+ - "count"
+ histogram_percentiles:
+ - "0.95"
+ hostname: "chef-nodename"
+ log_level: "INFO"
+ non_local_traffic: false
+ apm_config: {}
+ process_config:
+ enabled: "false"
+ blacklist_patterns: []
+ intervals: {}
+ process_dd_url: "https://process.datadoghq.com"
+ EOF
+
+ expect(chef_run).to(render_file('C:\ProgramData/Datadog/datadog.yaml').with_content { |content|
+ expect(YAML.safe_load(content).to_json).to be_json_eql(YAML.safe_load(expected_yaml).to_json)
+ })
+ end
+ end
+ end
end
end
end

MODIFY
templates/default/datadog.yaml.erb
templates/default/datadog.yaml.erb
@@ -89,7 +89,6 @@ agent_config = @extra_config.merge({
histogram_percentiles: string_list_to_array(node['datadog']['histogram_percentiles']),
use_dogstatsd: node['datadog']['dogstatsd'],
log_level: node['datadog']['log_level'], # TODO: make sure it's a seelog-compatible log level
- log_file: ::File.join(node['datadog']['log_file_directory'], "agent.log"),
# log agent options
logs_enabled: node['datadog']['enable_logs_agent'],
@@ -109,6 +108,10 @@ agent_config = @extra_config.merge({
}
})
+if node['datadog']['log_file_directory']
+ agent_config['log_file'] = ::File.join(node['datadog']['log_file_directory'], "agent.log")
+end
+
if !node['datadog']['use_v2_api'].nil? && !node['datadog']['use_v2_api'].empty?
agent_config['use_v2_api'] = node['datadog']['use_v2_api']
end

[windows] Fix default datadog.yaml template for Windows (#528)

And add a spec test