Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 'site' option. #582

Merged
merged 9 commits into from
Apr 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -66,6 +66,11 @@
'/etc/datadog-agent'
end

# The site of the Datadog intake to send Agent data to.
# This configuration option is supported since Agent 6.6
# Defaults to 'datadoghq.com', set to 'datadoghq.eu' to send data to the EU site.
default['datadog']['site'] = nil

# Set a key to true to make the agent6 use the v2 api on that endpoint, false otherwise.
# Leave key value to nil to use agent6 default for that endpoint.
# Supported keys: "series", "events", "service checks"
@@ -88,9 +93,14 @@
# Set prefix to '' if you want Chef tags to be sent without prefix.
default['datadog']['tag_prefix'] = 'tag:'

# Don't change these
# The host of the Datadog intake server to send agent data to
default['datadog']['url'] = 'https://app.datadoghq.com'
# The host of the Datadog intake server to send Agent data to, only set this option
# if you need the Agent to send data to a custom URL.
# The nil value will let the Agent 6 select the URL to send the data.
# Any non-nil value overrides the 'site' value, prefer using 'site' unless your
# use case isn't covered by 'site'.
# For Agent 5, the Agent 5 recipe will fallback on https://app.datadoghq.com
# (see recipes/dd-agent.rb).
default['datadog']['url'] = nil

# Add tags as override attributes in your role
# This can be a string of comma separated tags or a hash in this format:
8 changes: 7 additions & 1 deletion recipes/_agent6_config.rb
Original file line number Diff line number Diff line change
@@ -22,13 +22,19 @@
agent6_config_file = ::File.join(node['datadog']['agent6_config_dir'], 'datadog.yaml')
template agent6_config_file do
def template_vars
# we need to always provide an URL value for additional endpoints.
# use either the site option or the url one, the latter having priority.
dd_url = 'https://app.datadoghq.com'
dd_url = 'https://app.' + node['datadog']['site'] unless node['datadog']['site'].nil?
dd_url = node['datadog']['url'] unless node['datadog']['url'].nil?

additional_endpoints = {}
node['datadog']['extra_endpoints'].each do |_, endpoint|
next unless endpoint['enabled']
url = if endpoint['url']
endpoint['url']
else
node['datadog']['url']
dd_url
end
if additional_endpoints.key?(url)
additional_endpoints[url] << endpoint['api_key']
10 changes: 8 additions & 2 deletions recipes/dd-agent.rb
Original file line number Diff line number Diff line change
@@ -65,15 +65,21 @@
agent_config_file = ::File.join(node['datadog']['config_dir'], 'datadog.conf')
template agent_config_file do
def template_vars
# Default value of node['datadog']['url'] is now nil for an Agent 6
# but for compatibility with Agent 5, we still need to have the value
# set. It's set here.
dd_url = 'https://app.datadoghq.com'
dd_url = node['datadog']['url'] unless node['datadog']['url'].nil?

api_keys = [Chef::Datadog.api_key(node)]
dd_urls = [node['datadog']['url']]
dd_urls = [dd_url]
node['datadog']['extra_endpoints'].each do |_, endpoint|
next unless endpoint['enabled']
api_keys << endpoint['api_key']
dd_urls << if endpoint['url']
endpoint['url']
else
node['datadog']['url']
dd_url
end
end
{
15 changes: 13 additions & 2 deletions recipes/dd-handler.rb
Original file line number Diff line number Diff line change
@@ -26,7 +26,12 @@
end

include_recipe 'chef_handler'
ENV['DATADOG_HOST'] = node['datadog']['url']

if node['datadog']['chef_handler_version'] &&
Gem::Version.new(node['datadog']['chef_handler_version']) < Gem::Version.new('0.10.0')
Chef::Log.error('We do not support chef_handler_version < v0.10.0 anymore, please use a more recent version.')
return
end

chef_gem 'chef-handler-datadog' do # ~FC009
action :install
@@ -61,12 +66,18 @@ def extra_endpoints

def handler_config
extra_config = node['datadog']['handler_extra_config'].reject { |_, v| v.nil? }

# Since Agent 6 supports node['datadog']['url'] = nil, we need to fallback
# on a default value here.
dd_url = 'https://app.datadoghq.com'
dd_url = node['datadog']['url'] unless node['datadog']['url'].nil?

config = extra_config.merge(
:api_key => Chef::Datadog.api_key(node),
:application_key => Chef::Datadog.application_key(node),
:use_ec2_instance_id => node['datadog']['use_ec2_instance_id'],
:tag_prefix => node['datadog']['tag_prefix'],
:url => node['datadog']['url'],
:url => dd_url,
:extra_endpoints => extra_endpoints,
:tags_blacklist_regex => node['datadog']['tags_blacklist_regex'],
:send_policy_tags => node['datadog']['send_policy_tags'],
2 changes: 0 additions & 2 deletions spec/dd-agent_spec.rb
Original file line number Diff line number Diff line change
@@ -815,7 +815,6 @@ def set_env_var(name, value)
it 'contains expected YAML configuration' do
expected_yaml = <<-EOF
api_key: somethingnotnil
dd_url: https://app.datadoghq.com
tags: []
use_dogstatsd: true
bind_host: localhost
@@ -867,7 +866,6 @@ def set_env_var(name, value)
it 'contains expected YAML configuration' do
expected_yaml = <<-EOF
api_key: somethingnotnil
dd_url: https://app.datadoghq.com
tags: []
use_dogstatsd: true
bind_host: localhost
1 change: 1 addition & 0 deletions templates/default/datadog.yaml.erb
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@ end
## Populate agent_config ##
agent_config = @extra_config.merge({
api_key: @api_key,
site: node['datadog']['site'],
dd_url: node['datadog']['url'],
hostname: node['datadog']['hostname'],
bind_host: node['datadog']['bind_host'],