Skip to content

Commit

Permalink
Merge pull request #7 from lessonnine/bug/fix-dd-client
Browse files Browse the repository at this point in the history
Fix datadog target
  • Loading branch information
Leszek Zalewski authored Dec 21, 2020
2 parents 0a8a238 + 9f2601c commit eae449b
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.3.0] - 2020-12-21
### Added
- Datadog Target integration tests

### Fixed
- Datadog Target

## [0.2.0] - 2020-12-21
### Fixed
- Removed debugging information
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ source "https://rubygems.org"
# Specify your gem's dependencies in puma-plugin-telemetry.gemspec
gemspec

gem "dogstatsd-ruby"

gem "rake", "~> 12.0"
gem "rspec", "~> 3.0"
gem "rubocop", "~> 1.5"
Expand Down
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
PATH
remote: .
specs:
puma-plugin-telemetry (0.1.0)
puma-plugin-telemetry (0.3.0)
puma (>= 5.0)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.1)
diff-lcs (1.4.4)
dogstatsd-ruby (4.8.2)
nio4r (2.5.4)
parallel (1.20.1)
parser (2.7.2.0)
Expand Down Expand Up @@ -56,6 +57,7 @@ PLATFORMS
ruby

DEPENDENCIES
dogstatsd-ruby
puma-plugin-telemetry!
rake (~> 12.0)
rspec (~> 3.0)
Expand Down
2 changes: 1 addition & 1 deletion lib/puma/plugin/telemetry/targets/datadog_statsd_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(client:)
end

def call(telemetry)
client.batch do |statsd|
@client.batch do |statsd|
telemetry.each do |metric, value|
statsd.gauge(metric, value)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puma/plugin/telemetry/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Puma
class Plugin
module Telemetry
VERSION = "0.2.0"
VERSION = "0.3.0"
end
end
end
2 changes: 1 addition & 1 deletion spec/fixtures/config.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

app { |_env| [200, {}, ["embedded app"]] }
lowlevel_error_handler { |_err| [200, {}, ["error page"]] }
lowlevel_error_handler { |_err| [500, {}, ["error page"]] }

threads 1, 1
plugin "telemetry"
Expand Down
17 changes: 17 additions & 0 deletions spec/fixtures/dogstatsd.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

app { |_env| [200, {}, ["embedded app"]] }
lowlevel_error_handler { |_err| [500, {}, ["error page"]] }

threads 1, 1
plugin "telemetry"

require "datadog/statsd"
require "logger"

Puma::Plugin::Telemetry.configure do |config|
config.add_target :dogstatsd, client: Datadog::Statsd.new(logger: Logger.new($stdout))
config.frequency = 0.2
config.enabled = true
config.initial_delay = 2
end
2 changes: 1 addition & 1 deletion spec/fixtures/puma_telemetry_subset.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

app { |_env| [200, {}, ["embedded app"]] }
lowlevel_error_handler { |_err| [200, {}, ["error page"]] }
lowlevel_error_handler { |_err| [500, {}, ["error page"]] }

threads 1, 2
workers 2
Expand Down
23 changes: 23 additions & 0 deletions spec/integration/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,29 @@ class Plugin
expect(line).to start_with expected_telemetry
end
end

context "when dogstatsd target" do
let(:config) { "dogstatsd" }
let(:expected_telemetry) do
%w[
workers.booted:1|g
workers.total:1|g
workers.spawned_threads:1|g
workers.max_threads:1|g
workers.requests_count:0|g
queue.backlog:0|g
queue.capacity:1|g
]
end

it "doesn't crash" do
true while (line = @server.next_line) !~ /DEBUG -- : Statsd/

lines = ([line.slice(/workers.*/)] + Array.new(6) { @server.next_line.strip })

expect(lines).to eq(expected_telemetry)
end
end
end
end
end

0 comments on commit eae449b

Please sign in to comment.