Skip to content

Commit

Permalink
[CECO-1729] Installer support (#820)
Browse files Browse the repository at this point in the history
* Add installer support

* Add installer telemetry

* Add installer kitchen test

* (review): nits + import future GPG keys
  • Loading branch information
tbavelier authored Nov 27, 2024
1 parent f7d8383 commit da74780
Show file tree
Hide file tree
Showing 13 changed files with 946 additions and 72 deletions.
10 changes: 10 additions & 0 deletions environments/etc/installer-manifests/site.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node default {
class { 'datadog_agent':
api_key => 'somenonnullapikeythats32charlong',
manage_install => false,
datadog_installer_enabled => true,
apm_instrumentation_enabled => 'host',
apm_instrumentation_libraries => ['java:1', 'python:2'],
remote_updates => false,
}
}
12 changes: 12 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,15 @@ suites:
TARGET_PORT: 2222
LOGIN_USER: root
LOGIN_PASSWORD: puppet
- name: dd-installer
manifests: init.pp
provisioner:
manifests_path: environments/etc/installer-manifests
verifier:
default_pattern: true
additional_install_commmand: source /etc/profile.d/rvm.sh
env_vars:
TARGET_HOST: 127.0.0.1
TARGET_PORT: 2222
LOGIN_USER: root
LOGIN_PASSWORD: puppet
247 changes: 175 additions & 72 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,20 @@
#
# $windows_ddagentuser_password
# (Windows only) The password used to register the service`.
# $datadog_installer_enabled
# Boolean to enable or disable the Datadog installer.
# Boolean. Default: undef (false)
# $apm_instrumentation_enabled
# Configure APM instrumentation. Possible values are:
# - host: Both the Agent and your services are running on a host.
# - docker: The Agent and your services are running in separate Docker containers on the same host.
# - all: Supports all the previous scenarios for host and docker at the same time.
# $apm_instrumentation_libraries
# List of APM libraries to install. If not defined and APM instrumentation is set,
# the default libraries are pinned: ['java:1', 'python:2', 'js:5', 'dotnet:3', 'ruby:2']
# $remote_updates
# Boolean to enable or disable Agent remote updates.
# Boolean. Default: false
#
# Sample Usage:
#
Expand All @@ -257,7 +271,7 @@
# }
#
#
class datadog_agent(
class datadog_agent (
String $dd_url = '',
String $datadog_site = $datadog_agent::params::datadog_site,
String $host = '',
Expand Down Expand Up @@ -285,6 +299,7 @@
Boolean $manage_repo = true,
Boolean $manage_dogapi_gem = true,
Boolean $manage_install = true,
Optional[Boolean] $datadog_installer_enabled = undef,
$hostname_extraction_regex = undef,
Boolean $hostname_fqdn = false,
Variant[Stdlib::Port, Pattern[/^\d*$/]] $dogstatsd_port = 8125,
Expand Down Expand Up @@ -368,6 +383,9 @@
Boolean $windows_npm_install = false,
Optional[String] $windows_ddagentuser_name = undef,
Optional[String] $windows_ddagentuser_password = undef,
Boolean $remote_updates = $datadog_agent::params::remote_updates,
Optional[Enum['host', 'docker', 'all']] $apm_instrumentation_enabled = undef,
Optional[Array[String]] $apm_instrumentation_libraries = undef,
) inherits datadog_agent::params {

#In this regex, version '1:6.15.0~rc.1-1' would match as $1='1:', $2='6', $3='15', $4='0', $5='~rc.1', $6='1'
Expand All @@ -377,6 +395,7 @@
fail('Provided and deduced agent_major_version don\'t match')
}
$_agent_minor_version = 0 + $3
$_agent_patch_version = 0 + $4
} elsif $agent_major_version != undef {
$_agent_major_version = $agent_major_version
} else {
Expand Down Expand Up @@ -441,96 +460,176 @@
default: { $_loglevel = 'INFO' }
}

# Install agent
if $manage_install {
if $datadog_installer_enabled {
# If instrumentation is enabled and the libraries are not set, default to pinned latest versions
# Else, if user wants to install libraries without enabling instrumentation, use the provided libraries
if $apm_instrumentation_enabled and ! $apm_instrumentation_libraries {
$apm_instrumentation_libraries_str = join(['java:1', 'python:2', 'js:5', 'dotnet:3', 'ruby:2'], ',')
} elsif $apm_instrumentation_libraries {
$apm_instrumentation_libraries_str = join($apm_instrumentation_libraries, ',')
} else {
$apm_instrumentation_libraries_str = ''
}
# Agent version handling: the installer expects DD_AGENT_MINOR_VERSION to include the patch version.
# $_agent_minor_version is the minor version without the patch version.
# We need to add the patch version to the minor version to get the full version.
# If minor and patch version were not extracted (e.g. user is simply providing agent_major_version), we use an empty string for the minor version.
if $_agent_minor_version != undef and $_agent_patch_version != undef {
$_agent_minor_version_full = "${_agent_minor_version}.${_agent_patch_version}"
} else {
$_agent_minor_version_full = ''
}
case $facts['os']['name'] {
'Ubuntu','Debian','Raspbian' : {
if $use_apt_backup_keyserver != undef or $apt_backup_keyserver != undef or $apt_keyserver != undef {
notify { 'apt keyserver arguments deprecation':
message => '$use_apt_backup_keyserver, $apt_backup_keyserver and $apt_keyserver are deprecated since version 3.13.0',
loglevel => 'warning',
}
}
class { 'datadog_agent::ubuntu':
agent_major_version => $_agent_major_version,
agent_version => $agent_full_version,
agent_flavor => $agent_flavor,
agent_repo_uri => $agent_repo_uri,
release => $apt_release,
skip_apt_key_trusting => $skip_apt_key_trusting,
'Ubuntu','Debian','Raspbian': {
class { 'datadog_agent::ubuntu_installer':
api_key => $api_key,
datadog_site => $datadog_site,
agent_major_version => $_agent_major_version,
agent_minor_version => $_agent_minor_version_full,
manage_agent_install => $manage_install,
installer_repo_uri => $agent_repo_uri,
release => $apt_release,
skip_apt_key_trusting => $skip_apt_key_trusting,
apm_instrumentation_enabled => $apm_instrumentation_enabled,
apm_instrumentation_libraries_str => $apm_instrumentation_libraries_str,
remote_updates => $remote_updates,
}
}
'RedHat','CentOS','Fedora','Amazon','Scientific','OracleLinux','AlmaLinux','Rocky' : {
class { 'datadog_agent::redhat':
agent_major_version => $_agent_major_version,
agent_flavor => $agent_flavor,
agent_repo_uri => $agent_repo_uri,
manage_repo => $manage_repo,
agent_version => $agent_full_version,
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
}
}
'Windows' : {
class { 'datadog_agent::windows' :
agent_major_version => $_agent_major_version,
agent_repo_uri => $agent_repo_uri,
agent_version => $agent_full_version,
msi_location => $win_msi_location,
api_key => $api_key,
hostname => $host,
tags => $local_tags,
ensure => $win_ensure,
npm_install => $windows_npm_install,
ddagentuser_name => $windows_ddagentuser_name,
ddagentuser_password => $windows_ddagentuser_password,
}
if ($win_ensure == absent) {
return() #Config files will remain unchanged on uninstall
class { 'datadog_agent::redhat_installer':
api_key => $api_key,
datadog_site => $datadog_site,
agent_major_version => $_agent_major_version,
agent_minor_version => $_agent_minor_version_full,
installer_repo_uri => $agent_repo_uri,
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
apm_instrumentation_enabled => $apm_instrumentation_enabled,
apm_instrumentation_libraries_str => $apm_instrumentation_libraries_str,
remote_updates => $remote_updates,
}
}
'OpenSuSE', 'SLES' : {
class { 'datadog_agent::suse' :
agent_major_version => $_agent_major_version,
agent_flavor => $agent_flavor,
agent_repo_uri => $agent_repo_uri,
agent_version => $agent_full_version,
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
class { 'datadog_agent::suse_installer':
api_key => $api_key,
datadog_site => $datadog_site,
agent_major_version => $_agent_major_version,
agent_minor_version => $_agent_minor_version_full,
installer_repo_uri => $agent_repo_uri,
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
apm_instrumentation_enabled => $apm_instrumentation_enabled,
apm_instrumentation_libraries_str => $apm_instrumentation_libraries_str,
remote_updates => $remote_updates,
}
}
default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${facts['os']['name']}") }
default: { fail("Class[datadog_agent::installer]: Unsupported operatingsystem: ${facts['os']['name']}") }
}
} else {
if ! defined(Package[$agent_flavor]) {
package { $agent_flavor:
ensure => present,
source => 'Agent installation not managed by Puppet, make sure the Agent is installed beforehand.',
}

# If the agent is managed by the installer, we don't need to manage the agent installation
$_agent_managed_by_installer = ($datadog_installer_enabled and $remote_updates)

# Install agent
if ! $_agent_managed_by_installer {
if $manage_install {
case $facts['os']['name'] {
'Ubuntu','Debian','Raspbian' : {
if $use_apt_backup_keyserver != undef or $apt_backup_keyserver != undef or $apt_keyserver != undef {
notify { 'apt keyserver arguments deprecation':
message => '$use_apt_backup_keyserver, $apt_backup_keyserver and $apt_keyserver are deprecated since version 3.13.0',
loglevel => 'warning',
}
}
class { 'datadog_agent::ubuntu':
agent_major_version => $_agent_major_version,
agent_version => $agent_full_version,
agent_flavor => $agent_flavor,
agent_repo_uri => $agent_repo_uri,
release => $apt_release,
skip_apt_key_trusting => $skip_apt_key_trusting,
}
}
'RedHat','CentOS','Fedora','Amazon','Scientific','OracleLinux','AlmaLinux','Rocky' : {
class { 'datadog_agent::redhat':
agent_major_version => $_agent_major_version,
agent_flavor => $agent_flavor,
agent_repo_uri => $agent_repo_uri,
manage_repo => $manage_repo,
agent_version => $agent_full_version,
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
}
}
'Windows' : {
class { 'datadog_agent::windows' :
agent_major_version => $_agent_major_version,
agent_repo_uri => $agent_repo_uri,
agent_version => $agent_full_version,
msi_location => $win_msi_location,
api_key => $api_key,
hostname => $host,
tags => $local_tags,
ensure => $win_ensure,
npm_install => $windows_npm_install,
ddagentuser_name => $windows_ddagentuser_name,
ddagentuser_password => $windows_ddagentuser_password,
}
if ($win_ensure == absent) {
return() #Config files will remain unchanged on uninstall
}
}
'OpenSuSE', 'SLES' : {
class { 'datadog_agent::suse' :
agent_major_version => $_agent_major_version,
agent_flavor => $agent_flavor,
agent_repo_uri => $agent_repo_uri,
agent_version => $agent_full_version,
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
}
}
default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${facts['os']['name']}") }
}
} else {
if ! defined(Package[$agent_flavor]) {
package { $agent_flavor:
ensure => present,
source => 'Agent installation not managed by Puppet, make sure the Agent is installed beforehand.',
}
}
}
}

# Declare service
class { 'datadog_agent::service' :
agent_flavor => $agent_flavor,
service_ensure => $service_ensure,
service_enable => $service_enable,
service_provider => $service_provider,
}
if ! $_agent_managed_by_installer {
class { 'datadog_agent::service' :
agent_flavor => $agent_flavor,
service_ensure => $service_ensure,
service_enable => $service_enable,
service_provider => $service_provider,
}
if ($facts['os']['name'] != 'Windows') {
if ($dd_groups) {
user { $dd_user:
groups => $dd_groups,
notify => Service[$datadog_agent::params::service_name],
}
}

if ($facts['os']['name'] != 'Windows') {
if ($dd_groups) {
user { $dd_user:
groups => $dd_groups,
notify => Service[$datadog_agent::params::service_name],
# required by reports even in agent5 scenario
file { '/etc/datadog-agent':
ensure => directory,
owner => $dd_user,
group => $dd_group,
mode => $datadog_agent::params::permissions_directory,
require => Package[$agent_flavor],
}
}

# required by reports even in agent5 scenario
} else {
# required to manage config and install info files even with installer
file { '/etc/datadog-agent':
ensure => directory,
owner => $dd_user,
group => $dd_group,
mode => $datadog_agent::params::permissions_directory,
require => Package[$agent_flavor],
require => Package['datadog-installer'],
}
}

Expand Down Expand Up @@ -766,7 +865,10 @@
force => $conf_dir_purge,
owner => $dd_user,
group => $dd_group,
notify => Service[$datadog_agent::params::service_name]
}

if ! $_agent_managed_by_installer {
File[$_conf_dir] ~> Service[$datadog_agent::params::service_name]
}

$_local_tags = datadog_agent::tag6($local_tags, false, undef)
Expand All @@ -788,12 +890,12 @@
'dogstatsd_non_local_traffic' => $non_local_traffic,
'log_file' => $agent_log_file,
'log_level' => $log_level,
'remote_updates' => $remote_updates,
'tags' => unique(flatten(union($_local_tags, $_facts_tags, $_trusted_facts_tags))),
}

$agent_config = deep_merge($_agent_config, $extra_config)


if ($facts['os']['name'] == 'Windows') {


Expand Down Expand Up @@ -827,9 +929,11 @@
mode => '0640',
content => template('datadog_agent/datadog.yaml.erb'),
show_diff => false,
notify => Service[$datadog_agent::params::service_name],
require => File['/etc/datadog-agent'],
}
if ! $_agent_managed_by_installer {
File['/etc/datadog-agent/datadog.yaml'] ~> Service[$datadog_agent::params::service_name]
}

file { '/etc/datadog-agent/install_info':
owner => $dd_user,
Expand All @@ -838,7 +942,6 @@
content => template('datadog_agent/install_info.erb'),
require => File['/etc/datadog-agent'],
}

}

}
Expand Down
Loading

0 comments on commit da74780

Please sign in to comment.