17 changes: 15 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ 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.

## [v5.0.0](https://github.com/voxpupuli/puppet-prometheus/tree/v5.0.0) (2018-02-26)

[Full Changelog](https://github.com/voxpupuli/puppet-prometheus/compare/v4.1.1...v5.0.0)

**Breaking changes:**

- Feature/multiple rules files [\#166](https://github.com/voxpupuli/puppet-prometheus/pull/166) ([zipkid](https://github.com/zipkid))

**Merged pull requests:**

- Fix small typo in hiera example [\#164](https://github.com/voxpupuli/puppet-prometheus/pull/164) ([bearnard](https://github.com/bearnard))
- release 4.1.1 [\#163](https://github.com/voxpupuli/puppet-prometheus/pull/163) ([bastelfreak](https://github.com/bastelfreak))

## [v4.1.1](https://github.com/voxpupuli/puppet-prometheus/tree/v4.1.1) (2018-02-18)

[Full Changelog](https://github.com/voxpupuli/puppet-prometheus/compare/v4.1.0...v4.1.1)
Expand Down Expand Up @@ -122,6 +135,8 @@ These should not affect the functionality of the module.

- Running puppet restarts service [\#37](https://github.com/voxpupuli/puppet-prometheus/issues/37)
- manage systemd unit files with camptocamp/systemd [\#90](https://github.com/voxpupuli/puppet-prometheus/pull/90) ([bastelfreak](https://github.com/bastelfreak))
- add basic acceptance tests; fix wrong service handling in Ubuntu 14.04 [\#86](https://github.com/voxpupuli/puppet-prometheus/pull/86) ([bastelfreak](https://github.com/bastelfreak))
- Fix restart\_on\_change and add tests to Class\[prometheus\] [\#83](https://github.com/voxpupuli/puppet-prometheus/pull/83) ([sathieu](https://github.com/sathieu))
- add feature blackbox exporter [\#74](https://github.com/voxpupuli/puppet-prometheus/pull/74) ([bramblek1](https://github.com/bramblek1))
- Add nginx-vts-exporter [\#71](https://github.com/voxpupuli/puppet-prometheus/pull/71) ([viq](https://github.com/viq))
- Add pushgateway [\#68](https://github.com/voxpupuli/puppet-prometheus/pull/68) ([mdebruyn-trip](https://github.com/mdebruyn-trip))
Expand All @@ -135,8 +150,6 @@ These should not affect the functionality of the module.
- blackbox exporters source\_labels must be unquoted [\#98](https://github.com/voxpupuli/puppet-prometheus/pull/98) ([tuxmea](https://github.com/tuxmea))
- add service notification to systemd and sysv [\#95](https://github.com/voxpupuli/puppet-prometheus/pull/95) ([tuxmea](https://github.com/tuxmea))
- Fix isssue with node\_exporter containing empty pid on RHEL6. [\#88](https://github.com/voxpupuli/puppet-prometheus/pull/88) ([mkrakowitzer](https://github.com/mkrakowitzer))
- add basic acceptance tests; fix wrong service handling in Ubuntu 14.04 [\#86](https://github.com/voxpupuli/puppet-prometheus/pull/86) ([bastelfreak](https://github.com/bastelfreak))
- Fix restart\_on\_change and add tests to Class\[prometheus\] [\#83](https://github.com/voxpupuli/puppet-prometheus/pull/83) ([sathieu](https://github.com/sathieu))

**Closed issues:**

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class { '::prometheus::alertmanager':
the same in hiera

```puppet
rometheus::version: '2.0.0'
prometheus::version: '2.0.0'
prometheus::scrape_configs:
- job_name: 'nodexporter'
scrape_interval: '10s'
Expand Down
46 changes: 25 additions & 21 deletions manifests/alerts.pp
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
# Class: prometheus::alerts
# Define: prometheus::alerts
#
# This module manages prometheus alerts for prometheus
#
# [*location*]
# Where to create the alert file for prometheus
# This module manages prometheus alert files for prometheus
#
# [*alerts*]
# Array (< prometheus 2.0.0) or Hash (>= prometheus 2.0.0) of alerts (see README).
#
# [*alertfile_name*]
# Filename to use when storing the alerts file
# [*location*]
# Where to create the alert file for prometheus
#
class prometheus::alerts (
String $location,
define prometheus::alerts (
Variant[Array,Hash] $alerts,
String $alertfile_name = $prometheus::params::alertfile_name,
) inherits prometheus::params {
if ( versioncmp($::prometheus::version, '2.0.0') < 0 ){
file { "${location}/${alertfile_name}":
String $location = "${::prometheus::config_dir}/rules",
String $version = $::prometheus::version,
String $user = $::prometheus::user,
String $group = $::prometheus::group,
String $bin_dir = $::prometheus::bin_dir,
) {
if ( versioncmp($version, '2.0.0') < 0 ){
file { "${location}/${name}.rules":
ensure => 'file',
owner => $prometheus::user,
group => $prometheus::group,
owner => $user,
group => $group,
notify => Class['::prometheus::service_reload'],
content => epp("${module_name}/alerts.epp"),
validate_cmd => "${prometheus::bin_dir}/promtool check-rules %",
content => epp("${module_name}/alerts.epp", {'alerts' => $alerts}),
validate_cmd => "${bin_dir}/promtool check-rules %",
require => Class['::prometheus::install'],
before => Class['::prometheus::config'],
}
}
else {
file { "${location}/${alertfile_name}":
file { "${location}/${name}.rules":
ensure => 'file',
owner => $prometheus::user,
group => $prometheus::group,
owner => $user,
group => $group,
notify => Class['::prometheus::service_reload'],
content => $alerts.to_yaml,
validate_cmd => "${prometheus::bin_dir}/promtool check rules %",
validate_cmd => "${bin_dir}/promtool check rules %",
require => Class['::prometheus::install'],
before => Class['::prometheus::config'],
}
}
}
1 change: 0 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
group => $prometheus::group,
mode => $prometheus::config_mode,
notify => Class['::prometheus::service_reload'],
require => File["${prometheus::config_dir}/${prometheus::alertfile_name}"],
content => template($config_template),
validate_cmd => "${prometheus::bin_dir}/promtool ${cfg_verify_cmd} %",
}
Expand Down
41 changes: 34 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
# [*remote_write_configs*]
# Prometheus remote_write config to scrape prometheus 1.8+ instances
#
# [*alerts*]
# alert rules to put in alerts.rules
#
# [*extra_alerts*]
# Hash with extra alert rules to put in separate files.
#
# [*alert_relabel_config*]
# Prometheus alert relabel config under alerting
#
Expand Down Expand Up @@ -157,7 +163,8 @@
Array $scrape_configs = $::prometheus::params::scrape_configs,
Array $remote_read_configs = $::prometheus::params::remote_read_configs,
Array $remote_write_configs = $::prometheus::params::remote_write_configs,
$alerts = $::prometheus::params::alerts,
Variant[Array,Hash] $alerts = $::prometheus::params::alerts,
Hash $extra_alerts = {},
Array $alert_relabel_config = $::prometheus::params::alert_relabel_config,
Array $alertmanagers_config = $::prometheus::params::alertmanagers_config,
String $storage_retention = $::prometheus::params::storage_retention,
Expand All @@ -175,20 +182,40 @@
default => undef,
}


$config_hash_real = assert_type(Hash, deep_merge($config_defaults, $config_hash))

file { "${::prometheus::config_dir}/rules":
ensure => 'directory',
owner => $prometheus::user,
group => $prometheus::group,
mode => $prometheus::config_mode,
}

$extra_alerts.each | String $alerts_file_name, Hash $alerts_config | {
::prometheus::alerts { $alerts_file_name:
alerts => $alerts_config,
}
}
$extra_rule_files = suffix(prefix(keys($extra_alerts), "${config_dir}/rules/"), '.rules')

if ! empty($alerts) {
::prometheus::alerts { 'alert':
alerts => $alerts,
location => $config_dir,
}
$_rule_files = concat(["${config_dir}/alert.rules"], $extra_rule_files)
}
else {
$_rule_files = $extra_rule_files
}

anchor {'prometheus_first': }
-> class { '::prometheus::install':
purge_config_dir => $purge_config_dir,
}
-> class { '::prometheus::alerts':
location => $config_dir,
alerts => $alerts,
}
-> class { '::prometheus::config':
global_config => $global_config,
rule_files => $rule_files,
rule_files => $_rule_files,
scrape_configs => $scrape_configs,
remote_read_configs => $remote_read_configs,
remote_write_configs => $remote_write_configs,
Expand Down
4 changes: 2 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@
$beanstalkd_exporter_config = '/etc/beanstalkd-exporter.conf'
$package_ensure = 'latest'
$package_name = 'prometheus'
$alertfile_name = 'alert.rules'
$rule_files = [ "${config_dir}/${alertfile_name}" ]
$alertfile_name = 'alert'
$rule_files = [ "${config_dir}/${alertfile_name}.rules" ]
$scrape_configs = [ { 'job_name'=> 'prometheus', 'scrape_interval'=> '10s', 'scrape_timeout'=> '10s', 'static_configs'=> [ { 'targets'=> [ 'localhost:9090' ], 'labels'=> { 'alias'=> 'Prometheus'} } ] } ]
$remote_read_configs = []
$remote_write_configs = []
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": "4.1.1",
"version": "5.0.0",
"author": "Vox Pupuli",
"summary": "This module installs, configures and manages the Prometheus service.",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/prometheus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@

# prometheus::alerts
it {
is_expected.to contain_file('/etc/prometheus/alert.rules')
is_expected.not_to contain_file('/etc/prometheus/alert.rules')
}

# prometheus::run_service
Expand Down
80 changes: 80 additions & 0 deletions spec/defines/alerts_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require 'spec_helper'

describe 'prometheus::alerts' do
let :title do
'extra_alerts'
end

on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end

let :pre_condition do
'include ::prometheus'
end

[
{
alerts: [
{
'name' => 'alert_name',
'condition' => 'up == 0',
'timeduration' => '5min',
'labels' => [{ 'name' => 'severity', 'content' => 'woops' }],
'annotations' => [{ 'name' => 'summary', 'content' => 'did a woops {{ $labels.instance }}' }]
}
],
# location: '/etc/prometheus/rules',
# user: 'prometheus',
# group: 'prometheus',
# bin_dir: '/usr/local/bin',
},
{
version: '2.0.0-rc.1',
alerts: {
groups: [
{
name: 'alert.rules',
rules: [
{
'alert' => 'alert_name',
'expr' => 'up == 0',
'for' => '5min',
'labels' => { 'severity' => 'woops' },
'annotations' => {
'summary' => 'did a woops {{ $labels.instance }}'
}
}
]
}
]
},
# location: '/etc/prometheus/rules',
# user: 'prometheus',
# group: 'prometheus',
# bin_dir: '/usr/local/bin',
}
].each do |parameters|
context "with parameters #{parameters}" do
let(:params) do
parameters
end

prom_version = parameters[:version] || '1.5.2'
prom_major = prom_version[0]

it {
is_expected.to contain_file('/etc/prometheus/rules/extra_alerts.rules').with(
'ensure' => 'file',
'owner' => 'prometheus',
'group' => 'prometheus',
'content' => File.read(fixtures('files', "prometheus#{prom_major}.alert.rules"))
) # .that_notifies('Class[prometheus::service_reload]')
}
end
end
end
end
end
3 changes: 1 addition & 2 deletions spec/fixtures/files/prometheus1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ global:
evaluation_interval: 15s
external_labels:
monitor: master
rule_files:
- "/etc/prometheus/alert.rules"
rule_files: []
scrape_configs:
- job_name: prometheus
scrape_interval: 10s
Expand Down
3 changes: 1 addition & 2 deletions spec/fixtures/files/prometheus2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ global:
evaluation_interval: 15s
external_labels:
monitor: master
rule_files:
- "/etc/prometheus/alert.rules"
rule_files: []
scrape_configs:
- job_name: prometheus
scrape_interval: 10s
Expand Down
3 changes: 2 additions & 1 deletion templates/alerts.epp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<% $prometheus::alerts::alerts.each |$alert| { -%>
<%- | Array $alerts | -%>
<% $alerts.each |$alert| { -%>
ALERT <%= $alert['name'] %>
IF <%= $alert['condition'] %>
FOR <%= $alert['timeduration'] %>
Expand Down
2 changes: 1 addition & 1 deletion templates/prometheus.yaml.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% require 'yaml' -%>
<% global_config = scope.lookupvar('::prometheus::global_config') -%>
<% rule_files = scope.lookupvar('::prometheus::rule_files') -%>
<% rule_files = scope.lookupvar('::prometheus::_rule_files') -%>
<% scrape_configs = scope.lookupvar('::prometheus::scrape_configs') -%>
<% remote_read_configs = scope.lookupvar('::prometheus::remote_read_configs') -%>
<% remote_write_configs = scope.lookupvar('::prometheus::remote_write_configs') -%>
Expand Down