From 35bc1cefeef5e69362246117bdff659a9fe188ae Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sat, 19 May 2018 12:12:41 +0200 Subject: [PATCH 1/4] install prometheus server via own class --- data/defaults.yaml | 1 + manifests/config.pp | 32 +++++----- manifests/init.pp | 57 +---------------- manifests/install.pp | 81 ++++++++++++------------ manifests/run_service.pp | 8 +-- manifests/server.pp | 98 ++++++++++++++++++++++++++++++ manifests/service_reload.pp | 4 +- spec/acceptance/prometheus_spec.rb | 50 +++++++++++---- templates/prometheus.yaml.erb | 14 ++--- 9 files changed, 210 insertions(+), 135 deletions(-) create mode 100644 manifests/server.pp diff --git a/data/defaults.yaml b/data/defaults.yaml index 45f0d5364..657217fd6 100644 --- a/data/defaults.yaml +++ b/data/defaults.yaml @@ -2,6 +2,7 @@ prometheus::bin_dir: '/usr/local/bin' prometheus::version: '1.5.2' prometheus::install_method: 'url' +prometheus::manage_prometheus_server: false prometheus::alert_relabel_config: [] prometheus::alertmanagers_config: [] prometheus::alertmanager::config_dir: '/etc/alertmanager' diff --git a/manifests/config.pp b/manifests/config.pp index 2d1d61d49..1ac1ff7a6 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -6,8 +6,8 @@ Array $scrape_configs, Array $remote_read_configs, Array $remote_write_configs, - String $config_template = $prometheus::config_template, - String $storage_retention = $prometheus::storage_retention, + String $config_template = $prometheus::server::config_template, + String $storage_retention = $prometheus::server::storage_retention, ) { if $prometheus::init_style { @@ -21,8 +21,8 @@ fail('remote_write_configs requires prometheus 2.X') } $daemon_flags = [ - "-config.file=${prometheus::config_dir}/prometheus.yaml", - "-storage.local.path=${prometheus::localstorage}", + "-config.file=${prometheus::server::config_dir}/prometheus.yaml", + "-storage.local.path=${prometheus::server::localstorage}", "-storage.local.retention=${storage_retention}", "-web.console.templates=${prometheus::shared_dir}/consoles", "-web.console.libraries=${prometheus::shared_dir}/console_libraries", @@ -31,11 +31,11 @@ # helper variable indicating prometheus version, so we can use on this information in the template $prometheus_v2 = true $daemon_flags = [ - "--config.file=${prometheus::config_dir}/prometheus.yaml", - "--storage.tsdb.path=${prometheus::localstorage}", + "--config.file=${prometheus::server::config_dir}/prometheus.yaml", + "--storage.tsdb.path=${prometheus::server::localstorage}", "--storage.tsdb.retention=${storage_retention}", - "--web.console.templates=${prometheus::shared_dir}/consoles", - "--web.console.libraries=${prometheus::shared_dir}/console_libraries", + "--web.console.templates=${prometheus::server::shared_dir}/consoles", + "--web.console.libraries=${prometheus::server::shared_dir}/console_libraries", ] } @@ -50,7 +50,7 @@ $systemd_notify = Exec['prometheus-systemd-reload'] } - case $prometheus::init_style { + case $prometheus::server::init_style { 'upstart' : { file { '/etc/init/prometheus.conf': mode => '0444', @@ -105,12 +105,12 @@ } } default : { - fail("I don't know how to create an init script for style ${prometheus::init_style}") + fail("I don't know how to create an init script for style ${prometheus::server::init_style}") } } } - if versioncmp($prometheus::version, '2.0.0') >= 0 { + if versioncmp($prometheus::server::version, '2.0.0') >= 0 { $cfg_verify_cmd = 'check config' } else { $cfg_verify_cmd = 'check-config' @@ -118,13 +118,13 @@ file { 'prometheus.yaml': ensure => present, - path => "${prometheus::config_dir}/prometheus.yaml", - owner => $prometheus::user, - group => $prometheus::group, - mode => $prometheus::config_mode, + path => "${prometheus::server::config_dir}/prometheus.yaml", + owner => $prometheus::server::user, + group => $prometheus::server::group, + mode => $prometheus::server::config_mode, notify => Class['prometheus::service_reload'], content => template($config_template), - validate_cmd => "${prometheus::bin_dir}/promtool ${cfg_verify_cmd} %", + validate_cmd => "${prometheus::server::bin_dir}/promtool ${cfg_verify_cmd} %", } } diff --git a/manifests/init.pp b/manifests/init.pp index aebaa43ed..dfcb4b9d7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -154,6 +154,7 @@ Array $alertmanagers_config, String $storage_retention, Stdlib::Absolutepath $env_file_path, + Boolean $manage_prometheus_server, Hash $extra_alerts = {}, Boolean $service_enable = true, String $service_ensure = 'running', @@ -179,59 +180,7 @@ } } - if( versioncmp($prometheus::version, '1.0.0') == -1 ){ - $real_download_url = pick($download_url, - "${download_url_base}/download/${version}/${package_name}-${version}.${os}-${real_arch}.${download_extension}") - } else { - $real_download_url = pick($download_url, - "${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${real_arch}.${download_extension}") + if $manage_prometheus_server { + include prometheus::server } - $notify_service = $restart_on_change ? { - true => Service['prometheus'], - 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::config': - global_config => $global_config, - rule_files => $_rule_files, - scrape_configs => $scrape_configs, - remote_read_configs => $remote_read_configs, - remote_write_configs => $remote_write_configs, - config_template => $config_template, - storage_retention => $storage_retention, - } - -> class { 'prometheus::run_service': } - -> class { 'prometheus::service_reload': } - -> anchor {'prometheus_last': } } diff --git a/manifests/install.pp b/manifests/install.pp index 6b73d9730..88d136c69 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,4 +1,4 @@ -# Class prometheus::install +# Class prometheus::server::install # Install prometheus via different methods with parameters from init # Currently only the install from url is implemented, when Prometheus will deliver packages for some Linux distros I will # implement the package install method as well @@ -6,86 +6,89 @@ class prometheus::install ( Boolean $purge_config_dir = true, ) { - if $prometheus::localstorage { - file { $prometheus::localstorage: + + assert_private() + + if $prometheus::server::localstorage { + file { $prometheus::server::localstorage: ensure => 'directory', - owner => $prometheus::user, - group => $prometheus::group, + owner => $prometheus::server::user, + group => $prometheus::server::group, mode => '0755', } } - case $prometheus::install_method { + case $prometheus::server::install_method { 'url': { - archive { "/tmp/prometheus-${prometheus::version}.${prometheus::download_extension}": + archive { "/tmp/prometheus-${prometheus::server::version}.${prometheus::server::download_extension}": ensure => present, extract => true, extract_path => '/opt', - source => $prometheus::real_download_url, + source => $prometheus::server::real_download_url, checksum_verify => false, - creates => "/opt/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::real_arch}/prometheus", + creates => "/opt/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/prometheus", cleanup => true, } -> file { - "/opt/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::real_arch}/prometheus": + "/opt/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/prometheus": owner => 'root', group => 0, # 0 instead of root because OS X uses "wheel". mode => '0555'; - "${prometheus::bin_dir}/prometheus": + "${prometheus::server::bin_dir}/prometheus": ensure => link, - notify => $prometheus::notify_service, - target => "/opt/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::real_arch}/prometheus"; - "${prometheus::bin_dir}/promtool": + notify => $prometheus::server::notify_service, + target => "/opt/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/prometheus"; + "${prometheus::server::bin_dir}/promtool": ensure => link, - target => "/opt/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::real_arch}/promtool"; - $prometheus::shared_dir: + target => "/opt/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/promtool"; + $prometheus::server::shared_dir: ensure => directory, - owner => $prometheus::user, - group => $prometheus::group, + owner => $prometheus::server::user, + group => $prometheus::server::group, mode => '0755'; - "${prometheus::shared_dir}/consoles": + "${prometheus::server::shared_dir}/consoles": ensure => link, - notify => $prometheus::notify_service, - target => "/opt/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::real_arch}/consoles"; - "${prometheus::shared_dir}/console_libraries": + notify => $prometheus::server::notify_service, + target => "/opt/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/consoles"; + "${prometheus::server::shared_dir}/console_libraries": ensure => link, - notify => $prometheus::notify_service, - target => "/opt/prometheus-${prometheus::version}.${prometheus::os}-${prometheus::real_arch}/console_libraries"; + notify => $prometheus::server::notify_service, + target => "/opt/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/console_libraries"; } } 'package': { - package { $prometheus::package_name: - ensure => $prometheus::package_ensure, + package { $prometheus::server::package_name: + ensure => $prometheus::server::package_ensure, } - if $prometheus::manage_user { - User[$prometheus::user] -> Package[$prometheus::package_name] + if $prometheus::server::manage_user { + User[$prometheus::server::user] -> Package[$prometheus::server::package_name] } } 'none': {} default: { - fail("The provided install method ${prometheus::install_method} is invalid") + fail("The provided install method ${prometheus::server::install_method} is invalid") } } - if $prometheus::manage_user { - ensure_resource('user', [ $prometheus::user ], { + if $prometheus::server::manage_user { + ensure_resource('user', [ $prometheus::server::user ], { ensure => 'present', system => true, - groups => $prometheus::extra_groups, + groups => $prometheus::server::extra_groups, }) - if $prometheus::manage_group { - Group[$prometheus::group] -> User[$prometheus::user] + if $prometheus::server::manage_group { + Group[$prometheus::server::group] -> User[$prometheus::server::user] } } - if $prometheus::manage_group { - ensure_resource('group', [ $prometheus::group ],{ + if $prometheus::server::manage_group { + ensure_resource('group', [ $prometheus::server::group ],{ ensure => 'present', system => true, }) } - file { $prometheus::config_dir: + file { $prometheus::server::config_dir: ensure => 'directory', - owner => $prometheus::user, - group => $prometheus::group, + owner => $prometheus::server::user, + group => $prometheus::server::group, purge => $purge_config_dir, recurse => $purge_config_dir, } diff --git a/manifests/run_service.pp b/manifests/run_service.pp index d20845bda..65b19b9e0 100644 --- a/manifests/run_service.pp +++ b/manifests/run_service.pp @@ -5,16 +5,16 @@ # class prometheus::run_service { - $init_selector = $prometheus::init_style ? { + $init_selector = $prometheus::server::init_style ? { 'launchd' => 'io.prometheus.daemon', default => 'prometheus', } - if $prometheus::manage_service == true { + if $prometheus::server::manage_service == true { service { 'prometheus': - ensure => $prometheus::service_ensure, + ensure => $prometheus::server::service_ensure, name => $init_selector, - enable => $prometheus::service_enable, + enable => $prometheus::server::service_enable, hasrestart => true, } } diff --git a/manifests/server.pp b/manifests/server.pp new file mode 100644 index 000000000..e3198315f --- /dev/null +++ b/manifests/server.pp @@ -0,0 +1,98 @@ +# class to manage the actual prometheus server +# this is a private class that gets called from the init.pp +class prometheus::server ( + String $user = $prometheus::user, + String $group = $prometheus::group, + Array $extra_groups = $prometheus::extra_groups, + Stdlib::Absolutepath $bin_dir = $prometheus::bin_dir, + Stdlib::Absolutepath $shared_dir = $prometheus::shared_dir, + String $version = $prometheus::version, + String $install_method = $prometheus::install_method, + Variant[Stdlib::HTTPUrl, Stdlib::HTTPSUrl] $download_url_base = $prometheus::download_url_base, + String $download_extension = $prometheus::download_extension, + String $package_name = $prometheus::package_name, + String $package_ensure = $prometheus::package_ensure, + String $config_dir = $prometheus::config_dir, + Stdlib::Absolutepath $localstorage = $prometheus::localstorage, + String $config_template = $prometheus::config_template, + String $config_mode = $prometheus::config_mode, + Hash $global_config = $prometheus::global_config, + Array $rule_files = $prometheus::rule_files, + Array $scrape_configs = $prometheus::scrape_configs, + Array $remote_read_configs = $prometheus::remote_read_configs, + Array $remote_write_configs = $prometheus::remote_write_configs, + Variant[Array,Hash] $alerts = $prometheus::alerts, + Array $alert_relabel_config = $prometheus::alert_relabel_config, + Array $alertmanagers_config = $prometheus::alertmanagers_config, + String $storage_retention = $prometheus::storage_retention, + Stdlib::Absolutepath $env_file_path = $prometheus::env_file_path, + Hash $extra_alerts = $prometheus::extra_alerts, + Boolean $service_enable = $prometheus::service_enable, + String $service_ensure = $prometheus::service_ensure, + Boolean $manage_service = $prometheus::manage_service, + Boolean $restart_on_change = $prometheus::restart_on_change, + String $init_style = $prometheus::init_style, + String $extra_options = $prometheus::extra_options, + Hash $config_hash = $prometheus::config_hash, + Hash $config_defaults = $prometheus::config_defaults, + String $os = $prometheus::os, + Optional[String] $download_url = $prometheus::download_url, + String $arch = $prometheus::real_arch, + Boolean $manage_group = $prometheus::manage_group, + Boolean $purge_config_dir = $prometheus::purge_config_dir, + Boolean $manage_user = $prometheus::manage_user, +) inherits prometheus { + + if( versioncmp($version, '1.0.0') == -1 ){ + $real_download_url = pick($download_url, + "${download_url_base}/download/${version}/${package_name}-${version}.${os}-${arch}.${download_extension}") + } else { + $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['prometheus'], + default => undef, + } + + $config_hash_real = assert_type(Hash, deep_merge($config_defaults, $config_hash)) + + file { "${config_dir}/rules": + ensure => 'directory', + owner => $user, + group => $group, + mode => $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 + } + class { 'prometheus::install': + purge_config_dir => $prometheus::purge_config_dir, + } + -> class { 'prometheus::config': + global_config => $global_config, + rule_files => $_rule_files, + scrape_configs => $scrape_configs, + remote_read_configs => $remote_read_configs, + remote_write_configs => $remote_write_configs, + config_template => $config_template, + storage_retention => $storage_retention, + } + -> class { 'prometheus::run_service': } + -> class { 'prometheus::service_reload': } +} diff --git a/manifests/service_reload.pp b/manifests/service_reload.pp index 37ac6c0cb..b42078428 100644 --- a/manifests/service_reload.pp +++ b/manifests/service_reload.pp @@ -3,10 +3,10 @@ # changes class prometheus::service_reload() { - if $prometheus::manage_service == true { + if $prometheus::server::manage_service == true { $init_selector = $prometheus::run_service::init_selector - $prometheus_reload = $prometheus::init_style ? { + $prometheus_reload = $prometheus::server::init_style ? { 'systemd' => "systemctl reload-or-restart ${init_selector}", 'upstart' => "service ${init_selector} reload", 'sysv' => "/etc/init.d/${init_selector} reload", diff --git a/spec/acceptance/prometheus_spec.rb b/spec/acceptance/prometheus_spec.rb index ea7e2a66c..874f0fc44 100644 --- a/spec/acceptance/prometheus_spec.rb +++ b/spec/acceptance/prometheus_spec.rb @@ -1,37 +1,61 @@ require 'spec_helper_acceptance' -describe 'prometheus' do - it 'works idempotently with no errors' do - pp = 'include prometheus' - +describe 'prometheus exporter' do + it 'graphite_exporter works idempotently with no errors' do + pp = 'include prometheus::graphite_exporter' # Run it twice and test for idempotency apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end - describe service('prometheus') do + describe service('graphite_exporter') do it { is_expected.to be_running } it { is_expected.to be_enabled } end + # the class installs an exporter that listens on three ports + # it should not install the prometheus server (port 9090) + describe port(9108) do + it { is_expected.to be_listening.with('tcp6') } + end + describe port(9109) do + it { is_expected.to be_listening.with('tcp6') } + end + describe port(9109) do + it { is_expected.to be_listening.with('udp6') } + end + describe port(9090) do + it { is_expected.not_to be_listening.with('tcp6') } + end +end +describe 'prometheus server' do + it 'prometheus server via main class works idempotently with no errors' do + pp = "class{'prometheus': manage_prometheus_server => true }" - it 'graphite_exporter works idempotently with no errors' do - pp = 'include prometheus::graphite_exporter' # Run it twice and test for idempotency apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end - describe service('graphite_exporter') do + describe service('prometheus') do it { is_expected.to be_running } it { is_expected.to be_enabled } end - describe port(9108) do + describe port(9090) do it { is_expected.to be_listening.with('tcp6') } end - describe port(9109) do - it { is_expected.to be_listening.with('tcp6') } + it 'prometheus server via server class works idempotently with no errors' do + pp = 'include prometheus::server' + + # Run it twice and test for idempotency + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end - describe port(9109) do - it { is_expected.to be_listening.with('udp6') } + + describe service('prometheus') do + it { is_expected.to be_running } + it { is_expected.to be_enabled } + end + describe port(9090) do + it { is_expected.to be_listening.with('tcp6') } end end diff --git a/templates/prometheus.yaml.erb b/templates/prometheus.yaml.erb index f599f5f28..b59941aa7 100644 --- a/templates/prometheus.yaml.erb +++ b/templates/prometheus.yaml.erb @@ -1,16 +1,16 @@ <% require 'yaml' -%> -<% global_config = scope.lookupvar('::prometheus::global_config') -%> -<% 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') -%> +<% global_config = scope.lookupvar('::prometheus::server::global_config') -%> +<% rule_files = scope.lookupvar('::prometheus::server::_rule_files') -%> +<% scrape_configs = scope.lookupvar('::prometheus::server::scrape_configs') -%> +<% remote_read_configs = scope.lookupvar('::prometheus::server::remote_read_configs') -%> +<% remote_write_configs = scope.lookupvar('::prometheus::server::remote_write_configs') -%> <% full_config = { 'global'=>global_config, 'rule_files'=>rule_files, 'scrape_configs'=>scrape_configs, 'alerting'=>{ - 'alert_relabel_configs'=>scope.lookupvar('::prometheus::alert_relabel_config'), - 'alertmanagers'=>scope.lookupvar('::prometheus::alertmanagers_config'), + 'alert_relabel_configs'=>scope.lookupvar('::prometheus::server::alert_relabel_config'), + 'alertmanagers'=>scope.lookupvar('::prometheus::server::alertmanagers_config'), }, } if @prometheus_v2 From df1f628b6a1d91b9bd189b84f87fd75971420af3 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sat, 19 May 2018 13:04:55 +0200 Subject: [PATCH 2/4] restructure acceptance tests --- spec/acceptance/prometheus_exporter_spec.rb | 29 +++++++++++++++++++ ...heus_spec.rb => prometheus_server_spec.rb} | 27 ----------------- 2 files changed, 29 insertions(+), 27 deletions(-) create mode 100644 spec/acceptance/prometheus_exporter_spec.rb rename spec/acceptance/{prometheus_spec.rb => prometheus_server_spec.rb} (53%) diff --git a/spec/acceptance/prometheus_exporter_spec.rb b/spec/acceptance/prometheus_exporter_spec.rb new file mode 100644 index 000000000..ba291693b --- /dev/null +++ b/spec/acceptance/prometheus_exporter_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper_acceptance' + +describe 'prometheus exporter' do + it 'graphite_exporter works idempotently with no errors' do + pp = 'include prometheus::graphite_exporter' + # Run it twice and test for idempotency + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + end + + describe service('graphite_exporter') do + it { is_expected.to be_running } + it { is_expected.to be_enabled } + end + # the class installs an exporter that listens on three ports + # it should not install the prometheus server (port 9090) + describe port(9108) do + it { is_expected.to be_listening.with('tcp6') } + end + describe port(9109) do + it { is_expected.to be_listening.with('tcp6') } + end + describe port(9109) do + it { is_expected.to be_listening.with('udp6') } + end + describe port(9090) do + it { is_expected.not_to be_listening.with('tcp6') } + end +end diff --git a/spec/acceptance/prometheus_spec.rb b/spec/acceptance/prometheus_server_spec.rb similarity index 53% rename from spec/acceptance/prometheus_spec.rb rename to spec/acceptance/prometheus_server_spec.rb index 874f0fc44..f8ef6821a 100644 --- a/spec/acceptance/prometheus_spec.rb +++ b/spec/acceptance/prometheus_server_spec.rb @@ -1,32 +1,5 @@ require 'spec_helper_acceptance' -describe 'prometheus exporter' do - it 'graphite_exporter works idempotently with no errors' do - pp = 'include prometheus::graphite_exporter' - # Run it twice and test for idempotency - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) - end - - describe service('graphite_exporter') do - it { is_expected.to be_running } - it { is_expected.to be_enabled } - end - # the class installs an exporter that listens on three ports - # it should not install the prometheus server (port 9090) - describe port(9108) do - it { is_expected.to be_listening.with('tcp6') } - end - describe port(9109) do - it { is_expected.to be_listening.with('tcp6') } - end - describe port(9109) do - it { is_expected.to be_listening.with('udp6') } - end - describe port(9090) do - it { is_expected.not_to be_listening.with('tcp6') } - end -end describe 'prometheus server' do it 'prometheus server via main class works idempotently with no errors' do pp = "class{'prometheus': manage_prometheus_server => true }" From 7ed5ce0824241585d8415df19f0609a567963087 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sat, 19 May 2018 13:17:22 +0200 Subject: [PATCH 3/4] adjust spec tests to new class layout --- spec/classes/prometheus_spec.rb | 5 ++++- spec/defines/alerts_spec.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/classes/prometheus_spec.rb b/spec/classes/prometheus_spec.rb index 5f5788ead..87e3642e3 100644 --- a/spec/classes/prometheus_spec.rb +++ b/spec/classes/prometheus_spec.rb @@ -7,7 +7,7 @@ facts.merge(os_specific_facts(facts)) end - [{ version: '2.0.0-rc.1', bin_dir: '/usr/local/bin', install_method: 'url' }].each do |parameters| + [{ manage_prometheus_server: true, 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 @@ -203,6 +203,7 @@ context 'with alerts configured', alerts: true do [ { + manage_prometheus_server: true, version: '1.5.3', alerts: [{ 'name' => 'alert_name', @@ -213,6 +214,7 @@ }] }, { + manage_prometheus_server: true, version: '2.0.0-rc.1', alerts: { 'groups' => [{ @@ -258,6 +260,7 @@ context 'with remote write configured' do [ { + manage_prometheus_server: true, version: '2.0.0-rc.1', remote_write_configs: [ 'url' => 'http://domain.tld/path' diff --git a/spec/defines/alerts_spec.rb b/spec/defines/alerts_spec.rb index a578f964e..c3093a66a 100644 --- a/spec/defines/alerts_spec.rb +++ b/spec/defines/alerts_spec.rb @@ -12,7 +12,7 @@ end let :pre_condition do - 'include ::prometheus' + 'include prometheus::server' end [ From 0bef436c3b4fc17a73f75f73f90f0150dc592c05 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sat, 19 May 2018 13:32:03 +0200 Subject: [PATCH 4/4] update README.md with infos about breaking changes --- README.md | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 19dd8336e..31fc81155 100644 --- a/README.md +++ b/README.md @@ -45,11 +45,20 @@ This module automates the install and configuration of Prometheus monitoring too ## Usage +**Notice about breaking changes** + +Version 5.0.0 and older of this module allowed you to deploy the prometheus server by doing a simple `include prometheus`. +We introduced a [new class layout](https://github.com/voxpupuli/puppet-prometheus/pull/194) in +version 6. By default, including the `prometheus` class won't deploy the server now. +You need to include the `prometheus::server` class for this (which has the same +parameters as `prometheus` had). An alterntive approach is to set the +`manage_prometheus_server` parameter to true in the `prometheus` class. Backgroud information about this change are available in the related [pull request](https://github.com/voxpupuli/puppet-prometheus/pull/187) and the [issue](https://github.com/voxpupuli/puppet-prometheus/issues/184) + To set up a prometheus daemon: On the server (for prometheus version < 1.0.0): ```puppet -class { '::prometheus': +class { 'prometheus::server': global_config => { 'scrape_interval'=> '15s', 'evaluation_interval'=> '15s', 'external_labels'=> { 'monitor'=>'master'}}, rule_files => [ "/etc/prometheus/alert.rules" ], scrape_configs => [ @@ -69,7 +78,7 @@ class { '::prometheus': On the server (for prometheus version >= 1.0.0): ```puppet -class { 'prometheus': +class { 'prometheus::server': version => '1.0.0', scrape_configs => [ {'job_name'=>'prometheus','scrape_interval'=> '30s','scrape_timeout'=>'30s','static_configs'=> [{'targets'=>['localhost:9090'], 'labels'=> { 'alias'=>'Prometheus'}}]}], extra_options => '-alertmanager.url http://localhost:9093 -web.console.templates=/opt/prometheus-1.0.0.linux-amd64/consoles -web.console.libraries=/opt/prometheus-1.0.0.linux-amd64/console_libraries', @@ -79,7 +88,7 @@ class { 'prometheus': On the server (for prometheus version >= 2.0.0): ```puppet -class { '::prometheus': +class { 'prometheus::server': version => '2.0.0', alerts => { 'groups' => [{ 'name' => 'alert.rules', 'rules' => [{ 'alert' => 'InstanceDown', 'expr' => 'up == 0', 'for' => '5m', 'labels' => { 'severity' => 'page', }, 'annotations' => { 'summary' => 'Instance {{ $labels.instance }} down', 'description' => '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes.' }}]}]}, scrape_configs => [ @@ -98,7 +107,7 @@ class { '::prometheus': or simply: ```puppet -include ::prometheus +include prometheus::server ``` To add alert rules, add the following to the class prometheus in case you are using prometheus < 2.0: @@ -173,7 +182,8 @@ Real Prometheus >=2.0.0 setup example including alertmanager and slack_configs. ```puppet include profiles::prometheus -class { '::prometheus': +class { 'prometheus': + manage_prometheus_server => true, version => '2.0.0', alerts => { 'groups' => [{ 'name' => 'alert.rules', 'rules' => [{ 'alert' => 'InstanceDown', 'expr' => 'up == 0', 'for' => '5m', 'labels' => { 'severity' => 'page', }, 'annotations' => { 'summary' => 'Instance {{ $labels.instance }} down', 'description' => '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes.' } }]}]}, scrape_configs => [ @@ -198,7 +208,7 @@ class { '::prometheus': ], alertmanagers_config => [{ 'static_configs' => [{'targets' => [ 'localhost:9093' ]}]}], } -class { '::prometheus::alertmanager': +class { 'prometheus::alertmanager': version => '0.13.0', route => { 'group_by' => [ 'alertname', 'cluster', 'service' ], 'group_wait'=> '30s', 'group_interval'=> '5m', 'repeat_interval'=> '3h', 'receiver'=> 'slack' }, receivers => [ { 'name' => 'slack', 'slack_configs'=> [ { 'api_url'=> 'https://hooks.slack.com/services/ABCDEFG123456', 'channel' => '#channel', 'send_resolved' => true, 'username' => 'username'}] }] @@ -207,7 +217,8 @@ class { '::prometheus::alertmanager': the same in hiera -```puppet +```yaml +prometheus::manage_prometheus_server: true prometheus::version: '2.0.0' prometheus::scrape_configs: - job_name: 'nodexporter'