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

Fix prometheus not restarting after config changes on systemd based systems #390

Merged
merged 2 commits into from
Nov 18, 2019

Conversation

alexjfisher
Copy link
Member

@alexjfisher alexjfisher commented Nov 18, 2019

The unreliable 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 #382

This PR supersedes #383

File {
notify => Class['prometheus::run_service'],
}
$systemd_notify = [Exec['prometheus-systemd-reload'], Class['prometheus::run_service']]
Copy link
Member Author

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'
Copy link
Member Author

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' : {
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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 }"
Copy link
Member Author

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.

@alexjfisher alexjfisher changed the title Fix systemd unit file not notifying the service WIP: Fix systemd unit file not notifying the service Nov 18, 2019
notify => Class['prometheus::run_service'],
}
$systemd_notify = [Exec['prometheus-systemd-reload'], Class['prometheus::run_service']]
$notify = Class['prometheus::run_service']
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

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
@alexjfisher alexjfisher changed the title WIP: Fix systemd unit file not notifying the service Fix systemd unit file not notifying the service Nov 18, 2019
@alexjfisher alexjfisher changed the title Fix systemd unit file not notifying the service Fix prometheus not restarting after config changes on systemd based systems Nov 18, 2019
@bastelfreak bastelfreak added the bug Something isn't working label Nov 18, 2019
@bastelfreak bastelfreak merged commit 1840584 into voxpupuli:master Nov 18, 2019
Rovanion pushed a commit to Rovanion/puppet-prometheus that referenced this pull request May 5, 2021
Fix prometheus not restarting after config changes on systemd based systems
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prometheus daemon is not restarting when command-line arguments are changed
2 participants