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

Do not use configured dogstatsd instance when it's an incompatible version #1560

Merged

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Jun 18, 2021

A customer reported the following NoMethodError:

components.rb:245:in `each': private method `close' called for  #<Datadog::Statsd:0x00007fa757896bc8> (NoMethodError)

Turns out that the customer had an incompatible dogstatsd-ruby version, but since they had their instance manually configured, rather than created by the Metrics class, our version check was being bypassed. This led the incompatible dogstatsd-ruby version to be used, and one of the incompatibilites is the fact that #close was private on that old version.

A minimal test case for this issue is:

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'

  gem 'dogstatsd-ruby', '< 3'
  gem 'ddtrace', '= 0.50.0'
end

require 'ddtrace'
require 'datadog/statsd'

Datadog.configure do |c|
  c.runtime_metrics.statsd = Datadog::Statsd.new
end

Datadog.shutdown!

To fix this issue, I've changed the #initialize method to always call #supported? before either accepting a pre-existing statsd instance, or trying to create one.

To avoid silently breaking customer-expected behavior, I've also added a warning; hopefully customers with the wrong configuration will see the warning and know that they need to upgrade dogstatsd-ruby.

NOTE: We should really look into adding a hard dependency from ddtrace to dogstatsd-ruby so that we could do away with our home-grown incompatible version checking code.

…rsion

A customer reported the following `NoMethodError`:
```
components.rb:245:in `each': private method `close' called for
 #<Datadog::Statsd:0x00007fa757896bc8> (NoMethodError)
```

Turns out that the customer had an incompatible
dogstatsd-ruby version, but since they had their instance manually
configured, rather than created by the `Metrics` class, our version
check was being bypassed. This led the incompatible dogstatsd-ruby
version to be used, and one of the incompatibilites is the fact that
`#close` was private on that old version.

A minimal test case for this issue is:

```ruby
require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'

  gem 'dogstatsd-ruby', '< 3'
  gem 'ddtrace', '= 0.50.0'
end

require 'ddtrace'
require 'datadog/statsd'

Datadog.configure do |c|
  c.runtime_metrics.statsd = Datadog::Statsd.new
end

Datadog.shutdown!
```

To fix this issue, I've changed the `#initialize` method to always
call `#supported?` before either accepting a pre-existing `statsd`
instance, or trying to create one.

To avoid silently breaking customer-expected behavior, I've also
added a warning; hopefully customers with the wrong configuration will
see the warning and know that they need to upgrade `dogstatsd-ruby`.

NOTE: We should really look into adding a hard dependency from
ddtrace to dogstatsd-ruby so that we could do away with our
home-grown incompatible version checking code.
@ivoanjo ivoanjo requested a review from a team June 18, 2021 13:46
@ivoanjo ivoanjo force-pushed the fix/disallow-using-older-statsd-when-directly-configured branch from ab0894d to 1313907 Compare June 18, 2021 14:09
@ivoanjo ivoanjo force-pushed the fix/disallow-using-older-statsd-when-directly-configured branch from 1313907 to 79e7da5 Compare June 18, 2021 14:15
@codecov-commenter
Copy link

Codecov Report

Merging #1560 (79e7da5) into master (80ead5a) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1560   +/-   ##
=======================================
  Coverage   98.23%   98.24%           
=======================================
  Files         885      885           
  Lines       42554    42594   +40     
=======================================
+ Hits        41804    41845   +41     
+ Misses        750      749    -1     
Impacted Files Coverage Δ
lib/ddtrace/configuration/components.rb 98.19% <100.00%> (ø)
lib/ddtrace/metrics.rb 95.62% <100.00%> (+0.30%) ⬆️
lib/ddtrace/runtime/metrics.rb 96.36% <100.00%> (ø)
spec/ddtrace/metrics_spec.rb 99.61% <100.00%> (+0.02%) ⬆️
spec/ddtrace/runtime/metrics_spec.rb 96.58% <100.00%> (ø)
spec/ddtrace/profiling/ext/forking_spec.rb 100.00% <0.00%> (+0.61%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 80ead5a...79e7da5. Read the comment docs.

@marcotc marcotc merged commit 98d4fa3 into master Jun 18, 2021
@marcotc marcotc deleted the fix/disallow-using-older-statsd-when-directly-configured branch June 18, 2021 18:11
@github-actions github-actions bot added this to the 0.51.0 milestone Jun 18, 2021
ivoanjo added a commit that referenced this pull request Jun 21, 2021
Leftover from #1560, I noticed that I had left a confusing description for a test group.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants