-
-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add postgres exporter #236
Changes from 2 commits
5ec5caf
7e75e5b
433b51d
13be23c
6b9fc49
3055010
ab858a9
0d5fc50
ac1507b
8942df3
3cd4521
bcacade
631e6fc
04b0d09
0dd6171
677ac72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
# Class: prometheus::postgres_exporter | ||
# | ||
# This module manages prometheus node postgres_exporter | ||
# | ||
# Parameters: | ||
# [*arch*] | ||
# Architecture (amd64 or i386) | ||
# | ||
|
||
# [*bin_dir*] | ||
# Directory where binaries are located | ||
# | ||
# [*addr*] | ||
# Array of address of one or more redis nodes. Defaults to redis://localhost:6379 | ||
# | ||
# [*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 | ||
# For a full list of the exporter's supported extra options | ||
# please refer to https://github.com/wrouesnel/postgres_exporter | ||
# | ||
# [*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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not aware of a packaged version of postgres_exporter, if it exsist, its not tested. |
||
# | ||
# [*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 | ||
# | ||
# [*purge_config_dir*] | ||
# Purge config files no longer generated by Puppet | ||
# | ||
# [*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 'postgres_exporter') | ||
# | ||
# [*user*] | ||
# User which runs the service | ||
# | ||
# [*version*] | ||
# The binary release version | ||
|
||
# [*postgres_user*] | ||
# User to authenticate against postgres | ||
# | ||
# [*postgres_pass*] | ||
# Password to authenticate against postgres | ||
# | ||
# [*postgres_auth_method*] | ||
# method for presenting username and password to the exporter | ||
# This can be file, or env (default 'env') | ||
# | ||
# [*data_source_uri*] | ||
# Uri on howto connect to the database | ||
|
||
class prometheus::postgres_exporter ( | ||
String $download_extension, | ||
String $download_url_base, | ||
Array[String] $extra_groups, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please update this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. done |
||
String $group, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you update the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added quite a few [1]'s to where it makes sense. also some minor cleanups, in de comments |
||
String $package_ensure, | ||
String $package_name, | ||
String $user, | ||
String $version, | ||
String $data_source_uri, | ||
String $postgres_pass, | ||
String $postgres_user, | ||
Enum['env', 'file'] $postgres_auth_method, | ||
Boolean $purge_config_dir = true, | ||
Boolean $restart_on_change = true, | ||
Boolean $service_enable = true, | ||
String $service_ensure = 'running', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for all the other String datatypes here: Please ensure a minimal String length of 1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now its done for all non optional strings. |
||
String $service_name = 'postgres_exporter', | ||
Optional[String] $init_style = $prometheus::init_style, | ||
String $install_method = $prometheus::install_method, | ||
Boolean $manage_group = true, | ||
Boolean $manage_service = true, | ||
Boolean $manage_user = true, | ||
String $os = $prometheus::os, | ||
String $options = '', | ||
Optional[String] $download_url = undef, | ||
String $arch = $prometheus::real_arch, | ||
String $bin_dir = $prometheus::bin_dir, | ||
) inherits prometheus { | ||
|
||
$release = "v${version}" | ||
|
||
$real_download_url = pick($download_url, "${download_url_base}/download/${release}/${package_name}_${release}_${os}-${arch}.${download_extension}") | ||
|
||
$notify_service = $restart_on_change ? { | ||
true => Service[$service_name], | ||
default => undef, | ||
} | ||
|
||
case $postgres_auth_method { | ||
'env': { | ||
$env_vars = { | ||
'DATA_SOURCE_URI' => $data_source_uri, | ||
'DATA_SOURCE_USER' => $postgres_user, | ||
'DATA_SOURCE_PASS' => $postgres_pass, | ||
} | ||
} | ||
'file': { | ||
$env_vars = { | ||
'DATA_SOURCE_URI' => $data_source_uri, | ||
'DATA_SOURCE_USER_FILE' => $postgres_user, | ||
'DATA_SOURCE_PASS_FILE' => $postgres_pass, | ||
} | ||
} | ||
default: { | ||
$env_vars = {} | ||
} | ||
} | ||
|
||
if $install_method == 'url' { | ||
# Not a big fan of copypasting but prometheus::daemon takes for granted | ||
# a specific path embedded in the prometheus *_exporter tarball, which | ||
# redis_exporter lacks. | ||
# TODO: patch prometheus::daemon to support custom extract directories | ||
$exporter_install_method = 'none' | ||
$install_dir = "/opt/${service_name}-${version}.${os}-${arch}" | ||
file { $install_dir: | ||
ensure => 'directory', | ||
owner => 'root', | ||
group => 0, # 0 instead of root because OS X uses "wheel". | ||
mode => '0555', | ||
} | ||
-> archive { "/tmp/${service_name}-${version}.${download_extension}": | ||
ensure => present, | ||
extract => true, | ||
extract_path => $install_dir, | ||
extract_flags => '--strip-components=1 -xzf', | ||
source => $real_download_url, | ||
checksum_verify => false, | ||
creates => "${install_dir}/${service_name}", | ||
cleanup => true, | ||
} | ||
-> file { "${bin_dir}/${service_name}": | ||
ensure => link, | ||
notify => $notify_service, | ||
target => "${install_dir}/${service_name}", | ||
before => Prometheus::Daemon[$service_name], | ||
} | ||
} else { | ||
$exporter_install_method = $install_method | ||
} | ||
|
||
prometheus::daemon { $service_name: | ||
install_method => $exporter_install_method, | ||
version => $version, | ||
download_extension => $download_extension, | ||
env_vars => $env_vars, | ||
os => $os, | ||
arch => $arch, | ||
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, | ||
real_download_url => $real_download_url, | ||
group => $group, | ||
manage_group => $manage_group, | ||
purge => $purge_config_dir, | ||
options => $options, | ||
init_style => $init_style, | ||
service_ensure => $service_ensure, | ||
service_enable => $service_enable, | ||
manage_service => $manage_service, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'spec_helper_acceptance' | ||
|
||
describe 'prometheus postgres exporter' do | ||
it 'postgres_exporter works idempotently with no errors' do | ||
pp = 'include prometheus::postgres_exporter' | ||
# Run it twice and test for idempotency | ||
apply_manifest(pp, catch_failures: true) | ||
apply_manifest(pp, catch_changes: true) | ||
end | ||
|
||
describe service('postgres_exporter') do | ||
it { is_expected.to be_running } | ||
it { is_expected.to be_enabled } | ||
end | ||
# the class installs an the postgres_exporter that listens on port 9187 | ||
describe port(9187) do | ||
it { is_expected.to be_listening.with('tcp6') } | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'spec_helper' | ||
|
||
describe 'prometheus::postgres_exporter' do | ||
on_supported_os.each do |os, facts| | ||
context "on #{os}" do | ||
let(:facts) do | ||
facts.merge(os_specific_facts(facts)) | ||
end | ||
|
||
context 'with version specified' do | ||
let(:params) do | ||
{ | ||
version: '0.4.6', | ||
arch: 'amd64', | ||
os: 'linux', | ||
bin_dir: '/usr/local/bin', | ||
install_method: 'url' | ||
} | ||
end | ||
|
||
describe 'install correct binary' do | ||
it { is_expected.to contain_file('/usr/local/bin/postgres_exporter').with('target' => '/opt/postgres_exporter-0.4.6.linux-amd64/postgres_exporter') } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please also add something like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added, a few tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be awesome! |
||
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should postgres_user and postgres_pass default to undef? Might makes it more obvious to users that they need to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed,
i had to add the postgres_pass and postgres_pass to the spec test, to make the daemon start