-
-
Notifications
You must be signed in to change notification settings - Fork 269
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
Make the threshold plugin configurable #829
Conversation
a1a3b32
to
11cf645
Compare
```puppet class { 'collectd::plugin::processes': process_matches => [ 'carbon-cache', 'python.+carbon-cache', ], } class { 'collectd::plugin::threshold': plugins => { processes => { instance => 'carbon-cache', types => { data_source => 'processes', warning_min => 2, failure_min => 1, }, }, }, } ``` Fixes voxpupuli#292 (Above example from this issue).
manifests/plugin/threshold.pp
Outdated
@@ -2,12 +2,16 @@ | |||
class collectd::plugin::threshold ( | |||
$ensure = 'present', | |||
$interval = undef, | |||
Hash[String, Collectd::Threshold::Type] $types = {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you replace String
with String[1]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not just here I guess 🤔
Thanks for the excellent PR @smortex ! Can you please take a look at the inline comment I made? |
I do not think it makes sense to pass an empty string to any of these strings, so I changed them all to |
Hold a second! This data structure does not allow to build some valid hierarchies of configuration. For example we might want to configure thresholds on the class { 'collectd::plugin::threshold':
plugins => {
interface => {
instance => 'eth0',
types => {
if_octets => {
data_source => 'rx',
failure_max => 10000,
},
if_octets => { # <-------- Duplicate key "if_octets"
data_source => 'tx',
failure_max => 20000,
},
],
},
}.
} While it is possible to assign an array of hashes ( class { 'collectd::plugin::threshold':
plugins => [
{
name => 'interface',
instance => 'eth0',
types => [
{
name => 'if_octets',
data_source => 'rx',
failure_max => 10000,
},
{
name => 'if_octets',
data_source => 'tx',
failure_max => 20000,
},
],
},
],
} I should be able to hack this and to test it tomorrow 😉 |
@bastelfreak, I fixed the problem described above and updated the README to describe a typical use-case in new commits (I guess it's easier for reviewing). Feel free to squash all these commits into a single one when merging if you want to :-) |
Change most data types from Hash to Array to allow multiple blocks with the same name. The key of each Hash is now the 'name' of each Struct. While here, add an usage example to the README.
The previous configuration did not allowed to create a host with only plugins or types which is quite common, just like the plugin allows to not pass hosts, plugins or types. For consistency, never require any "child" Struct. While here, extend and reorder the tests.
name => 'load', | ||
data_source => 'shortterm', | ||
warning_max => $facts.dig('processors', 'count') * 1.2, | ||
failure_max => $facts.dig('processors', 'count') * 1.9, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting syntax. I never thought about appending dig()
directly to the $facts[]
hash.
manifests/plugin/threshold.pp
Outdated
@@ -2,12 +2,16 @@ | |||
class collectd::plugin::threshold ( | |||
$ensure = 'present', | |||
$interval = undef, | |||
Array[Collectd::Threshold::Type] $types = [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please align the =
chars please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in dd7fb6d
manifests/plugin/threshold.pp
Outdated
@@ -2,12 +2,16 @@ | |||
class collectd::plugin::threshold ( | |||
$ensure = 'present', | |||
$interval = undef, | |||
Array[Collectd::Threshold::Type] $types = [], | |||
Array[Collectd::Threshold::Plugin] $plugins = [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change, right? Because of the custom datatype, an empty array isn't allowed anymore and users now have to pass data to the new parameters, correct? Is that desired? If so, I need to mark it as backwards-incompatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so… I am quite new to the threshold plugin of collectd, but as far as I experienced, the puppet-collectd module allowed to enable the threshold
module but not to set a configuration, making it somewhat useless (the reason why I worked on this).
The default values of []
for $types
, $plugins
and $hosts
imply that if a user previously had enabled the threshold
module, if he does not change his configuration, the module is just loaded as it was before, without setting any thresholds (if the user used something external to the puppet-collectd module to setup a configuration, I guess this change should have no impact).
As a matter of facts, the first unit tests do not set $types
, $plugins
and $hosts
:
While here, align all parameters and default values.
Thanks for the updates @smortex ! |
Pull Request (PR) description
Allow to configure the threshold plugin
This Pull Request (PR) fixes the following issues
Fixes #292