Skip to content

Commit

Permalink
Add tests for elasticsearch_exporter and update a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
salekseev committed Oct 12, 2017
1 parent e9d3487 commit fc98f0c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 38 deletions.
73 changes: 38 additions & 35 deletions manifests/elasticsearch_exporter.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Class: prometheus::elasticsearch_exporter
#
# This module manages prometheus node elasticsearch_exporter
# This module manages prometheus elasticsearch_exporter
#
# Parameters:
# [*arch*]
Expand All @@ -9,6 +9,15 @@
# [*bin_dir*]
# Directory where binaries are located
#
# [*cnf_uri*]
# The URI to obtain elasticsearch stats from
#
# [*cnf_all*]
# If true, query stats for all nodes in the cluster, rather than just the node we connect to.
#
# [*cnf_timeout*]
# Timeout for trying to get stats from elasticsearch URI
#
# [*download_extension*]
# Extension for the release binary archive
#
Expand All @@ -27,9 +36,6 @@
# [*group*]
# Group under which the binary is running
#
# [*listen_address*]
# Address to listen on for web interface and telemetry. (default ":9108")
#
# [*init_style*]
# Service startup scripts style (e.g. rc, upstart or systemd)
#
Expand Down Expand Up @@ -66,49 +72,46 @@
# [*service_ensure*]
# State ensured for the service (default 'running')
#
# [*uri*]
# HTTP API address of an Elasticsearch node. (default "http://localhost:9200")
#
# [*user*]
# User which runs the service
#
# [*version*]
# The binary release version
class prometheus::elasticsearch_exporter (
$arch = $::prometheus::params::arch,
$bin_dir = $::prometheus::params::bin_dir,
$download_extension = $::prometheus::params::elasticsearch_exporter_download_extension,
$download_url = undef,
$download_url_base = $::prometheus::params::elasticsearch_exporter_download_url_base,
$extra_groups = $::prometheus::params::elasticsearch_exporter_extra_groups,
$extra_options = '',
$group = $::prometheus::params::elasticsearch_exporter_group,
$init_style = $::prometheus::params::init_style,
$install_method = $::prometheus::params::install_method,
$listen_address = $::prometheus::params::elasticsearch_exporter_listen_address,
Boolean $manage_group = true,
Boolean $manage_service = true,
Boolean $manage_user = true,
$os = $::prometheus::params::os,
$package_ensure = $::prometheus::params::elasticsearch_exporter_package_ensure,
$package_name = $::prometheus::params::elasticsearch_exporter_package_name,
Boolean $purge_config_dir = true,
Boolean $restart_on_change = true,
Boolean $service_enable = true,
$service_ensure = 'running',
$service_name = 'elasticsearch_exporter',
$uri = $::prometheus::params::elasticsearch_exporter_uri,
$user = $::prometheus::params::elasticsearch_exporter_user,
$version = $::prometheus::params::elasticsearch_exporter_version,
String $arch = $::prometheus::params::arch,
String $bin_dir = $::prometheus::params::bin_dir,
String $cnf_uri = $::prometheus::params::elasticsearch_exporter_cnf_uri,
String $cnf_timeout = $::prometheus::params::elasticsearch_exporter_cnf_timeout,
String $download_extension = $::prometheus::params::elasticsearch_exporter_download_extension,
Variant[Undef,String] $download_url = undef,
String $download_url_base = $::prometheus::params::elasticsearch_exporter_download_url_base,
Array $extra_groups = $::prometheus::params::elasticsearch_exporter_extra_groups,
String $extra_options = '',
String $group = $::prometheus::params::elasticsearch_exporter_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::elasticsearch_exporter_package_ensure,
String $package_name = $::prometheus::params::elasticsearch_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::elasticsearch_exporter_user,
String $version = $::prometheus::params::elasticsearch_exporter_version,
) inherits prometheus::params {
$real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")
#Please provide the download_url for versions < 0.9.0
$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[$service_name],
true => Service['elasticsearch_exporter'],
default => undef,
}

$options = "-es.uri ${uri} -web.listen-address ${listen_address} ${extra_options}"
$options = "-es.uri=${cnf_uri} -es.timeout=${cnf_timeout} ${extra_options}"

prometheus::daemon { 'elasticsearch_exporter':
install_method => $install_method,
Expand Down
6 changes: 3 additions & 3 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
$config_template = 'prometheus/prometheus.yaml.erb'
$download_extension = 'tar.gz'
$download_url_base = 'https://github.com/prometheus/prometheus/releases'
$elasticsearch_exporter_cnf_uri = 'http://localhost:9200'
$elasticsearch_exporter_cnf_timeout = '5s'
$elasticsearch_exporter_download_extension = 'tar.gz'
$elasticsearch_exporter_download_url_base = 'https://github.com/justwatchcom/elasticsearch_exporter/releases'
$elasticsearch_exporter_extra_groups = []
$elasticsearch_exporter_group = 'elasticsearch-exporter'
$elasticsearch_exporter_listen_address = ':9108'
$elasticsearch_exporter_package_ensure = 'latest'
$elasticsearch_exporter_package_name = 'elasticsearch_exporter'
$elasticsearch_exporter_uri = 'http://localhost:9200'
$elasticsearch_exporter_user = 'elasticsearch-exporter'
$elasticsearch_exporter_version = '1.0.1'
$elasticsearch_exporter_version = '1.0.2rc1'
$extra_groups = []
$global_config = { 'scrape_interval'=> '15s', 'evaluation_interval'=> '15s', 'external_labels'=> { 'monitor'=>'master'}}
$group = 'prometheus'
Expand Down
29 changes: 29 additions & 0 deletions spec/classes/elasticsearch_exporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

describe 'prometheus::elasticsearch_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: '1.0.0',
arch: 'amd64',
os: 'linux'
}
end

describe 'compile manifest' do
it { is_expected.to compile.with_all_deps }
end

describe 'install correct binary' do
it { is_expected.to contain_file('/usr/local/bin/elasticsearch_exporter').with('target' => '/opt/elasticsearch_exporter-1.0.0.linux-amd64/elasticsearch_exporter') }
end
end
end
end
end

0 comments on commit fc98f0c

Please sign in to comment.