statsd-instrument 2.3.2 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +1 -0
- data/.github/workflows/ci.yml +31 -0
- data/.gitignore +1 -0
- data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +1027 -0
- data/.rubocop.yml +21 -0
- data/CHANGELOG.md +41 -0
- data/CONTRIBUTING.md +26 -6
- data/Gemfile +2 -0
- data/Rakefile +3 -1
- data/lib/statsd/instrument/assertions.rb +24 -18
- data/lib/statsd/instrument/backend.rb +3 -2
- data/lib/statsd/instrument/backends/capture_backend.rb +2 -1
- data/lib/statsd/instrument/backends/logger_backend.rb +3 -3
- data/lib/statsd/instrument/backends/null_backend.rb +2 -0
- data/lib/statsd/instrument/backends/udp_backend.rb +20 -17
- data/lib/statsd/instrument/environment.rb +2 -0
- data/lib/statsd/instrument/helpers.rb +6 -2
- data/lib/statsd/instrument/matchers.rb +14 -11
- data/lib/statsd/instrument/metric.rb +34 -21
- data/lib/statsd/instrument/metric_expectation.rb +32 -18
- data/lib/statsd/instrument/railtie.rb +2 -1
- data/lib/statsd/instrument/version.rb +3 -1
- data/lib/statsd/instrument.rb +85 -36
- data/lib/statsd-instrument.rb +2 -0
- data/statsd-instrument.gemspec +13 -10
- data/test/assertions_test.rb +15 -4
- data/test/benchmark/default_tags.rb +47 -0
- data/test/benchmark/metrics.rb +9 -8
- data/test/benchmark/tags.rb +5 -3
- data/test/capture_backend_test.rb +4 -2
- data/test/environment_test.rb +2 -1
- data/test/helpers_test.rb +2 -1
- data/test/integration_test.rb +27 -7
- data/test/logger_backend_test.rb +10 -8
- data/test/matchers_test.rb +34 -20
- data/test/metric_test.rb +15 -4
- data/test/statsd_instrumentation_test.rb +7 -7
- data/test/statsd_test.rb +100 -10
- data/test/test_helper.rb +2 -0
- data/test/udp_backend_test.rb +5 -28
- metadata +23 -5
- data/.travis.yml +0 -12
data/test/matchers_test.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
require 'statsd/instrument/matchers'
|
3
5
|
|
4
6
|
class MatchersTest < Minitest::Test
|
5
7
|
def test_statsd_increment_matched
|
6
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', {})
|
8
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', {})
|
9
|
+
.matches?(lambda { StatsD.increment('counter') })
|
7
10
|
end
|
8
11
|
|
9
12
|
def test_statsd_increment_not_matched
|
10
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', {})
|
13
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', {})
|
14
|
+
.matches?(lambda { StatsD.increment('not_counter') })
|
11
15
|
end
|
12
16
|
|
13
17
|
def test_statsd_increment_compound_matched
|
@@ -31,72 +35,82 @@ class MatchersTest < Minitest::Test
|
|
31
35
|
end
|
32
36
|
|
33
37
|
def test_statsd_increment_with_times_matched
|
34
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 1)
|
38
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 1)
|
39
|
+
.matches?(lambda { StatsD.increment('counter') })
|
35
40
|
end
|
36
41
|
|
37
42
|
def test_statsd_increment_with_times_not_matched
|
38
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2)
|
43
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2)
|
44
|
+
.matches?(lambda { StatsD.increment('counter', times: 3) })
|
39
45
|
end
|
40
46
|
|
41
47
|
def test_statsd_increment_with_sample_rate_matched
|
42
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: 0.5)
|
48
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: 0.5)
|
49
|
+
.matches?(lambda { StatsD.increment('counter', sample_rate: 0.5) })
|
43
50
|
end
|
44
51
|
|
45
52
|
def test_statsd_increment_with_sample_rate_not_matched
|
46
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: 0.5)
|
53
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: 0.5)
|
54
|
+
.matches?(lambda { StatsD.increment('counter', sample_rate: 0.7) })
|
47
55
|
end
|
48
56
|
|
49
57
|
def test_statsd_increment_with_value_matched
|
50
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1)
|
58
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1)
|
59
|
+
.matches?(lambda { StatsD.increment('counter') })
|
51
60
|
end
|
52
61
|
|
53
62
|
def test_statsd_increment_with_value_matched_when_multiple_metrics
|
54
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1).matches?
|
63
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1).matches?(lambda {
|
55
64
|
StatsD.increment('counter', value: 2)
|
56
65
|
StatsD.increment('counter', value: 1)
|
57
|
-
}
|
66
|
+
})
|
58
67
|
end
|
59
68
|
|
60
69
|
def test_statsd_increment_with_value_not_matched_when_multiple_metrics
|
61
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1).matches?
|
70
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1).matches?(lambda {
|
62
71
|
StatsD.increment('counter', value: 2)
|
63
72
|
StatsD.increment('counter', value: 3)
|
64
|
-
}
|
73
|
+
})
|
65
74
|
end
|
66
75
|
|
67
76
|
def test_statsd_increment_with_value_not_matched
|
68
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 3)
|
77
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 3)
|
78
|
+
.matches?(lambda { StatsD.increment('counter') })
|
69
79
|
end
|
70
80
|
|
71
81
|
def test_statsd_increment_with_tags_matched
|
72
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a', 'b'])
|
82
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a', 'b'])
|
83
|
+
.matches?(lambda { StatsD.increment('counter', tags: ['a', 'b']) })
|
73
84
|
end
|
74
85
|
|
75
86
|
def test_statsd_increment_with_tags_not_matched
|
76
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a', 'b'])
|
87
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a', 'b'])
|
88
|
+
.matches?(lambda { StatsD.increment('counter', tags: ['c']) })
|
77
89
|
end
|
78
90
|
|
79
91
|
def test_statsd_increment_with_times_and_value_matched
|
80
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2, value: 1).matches?
|
92
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2, value: 1).matches?(lambda {
|
81
93
|
StatsD.increment('counter', value: 1)
|
82
94
|
StatsD.increment('counter', value: 1)
|
83
|
-
}
|
95
|
+
})
|
84
96
|
end
|
85
97
|
|
86
98
|
def test_statsd_increment_with_times_and_value_not_matched
|
87
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2, value: 1).matches?
|
99
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2, value: 1).matches?(lambda {
|
88
100
|
StatsD.increment('counter', value: 1)
|
89
101
|
StatsD.increment('counter', value: 2)
|
90
|
-
}
|
102
|
+
})
|
91
103
|
end
|
92
104
|
|
93
105
|
def test_statsd_increment_with_sample_rate_and_argument_matcher_matched
|
94
106
|
between_matcher = RSpec::Matchers::BuiltIn::BeBetween.new(0.4, 0.6).inclusive
|
95
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: between_matcher)
|
107
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: between_matcher)
|
108
|
+
.matches?(lambda { StatsD.increment('counter', sample_rate: 0.5) })
|
96
109
|
end
|
97
110
|
|
98
111
|
def test_statsd_increment_with_sample_rate_and_argument_matcher_not_matched
|
99
112
|
between_matcher = RSpec::Matchers::BuiltIn::BeBetween.new(0.4, 0.6).inclusive
|
100
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: between_matcher)
|
113
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: between_matcher)
|
114
|
+
.matches?(lambda { StatsD.increment('counter', sample_rate: 0.7) })
|
101
115
|
end
|
102
116
|
end
|
data/test/metric_test.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class MetricTest < Minitest::Test
|
4
|
-
|
5
6
|
def test_required_arguments
|
6
7
|
assert_raises(ArgumentError) { StatsD::Instrument::Metric.new(type: :c) }
|
7
8
|
assert_raises(ArgumentError) { StatsD::Instrument::Metric.new(name: 'test') }
|
@@ -41,11 +42,21 @@ class MetricTest < Minitest::Test
|
|
41
42
|
|
42
43
|
def test_handle_bad_tags
|
43
44
|
assert_equal ['ignored'], StatsD::Instrument::Metric.normalize_tags(['igno|red'])
|
44
|
-
assert_equal ['lol::class:omg::lol'], StatsD::Instrument::Metric.normalize_tags(
|
45
|
+
assert_equal ['lol::class:omg::lol'], StatsD::Instrument::Metric.normalize_tags("lol::class" => "omg::lol")
|
45
46
|
end
|
46
47
|
|
47
48
|
def test_rewrite_tags_provided_as_hash
|
48
|
-
assert_equal ['tag:value'], StatsD::Instrument::Metric.normalize_tags(:
|
49
|
-
assert_equal ['
|
49
|
+
assert_equal ['tag:value'], StatsD::Instrument::Metric.normalize_tags(tag: 'value')
|
50
|
+
assert_equal ['tag1:v1', 'tag2:v2'], StatsD::Instrument::Metric.normalize_tags(tag1: 'v1', tag2: 'v2')
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_default_tags
|
54
|
+
StatsD.stubs(:default_tags).returns(['default_tag:default_value'])
|
55
|
+
m = StatsD::Instrument::Metric.new(type: :c, name: 'counter', tags: { tag: 'value' })
|
56
|
+
assert_equal ['tag:value', 'default_tag:default_value'], m.tags
|
57
|
+
|
58
|
+
StatsD.stubs(:default_tags).returns(['tag:value'])
|
59
|
+
m = StatsD::Instrument::Metric.new(type: :c, name: 'counter', tags: { tag: 'value' })
|
60
|
+
assert_equal ['tag:value', 'tag:value'], m.tags # we don't care about duplicates
|
50
61
|
end
|
51
62
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
module ActiveMerchant; end
|
@@ -11,7 +13,7 @@ class ActiveMerchant::Base
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def post_with_block(&block)
|
14
|
-
|
16
|
+
block.call if block_given?
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -34,7 +36,7 @@ end
|
|
34
36
|
|
35
37
|
class ActiveMerchant::UniqueGateway < ActiveMerchant::Base
|
36
38
|
def ssl_post(arg)
|
37
|
-
{:
|
39
|
+
{ success: arg }
|
38
40
|
end
|
39
41
|
|
40
42
|
def purchase(arg)
|
@@ -87,7 +89,7 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
87
89
|
end
|
88
90
|
|
89
91
|
assert_statsd_increment('ActiveMerchant.Base.post_with_block') do
|
90
|
-
assert_equal 'true',
|
92
|
+
assert_equal 'true', ActiveMerchant::Base.new.post_with_block { 'true' }
|
91
93
|
assert_equal 'false', ActiveMerchant::Base.new.post_with_block { 'false' }
|
92
94
|
end
|
93
95
|
ensure
|
@@ -265,7 +267,6 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
265
267
|
ActiveMerchant::UniqueGateway.statsd_remove_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
|
266
268
|
end
|
267
269
|
|
268
|
-
|
269
270
|
def test_statsd_distribution
|
270
271
|
ActiveMerchant::UniqueGateway.statsd_distribution :ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3
|
271
272
|
|
@@ -412,10 +413,9 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
412
413
|
private
|
413
414
|
|
414
415
|
def assert_scope(klass, method, expected_scope)
|
415
|
-
method_scope =
|
416
|
-
when klass.private_method_defined?(method)
|
416
|
+
method_scope = if klass.private_method_defined?(method)
|
417
417
|
:private
|
418
|
-
|
418
|
+
elsif klass.protected_method_defined?(method)
|
419
419
|
:protected
|
420
420
|
else
|
421
421
|
:public
|
data/test/statsd_test.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class StatsDTest < Minitest::Test
|
4
6
|
include StatsD::Instrument::Assertions
|
5
7
|
|
8
|
+
def teardown
|
9
|
+
StatsD.default_tags = nil
|
10
|
+
end
|
11
|
+
|
6
12
|
def test_statsd_passed_collections_to_backend
|
7
13
|
StatsD.backend.expects(:collect_metric).with(instance_of(StatsD::Instrument::Metric))
|
8
14
|
StatsD.increment('test')
|
@@ -18,7 +24,7 @@ class StatsDTest < Minitest::Test
|
|
18
24
|
end
|
19
25
|
|
20
26
|
def test_statsd_measure_with_explicit_value_and_distribution_override
|
21
|
-
metric = capture_statsd_call {
|
27
|
+
metric = capture_statsd_call { StatsD.measure('values.foobar', 42, as_dist: true) }
|
22
28
|
assert_equal :d, metric.type
|
23
29
|
end
|
24
30
|
|
@@ -32,7 +38,7 @@ class StatsDTest < Minitest::Test
|
|
32
38
|
end
|
33
39
|
|
34
40
|
def test_statsd_measure_with_explicit_value_keyword_and_distribution_override
|
35
|
-
metric = capture_statsd_call {
|
41
|
+
metric = capture_statsd_call { StatsD.measure('values.foobar', value: 42, as_dist: true) }
|
36
42
|
assert_equal :d, metric.type
|
37
43
|
end
|
38
44
|
|
@@ -41,12 +47,12 @@ class StatsDTest < Minitest::Test
|
|
41
47
|
end
|
42
48
|
|
43
49
|
def test_statsd_measure_with_explicit_value_and_sample_rate
|
44
|
-
metric = capture_statsd_call { StatsD.measure('values.foobar', 42, :
|
50
|
+
metric = capture_statsd_call { StatsD.measure('values.foobar', 42, sample_rate: 0.1) }
|
45
51
|
assert_equal 0.1, metric.sample_rate
|
46
52
|
end
|
47
53
|
|
48
54
|
def test_statsd_measure_with_benchmarked_block_duration
|
49
|
-
StatsD::Instrument.stubs(:
|
55
|
+
StatsD::Instrument.stubs(:current_timestamp).returns(5.0, 5.0 + 1.12)
|
50
56
|
metric = capture_statsd_call do
|
51
57
|
StatsD.measure('values.foobar') { 'foo' }
|
52
58
|
end
|
@@ -65,11 +71,44 @@ class StatsDTest < Minitest::Test
|
|
65
71
|
assert_equal 'sarah', return_value
|
66
72
|
end
|
67
73
|
|
68
|
-
def
|
74
|
+
def test_statsd_measure_as_distribution_returns_return_value_of_block_even_if_nil
|
69
75
|
return_value = StatsD.measure('values.foobar', as_dist: true) { nil }
|
70
76
|
assert_nil return_value
|
71
77
|
end
|
72
78
|
|
79
|
+
def test_statsd_measure_with_return_in_block_still_captures
|
80
|
+
StatsD::Instrument.stubs(:current_timestamp).returns(5.0, 6.12)
|
81
|
+
result = nil
|
82
|
+
metric = capture_statsd_call do
|
83
|
+
lambda = -> do
|
84
|
+
StatsD.measure('values.foobar') { return 'from lambda' }
|
85
|
+
end
|
86
|
+
|
87
|
+
result = lambda.call
|
88
|
+
end
|
89
|
+
|
90
|
+
assert_equal 'from lambda', result
|
91
|
+
assert_equal 1120.0, metric.value
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_statsd_measure_with_exception_in_block_still_captures
|
95
|
+
StatsD::Instrument.stubs(:current_timestamp).returns(5.0, 6.12)
|
96
|
+
result = nil
|
97
|
+
metric = capture_statsd_call do
|
98
|
+
lambda = -> do
|
99
|
+
StatsD.measure('values.foobar') { raise 'from lambda' }
|
100
|
+
end
|
101
|
+
|
102
|
+
begin
|
103
|
+
result = lambda.call
|
104
|
+
rescue # rubocop:disable Lint/HandleExceptions:
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
assert_nil result
|
109
|
+
assert_equal 1120.0, metric.value
|
110
|
+
end
|
111
|
+
|
73
112
|
def test_statsd_increment
|
74
113
|
result = nil
|
75
114
|
metric = capture_statsd_call { result = StatsD.increment('values.foobar', 3) }
|
@@ -80,14 +119,14 @@ class StatsDTest < Minitest::Test
|
|
80
119
|
end
|
81
120
|
|
82
121
|
def test_statsd_increment_with_hash_argument
|
83
|
-
metric = capture_statsd_call { StatsD.increment('values.foobar', :
|
122
|
+
metric = capture_statsd_call { StatsD.increment('values.foobar', tags: ['test']) }
|
84
123
|
assert_equal StatsD.default_sample_rate, metric.sample_rate
|
85
124
|
assert_equal ['test'], metric.tags
|
86
125
|
assert_equal 1, metric.value
|
87
126
|
end
|
88
127
|
|
89
128
|
def test_statsd_increment_with_value_as_keyword_argument
|
90
|
-
metric = capture_statsd_call { StatsD.increment('values.foobar', :
|
129
|
+
metric = capture_statsd_call { StatsD.increment('values.foobar', value: 2) }
|
91
130
|
assert_equal StatsD.default_sample_rate, metric.sample_rate
|
92
131
|
assert_equal 2, metric.value
|
93
132
|
end
|
@@ -149,7 +188,7 @@ class StatsDTest < Minitest::Test
|
|
149
188
|
end
|
150
189
|
|
151
190
|
def test_statsd_distribution_with_benchmarked_block_duration
|
152
|
-
StatsD::Instrument.stubs(:
|
191
|
+
StatsD::Instrument.stubs(:current_timestamp).returns(5.0, 5.0 + 1.12)
|
153
192
|
metric = capture_statsd_call do
|
154
193
|
StatsD.distribution('values.foobar') { 'foo' }
|
155
194
|
end
|
@@ -157,10 +196,45 @@ class StatsDTest < Minitest::Test
|
|
157
196
|
assert_equal 1120.0, metric.value
|
158
197
|
end
|
159
198
|
|
199
|
+
def test_statsd_distribution_with_return_in_block_still_captures
|
200
|
+
StatsD::Instrument.stubs(:current_timestamp).returns(5.0, 5.0 + 1.12)
|
201
|
+
result = nil
|
202
|
+
metric = capture_statsd_call do
|
203
|
+
lambda = -> do
|
204
|
+
StatsD.distribution('values.foobar') { return 'from lambda' }
|
205
|
+
end
|
206
|
+
|
207
|
+
result = lambda.call
|
208
|
+
end
|
209
|
+
|
210
|
+
assert_equal 'from lambda', result
|
211
|
+
assert_equal :d, metric.type
|
212
|
+
assert_equal 1120.0, metric.value
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_statsd_distribution_with_exception_in_block_still_captures
|
216
|
+
StatsD::Instrument.stubs(:current_timestamp).returns(5.0, 5.0 + 1.12)
|
217
|
+
result = nil
|
218
|
+
metric = capture_statsd_call do
|
219
|
+
lambda = -> do
|
220
|
+
StatsD.distribution('values.foobar') { raise 'from lambda' }
|
221
|
+
end
|
222
|
+
|
223
|
+
begin
|
224
|
+
result = lambda.call
|
225
|
+
rescue # rubocop:disable Lint/HandleExceptions
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
assert_nil result
|
230
|
+
assert_equal :d, metric.type
|
231
|
+
assert_equal 1120.0, metric.value
|
232
|
+
end
|
233
|
+
|
160
234
|
def test_statsd_distribution_with_block_and_options
|
161
|
-
StatsD::Instrument.stubs(:
|
235
|
+
StatsD::Instrument.stubs(:current_timestamp).returns(5.0, 5.0 + 1.12)
|
162
236
|
metric = capture_statsd_call do
|
163
|
-
StatsD.distribution('values.foobar', :
|
237
|
+
StatsD.distribution('values.foobar', tags: ['test'], sample_rate: 0.9) { 'foo' }
|
164
238
|
end
|
165
239
|
assert_equal 1120.0, metric.value
|
166
240
|
assert_equal 'values.foobar', metric.name
|
@@ -187,6 +261,22 @@ class StatsDTest < Minitest::Test
|
|
187
261
|
assert_equal 42, metric.value
|
188
262
|
end
|
189
263
|
|
264
|
+
def test_statsd_durarion_returns_time_in_seconds
|
265
|
+
duration = StatsD::Instrument.duration {}
|
266
|
+
assert_kind_of Float, duration
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_statsd_durarion_does_not_swallow_exceptions
|
270
|
+
assert_raises(RuntimeError) do
|
271
|
+
StatsD::Instrument.duration { raise "Foo" }
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_statsd_default_tags_get_normalized
|
276
|
+
StatsD.default_tags = { first_tag: 'first_value', second_tag: 'second_value' }
|
277
|
+
assert_equal ['first_tag:first_value', 'second_tag:second_value'], StatsD.default_tags
|
278
|
+
end
|
279
|
+
|
190
280
|
protected
|
191
281
|
|
192
282
|
def capture_statsd_call(&block)
|
data/test/test_helper.rb
CHANGED
data/test/udp_backend_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class UDPBackendTest < Minitest::Test
|
@@ -76,7 +78,7 @@ class UDPBackendTest < Minitest::Test
|
|
76
78
|
StatsD.histogram('fooh', 42.4)
|
77
79
|
end
|
78
80
|
|
79
|
-
|
81
|
+
def test_distribution_syntax_on_datadog
|
80
82
|
@backend.implementation = :datadog
|
81
83
|
@backend.expects(:write_packet).with('fooh:42.4|d')
|
82
84
|
StatsD.distribution('fooh', 42.4)
|
@@ -90,8 +92,8 @@ class UDPBackendTest < Minitest::Test
|
|
90
92
|
|
91
93
|
def test_event_on_datadog_escapes_newlines
|
92
94
|
@backend.implementation = :datadog
|
93
|
-
@backend.expects(:write_packet).with(
|
94
|
-
StatsD.event(
|
95
|
+
@backend.expects(:write_packet).with("_e{8,5}:fooh\\n\\n|baz\\n")
|
96
|
+
StatsD.event("fooh\n\n", "baz\n")
|
95
97
|
end
|
96
98
|
|
97
99
|
def test_event_on_datadog_ignores_invalid_metadata
|
@@ -183,31 +185,6 @@ class UDPBackendTest < Minitest::Test
|
|
183
185
|
StatsD.increment('fail')
|
184
186
|
end
|
185
187
|
|
186
|
-
def test_synchronize_in_exit_handler_handles_thread_error_and_exits_cleanly
|
187
|
-
pid = fork do
|
188
|
-
Signal.trap('TERM') do
|
189
|
-
$sent_packet = false
|
190
|
-
|
191
|
-
class << @backend.socket
|
192
|
-
def send(command, *args)
|
193
|
-
$sent_packet = true if command == 'exiting:1|c'
|
194
|
-
command.length
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
StatsD.increment('exiting')
|
199
|
-
Process.exit!($sent_packet)
|
200
|
-
end
|
201
|
-
|
202
|
-
sleep 100
|
203
|
-
end
|
204
|
-
|
205
|
-
Process.kill('TERM', pid)
|
206
|
-
Process.waitpid(pid)
|
207
|
-
|
208
|
-
assert $?.success?, 'socket did not write on exit'
|
209
|
-
end
|
210
|
-
|
211
188
|
def test_socket_error_should_invalidate_socket
|
212
189
|
seq = sequence('fail_then_succeed')
|
213
190
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statsd-instrument
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Storimer
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2019-09-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -82,6 +82,20 @@ dependencies:
|
|
82
82
|
- - ">="
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: rubocop
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
85
99
|
- !ruby/object:Gem::Dependency
|
86
100
|
name: benchmark-ips
|
87
101
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,9 +118,12 @@ executables: []
|
|
104
118
|
extensions: []
|
105
119
|
extra_rdoc_files: []
|
106
120
|
files:
|
121
|
+
- ".github/CODEOWNERS"
|
107
122
|
- ".github/probots.yml"
|
123
|
+
- ".github/workflows/ci.yml"
|
108
124
|
- ".gitignore"
|
109
|
-
- ".
|
125
|
+
- ".rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml"
|
126
|
+
- ".rubocop.yml"
|
110
127
|
- CHANGELOG.md
|
111
128
|
- CONTRIBUTING.md
|
112
129
|
- Gemfile
|
@@ -131,6 +148,7 @@ files:
|
|
131
148
|
- shipit.rubygems.yml
|
132
149
|
- statsd-instrument.gemspec
|
133
150
|
- test/assertions_test.rb
|
151
|
+
- test/benchmark/default_tags.rb
|
134
152
|
- test/benchmark/metrics.rb
|
135
153
|
- test/benchmark/tags.rb
|
136
154
|
- test/capture_backend_test.rb
|
@@ -163,13 +181,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
181
|
- !ruby/object:Gem::Version
|
164
182
|
version: '0'
|
165
183
|
requirements: []
|
166
|
-
|
167
|
-
rubygems_version: 2.7.6
|
184
|
+
rubygems_version: 3.0.3
|
168
185
|
signing_key:
|
169
186
|
specification_version: 4
|
170
187
|
summary: A StatsD client for Ruby apps
|
171
188
|
test_files:
|
172
189
|
- test/assertions_test.rb
|
190
|
+
- test/benchmark/default_tags.rb
|
173
191
|
- test/benchmark/metrics.rb
|
174
192
|
- test/benchmark/tags.rb
|
175
193
|
- test/capture_backend_test.rb
|