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

Add validation to config changes #122

Merged
merged 4 commits into from
Jan 4, 2018

Conversation

costela
Copy link

@costela costela commented Nov 30, 2017

This PR adds a symlink to promtool in the same way a symlink to prometheus is currently added to /usr/local/bin.
Than it uses File's validate_cmd to call promtool and avoid replacing a configuration file with a broken version, both for the central config and for the alert rules.

Finally, also fix the first error thrown by the config check: we create the alerts file even if no alerts were provided. The empty file won't trigger a syntax error and also doesn't bother prometheus itself.

Fixes #31

@costela costela force-pushed the config_verify branch 2 times, most recently from 255b121 to 377b264 Compare November 30, 2017 16:28
@tuxmea
Copy link
Member

tuxmea commented Nov 30, 2017

@costela Many thanks for the PR. Please check the travis error:
Evaluation Error: Unknown variable: 'prometheus::alerts::location'. at manifests/config.pp:127:29

@costela
Copy link
Author

costela commented Nov 30, 2017

@tuxmea yeah, I'm on it. Had a last minute change of heart on the last patch, and it didn't go very smoothly 😉

@costela costela force-pushed the config_verify branch 3 times, most recently from bec0510 to 2a8b1b1 Compare November 30, 2017 16:50
@costela
Copy link
Author

costela commented Nov 30, 2017

@tuxmea done

@costela
Copy link
Author

costela commented Nov 30, 2017

Please note there's a small breaking change in the last patch: the purge parameter to prometheus::config was renamed and moved to prometheus::install, together with the creation of the /etc/prometheus directory. This was necessary to add the missing dependency between the config file and the alerts file without creating a dependency cycle.
Since I don't expect direct use of prometheus::config to be common (or supported), I assumed it was an acceptable change.

@costela
Copy link
Author

costela commented Dec 18, 2017

@tuxmea did you maybe have a minute to check the PR?
Don't mean to be a nuisance, but I have a second, bigger PR in the pipeline for #126 that I'm too lazy to rebase on master 😉

class prometheus::install
{
class prometheus::install (
Boolean $purge_config_dir = true,
Copy link
Member

Choose a reason for hiding this comment

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

Datatypes \o/

@bastelfreak bastelfreak mentioned this pull request Jan 4, 2018
Copy link
Member

@tuxmea tuxmea left a comment

Choose a reason for hiding this comment

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

Is there a specific reason why config_dir was moved from config.pp to install.pp?

@@ -78,4 +82,11 @@
system => true,
})
}
file { $prometheus::config_dir:
Copy link
Member

Choose a reason for hiding this comment

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

why moving this from config to install class?

Copy link
Author

Choose a reason for hiding this comment

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

as I mentioned in a comment above: this was necessary to add the missing dependency between the config file and the alerts file without creating a dependency cycle. Now both depend on the directory, which gets created first during install.
The config file needs the alerts file, because the newly introduced validation with promtool chokes if it can't find the named alerts file.
That's also the reason why I removed the conditional creation of the alerts file and create it always (even if empty). Otherwise the dependency would have to be conditional on the alert file's creation and the prometheus.yaml.erb template would also have to be changed to not always reference a possibly non-existent alerts file.
In summary: it just felt like the path of least resistance 😉

Copy link
Member

Choose a reason for hiding this comment

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

ACK +1

This is needed to break a dependency cycle involving alert.rules and the main config.

Minor breaking change: if anyone used the purge argument directly to prometheus::config (instead of the prometheus class itself), the call will have to be adjusted.
@bastelfreak bastelfreak merged commit 9b159cd into voxpupuli:master Jan 4, 2018
@costela costela deleted the config_verify branch January 4, 2018 15:42
Rovanion pushed a commit to Rovanion/puppet-prometheus that referenced this pull request May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Install Promtool
4 participants