From 8596b33fdcbe72454f750a4b68c474a7bcbd8d7f Mon Sep 17 00:00:00 2001 From: Christoph Maser Date: Wed, 22 Aug 2018 11:56:17 +0200 Subject: [PATCH] Add support for mysqld_exporter version 0.11.0 (#247) Flags now use the Kingpin library, and require double-dashes. https://github.com/prometheus/mysqld_exporter/pull/222 --- manifests/mysqld_exporter.pp | 7 +++-- spec/acceptance/mysqld_exporter_spec.rb | 38 +++++++++++++++++++++++++ spec/classes/mysqld_exporter_spec.rb | 29 +++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 spec/acceptance/mysqld_exporter_spec.rb create mode 100644 spec/classes/mysqld_exporter_spec.rb diff --git a/manifests/mysqld_exporter.pp b/manifests/mysqld_exporter.pp index 71379bd85..e1d1814e0 100644 --- a/manifests/mysqld_exporter.pp +++ b/manifests/mysqld_exporter.pp @@ -138,8 +138,11 @@ notify => $notify_service, } - $options = "-config.my-cnf=${cnf_config_path} ${extra_options}" - + if versioncmp($version, '0.11.0') < 0 { + $options = "-config.my-cnf=${cnf_config_path} ${extra_options}" + } else { + $options = "--config.my-cnf=${cnf_config_path} ${extra_options}" + } prometheus::daemon { 'mysqld_exporter': install_method => $install_method, version => $version, diff --git a/spec/acceptance/mysqld_exporter_spec.rb b/spec/acceptance/mysqld_exporter_spec.rb new file mode 100644 index 000000000..7e564f5fa --- /dev/null +++ b/spec/acceptance/mysqld_exporter_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper_acceptance' + +describe 'prometheus mysqld exporter' do + it 'mysqld_exporter works idempotently with no errors' do + if default[:platform] =~ %r{ubuntu-18.04-amd64} + pp = "package{'iproute2': ensure => present}" + apply_manifest(pp, catch_failures: true) + end + pp = 'include prometheus::mysqld_exporter' + # Run it twice and test for idempotency + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + end + + describe 'default install' do + describe service('mysqld_exporter') do + it { is_expected.to be_running } + it { is_expected.to be_enabled } + end + # the class installs an the mysqld_exporter that listens on port 9104 + describe port(9104) do + it { is_expected.to be_listening.with('tcp6') } + end + describe process('mysqld_exporter') do + its(:args) { is_expected.to match %r{\ -config.my-cnf} } + end + end + + describe 'update prometheus mysqld exporter' do + it 'update mysqld_exporter to 0.11.0' do + pp = "class {'prometheus::mysqld_exporter': version => '0.11.0' }" + apply_manifest(pp, catch_failures: true) + end + describe process('mysqld_exporter') do + its(:args) { is_expected.to match %r{\ --config.my-cnf} } + end + end +end diff --git a/spec/classes/mysqld_exporter_spec.rb b/spec/classes/mysqld_exporter_spec.rb new file mode 100644 index 000000000..c5743a01f --- /dev/null +++ b/spec/classes/mysqld_exporter_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe 'prometheus::mysqld_exporter' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge(os_specific_facts(facts)) + end + + context 'default' do + describe 'options is correct' do + it { is_expected.to contain_prometheus__daemon('mysqld_exporter').with('options' => '-config.my-cnf=/etc/.my.cnf ') } + end + end + + context 'with version >= 0.11.0' do + let(:params) do + { + version: '0.11.0' + } + end + + describe 'options is correct' do + it { is_expected.to contain_prometheus__daemon('mysqld_exporter').with('options' => '--config.my-cnf=/etc/.my.cnf ') } + end + end + end + end +end