Skip to content

Commit

Permalink
Create processess plugin type configuration on RedHat
Browse files Browse the repository at this point in the history
There was a name clash between:
* Puppet created configuration file.
* Package provided configuration file which was being purged.

Since a864d0d the collectd module on RedHat
purges the package provided file file `/etc/collectd.d/processes-config.conf`

The module was also creating this file with a concat and result was no
file on system.

To avoid the clash puppet now creates the file `processes_config.conf`. Note
the `-` vs `_`.

There is probably a cleaner fix to move all of the processes plugin configuration
into the per module file `/etc/collect.d/10-processses.conf` as that would
be more consistant with other simpler modules using a single template
rather than a concat. This would be a change for every module
however with `collectd::plugin` itself changing.

Fixes voxpupuli#926
  • Loading branch information
traylenator committed Mar 24, 2020
1 parent 940a7ad commit 1caca48
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 20 deletions.
6 changes: 3 additions & 3 deletions manifests/plugin/processes.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
interval => $interval,
}

concat { "${collectd::plugin_conf_dir}/processes-config.conf":
concat { "${collectd::plugin_conf_dir}/processes_config.conf":
ensure => $ensure,
mode => $collectd::config_mode,
owner => $collectd::config_owner,
Expand All @@ -32,13 +32,13 @@
concat::fragment { 'collectd_plugin_processes_conf_header':
order => '00',
content => epp('collectd/plugin/processes-header.conf.epp'),
target => "${collectd::plugin_conf_dir}/processes-config.conf",
target => "${collectd::plugin_conf_dir}/processes_config.conf",
}

concat::fragment { 'collectd_plugin_processes_conf_footer':
order => '99',
content => '</Plugin>',
target => "${collectd::plugin_conf_dir}/processes-config.conf",
target => "${collectd::plugin_conf_dir}/processes_config.conf",
}

if $processes {
Expand Down
2 changes: 1 addition & 1 deletion manifests/plugin/processes/process.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'collect_file_descriptor' => $collect_file_descriptor,
'collect_memory_maps' => $collect_memory_maps,
}),
target => "${collectd::plugin_conf_dir}/processes-config.conf",
target => "${collectd::plugin_conf_dir}/processes_config.conf",
}

}
2 changes: 1 addition & 1 deletion manifests/plugin/processes/processmatch.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
'collect_file_descriptor' => $collect_file_descriptor,
'collect_memory_maps' => $collect_memory_maps,
}),
target => "${collectd::plugin_conf_dir}/processes-config.conf",
target => "${collectd::plugin_conf_dir}/processes_config.conf",
}
}
45 changes: 45 additions & 0 deletions spec/acceptance/aa_define_plugin_processes_process_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'spec_helper_acceptance'

describe 'collectd::plugin::processes::process' do
context 'basic parameters' do
# Using puppet_apply as a helper
it 'works idempotently with no errors' do
pp = <<-EOS
class{'collectd':
utils => true,
}
collectd::plugin::processes::process{'bar':
collect_file_descriptor => true,
}
# Configure 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',
deletesocket => true,
}
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 }
its(:stdout) { is_expected.to match %r{processes-bar/ps_count} }
end
end
end
46 changes: 46 additions & 0 deletions spec/acceptance/aa_define_plugin_processes_processmatch_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'spec_helper_acceptance'

describe 'collectd::plugin::processes::processmatchs' do
context 'basic parameters' do
# Using puppet_apply as a helper
it 'works idempotently with no errors' do
pp = <<-EOS
class{'collectd':
utils => true,
}
# Configure one write plugin to keep logs quiet
collectd::plugin::processes::processmatch{'foo':
collect_file_descriptor => true,
regex => 'foo .*$',
}
class{'collectd::plugin::csv':}
# Create a socket to query
class{'collectd::plugin::unixsock':
socketfile => '/var/run/collectd-sock',
socketgroup => 'root',
deletesocket => true,
}
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 }
its(:stdout) { is_expected.to match %r{processes-foo/ps_count} }
end
end
end
34 changes: 19 additions & 15 deletions spec/classes/collectd_plugin_processes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
)
end

it "Will create #{options[:plugin_conf_dir]}/processes-config.conf" do
is_expected.to contain_concat("#{options[:plugin_conf_dir]}/processes-config.conf").that_requires('File[collectd.d]')
it "Will create #{options[:plugin_conf_dir]}/processes_config.conf" do
is_expected.to contain_concat("#{options[:plugin_conf_dir]}/processes_config.conf").that_requires('File[collectd.d]')
is_expected.to contain_concat__fragment('collectd_plugin_processes_conf_header').with(
content: "<Plugin processes>\n",
target: "#{options[:plugin_conf_dir]}/processes-config.conf",
target: "#{options[:plugin_conf_dir]}/processes_config.conf",
order: '00'
)
end

it "Will create #{options[:plugin_conf_dir]}/processes-config.conf" do
it "Will create #{options[:plugin_conf_dir]}/processes_config.conf" do
is_expected.to contain_concat__fragment('collectd_plugin_processes_conf_footer').with(
content: %r{</Plugin>},
target: "#{options[:plugin_conf_dir]}/processes-config.conf",
target: "#{options[:plugin_conf_dir]}/processes_config.conf",
order: '99'
)
end
Expand Down Expand Up @@ -66,15 +66,15 @@
}
end

it "Will create #{options[:plugin_conf_dir]}/processes-config.conf" do
is_expected.to contain_concat("#{options[:plugin_conf_dir]}/processes-config.conf").that_requires('File[collectd.d]')
it "Will create #{options[:plugin_conf_dir]}/processes_config.conf" do
is_expected.to contain_concat("#{options[:plugin_conf_dir]}/processes_config.conf").that_requires('File[collectd.d]')
is_expected.to contain_concat__fragment('collectd_plugin_processes_conf_header').with(
content: "<Plugin processes>
CollectContextSwitch true
CollectFileDescriptor false
CollectMemoryMaps true
",
target: "#{options[:plugin_conf_dir]}/processes-config.conf",
target: "#{options[:plugin_conf_dir]}/processes_config.conf",
order: '00'
)
is_expected.to contain_concat__fragment('collectd_plugin_processes_conf_process_httpd').with(
Expand All @@ -84,14 +84,14 @@
CollectMemoryMaps false
</Process>
",
target: "#{options[:plugin_conf_dir]}/processes-config.conf",
target: "#{options[:plugin_conf_dir]}/processes_config.conf",
order: '50'
)
is_expected.to contain_concat__fragment('collectd_plugin_processes_conf_process_mysql').with(
content: " <Process \"mysql\">
</Process>
",
target: "#{options[:plugin_conf_dir]}/processes-config.conf",
target: "#{options[:plugin_conf_dir]}/processes_config.conf",
order: '50'
)

Expand All @@ -102,14 +102,14 @@
CollectMemoryMaps false
</ProcessMatch>
",
target: "#{options[:plugin_conf_dir]}/processes-config.conf",
target: "#{options[:plugin_conf_dir]}/processes_config.conf",
order: '51'
)
is_expected.to contain_concat__fragment('collectd_plugin_processes_conf_processmatch_dove').with(
content: " <ProcessMatch \"dove\" \"dove.*\">
</ProcessMatch>
",
target: "#{options[:plugin_conf_dir]}/processes-config.conf",
target: "#{options[:plugin_conf_dir]}/processes_config.conf",
order: '51'
)
end
Expand All @@ -122,19 +122,19 @@
}
end

it "Will create #{options[:plugin_conf_dir]}/processes-config.conf" do
it "Will create #{options[:plugin_conf_dir]}/processes_config.conf" do
is_expected.to contain_concat__fragment('collectd_plugin_processes_conf_process_process1').with(
content: " <Process \"process1\">
</Process>
",
target: "#{options[:plugin_conf_dir]}/processes-config.conf",
target: "#{options[:plugin_conf_dir]}/processes_config.conf",
order: '50'
)
is_expected.to contain_concat__fragment('collectd_plugin_processes_conf_process_process2').with(
content: " <Process \"process2\">
</Process>
",
target: "#{options[:plugin_conf_dir]}/processes-config.conf",
target: "#{options[:plugin_conf_dir]}/processes_config.conf",
order: '50'
)
end
Expand All @@ -145,6 +145,10 @@
context 'on osfamily => RedHat' do
it 'Will delete packaging config file' do
is_expected.to contain_file('package_processes.load').with_ensure('absent')
is_expected.to contain_file('package_processes.load').with_path('/etc/collectd.d/processes-config.conf')
end
it 'Will not clash with package file' do
is_expected.not_to contain_concat('/etc/collectd.d/processes-config.conf')
end
end
end
Expand Down

0 comments on commit 1caca48

Please sign in to comment.