From 67d8cc577876c2b416fb7548841f7e1f5676f4fb Mon Sep 17 00:00:00 2001 From: Christoph Maser Date: Fri, 3 Aug 2018 12:33:17 +0200 Subject: [PATCH 1/3] update mysqld_exporter version to 0.11.0 Flags now use the Kingpin library, and require double-dashes. https://github.com/prometheus/mysqld_exporter/pull/222 Breaking change: if you do not set a version for mysqld_exporter *and* set `extra_options` make sure you update `extra_options` to be compatible with version 0.11.0 and greater. --- data/defaults.yaml | 2 +- manifests/mysqld_exporter.pp | 7 +++++-- spec/classes/mysqld_exporter_spec.rb | 31 ++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 spec/classes/mysqld_exporter_spec.rb diff --git a/data/defaults.yaml b/data/defaults.yaml index 2e3863ac8..d75464c28 100644 --- a/data/defaults.yaml +++ b/data/defaults.yaml @@ -168,7 +168,7 @@ prometheus::mysqld_exporter::group: 'mysqld-exporter' prometheus::mysqld_exporter::package_ensure: 'latest' prometheus::mysqld_exporter::package_name: 'mysqld_exporter' prometheus::mysqld_exporter::user: 'mysqld-exporter' -prometheus::mysqld_exporter::version: '0.9.0' +prometheus::mysqld_exporter::version: '0.11.0' prometheus::mongodb_exporter::cnf_uri: 'mongodb://localhost:27017' prometheus::mongodb_exporter::download_extension: 'tar.gz' prometheus::mongodb_exporter::download_url_base: 'https://github.com/percona/mongodb_exporter/releases' 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/classes/mysqld_exporter_spec.rb b/spec/classes/mysqld_exporter_spec.rb new file mode 100644 index 000000000..6eee16efa --- /dev/null +++ b/spec/classes/mysqld_exporter_spec.rb @@ -0,0 +1,31 @@ +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.9.0', + arch: 'amd64', + os: 'linux' + } + 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 From 48626afa393be8f926aeb03070e41bd2bf2e7d5c Mon Sep 17 00:00:00 2001 From: Christoph Maser Date: Mon, 13 Aug 2018 19:17:28 +0200 Subject: [PATCH 2/3] revert updating default version of mysql_exporter --- data/defaults.yaml | 2 +- spec/classes/mysqld_exporter_spec.rb | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/data/defaults.yaml b/data/defaults.yaml index d75464c28..2e3863ac8 100644 --- a/data/defaults.yaml +++ b/data/defaults.yaml @@ -168,7 +168,7 @@ prometheus::mysqld_exporter::group: 'mysqld-exporter' prometheus::mysqld_exporter::package_ensure: 'latest' prometheus::mysqld_exporter::package_name: 'mysqld_exporter' prometheus::mysqld_exporter::user: 'mysqld-exporter' -prometheus::mysqld_exporter::version: '0.11.0' +prometheus::mysqld_exporter::version: '0.9.0' prometheus::mongodb_exporter::cnf_uri: 'mongodb://localhost:27017' prometheus::mongodb_exporter::download_extension: 'tar.gz' prometheus::mongodb_exporter::download_url_base: 'https://github.com/percona/mongodb_exporter/releases' diff --git a/spec/classes/mysqld_exporter_spec.rb b/spec/classes/mysqld_exporter_spec.rb index 6eee16efa..c5743a01f 100644 --- a/spec/classes/mysqld_exporter_spec.rb +++ b/spec/classes/mysqld_exporter_spec.rb @@ -9,21 +9,19 @@ 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 ') } + 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 + context 'with version >= 0.11.0' do let(:params) do { - version: '0.9.0', - arch: 'amd64', - os: 'linux' + 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 ') } + it { is_expected.to contain_prometheus__daemon('mysqld_exporter').with('options' => '--config.my-cnf=/etc/.my.cnf ') } end end end From c208457962e946447481b587c7a3854fe1be7f5b Mon Sep 17 00:00:00 2001 From: Christoph Maser Date: Mon, 20 Aug 2018 09:17:28 +0200 Subject: [PATCH 3/3] add acceptance test for mysqld_exporter --- spec/acceptance/mysqld_exporter_spec.rb | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 spec/acceptance/mysqld_exporter_spec.rb 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