Skip to content

Commit 51934db

Browse files
remicalixtetruthbk
authored andcommitted
Support DD EU in reporter (#468)
* Write api_url in the report config * Use api_url to choose datadog host * Update spec tests * Add a default value for datadog_site
1 parent d45e121 commit 51934db

5 files changed

Lines changed: 44 additions & 2 deletions

File tree

lib/puppet/reports/datadog_reports.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
raise(Puppet::ParseError, "Datadog report config file #{configfile} not readable") unless File.readable?(configfile)
1414
config = YAML.load_file(configfile)
1515
API_KEY = config[:datadog_api_key]
16+
API_URL = config[:api_url]
1617

1718
# if need be initialize the regex
1819
if !config[:hostname_extraction_regex].nil?
@@ -110,7 +111,7 @@ def process
110111
end
111112

112113
Puppet.debug "Sending metrics for #{@msg_host} to Datadog"
113-
@dog = Dogapi::Client.new(API_KEY)
114+
@dog = Dogapi::Client.new(API_KEY, nil, nil, nil, nil, nil, API_URL)
114115
@dog.batch_metrics do
115116
self.metrics.each { |metric,data|
116117
data.values.each { |val|

manifests/init.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@
663663
if $puppet_run_reports {
664664
class { 'datadog_agent::reports':
665665
api_key => $api_key,
666+
datadog_site => $datadog_site,
666667
dogapi_version => $datadog_agent::params::dogapi_version,
667668
puppetmaster_user => $puppetmaster_user,
668669
hostname_extraction_regex => $hostname_extraction_regex,

manifests/reports.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
$api_key,
1818
$puppetmaster_user,
1919
$dogapi_version,
20-
$hostname_extraction_regex = nil
20+
$hostname_extraction_regex = nil,
21+
$datadog_site = 'datadoghq.com',
2122
) {
2223

2324
include datadog_agent

spec/classes/datadog_agent_reports_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,42 @@
9595
end
9696
end
9797
end
98+
99+
context 'EU site in report' do
100+
let(:params) do
101+
{
102+
api_key: 'notanapikey',
103+
hostname_extraction_regex: nil,
104+
puppetmaster_user: 'puppet',
105+
dogapi_version: 'installed',
106+
datadog_site: 'datadoghq.eu',
107+
}
108+
end
109+
describe "datadog_agent class dogapi version override" do
110+
let(:facts) do
111+
{
112+
operatingsystem: 'Debian',
113+
osfamily: 'debian'
114+
}
115+
end
116+
117+
it { should contain_class('ruby').with_rubygems_update(false) }
118+
it { should contain_class('ruby::params') }
119+
it { should contain_package('ruby').with_ensure('installed') }
120+
it { should contain_package('rubygems').with_ensure('installed') }
121+
122+
it do
123+
should contain_package('ruby-dev')\
124+
.with_ensure('installed')\
125+
.that_comes_before('Package[dogapi]')
126+
end
127+
128+
it do
129+
should contain_file('/etc/datadog-agent/datadog-reports.yaml')\
130+
.with_owner('puppet')\
131+
.with_group('root')\
132+
.with_content(/:api_url: api.datadoghq.eu/)
133+
end
134+
end
135+
end
98136
end

templates/datadog-reports.yaml.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44
---
55
:datadog_api_key: '<%= @api_key %>'
6+
:api_url: api.<%= @datadog_site %>
67
<% if !@hostname_extraction_regex.nil? -%>
78
:hostname_extraction_regex: '<%= @hostname_extraction_regex %>'
89
<% end -%>

0 commit comments

Comments
 (0)