statsd-instrument 3.0.0 → 3.0.1
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/workflows/ci.yml +3 -3
- data/.rubocop.yml +3 -13
- data/CHANGELOG.md +6 -0
- data/Gemfile +8 -0
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/bin/rake +29 -0
- data/bin/rubocop +29 -0
- data/lib/statsd/instrument.rb +4 -1
- data/lib/statsd/instrument/assertions.rb +200 -196
- data/lib/statsd/instrument/capture_sink.rb +23 -19
- data/lib/statsd/instrument/client.rb +414 -410
- 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 +80 -77
- data/lib/statsd/instrument/expectation.rb +96 -92
- data/lib/statsd/instrument/helpers.rb +11 -7
- data/lib/statsd/instrument/log_sink.rb +20 -16
- data/lib/statsd/instrument/matchers.rb +86 -70
- data/lib/statsd/instrument/null_sink.rb +12 -8
- data/lib/statsd/instrument/railtie.rb +11 -7
- data/lib/statsd/instrument/statsd_datagram_builder.rb +12 -8
- 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 +12 -12
- data/test/capture_sink_test.rb +8 -8
- data/test/client_test.rb +54 -54
- 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 +9 -9
- data/test/helpers/rubocop_helper.rb +9 -6
- data/test/helpers_test.rb +5 -5
- data/test/integration_test.rb +1 -1
- 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/positional_arguments_test.rb +10 -10
- data/test/statsd_instrumentation_test.rb +66 -66
- data/test/statsd_test.rb +44 -44
- data/test/test_helper.rb +6 -4
- data/test/udp_sink_test.rb +8 -8
- metadata +7 -103
- data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
@@ -73,18 +73,18 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
73
73
|
include StatsD::Instrument::Assertions
|
74
74
|
|
75
75
|
def test_statsd_count_if
|
76
|
-
ActiveMerchant::Gateway.statsd_count_if
|
76
|
+
ActiveMerchant::Gateway.statsd_count_if(:ssl_post, 'ActiveMerchant.Gateway.if')
|
77
77
|
|
78
78
|
assert_statsd_increment('ActiveMerchant.Gateway.if') do
|
79
79
|
ActiveMerchant::Gateway.new.purchase(true)
|
80
80
|
ActiveMerchant::Gateway.new.purchase(false)
|
81
81
|
end
|
82
82
|
ensure
|
83
|
-
ActiveMerchant::Gateway.statsd_remove_count_if
|
83
|
+
ActiveMerchant::Gateway.statsd_remove_count_if(:ssl_post, 'ActiveMerchant.Gateway.if')
|
84
84
|
end
|
85
85
|
|
86
86
|
def test_statsd_count_if_with_method_receiving_block
|
87
|
-
ActiveMerchant::Base.statsd_count_if
|
87
|
+
ActiveMerchant::Base.statsd_count_if(:post_with_block, 'ActiveMerchant.Base.post_with_block') do |result|
|
88
88
|
result == 'true'
|
89
89
|
end
|
90
90
|
|
@@ -93,11 +93,11 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
93
93
|
assert_equal 'false', ActiveMerchant::Base.new.post_with_block { 'false' }
|
94
94
|
end
|
95
95
|
ensure
|
96
|
-
ActiveMerchant::Base.statsd_remove_count_if
|
96
|
+
ActiveMerchant::Base.statsd_remove_count_if(:post_with_block, 'ActiveMerchant.Base.post_with_block')
|
97
97
|
end
|
98
98
|
|
99
99
|
def test_statsd_count_if_with_block
|
100
|
-
ActiveMerchant::UniqueGateway.statsd_count_if
|
100
|
+
ActiveMerchant::UniqueGateway.statsd_count_if(:ssl_post, 'ActiveMerchant.Gateway.block') do |result|
|
101
101
|
result[:success]
|
102
102
|
end
|
103
103
|
|
@@ -106,11 +106,11 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
106
106
|
ActiveMerchant::UniqueGateway.new.purchase(false)
|
107
107
|
end
|
108
108
|
ensure
|
109
|
-
ActiveMerchant::UniqueGateway.statsd_remove_count_if
|
109
|
+
ActiveMerchant::UniqueGateway.statsd_remove_count_if(:ssl_post, 'ActiveMerchant.Gateway.block')
|
110
110
|
end
|
111
111
|
|
112
112
|
def test_statsd_count_success
|
113
|
-
ActiveMerchant::Gateway.statsd_count_success
|
113
|
+
ActiveMerchant::Gateway.statsd_count_success(:ssl_post, 'ActiveMerchant.Gateway', sample_rate: 0.5)
|
114
114
|
|
115
115
|
assert_statsd_increment('ActiveMerchant.Gateway.success', sample_rate: 0.5, times: 1) do
|
116
116
|
ActiveMerchant::Gateway.new.purchase(true)
|
@@ -122,11 +122,11 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
122
122
|
ActiveMerchant::Gateway.new.purchase(true)
|
123
123
|
end
|
124
124
|
ensure
|
125
|
-
ActiveMerchant::Gateway.statsd_remove_count_success
|
125
|
+
ActiveMerchant::Gateway.statsd_remove_count_success(:ssl_post, 'ActiveMerchant.Gateway')
|
126
126
|
end
|
127
127
|
|
128
128
|
def test_statsd_count_success_with_method_receiving_block
|
129
|
-
ActiveMerchant::Base.statsd_count_success
|
129
|
+
ActiveMerchant::Base.statsd_count_success(:post_with_block, 'ActiveMerchant.Base.post_with_block') do |result|
|
130
130
|
result == 'successful'
|
131
131
|
end
|
132
132
|
|
@@ -140,11 +140,11 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
140
140
|
assert_equal 'not so successful', ActiveMerchant::Base.new.post_with_block { 'not so successful' }
|
141
141
|
end
|
142
142
|
ensure
|
143
|
-
ActiveMerchant::Base.statsd_remove_count_success
|
143
|
+
ActiveMerchant::Base.statsd_remove_count_success(:post_with_block, 'ActiveMerchant.Base.post_with_block')
|
144
144
|
end
|
145
145
|
|
146
146
|
def test_statsd_count_success_with_block
|
147
|
-
ActiveMerchant::UniqueGateway.statsd_count_success
|
147
|
+
ActiveMerchant::UniqueGateway.statsd_count_success(:ssl_post, 'ActiveMerchant.Gateway') do |result|
|
148
148
|
result[:success]
|
149
149
|
end
|
150
150
|
|
@@ -156,17 +156,17 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
156
156
|
ActiveMerchant::UniqueGateway.new.purchase(false)
|
157
157
|
end
|
158
158
|
ensure
|
159
|
-
ActiveMerchant::UniqueGateway.statsd_remove_count_success
|
159
|
+
ActiveMerchant::UniqueGateway.statsd_remove_count_success(:ssl_post, 'ActiveMerchant.Gateway')
|
160
160
|
end
|
161
161
|
|
162
162
|
def test_statsd_count
|
163
|
-
ActiveMerchant::Gateway.statsd_count
|
163
|
+
ActiveMerchant::Gateway.statsd_count(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
|
164
164
|
|
165
165
|
assert_statsd_increment('ActiveMerchant.Gateway.ssl_post') do
|
166
166
|
ActiveMerchant::Gateway.new.purchase(true)
|
167
167
|
end
|
168
168
|
ensure
|
169
|
-
ActiveMerchant::Gateway.statsd_remove_count
|
169
|
+
ActiveMerchant::Gateway.statsd_remove_count(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
|
170
170
|
end
|
171
171
|
|
172
172
|
def test_statsd_count_with_name_as_lambda
|
@@ -192,33 +192,33 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
192
192
|
end
|
193
193
|
|
194
194
|
def test_statsd_count_with_method_receiving_block
|
195
|
-
ActiveMerchant::Base.statsd_count
|
195
|
+
ActiveMerchant::Base.statsd_count(:post_with_block, 'ActiveMerchant.Base.post_with_block')
|
196
196
|
|
197
197
|
assert_statsd_increment('ActiveMerchant.Base.post_with_block') do
|
198
198
|
assert_equal 'block called', ActiveMerchant::Base.new.post_with_block { 'block called' }
|
199
199
|
end
|
200
200
|
ensure
|
201
|
-
ActiveMerchant::Base.statsd_remove_count
|
201
|
+
ActiveMerchant::Base.statsd_remove_count(:post_with_block, 'ActiveMerchant.Base.post_with_block')
|
202
202
|
end
|
203
203
|
|
204
204
|
def test_statsd_measure
|
205
|
-
ActiveMerchant::UniqueGateway.statsd_measure
|
205
|
+
ActiveMerchant::UniqueGateway.statsd_measure(:ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3)
|
206
206
|
|
207
207
|
assert_statsd_measure('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3) do
|
208
208
|
ActiveMerchant::UniqueGateway.new.purchase(true)
|
209
209
|
end
|
210
210
|
ensure
|
211
|
-
ActiveMerchant::UniqueGateway.statsd_remove_measure
|
211
|
+
ActiveMerchant::UniqueGateway.statsd_remove_measure(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
|
212
212
|
end
|
213
213
|
|
214
214
|
def test_statsd_measure_uses_normalized_metric_name
|
215
|
-
ActiveMerchant::UniqueGateway.statsd_measure
|
215
|
+
ActiveMerchant::UniqueGateway.statsd_measure(:ssl_post, 'ActiveMerchant::Gateway.ssl_post')
|
216
216
|
|
217
217
|
assert_statsd_measure('ActiveMerchant.Gateway.ssl_post') do
|
218
218
|
ActiveMerchant::UniqueGateway.new.purchase(true)
|
219
219
|
end
|
220
220
|
ensure
|
221
|
-
ActiveMerchant::UniqueGateway.statsd_remove_measure
|
221
|
+
ActiveMerchant::UniqueGateway.statsd_remove_measure(:ssl_post, 'ActiveMerchant::Gateway.ssl_post')
|
222
222
|
end
|
223
223
|
|
224
224
|
def test_statsd_measure_raises_without_a_provided_block
|
@@ -228,43 +228,43 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
228
228
|
end
|
229
229
|
|
230
230
|
def test_statsd_measure_with_method_receiving_block
|
231
|
-
ActiveMerchant::Base.statsd_measure
|
231
|
+
ActiveMerchant::Base.statsd_measure(:post_with_block, 'ActiveMerchant.Base.post_with_block')
|
232
232
|
|
233
233
|
assert_statsd_measure('ActiveMerchant.Base.post_with_block') do
|
234
234
|
assert_equal 'block called', ActiveMerchant::Base.new.post_with_block { 'block called' }
|
235
235
|
end
|
236
236
|
ensure
|
237
|
-
ActiveMerchant::Base.statsd_remove_measure
|
237
|
+
ActiveMerchant::Base.statsd_remove_measure(:post_with_block, 'ActiveMerchant.Base.post_with_block')
|
238
238
|
end
|
239
239
|
|
240
240
|
def test_statsd_measure_with_sample_rate
|
241
|
-
ActiveMerchant::UniqueGateway.statsd_measure
|
241
|
+
ActiveMerchant::UniqueGateway.statsd_measure(:ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1)
|
242
242
|
|
243
243
|
assert_statsd_measure('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1) do
|
244
244
|
ActiveMerchant::UniqueGateway.new.purchase(true)
|
245
245
|
end
|
246
246
|
ensure
|
247
|
-
ActiveMerchant::UniqueGateway.statsd_remove_measure
|
247
|
+
ActiveMerchant::UniqueGateway.statsd_remove_measure(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
|
248
248
|
end
|
249
249
|
|
250
250
|
def test_statsd_distribution
|
251
|
-
ActiveMerchant::UniqueGateway.statsd_distribution
|
251
|
+
ActiveMerchant::UniqueGateway.statsd_distribution(:ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3)
|
252
252
|
|
253
253
|
assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3) do
|
254
254
|
ActiveMerchant::UniqueGateway.new.purchase(true)
|
255
255
|
end
|
256
256
|
ensure
|
257
|
-
ActiveMerchant::UniqueGateway.statsd_remove_distribution
|
257
|
+
ActiveMerchant::UniqueGateway.statsd_remove_distribution(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
|
258
258
|
end
|
259
259
|
|
260
260
|
def test_statsd_distribution_uses_normalized_metric_name
|
261
|
-
ActiveMerchant::UniqueGateway.statsd_distribution
|
261
|
+
ActiveMerchant::UniqueGateway.statsd_distribution(:ssl_post, 'ActiveMerchant::Gateway.ssl_post')
|
262
262
|
|
263
263
|
assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post') do
|
264
264
|
ActiveMerchant::UniqueGateway.new.purchase(true)
|
265
265
|
end
|
266
266
|
ensure
|
267
|
-
ActiveMerchant::UniqueGateway.statsd_remove_distribution
|
267
|
+
ActiveMerchant::UniqueGateway.statsd_remove_distribution(:ssl_post, 'ActiveMerchant::Gateway.ssl_post')
|
268
268
|
end
|
269
269
|
|
270
270
|
def test_statsd_distribution_raises_without_a_provided_block
|
@@ -274,71 +274,71 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
274
274
|
end
|
275
275
|
|
276
276
|
def test_statsd_distribution_with_method_receiving_block
|
277
|
-
ActiveMerchant::Base.statsd_distribution
|
277
|
+
ActiveMerchant::Base.statsd_distribution(:post_with_block, 'ActiveMerchant.Base.post_with_block')
|
278
278
|
|
279
279
|
assert_statsd_distribution('ActiveMerchant.Base.post_with_block') do
|
280
280
|
assert_equal 'block called', ActiveMerchant::Base.new.post_with_block { 'block called' }
|
281
281
|
end
|
282
282
|
ensure
|
283
|
-
ActiveMerchant::Base.statsd_remove_distribution
|
283
|
+
ActiveMerchant::Base.statsd_remove_distribution(:post_with_block, 'ActiveMerchant.Base.post_with_block')
|
284
284
|
end
|
285
285
|
|
286
286
|
def test_statsd_distribution_with_tags
|
287
|
-
ActiveMerchant::UniqueGateway.statsd_distribution
|
287
|
+
ActiveMerchant::UniqueGateway.statsd_distribution(:ssl_post, 'ActiveMerchant.Gateway.ssl_post', tags: ['foo'])
|
288
288
|
|
289
289
|
assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post', tags: ['foo']) do
|
290
290
|
ActiveMerchant::UniqueGateway.new.purchase(true)
|
291
291
|
end
|
292
292
|
ensure
|
293
|
-
ActiveMerchant::UniqueGateway.statsd_remove_distribution
|
293
|
+
ActiveMerchant::UniqueGateway.statsd_remove_distribution(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
|
294
294
|
end
|
295
295
|
|
296
296
|
def test_statsd_distribution_with_sample_rate
|
297
|
-
ActiveMerchant::UniqueGateway.statsd_distribution
|
297
|
+
ActiveMerchant::UniqueGateway.statsd_distribution(:ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1)
|
298
298
|
|
299
299
|
assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1) do
|
300
300
|
ActiveMerchant::UniqueGateway.new.purchase(true)
|
301
301
|
end
|
302
302
|
ensure
|
303
|
-
ActiveMerchant::UniqueGateway.statsd_remove_distribution
|
303
|
+
ActiveMerchant::UniqueGateway.statsd_remove_distribution(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
|
304
304
|
end
|
305
305
|
|
306
306
|
def test_instrumenting_class_method
|
307
|
-
ActiveMerchant::Gateway.singleton_class.extend
|
308
|
-
ActiveMerchant::Gateway.singleton_class.statsd_count
|
307
|
+
ActiveMerchant::Gateway.singleton_class.extend(StatsD::Instrument)
|
308
|
+
ActiveMerchant::Gateway.singleton_class.statsd_count(:sync, 'ActiveMerchant.Gateway.sync')
|
309
309
|
|
310
310
|
assert_statsd_increment('ActiveMerchant.Gateway.sync') do
|
311
311
|
ActiveMerchant::Gateway.sync
|
312
312
|
end
|
313
313
|
ensure
|
314
|
-
ActiveMerchant::Gateway.singleton_class.statsd_remove_count
|
314
|
+
ActiveMerchant::Gateway.singleton_class.statsd_remove_count(:sync, 'ActiveMerchant.Gateway.sync')
|
315
315
|
end
|
316
316
|
|
317
317
|
def test_statsd_count_with_tags
|
318
|
-
ActiveMerchant::Gateway.singleton_class.extend
|
319
|
-
ActiveMerchant::Gateway.singleton_class.statsd_count
|
318
|
+
ActiveMerchant::Gateway.singleton_class.extend(StatsD::Instrument)
|
319
|
+
ActiveMerchant::Gateway.singleton_class.statsd_count(:sync, 'ActiveMerchant.Gateway.sync', tags: { key: 'value' })
|
320
320
|
|
321
321
|
assert_statsd_increment('ActiveMerchant.Gateway.sync', tags: ['key:value']) do
|
322
322
|
ActiveMerchant::Gateway.sync
|
323
323
|
end
|
324
324
|
ensure
|
325
|
-
ActiveMerchant::Gateway.singleton_class.statsd_remove_count
|
325
|
+
ActiveMerchant::Gateway.singleton_class.statsd_remove_count(:sync, 'ActiveMerchant.Gateway.sync')
|
326
326
|
end
|
327
327
|
|
328
328
|
def test_statsd_respects_global_prefix_changes
|
329
329
|
old_client = StatsD.singleton_client
|
330
330
|
|
331
331
|
StatsD.singleton_client = StatsD::Instrument::Client.new(prefix: 'Foo')
|
332
|
-
ActiveMerchant::Gateway.singleton_class.extend
|
333
|
-
ActiveMerchant::Gateway.singleton_class.statsd_count
|
332
|
+
ActiveMerchant::Gateway.singleton_class.extend(StatsD::Instrument)
|
333
|
+
ActiveMerchant::Gateway.singleton_class.statsd_count(:sync, 'ActiveMerchant.Gateway.sync')
|
334
334
|
StatsD.singleton_client = StatsD::Instrument::Client.new(prefix: 'Quc')
|
335
335
|
|
336
336
|
datagrams = capture_statsd_calls { ActiveMerchant::Gateway.sync }
|
337
|
-
assert_equal
|
338
|
-
assert_equal
|
337
|
+
assert_equal(1, datagrams.length)
|
338
|
+
assert_equal("Quc.ActiveMerchant.Gateway.sync", datagrams.first.name)
|
339
339
|
ensure
|
340
340
|
StatsD.singleton_client = old_client
|
341
|
-
ActiveMerchant::Gateway.singleton_class.statsd_remove_count
|
341
|
+
ActiveMerchant::Gateway.singleton_class.statsd_remove_count(:sync, 'ActiveMerchant.Gateway.sync')
|
342
342
|
end
|
343
343
|
|
344
344
|
def test_statsd_count_with_injected_client
|
@@ -349,24 +349,24 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
349
349
|
ActiveMerchant::Gateway.new.purchase(true)
|
350
350
|
end
|
351
351
|
ensure
|
352
|
-
ActiveMerchant::Gateway.statsd_remove_count
|
352
|
+
ActiveMerchant::Gateway.statsd_remove_count(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
|
353
353
|
end
|
354
354
|
|
355
355
|
def test_statsd_macro_can_disable_prefix
|
356
356
|
client = StatsD::Instrument::Client.new(prefix: 'foo')
|
357
|
-
ActiveMerchant::Gateway.singleton_class.extend
|
357
|
+
ActiveMerchant::Gateway.singleton_class.extend(StatsD::Instrument)
|
358
358
|
ActiveMerchant::Gateway.singleton_class.statsd_count_success(:sync,
|
359
359
|
'ActiveMerchant.Gateway.sync', no_prefix: true, client: client)
|
360
360
|
|
361
361
|
datagrams = client.capture { ActiveMerchant::Gateway.sync }
|
362
|
-
assert_equal
|
363
|
-
assert_equal
|
362
|
+
assert_equal(1, datagrams.length)
|
363
|
+
assert_equal("ActiveMerchant.Gateway.sync.success", datagrams.first.name)
|
364
364
|
ensure
|
365
|
-
ActiveMerchant::Gateway.singleton_class.statsd_remove_count_success
|
365
|
+
ActiveMerchant::Gateway.singleton_class.statsd_remove_count_success(:sync, 'ActiveMerchant.Gateway.sync')
|
366
366
|
end
|
367
367
|
|
368
368
|
def test_statsd_doesnt_change_method_scope_of_public_method
|
369
|
-
assert_scope
|
369
|
+
assert_scope(InstrumentedClass, :public_and_instrumented, :public)
|
370
370
|
|
371
371
|
assert_statsd_increment('InstrumentedClass.public_and_instrumented') do
|
372
372
|
InstrumentedClass.new.send(:public_and_instrumented)
|
@@ -374,7 +374,7 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
374
374
|
end
|
375
375
|
|
376
376
|
def test_statsd_doesnt_change_method_scope_of_protected_method
|
377
|
-
assert_scope
|
377
|
+
assert_scope(InstrumentedClass, :protected_and_instrumented, :protected)
|
378
378
|
|
379
379
|
assert_statsd_increment('InstrumentedClass.protected_and_instrumented') do
|
380
380
|
InstrumentedClass.new.send(:protected_and_instrumented)
|
@@ -382,7 +382,7 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
382
382
|
end
|
383
383
|
|
384
384
|
def test_statsd_doesnt_change_method_scope_of_private_method
|
385
|
-
assert_scope
|
385
|
+
assert_scope(InstrumentedClass, :private_and_instrumented, :private)
|
386
386
|
|
387
387
|
assert_statsd_increment('InstrumentedClass.private_and_instrumented') do
|
388
388
|
InstrumentedClass.new.send(:private_and_instrumented)
|
@@ -390,27 +390,27 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
390
390
|
end
|
391
391
|
|
392
392
|
def test_statsd_doesnt_change_method_scope_on_removal_of_public_method
|
393
|
-
assert_scope
|
394
|
-
InstrumentedClass.statsd_remove_count
|
395
|
-
assert_scope
|
393
|
+
assert_scope(InstrumentedClass, :public_and_instrumented, :public)
|
394
|
+
InstrumentedClass.statsd_remove_count(:public_and_instrumented, 'InstrumentedClass.public_and_instrumented')
|
395
|
+
assert_scope(InstrumentedClass, :public_and_instrumented, :public)
|
396
396
|
|
397
|
-
InstrumentedClass.statsd_count
|
397
|
+
InstrumentedClass.statsd_count(:public_and_instrumented, 'InstrumentedClass.public_and_instrumented')
|
398
398
|
end
|
399
399
|
|
400
400
|
def test_statsd_doesnt_change_method_scope_on_removal_of_protected_method
|
401
|
-
assert_scope
|
402
|
-
InstrumentedClass.statsd_remove_count
|
403
|
-
assert_scope
|
401
|
+
assert_scope(InstrumentedClass, :protected_and_instrumented, :protected)
|
402
|
+
InstrumentedClass.statsd_remove_count(:protected_and_instrumented, 'InstrumentedClass.protected_and_instrumented')
|
403
|
+
assert_scope(InstrumentedClass, :protected_and_instrumented, :protected)
|
404
404
|
|
405
|
-
InstrumentedClass.statsd_count
|
405
|
+
InstrumentedClass.statsd_count(:protected_and_instrumented, 'InstrumentedClass.protected_and_instrumented')
|
406
406
|
end
|
407
407
|
|
408
408
|
def test_statsd_doesnt_change_method_scope_on_removal_of_private_method
|
409
|
-
assert_scope
|
410
|
-
InstrumentedClass.statsd_remove_count
|
411
|
-
assert_scope
|
409
|
+
assert_scope(InstrumentedClass, :private_and_instrumented, :private)
|
410
|
+
InstrumentedClass.statsd_remove_count(:private_and_instrumented, 'InstrumentedClass.private_and_instrumented')
|
411
|
+
assert_scope(InstrumentedClass, :private_and_instrumented, :private)
|
412
412
|
|
413
|
-
InstrumentedClass.statsd_count
|
413
|
+
InstrumentedClass.statsd_count(:private_and_instrumented, 'InstrumentedClass.private_and_instrumented')
|
414
414
|
end
|
415
415
|
|
416
416
|
def test_statsd_works_with_prepended_modules
|
@@ -440,6 +440,6 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
440
440
|
:public
|
441
441
|
end
|
442
442
|
|
443
|
-
assert_equal
|
443
|
+
assert_equal(method_scope, expected_scope, "Expected method to be #{expected_scope}")
|
444
444
|
end
|
445
445
|
end
|
data/test/statsd_test.rb
CHANGED
@@ -7,14 +7,14 @@ class StatsDTest < Minitest::Test
|
|
7
7
|
|
8
8
|
def test_statsd_measure_with_explicit_value
|
9
9
|
metric = capture_statsd_call { StatsD.measure('values.foobar', 42) }
|
10
|
-
assert_equal
|
11
|
-
assert_equal
|
12
|
-
assert_equal
|
10
|
+
assert_equal('values.foobar', metric.name)
|
11
|
+
assert_equal(42, metric.value)
|
12
|
+
assert_equal(:ms, metric.type)
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_statsd_measure_with_explicit_value_and_sample_rate
|
16
16
|
metric = capture_statsd_call { StatsD.measure('values.foobar', 42, sample_rate: 0.1) }
|
17
|
-
assert_equal
|
17
|
+
assert_equal(0.1, metric.sample_rate)
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_statsd_measure_with_benchmarked_block_duration
|
@@ -22,12 +22,12 @@ class StatsDTest < Minitest::Test
|
|
22
22
|
metric = capture_statsd_call do
|
23
23
|
StatsD.measure('values.foobar') { 'foo' }
|
24
24
|
end
|
25
|
-
assert_equal
|
25
|
+
assert_equal(1120.0, metric.value)
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_statsd_measure_returns_return_value_of_block
|
29
29
|
return_value = StatsD.measure('values.foobar') { 'sarah' }
|
30
|
-
assert_equal
|
30
|
+
assert_equal('sarah', return_value)
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_statsd_measure_with_return_in_block_still_captures
|
@@ -41,8 +41,8 @@ class StatsDTest < Minitest::Test
|
|
41
41
|
result = lambda.call
|
42
42
|
end
|
43
43
|
|
44
|
-
assert_equal
|
45
|
-
assert_equal
|
44
|
+
assert_equal('from lambda', result)
|
45
|
+
assert_equal(1120.0, metric.value)
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_statsd_measure_with_exception_in_block_still_captures
|
@@ -60,29 +60,29 @@ class StatsDTest < Minitest::Test
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
assert_nil
|
64
|
-
assert_equal
|
63
|
+
assert_nil(result)
|
64
|
+
assert_equal(1120.0, metric.value)
|
65
65
|
end
|
66
66
|
|
67
67
|
def test_statsd_increment
|
68
68
|
metric = capture_statsd_call { StatsD.increment('values.foobar', 3) }
|
69
|
-
assert_equal
|
70
|
-
assert_equal
|
71
|
-
assert_equal
|
69
|
+
assert_equal(:c, metric.type)
|
70
|
+
assert_equal('values.foobar', metric.name)
|
71
|
+
assert_equal(3, metric.value)
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_statsd_increment_with_hash_argument
|
75
75
|
metric = capture_statsd_call { StatsD.increment('values.foobar', tags: ['test']) }
|
76
|
-
assert_equal
|
77
|
-
assert_equal
|
78
|
-
assert_equal
|
76
|
+
assert_equal(StatsD.singleton_client.default_sample_rate, metric.sample_rate)
|
77
|
+
assert_equal(['test'], metric.tags)
|
78
|
+
assert_equal(1, metric.value)
|
79
79
|
end
|
80
80
|
|
81
81
|
def test_statsd_gauge
|
82
82
|
metric = capture_statsd_call { StatsD.gauge('values.foobar', 12) }
|
83
|
-
assert_equal
|
84
|
-
assert_equal
|
85
|
-
assert_equal
|
83
|
+
assert_equal(:g, metric.type)
|
84
|
+
assert_equal('values.foobar', metric.name)
|
85
|
+
assert_equal(12, metric.value)
|
86
86
|
end
|
87
87
|
|
88
88
|
def test_statsd_gauge_without_value
|
@@ -91,23 +91,23 @@ class StatsDTest < Minitest::Test
|
|
91
91
|
|
92
92
|
def test_statsd_set
|
93
93
|
metric = capture_statsd_call { StatsD.set('values.foobar', 'unique_identifier') }
|
94
|
-
assert_equal
|
95
|
-
assert_equal
|
96
|
-
assert_equal
|
94
|
+
assert_equal(:s, metric.type)
|
95
|
+
assert_equal('values.foobar', metric.name)
|
96
|
+
assert_equal('unique_identifier', metric.value)
|
97
97
|
end
|
98
98
|
|
99
99
|
def test_statsd_histogram
|
100
100
|
metric = capture_statsd_call { StatsD.histogram('values.foobar', 42) }
|
101
|
-
assert_equal
|
102
|
-
assert_equal
|
103
|
-
assert_equal
|
101
|
+
assert_equal(:h, metric.type)
|
102
|
+
assert_equal('values.foobar', metric.name)
|
103
|
+
assert_equal(42, metric.value)
|
104
104
|
end
|
105
105
|
|
106
106
|
def test_statsd_distribution
|
107
107
|
metric = capture_statsd_call { StatsD.distribution('values.foobar', 42) }
|
108
|
-
assert_equal
|
109
|
-
assert_equal
|
110
|
-
assert_equal
|
108
|
+
assert_equal(:d, metric.type)
|
109
|
+
assert_equal('values.foobar', metric.name)
|
110
|
+
assert_equal(42, metric.value)
|
111
111
|
end
|
112
112
|
|
113
113
|
def test_statsd_distribution_with_benchmarked_block_duration
|
@@ -116,8 +116,8 @@ class StatsDTest < Minitest::Test
|
|
116
116
|
result = StatsD.distribution('values.foobar') { 'foo' }
|
117
117
|
assert_equal 'foo', result
|
118
118
|
end
|
119
|
-
assert_equal
|
120
|
-
assert_equal
|
119
|
+
assert_equal(:d, metric.type)
|
120
|
+
assert_equal(1120.0, metric.value)
|
121
121
|
end
|
122
122
|
|
123
123
|
def test_statsd_distribution_with_return_in_block_still_captures
|
@@ -132,9 +132,9 @@ class StatsDTest < Minitest::Test
|
|
132
132
|
result = lambda.call
|
133
133
|
end
|
134
134
|
|
135
|
-
assert_equal
|
136
|
-
assert_equal
|
137
|
-
assert_equal
|
135
|
+
assert_equal('from lambda', result)
|
136
|
+
assert_equal(:d, metric.type)
|
137
|
+
assert_equal(1120.0, metric.value)
|
138
138
|
end
|
139
139
|
|
140
140
|
def test_statsd_distribution_with_exception_in_block_still_captures
|
@@ -152,9 +152,9 @@ class StatsDTest < Minitest::Test
|
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
155
|
-
assert_nil
|
156
|
-
assert_equal
|
157
|
-
assert_equal
|
155
|
+
assert_nil(result)
|
156
|
+
assert_equal(:d, metric.type)
|
157
|
+
assert_equal(1120.0, metric.value)
|
158
158
|
end
|
159
159
|
|
160
160
|
def test_statsd_distribution_with_block_and_options
|
@@ -162,25 +162,25 @@ class StatsDTest < Minitest::Test
|
|
162
162
|
metric = capture_statsd_call do
|
163
163
|
StatsD.distribution('values.foobar', tags: ['test'], sample_rate: 0.9) { 'foo' }
|
164
164
|
end
|
165
|
-
assert_equal
|
166
|
-
assert_equal
|
167
|
-
assert_equal
|
168
|
-
assert_equal
|
165
|
+
assert_equal(1120.0, metric.value)
|
166
|
+
assert_equal('values.foobar', metric.name)
|
167
|
+
assert_equal(0.9, metric.sample_rate)
|
168
|
+
assert_equal(['test'], metric.tags)
|
169
169
|
end
|
170
170
|
|
171
171
|
def test_statsd_distribution_returns_return_value_of_block
|
172
172
|
return_value = StatsD.distribution('values.foobar') { 'sarah' }
|
173
|
-
assert_equal
|
173
|
+
assert_equal('sarah', return_value)
|
174
174
|
end
|
175
175
|
|
176
176
|
def test_statsd_measure_returns_return_value_of_block_even_if_nil
|
177
177
|
return_value = StatsD.distribution('values.foobar') { nil }
|
178
|
-
assert_nil
|
178
|
+
assert_nil(return_value)
|
179
179
|
end
|
180
180
|
|
181
181
|
def test_statsd_duration_returns_time_in_seconds
|
182
182
|
duration = StatsD::Instrument.duration {}
|
183
|
-
assert_kind_of
|
183
|
+
assert_kind_of(Float, duration)
|
184
184
|
end
|
185
185
|
|
186
186
|
def test_statsd_duration_does_not_swallow_exceptions
|
@@ -193,7 +193,7 @@ class StatsDTest < Minitest::Test
|
|
193
193
|
|
194
194
|
def capture_statsd_call(&block)
|
195
195
|
metrics = capture_statsd_calls(&block)
|
196
|
-
assert_equal
|
196
|
+
assert_equal(1, metrics.length)
|
197
197
|
metrics.first
|
198
198
|
end
|
199
199
|
end
|