From: Tom Hughes Date: Mon, 3 Jul 2023 23:51:58 +0000 (+0100) Subject: Attach extra labels to jobs X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/88f820a038a839a687db7374235eca3003790296 Attach extra labels to jobs --- diff --git a/cookbooks/prometheus/recipes/server.rb b/cookbooks/prometheus/recipes/server.rb index ffe76117e..07a96b912 100644 --- a/cookbooks/prometheus/recipes/server.rb +++ b/cookbooks/prometheus/recipes/server.rb @@ -136,6 +136,7 @@ search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client name = exporter[:name] address = exporter[:address] sni = exporter[:sni] + labels = Array(exporter[:labels]) scrape_interval = exporter[:scrape_interval] scrape_timeout = exporter[:scrape_timeout] metric_relabel = exporter[:metric_relabel] || [] @@ -143,6 +144,7 @@ search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client name = key address = exporter sni = nil + labels = [] scrape_interval = nil scrape_timeout = nil metric_relabel = [] @@ -153,6 +155,7 @@ search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client :address => address, :sni => sni, :instance => client.name.split(".").first, + :labels => labels, :scrape_interval => scrape_interval, :scrape_timeout => scrape_timeout, :metric_relabel => metric_relabel diff --git a/cookbooks/prometheus/templates/default/prometheus.yml.erb b/cookbooks/prometheus/templates/default/prometheus.yml.erb index 922fa123b..daa10a495 100644 --- a/cookbooks/prometheus/templates/default/prometheus.yml.erb +++ b/cookbooks/prometheus/templates/default/prometheus.yml.erb @@ -72,7 +72,7 @@ scrape_configs: - "<%= target[:address] %>" labels: instance: <%= target[:instance] %> -<% Hash(target[:labels]).sort.each do |name, value| -%> +<% target[:labels].sort.each do |name, value| -%> <%= name %>: <%= value %> <% end -%> <% end -%>