statsd-instrument 3.0.0.pre1 → 3.1.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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint.yml +22 -0
  3. data/.github/workflows/tests.yml +31 -0
  4. data/.rubocop.yml +3 -13
  5. data/CHANGELOG.md +50 -0
  6. data/Gemfile +8 -2
  7. data/README.md +6 -3
  8. data/Rakefile +7 -7
  9. data/benchmark/send-metrics-to-dev-null-log +12 -11
  10. data/benchmark/send-metrics-to-local-udp-receiver +16 -15
  11. data/bin/rake +29 -0
  12. data/bin/rubocop +29 -0
  13. data/lib/statsd-instrument.rb +1 -1
  14. data/lib/statsd/instrument.rb +112 -145
  15. data/lib/statsd/instrument/assertions.rb +200 -208
  16. data/lib/statsd/instrument/batched_udp_sink.rb +154 -0
  17. data/lib/statsd/instrument/capture_sink.rb +23 -19
  18. data/lib/statsd/instrument/client.rb +410 -306
  19. data/lib/statsd/instrument/datagram.rb +69 -65
  20. data/lib/statsd/instrument/datagram_builder.rb +81 -77
  21. data/lib/statsd/instrument/dogstatsd_datagram.rb +76 -72
  22. data/lib/statsd/instrument/dogstatsd_datagram_builder.rb +68 -64
  23. data/lib/statsd/instrument/environment.rb +88 -77
  24. data/lib/statsd/instrument/expectation.rb +96 -96
  25. data/lib/statsd/instrument/helpers.rb +11 -7
  26. data/lib/statsd/instrument/log_sink.rb +20 -16
  27. data/lib/statsd/instrument/matchers.rb +93 -74
  28. data/lib/statsd/instrument/null_sink.rb +12 -8
  29. data/lib/statsd/instrument/railtie.rb +11 -7
  30. data/lib/statsd/instrument/rubocop.rb +8 -8
  31. data/lib/statsd/instrument/rubocop/measure_as_dist_argument.rb +1 -1
  32. data/lib/statsd/instrument/rubocop/metaprogramming_positional_arguments.rb +2 -2
  33. data/lib/statsd/instrument/rubocop/metric_prefix_argument.rb +1 -1
  34. data/lib/statsd/instrument/rubocop/metric_return_value.rb +2 -2
  35. data/lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb +1 -1
  36. data/lib/statsd/instrument/rubocop/positional_arguments.rb +4 -4
  37. data/lib/statsd/instrument/rubocop/singleton_configuration.rb +1 -1
  38. data/lib/statsd/instrument/rubocop/splat_arguments.rb +2 -2
  39. data/lib/statsd/instrument/statsd_datagram_builder.rb +12 -8
  40. data/lib/statsd/instrument/strict.rb +1 -6
  41. data/lib/statsd/instrument/udp_sink.rb +49 -47
  42. data/lib/statsd/instrument/version.rb +1 -1
  43. data/statsd-instrument.gemspec +4 -8
  44. data/test/assertions_test.rb +205 -161
  45. data/test/benchmark/clock_gettime.rb +1 -1
  46. data/test/benchmark/default_tags.rb +9 -9
  47. data/test/benchmark/metrics.rb +8 -8
  48. data/test/benchmark/tags.rb +4 -4
  49. data/test/capture_sink_test.rb +14 -14
  50. data/test/client_test.rb +96 -96
  51. data/test/datagram_builder_test.rb +55 -55
  52. data/test/datagram_test.rb +5 -5
  53. data/test/dogstatsd_datagram_builder_test.rb +37 -37
  54. data/test/environment_test.rb +30 -21
  55. data/test/helpers/rubocop_helper.rb +12 -9
  56. data/test/helpers_test.rb +15 -15
  57. data/test/integration_test.rb +7 -7
  58. data/test/log_sink_test.rb +4 -4
  59. data/test/matchers_test.rb +54 -54
  60. data/test/null_sink_test.rb +4 -4
  61. data/test/rubocop/measure_as_dist_argument_test.rb +2 -2
  62. data/test/rubocop/metaprogramming_positional_arguments_test.rb +2 -2
  63. data/test/rubocop/metric_prefix_argument_test.rb +2 -2
  64. data/test/rubocop/metric_return_value_test.rb +6 -6
  65. data/test/rubocop/metric_value_keyword_argument_test.rb +3 -3
  66. data/test/rubocop/positional_arguments_test.rb +12 -12
  67. data/test/rubocop/singleton_configuration_test.rb +8 -8
  68. data/test/rubocop/splat_arguments_test.rb +2 -2
  69. data/test/statsd_datagram_builder_test.rb +6 -6
  70. data/test/statsd_instrumentation_test.rb +122 -122
  71. data/test/statsd_test.rb +69 -67
  72. data/test/test_helper.rb +19 -10
  73. data/test/udp_sink_test.rb +122 -50
  74. metadata +12 -92
  75. data/.github/workflows/ci.yml +0 -56
  76. data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
4
- require 'statsd/instrument/rubocop'
3
+ require "test_helper"
4
+ require "statsd/instrument/rubocop"
5
5
 
6
6
  module Rubocop
7
7
  class SplatArgumentsTest < Minitest::Test
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  class StatsDDatagramBuilderTest < Minitest::Test
6
6
  def setup
@@ -8,13 +8,13 @@ class StatsDDatagramBuilderTest < Minitest::Test
8
8
  end
9
9
 
10
10
  def test_raises_on_unsupported_metrics
11
- assert_raises(NotImplementedError) { @datagram_builder.h('fo:o', 10, nil, nil) }
12
- assert_raises(NotImplementedError) { @datagram_builder.d('fo:o', 10, nil, nil) }
13
- assert_raises(NotImplementedError) { @datagram_builder.kv('fo:o', 10, nil, nil) }
11
+ assert_raises(NotImplementedError) { @datagram_builder.h("fo:o", 10, nil, nil) }
12
+ assert_raises(NotImplementedError) { @datagram_builder.d("fo:o", 10, nil, nil) }
13
+ assert_raises(NotImplementedError) { @datagram_builder.kv("fo:o", 10, nil, nil) }
14
14
  end
15
15
 
16
16
  def test_raises_when_using_tags
17
- assert_raises(NotImplementedError) { @datagram_builder.c('fo:o', 10, nil, foo: 'bar') }
18
- assert_raises(NotImplementedError) { StatsD::Instrument::StatsDDatagramBuilder.new(default_tags: ['foo']) }
17
+ assert_raises(NotImplementedError) { @datagram_builder.c("fo:o", 10, nil, foo: "bar") }
18
+ assert_raises(NotImplementedError) { StatsD::Instrument::StatsDDatagramBuilder.new(default_tags: ["foo"]) }
19
19
  end
20
20
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  class StatsDInstrumentationTest < Minitest::Test
6
6
  module ActiveMerchant
@@ -9,9 +9,9 @@ class StatsDInstrumentationTest < Minitest::Test
9
9
 
10
10
  def ssl_post(arg)
11
11
  if arg
12
- 'OK'
12
+ "OK"
13
13
  else
14
- raise 'Not OK'
14
+ raise "Not OK"
15
15
  end
16
16
  end
17
17
 
@@ -46,7 +46,7 @@ class StatsDInstrumentationTest < Minitest::Test
46
46
 
47
47
  class GatewaySubClass < ActiveMerchant::Gateway
48
48
  def metric_name
49
- 'subgateway'
49
+ "subgateway"
50
50
  end
51
51
  end
52
52
 
@@ -55,126 +55,126 @@ class StatsDInstrumentationTest < Minitest::Test
55
55
 
56
56
  def public_and_instrumented
57
57
  end
58
- statsd_count :public_and_instrumented, 'InstrumentedClass.public_and_instrumented'
58
+ statsd_count :public_and_instrumented, "InstrumentedClass.public_and_instrumented"
59
59
 
60
60
  protected
61
61
 
62
62
  def protected_and_instrumented
63
63
  end
64
- statsd_count :protected_and_instrumented, 'InstrumentedClass.protected_and_instrumented'
64
+ statsd_count :protected_and_instrumented, "InstrumentedClass.protected_and_instrumented"
65
65
 
66
66
  private
67
67
 
68
68
  def private_and_instrumented
69
69
  end
70
- statsd_count :private_and_instrumented, 'InstrumentedClass.private_and_instrumented'
70
+ statsd_count :private_and_instrumented, "InstrumentedClass.private_and_instrumented"
71
71
  end
72
72
 
73
73
  include StatsD::Instrument::Assertions
74
74
 
75
75
  def test_statsd_count_if
76
- ActiveMerchant::Gateway.statsd_count_if :ssl_post, 'ActiveMerchant.Gateway.if'
76
+ ActiveMerchant::Gateway.statsd_count_if(:ssl_post, "ActiveMerchant.Gateway.if")
77
77
 
78
- assert_statsd_increment('ActiveMerchant.Gateway.if') do
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 :ssl_post, 'ActiveMerchant.Gateway.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 :post_with_block, 'ActiveMerchant.Base.post_with_block' do |result|
88
- result == 'true'
87
+ ActiveMerchant::Base.statsd_count_if(:post_with_block, "ActiveMerchant.Base.post_with_block") do |result|
88
+ result == "true"
89
89
  end
90
90
 
91
- assert_statsd_increment('ActiveMerchant.Base.post_with_block') do
92
- assert_equal 'true', ActiveMerchant::Base.new.post_with_block { 'true' }
93
- assert_equal 'false', ActiveMerchant::Base.new.post_with_block { 'false' }
91
+ assert_statsd_increment("ActiveMerchant.Base.post_with_block") do
92
+ assert_equal("true", ActiveMerchant::Base.new.post_with_block { "true" })
93
+ assert_equal("false", ActiveMerchant::Base.new.post_with_block { "false" })
94
94
  end
95
95
  ensure
96
- ActiveMerchant::Base.statsd_remove_count_if :post_with_block, 'ActiveMerchant.Base.post_with_block'
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 :ssl_post, 'ActiveMerchant.Gateway.block' do |result|
100
+ ActiveMerchant::UniqueGateway.statsd_count_if(:ssl_post, "ActiveMerchant.Gateway.block") do |result|
101
101
  result[:success]
102
102
  end
103
103
 
104
- assert_statsd_increment('ActiveMerchant.Gateway.block', times: 1) do
104
+ assert_statsd_increment("ActiveMerchant.Gateway.block", times: 1) do
105
105
  ActiveMerchant::UniqueGateway.new.purchase(true)
106
106
  ActiveMerchant::UniqueGateway.new.purchase(false)
107
107
  end
108
108
  ensure
109
- ActiveMerchant::UniqueGateway.statsd_remove_count_if :ssl_post, 'ActiveMerchant.Gateway.block'
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 :ssl_post, 'ActiveMerchant.Gateway', sample_rate: 0.5
113
+ ActiveMerchant::Gateway.statsd_count_success(:ssl_post, "ActiveMerchant.Gateway", sample_rate: 0.5)
114
114
 
115
- assert_statsd_increment('ActiveMerchant.Gateway.success', sample_rate: 0.5, times: 1) do
115
+ assert_statsd_increment("ActiveMerchant.Gateway.success", sample_rate: 0.5, times: 1) do
116
116
  ActiveMerchant::Gateway.new.purchase(true)
117
117
  ActiveMerchant::Gateway.new.purchase(false)
118
118
  end
119
119
 
120
- assert_statsd_increment('ActiveMerchant.Gateway.failure', sample_rate: 0.5, times: 1) do
120
+ assert_statsd_increment("ActiveMerchant.Gateway.failure", sample_rate: 0.5, times: 1) do
121
121
  ActiveMerchant::Gateway.new.purchase(false)
122
122
  ActiveMerchant::Gateway.new.purchase(true)
123
123
  end
124
124
  ensure
125
- ActiveMerchant::Gateway.statsd_remove_count_success :ssl_post, 'ActiveMerchant.Gateway'
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 :post_with_block, 'ActiveMerchant.Base.post_with_block' do |result|
130
- result == 'successful'
129
+ ActiveMerchant::Base.statsd_count_success(:post_with_block, "ActiveMerchant.Base.post_with_block") do |result|
130
+ result == "successful"
131
131
  end
132
132
 
133
- assert_statsd_increment('ActiveMerchant.Base.post_with_block.success', times: 1) do
134
- assert_equal 'successful', ActiveMerchant::Base.new.post_with_block { 'successful' }
135
- assert_equal 'not so successful', ActiveMerchant::Base.new.post_with_block { 'not so successful' }
133
+ assert_statsd_increment("ActiveMerchant.Base.post_with_block.success", times: 1) do
134
+ assert_equal("successful", ActiveMerchant::Base.new.post_with_block { "successful" })
135
+ assert_equal("not so successful", ActiveMerchant::Base.new.post_with_block { "not so successful" })
136
136
  end
137
137
 
138
- assert_statsd_increment('ActiveMerchant.Base.post_with_block.failure', times: 1) do
139
- assert_equal 'successful', ActiveMerchant::Base.new.post_with_block { 'successful' }
140
- assert_equal 'not so successful', ActiveMerchant::Base.new.post_with_block { 'not so successful' }
138
+ assert_statsd_increment("ActiveMerchant.Base.post_with_block.failure", times: 1) do
139
+ assert_equal("successful", ActiveMerchant::Base.new.post_with_block { "successful" })
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 :post_with_block, 'ActiveMerchant.Base.post_with_block'
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 :ssl_post, 'ActiveMerchant.Gateway' do |result|
147
+ ActiveMerchant::UniqueGateway.statsd_count_success(:ssl_post, "ActiveMerchant.Gateway") do |result|
148
148
  result[:success]
149
149
  end
150
150
 
151
- assert_statsd_increment('ActiveMerchant.Gateway.success') do
151
+ assert_statsd_increment("ActiveMerchant.Gateway.success") do
152
152
  ActiveMerchant::UniqueGateway.new.purchase(true)
153
153
  end
154
154
 
155
- assert_statsd_increment('ActiveMerchant.Gateway.failure') do
155
+ assert_statsd_increment("ActiveMerchant.Gateway.failure") do
156
156
  ActiveMerchant::UniqueGateway.new.purchase(false)
157
157
  end
158
158
  ensure
159
- ActiveMerchant::UniqueGateway.statsd_remove_count_success :ssl_post, 'ActiveMerchant.Gateway'
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 :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
163
+ ActiveMerchant::Gateway.statsd_count(:ssl_post, "ActiveMerchant.Gateway.ssl_post")
164
164
 
165
- assert_statsd_increment('ActiveMerchant.Gateway.ssl_post') do
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 :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
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
173
173
  metric_namer = lambda { |object, args| "#{object.metric_name}.#{args.first}" }
174
174
  ActiveMerchant::Gateway.statsd_count(:ssl_post, metric_namer)
175
175
 
176
- assert_statsd_increment('subgateway.foo') do
177
- GatewaySubClass.new.purchase('foo')
176
+ assert_statsd_increment("subgateway.foo") do
177
+ GatewaySubClass.new.purchase("foo")
178
178
  end
179
179
  ensure
180
180
  ActiveMerchant::Gateway.statsd_remove_count(:ssl_post, metric_namer)
@@ -184,233 +184,233 @@ class StatsDInstrumentationTest < Minitest::Test
184
184
  metric_namer = proc { |object, args| "#{object.metric_name}.#{args.first}" }
185
185
  ActiveMerchant::Gateway.statsd_count(:ssl_post, metric_namer)
186
186
 
187
- assert_statsd_increment('subgateway.foo') do
188
- GatewaySubClass.new.purchase('foo')
187
+ assert_statsd_increment("subgateway.foo") do
188
+ GatewaySubClass.new.purchase("foo")
189
189
  end
190
190
  ensure
191
191
  ActiveMerchant::Gateway.statsd_remove_count(:ssl_post, metric_namer)
192
192
  end
193
193
 
194
194
  def test_statsd_count_with_method_receiving_block
195
- ActiveMerchant::Base.statsd_count :post_with_block, 'ActiveMerchant.Base.post_with_block'
195
+ ActiveMerchant::Base.statsd_count(:post_with_block, "ActiveMerchant.Base.post_with_block")
196
196
 
197
- assert_statsd_increment('ActiveMerchant.Base.post_with_block') do
198
- assert_equal 'block called', ActiveMerchant::Base.new.post_with_block { 'block called' }
197
+ assert_statsd_increment("ActiveMerchant.Base.post_with_block") do
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 :post_with_block, 'ActiveMerchant.Base.post_with_block'
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 :ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3
205
+ ActiveMerchant::UniqueGateway.statsd_measure(:ssl_post, "ActiveMerchant.Gateway.ssl_post", sample_rate: 0.3)
206
206
 
207
- assert_statsd_measure('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3) do
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 :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
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 :ssl_post, 'ActiveMerchant::Gateway.ssl_post'
215
+ ActiveMerchant::UniqueGateway.statsd_measure(:ssl_post, "ActiveMerchant::Gateway.ssl_post")
216
216
 
217
- assert_statsd_measure('ActiveMerchant.Gateway.ssl_post') do
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 :ssl_post, 'ActiveMerchant::Gateway.ssl_post'
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
225
225
  assert_raises(LocalJumpError) do
226
- assert_statsd_measure('ActiveMerchant.Gateway.ssl_post')
226
+ assert_statsd_measure("ActiveMerchant.Gateway.ssl_post")
227
227
  end
228
228
  end
229
229
 
230
230
  def test_statsd_measure_with_method_receiving_block
231
- ActiveMerchant::Base.statsd_measure :post_with_block, 'ActiveMerchant.Base.post_with_block'
231
+ ActiveMerchant::Base.statsd_measure(:post_with_block, "ActiveMerchant.Base.post_with_block")
232
232
 
233
- assert_statsd_measure('ActiveMerchant.Base.post_with_block') do
234
- assert_equal 'block called', ActiveMerchant::Base.new.post_with_block { 'block called' }
233
+ assert_statsd_measure("ActiveMerchant.Base.post_with_block") do
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 :post_with_block, 'ActiveMerchant.Base.post_with_block'
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 :ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1
241
+ ActiveMerchant::UniqueGateway.statsd_measure(:ssl_post, "ActiveMerchant.Gateway.ssl_post", sample_rate: 0.1)
242
242
 
243
- assert_statsd_measure('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1) do
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 :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
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 :ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3
251
+ ActiveMerchant::UniqueGateway.statsd_distribution(:ssl_post, "ActiveMerchant.Gateway.ssl_post", sample_rate: 0.3)
252
252
 
253
- assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3) do
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 :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
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 :ssl_post, 'ActiveMerchant::Gateway.ssl_post'
261
+ ActiveMerchant::UniqueGateway.statsd_distribution(:ssl_post, "ActiveMerchant::Gateway.ssl_post")
262
262
 
263
- assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post') do
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 :ssl_post, 'ActiveMerchant::Gateway.ssl_post'
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
271
271
  assert_raises(LocalJumpError) do
272
- assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post')
272
+ assert_statsd_distribution("ActiveMerchant.Gateway.ssl_post")
273
273
  end
274
274
  end
275
275
 
276
276
  def test_statsd_distribution_with_method_receiving_block
277
- ActiveMerchant::Base.statsd_distribution :post_with_block, 'ActiveMerchant.Base.post_with_block'
277
+ ActiveMerchant::Base.statsd_distribution(:post_with_block, "ActiveMerchant.Base.post_with_block")
278
278
 
279
- assert_statsd_distribution('ActiveMerchant.Base.post_with_block') do
280
- assert_equal 'block called', ActiveMerchant::Base.new.post_with_block { 'block called' }
279
+ assert_statsd_distribution("ActiveMerchant.Base.post_with_block") do
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 :post_with_block, 'ActiveMerchant.Base.post_with_block'
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 :ssl_post, 'ActiveMerchant.Gateway.ssl_post', tags: ['foo']
287
+ ActiveMerchant::UniqueGateway.statsd_distribution(:ssl_post, "ActiveMerchant.Gateway.ssl_post", tags: ["foo"])
288
288
 
289
- assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post', tags: ['foo']) do
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 :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
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 :ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1
297
+ ActiveMerchant::UniqueGateway.statsd_distribution(:ssl_post, "ActiveMerchant.Gateway.ssl_post", sample_rate: 0.1)
298
298
 
299
- assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1) do
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 :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
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 StatsD::Instrument
308
- ActiveMerchant::Gateway.singleton_class.statsd_count :sync, 'ActiveMerchant.Gateway.sync'
307
+ ActiveMerchant::Gateway.singleton_class.extend(StatsD::Instrument)
308
+ ActiveMerchant::Gateway.singleton_class.statsd_count(:sync, "ActiveMerchant.Gateway.sync")
309
309
 
310
- assert_statsd_increment('ActiveMerchant.Gateway.sync') do
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 :sync, 'ActiveMerchant.Gateway.sync'
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 StatsD::Instrument
319
- ActiveMerchant::Gateway.singleton_class.statsd_count :sync, 'ActiveMerchant.Gateway.sync', tags: { key: 'value' }
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
- assert_statsd_increment('ActiveMerchant.Gateway.sync', tags: ['key:value']) do
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 :sync, 'ActiveMerchant.Gateway.sync'
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
- StatsD.singleton_client = StatsD::Instrument::Client.new(prefix: 'Foo')
332
- ActiveMerchant::Gateway.singleton_class.extend StatsD::Instrument
333
- ActiveMerchant::Gateway.singleton_class.statsd_count :sync, 'ActiveMerchant.Gateway.sync'
334
- StatsD.singleton_client = StatsD::Instrument::Client.new(prefix: 'Quc')
331
+ StatsD.singleton_client = StatsD::Instrument::Client.new(prefix: "Foo")
332
+ ActiveMerchant::Gateway.singleton_class.extend(StatsD::Instrument)
333
+ ActiveMerchant::Gateway.singleton_class.statsd_count(:sync, "ActiveMerchant.Gateway.sync")
334
+ StatsD.singleton_client = StatsD::Instrument::Client.new(prefix: "Quc")
335
335
 
336
336
  datagrams = capture_statsd_calls { ActiveMerchant::Gateway.sync }
337
- assert_equal 1, datagrams.length
338
- assert_equal "Quc.ActiveMerchant.Gateway.sync", datagrams.first.name
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 :sync, 'ActiveMerchant.Gateway.sync'
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
345
- client = StatsD::Instrument::Client.new(prefix: 'prefix')
345
+ client = StatsD::Instrument::Client.new(prefix: "prefix")
346
346
 
347
- ActiveMerchant::Gateway.statsd_count(:ssl_post, 'ActiveMerchant.Gateway.ssl_post', client: client)
348
- assert_statsd_increment('prefix.ActiveMerchant.Gateway.ssl_post', client: client) do
347
+ ActiveMerchant::Gateway.statsd_count(:ssl_post, "ActiveMerchant.Gateway.ssl_post", client: client)
348
+ assert_statsd_increment("prefix.ActiveMerchant.Gateway.ssl_post", client: client) do
349
349
  ActiveMerchant::Gateway.new.purchase(true)
350
350
  end
351
351
  ensure
352
- ActiveMerchant::Gateway.statsd_remove_count :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
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
- client = StatsD::Instrument::Client.new(prefix: 'foo')
357
- ActiveMerchant::Gateway.singleton_class.extend StatsD::Instrument
356
+ client = StatsD::Instrument::Client.new(prefix: "foo")
357
+ ActiveMerchant::Gateway.singleton_class.extend(StatsD::Instrument)
358
358
  ActiveMerchant::Gateway.singleton_class.statsd_count_success(:sync,
359
- 'ActiveMerchant.Gateway.sync', no_prefix: true, client: client)
359
+ "ActiveMerchant.Gateway.sync", no_prefix: true, client: client)
360
360
 
361
361
  datagrams = client.capture { ActiveMerchant::Gateway.sync }
362
- assert_equal 1, datagrams.length
363
- assert_equal "ActiveMerchant.Gateway.sync.success", datagrams.first.name
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 :sync, 'ActiveMerchant.Gateway.sync'
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 InstrumentedClass, :public_and_instrumented, :public
369
+ assert_scope(InstrumentedClass, :public_and_instrumented, :public)
370
370
 
371
- assert_statsd_increment('InstrumentedClass.public_and_instrumented') do
371
+ assert_statsd_increment("InstrumentedClass.public_and_instrumented") do
372
372
  InstrumentedClass.new.send(:public_and_instrumented)
373
373
  end
374
374
  end
375
375
 
376
376
  def test_statsd_doesnt_change_method_scope_of_protected_method
377
- assert_scope InstrumentedClass, :protected_and_instrumented, :protected
377
+ assert_scope(InstrumentedClass, :protected_and_instrumented, :protected)
378
378
 
379
- assert_statsd_increment('InstrumentedClass.protected_and_instrumented') do
379
+ assert_statsd_increment("InstrumentedClass.protected_and_instrumented") do
380
380
  InstrumentedClass.new.send(:protected_and_instrumented)
381
381
  end
382
382
  end
383
383
 
384
384
  def test_statsd_doesnt_change_method_scope_of_private_method
385
- assert_scope InstrumentedClass, :private_and_instrumented, :private
385
+ assert_scope(InstrumentedClass, :private_and_instrumented, :private)
386
386
 
387
- assert_statsd_increment('InstrumentedClass.private_and_instrumented') do
387
+ assert_statsd_increment("InstrumentedClass.private_and_instrumented") do
388
388
  InstrumentedClass.new.send(:private_and_instrumented)
389
389
  end
390
390
  end
391
391
 
392
392
  def test_statsd_doesnt_change_method_scope_on_removal_of_public_method
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
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 :public_and_instrumented, 'InstrumentedClass.public_and_instrumented'
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 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
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 :protected_and_instrumented, 'InstrumentedClass.protected_and_instrumented'
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 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
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 :private_and_instrumented, 'InstrumentedClass.private_and_instrumented'
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 method_scope, expected_scope, "Expected method to be #{expected_scope}"
443
+ assert_equal(method_scope, expected_scope, "Expected method to be #{expected_scope}")
444
444
  end
445
445
  end