-
-
Notifications
You must be signed in to change notification settings - Fork 241
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
Fix prometheus not restarting after config changes on systemd based systems #390
Conversation
File { | ||
notify => Class['prometheus::run_service'], | ||
} | ||
$systemd_notify = [Exec['prometheus-systemd-reload'], Class['prometheus::run_service']] |
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.
Both this variable and the Exec
resource disappeared 2 years ago in #90
} | ||
} | ||
'systemd' : { | ||
include 'systemd' |
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.
systemd::unit_file
already has an include systemd
owner => 'root', | ||
group => 'root', | ||
content => template('prometheus/prometheus.debian.erb'), | ||
'sysv', 'redhat', 'debian', 'sles' : { |
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.
These all declare the same file, so I've tried to remove a bit of duplication here.
@@ -232,6 +224,7 @@ | |||
group => $prometheus::server::group, | |||
purge => true, | |||
recurse => true, | |||
notify => Class['prometheus::service_reload'], # After purging, a reload is needed |
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.
Previously, a purge of scrape job files would have caused a full service restart.
@@ -94,6 +94,6 @@ | |||
|
|||
Class['prometheus::install'] | |||
-> Class['prometheus::config'] | |||
-> Class['prometheus::run_service'] | |||
-> Class['prometheus::run_service'] # Note: config must *not* be configured here to notify run_service. Some resources in config.pp need to notify service_reload instead |
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.
My first thought was to add
if $restart_on_change {
Class['prometheus::config'] ~> Class['prometheus::run_service']
}
to this class. This would have been a mistake. Hopefully this comment will stop someone else having the same idea in the future! :)
@@ -2,7 +2,7 @@ | |||
|
|||
describe 'prometheus server basics' do | |||
it 'prometheus server via main class works idempotently with no errors' do | |||
pp = "class{'prometheus': manage_prometheus_server => true, version => '1.5.2' }" | |||
pp = "class{'prometheus': manage_prometheus_server => true }" |
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.
Default version (> 2.0.0) is needed to test the admin API.
9ca2ec5
to
ddc9d7b
Compare
manifests/config.pp
Outdated
notify => Class['prometheus::run_service'], | ||
} | ||
$systemd_notify = [Exec['prometheus-systemd-reload'], Class['prometheus::run_service']] | ||
$notify = Class['prometheus::run_service'] |
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.
we should now use a selector statement here?
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.
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.
sure. Updated. I could always go either way when deciding if a selector is more readable than a simple if/else
when the control expression is a Boolean.
In systemd, the service is currently not being restarted after configuration changes. See voxpupuliGH-382 The acceptance test in this commit reconfigures prometheus with the admin API enabled and then attempts to access it. See https://prometheus.io/docs/prometheus/latest/querying/api/#tsdb-admin-apis
The [unreliable](https://puppet.com/docs/puppet/5.5/lang_defaults.html#behavior) resource default ``` File{ notify => Class['prometheus::run_service'] } ``` is replaced by a `$notify` variable that is set on the relevant file resources *and* `systemd::unit_file`. Some care was needed to make sure the reload behaviour wasn't broken. ie If the configuration change is just a new scrape job that is collected, the service should only be reloaded, not restarted. Fixes voxpupuli#382
ddc9d7b
to
8588d88
Compare
Fix prometheus not restarting after config changes on systemd based systems
The unreliable resource default
is replaced by a
$notify
variable that is set on the relevant fileresources and
systemd::unit_file
. Some care was needed to make surethe reload behaviour wasn't broken. ie If the configuration change is
just a new scrape job that is collected, the service should only be
reloaded, not restarted.
Fixes #382
This PR supersedes #383