31 changes: 25 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,26 @@ All notable changes to this project will be documented in this file.
Each new release typically also includes the latest modulesync defaults.
These should not affect the functionality of the module.

## [v8.2.1](https://github.com/voxpupuli/puppet-prometheus/tree/v8.2.1) (2020-01-25)
## [v8.3.0](https://github.com/voxpupuli/puppet-prometheus/tree/v8.3.0) (2020-02-28)

[Full Changelog](https://github.com/voxpupuli/puppet-prometheus/compare/v8.2.1...v8.3.0)

**Implemented enhancements:**

- Add service\_name parameter to haproxy-exporter [\#428](https://github.com/voxpupuli/puppet-prometheus/pull/428) ([unki](https://github.com/unki))
- Add parameter max\_open\_files to server class [\#425](https://github.com/voxpupuli/puppet-prometheus/pull/425) ([kubicgruenfeld](https://github.com/kubicgruenfeld))
- Support reloading alertmanager rather than restarting [\#424](https://github.com/voxpupuli/puppet-prometheus/pull/424) ([treydock](https://github.com/treydock))

**Fixed bugs:**

- Fix duplicate command line options in SysV script [\#427](https://github.com/voxpupuli/puppet-prometheus/pull/427) ([lukebigum](https://github.com/lukebigum))
- Add config mode to config\_dir creation [\#397](https://github.com/voxpupuli/puppet-prometheus/pull/397) ([jpc2350](https://github.com/jpc2350))

**Merged pull requests:**

- if $purge\_config\_dir=true, force-manage config\_dir [\#426](https://github.com/voxpupuli/puppet-prometheus/pull/426) ([unki](https://github.com/unki))

## [v8.2.1](https://github.com/voxpupuli/puppet-prometheus/tree/v8.2.1) (2020-01-26)

[Full Changelog](https://github.com/voxpupuli/puppet-prometheus/compare/v8.2.0...v8.2.1)

Expand Down Expand Up @@ -548,7 +567,7 @@ These should not affect the functionality of the module.

## [v2.0.0](https://github.com/voxpupuli/puppet-prometheus/tree/v2.0.0) (2017-10-12)

[Full Changelog](https://github.com/voxpupuli/puppet-prometheus/compare/1.0.0...v2.0.0)
[Full Changelog](https://github.com/voxpupuli/puppet-prometheus/compare/v1.0.0...v2.0.0)

**Breaking changes:**

Expand Down Expand Up @@ -580,13 +599,13 @@ These should not affect the functionality of the module.
- Add param service\_name to node\_exporter class [\#40](https://github.com/voxpupuli/puppet-prometheus/pull/40) ([bastelfreak](https://github.com/bastelfreak))
- backport changes to upstream [\#39](https://github.com/voxpupuli/puppet-prometheus/pull/39) ([bastelfreak](https://github.com/bastelfreak))

## [1.0.0](https://github.com/voxpupuli/puppet-prometheus/tree/1.0.0) (2017-03-26)
## [v1.0.0](https://github.com/voxpupuli/puppet-prometheus/tree/v1.0.0) (2017-03-26)

[Full Changelog](https://github.com/voxpupuli/puppet-prometheus/compare/v1.0.0...1.0.0)
[Full Changelog](https://github.com/voxpupuli/puppet-prometheus/compare/1.0.0...v1.0.0)

## [v1.0.0](https://github.com/voxpupuli/puppet-prometheus/tree/v1.0.0) (2017-03-26)
## [1.0.0](https://github.com/voxpupuli/puppet-prometheus/tree/1.0.0) (2017-03-26)

[Full Changelog](https://github.com/voxpupuli/puppet-prometheus/compare/v0.2.4...v1.0.0)
[Full Changelog](https://github.com/voxpupuli/puppet-prometheus/compare/v0.2.4...1.0.0)

## [v0.2.4](https://github.com/voxpupuli/puppet-prometheus/tree/v0.2.4) (2017-03-13)

Expand Down
22 changes: 22 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,14 @@ Data type: `Stdlib::Absolutepath`



##### `reload_on_change`

Data type: `Boolean`



Default value: `false`

##### `manage_config`

Data type: `Boolean`
Expand Down Expand Up @@ -2888,6 +2896,12 @@ State ensured for the service (default 'running')

Default value: 'running'

##### `service_name`

Data type: `String[1]`

Name of the haproxy exporter service (default 'haproxy_exporter')

##### `user`

Data type: `String`
Expand Down Expand Up @@ -6171,6 +6185,14 @@ Data type: `Optional[Array[Hash[String[1], Any]]]`

Default value: $prometheus::collect_scrape_jobs

##### `max_open_files`

Data type: `Optional[Integer]`



Default value: $prometheus::max_open_files

##### `usershell`

Data type: `Stdlib::Absolutepath`
Expand Down
1 change: 1 addition & 0 deletions data/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ prometheus::haproxy_exporter::extra_groups: []
prometheus::haproxy_exporter::group: 'haproxy-exporter'
prometheus::haproxy_exporter::package_ensure: 'latest'
prometheus::haproxy_exporter::package_name: 'haproxy_exporter'
prometheus::haproxy_exporter::service_name: 'haproxy_exporter'
prometheus::haproxy_exporter::user: 'haproxy-user'
prometheus::haproxy_exporter::version: '0.10.0'
prometheus::nginx_vts_exporter::nginx_scrape_uri: 'http://localhost/status/format/json'
Expand Down
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
2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

assert_private()

$max_open_files = $prometheus::max_open_files
$max_open_files = $prometheus::server::max_open_files

$prometheus_v2 = versioncmp($prometheus::server::version, '2.0.0') >= 0

Expand Down
9 changes: 6 additions & 3 deletions manifests/haproxy_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@
# Whether to enable the service from puppet (default true)
# @param service_ensure
# State ensured for the service (default 'running')
# @param service_name
# Name of the haproxy exporter service (default 'haproxy_exporter')
# @param user
# User which runs the service
# @param version
# The binary release version
class prometheus::haproxy_exporter(
class prometheus::haproxy_exporter (
Variant[Stdlib::HTTPUrl, Pattern[/unix:(?:\/.+)+/]] $cnf_scrape_uri,
String $download_extension,
Array $extra_groups,
String $group,
String $package_ensure,
String $package_name,
String[1] $service_name,
String $user,
String $version,
Prometheus::Uri $download_url_base,
Expand All @@ -77,13 +80,13 @@

$real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")
$notify_service = $restart_on_change ? {
true => Service['haproxy_exporter'],
true => Service[$service_name],
default => undef,
}

$options = "--haproxy.scrape-uri=\"${cnf_scrape_uri}\" ${extra_options}"

prometheus::daemon { 'haproxy_exporter':
prometheus::daemon { $service_name:
install_method => $install_method,
version => $version,
download_extension => $download_extension,
Expand Down
2 changes: 2 additions & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@
ensure => 'directory',
owner => 'root',
group => $prometheus::server::group,
mode => $prometheus::server::config_mode,
purge => $prometheus::server::purge_config_dir,
recurse => $prometheus::server::purge_config_dir,
force => $prometheus::server::purge_config_dir,
}
}
1 change: 1 addition & 0 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
Boolean $manage_config = $prometheus::manage_config,
Optional[Variant[Stdlib::HTTPurl, Stdlib::Unixpath, String[1]]] $external_url = $prometheus::external_url,
Optional[Array[Hash[String[1], Any]]] $collect_scrape_jobs = $prometheus::collect_scrape_jobs,
Optional[Integer] $max_open_files = $prometheus::max_open_files,
Stdlib::Absolutepath $usershell = $prometheus::usershell,
) inherits prometheus {

Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppet-prometheus",
"version": "8.2.1",
"version": "8.3.0",
"author": "Vox Pupuli",
"summary": "This module installs, configures and manages the Prometheus service.",
"license": "Apache-2.0",
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
3 changes: 2 additions & 1 deletion spec/classes/prometheus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
'owner' => 'root',
'group' => 'prometheus',
'purge' => true,
'recurse' => true
'recurse' => true,
'force' => true
)
}

Expand Down
51 changes: 51 additions & 0 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'spec_helper'

describe 'prometheus::server' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge(os_specific_facts(facts))
end

[{ version: '2.0.0-rc.1', bin_dir: '/usr/local/bin', install_method: 'url' }].each do |parameters|
context "with parameters #{parameters}" do
let(:params) do
parameters
end

if ['centos-7-x86_64', 'centos-8-x86_64', 'debian-8-x86_64', 'debian-9-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'ubuntu-16.04-x86_64', 'ubuntu-18.04-x86_64'].include?(os)
prom_version = parameters[:version] || '1.5.2'
prom_major = prom_version[0]
it {
is_expected.to contain_class('systemd')
}

it {
is_expected.to contain_systemd__unit_file('prometheus.service').with(
'content' => File.read(fixtures('files', "prometheus#{prom_major}.systemd"))
)
}
describe 'max_open_files' do
context 'by default' do
it {
content = catalogue.resource('systemd::unit_file', 'prometheus.service').send(:parameters)[:content]
expect(content).not_to include('LimitNOFILE')
}
end
context 'when set to 1000000' do
let(:params) do
parameters.merge('max_open_files' => 1_000_000)
end

it {
content = catalogue.resource('systemd::unit_file', 'prometheus.service').send(:parameters)[:content]
expect(content).to include('LimitNOFILE=1000000')
}
end
end
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion templates/prometheus.sysv.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ start() {
daemon --user=<%= scope.lookupvar('prometheus::server::user') %> \
--pidfile="$PID_FILE" \
"$DAEMON" <%= @daemon_flags.join(" \\\n ") %> \
<%= scope.lookupvar('prometheus::server::extra_options') %> >> "$LOG_FILE" &
>> "$LOG_FILE" &
retcode=$?
mkpidfile
touch /var/lock/subsys/prometheus
Expand Down