diff --git a/lib/cloud_controller/dependency_locator.rb b/lib/cloud_controller/dependency_locator.rb index e21482fd0f5..8b71dae7833 100644 --- a/lib/cloud_controller/dependency_locator.rb +++ b/lib/cloud_controller/dependency_locator.rb @@ -349,14 +349,11 @@ def registry_buddy_client def statsd_client if @dependencies[:statsd_client] @dependencies[:statsd_client] + elsif config.get(:enable_statsd_metrics) == true || config.get(:enable_statsd_metrics).nil? + Statsd.logger = Steno.logger('statsd.client') + register(:statsd_client, Statsd.new(config.get(:statsd_host), config.get(:statsd_port))) else - config = CloudController::DependencyLocator.instance.config - if config.get(:enable_statsd_metrics) == true - Statsd.logger = Steno.logger('statsd.client') - register(:statsd_client, Statsd.new(config.get(:statsd_host), config.get(:statsd_port))) - else - register(:statsd_client, NullStatsdClient.new) - end + register(:statsd_client, NullStatsdClient.new) end end diff --git a/spec/unit/lib/cloud_controller/dependency_locator_spec.rb b/spec/unit/lib/cloud_controller/dependency_locator_spec.rb index 08d0186be1f..35e3db6948b 100644 --- a/spec/unit/lib/cloud_controller/dependency_locator_spec.rb +++ b/spec/unit/lib/cloud_controller/dependency_locator_spec.rb @@ -485,13 +485,8 @@ expect(locator.statsd_client).to eq(expected_client) end - it 'returns the null statsd client' do - host = 'test-host' - port = 1234 - + it 'returns the null statsd client if enable_statsd_metrics is set to false' do TestConfig.override( - statsd_host: host, - statsd_port: port, enable_statsd_metrics: false ) @@ -509,7 +504,8 @@ TestConfig.context = :deployment_updater TestConfig.override( statsd_host: host, - statsd_port: port + statsd_port: port, + enable_statsd_metrics: nil ) expected_client = double(Statsd)