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 of IOT agent flavor #717

Merged
merged 5 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ depends 'yum', '< 5.0'
# Berksfile
cookbook 'datadog', '~> 4.0.0'
```

```shell
# Knife
knife cookbook site install datadog
```

2. Set the [Datadog-specific attributes](#datadog-attributes) in a role, environment, or another recipe:
```text
node.default['datadog']['api_key'] = "<YOUR_DD_API_KEY>"
Expand Down Expand Up @@ -149,7 +149,7 @@ Follow the steps below to deploy the Datadog Agent with Chef on AWS OpsWorks:

### Integrations

Enable Agent integrations by including the [recipe](#recipes) and configuration details in your role’s run-list and attributes.
Enable Agent integrations by including the [recipe](#recipes) and configuration details in your role’s run-list and attributes.
**Note**: You can create additional integration recipes by using the [datadog_monitor](#datadog-monitor) resource.

Associate your recipes with the desired `roles`, for example `role:chef-client` should contain `datadog::dd-handler` and `role:base` should start the Agent with `datadog::dd-agent`. Below is an example role with the `dd-handler`, `dd-agent`, and `mongo` recipes:
Expand Down Expand Up @@ -189,6 +189,7 @@ By default, the current major version of this cookbook installs Agent v7. The fo
| `agent_major_version` | Pin the major version of the Agent to 5, 6, or 7 (default). |
| `agent_version` | Pin a specific Agent version (recommended). |
| `agent_package_action` | (Linux only) Defaults to `'install'` (recommended), `'upgrade'` to get automatic Agent updates (not recommended, use the default and change the pinned `agent_version` to upgrade). |
| `agent_flavor` | (Linux only) Defaults to `'datadog-agent'` to install the datadog-agent, can be set to `'datadog-iot-agent'` to install the IOT agent. |

See the sample [attributes/default.rb][1] for your cookbook version for all available attributes.

Expand Down
2 changes: 2 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
# Example:
# default['datadog']['agent_version'] = '7.16.0'
default['datadog']['agent_version'] = nil # nil to install latest
# Agent flavor to install, acceptable values are "datadog-agent", "datadog-iot-agent"
default['datadog']['agent_flavor'] = 'datadog-agent' # "datadog-agent" to install the datadog-agent package

# Allow override with `upgrade` to get latest (Linux only)
default['datadog']['agent_package_action'] = 'install'
Expand Down
13 changes: 13 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ suites:
api_key: somenonnullapikeythats32charlong
application_key: alsonotnil

- name: dd-agent-iot
run_list:
- recipe[datadog::dd-agent]
attributes:
datadog: &DATADOG
api_key: somenonnullapikeythats32charlong
application_key: alsonotnil
install_info_enabled: true
agent_flavor: datadog-iot-agent
aptrepo: 'https://apt.datad0g.com'
aptrepo_dist: 'beta'
agent_version: '7.20.0~rc.3'

- name: system-probe
run_list:
- recipe[datadog::dd-agent]
Expand Down
17 changes: 17 additions & 0 deletions libraries/recipe_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ class Chef
# Helper class for Datadog Chef recipes
class Datadog
class << self
ACCEPTABLE_AGENT_FLAVORS = %w[
datadog-agent
datadog-iot-agent
].freeze

def agent_version(node)
dd_agent_version = node['datadog']['agent_version']
if dd_agent_version.respond_to?(:each_pair)
Expand Down Expand Up @@ -47,6 +52,18 @@ def agent_major_version(node)
7
end

def agent_flavor(node)
# user-specified values
agent_flavor = node['datadog']['agent_flavor']
agent_flavor ||= node.default['datadog']['agent_flavor']

unless ACCEPTABLE_AGENT_FLAVORS.include?(agent_flavor)
raise "Unknown agent flavor '#{agent_flavor}' (acceptable values: #{ACCEPTABLE_AGENT_FLAVORS.inspect})"
end

agent_flavor
end

def api_key(node)
run_state_or_attribute(node, 'api_key')
end
Expand Down
10 changes: 6 additions & 4 deletions recipes/_install-linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@
include_recipe 'datadog::repository' if node['datadog']['installrepo']

dd_agent_version = Chef::Datadog.agent_version(node)
dd_agent_flavor = Chef::Datadog.agent_flavor(node)

package_action = node['datadog']['agent_package_action']

package_retries = node['datadog']['agent_package_retries']
package_retry_delay = node['datadog']['agent_package_retry_delay']

# Install the regular package
case node['platform_family']
when 'debian'
apt_package 'datadog-agent' do
apt_package dd_agent_flavor do
version dd_agent_version
retries package_retries unless package_retries.nil?
retry_delay package_retry_delay unless package_retry_delay.nil?
Expand All @@ -41,14 +43,14 @@
node['platform_family'] == 'fedora' && node['platform_version'].to_i >= 28
# yum_package doesn't work on RHEL 8 and Fedora >= 28
# dnf_package only works on RHEL 8 / Fedora >= 28 if Chef 15+ is used
dnf_package 'datadog-agent' do
dnf_package dd_agent_flavor do
version dd_agent_version
retries package_retries unless package_retries.nil?
retry_delay package_retry_delay unless package_retry_delay.nil?
action package_action # default is :install
end
else
yum_package 'datadog-agent' do
yum_package dd_agent_flavor do
version dd_agent_version
retries package_retries unless package_retries.nil?
retry_delay package_retry_delay unless package_retry_delay.nil?
Expand All @@ -57,7 +59,7 @@
end
end
when 'suse'
zypper_package 'datadog-agent' do # ~FC009
zypper_package dd_agent_flavor do # ~FC009
version dd_agent_version
retries package_retries unless package_retries.nil?
retry_delay package_retry_delay unless package_retry_delay.nil?
Expand Down
5 changes: 5 additions & 0 deletions recipes/_install-windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#

dd_agent_version = Chef::Datadog.agent_version(node)
dd_agent_flavor = Chef::Datadog.agent_flavor(node)

if dd_agent_flavor != 'datadog-agent'
raise "Unsupported agent flavor '#{dd_agent_flavor}' on Windows (only supports 'datadog-agent')"
end

if dd_agent_version.nil?
# Use latest
Expand Down
29 changes: 29 additions & 0 deletions test/integration/dd-agent-iot/serverspec/dd-agent_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

@agent_package_name = 'datadog-iot-agent'

describe package(@agent_package_name) do
it { should be_installed }
end

describe service(@agent_service_name) do
it { should be_running }
end

describe command('/opt/datadog-agent/bin/agent/agent status | grep -v "Instance ID"'), :if => os[:family] != 'windows' do
its(:exit_status) { should eq 0 }
its(:stdout) { should contain '[OK]' }
its(:stdout) { should_not contain 'ERROR' }
end

# The new APT key is imported
describe command('apt-key list'), :if => ['debian', 'ubuntu'].include?(os[:family]) do
its(:exit_status) { should eq 0 }
its(:stdout) { should contain '382E94DE' }
end

# The new RPM key is imported
describe command('rpm -q gpg-pubkey-e09422b3'), :if => os[:family] == 'redhat' do
its(:exit_status) { should eq 0 }
its(:stdout) { should contain 'gpg-pubkey-e09422b3' }
end
25 changes: 25 additions & 0 deletions test/integration/dd-agent-iot/serverspec/install_info_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'spec_helper'

@agent_package_name = 'datadog-iot-agent'

describe 'Install infos' do
let(:install_info_path) do
if os == :windows
"#{ENV['ProgramData']}\\Datadog\\install_info"
else
'/etc/datadog-agent/install_info'
end
end

let(:install_info) do
YAML.load_file(install_info_path)
end

it 'adds an install_info' do
expect(install_info['install_method']).to match(
'tool_version' => /chef-\d+\.\d+\.\d+/,
'tool' => 'chef',
'installer_version' => /^datadog_cookbook-\d+\.\d+\.\d+$/
)
end
end
4 changes: 2 additions & 2 deletions test/integration/dd-agent/serverspec/dd-agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
it { should be_running }
end

describe command('/etc/init.d/datadog-agent info | grep -v "API Key is invalid"'), :if => os[:family] != 'windows' do
describe command('/opt/datadog-agent/bin/agent/agent status | grep -v "Instance ID"'), :if => os[:family] != 'windows' do
its(:exit_status) { should eq 0 }
its(:stdout) { should contain 'OK' }
its(:stdout) { should contain '[OK]' }
its(:stdout) { should_not contain 'ERROR' }
end

Expand Down