From e5a798718675b4d03d01c5c3ca13e7a32e480260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Mon, 22 Feb 2021 16:14:51 -0500 Subject: [PATCH] remove duplicate exported scrape job name in file name Between #435 and #450, the file path for the exported job names was changed to use underscores instead of colons. That's fine, except that, in the end, the actual filename had a superfluous `$scrape_job_name` parameter added. Taking the Apache exporter as an example, I used to have: /etc/prometheus/file_sd_config.d/apache_perdulce.torproject.org:9117.yaml I now have: /etc/prometheus/file_sd_config.d/apache_apache_eugeni.torproject.org_9117.yaml That still works of course: the old file is removed and the new one is picked up, but it does look silly and needlessly redundant. I should note that this might mean some clashes between jobs, if the same host/port combination is scraped by multiple jobs on the Prometheus server. I have no idea if that's a valid use case, but I should point out that, if it is, then the `job_name` parameter should just be removed and instead the resource name should forcibly include the job name, instead of enforcing this weird duplication. In other words, maybe this is also an API breaking change that should warrant a changelog entry, but I'll let my co-maintainers be the judges of this. --- manifests/daemon.pp | 2 +- spec/defines/daemon_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/manifests/daemon.pp b/manifests/daemon.pp index 1c543ce12..8642844e5 100644 --- a/manifests/daemon.pp +++ b/manifests/daemon.pp @@ -250,7 +250,7 @@ fail('must set $scrape_port on exported daemon') } - @@prometheus::scrape_job { "${scrape_job_name}_${scrape_host}_${scrape_port}": + @@prometheus::scrape_job { "${scrape_host}_${scrape_port}": job_name => $scrape_job_name, targets => ["${scrape_host}:${scrape_port}"], labels => $scrape_job_labels, diff --git a/spec/defines/daemon_spec.rb b/spec/defines/daemon_spec.rb index cb9f8f502..ec1b271f2 100644 --- a/spec/defines/daemon_spec.rb +++ b/spec/defines/daemon_spec.rb @@ -153,7 +153,7 @@ subject { exported_resources } it { - is_expected.to contain_prometheus__scrape_job('smurf_exporter_localhost_1234').with( + is_expected.to contain_prometheus__scrape_job('localhost_1234').with( 'labels' => { 'alias' => 'localhost' } @@ -185,7 +185,7 @@ subject { exported_resources } it { - is_expected.to contain_prometheus__scrape_job('smurf_exporter_localhost_1234').with( + is_expected.to contain_prometheus__scrape_job('localhost_1234').with( 'labels' => { 'instance' => 'smurf1' }