Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write_http/disk is own sub package on CentOS 8 #920

Merged
merged 1 commit into from
Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifests/plugin/disk.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

include collectd

if $facts['os']['family'] == 'RedHat' {
if $facts['os']['family'] == 'RedHat' and versioncmp($facts['os']['release']['major'],'8') >= 0 {
if $manage_package != undef {
$_manage_package = $manage_package
} else {
Expand Down
25 changes: 23 additions & 2 deletions manifests/plugin/write_http.pp
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# https://collectd.org/wiki/index.php/Plugin:Write_HTTP
# @summary Enable write_http plugin
#
# @see https://collectd.org/wiki/index.php/Plugin:Write_HTTP
#
# @parameter Manage a collectd-write_http package? If undef a suitable value per OS will be chosen.
#
class collectd::plugin::write_http (
Enum['present', 'absent'] $ensure = 'present',
Hash[String, Hash[String, Scalar]] $nodes = {},
Hash[String, Hash[String, Scalar]] $urls = {}
Hash[String, Hash[String, Scalar]] $urls = {},
Optional[Boolean] $manage_package = undef,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of an Optional Boolean. Can't we set the default to true or fals?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case there are 3 states.

  • Use the default for operating system (so false on debian, true on redhat 8)
  • Force to be false.
  • Force to be true.

) {

include collectd
Expand All @@ -11,6 +17,21 @@
fail('Only one of nodes or urls is supposed to be defined')
}

if $manage_package !~ Undef {
$_manage_package = $manage_package
} else {
if $facts['os']['family'] == 'RedHat' and versioncmp($facts['os']['release']['major'],'8') >= 0 {
traylenator marked this conversation as resolved.
Show resolved Hide resolved
$_manage_package = true
} else {
$_manage_package = false
}
}
if $_manage_package {
package{'collectd-write_http':
ensure => $ensure,
}
}

$endpoints = merge($nodes, $urls)
collectd::plugin { 'write_http':
ensure => $ensure,
Expand Down
46 changes: 46 additions & 0 deletions spec/acceptance/class_plugin_disk_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'spec_helper_acceptance'

describe 'collectd::plugin::disk class' do
context 'basic parameters' do
# Using puppet_apply as a helper
it 'works idempotently with no errors' do
pp = <<-EOS
class{'collectd':
utils => true,
}
class{'collectd::plugin::disk': }
# Add one write plugin to keep logs quiet
class{'collectd::plugin::csv':}
# Create a socket to query
class{'collectd::plugin::unixsock':
socketfile => '/var/run/collectd-sock',
socketgroup => 'root',
}

EOS
# Run 3 times since the collectd_version
# fact is impossible until collectd is
# installed.
apply_manifest(pp, catch_failures: false)
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
# Wait to get some data
shell('sleep 10')
end

describe service('collectd') do
it { is_expected.to be_running }
end

describe command('collectdctl -s /var/run/collectd-sock listval') do
its(:exit_status) { is_expected.to eq 0 }
# the reason debian does not report disk metrics on docker images despite the
# module being loaded is an exercise for the reader.
# For CentOS 7 it works on my laptop but not in travis.
# disk plugin is probably very sensitive to environment.
if fact('os.family') == 'Redhat' && fact('os.release.major') == '8'
its(:stdout) { is_expected.to match %r{disk_time} }
end
end
end
end
30 changes: 30 additions & 0 deletions spec/acceptance/class_plugin_write_http_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'spec_helper_acceptance'

describe 'collectd::plugin::write_http class' do
context 'basic parameters' do
# Using puppet_apply as a helper
it 'works idempotently with no errors' do
pp = <<-EOS
class{'collectd':}
class { 'collectd::plugin::write_http':
nodes => {
'collect1' => { 'url' => 'collect1.example.org', 'format' => 'JSON' },
'collect2' => { 'url' => 'collect2.example.org'},
}
}
EOS
# Run 3 times since the collectd_version
# fact is impossible until collectd is
# installed.
apply_manifest(pp, catch_failures: false)
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
# Wait to get some data
shell('sleep 10')
end

describe service('collectd') do
it { is_expected.to be_running }
end
end
end
4 changes: 2 additions & 2 deletions spec/classes/collectd_plugin_disk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@
end
end

case facts[:os]['family']
when 'RedHat'
case [facts[:os]['family'], facts[:os]['release']['major']]
when %w[RedHat 8]
context ':manage_package => undef with collectd 5.5 and up' do
let :facts do
facts.merge(collectd_version: '5.5')
Expand Down
6 changes: 6 additions & 0 deletions spec/classes/collectd_plugin_write_http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
content: "#\ Generated by Puppet\n<LoadPlugin write_http>\n Globals false\n</LoadPlugin>\n\n<Plugin \"write_http\">\n <URL \"collectd.org.1\">\n\n Format \"JSON\"\n </URL>\n\n</Plugin>\n\n"
)
end
case [facts[:os]['family'], facts[:os]['release']['major']]
when %w[RedHat 8]
it { is_expected.to contain_package('collectd-write_http') }
else
it { is_expected.not_to contain_package('collectd-write_http') }
end
end

context ':ensure => present and :nodes => { \'collectd\' => { \'url\' => \'collectd.org.1\', \'format\' => \'JSON\'}}' do
Expand Down