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
new feature - consul_exporter #36
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
323a597
Adding consul_exporter
e64379e
Cater for archives with different binary file location
8c6a0f4
Linting file
0a850ba
Merge remote-tracking branch 'upstream/master'
359bc50
Drop support for custom_binary_location
db5a999
Support version 0.3.0 and higher
7a22112
Merge remote-tracking branch 'upstream/master'
2fd641e
Replaced legacy functions with native puppet datatypes
79ba509
Add unit test for consul_exporter
8313794
Remove trailing comma
a8b66dd
Update README
e5ce3de
Merge remote-tracking branch 'upstream/master'
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
# Class: prometheus::consul_exporter | ||
# | ||
# This module manages prometheus node consul_exporter | ||
# | ||
# Parameters: | ||
# [*arch*] | ||
# Architecture (amd64 or i386) | ||
# | ||
# [*bin_dir*] | ||
# Directory where binaries are located | ||
# | ||
# [*consul_server*] | ||
# HTTP API address of a Consul server or agent. (prefix with https:// to connect over HTTPS) (default "http://localhost:8500") | ||
# | ||
# [*consul_health_summary*] | ||
# Generate a health summary for each service instance. Needs n+1 queries to collect all information. (default true) | ||
# | ||
# [*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) | ||
# | ||
# [*log_level*] | ||
# Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal] (default "info") | ||
# | ||
# [*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') | ||
# | ||
# [*user*] | ||
# User which runs the service | ||
# | ||
# [*version*] | ||
# The binary release version | ||
# | ||
# [*web_listen_address*] | ||
# Address to listen on for web interface and telemetry. (default ":9107") | ||
# | ||
# [*web_telemetry_path*] | ||
# Path under which to expose metrics. (default "/metrics") | ||
class prometheus::consul_exporter ( | ||
String $arch = $::prometheus::params::arch, | ||
String $bin_dir = $::prometheus::params::bin_dir, | ||
Boolean $consul_health_summary = $::prometheus::params::consul_exporter_consul_health_summary, | ||
String $consul_server = $::prometheus::params::consul_exporter_consul_server, | ||
String $download_extension = $::prometheus::params::consul_exporter_download_extension, | ||
Optional[String] $download_url = undef, | ||
String $download_url_base = $::prometheus::params::consul_exporter_download_url_base, | ||
Array $extra_groups = $::prometheus::params::consul_exporter_extra_groups, | ||
String $extra_options = '', | ||
String $group = $::prometheus::params::consul_exporter_group, | ||
String $init_style = $::prometheus::params::init_style, | ||
String $install_method = $::prometheus::params::install_method, | ||
String $log_level = $::prometheus::params::consul_exporter_log_level, | ||
Boolean $manage_group = true, | ||
Boolean $manage_service = true, | ||
Boolean $manage_user = true, | ||
String $os = $::prometheus::params::os, | ||
String $package_ensure = $::prometheus::params::consul_exporter_package_ensure, | ||
String $package_name = $::prometheus::params::consul_exporter_package_name, | ||
Boolean $purge_config_dir = true, | ||
Boolean $restart_on_change = true, | ||
Boolean $service_enable = true, | ||
String $service_ensure = 'running', | ||
String $user = $::prometheus::params::consul_exporter_user, | ||
String $version = $::prometheus::params::consul_exporter_version, | ||
String $web_listen_address = $::prometheus::params::consul_exporter_web_listen_address, | ||
String $web_telemetry_path = $::prometheus::params::consul_exporter_web_telemetry_path, | ||
) inherits prometheus::params { | ||
# Prometheus added a 'v' on the realease name at 0.3.0 | ||
if versioncmp ($version, '0.3.0') == -1 { | ||
fail("I only support consul_exporter version '0.3.0' or higher") | ||
} | ||
|
||
$real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}") | ||
|
||
if $consul_health_summary { | ||
$real_consul_health_summary = '-consul.health-summary' | ||
} else { | ||
$real_consul_health_summary = '' | ||
} | ||
|
||
$notify_service = $restart_on_change ? { | ||
true => Service['consul_exporter'], | ||
default => undef, | ||
} | ||
|
||
$options = "-consul.server=${consul_server} ${real_consul_health_summary} -web.listen-address=${web_listen_address} -web.telemetry-path=${web_telemetry_path} -log.level=${log_level} ${extra_options}" | ||
|
||
prometheus::daemon { 'consul_exporter': | ||
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, | ||
purge => $purge_config_dir, | ||
options => $options, | ||
init_style => $init_style, | ||
service_ensure => $service_ensure, | ||
service_enable => $service_enable, | ||
manage_service => $manage_service, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'spec_helper' | ||
|
||
describe 'prometheus::consul_exporter' 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.3.0', | ||
arch: 'amd64', | ||
os: 'linux' | ||
} | ||
end | ||
|
||
describe 'with all defaults' do | ||
it { is_expected.to compile.with_all_deps } | ||
it { is_expected.to contain_file('/usr/local/bin/consul_exporter').with('target' => '/opt/consul_exporter-0.3.0.linux-amd64/consul_exporter') } | ||
it { is_expected.to contain_prometheus__daemon('consul_exporter') } | ||
it { is_expected.to contain_user('consul-exporter') } | ||
it { is_expected.to contain_group('consul-exporter') } | ||
it { is_expected.to contain_service('consul_exporter') } | ||
end | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
datatypes \o/