From d4871772bcd93d5cd336aca53ef6b85f40fb2e65 Mon Sep 17 00:00:00 2001 From: Mike DeBruyn Date: Fri, 13 Oct 2017 11:29:02 -0400 Subject: [PATCH 1/6] Adding pushgateway --- manifests/params.pp | 8 +++ manifests/pushgateway.pp | 133 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 manifests/pushgateway.pp diff --git a/manifests/params.pp b/manifests/params.pp index 814ff5a9f..e8c081780 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -59,6 +59,14 @@ $process_exporter_user = 'process-exporter' $process_exporter_version = '0.1.0' $process_exporter_config_path = '/etc/process-exporter.yaml' + $pushgateway_download_extension = 'tar.gz' + $pushgateway_download_url_base = 'https://github.com/prometheus/pushgateway/releases' + $pushgateway_extra_groups = [] + $pushgateway_group = 'pushgateway' + $pushgateway_package_ensure = 'latest' + $pushgateway_package_name = 'pushgateway' + $pushgateway_user = 'pushgateway' + $pushgateway_version = '0.4.0' $mysqld_exporter_cnf_config_path = '/etc/.my.cnf' $mysqld_exporter_cnf_host = 'localhost' $mysqld_exporter_cnf_password = 'password' diff --git a/manifests/pushgateway.pp b/manifests/pushgateway.pp new file mode 100644 index 000000000..b4695534f --- /dev/null +++ b/manifests/pushgateway.pp @@ -0,0 +1,133 @@ +# Class: prometheus::pushgateway +# +# This module manages prometheus node pushgateway +# +# Parameters: +# [*arch*] +# Architecture (amd64 or i386) + +# [*bin_dir*] +# Directory where binaries are located +# +# [*download_extension*] +# Extension for the release binary archive +# +# [*download_url*] +# Complete URL corresponding to the where the release binary archive can be downloaded +# +# [*download_url_base*] +# Base URL for the binary archive +# +# [*extra_groups*] +# Extra groups to add the binary user to +# +# [*extra_options*] +# Extra options added to the startup command +# +# [*group*] +# Group under which the binary is running +# +# [*init_style*] +# Service startup scripts style (e.g. rc, upstart or systemd) +# +# [*install_method*] +# Installation method: url or package (only url is supported currently) +# +# [*manage_group*] +# Whether to create a group for or rely on external code for that +# +# [*manage_service*] +# Should puppet manage the service? (default true) +# +# [*manage_user*] +# Whether to create user or rely on external code for that +# +# [*os*] +# Operating system (linux is the only one supported) +# +# [*package_ensure*] +# If package, then use this for package ensure default 'latest' +# +# [*package_name*] +# The binary package name - not available yet +# +# [*restart_on_change*] +# Should puppet restart the service on configuration change? (default true) +# +# [*service_enable*] +# Whether to enable the service from puppet (default true) +# +# [*service_ensure*] +# State ensured for the service (default 'running') +# +# [*service_name*] +# Name of the node exporter service (default 'pushgateway') +# +# [*user*] +# User which runs the service +# +# [*version*] +# The binary release version +class prometheus::pushgateway ( + $arch = $::prometheus::params::arch, + $bin_dir = $::prometheus::params::bin_dir, + $download_extension = $::prometheus::params::pushgateway_download_extension, + $download_url = undef, + $download_url_base = $::prometheus::params::pushgateway_download_url_base, + $extra_groups = $::prometheus::params::pushgateway_extra_groups, + $extra_options = '', + $group = $::prometheus::params::pushgateway_group, + $init_style = $::prometheus::params::init_style, + $install_method = $::prometheus::params::install_method, + $manage_group = true, + $manage_service = true, + $manage_user = true, + $os = $::prometheus::params::os, + $package_ensure = $::prometheus::params::pushgateway_package_ensure, + $package_name = $::prometheus::params::pushgateway_package_name, + $restart_on_change = true, + $service_enable = true, + $service_ensure = 'running', + $service_name = 'pushgateway', + $user = $::prometheus::params::pushgateway_user, + $version = $::prometheus::params::pushgateway_version, +) inherits prometheus::params { + # Prometheus added a 'v' on the realease name at 0.13.0 + if versioncmp ($version, '0.3.0') >= 0 { + $release = "v${version}" + } + else { + $release = $version + } + $real_download_url = pick($download_url,"${download_url_base}/download/${release}/${package_name}-${version}.${os}-${arch}.${download_extension}") + validate_bool($manage_user) + validate_bool($manage_service) + validate_bool($restart_on_change) + $notify_service = $restart_on_change ? { + true => Service[$service_name], + default => undef, + } + + prometheus::daemon { $service_name : + install_method => $install_method, + version => $version, + download_extension => $download_extension, + os => $os, + arch => $arch, + real_download_url => $real_download_url, + bin_dir => $bin_dir, + notify_service => $notify_service, + package_name => $package_name, + package_ensure => $package_ensure, + manage_user => $manage_user, + user => $user, + extra_groups => $extra_groups, + group => $group, + manage_group => $manage_group, + options => $options, + init_style => $init_style, + service_ensure => $service_ensure, + service_enable => $service_enable, + manage_service => $manage_service, + } +} From 217aa8c00f4e55519409c03ee333d229b1e55c2a Mon Sep 17 00:00:00 2001 From: Mike DeBruyn Date: Fri, 13 Oct 2017 12:57:13 -0400 Subject: [PATCH 2/6] fix comment version number --- manifests/pushgateway.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/pushgateway.pp b/manifests/pushgateway.pp index b4695534f..570d66d97 100644 --- a/manifests/pushgateway.pp +++ b/manifests/pushgateway.pp @@ -92,7 +92,7 @@ $user = $::prometheus::params::pushgateway_user, $version = $::prometheus::params::pushgateway_version, ) inherits prometheus::params { - # Prometheus added a 'v' on the realease name at 0.13.0 + # Prometheus added a 'v' on the realease name at 0.3.0 if versioncmp ($version, '0.3.0') >= 0 { $release = "v${version}" } From b394e5814d5e67a9367b9c078f17fb1d56e0099f Mon Sep 17 00:00:00 2001 From: Mike DeBruyn Date: Fri, 13 Oct 2017 13:12:00 -0400 Subject: [PATCH 3/6] Add pushgateway spec test --- spec/classes/pushgateway_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/classes/pushgateway_spec.rb diff --git a/spec/classes/pushgateway_spec.rb b/spec/classes/pushgateway_spec.rb new file mode 100644 index 000000000..328fe86d1 --- /dev/null +++ b/spec/classes/pushgateway_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe 'prometheus::pushgateway' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + + context 'with version specified' do + let(:params) do + { + version: '0.4.0', + arch: 'amd64', + os: 'linux' + } + end + + describe 'install correct binary' do + it { is_expected.to contain_file('/usr/local/bin/pushgateway').with('target' => '/opt/pushgateway-0.4.0.linux-amd64/pushgateway') } + end + end + end + end +end From 15c69bde1908579a7e552357fdcba1538b4f50ca Mon Sep 17 00:00:00 2001 From: Mike DeBruyn Date: Fri, 13 Oct 2017 13:32:01 -0400 Subject: [PATCH 4/6] fix options --- manifests/pushgateway.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/pushgateway.pp b/manifests/pushgateway.pp index 570d66d97..fbcc5ba1b 100644 --- a/manifests/pushgateway.pp +++ b/manifests/pushgateway.pp @@ -124,7 +124,7 @@ extra_groups => $extra_groups, group => $group, manage_group => $manage_group, - options => $options, + options => $extra_options, init_style => $init_style, service_ensure => $service_ensure, service_enable => $service_enable, From e7fc0d44aa97a190dcd8feca9adb481311719691 Mon Sep 17 00:00:00 2001 From: Mike DeBruyn Date: Fri, 13 Oct 2017 13:39:34 -0400 Subject: [PATCH 5/6] Adding Datatypes to the pushgateway class --- manifests/pushgateway.pp | 47 +++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/manifests/pushgateway.pp b/manifests/pushgateway.pp index fbcc5ba1b..4ae3d481d 100644 --- a/manifests/pushgateway.pp +++ b/manifests/pushgateway.pp @@ -69,28 +69,28 @@ # [*version*] # The binary release version class prometheus::pushgateway ( - $arch = $::prometheus::params::arch, - $bin_dir = $::prometheus::params::bin_dir, - $download_extension = $::prometheus::params::pushgateway_download_extension, - $download_url = undef, - $download_url_base = $::prometheus::params::pushgateway_download_url_base, - $extra_groups = $::prometheus::params::pushgateway_extra_groups, - $extra_options = '', - $group = $::prometheus::params::pushgateway_group, - $init_style = $::prometheus::params::init_style, - $install_method = $::prometheus::params::install_method, - $manage_group = true, - $manage_service = true, - $manage_user = true, - $os = $::prometheus::params::os, - $package_ensure = $::prometheus::params::pushgateway_package_ensure, - $package_name = $::prometheus::params::pushgateway_package_name, - $restart_on_change = true, - $service_enable = true, - $service_ensure = 'running', - $service_name = 'pushgateway', - $user = $::prometheus::params::pushgateway_user, - $version = $::prometheus::params::pushgateway_version, + String $arch = $::prometheus::params::arch, + String $bin_dir = $::prometheus::params::bin_dir, + String $download_extension = $::prometheus::params::pushgateway_download_extension, + Variant[Undef,String] $download_url = undef, + String $download_url_base = $::prometheus::params::pushgateway_download_url_base, + Array $extra_groups = $::prometheus::params::pushgateway_extra_groups, + String $extra_options = '', + String $group = $::prometheus::params::pushgateway_group, + String $init_style = $::prometheus::params::init_style, + String $install_method = $::prometheus::params::install_method, + Boolean $manage_group = true, + Boolean $manage_service = true, + Boolean $manage_user = true, + String $os = $::prometheus::params::os, + String $package_ensure = $::prometheus::params::pushgateway_package_ensure, + String $package_name = $::prometheus::params::pushgateway_package_name, + Boolean $restart_on_change = true, + Boolean $service_enable = true, + String $service_ensure = 'running', + String $service_name = 'pushgateway', + String $user = $::prometheus::params::pushgateway_user, + String $version = $::prometheus::params::pushgateway_version, ) inherits prometheus::params { # Prometheus added a 'v' on the realease name at 0.3.0 if versioncmp ($version, '0.3.0') >= 0 { @@ -100,9 +100,6 @@ $release = $version } $real_download_url = pick($download_url,"${download_url_base}/download/${release}/${package_name}-${version}.${os}-${arch}.${download_extension}") - validate_bool($manage_user) - validate_bool($manage_service) - validate_bool($restart_on_change) $notify_service = $restart_on_change ? { true => Service[$service_name], default => undef, From 73deb06cc3eb7333738d82269284c39275b88bee Mon Sep 17 00:00:00 2001 From: Mike DeBruyn Date: Fri, 13 Oct 2017 13:41:42 -0400 Subject: [PATCH 6/6] fix pushgateway spec formatting --- spec/classes/pushgateway_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/classes/pushgateway_spec.rb b/spec/classes/pushgateway_spec.rb index 328fe86d1..05eb24319 100644 --- a/spec/classes/pushgateway_spec.rb +++ b/spec/classes/pushgateway_spec.rb @@ -10,9 +10,9 @@ context 'with version specified' do let(:params) do { - version: '0.4.0', - arch: 'amd64', - os: 'linux' + version: '0.4.0', + arch: 'amd64', + os: 'linux' } end