From b34a31323f1a707d866b9b7bba5d4607336d7ad1 Mon Sep 17 00:00:00 2001 From: Lukas <146716912+lbdemv@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:36:32 +0200 Subject: [PATCH 1/2] Update options flag to new double dash format The nginx exporter logs the following deprecation warning after startup. ``` nginx-prometheus-exporter: the flag format is deprecated and will be removed in a future release, please use the new format: --nginx.scrape-uri ``` This PR intends to fix that deprecated format and use the current flag format with double dashes. --- manifests/nginx_prometheus_exporter.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/nginx_prometheus_exporter.pp b/manifests/nginx_prometheus_exporter.pp index 0c04e8cd..53227228 100644 --- a/manifests/nginx_prometheus_exporter.pp +++ b/manifests/nginx_prometheus_exporter.pp @@ -97,7 +97,7 @@ default => undef, } - $options = "-nginx.scrape-uri '${scrape_uri}' ${extra_options}" + $options = "--nginx.scrape-uri '${scrape_uri}' ${extra_options}" $extract_path = "/opt/${package_name}-${version}.${os}-${arch}" $archive_bin_path = "${extract_path}/${bin_name}" From be85ab31584d2f22b5baab4f44c5bc47b342db29 Mon Sep 17 00:00:00 2001 From: Lukas Baron Date: Thu, 24 Oct 2024 12:45:52 +0200 Subject: [PATCH 2/2] Update test spec to reflect new flag format in expected result --- manifests/nginx_prometheus_exporter.pp | 6 ++++- .../nginx_prometheus_exporter_spec.rb | 26 +++++++++++++------ .../classes/nginx_prometheus_exporter_spec.rb | 15 +++++++++++ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/manifests/nginx_prometheus_exporter.pp b/manifests/nginx_prometheus_exporter.pp index 53227228..9df9d499 100644 --- a/manifests/nginx_prometheus_exporter.pp +++ b/manifests/nginx_prometheus_exporter.pp @@ -97,7 +97,11 @@ default => undef, } - $options = "--nginx.scrape-uri '${scrape_uri}' ${extra_options}" + if versioncmp($version, '1.0.0') >= 0 { + $options = "--nginx.scrape-uri '${scrape_uri}' ${extra_options}" + } else { + $options = "-nginx.scrape-uri '${scrape_uri}' ${extra_options}" + } $extract_path = "/opt/${package_name}-${version}.${os}-${arch}" $archive_bin_path = "${extract_path}/${bin_name}" diff --git a/spec/acceptance/nginx_prometheus_exporter_spec.rb b/spec/acceptance/nginx_prometheus_exporter_spec.rb index 1192d1d4..cc15acb2 100644 --- a/spec/acceptance/nginx_prometheus_exporter_spec.rb +++ b/spec/acceptance/nginx_prometheus_exporter_spec.rb @@ -36,16 +36,26 @@ class { 'prometheus::nginx_prometheus_exporter': describe port(9113) do it { is_expected.to be_listening.with('tcp6') } end + # the describe process uses `ps -C` which truncates the cmd output to 15 characters on newer versions. + describe process('nginx-prometheu') do + its(:args) { is_expected.to match %r{\ -nginx.scrape-uri http://localhost:8888/stub_status} } + end + end + + describe 'update to version >= 1.0.0' do + it 'uses double-dash arguments for version >= 1.0.0' do + pp = <<-EOS + class { 'prometheus::nginx_prometheus_exporter': + scrape_uri => 'http://localhost:8888/stub_status', + version => '1.2.0', + } + EOS + apply_manifest(pp, catch_failures: true) + end - if os == 'centos-7-x86_64' - describe process('nginx-prometheus-exporter') do - its(:args) { is_expected.to match %r{\ -nginx.scrape-uri http://localhost:8888/stub_status} } - end - else - describe process('nginx-prometheu') do - its(:args) { is_expected.to match %r{\ -nginx.scrape-uri http://localhost:8888/stub_status} } - end + describe process('nginx-prometheu') do + its(:args) { is_expected.to match %r{\ --nginx.scrape-uri http://localhost:8888/stub_status} } end end end diff --git a/spec/classes/nginx_prometheus_exporter_spec.rb b/spec/classes/nginx_prometheus_exporter_spec.rb index 91dff0fd..7aa85830 100644 --- a/spec/classes/nginx_prometheus_exporter_spec.rb +++ b/spec/classes/nginx_prometheus_exporter_spec.rb @@ -70,6 +70,21 @@ it { is_expected.to contain_file('/opt/nginx-prometheus-exporter-0.11.0.linux-amd64') } end end + + context 'with version >= 1.0.0' do + let(:params) do + { + version: '1.2.0', + } + end + + it { is_expected.to contain_prometheus__daemon('nginx_prometheus_exporter').with('options' => "--nginx.scrape-uri 'http://localhost:8080/stub_status' ") } + + describe 'install correct binary' do + it { is_expected.to contain_file('/usr/local/bin/nginx-prometheus-exporter').with('target' => '/opt/nginx-prometheus-exporter-1.2.0.linux-amd64/nginx-prometheus-exporter') } + it { is_expected.to contain_file('/opt/nginx-prometheus-exporter-1.2.0.linux-amd64') } + end + end end end end