Skip to content

Commit 9fd61ef

Browse files
committed
Replace statsd-client with dogstatsd-ruby
statsd-ruby has not been released in 5+ years and the repo is archived. dogstatsd-ruby is well maintained and gets regular releases.
1 parent d23b502 commit 9fd61ef

17 files changed

Lines changed: 55 additions & 22 deletions

File tree

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ gem 'clockwork', require: false
66
gem 'cloudfront-signer'
77
gem 'concurrent-ruby'
88
gem 'digest-xxhash'
9+
gem 'dogstatsd-ruby', '~> 5.7'
910
gem 'fluent-logger'
1011
gem 'googleapis-common-protos', '>= 1.8.0'
1112
gem 'hashdiff'
@@ -29,7 +30,6 @@ gem 'sequel', '~> 5.106'
2930
gem 'sequel_pg', require: 'sequel'
3031
gem 'sinatra', '~> 4.2'
3132
gem 'sinatra-contrib'
32-
gem 'statsd-ruby', '~> 1.5.0'
3333
gem 'talentbox-delayed_job_sequel', '~> 4.4.0'
3434
gem 'uri', '~> 1.1'
3535
gem 'vmstat', '~> 2.3'

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ GEM
7777
diff-lcs (1.6.2)
7878
digest-xxhash (0.2.9)
7979
docile (1.1.5)
80+
dogstatsd-ruby (5.7.1)
8081
drb (2.2.3)
8182
erb (6.0.4)
8283
erubi (1.13.1)
@@ -431,7 +432,6 @@ GEM
431432
spring (4.7.0)
432433
spring-commands-rspec (1.0.4)
433434
spring (>= 0.9.1)
434-
statsd-ruby (1.5.0)
435435
stringio (3.2.0)
436436
talentbox-delayed_job_sequel (4.4.0)
437437
delayed_job (~> 4.1)
@@ -479,6 +479,7 @@ DEPENDENCIES
479479
concurrent-ruby
480480
debug (~> 1.11)
481481
digest-xxhash
482+
dogstatsd-ruby (~> 5.7)
482483
factory_bot (~> 6.5)
483484
fluent-logger
484485
fog-aws
@@ -532,7 +533,6 @@ DEPENDENCIES
532533
solargraph
533534
spring
534535
spring-commands-rspec
535-
statsd-ruby (~> 1.5.0)
536536
talentbox-delayed_job_sequel (~> 4.4.0)
537537
timecop
538538
uri (~> 1.1)

app/jobs/diego/sync.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'cloud_controller/diego/processes_sync'
22
require 'cloud_controller/diego/tasks_sync'
3-
require 'statsd'
3+
require 'cloud_controller/metrics/statsd_client_adapter'
44

55
module VCAP::CloudController
66
module Jobs

lib/cloud_controller/dependency_locator.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
require 'cloud_controller/packager/local_bits_packer'
2525
require 'credhub/client'
2626
require 'cloud_controller/metrics/prometheus_updater'
27+
require 'cloud_controller/metrics/statsd_client_adapter'
2728
require 'cloud_controller/execution_context'
2829

2930
module CloudController
@@ -367,8 +368,8 @@ def statsd_client
367368
if @dependencies[:statsd_client]
368369
@dependencies[:statsd_client]
369370
elsif config.get(:enable_statsd_metrics) == true || config.get(:enable_statsd_metrics).nil?
370-
Statsd.logger = Steno.logger('statsd.client')
371-
register(:statsd_client, Statsd.new(config.get(:statsd_host), config.get(:statsd_port)))
371+
statsd = Datadog::Statsd.new(config.get(:statsd_host), config.get(:statsd_port))
372+
register(:statsd_client, VCAP::CloudController::Metrics::StatsdClientAdapter.new(statsd))
372373
else
373374
register(:statsd_client, NullStatsdClient.new)
374375
end
@@ -472,6 +473,10 @@ def increment(_key)
472473
# Null implementation
473474
end
474475

476+
def decrement(_key)
477+
# Null implementation
478+
end
479+
475480
def gauge(_stat, _value, _sample_rate=1)
476481
# Null implementation
477482
end

lib/cloud_controller/metrics/request_metrics.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'statsd'
1+
require 'cloud_controller/metrics/statsd_client_adapter'
22

33
module VCAP::CloudController
44
module Metrics
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'datadog/statsd'
2+
require 'forwardable'
3+
4+
module VCAP::CloudController::Metrics
5+
# Adapts a Datadog::Statsd (dogstatsd-ruby v5) client to the small surface that
6+
# StatsdUpdater relies on. dogstatsd-ruby dropped the block-yielding `batch` method
7+
# that statsd-ruby offered; v5 buffers metrics internally instead. This adapter
8+
# restores `batch` by yielding itself and flushing synchronously afterwards, so the
9+
# emitted wire format and grouping behaviour stay unchanged.
10+
class StatsdClientAdapter
11+
extend Forwardable
12+
13+
def_delegators :@statsd, :gauge, :increment, :decrement, :timing
14+
15+
def initialize(statsd)
16+
@statsd = statsd
17+
end
18+
19+
def batch
20+
yield self
21+
@statsd.flush(sync: true)
22+
end
23+
end
24+
end

lib/cloud_controller/metrics/statsd_updater.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'statsd'
1+
require 'cloud_controller/metrics/statsd_client_adapter'
22

33
module VCAP::CloudController::Metrics
44
class StatsdUpdater

spec/unit/controllers/base/base_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module VCAP::CloudController
99
let(:config) { double(Config, get: nil) }
1010
let(:dependencies) do
1111
{
12-
statsd_client: double(Statsd)
12+
statsd_client: double(VCAP::CloudController::Metrics::StatsdClientAdapter)
1313
}
1414
end
1515

spec/unit/controllers/base/model_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module VCAP::CloudController
88
{
99
object_renderer: nil,
1010
collection_renderer: nil,
11-
statsd_client: double(Statsd)
11+
statsd_client: double(VCAP::CloudController::Metrics::StatsdClientAdapter)
1212
}
1313
end
1414
let(:config) { double(Config, get: nil) }

spec/unit/controllers/internal/log_access_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module VCAP::CloudController
2020
{},
2121
nil,
2222
{
23-
statsd_client: double(Statsd)
23+
statsd_client: double(VCAP::CloudController::Metrics::StatsdClientAdapter)
2424
}
2525
)
2626
end

0 commit comments

Comments
 (0)