Skip to content

Commit

Permalink
Add support for dogstatsd-ruby 5
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlok committed Sep 23, 2021
1 parent 7871534 commit 81a6639
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
racecar (2.3.1)
racecar (2.4.0)
king_konf (~> 1.0.0)
rdkafka (~> 0.10.0)

Expand All @@ -16,7 +16,7 @@ GEM
coderay (1.1.3)
concurrent-ruby (1.1.9)
diff-lcs (1.4.4)
dogstatsd-ruby (4.8.2)
dogstatsd-ruby (5.2.0)
ffi (1.15.4)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -56,12 +56,12 @@ PLATFORMS
DEPENDENCIES
activesupport (< 6.0)
bundler (>= 1.13, < 3)
dogstatsd-ruby (>= 4.0.0, < 5.0.0)
dogstatsd-ruby (>= 4.0.0, < 6.0.0)
pry
racecar!
rake (> 10.0)
rspec (~> 3.0)
timecop

BUNDLED WITH
2.2.15
2.2.26
6 changes: 5 additions & 1 deletion lib/racecar/datadog.rb
Expand Up @@ -63,10 +63,14 @@ def tags=(tags)
clear
end

def close
@statsd&.close
end

private

def clear
@statsd && @statsd.close
close
@statsd = nil
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/racecar/runner.rb
Expand Up @@ -92,6 +92,7 @@ def run
end
ensure
producer.close
Racecar::Datadog.close if Object.const_defined?("Racecar::Datadog")
end

def stop
Expand Down
2 changes: 1 addition & 1 deletion racecar.gemspec
Expand Up @@ -30,6 +30,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake", "> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "timecop"
spec.add_development_dependency "dogstatsd-ruby", ">= 4.0.0", "< 5.0.0"
spec.add_development_dependency "dogstatsd-ruby", ">= 4.0.0", "< 6.0.0"
spec.add_development_dependency "activesupport", ">= 4.0", "< 6.1"
end
24 changes: 24 additions & 0 deletions spec/runner_spec.rb
Expand Up @@ -699,11 +699,35 @@ def process_batch(batch, hello); end

context "#stop" do
let(:processor) { TestConsumer.new }
let(:datadog) { double("Racecar::Datadog", close: nil) }

it "allows the processor to tear down resources" do
runner.run

expect(processor.torn_down?).to eq true
end

context "when DataDog metrics are disabled" do
before do
allow(Object).to receive(:const_defined?).with("Racecar::Datadog").and_return(false)
end

it "does not close Datadog::Statsd instance" do
expect(datadog).not_to receive(:close)
runner.run
end
end

context "when DataDog metrics are enabled" do
before do
stub_const("Racecar::Datadog", datadog)
allow(Object).to receive(:const_defined?).with("Racecar::Datadog").and_return(true)
end

it "closes Datadog::Statsd instance" do
expect(datadog).to receive(:close)
runner.run
end
end
end
end

0 comments on commit 81a6639

Please sign in to comment.