statsd-instrument 2.9.2 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +16 -23
- data/.rubocop.yml +3 -13
- data/CHANGELOG.md +33 -0
- data/Gemfile +8 -0
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/benchmark/send-metrics-to-dev-null-log +5 -2
- data/benchmark/send-metrics-to-local-udp-receiver +8 -6
- data/bin/rake +29 -0
- data/bin/rubocop +29 -0
- data/lib/statsd/instrument.rb +80 -144
- data/lib/statsd/instrument/assertions.rb +200 -208
- data/lib/statsd/instrument/capture_sink.rb +23 -19
- data/lib/statsd/instrument/client.rb +414 -320
- data/lib/statsd/instrument/datagram.rb +69 -65
- data/lib/statsd/instrument/datagram_builder.rb +81 -77
- data/lib/statsd/instrument/dogstatsd_datagram.rb +76 -72
- data/lib/statsd/instrument/dogstatsd_datagram_builder.rb +68 -64
- data/lib/statsd/instrument/environment.rb +79 -98
- data/lib/statsd/instrument/expectation.rb +96 -96
- data/lib/statsd/instrument/helpers.rb +10 -35
- data/lib/statsd/instrument/log_sink.rb +20 -16
- data/lib/statsd/instrument/matchers.rb +86 -71
- data/lib/statsd/instrument/null_sink.rb +12 -8
- data/lib/statsd/instrument/railtie.rb +11 -11
- data/lib/statsd/instrument/statsd_datagram_builder.rb +12 -8
- data/lib/statsd/instrument/strict.rb +12 -123
- data/lib/statsd/instrument/udp_sink.rb +50 -46
- data/lib/statsd/instrument/version.rb +1 -1
- data/statsd-instrument.gemspec +2 -8
- data/test/assertions_test.rb +46 -12
- data/test/capture_sink_test.rb +8 -8
- data/test/client_test.rb +62 -51
- data/test/datagram_builder_test.rb +29 -29
- data/test/datagram_test.rb +1 -1
- data/test/dogstatsd_datagram_builder_test.rb +28 -28
- data/test/environment_test.rb +10 -46
- data/test/helpers/rubocop_helper.rb +11 -8
- data/test/helpers_test.rb +5 -5
- data/test/integration_test.rb +10 -25
- data/test/log_sink_test.rb +2 -2
- data/test/matchers_test.rb +36 -36
- data/test/null_sink_test.rb +2 -2
- data/test/rubocop/metric_return_value_test.rb +3 -3
- data/test/rubocop/metric_value_keyword_argument_test.rb +1 -1
- data/test/rubocop/positional_arguments_test.rb +10 -10
- data/test/statsd_instrumentation_test.rb +97 -122
- data/test/statsd_test.rb +50 -75
- data/test/test_helper.rb +7 -5
- data/test/udp_sink_test.rb +8 -8
- metadata +7 -125
- data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
- data/benchmark/datagram-client +0 -40
- data/lib/statsd/instrument/backend.rb +0 -18
- data/lib/statsd/instrument/backends/capture_backend.rb +0 -32
- data/lib/statsd/instrument/backends/logger_backend.rb +0 -20
- data/lib/statsd/instrument/backends/null_backend.rb +0 -9
- data/lib/statsd/instrument/backends/udp_backend.rb +0 -152
- data/lib/statsd/instrument/legacy_client.rb +0 -301
- data/lib/statsd/instrument/metric.rb +0 -155
- data/test/assertions_on_legacy_client_test.rb +0 -344
- data/test/capture_backend_test.rb +0 -26
- data/test/compatibility/dogstatsd_datagram_compatibility_test.rb +0 -161
- data/test/deprecations_test.rb +0 -139
- data/test/logger_backend_test.rb +0 -22
- data/test/metric_test.rb +0 -47
- data/test/udp_backend_test.rb +0 -228
@@ -1,62 +1,66 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
class
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
module StatsD
|
4
|
+
module Instrument
|
5
|
+
# @note This class is part of the new Client implementation that is intended
|
6
|
+
# to become the new default in the next major release of this library.
|
7
|
+
class UDPSink
|
8
|
+
def self.for_addr(addr)
|
9
|
+
host, port_as_string = addr.split(':', 2)
|
10
|
+
new(host, Integer(port_as_string))
|
11
|
+
end
|
10
12
|
|
11
|
-
|
13
|
+
attr_reader :host, :port
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def initialize(host, port)
|
16
|
+
@host = host
|
17
|
+
@port = port
|
18
|
+
@mutex = Mutex.new
|
19
|
+
@socket = nil
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
def sample?(sample_rate)
|
23
|
+
sample_rate == 1 || rand < sample_rate
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
def <<(datagram)
|
27
|
+
with_socket { |socket| socket.send(datagram, 0) > 0 }
|
28
|
+
self
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
rescue ThreadError
|
31
|
+
# In cases where a TERM or KILL signal has been sent, and we send stats as
|
32
|
+
# part of a signal handler, locks cannot be acquired, so we do our best
|
33
|
+
# to try and send the datagram without a lock.
|
34
|
+
socket.send(datagram, 0) > 0
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
rescue SocketError, IOError, SystemCallError
|
37
|
+
# TODO: log?
|
38
|
+
invalidate_socket
|
39
|
+
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
def addr
|
42
|
+
"#{host}:#{port}"
|
43
|
+
end
|
42
44
|
|
43
|
-
|
45
|
+
private
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
def with_socket
|
48
|
+
@mutex.synchronize { yield(socket) }
|
49
|
+
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
def socket
|
52
|
+
if @socket.nil?
|
53
|
+
@socket = UDPSocket.new
|
54
|
+
@socket.connect(@host, @port)
|
55
|
+
end
|
56
|
+
@socket
|
57
|
+
end
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
59
|
+
def invalidate_socket
|
60
|
+
@mutex.synchronize do
|
61
|
+
@socket = nil
|
62
|
+
end
|
63
|
+
end
|
60
64
|
end
|
61
65
|
end
|
62
66
|
end
|
data/statsd-instrument.gemspec
CHANGED
@@ -16,15 +16,9 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.license = "MIT"
|
17
17
|
|
18
18
|
spec.files = `git ls-files`.split($/)
|
19
|
-
spec.executables = spec.files.grep(%r{^
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.
|
24
|
-
spec.add_development_dependency 'minitest'
|
25
|
-
spec.add_development_dependency 'rspec'
|
26
|
-
spec.add_development_dependency 'mocha'
|
27
|
-
spec.add_development_dependency 'yard'
|
28
|
-
spec.add_development_dependency 'rubocop'
|
29
|
-
spec.add_development_dependency 'benchmark-ips'
|
23
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
30
24
|
end
|
data/test/assertions_test.rb
CHANGED
@@ -31,7 +31,7 @@ class AssertionsTest < Minitest::Test
|
|
31
31
|
StatsD.increment('counter')
|
32
32
|
end
|
33
33
|
end
|
34
|
-
assert_equal
|
34
|
+
assert_equal(assertion.message, "No StatsD calls for metric counter expected.")
|
35
35
|
|
36
36
|
@test_case.assert_no_statsd_calls('counter1', 'counter2') do
|
37
37
|
# noop
|
@@ -49,21 +49,21 @@ class AssertionsTest < Minitest::Test
|
|
49
49
|
StatsD.increment('counter3')
|
50
50
|
end
|
51
51
|
end
|
52
|
-
assert_equal
|
52
|
+
assert_equal(assertion.message, "No StatsD calls for metric counter1, counter2 expected.")
|
53
53
|
|
54
54
|
assertion = assert_raises(Minitest::Assertion) do
|
55
55
|
@test_case.assert_no_statsd_calls('counter0', 'counter1', 'counter2') do
|
56
56
|
StatsD.increment('counter1')
|
57
57
|
end
|
58
58
|
end
|
59
|
-
assert_equal
|
59
|
+
assert_equal(assertion.message, "No StatsD calls for metric counter1 expected.")
|
60
60
|
|
61
61
|
assertion = assert_raises(Minitest::Assertion) do
|
62
62
|
@test_case.assert_no_statsd_calls do
|
63
63
|
StatsD.increment('other')
|
64
64
|
end
|
65
65
|
end
|
66
|
-
assert_equal
|
66
|
+
assert_equal(assertion.message, "No StatsD calls for metric other expected.")
|
67
67
|
|
68
68
|
assertion = assert_raises(Minitest::Assertion) do
|
69
69
|
@test_case.assert_no_statsd_calls do
|
@@ -71,7 +71,7 @@ class AssertionsTest < Minitest::Test
|
|
71
71
|
StatsD.increment('another')
|
72
72
|
end
|
73
73
|
end
|
74
|
-
assert_equal
|
74
|
+
assert_equal(assertion.message, "No StatsD calls for metric other, another expected.")
|
75
75
|
end
|
76
76
|
|
77
77
|
def test_assert_statsd
|
@@ -202,8 +202,8 @@ class AssertionsTest < Minitest::Test
|
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
|
-
assert_includes
|
206
|
-
assert_includes
|
205
|
+
assert_includes(assertion.message, "Captured metrics with the same key")
|
206
|
+
assert_includes(assertion.message, "MyJob")
|
207
207
|
end
|
208
208
|
|
209
209
|
def test_capture_and_assert
|
@@ -367,7 +367,7 @@ class AssertionsTest < Minitest::Test
|
|
367
367
|
end
|
368
368
|
end
|
369
369
|
end
|
370
|
-
assert_includes
|
370
|
+
assert_includes(assertion.message, "No StatsD calls for metric counter of type c were made")
|
371
371
|
end
|
372
372
|
|
373
373
|
def test_assertion_block_with_unexpected_exceptions
|
@@ -377,7 +377,7 @@ class AssertionsTest < Minitest::Test
|
|
377
377
|
raise "unexpected"
|
378
378
|
end
|
379
379
|
end
|
380
|
-
assert_includes
|
380
|
+
assert_includes(assertion.message, "An exception occurred in the block provided to the StatsD assertion")
|
381
381
|
|
382
382
|
assertion = assert_raises(Minitest::Assertion) do
|
383
383
|
@test_case.assert_raises(RuntimeError) do
|
@@ -387,7 +387,7 @@ class AssertionsTest < Minitest::Test
|
|
387
387
|
end
|
388
388
|
end
|
389
389
|
end
|
390
|
-
assert_includes
|
390
|
+
assert_includes(assertion.message, "An exception occurred in the block provided to the StatsD assertion")
|
391
391
|
|
392
392
|
assertion = assert_raises(Minitest::Assertion) do
|
393
393
|
@test_case.assert_raises(RuntimeError) do
|
@@ -396,7 +396,7 @@ class AssertionsTest < Minitest::Test
|
|
396
396
|
end
|
397
397
|
end
|
398
398
|
end
|
399
|
-
assert_includes
|
399
|
+
assert_includes(assertion.message, "An exception occurred in the block provided to the StatsD assertion")
|
400
400
|
end
|
401
401
|
|
402
402
|
def test_assertion_block_with_other_assertion_failures
|
@@ -406,6 +406,40 @@ class AssertionsTest < Minitest::Test
|
|
406
406
|
@test_case.flunk('other assertion failure')
|
407
407
|
end
|
408
408
|
end
|
409
|
-
assert_equal
|
409
|
+
assert_equal("other assertion failure", assertion.message)
|
410
|
+
end
|
411
|
+
|
412
|
+
def test_assert_when_using_no_prefix
|
413
|
+
env = StatsD::Instrument::Environment.new('STATSD_PREFIX' => nil)
|
414
|
+
StatsD.singleton_client = StatsD::Instrument::Client.from_env(env)
|
415
|
+
|
416
|
+
@test_case.assert_statsd_increment('incr', no_prefix: false) do
|
417
|
+
StatsD.increment('incr')
|
418
|
+
end
|
419
|
+
|
420
|
+
@test_case.assert_statsd_increment('incr', no_prefix: true) do
|
421
|
+
StatsD.increment('incr')
|
422
|
+
end
|
423
|
+
|
424
|
+
env = StatsD::Instrument::Environment.new('STATSD_PREFIX' => 'prefix')
|
425
|
+
StatsD.singleton_client = StatsD::Instrument::Client.from_env(env)
|
426
|
+
|
427
|
+
@test_case.assert_statsd_increment('incr', no_prefix: false) do
|
428
|
+
StatsD.increment('incr')
|
429
|
+
end
|
430
|
+
|
431
|
+
assert_raises(Minitest::Assertion) do
|
432
|
+
@test_case.assert_statsd_increment('incr', no_prefix: true) do
|
433
|
+
StatsD.increment('incr')
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
@test_case.assert_statsd_increment('prefix.incr', no_prefix: true) do
|
438
|
+
StatsD.increment('incr')
|
439
|
+
end
|
440
|
+
|
441
|
+
@test_case.assert_statsd_increment('incr', no_prefix: true) do
|
442
|
+
StatsD.increment('incr', no_prefix: true)
|
443
|
+
end
|
410
444
|
end
|
411
445
|
end
|
data/test/capture_sink_test.rb
CHANGED
@@ -7,9 +7,9 @@ class CaptureSinkTest < Minitest::Test
|
|
7
7
|
capture_sink = StatsD::Instrument::CaptureSink.new(parent: [])
|
8
8
|
capture_sink << 'foo:1|c'
|
9
9
|
|
10
|
-
assert_equal
|
11
|
-
assert_kind_of
|
12
|
-
assert_equal
|
10
|
+
assert_equal(1, capture_sink.datagrams.length)
|
11
|
+
assert_kind_of(StatsD::Instrument::Datagram, capture_sink.datagrams.first)
|
12
|
+
assert_equal('foo:1|c', capture_sink.datagrams.first.source)
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_capture_sink_sends_datagrams_to_parent
|
@@ -17,7 +17,7 @@ class CaptureSinkTest < Minitest::Test
|
|
17
17
|
capture_sink = StatsD::Instrument::CaptureSink.new(parent: parent)
|
18
18
|
capture_sink << 'foo:1|c' << 'bar:1|c'
|
19
19
|
|
20
|
-
assert_equal
|
20
|
+
assert_equal(['foo:1|c', 'bar:1|c'], parent)
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_nesting_capture_sink_instances
|
@@ -28,15 +28,15 @@ class CaptureSinkTest < Minitest::Test
|
|
28
28
|
outer_capture_sink << 'foo:1|c'
|
29
29
|
inner_capture_sink << 'bar:1|c'
|
30
30
|
|
31
|
-
assert_equal
|
32
|
-
assert_equal
|
31
|
+
assert_equal(['foo:1|c', 'bar:1|c'], outer_capture_sink.datagrams.map(&:source))
|
32
|
+
assert_equal(['bar:1|c'], inner_capture_sink.datagrams.map(&:source))
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_using_a_different_datagram_class
|
36
36
|
sink = StatsD::Instrument::CaptureSink.new(parent: [], datagram_class: String)
|
37
37
|
sink << 'foo:1|c'
|
38
38
|
|
39
|
-
assert
|
40
|
-
assert_equal
|
39
|
+
assert(sink.datagrams.all? { |datagram| datagram.is_a?(String) })
|
40
|
+
assert_equal(['foo:1|c'], sink.datagrams)
|
41
41
|
end
|
42
42
|
end
|
data/test/client_test.rb
CHANGED
@@ -19,25 +19,25 @@ class ClientTest < Minitest::Test
|
|
19
19
|
)
|
20
20
|
client = StatsD::Instrument::Client.from_env(env)
|
21
21
|
|
22
|
-
assert_equal
|
23
|
-
assert_equal
|
24
|
-
assert_equal
|
25
|
-
assert_equal
|
22
|
+
assert_equal(0.1, client.default_sample_rate)
|
23
|
+
assert_equal('foo', client.prefix)
|
24
|
+
assert_equal(['shard:1', 'env:production'], client.default_tags)
|
25
|
+
assert_equal(StatsD::Instrument::StatsDDatagramBuilder, client.datagram_builder_class)
|
26
26
|
|
27
|
-
assert_kind_of
|
28
|
-
assert_equal
|
29
|
-
assert_equal
|
27
|
+
assert_kind_of(StatsD::Instrument::UDPSink, client.sink)
|
28
|
+
assert_equal('1.2.3.4', client.sink.host)
|
29
|
+
assert_equal(8125, client.sink.port)
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_client_from_env_has_sensible_defaults
|
33
33
|
env = StatsD::Instrument::Environment.new({})
|
34
34
|
client = StatsD::Instrument::Client.from_env(env)
|
35
35
|
|
36
|
-
assert_equal
|
37
|
-
assert_nil
|
38
|
-
assert_nil
|
39
|
-
assert_equal
|
40
|
-
assert_kind_of
|
36
|
+
assert_equal(1.0, client.default_sample_rate)
|
37
|
+
assert_nil(client.prefix)
|
38
|
+
assert_nil(client.default_tags)
|
39
|
+
assert_equal(StatsD::Instrument::DogStatsDDatagramBuilder, client.datagram_builder_class)
|
40
|
+
assert_kind_of(StatsD::Instrument::LogSink, client.sink)
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_client_from_env_with_overrides
|
@@ -51,12 +51,12 @@ class ClientTest < Minitest::Test
|
|
51
51
|
client = StatsD::Instrument::Client.from_env(env,
|
52
52
|
prefix: 'bar', implementation: 'dogstatsd', sink: StatsD::Instrument::NullSink.new)
|
53
53
|
|
54
|
-
assert_equal
|
55
|
-
assert_equal
|
56
|
-
assert_equal
|
57
|
-
assert_equal
|
54
|
+
assert_equal(0.1, client.default_sample_rate)
|
55
|
+
assert_equal('bar', client.prefix)
|
56
|
+
assert_equal(['shard:1', 'env:production'], client.default_tags)
|
57
|
+
assert_equal(StatsD::Instrument::DogStatsDDatagramBuilder, client.datagram_builder_class)
|
58
58
|
|
59
|
-
assert_kind_of
|
59
|
+
assert_kind_of(StatsD::Instrument::NullSink, client.sink)
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_capture
|
@@ -71,27 +71,27 @@ class ClientTest < Minitest::Test
|
|
71
71
|
end
|
72
72
|
@client.increment('quc')
|
73
73
|
|
74
|
-
assert_equal
|
75
|
-
assert_equal
|
74
|
+
assert_equal(['bar', 'baz'], outer_datagrams.map(&:name))
|
75
|
+
assert_equal(['baz'], inner_datagrams.map(&:name))
|
76
76
|
end
|
77
77
|
|
78
78
|
def test_metric_methods_return_truish_void
|
79
|
-
assert
|
80
|
-
assert
|
81
|
-
assert
|
82
|
-
assert
|
79
|
+
assert(@client.increment('foo'))
|
80
|
+
assert(@client.measure('bar', 122.54))
|
81
|
+
assert(@client.set('baz', 123))
|
82
|
+
assert(@client.gauge('baz', 12.3))
|
83
83
|
end
|
84
84
|
|
85
85
|
def test_increment_with_default_value
|
86
86
|
datagrams = @client.capture { @client.increment('foo') }
|
87
|
-
assert_equal
|
88
|
-
assert_equal
|
87
|
+
assert_equal(1, datagrams.size)
|
88
|
+
assert_equal('foo:1|c', datagrams.first.source)
|
89
89
|
end
|
90
90
|
|
91
91
|
def test_measure_with_value
|
92
92
|
datagrams = @client.capture { @client.measure('foo', 122.54) }
|
93
|
-
assert_equal
|
94
|
-
assert_equal
|
93
|
+
assert_equal(1, datagrams.size)
|
94
|
+
assert_equal('foo:122.54|ms', datagrams.first.source)
|
95
95
|
end
|
96
96
|
|
97
97
|
def test_measure_with_block
|
@@ -99,32 +99,32 @@ class ClientTest < Minitest::Test
|
|
99
99
|
datagrams = @client.capture do
|
100
100
|
@client.measure('foo') {}
|
101
101
|
end
|
102
|
-
assert_equal
|
103
|
-
assert_equal
|
102
|
+
assert_equal(1, datagrams.size)
|
103
|
+
assert_equal('foo:100.0|ms', datagrams.first.source)
|
104
104
|
end
|
105
105
|
|
106
106
|
def test_gauge
|
107
107
|
datagrams = @client.capture { @client.gauge('foo', 123) }
|
108
|
-
assert_equal
|
109
|
-
assert_equal
|
108
|
+
assert_equal(1, datagrams.size)
|
109
|
+
assert_equal('foo:123|g', datagrams.first.source)
|
110
110
|
end
|
111
111
|
|
112
112
|
def test_set
|
113
113
|
datagrams = @client.capture { @client.set('foo', 12345) }
|
114
|
-
assert_equal
|
115
|
-
assert_equal
|
114
|
+
assert_equal(1, datagrams.size)
|
115
|
+
assert_equal('foo:12345|s', datagrams.first.source)
|
116
116
|
end
|
117
117
|
|
118
118
|
def test_histogram
|
119
119
|
datagrams = @dogstatsd_client.capture { @dogstatsd_client.histogram('foo', 12.44) }
|
120
|
-
assert_equal
|
121
|
-
assert_equal
|
120
|
+
assert_equal(1, datagrams.size)
|
121
|
+
assert_equal('foo:12.44|h', datagrams.first.source)
|
122
122
|
end
|
123
123
|
|
124
124
|
def test_distribution_with_value
|
125
125
|
datagrams = @dogstatsd_client.capture { @dogstatsd_client.distribution('foo', 12.44) }
|
126
|
-
assert_equal
|
127
|
-
assert_equal
|
126
|
+
assert_equal(1, datagrams.size)
|
127
|
+
assert_equal('foo:12.44|d', datagrams.first.source)
|
128
128
|
end
|
129
129
|
|
130
130
|
def test_distribution_with_block
|
@@ -132,8 +132,8 @@ class ClientTest < Minitest::Test
|
|
132
132
|
datagrams = @dogstatsd_client.capture do
|
133
133
|
@dogstatsd_client.distribution('foo') {}
|
134
134
|
end
|
135
|
-
assert_equal
|
136
|
-
assert_equal
|
135
|
+
assert_equal(1, datagrams.size)
|
136
|
+
assert_equal("foo:100.0|d", datagrams.first.source)
|
137
137
|
end
|
138
138
|
|
139
139
|
def test_latency_emits_ms_metric
|
@@ -141,8 +141,8 @@ class ClientTest < Minitest::Test
|
|
141
141
|
datagrams = @client.capture do
|
142
142
|
@client.latency('foo') {}
|
143
143
|
end
|
144
|
-
assert_equal
|
145
|
-
assert_equal
|
144
|
+
assert_equal(1, datagrams.size)
|
145
|
+
assert_equal("foo:100.0|ms", datagrams.first.source)
|
146
146
|
end
|
147
147
|
|
148
148
|
def test_latency_on_dogstatsd_prefers_distribution_metric_type
|
@@ -150,8 +150,8 @@ class ClientTest < Minitest::Test
|
|
150
150
|
datagrams = @dogstatsd_client.capture do
|
151
151
|
@dogstatsd_client.latency('foo') {}
|
152
152
|
end
|
153
|
-
assert_equal
|
154
|
-
assert_equal
|
153
|
+
assert_equal(1, datagrams.size)
|
154
|
+
assert_equal("foo:100.0|d", datagrams.first.source)
|
155
155
|
end
|
156
156
|
|
157
157
|
def test_latency_calls_block_even_when_not_sending_a_sample
|
@@ -159,19 +159,19 @@ class ClientTest < Minitest::Test
|
|
159
159
|
@client.capture do
|
160
160
|
@client.latency('foo', sample_rate: 0) { called = true }
|
161
161
|
end
|
162
|
-
assert
|
162
|
+
assert(called, "The block should have been called")
|
163
163
|
end
|
164
164
|
|
165
165
|
def test_service_check
|
166
166
|
datagrams = @dogstatsd_client.capture { @dogstatsd_client.service_check('service', :ok) }
|
167
|
-
assert_equal
|
168
|
-
assert_equal
|
167
|
+
assert_equal(1, datagrams.size)
|
168
|
+
assert_equal("_sc|service|0", datagrams.first.source)
|
169
169
|
end
|
170
170
|
|
171
171
|
def test_event
|
172
172
|
datagrams = @dogstatsd_client.capture { @dogstatsd_client.event('service', "event\ndescription") }
|
173
|
-
assert_equal
|
174
|
-
assert_equal
|
173
|
+
assert_equal(1, datagrams.size)
|
174
|
+
assert_equal("_e{7,18}:service|event\\ndescription", datagrams.first.source)
|
175
175
|
end
|
176
176
|
|
177
177
|
def test_no_prefix
|
@@ -181,9 +181,20 @@ class ClientTest < Minitest::Test
|
|
181
181
|
client.increment('bar', no_prefix: true)
|
182
182
|
end
|
183
183
|
|
184
|
-
assert_equal
|
185
|
-
assert_equal
|
186
|
-
assert_equal
|
184
|
+
assert_equal(2, datagrams.size)
|
185
|
+
assert_equal("foo.bar", datagrams[0].name)
|
186
|
+
assert_equal("bar", datagrams[1].name)
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_default_tags_normalization
|
190
|
+
client = StatsD::Instrument::Client.new(default_tags: { first_tag: 'f|irst_value', second_tag: 'sec,ond_value' })
|
191
|
+
datagrams = client.capture do
|
192
|
+
client.increment('bar', tags: ['th|ird_#,tag'])
|
193
|
+
end
|
194
|
+
|
195
|
+
assert_includes(datagrams.first.tags, 'first_tag:first_value')
|
196
|
+
assert_includes(datagrams.first.tags, 'second_tag:second_value')
|
197
|
+
assert_includes(datagrams.first.tags, 'third_#tag')
|
187
198
|
end
|
188
199
|
|
189
200
|
def test_sampling
|