Skip to content
This repository was archived by the owner on Sep 29, 2020. It is now read-only.

Commit 434aa36

Browse files
committed
Improve version handling to avoid multiple puppet runs for some situations
When an administrator knows the version of collectd that will be used or at least the minimum version available the need for two puppet runs before convergence can be avoided or at least minimised. Instead of using the fact in the templates they now use a class variable set to one of (in priority order): * collectd_version (i.e. the fact) * version (the semver matched part of it only) * minimum_version (undef by default) Existing behaviour is preserved except for a corner case where version is set to something specific and collectd is not yet installed. In this case puppet will only take one run and assume the version specified when creating the templates references voxpupuli#162
1 parent 8d89800 commit 434aa36

29 files changed

+69
-57
lines changed

README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ declaration:
2727

2828
```puppet
2929
class { '::collectd':
30-
purge => true,
31-
recurse => true,
32-
purge_config => true,
30+
purge => true,
31+
recurse => true,
32+
purge_config => true,
33+
minimum_version => '5.4',
3334
}
3435
```
3536

@@ -38,6 +39,10 @@ the default configurations shipped in collectd.conf and use
3839
custom configurations stored in conf.d. From here you can set up
3940
additional plugins as shown below.
4041

42+
Specifying the version or minimum_version of collectd as shown above reduces the need for
43+
two puppet runs to coverge. See [Puppet needs two runs to correctly write my conf, why?](#puppet-needs-two-runs-to-correctly-write-my-conf,-why?) below.
44+
45+
4146
Simple Plugins
4247
--------------
4348

@@ -1086,7 +1091,10 @@ See metadata.json for supported platforms
10861091

10871092
##Known issues
10881093

1094+
###Puppet needs two runs to correctly write my conf, why?
1095+
10891096
Some plugins will need two runs of Puppet to fully generate the configuration for collectd. See [this issue](https://github.com/pdxcat/puppet-module-collectd/issues/162).
1097+
This can be avoided by specifying an explicit version (`$version`) or a minimum version (`$minimum_version`) to the collectd class
10901098

10911099
##Development
10921100

manifests/init.pp

+4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
$write_queue_limit_low = undef,
1515
$package_name = $collectd::params::package,
1616
$version = installed,
17+
$minimum_version = undef,
1718
) inherits collectd::params {
1819

1920
$plugin_conf_dir = $collectd::params::plugin_conf_dir
2021
validate_bool($purge_config, $fqdnlookup)
2122
validate_array($include, $typesdb)
2223

24+
# Version for templates
25+
$_collectd_version = pick($::collectd_version, regsubst($version, '^\d+(?:\.\d+){1.2}', '\0'), $minimum_version)
26+
2327
package { $package_name:
2428
ensure => $version,
2529
name => $package_name,

spec/classes/collectd_plugin_cpu_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
context 'cpu options should be set with collectd 5.5' do
3434
let :facts do
3535
{:osfamily => 'RedHat',
36-
:collectd_version => '5.5',
36+
:_collectd_version => '5.5',
3737
}
3838
end
3939
let :params do

spec/classes/collectd_plugin_exec_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
:id => 'root',
1010
:kernel => 'Linux',
1111
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
12-
:collectd_version => '5.0'
12+
:_collectd_version => '5.0'
1313
}
1414
end
1515

spec/classes/collectd_plugin_libvirt_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
}
1010
end
1111

12-
context 'with collectd_version < 5.0' do
12+
context 'with _collectd_version < 5.0' do
1313
let :facts do
1414
{ :osfamily => 'Debian',
15-
:collectd_version => '4.10.1',
15+
:_collectd_version => '4.10.1',
1616
}
1717
end
1818

@@ -22,10 +22,10 @@
2222
end
2323
end
2424

25-
context 'with collectd_version >= 5.0' do
25+
context 'with _collectd_version >= 5.0' do
2626
let :facts do
2727
{ :osfamily => 'Debian',
28-
:collectd_version => '5.0.0',
28+
:_collectd_version => '5.0.0',
2929
}
3030
end
3131

spec/classes/collectd_plugin_memory_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
context ':ensure => present, specific params, collectd version 5.4.2' do
1919
let :facts do
2020
{ :osfamily => 'Redhat',
21-
:collectd_version => '5.4.2'
21+
:_collectd_version => '5.4.2'
2222
}
2323
end
2424

@@ -38,7 +38,7 @@
3838
context ':ensure => present, specific params, collectd version 5.5.0' do
3939
let :facts do
4040
{ :osfamily => 'Redhat',
41-
:collectd_version => '5.5.0'
41+
:_collectd_version => '5.5.0'
4242
}
4343
end
4444

spec/classes/collectd_plugin_openvpn_spec.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
context ':ensure => present, default params' do
99
let :facts do
1010
{ :osfamily => 'RedHat',
11-
:collectd_version => '5.4',
11+
:_collectd_version => '5.4',
1212
}
1313
end
1414

@@ -24,7 +24,7 @@
2424
context ':statusfile param is an array' do
2525
let :facts do
2626
{ :osfamily => 'RedHat',
27-
:collectd_version => '5.4',
27+
:_collectd_version => '5.4',
2828
}
2929
end
3030

@@ -47,7 +47,7 @@
4747
context ':statusfile is a string but not an absolute path' do
4848
let :facts do
4949
{ :osfamily => 'RedHat',
50-
:collectd_version => '5.4',
50+
:_collectd_version => '5.4',
5151
}
5252
end
5353

@@ -64,7 +64,7 @@
6464
context ':statusfile param is not a string or array' do
6565
let :facts do
6666
{ :osfamily => 'RedHat',
67-
:collectd_version => '5.4',
67+
:_collectd_version => '5.4',
6868
}
6969
end
7070

@@ -80,7 +80,7 @@
8080
context ':improvednamingschema is not a bool' do
8181
let :facts do
8282
{ :osfamily => 'RedHat',
83-
:collectd_version => '5.4'}
83+
:_collectd_version => '5.4'}
8484
end
8585
let :params do
8686
{:improvednamingschema => "true"}
@@ -94,7 +94,7 @@
9494
context ':collectcompression is not a bool' do
9595
let :facts do
9696
{ :osfamily => 'RedHat',
97-
:collectd_version => '5.4'}
97+
:_collectd_version => '5.4'}
9898
end
9999
let :params do
100100
{:collectcompression => "true"}
@@ -108,7 +108,7 @@
108108
context ':collectindividualusers is not a bool' do
109109
let :facts do
110110
{ :osfamily => 'RedHat',
111-
:collectd_version => '5.4'}
111+
:_collectd_version => '5.4'}
112112
end
113113
let :params do
114114
{:collectindividualusers => "true"}
@@ -122,7 +122,7 @@
122122
context ':collectusercount is not a bool' do
123123
let :facts do
124124
{ :osfamily => 'RedHat',
125-
:collectd_version => '5.4'}
125+
:_collectd_version => '5.4'}
126126
end
127127
let :params do
128128
{:collectusercount => "true"}
@@ -136,7 +136,7 @@
136136
context ':interval is not default and is an integer' do
137137
let :facts do
138138
{ :osfamily => 'RedHat',
139-
:collectd_version => '5.4'}
139+
:_collectd_version => '5.4'}
140140
end
141141
let :params do
142142
{:interval => 15}
@@ -154,7 +154,7 @@
154154
context ':ensure => absent' do
155155
let :facts do
156156
{ :osfamily => 'RedHat',
157-
:collectd_version => '5.4',
157+
:_collectd_version => '5.4',
158158
}
159159
end
160160
let :params do

spec/classes/collectd_plugin_processes_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
:id => 'root',
99
:kernel => 'Linux',
1010
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
11-
:collectd_version => '5.0'
11+
:_collectd_version => '5.0'
1212
}
1313
end
1414

spec/classes/collectd_plugin_python_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
:id => 'root',
1010
:kernel => 'Linux',
1111
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
12-
:collectd_version => '5.0'
12+
:_collectd_version => '5.0'
1313
}
1414
end
1515

spec/classes/collectd_plugin_swap_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
context ':ensure => present, specific params, collectd version 5.0' do
1919
let :facts do
2020
{ :osfamily => 'Redhat',
21-
:collectd_version => '5.0'
21+
:_collectd_version => '5.0'
2222
}
2323
end
2424

@@ -34,7 +34,7 @@
3434
context ':ensure => present, specific params, collectd version 5.2.0' do
3535
let :facts do
3636
{ :osfamily => 'Redhat',
37-
:collectd_version => '5.2.0'
37+
:_collectd_version => '5.2.0'
3838
}
3939
end
4040

@@ -50,7 +50,7 @@
5050
context ':ensure => present, specific params, collectd version 5.5.0' do
5151
let :facts do
5252
{ :osfamily => 'Redhat',
53-
:collectd_version => '5.5.0'
53+
:_collectd_version => '5.5.0'
5454
}
5555
end
5656

spec/classes/collectd_plugin_varnish_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
context 'When the version is not 5.4' do
55
let :facts do
66
{ :osfamily => 'RedHat',
7-
:collectd_version => '5.3',
7+
:_collectd_version => '5.3',
88
}
99
end
1010
let :params do
@@ -23,7 +23,7 @@
2323
context 'When the version is nil' do
2424
let :facts do
2525
{ :osfamily => 'RedHat',
26-
:collectd_version => nil,
26+
:_collectd_version => nil,
2727
}
2828
end
2929
let :params do
@@ -43,7 +43,7 @@
4343
context 'When the version is 5.4' do
4444
let :facts do
4545
{ :osfamily => 'RedHat',
46-
:collectd_version => '5.4',
46+
:_collectd_version => '5.4',
4747
}
4848
end
4949
context 'when there are no params given' do

spec/classes/collectd_plugin_write_graphite_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
:id => 'root',
1010
:kernel => 'Linux',
1111
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
12-
:collectd_version => '5.0'
12+
:_collectd_version => '5.0'
1313
}
1414
end
1515

@@ -101,7 +101,7 @@
101101
:id => 'root',
102102
:kernel => 'Linux',
103103
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
104-
:collectd_version => '5.3'
104+
:_collectd_version => '5.3'
105105
}
106106
end
107107
let :params do

spec/defines/collectd_plugin_network_listener_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
let :facts do
77
{
88
:osfamily => 'Redhat',
9-
:collectd_version => '4.6'
9+
:_collectd_version => '4.6'
1010
}
1111
end
1212
let (:title) {'mylistener'}
@@ -29,7 +29,7 @@
2929
let :facts do
3030
{
3131
:osfamily => 'Redhat',
32-
:collectd_version => '5.1.0'
32+
:_collectd_version => '5.1.0'
3333
}
3434
end
3535
let (:title) {'mylistener'}

spec/defines/collectd_plugin_network_server_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
let :facts do
77
{
88
:osfamily => 'Redhat',
9-
:collectd_version => '5.1.0'
9+
:_collectd_version => '5.1.0'
1010
}
1111
end
1212
let (:title) {'node1'}

spec/defines/collectd_plugin_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
let(:title) { 'test' }
77
let :facts do
88
{
9-
:collectd_version => '5.3',
9+
:_collectd_version => '5.3',
1010
:osfamily => 'Debian',
1111
}
1212
end
@@ -21,7 +21,7 @@
2121
let(:title) { 'test' }
2222
let :facts do
2323
{
24-
:collectd_version => '4.9.3',
24+
:_collectd_version => '4.9.3',
2525
:osfamily => 'Debian',
2626
}
2727
end

spec/defines/collectd_plugin_write_graphite_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
let(:title) { 'graphite_udp' }
1515
let :facts do
1616
{ :osfamily => 'RedHat',
17-
:collectd_version => '5.3',
17+
:_collectd_version => '5.3',
1818
:concat_basedir => tmpfilename('collectd-graphite'),
1919
}
2020
end
@@ -34,7 +34,7 @@
3434
let(:title) { 'wg' }
3535
let :facts do
3636
{ :osfamily => 'RedHat',
37-
:collectd_version => '5.4',
37+
:_collectd_version => '5.4',
3838
:concat_basedir => tmpfilename('collectd-graphite'),
3939
}
4040
end

templates/loadplugin.conf.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Generated by Puppet
2-
<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '4.9.4']) >= 0) -%>
2+
<% if @_collectd_version and (scope.function_versioncmp([@_collectd_version, '4.9.4']) >= 0) -%>
33
<LoadPlugin <%= @plugin %>>
44
Globals <%= @globals %>
5-
<% if @interval and @collectd_version and (scope.function_versioncmp([@collectd_version, '5.2']) >= 0) -%>
5+
<% if @interval and @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.2']) >= 0) -%>
66
Interval <%= @interval %>
77
<% end -%>
88
</LoadPlugin>

templates/mysql-database.conf.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Host "<%= @host %>"
66
User "<%= @username %>"
77
Password "<%= @password %>"
8-
<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '5.0']) >= 0) -%>
8+
<% if @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.0']) >= 0) -%>
99
Port "<%= @port %>"
1010
<% else -%>
1111
Port <%= @port %>

templates/plugin/cpu.conf.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '5.5']) >= 0) -%>
1+
<% if @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.5']) >= 0) -%>
22
<Plugin cpu>
33
ReportByState = <%= @reportbystate %>
44
ReportByCpu = <%= @reportbycpu %>

templates/plugin/curl-page.conf.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
<% if @cacert -%>
1717
CACert "<%= @cacert %>"
1818
<% end -%>
19-
<% if @header and @collectd_version and (scope.function_versioncmp([@collectd_version, '5.3']) >= 0) -%>
19+
<% if @header and @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.3']) >= 0) -%>
2020
Header "<%= @header %>"
2121
<% end -%>
22-
<% if @post and @collectd_version and (scope.function_versioncmp([@collectd_version, '5.3']) >= 0) -%>
22+
<% if @post and @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.3']) >= 0) -%>
2323
Post "<%= @post %>"
2424
<% end -%>
2525
<% unless @measureresponsetime.nil? -%>

0 commit comments

Comments
 (0)