statsd-instrument 3.0.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint.yml +22 -0
  3. data/.github/workflows/{ci.yml → tests.yml} +3 -21
  4. data/.rubocop.yml +2 -1
  5. data/CHANGELOG.md +18 -0
  6. data/Gemfile +8 -10
  7. data/README.md +7 -4
  8. data/Rakefile +6 -6
  9. data/benchmark/send-metrics-to-dev-null-log +14 -14
  10. data/benchmark/send-metrics-to-local-udp-receiver +18 -18
  11. data/lib/statsd/instrument/assertions.rb +7 -7
  12. data/lib/statsd/instrument/batched_udp_sink.rb +159 -0
  13. data/lib/statsd/instrument/client.rb +3 -3
  14. data/lib/statsd/instrument/datagram.rb +1 -1
  15. data/lib/statsd/instrument/datagram_builder.rb +10 -22
  16. data/lib/statsd/instrument/dogstatsd_datagram_builder.rb +2 -2
  17. data/lib/statsd/instrument/environment.rb +19 -11
  18. data/lib/statsd/instrument/expectation.rb +6 -18
  19. data/lib/statsd/instrument/matchers.rb +8 -4
  20. data/lib/statsd/instrument/railtie.rb +1 -1
  21. data/lib/statsd/instrument/rubocop/measure_as_dist_argument.rb +1 -1
  22. data/lib/statsd/instrument/rubocop/metaprogramming_positional_arguments.rb +2 -2
  23. data/lib/statsd/instrument/rubocop/metric_prefix_argument.rb +1 -1
  24. data/lib/statsd/instrument/rubocop/metric_return_value.rb +3 -3
  25. data/lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb +1 -1
  26. data/lib/statsd/instrument/rubocop/positional_arguments.rb +4 -4
  27. data/lib/statsd/instrument/rubocop/singleton_configuration.rb +1 -1
  28. data/lib/statsd/instrument/rubocop/splat_arguments.rb +2 -2
  29. data/lib/statsd/instrument/rubocop.rb +13 -34
  30. data/lib/statsd/instrument/strict.rb +1 -1
  31. data/lib/statsd/instrument/udp_sink.rb +11 -13
  32. data/lib/statsd/instrument/version.rb +1 -1
  33. data/lib/statsd/instrument.rb +56 -59
  34. data/lib/statsd-instrument.rb +1 -1
  35. data/statsd-instrument.gemspec +2 -0
  36. data/test/assertions_test.rb +200 -155
  37. data/test/benchmark/clock_gettime.rb +1 -1
  38. data/test/benchmark/metrics.rb +8 -8
  39. data/test/benchmark/tags.rb +4 -4
  40. data/test/capture_sink_test.rb +11 -11
  41. data/test/client_test.rb +64 -64
  42. data/test/datagram_builder_test.rb +41 -41
  43. data/test/datagram_test.rb +5 -5
  44. data/test/dogstatsd_datagram_builder_test.rb +22 -22
  45. data/test/environment_test.rb +26 -17
  46. data/test/helpers/rubocop_helper.rb +3 -3
  47. data/test/helpers_test.rb +12 -12
  48. data/test/integration_test.rb +6 -6
  49. data/test/log_sink_test.rb +2 -2
  50. data/test/matchers_test.rb +46 -46
  51. data/test/null_sink_test.rb +2 -2
  52. data/test/rubocop/measure_as_dist_argument_test.rb +2 -2
  53. data/test/rubocop/metaprogramming_positional_arguments_test.rb +2 -2
  54. data/test/rubocop/metric_prefix_argument_test.rb +2 -2
  55. data/test/rubocop/metric_return_value_test.rb +3 -3
  56. data/test/rubocop/metric_value_keyword_argument_test.rb +3 -3
  57. data/test/rubocop/positional_arguments_test.rb +2 -2
  58. data/test/rubocop/singleton_configuration_test.rb +8 -8
  59. data/test/rubocop/splat_arguments_test.rb +2 -2
  60. data/test/statsd_datagram_builder_test.rb +6 -6
  61. data/test/statsd_instrumentation_test.rb +104 -104
  62. data/test/statsd_test.rb +35 -35
  63. data/test/test_helper.rb +13 -6
  64. data/test/udp_sink_test.rb +142 -44
  65. metadata +21 -7
  66. data/test/benchmark/default_tags.rb +0 -47
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  class NullSinkTest < Minitest::Test
6
6
  def test_null_sink
7
7
  null_sink = StatsD::Instrument::NullSink.new
8
- null_sink << 'foo:1|c' << 'bar:1|c'
8
+ null_sink << "foo:1|c" << "bar:1|c"
9
9
  pass # We don't have anything to assert, except that no exception was raised
10
10
  end
11
11
 
@@ -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 MeasureAsDistArgumentTest < Minitest::Test
@@ -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 MetaprogrammingPositionalArgumentsTest < Minitest::Test
@@ -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 MetricPrefixArgumentTest < Minitest::Test
@@ -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 MetricReturnValueTest < Minitest::Test
@@ -12,7 +12,7 @@ module Rubocop
12
12
  end
13
13
 
14
14
  def test_ok_for_non_metric_method
15
- assert_no_offenses('backend = StatsD.backend')
15
+ assert_no_offenses("backend = StatsD.backend")
16
16
  end
17
17
 
18
18
  def test_ok_as_naked_statement
@@ -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 MetricValueKeywordArgumentTest < Minitest::Test
@@ -31,7 +31,7 @@ module Rubocop
31
31
  def test_offense_with_value_keyword
32
32
  assert_offense("StatsD.increment('foo', value: 1)")
33
33
  assert_offense("StatsD.increment('foo', :value => 1)")
34
- assert_offense("StatsD.increment('foo', 'value' => 1)")
34
+ # assert_offense("StatsD.increment('foo', 'value' => 1)")
35
35
  assert_offense("StatsD.increment('foo', sample_rate: 0.1, value: 1, tags: ['foo'])")
36
36
  assert_offense("StatsD.increment('foo', value: 1, &block)")
37
37
  end
@@ -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 PositionalArgumentsTest < Minitest::Test
@@ -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 SingletonConfigurationTest < Minitest::Test
@@ -13,7 +13,7 @@ module Rubocop
13
13
 
14
14
  def test_offense_statsd_backend
15
15
  assert_offense('StatsD.backend = "foo"')
16
- assert_offense('old_backend = StatsD.backend')
16
+ assert_offense("old_backend = StatsD.backend")
17
17
  end
18
18
 
19
19
  def test_offense_statsd_prefix
@@ -23,21 +23,21 @@ module Rubocop
23
23
 
24
24
  def test_offense_statsd_default_tags
25
25
  assert_offense('StatsD.default_tags = ["foo"]')
26
- assert_offense('StatsD.default_tags.empty?')
26
+ assert_offense("StatsD.default_tags.empty?")
27
27
  end
28
28
 
29
29
  def test_offense_statsd_default_sample_rate
30
- assert_offense('StatsD.default_sample_rate = 1.0')
31
- assert_offense('should_sample = StatsD.default_sample_rate > rand')
30
+ assert_offense("StatsD.default_sample_rate = 1.0")
31
+ assert_offense("should_sample = StatsD.default_sample_rate > rand")
32
32
  end
33
33
 
34
34
  def test_no_offense_for_other_methods
35
- assert_no_offenses('StatsD.singleton_client = my_client')
35
+ assert_no_offenses("StatsD.singleton_client = my_client")
36
36
  assert_no_offenses('StatsD.logger.info("foo")')
37
37
  end
38
38
 
39
39
  def test_no_offense_for_constant_reference
40
- assert_no_offenses('legacy_client = StatsD')
40
+ assert_no_offenses("legacy_client = StatsD")
41
41
  end
42
42
  end
43
43
  end
@@ -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,191 +184,191 @@ 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
307
  ActiveMerchant::Gateway.singleton_class.extend(StatsD::Instrument)
308
- ActiveMerchant::Gateway.singleton_class.statsd_count(:sync, 'ActiveMerchant.Gateway.sync')
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
318
  ActiveMerchant::Gateway.singleton_class.extend(StatsD::Instrument)
319
- ActiveMerchant::Gateway.singleton_class.statsd_count(:sync, 'ActiveMerchant.Gateway.sync', tags: { key: 'value' })
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')
331
+ StatsD.singleton_client = StatsD::Instrument::Client.new(prefix: "Foo")
332
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')
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
337
  assert_equal(1, datagrams.length)
338
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("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')
356
+ client = StatsD::Instrument::Client.new(prefix: "foo")
357
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
362
  assert_equal(1, datagrams.length)
363
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
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
@@ -376,7 +376,7 @@ class StatsDInstrumentationTest < Minitest::Test
376
376
  def test_statsd_doesnt_change_method_scope_of_protected_method
377
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
@@ -384,33 +384,33 @@ class StatsDInstrumentationTest < Minitest::Test
384
384
  def test_statsd_doesnt_change_method_scope_of_private_method
385
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
393
  assert_scope(InstrumentedClass, :public_and_instrumented, :public)
394
- InstrumentedClass.statsd_remove_count(:public_and_instrumented, 'InstrumentedClass.public_and_instrumented')
394
+ InstrumentedClass.statsd_remove_count(:public_and_instrumented, "InstrumentedClass.public_and_instrumented")
395
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
401
  assert_scope(InstrumentedClass, :protected_and_instrumented, :protected)
402
- InstrumentedClass.statsd_remove_count(:protected_and_instrumented, 'InstrumentedClass.protected_and_instrumented')
402
+ InstrumentedClass.statsd_remove_count(:protected_and_instrumented, "InstrumentedClass.protected_and_instrumented")
403
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
409
  assert_scope(InstrumentedClass, :private_and_instrumented, :private)
410
- InstrumentedClass.statsd_remove_count(:private_and_instrumented, 'InstrumentedClass.private_and_instrumented')
410
+ InstrumentedClass.statsd_remove_count(:private_and_instrumented, "InstrumentedClass.private_and_instrumented")
411
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