From 3ff4e0c94507394aac109cec5f5f80b9750c9003 Mon Sep 17 00:00:00 2001 From: Sven Krieger <37476281+svkrieger@users.noreply.github.com> Date: Fri, 17 Nov 2023 13:00:41 +0100 Subject: [PATCH] When the flag is set to true, the prom_scraper_config.yml will be rendered empty and therefore ignored by the prom_scraper. This is useful if you want to use another scraper. --- jobs/cloud_controller_ng/spec | 4 ++ .../templates/prom_scraper_config.yml.erb | 2 + spec/cloud_controller_ng/prom_scraper_spec.rb | 37 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 spec/cloud_controller_ng/prom_scraper_spec.rb diff --git a/jobs/cloud_controller_ng/spec b/jobs/cloud_controller_ng/spec index 07d5b4f518..5d535198ca 100644 --- a/jobs/cloud_controller_ng/spec +++ b/jobs/cloud_controller_ng/spec @@ -1073,6 +1073,10 @@ properties: cc.public_tls.private_key: description: "PEM-encoded key for secure TLS communication over external endpoints" + cc.prom_scraper.disabled: + description: "When set to true, the prom_scraper job won't scrape the Cloud Controller's metrics. + Use this if you have another scraper in place and to prevent scraping metrics twice." + default: false cc.prom_scraper_tls.ca_cert: description: "PEM-encoded CA certificate for secure, mutually authenticated TLS communication with prom_scraper" cc.prom_scraper_tls.public_cert: diff --git a/jobs/cloud_controller_ng/templates/prom_scraper_config.yml.erb b/jobs/cloud_controller_ng/templates/prom_scraper_config.yml.erb index d2768cdf38..2f4b9f00fa 100644 --- a/jobs/cloud_controller_ng/templates/prom_scraper_config.yml.erb +++ b/jobs/cloud_controller_ng/templates/prom_scraper_config.yml.erb @@ -1,6 +1,8 @@ +<% if p("cc.prom_scraper.disabled") != true -%> port: <%= p("cc.prom_metrics_server_tls_port") %> source_id: "cloud_controller_ng" instance_id: <%= spec.id || spec.index.to_s %> scheme: https server_name: <%= p("cc.internal_service_hostname") %> path: /internal/v4/metrics +<% end -%> diff --git a/spec/cloud_controller_ng/prom_scraper_spec.rb b/spec/cloud_controller_ng/prom_scraper_spec.rb new file mode 100644 index 0000000000..90d9a4d8ff --- /dev/null +++ b/spec/cloud_controller_ng/prom_scraper_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'rspec' +require 'bosh/template/test' + +module Bosh + module Template + module Test + describe 'prom_scraper config template rendering' do + let(:release_path) { File.join(File.dirname(__FILE__), '../..') } + let(:release) { ReleaseDir.new(release_path) } + let(:job) { release.job('cloud_controller_ng') } + + describe 'prom_scraper_config.yml' do + let(:template) { job.template('config/prom_scraper_config.yml') } + let(:manifest_properties) { {} } + + before do + @rendered_file = template.render(manifest_properties, consumes: {}) + end + + it 'renders default values' do + expect(@rendered_file).to include('port: 9025') + end + + context 'when prom_scraper is disabled' do + let(:manifest_properties) { { 'cc' => { 'prom_scraper' => { 'disabled' => true } } } } + + it 'renders an empty file' do + expect(@rendered_file).not_to include('port: 9025') + end + end + end + end + end + end +end