Skip to content

Commit

Permalink
[apm] adding support for APM analyze spans in A5 + changing argument …
Browse files Browse the repository at this point in the history
…to hash
  • Loading branch information
truthbk committed Jan 21, 2019
1 parent b65f607 commit b03b8a3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 18 deletions.
25 changes: 15 additions & 10 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
$apm_enabled = $datadog_agent::params::apm_default_enabled,
$apm_env = 'none',
$apm_non_local_traffic = false,
Optional[Array[Tuple[String,Float[0, 1], 2, 1]]] $apm_analyzed_spans = undef,
Optional[Hash[String, Float[0, 1]]] $apm_analyzed_spans = undef,
$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,
Expand Down Expand Up @@ -497,6 +497,7 @@
}

if $agent5_enable {

file { '/etc/dd-agent':
ensure => directory,
owner => $dd_user,
Expand Down Expand Up @@ -559,7 +560,7 @@
}
}

if ($apm_enabled == true) and ($apm_env != 'none') {
if ($apm_enabled == true) and ($apm_env != 'none') or $apm_analyzed_spans {
concat::fragment{ 'datadog apm footer':
target => '/etc/dd-agent/datadog.conf',
content => template('datadog_agent/datadog_apm_footer.conf.erb'),
Expand Down Expand Up @@ -617,15 +618,14 @@
$host_config = {}
}

$apm_extra_config = {
'apm_config' => {},
}
if $apm_analyzed_spans {
$span_list = $apm_analyzed_spans.map { |service, resource, percentage|
"#{service}|#{resource}: #{percentage}"
$apm_analyzed_span_config = {
'apm_config' => {
'apm_analyzed_spans' => $apm_analyzed_spans
}
}

$apm_extra_config['apm_config']['apm_analyzed_spans'] = $span_list
} else {
$apm_analyzed_span_config = {}
}

if $statsd_forward_host != '' {
Expand All @@ -642,7 +642,12 @@
} else {
$statsd_forward_config = {}
}
$extra_config = deep_merge($base_extra_config, $agent6_extra_options, $apm_extra_config, $statsd_forward_config, $host_config)
$extra_config = deep_merge(
$base_extra_config,
$agent6_extra_options,
$apm_analyzed_span_config,
$statsd_forward_config,
$host_config)

file { $conf6_dir:
ensure => directory,
Expand Down
40 changes: 40 additions & 0 deletions spec/classes/datadog_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,27 @@
'order' => '07',
)}
end
context 'with apm_enabled and apm_analyzed_spans set' do
let(:params) {{ :apm_enabled => true,
:agent5_enable => true,
:apm_analyzed_spans => {
'foo|bar' => 0.5,
'haz|qux' => 0.1
},
}}
it { should contain_concat__fragment('datadog footer').with(
'content' => /^apm_enabled: true\n/,
)}
it { should contain_concat__fragment('datadog apm footer').with(
'content' => /^\[trace.analyzed_spans\]\n/,
)}
it { should contain_concat__fragment('datadog apm footer').with(
'content' => /^\[trace.analyzed_spans\]\nfoo|bar: 0.5\nhaz|qux: 0.1/,
)}
it { should contain_concat__fragment('datadog apm footer').with(
'order' => '07',
)}
end
context 'with service_discovery enabled' do
let(:params) {{ :service_discovery_backend => 'docker',
:sd_config_backend => 'etcd',
Expand Down Expand Up @@ -1067,6 +1088,25 @@
'content' => /^\ \ apm_non_local_traffic: true\n/,
)}
end

context 'with apm_enabled set to true and apm_analyzed_spans specified' do
let(:params) {{
:apm_enabled => true,
:apm_analyzed_spans => {
'foo|bar' => 0.5,
'haz|qux' => 0.1
},
}}
it { should contain_file('/etc/datadog-agent/datadog.yaml').with(
'content' => /^apm_config:\n/,
)}
it { should contain_file('/etc/datadog-agent/datadog.yaml').with(
'content' => /^apm_config:\n\ \ enabled: true\n/,
)}
it { should contain_file('/etc/datadog-agent/datadog.yaml').with(
'content' => /^\ \ apm_analyzed_spans:\n\ \ \ \ foo|bar: 0.5\n\ \ \ \ haz|qux: 0.1\n/,
)}
end
context 'with extra_options and Process enabled' do
let(:params) {{
:apm_enabled => false,
Expand Down
7 changes: 7 additions & 0 deletions templates/datadog_apm_footer.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
[trace.agent]
env: <%= @apm_env %>
<% end -%>

<% if @apm_analyzed_spans -%>
[trace.analyzed_spans]
<% @apm_analyzed_spans.each do |span, value| -%>
<%= span %>: <%= value %>
<% end %>
<% end -%>
8 changes: 0 additions & 8 deletions templates/datadog_footer.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,6 @@ process_agent_enabled: <%= @process_enabled %>
# Enable the trace agent.
apm_enabled: <%= @apm_enabled %>

# Enable and the trace search & analytics by adding a list of entered APM events.
<% if @apm_analyzed_spans -%>
analyzed_spans:

<%= @apm_analyzed_spans.each { |service, resource, percentage|
puts "#{service}|#{resource}: #{percentage}"
} %>
<% end -%>
<% if not @extra_template.empty? -%>
# ========================================================================== #
# Custom Templates from Puppet #
Expand Down

0 comments on commit b03b8a3

Please sign in to comment.