diff --git a/data/defaults.yaml b/data/defaults.yaml index 7889799f1..936e02bbd 100644 --- a/data/defaults.yaml +++ b/data/defaults.yaml @@ -193,7 +193,7 @@ prometheus::mongodb_exporter::package_ensure: 'latest' prometheus::mongodb_exporter::package_name: 'mongodb_exporter' prometheus::mongodb_exporter::service_name: 'mongodb_exporter' prometheus::mongodb_exporter::user: 'mongodb-exporter' -prometheus::mongodb_exporter::version: '0.3.1' +prometheus::mongodb_exporter::version: '0.11.0' prometheus::mongodb_exporter::use_kingpin: false prometheus::node_exporter::download_extension: 'tar.gz' prometheus::node_exporter::download_url_base: 'https://github.com/prometheus/node_exporter/releases' diff --git a/manifests/mongodb_exporter.pp b/manifests/mongodb_exporter.pp index 154782886..6f36065d3 100644 --- a/manifests/mongodb_exporter.pp +++ b/manifests/mongodb_exporter.pp @@ -98,8 +98,40 @@ $options = "${flag_prefix}mongodb.uri=${cnf_uri} ${extra_options}" + if $install_method == 'url' and (versioncmp($version, '0.7.0') >= 0) { + # Not a big fan of copypasting but prometheus::daemon takes for granted + # a specific path embedded in the prometheus *_exporter tarball, which + # mongodb_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, + 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 { 'mongodb_exporter': - install_method => $install_method, + install_method => $exporter_install_method, version => $version, download_extension => $download_extension, os => $os, diff --git a/spec/acceptance/mongodb_exporter_spec.rb b/spec/acceptance/mongodb_exporter_spec.rb new file mode 100644 index 000000000..437bb6b4d --- /dev/null +++ b/spec/acceptance/mongodb_exporter_spec.rb @@ -0,0 +1,54 @@ +require 'spec_helper_acceptance' + +describe 'prometheus mongodb_exporter' do + it 'mongodb_exporter works idempotently with no errors' do + pp = 'include prometheus::mongodb_exporter' + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, expect_changes: true) + shell('sleep 30') + end + + describe 'prometheus mongodb_exporter version 0.3.1' do + it ' mongodb_exporter installs with version 0.3.1' do + pp = "class { 'prometheus::mongodb_exporter': version => '0.3.1' }" + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + shell('sleep 30') + end + + describe process('mongodb_exporter') do + its(:args) { is_expected.to match %r{\ -mongodb.uri} } + end + + describe service('mongodb_exporter') do + it { is_expected.to be_running } + it { is_expected.to be_enabled } + end + + describe port(9216) do + it { is_expected.to be_listening.with('tcp6') } + end + end + + describe 'prometheus mongodb_exporter version 0.11.0' do + it ' mongodb_exporter installs with version 0.11.0' do + pp = "class { 'prometheus::mongodb_exporter': version => '0.11.0', use_kingpin => true }" + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + shell('sleep 30') + end + + describe process('mongodb_exporter') do + its(:args) { is_expected.to match %r{\ --mongodb.uri} } + end + + describe service('mongodb_exporter') do + it { is_expected.to be_running } + it { is_expected.to be_enabled } + end + + describe port(9216) do + it { is_expected.to be_listening.with('tcp6') } + end + end +end