From a0fafb83914d9b31d2aa43da20d7e18addaaea56 Mon Sep 17 00:00:00 2001 From: Adrian Date: Mon, 11 Oct 2021 15:08:15 -0700 Subject: [PATCH] Add tests for customizing collection_frequency This commit adds tests to the puppet_metrics_collector and puppet_metrics_collector::system classes for customizing the collection interval. It also removes the String() casts. --- manifests/system/postgres.pp | 2 +- manifests/system/vmware.pp | 2 +- spec/classes/init_spec.rb | 8 ++++++++ .../classes/puppet_metrics_collector_system_spec.rb | 13 +++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/manifests/system/postgres.pp b/manifests/system/postgres.pp index d963c44..7910f0a 100644 --- a/manifests/system/postgres.pp +++ b/manifests/system/postgres.pp @@ -36,7 +36,7 @@ metrics_command => $metrics_command, tidy_command => $tidy_command, metric_ensure => $metrics_ensure, - minute => String("0/${collection_frequency}"), + minute => "0/${collection_frequency}", notify => Exec['puppet_metrics_collector_system_daemon_reload'], } diff --git a/manifests/system/vmware.pp b/manifests/system/vmware.pp index adec17b..cae7b7b 100644 --- a/manifests/system/vmware.pp +++ b/manifests/system/vmware.pp @@ -44,7 +44,7 @@ metrics_command => $metrics_command, tidy_command => $tidy_command, metric_ensure => $metrics_ensure, - minute => String("0/${collection_frequency}"), + minute => "0/${collection_frequency}", notify => Exec['puppet_metrics_collector_system_daemon_reload'], } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index c2f2b2f..4e331e7 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -26,4 +26,12 @@ it { is_expected.to compile } end + + context 'when customizing the collection frequency' do + let(:params) { { collection_frequency: 10 } } + + ['ace', 'bolt', 'orchestrator', 'puppetdb', 'puppetserver'].each do |service| + it { is_expected.to contain_file("/etc/systemd/system/puppet_#{service}-metrics.timer").with_content(%r{OnCalendar=.*0\/10}) } + end + end end diff --git a/spec/classes/puppet_metrics_collector_system_spec.rb b/spec/classes/puppet_metrics_collector_system_spec.rb index 9cb7efb..2510c1e 100644 --- a/spec/classes/puppet_metrics_collector_system_spec.rb +++ b/spec/classes/puppet_metrics_collector_system_spec.rb @@ -115,4 +115,17 @@ class {'puppet_metrics_collector': it { is_expected.not_to contain_puppet_metrics_collector__collect('system_cpu').with_metrics_command(%r{--influx-db\s+puppet_metrics}) } end + + context 'when customizing the collection frequency' do + let(:facts) { + { puppet_metrics_collector: { have_vmware_tools: true, have_systemd: true, have_sysstat: true, have_pe_psql: true }, + virtual: 'vmware' + } + } + let(:params) { { collection_frequency: 10 } } + + ['system_cpu', 'system_memory', 'system_processes', 'postgres', 'vmware'].each do |service| + it { is_expected.to contain_file("/etc/systemd/system/puppet_#{service}-metrics.timer").with_content(%r{OnCalendar=.*0\/10}) } + end + end end