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

Make the threshold plugin configurable #829

Merged
merged 5 commits into from
Jul 15, 2018

Conversation

smortex
Copy link
Member

@smortex smortex commented Jul 11, 2018

Pull Request (PR) description

Allow to configure the threshold plugin

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,
      },
    },
  },
}

This Pull Request (PR) fixes the following issues

Fixes #292

@smortex smortex force-pushed the threshold branch 2 times, most recently from a1a3b32 to 11cf645 Compare July 11, 2018 13:54
```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).
@@ -2,12 +2,16 @@
class collectd::plugin::threshold (
$ensure = 'present',
$interval = undef,
Hash[String, Collectd::Threshold::Type] $types = {},
Copy link
Member

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]?

Copy link
Member Author

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 🤔

@bastelfreak
Copy link
Member

Thanks for the excellent PR @smortex ! Can you please take a look at the inline comment I made?

@smortex
Copy link
Member Author

smortex commented Jul 11, 2018

I do not think it makes sense to pass an empty string to any of these strings, so I changed them all to String[1]. Thanks!

@smortex
Copy link
Member Author

smortex commented Jul 12, 2018

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 rx and tx data sources of a single network interface:

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 ({ if_octets => [ { ...tx }, { ...rx }]}), this impose a level of hierarchy that does not exist in collectd, and I would rather change this to something like that:

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 😉

@smortex
Copy link
Member Author

smortex commented Jul 13, 2018

@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,
Copy link
Member

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.

@@ -2,12 +2,16 @@
class collectd::plugin::threshold (
$ensure = 'present',
$interval = undef,
Array[Collectd::Threshold::Type] $types = [],
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in dd7fb6d

@@ -2,12 +2,16 @@
class collectd::plugin::threshold (
$ensure = 'present',
$interval = undef,
Array[Collectd::Threshold::Type] $types = [],
Array[Collectd::Threshold::Plugin] $plugins = [],
Copy link
Member

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.

Copy link
Member Author

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:

https://github.com/smortex/puppet-collectd/blob/29a87d1a44acb80b238e22ca2168032025cb5c9f/spec/classes/collectd_plugin_threshold_spec.rb#L71-L99

@bastelfreak bastelfreak mentioned this pull request Jul 14, 2018
While here, align all parameters and default values.
@bastelfreak
Copy link
Member

Thanks for the updates @smortex !

@bastelfreak bastelfreak merged commit 8a3b009 into voxpupuli:master Jul 15, 2018
@bastelfreak bastelfreak added the enhancement New feature or request label Jul 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request - thresholds
2 participants