From 48481159a8589edb4f6d92a56d8a12eab1f1eafb Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Wed, 1 Aug 2018 00:21:10 +0200 Subject: [PATCH 1/2] enhance acceptance tests --- spec/acceptance/prometheus_server_spec.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/acceptance/prometheus_server_spec.rb b/spec/acceptance/prometheus_server_spec.rb index f8ef6821a..98b49d384 100644 --- a/spec/acceptance/prometheus_server_spec.rb +++ b/spec/acceptance/prometheus_server_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'prometheus server' do +describe 'prometheus server basics' do it 'prometheus server via main class works idempotently with no errors' do pp = "class{'prometheus': manage_prometheus_server => true }" @@ -31,4 +31,22 @@ describe port(9090) do it { is_expected.to be_listening.with('tcp6') } end + + describe 'prometheus server with options' do + it 'is idempotent' do + pp = "class{'prometheus::server': version => '2.3.2', external_url => '/test'}" + # Run it twice and test for idempotency + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + end + + 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 end From cbc64fa1439ab71c76f3da7df6cf870605c9b2ac Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Wed, 1 Aug 2018 23:22:59 +0200 Subject: [PATCH 2/2] dont quote web.external-url param --- manifests/config.pp | 8 ++- manifests/init.pp | 2 +- manifests/server.pp | 84 ++++++++++++------------- spec/fixtures/files/prometheus2.debian | 1 - spec/fixtures/files/prometheus2.systemd | 1 - spec/fixtures/files/prometheus2.sysv | 1 - spec/fixtures/files/prometheus2.upstart | 1 - 7 files changed, 49 insertions(+), 49 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 9218a4102..2d3a9e31d 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -24,14 +24,18 @@ } else { # helper variable indicating prometheus version, so we can use on this information in the template $prometheus_v2 = true - $daemon_flags = [ + $daemon_flags_basic = [ "--config.file=${prometheus::server::config_dir}/${prometheus::server::configname}", "--storage.tsdb.path=${prometheus::server::localstorage}", "--storage.tsdb.retention=${prometheus::server::storage_retention}", "--web.console.templates=${prometheus::server::shared_dir}/consoles", "--web.console.libraries=${prometheus::server::shared_dir}/console_libraries", - "--web.external-url='${prometheus::server::external_url}'", ] + if $prometheus::server::external_url { + $daemon_flags = $daemon_flags_basic + "--web.external-url=${prometheus::server::external_url}" + } else { + $daemon_flags = $daemon_flags_basic + } } # the vast majority of files here are init-files diff --git a/manifests/init.pp b/manifests/init.pp index b255e9e19..6382f9844 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -179,7 +179,7 @@ Hash $config_hash = {}, Hash $config_defaults = {}, String $os = downcase($facts['kernel']), - Variant[Stdlib::HTTPUrl, Stdlib::Unixpath, String[0]] $external_url = '', + Optional[Variant[Stdlib::HTTPUrl, Stdlib::Unixpath, String[1]]] $external_url = undef, ) { case $arch { diff --git a/manifests/server.pp b/manifests/server.pp index 335db1609..e9d2ca716 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -1,48 +1,48 @@ # class to manage the actual prometheus server # this is a private class that gets called from the init.pp class prometheus::server ( - String $configname = $prometheus::configname, - 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, - Variant[Stdlib::HTTPurl, Stdlib::Unixpath, String[0]] $external_url = $prometheus::external_url, + String $configname = $prometheus::configname, + 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, + Optional[Variant[Stdlib::HTTPurl, Stdlib::Unixpath, String[1]]] $external_url = $prometheus::external_url, ) inherits prometheus { if( versioncmp($version, '1.0.0') == -1 ){ diff --git a/spec/fixtures/files/prometheus2.debian b/spec/fixtures/files/prometheus2.debian index f079132d9..89976cf33 100644 --- a/spec/fixtures/files/prometheus2.debian +++ b/spec/fixtures/files/prometheus2.debian @@ -23,7 +23,6 @@ DAEMON_ARGS="--config.file=/etc/prometheus/prometheus.yaml --storage.tsdb.retention=360h --web.console.templates=/usr/local/share/prometheus/consoles --web.console.libraries=/usr/local/share/prometheus/console_libraries - --web.external-url='' " USER=prometheus SCRIPTNAME=/etc/init.d/$NAME diff --git a/spec/fixtures/files/prometheus2.systemd b/spec/fixtures/files/prometheus2.systemd index 640fdca5e..fcac62e10 100644 --- a/spec/fixtures/files/prometheus2.systemd +++ b/spec/fixtures/files/prometheus2.systemd @@ -12,7 +12,6 @@ ExecStart=/usr/local/bin/prometheus \ --storage.tsdb.retention=360h \ --web.console.templates=/usr/local/share/prometheus/consoles \ --web.console.libraries=/usr/local/share/prometheus/console_libraries \ - --web.external-url='' \ ExecReload=/bin/kill -HUP $MAINPID KillMode=process diff --git a/spec/fixtures/files/prometheus2.sysv b/spec/fixtures/files/prometheus2.sysv index b4f6c742a..32c0dda4f 100644 --- a/spec/fixtures/files/prometheus2.sysv +++ b/spec/fixtures/files/prometheus2.sysv @@ -56,7 +56,6 @@ start() { --storage.tsdb.retention=360h \ --web.console.templates=/usr/local/share/prometheus/consoles \ --web.console.libraries=/usr/local/share/prometheus/console_libraries \ - --web.external-url='' \ >> "$LOG_FILE" & retcode=$? mkpidfile diff --git a/spec/fixtures/files/prometheus2.upstart b/spec/fixtures/files/prometheus2.upstart index bff9330de..150cf0063 100644 --- a/spec/fixtures/files/prometheus2.upstart +++ b/spec/fixtures/files/prometheus2.upstart @@ -27,7 +27,6 @@ script --storage.tsdb.retention=360h \ --web.console.templates=/usr/local/share/prometheus/consoles \ --web.console.libraries=/usr/local/share/prometheus/console_libraries \ - --web.external-url='' \ end script