From 6450f948426dcc177b3d83a497d3cee6ba438098 Mon Sep 17 00:00:00 2001 From: Fanny Jiang Date: Fri, 14 Feb 2025 09:29:27 -0500 Subject: [PATCH 1/8] fix tests --- .rubocop | 1 + .rubocop.yml | 2 +- Gemfile | 4 +- Gemfile.lock | 10 ++-- lib/puppet/reports/datadog_reports.rb | 2 +- manifests/integrations/disk.pp | 16 +----- .../datadog_agent_integrations_disk_spec.rb | 57 ++++++++++--------- spec/classes/datadog_agent_reports_spec.rb | 15 +++++ spec/classes/datadog_agent_spec.rb | 12 ++++ spec/classes/datadog_agent_ubuntu_spec.rb | 18 ++++++ spec/default_facts.yml | 4 -- templates/agent-conf.d/disk.yaml.erb | 8 ++- 12 files changed, 95 insertions(+), 54 deletions(-) diff --git a/.rubocop b/.rubocop index fc40e8e2..92530682 100644 --- a/.rubocop +++ b/.rubocop @@ -1 +1,2 @@ --ignore-unrecognized-cops +--autocorrect \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml index d464e5c3..bb7b4a33 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,7 +5,7 @@ require: AllCops: NewCops: enable DisplayCopNames: true - TargetRubyVersion: '2.6' + TargetRubyVersion: '3.3' Include: - "**/*.rb" Exclude: diff --git a/Gemfile b/Gemfile index 9e439191..5cd72cd0 100644 --- a/Gemfile +++ b/Gemfile @@ -47,11 +47,11 @@ group :development do gem "voxpupuli-puppet-lint-plugins", '~> 4.0', require: false gem "dependency_checker", '= 0.3.0', require: false else - gem "facterdb", '~> 2.1', require: false + gem "facterdb", '~> 3.4.0', require: false gem "test-kitchen", '~> 3.7.0' gem "rubocop", '~> 1.50.0', require: false gem "rubocop-rspec", '= 2.19.0', require: false - gem "rspec-puppet-facts", '~> 4.0', require: false + gem "rspec-puppet-facts", '~> 5.2.0', require: false gem "rubocop-performance", '= 1.16.0', require: false gem "librarian-puppet", '~> 5.0' gem "io-console", '= 0.7.2', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 9f6f1a43..2f2b1695 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -74,7 +74,7 @@ GEM facter (4.10.0) hocon (~> 1.3) thor (>= 1.0.1, < 1.3) - facterdb (2.1.0) + facterdb (3.4.0) facter (< 5.0.0) jgrep (~> 1.5, >= 1.5.4) faraday (2.12.2) @@ -366,10 +366,10 @@ GEM rspec-support (~> 3.13.0) rspec-puppet (5.0.0) rspec (~> 3.0) - rspec-puppet-facts (4.0.0) + rspec-puppet-facts (5.2.0) deep_merge (~> 1.2) facter (< 5) - facterdb (~> 2.1) + facterdb (~> 3.1) puppet (>= 7, < 9) rspec-support (3.13.2) rsync (1.0.9) @@ -526,7 +526,7 @@ DEPENDENCIES bcrypt_pbkdf (= 1.0.1) deep_merge (~> 1.2.2) dependency_checker (~> 1.0.0) - facterdb (~> 2.1) + facterdb (~> 3.4.0) io-console (= 0.7.2) json (= 2.6.3) kitchen-docker (~> 3.0.0) @@ -545,7 +545,7 @@ DEPENDENCIES puppetlabs_spec_helper (~> 8.0) rb-readline (= 0.5.5) rexml (~> 3.4.0) - rspec-puppet-facts (~> 4.0) + rspec-puppet-facts (~> 5.2.0) rubocop (~> 1.50.0) rubocop-performance (= 1.16.0) rubocop-rspec (= 2.19.0) diff --git a/lib/puppet/reports/datadog_reports.rb b/lib/puppet/reports/datadog_reports.rb index b33de959..df29af71 100644 --- a/lib/puppet/reports/datadog_reports.rb +++ b/lib/puppet/reports/datadog_reports.rb @@ -147,7 +147,7 @@ def process msg_title: event_title, event_type: 'config_management.run', event_object: @msg_host, - alert_type: alert_type, + alert_type:, priority: event_priority, source_type_name: 'puppet', tags: dog_tags), diff --git a/manifests/integrations/disk.pp b/manifests/integrations/disk.pp index fbd58372..715a7f96 100644 --- a/manifests/integrations/disk.pp +++ b/manifests/integrations/disk.pp @@ -63,9 +63,9 @@ # excluded_disk_re => '/dev/sd[e-z]*' # } class datadog_agent::integrations::disk ( - String $use_mount = 'no', - Optional[String] $all_partitions = undef, - Optional[String] $tag_by_filesystem = undef, + Optional[Boolean] $use_mount = undef, + Optional[Boolean] $all_partitions = undef, + Optional[Boolean] $tag_by_filesystem = undef, Optional[Array[String]] $filesystem_exclude = undef, Optional[Array[String]] $device_exclude = undef, Optional[Array[String]] $mountpoint_exclude = undef, @@ -85,16 +85,6 @@ ) inherits datadog_agent::params { require datadog_agent - # check that $all_partitions is either no or yes - if $all_partitions !~ '^(no|yes)$' { - fail('all_partitions must be either no or yes') - } - - # check that $use_mount is either no or yes - if $use_mount !~ '^(no|yes)$' { - fail('use_mount must be either no or yes') - } - $legacy_dst = "${datadog_agent::params::legacy_conf_dir}/disk.yaml" if $datadog_agent::_agent_major_version > 5 { $dst_dir = "${datadog_agent::params::conf_dir}/disk.d" diff --git a/spec/classes/datadog_agent_integrations_disk_spec.rb b/spec/classes/datadog_agent_integrations_disk_spec.rb index 77ee5631..0364b6f2 100644 --- a/spec/classes/datadog_agent_integrations_disk_spec.rb +++ b/spec/classes/datadog_agent_integrations_disk_spec.rb @@ -5,17 +5,22 @@ context 'supported agents' do let(:pre_condition) { "class {'::datadog_agent': agent_major_version => #{agent_major_version}}" } - conf_file = if agent_major_version == 5 - '/etc/dd-agent/conf.d/disk.yaml' - else - "#{CONF_DIR}/disk.d/conf.yaml" - end + let(:yaml_conf) do + <<-HEREDOC +### MANAGED BY PUPPET + +init_config: + +instances: + - use_mount: false + HEREDOC + end + + conf_file = "#{CONF_DIR}/disk.d/conf.yaml" it { is_expected.to compile.with_all_deps } it { - is_expected.to contain_file(conf_file).with_content( - %r{\s+use_mount:\s+no[\r]*$}, - ).with( + is_expected.to contain_file(conf_file).with_content(yaml_conf).with( owner: DD_USER, group: DD_GROUP, mode: PERMISSIONS_PROTECTED_FILE, @@ -39,13 +44,13 @@ context 'we handle strings and arrays the same' do let(:params) do { - use_mount: 'yes', + use_mount: true, excluded_filesystems: ['tmpfs', 'dev'], excluded_disks: '/dev/sda1', excluded_disk_re: '/dev/sdb.*', excluded_mountpoint_re: '/mnt/other.*', - all_partitions: 'yes', - tag_by_filesystem: 'no', + all_partitions: true, + tag_by_filesystem: false, } end let(:yaml_conf) do @@ -55,7 +60,7 @@ init_config: instances: - - use_mount: yes + - use_mount: true excluded_filesystems: - tmpfs - dev @@ -63,8 +68,8 @@ - /dev/sda1 excluded_disk_re: /dev/sdb.* excluded_mountpoint_re: /mnt/other.* - all_partitions: yes - tag_by_filesystem: no + all_partitions: true + tag_by_filesystem: false HEREDOC end @@ -74,15 +79,15 @@ context 'we handle new disk configuration option' do let(:params) do { - use_mount: 'yes', + use_mount: true, filesystem_blacklist: ['tmpfs', 'dev'], device_blacklist: ['/dev/sda1'], mountpoint_blacklist: ['/mnt/foo'], filesystem_whitelist: ['ext4', 'hdfs', 'reiserfs'], device_whitelist: ['/dev/sdc1', '/dev/sdc2', '/dev/sdd2'], mountpoint_whitelist: ['/mnt/logs', '/mnt/builds'], - all_partitions: 'yes', - tag_by_filesystem: 'no', + all_partitions: true, + tag_by_filesystem: false, } end let(:yaml_conf) do @@ -92,7 +97,7 @@ init_config: instances: - - use_mount: yes + - use_mount: true file_system_blacklist: - tmpfs - dev @@ -111,8 +116,8 @@ mount_point_whitelist: - /mnt/logs - /mnt/builds - all_partitions: yes - tag_by_filesystem: no + all_partitions: true + tag_by_filesystem: false HEREDOC end @@ -122,15 +127,15 @@ context 'agent_version >= 7.24.0 disk configuration option' do let(:params) do { - use_mount: 'yes', + use_mount: true, filesystem_exclude: ['tmpfs', 'dev'], device_exclude: ['/dev/sda1'], mountpoint_exclude: ['/mnt/foo'], filesystem_include: ['ext4', 'hdfs', 'reiserfs'], device_include: ['/dev/sdc1', '/dev/sdc2', '/dev/sdd2'], mountpoint_include: ['/mnt/logs', '/mnt/builds'], - all_partitions: 'yes', - tag_by_filesystem: 'no', + all_partitions: true, + tag_by_filesystem: false, } end let(:yaml_conf) do @@ -140,7 +145,7 @@ init_config: instances: - - use_mount: yes + - use_mount: true file_system_exclude: - tmpfs - dev @@ -159,8 +164,8 @@ mount_point_include: - /mnt/logs - /mnt/builds - all_partitions: yes - tag_by_filesystem: no + all_partitions: true + tag_by_filesystem: false HEREDOC end diff --git a/spec/classes/datadog_agent_reports_spec.rb b/spec/classes/datadog_agent_reports_spec.rb index a88c2041..1ef0ec64 100644 --- a/spec/classes/datadog_agent_reports_spec.rb +++ b/spec/classes/datadog_agent_reports_spec.rb @@ -28,6 +28,9 @@ 'major' => getosmajor(operatingsystem), 'full' => getosrelease(operatingsystem), }, + 'distro' => { + 'codename' => getoscodename(operatingsystem), + } }, } end @@ -95,6 +98,9 @@ 'major' => '8', 'full' => '8.1', }, + 'distro' => { + 'codename' => 'jessie', + } }, } end @@ -144,6 +150,9 @@ 'major' => '8', 'full' => '8.1', }, + 'distro' => { + 'codename' => 'jessie', + } }, } end @@ -188,6 +197,9 @@ 'major' => '8', 'full' => '8.1', }, + 'distro' => { + 'codename' => 'jessie', + } }, } end @@ -234,6 +246,9 @@ 'major' => '8', 'full' => '8.1', }, + 'distro' => { + 'codename' => 'jessie', + } }, } end diff --git a/spec/classes/datadog_agent_spec.rb b/spec/classes/datadog_agent_spec.rb index bbc47014..60e59342 100644 --- a/spec/classes/datadog_agent_spec.rb +++ b/spec/classes/datadog_agent_spec.rb @@ -14,6 +14,9 @@ 'major' => '3', 'full' => '3.0', }, + 'distro' => { + 'codename' => 'nexenta', + } }, } end @@ -68,6 +71,9 @@ 'major' => '14', 'full' => '14.04', }, + 'distro' => { + 'codename' => 'trusty', + }, }, } end @@ -94,6 +100,9 @@ 'major' => '14', 'full' => '14.04', }, + 'distro' => { + 'codename' => 'trusty', + }, }, } end @@ -120,6 +129,9 @@ 'major' => '14', 'full' => '14.04', }, + 'distro' => { + 'codename' => 'trusty', + }, }, } end diff --git a/spec/classes/datadog_agent_ubuntu_spec.rb b/spec/classes/datadog_agent_ubuntu_spec.rb index 6de162e5..ee6ef100 100644 --- a/spec/classes/datadog_agent_ubuntu_spec.rb +++ b/spec/classes/datadog_agent_ubuntu_spec.rb @@ -94,6 +94,9 @@ 'major' => '14', 'full' => '14.04', }, + 'distro' => { + 'codename' => 'trusty', + } }, } end @@ -146,6 +149,9 @@ 'major' => '14', 'full' => '14.04', }, + 'distro' => { + 'codename' => 'trusty', + } }, } end @@ -195,6 +201,9 @@ 'major' => '14', 'full' => '14.04', }, + 'distro' => { + 'codename' => 'trusty', + } }, } end @@ -219,6 +228,9 @@ 'major' => '16', 'full' => '16.04', }, + 'distro' => { + 'codename' => 'xenial', + } }, } end @@ -243,6 +255,9 @@ 'major' => '8', 'full' => '8.0', }, + 'distro' => { + 'codename' => 'jessie', + } }, } end @@ -267,6 +282,9 @@ 'major' => '9', 'full' => '9.0', }, + 'distro' => { + 'codename' => 'stretch', + } }, } end diff --git a/spec/default_facts.yml b/spec/default_facts.yml index ac3ae8cb..3346c394 100644 --- a/spec/default_facts.yml +++ b/spec/default_facts.yml @@ -7,7 +7,3 @@ networking: ip6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" mac: "AA:AA:AA:AA:AA:AA" is_pe: false - -os: - distro: - codename: "jammy" \ No newline at end of file diff --git a/templates/agent-conf.d/disk.yaml.erb b/templates/agent-conf.d/disk.yaml.erb index 5681f4b3..5d7e9076 100644 --- a/templates/agent-conf.d/disk.yaml.erb +++ b/templates/agent-conf.d/disk.yaml.erb @@ -3,7 +3,11 @@ init_config: instances: +<% if @use_mount.nil? -%> + - use_mount: false +<% else -%> - use_mount: <%= @use_mount %> +<% end -%> <% if @filesystem_blacklist -%> file_system_blacklist: <% (Array(@filesystem_blacklist)).each do |fs| -%> @@ -94,9 +98,9 @@ instances: <% if @excluded_mountpoint_re -%> excluded_mountpoint_re: <%= @excluded_mountpoint_re %> <% end -%> -<% if @all_partitions -%> +<% if not @all_partitions.nil? -%> all_partitions: <%= @all_partitions %> <% end -%> -<% if @tag_by_filesystem -%> +<% if not @tag_by_filesystem.nil? -%> tag_by_filesystem: <%= @tag_by_filesystem %> <% end -%> From 5e3f94178d8106afbc7d28207dca28146f73fe35 Mon Sep 17 00:00:00 2001 From: Fanny Jiang Date: Fri, 14 Feb 2025 09:31:03 -0500 Subject: [PATCH 2/8] fix tests --- spec/spec_helper.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f51f1b1d..0989f844 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -71,6 +71,16 @@ def getosrelease(operatingsystem) end end +def getoscodename(operatingsystem) + if DEBIAN_OS.include?(operatingsystem) + 'trusty' + elsif REDHAT_OS.include?(operatingsystem) + 'maipo' + else + 'seattle' + end +end + # Get parameters from catalogue. def get_from_catalogue(type, name, parameter) catalogue.resource(type, name).send(:parameters)[parameter.to_sym] @@ -96,6 +106,9 @@ def get_from_catalogue(type, name, parameter) minor: (RSpec::Support::OS.windows? ? 'SP1' : '04'), full: (RSpec::Support::OS.windows? ? '2019 SP1' : '14.04'), }, + 'distro' => { + 'codename' => (RSpec::Support::OS.windows? ? 'seattle' : 'focal'), + }, } } From a4c7b88e3e412b88d36ffe709a22b9733caaa39b Mon Sep 17 00:00:00 2001 From: Fanny Jiang Date: Fri, 14 Feb 2025 09:44:09 -0500 Subject: [PATCH 3/8] remove agent 5 --- manifests/init.pp | 431 ++--- .../datadog_agent_integrations_kafka_spec.rb | 6 +- spec/classes/datadog_agent_redhat_spec.rb | 60 - spec/classes/datadog_agent_spec.rb | 1449 +---------------- spec/classes/datadog_agent_ubuntu_spec.rb | 54 - spec/spec_helper.rb | 2 +- templates/agent-conf.d/cassandra.yaml.erb | 3 +- templates/agent-conf.d/kafka.yaml.erb | 6 - 8 files changed, 190 insertions(+), 1821 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index b124f2f8..badd8b62 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -646,309 +646,198 @@ } } - if $_agent_major_version == 5 { - if ($facts['os']['name'] == 'Windows') { - fail('Installation of agent 5 with puppet is not supported on Windows') - } - - if !empty($agent_extra_options) { - notify { 'Setting agent_extra_options has no effect with Agent 5': } - } - - file { '/etc/dd-agent': - ensure => directory, - owner => $dd_user, - group => $dd_group, - mode => $datadog_agent::params::permissions_directory, - require => Package[$agent_flavor], - } - - file { $_conf_dir: - ensure => directory, - purge => $conf_dir_purge, - recurse => true, - force => $conf_dir_purge, - owner => $dd_user, - group => $dd_group, - notify => Service[$datadog_agent::params::service_name], - } - - concat { '/etc/dd-agent/datadog.conf': - owner => $dd_user, - group => $dd_group, - mode => '0640', - notify => Service[$datadog_agent::params::service_name], - require => File['/etc/dd-agent'], - } - - if $dd_url.empty { - $_dd_url = 'https://app.datadoghq.com' - } else { - $_dd_url = $dd_url - } - concat::fragment { 'datadog header': - target => '/etc/dd-agent/datadog.conf', - content => template('datadog_agent/datadog_header.conf.erb'), - order => '01', - } - - concat::fragment { 'datadog tags': - target => '/etc/dd-agent/datadog.conf', - content => 'tags: ', - order => '02', - } - - datadog_agent::tag5 { $local_tags: } - datadog_agent::tag5 { $facts_to_tags: - lookup_fact => true, - } - - concat::fragment { 'datadog footer': - target => '/etc/dd-agent/datadog.conf', - content => template('datadog_agent/datadog_footer.conf.erb'), - order => '05', + # lint:ignore:quoted_booleans + $process_enabled_str = $process_enabled ? { true => 'true' , default => 'disabled' } + # lint:endignore + $base_extra_config = { + 'apm_config' => { + 'enabled' => $apm_enabled, + 'env' => $apm_env, + 'apm_non_local_traffic' => $apm_non_local_traffic, + }, + 'process_config' => { + 'enabled' => $process_enabled_str, + 'scrub_args' => $scrub_args, + 'custom_sensitive_words' => $custom_sensitive_words, + }, + 'logs_enabled' => $logs_enabled, + } + if $logs_open_files_limit { + $logs_base_config = { + 'logs_config' => { + 'container_collect_all' => $container_collect_all, + 'open_files_limit' => $logs_open_files_limit, + }, } - - unless $extra_template.empty { - concat::fragment { 'datadog extra_template footer': - target => '/etc/dd-agent/datadog.conf', - content => template($extra_template), - order => '06', - } + } else { + $logs_base_config = { + 'logs_config' => { + 'container_collect_all' => $container_collect_all, + }, } - - if ($apm_enabled == true) and (($apm_env != 'none') or $apm_analyzed_spans or $apm_obfuscation) { - concat::fragment { 'datadog apm footer': - target => '/etc/dd-agent/datadog.conf', - content => template('datadog_agent/datadog_apm_footer.conf.erb'), - order => '07', - } + } + if $host.empty { + $host_config = {} + } else { + $host_config = { + 'hostname' => $host, } + } - if ($process_enabled == true) { - concat::fragment { 'datadog process agent footer': - target => '/etc/dd-agent/datadog.conf', - content => template('datadog_agent/datadog_process_footer.conf.erb'), - order => '08', - } + if $apm_analyzed_spans { + $apm_analyzed_span_config = { + 'apm_config' => { + 'analyzed_spans' => $apm_analyzed_spans, + }, } + } else { + $apm_analyzed_span_config = {} + } - file { '/etc/dd-agent/install_info': - owner => $dd_user, - group => $dd_group, - mode => '0640', - content => template('datadog_agent/install_info.erb'), - require => File['/etc/dd-agent'], + if $apm_obfuscation { + $apm_obfuscation_config = { + 'apm_config' => { + 'obfuscation' => $apm_obfuscation, + }, } - } else { #Agent 6/7 + } else { + $apm_obfuscation_config = {} + } - # notify of broken params on agent6/7 - if !empty($proxy_host) { - notify { 'Setting proxy_host is only used with Agent 5. Please use agent_extra_options to set your proxy': } - } - if !empty($proxy_port) { - notify { 'Setting proxy_port is only used with Agent 5. Please use agent_extra_options to set your proxy': } - } - if !empty($proxy_user) { - notify { 'Setting proxy_user is only used with Agent 5. Please use agent_extra_options to set your proxy': } - } - if !empty($proxy_password) { - notify { 'Setting proxy_password is only used with Agent 5. Please use agent_extra_options to set your proxy': } + if $apm_filter_tags { + $apm_filter_tags_config = { + 'apm_config' => { + 'filter_tags' => $apm_filter_tags, + }, } + } else { + $apm_filter_tags_config = {} + } - # lint:ignore:quoted_booleans - $process_enabled_str = $process_enabled ? { true => 'true' , default => 'disabled' } - # lint:endignore - $base_extra_config = { + if $apm_filter_tags_regex { + $apm_filter_tags_regex_config = { 'apm_config' => { - 'enabled' => $apm_enabled, - 'env' => $apm_env, - 'apm_non_local_traffic' => $apm_non_local_traffic, - }, - 'process_config' => { - 'enabled' => $process_enabled_str, - 'scrub_args' => $scrub_args, - 'custom_sensitive_words' => $custom_sensitive_words, + 'filter_tags_regex' => $apm_filter_tags_regex, }, - 'logs_enabled' => $logs_enabled, } - if $logs_open_files_limit { - $logs_base_config = { - 'logs_config' => { - 'container_collect_all' => $container_collect_all, - 'open_files_limit' => $logs_open_files_limit, - }, - } - } else { - $logs_base_config = { - 'logs_config' => { - 'container_collect_all' => $container_collect_all, - }, + } else { + $apm_filter_tags_regex_config = {} + } + + if $statsd_forward_host.empty { + $statsd_forward_config = {} + } else { + if String($statsd_forward_port).empty { + $statsd_forward_config = { + 'statsd_forward_host' => $statsd_forward_host, } - } - if $host.empty { - $host_config = {} } else { - $host_config = { - 'hostname' => $host, + $statsd_forward_config = { + 'statsd_forward_host' => $statsd_forward_host, + 'statsd_forward_port' => $statsd_forward_port, } } + } - if $apm_analyzed_spans { - $apm_analyzed_span_config = { - 'apm_config' => { - 'analyzed_spans' => $apm_analyzed_spans, - }, - } - } else { - $apm_analyzed_span_config = {} + if $additional_checksd { + $additional_checksd_config = { + 'additional_checksd' => $additional_checksd, } + } else { + $additional_checksd_config = {} + } - if $apm_obfuscation { - $apm_obfuscation_config = { - 'apm_config' => { - 'obfuscation' => $apm_obfuscation, - }, - } - } else { - $apm_obfuscation_config = {} - } + $extra_config = deep_merge( + $base_extra_config, + $logs_base_config, + $agent_extra_options, + $apm_analyzed_span_config, + $apm_obfuscation_config, + $apm_filter_tags_config, + $apm_filter_tags_regex_config, + $statsd_forward_config, + $host_config, + $additional_checksd_config + ) + + file { $_conf_dir: + ensure => directory, + purge => $conf_dir_purge, + recurse => true, + force => $conf_dir_purge, + owner => $dd_user, + group => $dd_group, + } - if $apm_filter_tags { - $apm_filter_tags_config = { - 'apm_config' => { - 'filter_tags' => $apm_filter_tags, - }, - } - } else { - $apm_filter_tags_config = {} - } + if ! $_agent_managed_by_installer { + File[$_conf_dir] ~> Service[$datadog_agent::params::service_name] + } - if $apm_filter_tags_regex { - $apm_filter_tags_regex_config = { - 'apm_config' => { - 'filter_tags_regex' => $apm_filter_tags_regex, - }, - } - } else { - $apm_filter_tags_regex_config = {} - } + $_local_tags = datadog_agent::tag6($local_tags, false, undef) + $_facts_tags = datadog_agent::tag6($facts_to_tags, true, $facts) + $_trusted_facts_tags = datadog_agent::tag6($trusted_facts_to_tags, true, $trusted) + + $_agent_config = { + 'api_key' => $api_key, + 'dd_url' => $dd_url, + 'site' => $datadog_site, + 'cmd_port' => $cmd_port, + 'hostname_fqdn' => $hostname_fqdn, + 'collect_ec2_tags' => $collect_ec2_tags, + 'collect_gce_tags' => $collect_gce_tags, + 'confd_path' => $_conf_dir, + 'enable_metadata_collection' => $collect_instance_metadata, + 'dogstatsd_port' => $dogstatsd_port, + 'dogstatsd_socket' => $dogstatsd_socket, + 'dogstatsd_non_local_traffic' => $non_local_traffic, + 'log_file' => $agent_log_file, + 'log_level' => $log_level, + 'remote_updates' => $remote_updates, + 'remote_policies' => $remote_policies, + 'tags' => unique(flatten(union($_local_tags, $_facts_tags, $_trusted_facts_tags))), + } - if $statsd_forward_host.empty { - $statsd_forward_config = {} - } else { - if String($statsd_forward_port).empty { - $statsd_forward_config = { - 'statsd_forward_host' => $statsd_forward_host, - } - } else { - $statsd_forward_config = { - 'statsd_forward_host' => $statsd_forward_host, - 'statsd_forward_port' => $statsd_forward_port, - } - } + $agent_config = deep_merge($_agent_config, $extra_config) + + if ($facts['os']['name'] == 'Windows') { + file { 'C:/ProgramData/Datadog': + ensure => directory, } - if $additional_checksd { - $additional_checksd_config = { - 'additional_checksd' => $additional_checksd, - } - } else { - $additional_checksd_config = {} + file { 'C:/ProgramData/Datadog/datadog.yaml': + owner => $dd_user, + group => $dd_group, + mode => '0660', + content => template('datadog_agent/datadog.yaml.erb'), + show_diff => false, + notify => Service[$datadog_agent::params::service_name], + require => File['C:/ProgramData/Datadog'], } - $extra_config = deep_merge( - $base_extra_config, - $logs_base_config, - $agent_extra_options, - $apm_analyzed_span_config, - $apm_obfuscation_config, - $apm_filter_tags_config, - $apm_filter_tags_regex_config, - $statsd_forward_config, - $host_config, - $additional_checksd_config - ) - - file { $_conf_dir: - ensure => directory, - purge => $conf_dir_purge, - recurse => true, - force => $conf_dir_purge, + file { 'C:/ProgramData/Datadog/install_info': owner => $dd_user, group => $dd_group, + mode => '0660', + content => template('datadog_agent/install_info.erb'), + require => File['C:/ProgramData/Datadog'], } - - if ! $_agent_managed_by_installer { - File[$_conf_dir] ~> Service[$datadog_agent::params::service_name] - } - - $_local_tags = datadog_agent::tag6($local_tags, false, undef) - $_facts_tags = datadog_agent::tag6($facts_to_tags, true, $facts) - $_trusted_facts_tags = datadog_agent::tag6($trusted_facts_to_tags, true, $trusted) - - $_agent_config = { - 'api_key' => $api_key, - 'dd_url' => $dd_url, - 'site' => $datadog_site, - 'cmd_port' => $cmd_port, - 'hostname_fqdn' => $hostname_fqdn, - 'collect_ec2_tags' => $collect_ec2_tags, - 'collect_gce_tags' => $collect_gce_tags, - 'confd_path' => $_conf_dir, - 'enable_metadata_collection' => $collect_instance_metadata, - 'dogstatsd_port' => $dogstatsd_port, - 'dogstatsd_socket' => $dogstatsd_socket, - 'dogstatsd_non_local_traffic' => $non_local_traffic, - 'log_file' => $agent_log_file, - 'log_level' => $log_level, - 'remote_updates' => $remote_updates, - 'remote_policies' => $remote_policies, - 'tags' => unique(flatten(union($_local_tags, $_facts_tags, $_trusted_facts_tags))), + } else { + file { '/etc/datadog-agent/datadog.yaml': + owner => $dd_user, + group => $dd_group, + mode => '0640', + content => template('datadog_agent/datadog.yaml.erb'), + show_diff => false, + notify => Service[$datadog_agent::params::service_name], + require => File['/etc/datadog-agent'], } - $agent_config = deep_merge($_agent_config, $extra_config) - - if ($facts['os']['name'] == 'Windows') { - file { 'C:/ProgramData/Datadog': - ensure => directory, - } - - file { 'C:/ProgramData/Datadog/datadog.yaml': - owner => $dd_user, - group => $dd_group, - mode => '0660', - content => template('datadog_agent/datadog.yaml.erb'), - show_diff => false, - notify => Service[$datadog_agent::params::service_name], - require => File['C:/ProgramData/Datadog'], - } - - file { 'C:/ProgramData/Datadog/install_info': - owner => $dd_user, - group => $dd_group, - mode => '0660', - content => template('datadog_agent/install_info.erb'), - require => File['C:/ProgramData/Datadog'], - } - } else { - file { '/etc/datadog-agent/datadog.yaml': - owner => $dd_user, - group => $dd_group, - mode => '0640', - content => template('datadog_agent/datadog.yaml.erb'), - show_diff => false, - notify => Service[$datadog_agent::params::service_name], - require => File['/etc/datadog-agent'], - } - - file { '/etc/datadog-agent/install_info': - owner => $dd_user, - group => $dd_group, - mode => '0640', - content => template('datadog_agent/install_info.erb'), - require => File['/etc/datadog-agent'], - } + file { '/etc/datadog-agent/install_info': + owner => $dd_user, + group => $dd_group, + mode => '0640', + content => template('datadog_agent/install_info.erb'), + require => File['/etc/datadog-agent'], } } diff --git a/spec/classes/datadog_agent_integrations_kafka_spec.rb b/spec/classes/datadog_agent_integrations_kafka_spec.rb index 1c32579a..fdeacea2 100644 --- a/spec/classes/datadog_agent_integrations_kafka_spec.rb +++ b/spec/classes/datadog_agent_integrations_kafka_spec.rb @@ -5,11 +5,7 @@ context 'supported agents' do let(:pre_condition) { "class {'::datadog_agent': agent_major_version => #{agent_major_version}}" } - conf_file = if agent_major_version == 5 - '/etc/dd-agent/conf.d/kafka.yaml' - else - "#{CONF_DIR}/kafka.d/conf.yaml" - end + conf_file = "#{CONF_DIR}/kafka.d/conf.yaml" it { is_expected.to compile.with_all_deps } it { diff --git a/spec/classes/datadog_agent_redhat_spec.rb b/spec/classes/datadog_agent_redhat_spec.rb index 2c4ea4da..c469717f 100644 --- a/spec/classes/datadog_agent_redhat_spec.rb +++ b/spec/classes/datadog_agent_redhat_spec.rb @@ -1,66 +1,6 @@ require 'spec_helper' describe 'datadog_agent::redhat' do - context 'agent 5' do - if RSpec::Support::OS.windows? - return - end - - let(:facts) do - { - os: { - 'architecture' => 'x86_64', - 'family' => 'redhat', - 'name' => 'Fedora', - 'release' => { - 'major' => '36', - 'full' => '36', - }, - }, - } - end - - # it should install the mirror - context 'with manage_repo => true' do - let(:params) do - { - manage_repo: true, - agent_major_version: 5, - } - end - - it do - is_expected.to contain_yumrepo('datadog') - .with_enabled(1)\ - .with_gpgcheck(1)\ - .with_gpgkey('https://keys.datadoghq.com/DATADOG_RPM_KEY_CURRENT.public - https://keys.datadoghq.com/DATADOG_RPM_KEY_FD4BF915.public - https://keys.datadoghq.com/DATADOG_RPM_KEY_B01082D3.public - https://keys.datadoghq.com/DATADOG_RPM_KEY_E09422B3.public')\ - .with_baseurl('https://yum.datadoghq.com/rpm/x86_64/')\ - .with_repo_gpgcheck(false) - end - end - context 'with manage_repo => false' do - let(:params) do - { - manage_repo: false, agent_major_version: 5 - } - end - - it do - is_expected.not_to contain_yumrepo('datadog') - is_expected.not_to contain_yumrepo('datadog5') - is_expected.not_to contain_yumrepo('datadog6') - end - end - # it should install the packages - it do - is_expected.to contain_package('datadog-agent')\ - .with_ensure('latest') - end - end - context 'agent 6' do let(:facts) do { diff --git a/spec/classes/datadog_agent_spec.rb b/spec/classes/datadog_agent_spec.rb index 60e59342..0fc614fe 100644 --- a/spec/classes/datadog_agent_spec.rb +++ b/spec/classes/datadog_agent_spec.rb @@ -29,32 +29,6 @@ end end - context 'autodetect major version agent 5' do - let(:params) do - { - agent_version: '5.15.1', - } - end - let(:facts) do - { - os: { - 'architecture' => 'x86_64', - 'family' => 'debian', - 'name' => 'Ubuntu', - 'release' => { - 'major' => '14', - 'full' => '14.04', - }, - }, - } - end - - it do - is_expected.to contain_file('/etc/apt/sources.list.d/datadog.list')\ - .with_content(%r{deb\s+\[signed-by=/usr/share/keyrings/datadog-archive-keyring.gpg\]\s+https://apt.datadoghq.com/\s+stable\s+main}) - end - end - context 'autodetect major version agent 6' do let(:params) do { @@ -158,6 +132,9 @@ 'major' => '14', 'full' => '14.04', }, + 'distro' => { + 'codename' => 'trusty', + }, }, } end @@ -184,6 +161,9 @@ 'major' => '14', 'full' => '14.04', }, + 'distro' => { + 'codename' => 'trusty', + }, }, } end @@ -210,6 +190,9 @@ 'major' => '14', 'full' => '14.04', }, + 'distro' => { + 'codename' => 'trusty', + }, }, } end @@ -238,6 +221,9 @@ 'major' => '14', 'full' => '14.04', }, + 'distro' => { + 'codename' => 'trusty', + }, }, } end @@ -316,6 +302,9 @@ 'major' => getosmajor(operatingsystem), 'full' => getosrelease(operatingsystem), }, + 'distro' => { + 'code' => getoscodename(operatingsystem), + } }, } end @@ -348,1304 +337,6 @@ end end - describe "datadog_agent 5 class common actions on #{operatingsystem}" do - let(:params) do - { - puppet_run_reports: true, - agent_major_version: 5, - } - end - let(:facts) do - { - os: { - 'architecture' => 'x86_64', - 'family' => getosfamily(operatingsystem), - 'name' => operatingsystem, - 'release' => { - 'major' => getosmajor(operatingsystem), - 'full' => getosrelease(operatingsystem), - }, - }, - } - end - - if WINDOWS_OS.include?(operatingsystem) - it 'agent 5 should raise on Windows' do - is_expected.to raise_error(Puppet::Error, %r{Installation of agent 5 with puppet is not supported on Windows}) - end - else - it { is_expected.to compile.with_all_deps } - - it { is_expected.to contain_class('datadog_agent') } - - describe 'datadog_agent imports the default params' do - it { is_expected.to contain_class('datadog_agent::params') } - end - - it { is_expected.to contain_file('/etc/datadog-agent') } - it { is_expected.to contain_file('/etc/dd-agent') } - it { is_expected.to contain_concat('/etc/dd-agent/datadog.conf') } - it { is_expected.to contain_file('/etc/dd-agent/conf.d').with_ensure('directory') } - - it { is_expected.to contain_class('datadog_agent::reports') } - - describe 'parameter check' do - context 'with defaults' do - context 'for proxy' do - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{dd_url: https://app.datadoghq.com\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^# proxy_host:\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^# proxy_port:\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^# proxy_user:\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^# proxy_password:\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^# skip_ssl_validation: no\n}, - ) - } - end - - context 'for general' do - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^api_key: your_API_key\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^# hostname:\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^non_local_traffic: false\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^collect_ec2_tags: false\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^collect_instance_metadata: true\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{# recent_point_threshold: 30\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^# listen_port: 17123\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^# graphite_listen_port: 17124\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{# additional_checksd: /etc/dd-agent/checks.d/\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^use_curl_http_client: false\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^# device_blacklist_re: .*\\/dev\\/mapper\\/lxc-box.*\n}, - ) - } - end - - context 'for pup' do - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^use_pup: no\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^# pup_port: 17125\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^# pup_interface: localhost\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{# pup_url: http://localhost:17125\n}, - ) - } - end - - context 'for dogstatsd' do - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^# bind_host: localhost\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^use_dogstatsd: yes\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^dogstatsd_port: 8125\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{# dogstatsd_target: http://localhost:17123\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^# dogstatsd_interval: 10\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^dogstatsd_normalize: yes\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^# statsd_forward_host: address_of_own_statsd_server\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^# statsd_forward_port: 8125\n}, - ) - } - end - - context 'for logging' do - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^log_level: INFO\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^log_to_syslog: yes\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{# collector_log_file: /var/log/datadog/collector.log\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{# forwarder_log_file: /var/log/datadog/forwarder.log\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{# dogstatsd_log_file: /var/log/datadog/dogstatsd.log\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with - # 'content' => %r{# pup_log_file: /var/log/datadog/pup.log\n}, - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^# syslog_host:\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^# syslog_port:\n}, - ) - } - end - - context 'for service_discovery' do - it { - is_expected.to contain_concat__fragment('datadog footer').without( - 'content' => %r{^service_discovery_backend:\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').without( - 'content' => %r{^sd_config_backend:\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').without( - 'content' => %r{^sd_backend_host:\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').without( - 'content' => %r{^sd_backend_port:\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').without( - 'content' => %r{^sd_template_dir:\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').without( - 'content' => %r{^consul_token:\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').without( - 'content' => %r{^# sd_jmx_enable:\n}, - ) - } - end - - context 'for APM' do - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^apm_enabled: false\n}, - ) - } - end - end - - context 'with user provided paramaters' do - context 'with a custom dd_url' do - let(:params) do - { - dd_url: 'https://notaurl.datadoghq.com', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{dd_url: https://notaurl.datadoghq.com\n}, - ) - } - end - context 'with a custom proxy_host' do - let(:params) do - { - proxy_host: 'localhost', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^proxy_host: localhost\n}, - ) - } - end - context 'with a custom proxy_port' do - let(:params) do - { - proxy_port: '1234', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^proxy_port: 1234\n}, - ) - } - end - context 'with a custom proxy_port, specified as an integer' do - let(:params) do - { - proxy_port: 1234, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^proxy_port: 1234\n}, - ) - } - end - context 'with a custom proxy_user' do - let(:params) do - { - proxy_user: 'notauser', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^proxy_user: notauser\n}, - ) - } - end - context 'with a custom api_key' do - let(:params) do - { - api_key: 'notakey', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^api_key: notakey\n}, - ) - } - end - context 'with a custom hostname' do - let(:params) do - { - host: 'notahost', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^hostname: notahost\n}, - ) - } - end - context 'with non_local_traffic set to true' do - let(:params) do - { - non_local_traffic: true, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^non_local_traffic: true\n}, - ) - } - end - # Should expand testing to cover changes to the case upcase - context 'with log level set to critical' do - let(:params) do - { - log_level: 'critical', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^log_level: CRITICAL\n}, - ) - } - end - context 'with a custom hostname' do - let(:params) do - { - host: 'notahost', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^hostname: notahost\n}, - ) - } - end - context 'with log_to_syslog set to false' do - let(:params) do - { - log_to_syslog: false, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^log_to_syslog: no\n}, - ) - } - end - context 'with skip_ssl_validation set to true' do - let(:params) do - { - skip_ssl_validation: true, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog header').with( - 'content' => %r{^skip_ssl_validation: true\n}, - ) - } - end - context 'with collect_ec2_tags set to yes' do - let(:params) do - { - collect_ec2_tags: true, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^collect_ec2_tags: true\n}, - ) - } - end - context 'with collect_instance_metadata set to no' do - let(:params) do - { - collect_instance_metadata: false, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^collect_instance_metadata: false\n}, - ) - } - end - context 'with recent_point_threshold set to 60' do - let(:params) do - { - recent_point_threshold: '60', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^recent_point_threshold: 60\n}, - ) - } - end - context 'with a custom port set to 17125' do - let(:params) do - { - listen_port: '17125', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^listen_port: 17125\n}, - ) - } - end - context 'with a custom port set to 17125, specified as an integer' do - let(:params) do - { - listen_port: 17_125, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^listen_port: 17125\n}, - ) - } - end - context 'listening for graphite data on port 17124' do - let(:params) do - { - graphite_listen_port: '17124', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^graphite_listen_port: 17124\n}, - ) - } - end - context 'listening for graphite data on port 17124, port specified as an integer' do - let(:params) do - { - graphite_listen_port: 17_124, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^graphite_listen_port: 17124\n}, - ) - } - end - context 'with configuration for a custom checks.d' do - let(:params) do - { - additional_checksd: '/etc/dd-agent/checks_custom.d', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{additional_checksd: /etc/dd-agent/checks_custom.d\n}, - ) - } - end - context 'with configuration for a custom checks.d' do - let(:params) do - { - additional_checksd: '/etc/dd-agent/checks_custom.d', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{additional_checksd: /etc/dd-agent/checks_custom.d\n}, - ) - } - end - context 'with configuration for a custom checks.d' do - let(:params) do - { - additional_checksd: '/etc/dd-agent/checks_custom.d', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{additional_checksd: /etc/dd-agent/checks_custom.d\n}, - ) - } - end - context 'with using the Tornado HTTP client' do - let(:params) do - { - use_curl_http_client: true, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^use_curl_http_client: true\n}, - ) - } - end - context 'with a custom bind_host' do - let(:params) do - { - bind_host: 'test', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^bind_host: test\n}, - ) - } - end - context 'with pup enabled' do - let(:params) do - { - use_pup: true, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^use_pup: yes\n}, - ) - } - end - context 'with a custom pup_port' do - let(:params) do - { - pup_port: '17126', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^pup_port: 17126\n}, - ) - } - end - context 'with a custom pup_port, specified as an integer' do - let(:params) do - { - pup_port: 17_126, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^pup_port: 17126\n}, - ) - } - end - context 'with a custom pup_interface' do - let(:params) do - { - pup_interface: 'notalocalhost', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^pup_interface: notalocalhost\n}, - ) - } - end - context 'with a custom pup_url' do - let(:params) do - { - pup_url: 'http://localhost:17126', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{pup_url: http://localhost:17126\n}, - ) - } - end - context 'with use_dogstatsd set to no' do - let(:params) do - { - use_dogstatsd: false, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^use_dogstatsd: no\n}, - ) - } - end - context 'with use_dogstatsd set to yes' do - let(:params) do - { - use_dogstatsd: true, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^use_dogstatsd: yes\n}, - ) - } - end - context 'with dogstatsd_port set to 8126 - must be specified as an integer!' do - let(:params) do - { - dogstatsd_port: 8126, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^dogstatsd_port: 8126\n}, - ) - } - end - context 'with dogstatsd_port set to 8126' do - let(:params) do - { - dogstatsd_port: 8126, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^dogstatsd_port: 8126\n}, - ) - } - end - context 'with dogstatsd_target set to localhost:17124' do - let(:params) do - { - dogstatsd_target: 'http://localhost:17124', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{dogstatsd_target: http://localhost:17124\n}, - ) - } - end - context 'with dogstatsd_interval set to 5' do - let(:params) do - { - dogstatsd_interval: '5', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^dogstatsd_interval: 5\n}, - ) - } - end - context 'with dogstatsd_interval set to 5' do - let(:params) do - { - dogstatsd_interval: '5', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^dogstatsd_interval: 5\n}, - ) - } - end - context 'with dogstatsd_normalize set to false' do - let(:params) do - { - dogstatsd_normalize: false, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^dogstatsd_normalize: no\n}, - ) - } - end - context 'with statsd_forward_host set to localhost:3958' do - let(:params) do - { - statsd_forward_host: 'localhost:3958', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^statsd_forward_host: localhost:3958\n}, - ) - } - end - context 'with statsd_forward_port set to 8126' do - let(:params) do - { - statsd_forward_port: '8126', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^statsd_forward_port: 8126\n}, - ) - } - end - context 'with statsd_forward_port set to 8126, specified as an integer' do - let(:params) do - { - statsd_forward_port: 8126, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^statsd_forward_port: 8126\n}, - ) - } - end - context 'with device_blacklist_re set to test' do - let(:params) do - { - device_blacklist_re: 'test', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^device_blacklist_re: test\n}, - ) - } - end - context 'with device_blacklist_re set to test' do - let(:params) do - { - device_blacklist_re: 'test', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^device_blacklist_re: test\n}, - ) - } - end - context 'with custom_emitters set to /test/emitter' do - let(:params) do - { - custom_emitters: '/test/emitter/', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{custom_emitters: /test/emitter/\n}, - ) - } - end - context 'with custom_emitters set to /test/emitter' do - let(:params) do - { - custom_emitters: '/test/emitter/', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{custom_emitters: /test/emitter/\n}, - ) - } - end - context 'with collector_log_file set to /test/log' do - let(:params) do - { - collector_log_file: '/test/log', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{collector_log_file: /test/log\n}, - ) - } - end - context 'with forwarder_log_file set to /test/log' do - let(:params) do - { - forwarder_log_file: '/test/log', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{forwarder_log_file: /test/log\n}, - ) - } - end - context 'with forwarder_log_file set to /test/log' do - let(:params) do - { - forwarder_log_file: '/test/log', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{forwarder_log_file: /test/log\n}, - ) - } - end - context 'with dogstatsd_log_file set to /test/log' do - let(:params) do - { - dogstatsd_log_file: '/test/log', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{dogstatsd_log_file: /test/log\n}, - ) - } - end - context 'with pup_log_file set to /test/log' do - let(:params) do - { - pup_log_file: '/test/log', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^pup_log_file: /test/log\n}, - ) - } - end - context 'with syslog location set to localhost' do - let(:params) do - { - syslog_host: 'localhost', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^syslog_host: localhost\n}, - ) - } - end - context 'with syslog port set to 8080' do - let(:params) do - { - syslog_port: '8080', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^syslog_port: 8080\n}, - ) - } - end - context 'with syslog port set to 8080, specified as an integer' do - let(:params) do - { - syslog_port: 8080, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^syslog_port: 8080\n}, - ) - } - end - context 'with apm_enabled set to true' do - let(:params) do - { - apm_enabled: true, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^apm_enabled: true\n}, - ) - } - end - context 'with apm_enabled set to true and env specified' do - let(:params) do - { - apm_enabled: true, - apm_env: 'foo', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^apm_enabled: true\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog apm footer').with( - 'content' => %r{^\[trace.agent\]\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog apm footer').with( - 'content' => %r{^env: foo\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog apm footer').with( - 'order' => '07', - ) - } - end - context 'with apm_enabled and apm_analyzed_spans set' do - let(:params) do - { - apm_enabled: true, - agent_major_version: 5, - apm_analyzed_spans: { - 'foo|bar' => 0.5, - 'haz|qux' => 0.1, - }, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^apm_enabled: true\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog apm footer').with( - 'content' => %r{^\[trace.analyzed_spans\]\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog apm footer').with( - 'content' => %r{^\[trace.analyzed_spans\]\nfoo|bar: 0.5\nhaz|qux: 0.1}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog apm footer').with( - 'order' => '07', - ) - } - end - context 'with service_discovery enabled' do - let(:params) do - { - service_discovery_backend: 'docker', - sd_config_backend: 'etcd', - sd_backend_host: 'localhost', - sd_backend_port: 8080, - sd_jmx_enable: true, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^service_discovery_backend: docker\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^sd_config_backend: etcd\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^sd_backend_host: localhost\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^sd_backend_port: 8080\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^sd_jmx_enable: true\n}, - ) - } - end - context 'with extra_template enabled' do - let(:params) do - { - extra_template: 'custom_datadog/extra_template_test.erb', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog extra_template footer').with( - 'order' => '06', - ) - } - it { - is_expected.to contain_concat__fragment('datadog extra_template footer').with( - 'content' => %r{^# extra template is here\n}, - ) - } - it { - is_expected.not_to contain_concat__fragment('datadog apm footer').with( - 'order' => '07', - ) - } - end - context 'with APM enabled' do - let(:params) do - { - apm_enabled: true, - apm_env: 'foo', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog apm footer').with( - 'order' => '07', - ) - } - end - context 'with APM enabled but no APM env' do - let(:params) do - { - apm_enabled: true, - agent_major_version: 5, - } - end - - it { - is_expected.not_to contain_concat__fragment('datadog apm footer').with( - 'order' => '07', - ) - } - end - context 'with extra_template and APM enabled' do - let(:params) do - { - extra_template: 'custom_datadog/extra_template_test.erb', - apm_enabled: true, - apm_env: 'foo', - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog extra_template footer').with( - 'order' => '06', - ) - } - it { - is_expected.to contain_concat__fragment('datadog extra_template footer').with( - 'content' => %r{^# extra template is here\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog apm footer').with( - 'order' => '07', - ) - } - end - context 'with process_agent enabled' do - let(:params) do - { - process_enabled: true, - agent_major_version: 5, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^process_agent_enabled: true\n}, - ) - } - end - - context 'with data scrubbing disabled' do - let(:params) do - { - process_enabled: true, - agent_major_version: 5, - scrub_args: false, - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^process_agent_enabled: true\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog process agent footer').with( - 'content' => %r{^\[process.config\]\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog process agent footer').with( - 'content' => %r{^scrub_args: false\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog process agent footer').with( - 'content' => %r{^custom_sensitive_words: \n}, - ) - } - end - - context 'with data scrubbing enabled with custom sensitive_words' do - let(:params) do - { - process_enabled: true, - agent_major_version: 5, - custom_sensitive_words: ['consul_token', 'dd_key'], - } - end - - it { - is_expected.to contain_concat__fragment('datadog footer').with( - 'content' => %r{^process_agent_enabled: true\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog process agent footer').with( - 'content' => %r{^\[process.config\]\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog process agent footer').with( - 'content' => %r{^scrub_args: true\n}, - ) - } - it { - is_expected.to contain_concat__fragment('datadog process agent footer').with( - 'content' => %r{^custom_sensitive_words: consul_token,dd_key\n}, - ) - } - end - end - end - - if REDHAT_OS.include?(operatingsystem) - it { is_expected.to contain_class('datadog_agent::redhat') } - end - end - end - describe "datadog_agent 6/7 class with reports on #{operatingsystem}" do let(:params) do { @@ -1662,6 +353,9 @@ 'major' => getosmajor(operatingsystem), 'full' => getosrelease(operatingsystem), }, + 'distro' => { + 'codename' => getoscodename(operatingsystem), + } }, } end @@ -1695,6 +389,9 @@ 'major' => getosmajor(operatingsystem), 'full' => getosrelease(operatingsystem), }, + 'distro' => { + 'codename' => getoscodename(operatingsystem) + }, }, } end @@ -1717,11 +414,6 @@ it { is_expected.to contain_file(install_info_file) } it { is_expected.to contain_file(config_dir + '/conf.d').with_ensure('directory') } - # Agent 5 files - it { is_expected.not_to contain_file('/etc/dd-agent') } - it { is_expected.not_to contain_concat('/etc/dd-agent/datadog.conf') } - it { is_expected.not_to contain_file('/etc/dd-agent/conf.d').with_ensure('directory') } - describe 'install_info check' do let!(:install_info) do contents = catalogue.resource('file', install_info_file).send(:parameters)[:content] @@ -1905,68 +597,6 @@ ) } end - context 'deprecated proxy settings' do - let(:params) do - { - proxy_host: 'foo', - proxy_port: 1234, - proxy_user: 'bar', - proxy_password: 'abcd1234', - } - end - - it { - is_expected.to contain_notify( - 'Setting proxy_host is only used with Agent 5. Please use agent_extra_options to set your proxy', - ) - } - it { - is_expected.to contain_notify( - 'Setting proxy_port is only used with Agent 5. Please use agent_extra_options to set your proxy', - ) - } - it { - is_expected.to contain_notify( - 'Setting proxy_user is only used with Agent 5. Please use agent_extra_options to set your proxy', - ) - } - it { - is_expected.to contain_notify( - 'Setting proxy_password is only used with Agent 5. Please use agent_extra_options to set your proxy', - ) - } - end - context 'deprecated proxy settings with default values' do - let(:params) do - { - proxy_host: '', - proxy_port: '', - proxy_user: '', - proxy_password: '', - } - end - - it { - is_expected.not_to contain_notify( - 'Setting proxy_host is only used with Agent 5. Please use agent_extra_options to set your proxy', - ) - } - it { - is_expected.not_to contain_notify( - 'Setting proxy_port is only used with Agent 5. Please use agent_extra_options to set your proxy', - ) - } - it { - is_expected.not_to contain_notify( - 'Setting proxy_user is only used with Agent 5. Please use agent_extra_options to set your proxy', - ) - } - it { - is_expected.not_to contain_notify( - 'Setting proxy_password is only used with Agent 5. Please use agent_extra_options to set your proxy', - ) - } - end end context 'with additional agents config' do @@ -2311,6 +941,9 @@ 'major' => '6', 'full' => '6.3', }, + 'distro' => { + 'codename' => 'santiago', + } }, } end @@ -2361,6 +994,9 @@ 'major' => '6', 'full' => '6.3', }, + 'distro' => { + 'codename' => 'santiago', + } }, } end @@ -2370,36 +1006,5 @@ .with_content(%r{tags:\n- os.family:redhat\n- facts_array:one\n- facts_array:two\n- facts_hash.actor.first_name:Macaulay\n- looks.like.a.path:but_its_not}) end end - - describe 'a5 ensure facts_array outputs a list of tags' do - let(:params) do - { - agent_major_version: 5, - puppet_run_reports: true, - facts_to_tags: ['osfamily', 'facts_array'], - } - end - let(:facts) do - { - facts_array: ['one', 'two'], - osfamily: 'redhat', - os: { - 'architecture' => 'x86_64', - 'family' => 'redhat', - 'name' => 'CentOS', - 'release' => { - 'major' => '6', - 'full' => '6.3', - }, - }, - } - end - - it { is_expected.to contain_concat('/etc/dd-agent/datadog.conf') } - it { is_expected.to contain_concat__fragment('datadog tags').with_content('tags: ') } - it { is_expected.to contain_concat__fragment('datadog tag osfamily:redhat').with_content('osfamily:redhat, ') } - it { is_expected.to contain_concat__fragment('datadog tag facts_array:one').with_content('facts_array:one, ') } - it { is_expected.to contain_concat__fragment('datadog tag facts_array:two').with_content('facts_array:two, ') } - end end end diff --git a/spec/classes/datadog_agent_ubuntu_spec.rb b/spec/classes/datadog_agent_ubuntu_spec.rb index ee6ef100..da5c31e9 100644 --- a/spec/classes/datadog_agent_ubuntu_spec.rb +++ b/spec/classes/datadog_agent_ubuntu_spec.rb @@ -23,60 +23,6 @@ end describe 'datadog_agent::ubuntu' do - context 'agent 5' do - if RSpec::Support::OS.windows? - return - end - let(:params) do - { - agent_major_version: 5, - } - end - let(:facts) do - { - os: { - 'architecture' => 'x86_64', - 'family' => 'debian', - 'name' => 'Ubuntu', - 'release' => { - 'major' => '14', - 'full' => '14.04', - }, - }, - } - end - - it do - is_expected.to contain_file('/etc/apt/sources.list.d/datadog5.list') - .with_ensure('absent') - is_expected.to contain_file('/etc/apt/sources.list.d/datadog6.list') - .with_ensure('absent') - is_expected.to contain_file('/etc/apt/sources.list.d/datadog.list')\ - .with_content(%r{deb\s+\[signed-by=/usr/share/keyrings/datadog-archive-keyring.gpg\]\s+https://apt.datadoghq.com/\s+stable\s+main}) - end - - # it should install the mirror - it { is_expected.not_to contain_apt__key('935F5A436A5A6E8788F0765B226AE980C7A7DA52') } - - it do - is_expected.to contain_file('/etc/apt/sources.list.d/datadog.list')\ - .that_notifies('exec[apt_update]') - end - it { is_expected.to contain_exec('apt_update') } - - # it should install the packages - it do - is_expected.to contain_package('datadog-agent-base')\ - .with_ensure('absent')\ - .that_comes_before('package[datadog-agent]') - end - it do - is_expected.to contain_package('datadog-agent')\ - .that_requires('file[/etc/apt/sources.list.d/datadog.list]')\ - .that_requires('exec[apt_update]') - end - end - context 'agent 6' do let(:params) do { diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0989f844..10336330 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -27,7 +27,7 @@ PERMISSIONS_PROTECTED_FILE = '0660' else ALL_OS = DEBIAN_OS + REDHAT_OS - ALL_SUPPORTED_AGENTS = [5, 6, 7].freeze + ALL_SUPPORTED_AGENTS = [6, 7].freeze CONF_DIR = '/etc/datadog-agent/conf.d' DD_USER = 'dd-agent' DD_GROUP = 'dd-agent' diff --git a/templates/agent-conf.d/cassandra.yaml.erb b/templates/agent-conf.d/cassandra.yaml.erb index afc51389..86afee02 100644 --- a/templates/agent-conf.d/cassandra.yaml.erb +++ b/templates/agent-conf.d/cassandra.yaml.erb @@ -33,8 +33,7 @@ init_config: ## @param conf - list of objects - required ## List of metrics to be collected by the integration ## Read http://docs.datadoghq.com/integrations/java/ to learn how to customize it - ## Agent 5: Customize all your metrics below - ## Agent 6: The default metrics to be collected are kept in metrics.yaml, but you can still add your own metrics here + ## Agent 6/7: The default metrics to be collected are kept in metrics.yaml, but you can still add your own metrics here # conf: - include: diff --git a/templates/agent-conf.d/kafka.yaml.erb b/templates/agent-conf.d/kafka.yaml.erb index c76955f2..88ffabbc 100644 --- a/templates/agent-conf.d/kafka.yaml.erb +++ b/templates/agent-conf.d/kafka.yaml.erb @@ -1,11 +1,5 @@ ### MANAGED BY PUPPET -########## -# WARNING -########## -# This sample works only for Kafka >= 0.8.2. -# If you are running a version older than that, you can refer to agent 5.2.x released -# sample files, https://raw.githubusercontent.com/DataDog/dd-agent/5.2.1/conf.d/kafka.yaml.example instances: <% @servers.each do |server| -%> - host: <%= server['host'] %> From 4b78abd1cc7982b4afdb37e48fa5abdddf33f8fc Mon Sep 17 00:00:00 2001 From: Fanny Jiang Date: Fri, 14 Feb 2025 12:57:49 -0500 Subject: [PATCH 4/8] fix rubocop target ruby version --- .rubocop | 2 +- .rubocop.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop b/.rubocop index 92530682..f0cd84d6 100644 --- a/.rubocop +++ b/.rubocop @@ -1,2 +1,2 @@ --ignore-unrecognized-cops ---autocorrect \ No newline at end of file +--autocorrect diff --git a/.rubocop.yml b/.rubocop.yml index bb7b4a33..056c84ef 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,7 +5,7 @@ require: AllCops: NewCops: enable DisplayCopNames: true - TargetRubyVersion: '3.3' + TargetRubyVersion: '3.2' Include: - "**/*.rb" Exclude: From 25d62bbc403d2b30f1fb7ee682db8e05347b00f1 Mon Sep 17 00:00:00 2001 From: Fanny Jiang Date: Fri, 14 Feb 2025 13:00:52 -0500 Subject: [PATCH 5/8] remote --autocorrect from .rubocop --- .rubocop | 1 - 1 file changed, 1 deletion(-) diff --git a/.rubocop b/.rubocop index f0cd84d6..fc40e8e2 100644 --- a/.rubocop +++ b/.rubocop @@ -1,2 +1 @@ --ignore-unrecognized-cops ---autocorrect From 8f44885d9d510368765f749a96bf4703e899902e Mon Sep 17 00:00:00 2001 From: Fanny Jiang Date: Fri, 14 Feb 2025 12:02:41 -0500 Subject: [PATCH 6/8] add facter and kitchen-puppet gems to kitchen gemfile, disable centos stream kitchen tests --- environments/etc/Gemfile | 6 ++++- kitchen.yml | 48 ++++++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/environments/etc/Gemfile b/environments/etc/Gemfile index 7ac3eebb..2c67d16f 100644 --- a/environments/etc/Gemfile +++ b/environments/etc/Gemfile @@ -1,7 +1,11 @@ source 'https://rubygems.org' -gem 'semantic_puppet', '1.1.1' +gem 'semantic_puppet', '1.1.1' gem 'multipart-post', '2.4.1' gem 'r10k', '4.1.0' gem 'json', '2.6.3' gem 'racc', '~> 1.4.0' gem 'net-ssh', '~> 7.3' +gem "facterdb", '~> 3.4.0' +gem "rspec-puppet-facts", '~> 5.2.0' +gem "facter", '~> 4.10.0' +gem "kitchen-puppet", '~> 3.7.0' \ No newline at end of file diff --git a/kitchen.yml b/kitchen.yml index 0c865012..f8652aef 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -95,26 +95,36 @@ platforms: # - cd /home && bundle install # - cd /home/kitchen/puppet && r10k puppetfile install --moduledir=/tmp/modules -- name: centos-stream9-puppet-8 - driver: - image: 'quay.io/centos/centos:stream9' - platform: centosstream - use_sudo: true - privileged: true - provision_command: - - rpm -Uvh https://yum.puppet.com/puppet8-release-el-9.noarch.rpm #installs the puppet-agent repo - - yum install -y puppet-agent rubygems ruby-devel - - dnf group install -y "Development Tools" - - ln -s /opt/puppetlabs/bin/puppet /usr/bin/puppet - - mkdir /home/kitchen/puppet -p - - printf <%= File.read('environments/etc/Puppetfile').inspect %> > /home/kitchen/puppet/Puppetfile - - printf <%= File.read('environments/etc/Gemfile').inspect %> > /home/Gemfile - - - gem install bundler -v '= 2.4.13' - # we use bundle to install gems and to lock dependencies versions of semantic_puppet and multipart-post - - cd /home && bundle install - - cd /home/kitchen/puppet && r10k puppetfile install --moduledir=/tmp/modules +# TODO: validate module support for CentOS Stream +# Debug: Service[datadog-agent](provider=base): Executing 'ps -ef' +# Debug: Executing: 'ps -ef' +# Error: /Service[datadog-agent]: Could not evaluate: Execution of 'ps -ef' returned 1: Error: Could not execute posix command: No such file or directory - ps +# Debug: Service[datadog-agent](provider=base): Executing 'ps -ef' +# Debug: Executing: 'ps -ef' +# Error: /Service[datadog-agent]: Failed to call refresh: Execution of 'ps -ef' returned 1: Error: Could not execute posix command: No such file or directory - ps +# Error: /Service[datadog-agent]: Execution of 'ps -ef' returned 1: Error: Could not execute posix command: No such file or directory - ps +#- name: centos-stream9-puppet-8 +# driver: +# image: 'quay.io/centos/centos:stream9' +# platform: centosstream +# docker_platform: linux/amd64 +# use_sudo: true +# privileged: true +# provision_command: +# - rpm -Uvh https://yum.puppet.com/puppet8-release-el-9.noarch.rpm #installs the puppet-agent repo +# - yum install -y puppet-agent rubygems ruby-devel +# - dnf group install -y "Development Tools" +# - ln -s /opt/puppetlabs/bin/puppet /usr/bin/puppet +# +# - mkdir /home/kitchen/puppet -p +# - printf <%= File.read('environments/etc/Puppetfile').inspect %> > /home/kitchen/puppet/Puppetfile +# - printf <%= File.read('environments/etc/Gemfile').inspect %> > /home/Gemfile +# +# - gem install bundler -v '= 2.4.13' +# # we use bundle to install gems and to lock dependencies versions of semantic_puppet and multipart-post +# - cd /home && bundle install +# - cd /home/kitchen/puppet && r10k puppetfile install --moduledir=/tmp/modules - name: rocky-9-puppet-8 driver: From 3642387294dbf05a72559720092ced6645d82b48 Mon Sep 17 00:00:00 2001 From: Fanny Jiang Date: Fri, 14 Feb 2025 12:13:06 -0500 Subject: [PATCH 7/8] temporarily disable rocky 9 kitchen tests --- kitchen.yml | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/kitchen.yml b/kitchen.yml index f8652aef..0e5fd718 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -97,7 +97,7 @@ platforms: # TODO: validate module support for CentOS Stream -# Debug: Service[datadog-agent](provider=base): Executing 'ps -ef' +# Debug: Service[datadog-agent](provider=base): Executing 'ps -ef' # Debug: Executing: 'ps -ef' # Error: /Service[datadog-agent]: Could not evaluate: Execution of 'ps -ef' returned 1: Error: Could not execute posix command: No such file or directory - ps # Debug: Service[datadog-agent](provider=base): Executing 'ps -ef' @@ -126,24 +126,33 @@ platforms: # - cd /home && bundle install # - cd /home/kitchen/puppet && r10k puppetfile install --moduledir=/tmp/modules -- name: rocky-9-puppet-8 - driver: - image: 'rockylinux:9.3' - platform: centosstream # kitchen-docker has issues installing packages otherwises - provision_command: - - dnf install -y https://yum.puppet.com/puppet8-release-el-9.noarch.rpm #installs the puppet-agent repo - - dnf install -y puppet-agent rubygems ruby-devel - - dnf group install -y "Development Tools" - - ln -s /opt/puppetlabs/bin/puppet /usr/bin/puppet - - - mkdir /home/kitchen/puppet - - printf <%= File.read('environments/etc/Puppetfile').inspect %> > /home/kitchen/puppet/Puppetfile - - printf <%= File.read('environments/etc/Gemfile').inspect %> > /home/Gemfile - - - gem install bundler -v '= 2.4.13' - - cd /home && bundle install - - cd /home/kitchen/puppet && r10k puppetfile install --moduledir=/tmp/modules +# TODO: validate module support for Rocky Linux +# Debug: Service[datadog-agent](provider=base): Executing 'ps -ef' +# Debug: Executing: 'ps -ef' +# Error: /Service[datadog-agent]: Could not evaluate: Execution of 'ps -ef' returned 1: Error: Could not execute posix command: No such file or directory - ps +# Debug: Service[datadog-agent](provider=base): Executing 'ps -ef' +# Debug: Executing: 'ps -ef' +# Error: /Service[datadog-agent]: Failed to call refresh: Execution of 'ps -ef' returned 1: Error: Could not execute posix command: No such file or directory - ps +# Error: /Service[datadog-agent]: Execution of 'ps -ef' returned 1: Error: Could not execute posix command: No such file or directory - ps +#- name: rocky-9-puppet-8 +# driver: +# image: 'rockylinux:9.3' +# platform: centosstream # kitchen-docker has issues installing packages otherwises +# provision_command: +# - dnf install -y https://yum.puppet.com/puppet8-release-el-9.noarch.rpm #installs the puppet-agent repo +# - dnf install -y puppet-agent rubygems ruby-devel +# - dnf group install -y "Development Tools" +# - ln -s /opt/puppetlabs/bin/puppet /usr/bin/puppet +# +# - mkdir /home/kitchen/puppet +# - printf <%= File.read('environments/etc/Puppetfile').inspect %> > /home/kitchen/puppet/Puppetfile +# - printf <%= File.read('environments/etc/Gemfile').inspect %> > /home/Gemfile +# +# - gem install bundler -v '= 2.4.13' +# +# - cd /home && bundle install +# - cd /home/kitchen/puppet && r10k puppetfile install --moduledir=/tmp/modules # - name: opensuse/leap-15 # # Workaround for flakes on initializing opensuse/leap-15: From ba41ecfc823d7adad60ef3ce5cbc860bbc59d7ee Mon Sep 17 00:00:00 2001 From: Fanny Jiang Date: Fri, 14 Feb 2025 13:40:25 -0500 Subject: [PATCH 8/8] fix ubuntu kitchen tests --- manifests/init.pp | 2 ++ templates/installer/telemetry/log.json.epp | 2 +- templates/installer/telemetry/trace.json.epp | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index badd8b62..952a7673 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -395,6 +395,8 @@ $_agent_major_version = $agent_major_version } else { $_agent_major_version = $datadog_agent::params::default_agent_major_version + $_agent_minor_version = 0 + $_agent_patch_version = 0 } case $facts['os']['name'] { diff --git a/templates/installer/telemetry/log.json.epp b/templates/installer/telemetry/log.json.epp index c0dd58f8..c303a1d8 100644 --- a/templates/installer/telemetry/log.json.epp +++ b/templates/installer/telemetry/log.json.epp @@ -6,7 +6,7 @@ "seq_id": 2, "origin": "puppet", "host": { - "hostname": "<%= $hostname %>", + "hostname": "<%= $facts['networking']['hostname'] %>", "os": "<%= $facts['os']['name'] %>", "distribution": "<%= $facts['os']['family'] %>", "architecture": "<%= $facts['os']['architecture'] %>", diff --git a/templates/installer/telemetry/trace.json.epp b/templates/installer/telemetry/trace.json.epp index bfb274a7..1c20c058 100644 --- a/templates/installer/telemetry/trace.json.epp +++ b/templates/installer/telemetry/trace.json.epp @@ -6,7 +6,7 @@ "seq_id": 1, "origin": "puppet", "host": { - "hostname": "<%= $hostname %>", + "hostname": "<%= $facts['networking']['hostname'] %>", "os": "<%= $facts['os']['name'] %>", "distribution": "<%= $facts['os']['family'] %>", "architecture": "<%= $facts['os']['architecture'] %>",