Skip to content

Commit

Permalink
Add tests for customizing collection_frequency
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
m0dular committed Oct 11, 2021
1 parent 321df28 commit a0fafb8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion manifests/system/postgres.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}

Expand Down
2 changes: 1 addition & 1 deletion manifests/system/vmware.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}

Expand Down
8 changes: 8 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions spec/classes/puppet_metrics_collector_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a0fafb8

Please sign in to comment.