From 6e28bd5f818fe1ec8cd0d3c95e593626319a315e Mon Sep 17 00:00:00 2001 From: Alexander Nicke Date: Tue, 21 Apr 2026 15:46:16 +0200 Subject: [PATCH] Fix: stats_promex_enable default false still rendered prometheus-exporter if_p yields whenever a property has any value (including spec defaults), so the prometheus-exporter line was always emitted regardless of the property's boolean value. Switch to if p(...) to evaluate the boolean. --- jobs/haproxy/templates/haproxy.config.erb | 2 +- .../haproxy/templates/haproxy_config/stats_listener_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/jobs/haproxy/templates/haproxy.config.erb b/jobs/haproxy/templates/haproxy.config.erb index 07c14cf5..b1644a20 100644 --- a/jobs/haproxy/templates/haproxy.config.erb +++ b/jobs/haproxy/templates/haproxy.config.erb @@ -362,7 +362,7 @@ listen stats acl private src <%= p("ha_proxy.trusted_stats_cidrs") %> http-request deny unless private mode http - <%- if_p("ha_proxy.stats_promex_enable") do -%> + <%- if p("ha_proxy.stats_promex_enable") -%> http-request use-service prometheus-exporter if { path <%= p("ha_proxy.stats_promex_path") %> } <%- end -%> stats enable diff --git a/spec/haproxy/templates/haproxy_config/stats_listener_spec.rb b/spec/haproxy/templates/haproxy_config/stats_listener_spec.rb index 18caa5fa..6c0a3630 100644 --- a/spec/haproxy/templates/haproxy_config/stats_listener_spec.rb +++ b/spec/haproxy/templates/haproxy_config/stats_listener_spec.rb @@ -44,6 +44,12 @@ end end + context 'when ha_proxy.stats_promex_enable is false (default)' do + it 'does not include a prometheus exporter endpoint' do + expect(stats_listener).not_to include(a_string_including('prometheus-exporter')) + end + end + context 'when ha_proxy.trusted_stats_cidrs is set' do let(:properties) do default_properties.merge({ 'trusted_stats_cidrs' => '1.2.3.4/32' })