From 793c1098d4774a17eac2399d3ed10d4a2081a8a6 Mon Sep 17 00:00:00 2001 From: Katharina Przybill <30441792+kathap@users.noreply.github.com> Date: Fri, 5 Jan 2024 10:34:50 +0100 Subject: [PATCH] Introduce config option to disable statsd metrics This config option allows to send metrics only via prometheus --- config/cloud_controller.yml | 1 + .../config_schemas/base/api_schema.rb | 1 + .../config_schemas/base/clock_schema.rb | 1 + .../base/deployment_updater_schema.rb | 1 + lib/cloud_controller/dependency_locator.rb | 26 +++++++++++++++++++ .../deployment_updater/scheduler.rb | 6 ++++- lib/cloud_controller/diego/messenger.rb | 7 ++++- spec/fixtures/config/port_8181_config.yml | 1 + 8 files changed, 42 insertions(+), 2 deletions(-) diff --git a/config/cloud_controller.yml b/config/cloud_controller.yml index 450568e5b8f..11ddf1b838d 100644 --- a/config/cloud_controller.yml +++ b/config/cloud_controller.yml @@ -354,6 +354,7 @@ staging: statsd_host: "127.0.0.1" statsd_port: 8125 +disable_statsd_metrics: false perform_blob_cleanup: false diff --git a/lib/cloud_controller/config_schemas/base/api_schema.rb b/lib/cloud_controller/config_schemas/base/api_schema.rb index c6f96d4bf6e..a8bcf59069a 100644 --- a/lib/cloud_controller/config_schemas/base/api_schema.rb +++ b/lib/cloud_controller/config_schemas/base/api_schema.rb @@ -322,6 +322,7 @@ class ApiSchema < VCAP::Config statsd_host: String, statsd_port: Integer, + optional(:disable_statsd_metrics) => bool, system_hostnames: [String], default_app_ssh_access: bool, diff --git a/lib/cloud_controller/config_schemas/base/clock_schema.rb b/lib/cloud_controller/config_schemas/base/clock_schema.rb index 2ddac9017fb..8c6f4d5ec82 100644 --- a/lib/cloud_controller/config_schemas/base/clock_schema.rb +++ b/lib/cloud_controller/config_schemas/base/clock_schema.rb @@ -177,6 +177,7 @@ class ClockSchema < VCAP::Config statsd_host: String, statsd_port: Integer, + optional(:disable_statsd_metrics) => bool, max_labels_per_resource: Integer, max_annotations_per_resource: Integer, diff --git a/lib/cloud_controller/config_schemas/base/deployment_updater_schema.rb b/lib/cloud_controller/config_schemas/base/deployment_updater_schema.rb index 98bb1d0db8d..da1cac6b761 100644 --- a/lib/cloud_controller/config_schemas/base/deployment_updater_schema.rb +++ b/lib/cloud_controller/config_schemas/base/deployment_updater_schema.rb @@ -130,6 +130,7 @@ class DeploymentUpdaterSchema < VCAP::Config statsd_host: String, statsd_port: Integer, + optional(:disable_statsd_metrics) => bool, max_labels_per_resource: Integer, max_annotations_per_resource: Integer, diff --git a/lib/cloud_controller/dependency_locator.rb b/lib/cloud_controller/dependency_locator.rb index 6bb42db847a..6523f652f72 100644 --- a/lib/cloud_controller/dependency_locator.rb +++ b/lib/cloud_controller/dependency_locator.rb @@ -441,4 +441,30 @@ def create_paginated_collection_renderer(opts={}) }) end end + + class NullDependencyLocator + include Singleton + + def config + Struct.new + end + + def statsd_client + @statsd_client ||= NullStatsdClient.new + end + + def statsd_updater + # Null implementation + end + + class NullStatsdClient + def timing(_key, _value) + # Null implementation + end + + def increment(_key) + # Null implementation + end + end + end end diff --git a/lib/cloud_controller/deployment_updater/scheduler.rb b/lib/cloud_controller/deployment_updater/scheduler.rb index c6b2b5a1a5e..f6acc31a36f 100644 --- a/lib/cloud_controller/deployment_updater/scheduler.rb +++ b/lib/cloud_controller/deployment_updater/scheduler.rb @@ -9,7 +9,11 @@ class << self def start with_error_logging('cc.deployment_updater') do config = CloudController::DependencyLocator.instance.config - statsd_client = CloudController::DependencyLocator.instance.statsd_client + if config.get(:disable_statsd_metrics) == false + statsd_client = CloudController::DependencyLocator.instance.statsd_client + else + statsd_client = CloudController::NullDependencyLocator.instance.statsd_client + end update_step = proc { update( diff --git a/lib/cloud_controller/diego/messenger.rb b/lib/cloud_controller/diego/messenger.rb index 089d1484983..ff95c9606cc 100644 --- a/lib/cloud_controller/diego/messenger.rb +++ b/lib/cloud_controller/diego/messenger.rb @@ -58,7 +58,12 @@ def bbs_stager_client end def statsd_updater - CloudController::DependencyLocator.instance.statsd_updater + config = CloudController::DependencyLocator.instance.config + if config.get(:disable_statsd_metrics) == false + CloudController::DependencyLocator.instance.statsd_updater + else + CloudController::NullDependencyLocator.instance.statsd_updater + end end def prometheus_updater diff --git a/spec/fixtures/config/port_8181_config.yml b/spec/fixtures/config/port_8181_config.yml index ddec9eeea1c..eade372e5ee 100644 --- a/spec/fixtures/config/port_8181_config.yml +++ b/spec/fixtures/config/port_8181_config.yml @@ -206,6 +206,7 @@ droplets: statsd_host: "127.0.0.1" statsd_port: 8125 +disable_statsd_metrics: false perform_blob_cleanup: false