Skip to content

Commit 37e5a88

Browse files
authored
[AGENTONB-2490] Support remote_updates through embedded installer (#866)
* do not manage Agent with deprecated deb/rpm installer * Ensure Agent service is not running if experiment is running
1 parent 4ca062b commit 37e5a88

5 files changed

Lines changed: 147 additions & 270 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Facter.add(:datadog_agent_exp_active) do
2+
confine kernel: 'Linux'
3+
setcode do
4+
active = false
5+
6+
# Determine via service manager when available
7+
if Facter::Util::Resolution.which('systemctl')
8+
active = system('systemctl is-active --quiet datadog-agent-exp')
9+
elsif Facter::Util::Resolution.which('service')
10+
active = system('service datadog-agent-exp status >/dev/null 2>&1')
11+
elsif Facter::Util::Resolution.which('pgrep')
12+
# Fallback: look for the experiment agent binary as the running command (exact path prefix)
13+
active = system('pgrep -f "^/opt/datadog-packages/datadog-agent/experiment/bin/agent/agent( |$)" >/dev/null 2>&1')
14+
end
15+
16+
active
17+
end
18+
end

manifests/init.pp

Lines changed: 125 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -439,194 +439,101 @@
439439
default: { $_loglevel = 'INFO' }
440440
}
441441

442-
if $datadog_installer_enabled {
443-
# If instrumentation is enabled and the libraries are not set, default to pinned latest versions
444-
# Else, if user wants to install libraries without enabling instrumentation, use the provided libraries
445-
if $apm_instrumentation_enabled and ! $apm_instrumentation_libraries {
446-
$apm_instrumentation_libraries_str = join(['java:1', 'python:2', 'js:5', 'dotnet:3', 'ruby:2'], ',')
447-
} elsif $apm_instrumentation_libraries {
448-
$apm_instrumentation_libraries_str = join($apm_instrumentation_libraries, ',')
449-
} else {
450-
$apm_instrumentation_libraries_str = ''
451-
}
452-
# Agent version handling: the installer expects DD_AGENT_MINOR_VERSION to include the patch version.
453-
# $_agent_minor_version is the minor version without the patch version.
454-
# We need to add the patch version to the minor version to get the full version.
455-
# 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.
456-
if $_agent_minor_version != undef and $_agent_patch_version != undef {
457-
$_agent_minor_version_full = "${_agent_minor_version}.${_agent_patch_version}"
458-
} else {
459-
$_agent_minor_version_full = ''
460-
}
442+
# Install agent
443+
if $manage_install {
461444
case $facts['os']['name'] {
462-
'Ubuntu','Debian','Raspbian': {
463-
class { 'datadog_agent::ubuntu_installer':
464-
api_key => $api_key,
465-
datadog_site => $datadog_site,
466-
agent_major_version => $_agent_major_version,
467-
agent_minor_version => $_agent_minor_version_full,
468-
manage_agent_install => $manage_install,
469-
installer_repo_uri => $agent_repo_uri,
470-
release => $apt_release,
471-
skip_apt_key_trusting => $skip_apt_key_trusting,
472-
apm_instrumentation_enabled => $apm_instrumentation_enabled,
473-
apm_instrumentation_libraries_str => $apm_instrumentation_libraries_str,
474-
remote_updates => $remote_updates,
475-
remote_policies => $remote_policies,
445+
'Ubuntu','Debian','Raspbian' : {
446+
if $use_apt_backup_keyserver != undef or $apt_backup_keyserver != undef or $apt_keyserver != undef {
447+
notify { 'apt keyserver arguments deprecation':
448+
message => '$use_apt_backup_keyserver, $apt_backup_keyserver and $apt_keyserver are deprecated since version 3.13.0',
449+
loglevel => 'warning',
450+
}
476451
}
477-
}
478-
'RedHat','CentOS','Fedora','Amazon','Scientific','OracleLinux','AlmaLinux','Rocky' : {
479-
class { 'datadog_agent::redhat_installer':
480-
api_key => $api_key,
481-
datadog_site => $datadog_site,
482-
agent_major_version => $_agent_major_version,
483-
agent_minor_version => $_agent_minor_version_full,
484-
installer_repo_uri => $agent_repo_uri,
485-
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
486-
apm_instrumentation_enabled => $apm_instrumentation_enabled,
487-
apm_instrumentation_libraries_str => $apm_instrumentation_libraries_str,
488-
remote_updates => $remote_updates,
489-
remote_policies => $remote_policies,
452+
class { 'datadog_agent::ubuntu':
453+
agent_major_version => $_agent_major_version,
454+
agent_version => $agent_full_version,
455+
agent_flavor => $agent_flavor,
456+
agent_repo_uri => $agent_repo_uri,
457+
release => $apt_release,
458+
skip_apt_key_trusting => $skip_apt_key_trusting,
490459
}
491460
}
492-
'OpenSuSE', 'SLES' : {
493-
class { 'datadog_agent::suse_installer':
494-
api_key => $api_key,
495-
datadog_site => $datadog_site,
496-
agent_major_version => $_agent_major_version,
497-
agent_minor_version => $_agent_minor_version_full,
498-
installer_repo_uri => $agent_repo_uri,
499-
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
500-
apm_instrumentation_enabled => $apm_instrumentation_enabled,
501-
apm_instrumentation_libraries_str => $apm_instrumentation_libraries_str,
502-
remote_updates => $remote_updates,
503-
remote_policies => $remote_policies,
461+
'RedHat','CentOS','Fedora','Amazon','Scientific','OracleLinux','AlmaLinux','Rocky' : {
462+
class { 'datadog_agent::redhat':
463+
agent_major_version => $_agent_major_version,
464+
agent_flavor => $agent_flavor,
465+
agent_repo_uri => $agent_repo_uri,
466+
manage_repo => $manage_repo,
467+
agent_version => $agent_full_version,
468+
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
504469
}
505470
}
506-
default: { fail("Class[datadog_agent::installer]: Unsupported operatingsystem: ${facts['os']['name']}") }
507-
}
508-
}
509-
510-
# If the agent is managed by the installer, we don't need to manage the agent installation
511-
$_agent_managed_by_installer = ($datadog_installer_enabled and $remote_updates)
512-
513-
# Install agent
514-
if ! $_agent_managed_by_installer {
515-
if $manage_install {
516-
case $facts['os']['name'] {
517-
'Ubuntu','Debian','Raspbian' : {
518-
if $use_apt_backup_keyserver != undef or $apt_backup_keyserver != undef or $apt_keyserver != undef {
519-
notify { 'apt keyserver arguments deprecation':
520-
message => '$use_apt_backup_keyserver, $apt_backup_keyserver and $apt_keyserver are deprecated since version 3.13.0',
521-
loglevel => 'warning',
522-
}
523-
}
524-
class { 'datadog_agent::ubuntu':
525-
agent_major_version => $_agent_major_version,
526-
agent_version => $agent_full_version,
527-
agent_flavor => $agent_flavor,
528-
agent_repo_uri => $agent_repo_uri,
529-
release => $apt_release,
530-
skip_apt_key_trusting => $skip_apt_key_trusting,
531-
}
532-
}
533-
'RedHat','CentOS','Fedora','Amazon','Scientific','OracleLinux','AlmaLinux','Rocky' : {
534-
class { 'datadog_agent::redhat':
535-
agent_major_version => $_agent_major_version,
536-
agent_flavor => $agent_flavor,
537-
agent_repo_uri => $agent_repo_uri,
538-
manage_repo => $manage_repo,
539-
agent_version => $agent_full_version,
540-
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
541-
}
471+
'Windows' : {
472+
class { 'datadog_agent::windows' :
473+
agent_major_version => $_agent_major_version,
474+
agent_repo_uri => $agent_repo_uri,
475+
agent_version => $agent_full_version,
476+
msi_location => $win_msi_location,
477+
api_key => $api_key,
478+
hostname => $host,
479+
tags => $local_tags,
480+
ensure => $win_ensure,
481+
npm_install => $windows_npm_install,
482+
ddagentuser_name => $windows_ddagentuser_name,
483+
ddagentuser_password => $windows_ddagentuser_password,
542484
}
543-
'Windows' : {
544-
class { 'datadog_agent::windows' :
545-
agent_major_version => $_agent_major_version,
546-
agent_repo_uri => $agent_repo_uri,
547-
agent_version => $agent_full_version,
548-
msi_location => $win_msi_location,
549-
api_key => $api_key,
550-
hostname => $host,
551-
tags => $local_tags,
552-
ensure => $win_ensure,
553-
npm_install => $windows_npm_install,
554-
ddagentuser_name => $windows_ddagentuser_name,
555-
ddagentuser_password => $windows_ddagentuser_password,
556-
}
557-
if ($win_ensure == absent) {
558-
return() #Config files will remain unchanged on uninstall
559-
}
485+
if ($win_ensure == absent) {
486+
return() #Config files will remain unchanged on uninstall
560487
}
561-
'OpenSuSE', 'SLES' : {
562-
class { 'datadog_agent::suse' :
563-
agent_major_version => $_agent_major_version,
564-
agent_flavor => $agent_flavor,
565-
agent_repo_uri => $agent_repo_uri,
566-
agent_version => $agent_full_version,
567-
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
568-
}
569-
}
570-
default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${facts['os']['name']}") }
571488
}
572-
} else {
573-
if ! defined(Package[$agent_flavor]) {
574-
package { $agent_flavor:
575-
ensure => present,
576-
source => 'Agent installation not managed by Puppet, make sure the Agent is installed beforehand.',
489+
'OpenSuSE', 'SLES' : {
490+
class { 'datadog_agent::suse' :
491+
agent_major_version => $_agent_major_version,
492+
agent_flavor => $agent_flavor,
493+
agent_repo_uri => $agent_repo_uri,
494+
agent_version => $agent_full_version,
495+
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
577496
}
578497
}
498+
default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${facts['os']['name']}") }
499+
}
500+
} else {
501+
if ! defined(Package[$agent_flavor]) {
502+
package { $agent_flavor:
503+
ensure => present,
504+
source => 'Agent installation not managed by Puppet, make sure the Agent is installed beforehand.',
505+
}
579506
}
580507
}
581508

582509
# Declare service
583-
if ! $_agent_managed_by_installer {
584-
class { 'datadog_agent::service' :
585-
agent_flavor => $agent_flavor,
586-
service_ensure => $service_ensure,
587-
service_enable => $service_enable,
588-
service_provider => $service_provider,
589-
}
590-
if ($facts['os']['name'] != 'Windows') {
591-
if ($dd_groups) {
592-
user { $dd_user:
593-
groups => $dd_groups,
594-
notify => Service[$datadog_agent::params::service_name],
595-
}
596-
}
510+
if ($facts['os']['name'] != 'Windows' and $facts['datadog_agent_exp_active'] == true) {
511+
$_service_ensure = 'stopped'
512+
} else {
513+
$_service_ensure = $service_ensure
514+
}
597515

598-
# required by reports even in agent5 scenario
599-
file { '/etc/datadog-agent':
600-
ensure => directory,
601-
owner => $dd_user,
602-
group => $dd_group,
603-
mode => $datadog_agent::params::permissions_directory,
604-
require => Package[$agent_flavor],
516+
class { 'datadog_agent::service' :
517+
agent_flavor => $agent_flavor,
518+
service_ensure => $_service_ensure,
519+
service_enable => $service_enable,
520+
service_provider => $service_provider,
521+
}
522+
if ($facts['os']['name'] != 'Windows') {
523+
if ($dd_groups) {
524+
user { $dd_user:
525+
groups => $dd_groups,
526+
notify => Service[$datadog_agent::params::service_name],
605527
}
606528
}
607-
} else {
608-
class { 'datadog_agent::service' :
609-
# Declare service for agent managed by installer with installer flavor
610-
agent_flavor => 'datadog-installer',
611-
service_ensure => $service_ensure,
612-
service_enable => $service_enable,
613-
service_provider => $service_provider,
614-
}
615-
if ($facts['os']['name'] != 'Windows') {
616-
if ($dd_groups) {
617-
user { $dd_user:
618-
groups => $dd_groups,
619-
notify => Service[$datadog_agent::params::service_name],
620-
}
621-
}
622-
# required to manage config and install info files even with installer
623-
file { '/etc/datadog-agent':
624-
ensure => directory,
625-
owner => $dd_user,
626-
group => $dd_group,
627-
mode => $datadog_agent::params::permissions_directory,
628-
require => Package['datadog-installer'],
629-
}
529+
530+
# required by reports even in agent5 scenario
531+
file { '/etc/datadog-agent':
532+
ensure => directory,
533+
owner => $dd_user,
534+
group => $dd_group,
535+
mode => $datadog_agent::params::permissions_directory,
536+
require => Package[$agent_flavor],
630537
}
631538
}
632539

@@ -751,10 +658,7 @@
751658
force => $conf_dir_purge,
752659
owner => $dd_user,
753660
group => $dd_group,
754-
}
755-
756-
if ! $_agent_managed_by_installer {
757-
File[$_conf_dir] ~> Service[$datadog_agent::params::service_name]
661+
notify => Service[$datadog_agent::params::service_name],
758662
}
759663

760664
$_local_tags = datadog_agent::tag6($local_tags, false, undef)
@@ -851,4 +755,51 @@
851755
}
852756

853757
create_resources('datadog_agent::integration', $local_integrations)
758+
759+
# Install the deprecated RPM/DEB installer if APM instrumentation is enabled
760+
if $datadog_installer_enabled {
761+
# If instrumentation is enabled and the libraries are not set, default to pinned latest versions
762+
# Else, if user wants to install libraries without enabling instrumentation, use the provided libraries
763+
if $apm_instrumentation_enabled and ! $apm_instrumentation_libraries {
764+
$apm_instrumentation_libraries_str = join(['java:1', 'python:2', 'js:5', 'dotnet:3', 'ruby:2'], ',')
765+
} elsif $apm_instrumentation_libraries {
766+
$apm_instrumentation_libraries_str = join($apm_instrumentation_libraries, ',')
767+
} else {
768+
$apm_instrumentation_libraries_str = ''
769+
}
770+
case $facts['os']['name'] {
771+
'Ubuntu','Debian','Raspbian': {
772+
class { 'datadog_agent::ubuntu_installer':
773+
api_key => $api_key,
774+
datadog_site => $datadog_site,
775+
installer_repo_uri => $agent_repo_uri,
776+
release => $apt_release,
777+
skip_apt_key_trusting => $skip_apt_key_trusting,
778+
apm_instrumentation_enabled => $apm_instrumentation_enabled,
779+
apm_instrumentation_libraries_str => $apm_instrumentation_libraries_str,
780+
}
781+
}
782+
'RedHat','CentOS','Fedora','Amazon','Scientific','OracleLinux','AlmaLinux','Rocky' : {
783+
class { 'datadog_agent::redhat_installer':
784+
api_key => $api_key,
785+
datadog_site => $datadog_site,
786+
installer_repo_uri => $agent_repo_uri,
787+
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
788+
apm_instrumentation_enabled => $apm_instrumentation_enabled,
789+
apm_instrumentation_libraries_str => $apm_instrumentation_libraries_str,
790+
}
791+
}
792+
'OpenSuSE', 'SLES' : {
793+
class { 'datadog_agent::suse_installer':
794+
api_key => $api_key,
795+
datadog_site => $datadog_site,
796+
installer_repo_uri => $agent_repo_uri,
797+
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
798+
apm_instrumentation_enabled => $apm_instrumentation_enabled,
799+
apm_instrumentation_libraries_str => $apm_instrumentation_libraries_str,
800+
}
801+
}
802+
default: { fail("Class[datadog_agent::installer]: Unsupported operatingsystem: ${facts['os']['name']}") }
803+
}
804+
}
854805
}

0 commit comments

Comments
 (0)