Skip to content

Commit

Permalink
Add warning for incompatible dogstastd-ruby version (#1544)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc authored Jun 7, 2021
1 parent b457fa4 commit 529b37c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/ddtrace/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
require 'set'
require 'logger'
require 'ddtrace/environment'
require 'ddtrace/utils/time'
require 'ddtrace/runtime/identity'
require 'ddtrace/utils/only_once'
require 'ddtrace/utils/time'

module Datadog
# Acts as client for sending metrics (via Statsd)
Expand Down Expand Up @@ -49,6 +50,8 @@ def default_port
def default_statsd_client
require 'datadog/statsd'

incompatible_statsd_warning

# Create a StatsD client that points to the agent.
Datadog::Statsd.new(default_hostname, default_port)
end
Expand Down Expand Up @@ -232,5 +235,21 @@ def gauge(stat, value, options = nil)
include Options
extend Options
extend Helpers

private

INCOMPATIBLE_STATSD_ONLY_ONCE = Datadog::Utils::OnlyOnce.new
private_constant :INCOMPATIBLE_STATSD_ONLY_ONCE

def incompatible_statsd_warning
return if Gem.loaded_specs['dogstatsd-ruby'].version < Gem::Version.new('5.0')

INCOMPATIBLE_STATSD_ONLY_ONCE.run do
Datadog.logger.warn(
'This version of `ddtrace` is incompatible with `dogstastd-ruby` version >= 5.0 and can ' \
'cause unbounded memory usage. Please use `dogstastd-ruby` version < 5.0 instead.'
)
end
end
end
end
29 changes: 29 additions & 0 deletions spec/ddtrace/metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
include_context 'metrics'

subject(:metrics) { described_class.new(options) }
after { metrics.close }

let(:options) { { statsd: statsd } }

Expand Down Expand Up @@ -722,6 +723,34 @@
end
end
end

describe '#incompatible_statsd_warning' do
let(:options) { {} }

before { described_class.const_get('INCOMPATIBLE_STATSD_ONLY_ONCE').send(:reset_ran_once_state_for_tests) }
after { described_class.const_get('INCOMPATIBLE_STATSD_ONLY_ONCE').send(:reset_ran_once_state_for_tests) }

context 'with an incompatible dogstastd-ruby version' do
before { skip unless Gem.loaded_specs['dogstatsd-ruby'].version >= Gem::Version.new('5.0') }

it 'emits deprecation warning once' do
expect(Datadog.logger).to receive(:warn)
.with(/This version of `ddtrace` is incompatible with `dogstastd-ruby`/).once

metrics
end
end

context 'with a compatible dogstastd-ruby version' do
before { skip unless Gem.loaded_specs['dogstatsd-ruby'].version < Gem::Version.new('5.0') }

it 'emits no warnings' do
expect(Datadog.logger).to_not receive(:warn)

metrics
end
end
end
end

RSpec.describe Datadog::Metrics::Options do
Expand Down

0 comments on commit 529b37c

Please sign in to comment.