Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce config option to disable statsd metrics #3585

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/cloud_controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ staging:

statsd_host: "127.0.0.1"
statsd_port: 8125
enable_statsd_metrics: true

perform_blob_cleanup: false

Expand Down
1 change: 1 addition & 0 deletions lib/cloud_controller/config_schemas/base/api_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ class ApiSchema < VCAP::Config

statsd_host: String,
statsd_port: Integer,
optional(:enable_statsd_metrics) => bool,
system_hostnames: [String],
default_app_ssh_access: bool,

Expand Down
1 change: 1 addition & 0 deletions lib/cloud_controller/config_schemas/base/clock_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class ClockSchema < VCAP::Config

statsd_host: String,
statsd_port: Integer,
optional(:enable_statsd_metrics) => bool,

max_labels_per_resource: Integer,
max_annotations_per_resource: Integer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class DeploymentUpdaterSchema < VCAP::Config

statsd_host: String,
statsd_port: Integer,
optional(:enable_statsd_metrics) => bool,

max_labels_per_resource: Integer,
max_annotations_per_resource: Integer,
Expand Down
27 changes: 25 additions & 2 deletions lib/cloud_controller/dependency_locator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,13 @@ def statsd_client
if @dependencies[:statsd_client]
@dependencies[:statsd_client]
else
Statsd.logger = Steno.logger('statsd.client')
register(:statsd_client, Statsd.new(config.get(:statsd_host), config.get(:statsd_port)))
config = CloudController::DependencyLocator.instance.config
kathap marked this conversation as resolved.
Show resolved Hide resolved
if config.get(:enable_statsd_metrics) == true
kathap marked this conversation as resolved.
Show resolved Hide resolved
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
end
end

Expand Down Expand Up @@ -441,4 +446,22 @@ def create_paginated_collection_renderer(opts={})
})
end
end

class NullStatsdClient
def timing(_key, _value)
# Null implementation
end

def increment(_key)
# Null implementation
end

def gauge(_stat, _value, _sample_rate=1)
# Null implementation
end

def batch
# Null implementation
end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/config/port_8181_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ droplets:

statsd_host: "127.0.0.1"
statsd_port: 8125
enable_statsd_metrics: true

perform_blob_cleanup: false

Expand Down
35 changes: 35 additions & 0 deletions spec/unit/lib/cloud_controller/dependency_locator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,41 @@

expect(locator.statsd_client).to eq(expected_client)
end

it 'returns the null statsd client' do
kathap marked this conversation as resolved.
Show resolved Hide resolved
host = 'test-host'
port = 1234

TestConfig.override(
statsd_host: host,
kathap marked this conversation as resolved.
Show resolved Hide resolved
statsd_port: port,
enable_statsd_metrics: false
)

expected_client = double(CloudController::NullStatsdClient)

allow(CloudController::NullStatsdClient).to receive(:new).
and_return(expected_client)

expect(locator.statsd_client).to eq(expected_client)
end

it 'returns the statsd client for other than api vms' do
host = 'test-host'
port = 1234
TestConfig.context = :deployment_updater
TestConfig.override(
kathap marked this conversation as resolved.
Show resolved Hide resolved
statsd_host: host,
statsd_port: port
)

expected_client = double(Statsd)

allow(Statsd).to receive(:new).with(host, port).
and_return(expected_client)

expect(locator.statsd_client).to eq(expected_client)
end
end

describe '#bbs_stager_client' do
Expand Down