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

Support reloading alertmanager rather than restarting #424

Merged
merged 1 commit into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions manifests/alertmanager.pp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
Stdlib::Ensure::Service $service_ensure = 'running',
String[1] $service_name = 'alertmanager',
Boolean $restart_on_change = true,
Boolean $reload_on_change = false,
Boolean $purge_config_dir = true,
Boolean $manage_config = true,
Prometheus::Initstyle $init_style = $facts['service_provider'],
Expand Down Expand Up @@ -138,6 +139,25 @@
default => undef,
}

$alertmanager_reload = $prometheus::init_style ? {
'systemd' => "systemctl reload-or-restart ${service_name}",
/^(upstart|none)$/ => "service ${service_name} reload",
/^(sysv|redhat|sles|debian)$/ => "/etc/init.d/${service_name} reload",
'launchd' => "launchctl stop ${service_name} && launchctl start ${service_name}",
}

exec { 'alertmanager-reload':
command => $alertmanager_reload,
path => [ '/usr/bin', '/bin', '/usr/sbin', '/sbin' ],
refreshonly => true,
}

if $reload_on_change {
$_notify_service = Exec['alertmanager-reload']
} else {
$_notify_service = $notify_service
}

file { $config_dir:
ensure => 'directory',
owner => 'root',
Expand All @@ -160,7 +180,7 @@
group => $group,
mode => $config_mode,
content => template('prometheus/alertmanager.yaml.erb'),
notify => $notify_service,
notify => $_notify_service,
require => File["${bin_dir}/amtool", $config_dir],
validate_cmd => "${bin_dir}/amtool check-config --alertmanager.url='' %",
}
Expand All @@ -174,7 +194,7 @@
group => $group,
mode => $config_mode,
content => template('prometheus/alertmanager.yaml.erb'),
notify => $notify_service,
notify => $_notify_service,
require => File[$config_dir],
}
}
Expand Down
19 changes: 18 additions & 1 deletion spec/classes/alertmanager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,27 @@
end
describe 'config file contents' do
it {
is_expected.to contain_file('/etc/alertmanager/alertmanager.yaml')
is_expected.to contain_file('/etc/alertmanager/alertmanager.yaml').with_notify('Service[alertmanager]')
verify_contents(catalogue, '/etc/alertmanager/alertmanager.yaml', ['---', 'global:', ' smtp_smarthost: localhost:25', ' smtp_from: alertmanager@localhost'])
}
end
describe 'service reload' do
it {
is_expected.to contain_exec('alertmanager-reload').with(
# 'command' => 'systemctl reload alertmanager',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin'],
'refreshonly' => true
)
}
end
end

context 'when reload_on_change => true' do
let(:params) { { reload_on_change: true } }

it {
is_expected.to contain_file('/etc/alertmanager/alertmanager.yaml').with_notify('Exec[alertmanager-reload]')
}
end

context 'with manage_config => false' do
Expand Down