statsd-instrument 3.0.0.pre1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yml +22 -0
- data/.github/workflows/tests.yml +31 -0
- data/.rubocop.yml +3 -13
- data/CHANGELOG.md +50 -0
- data/Gemfile +8 -2
- data/README.md +6 -3
- data/Rakefile +7 -7
- data/benchmark/send-metrics-to-dev-null-log +12 -11
- data/benchmark/send-metrics-to-local-udp-receiver +16 -15
- data/bin/rake +29 -0
- data/bin/rubocop +29 -0
- data/lib/statsd-instrument.rb +1 -1
- data/lib/statsd/instrument.rb +112 -145
- data/lib/statsd/instrument/assertions.rb +200 -208
- data/lib/statsd/instrument/batched_udp_sink.rb +154 -0
- data/lib/statsd/instrument/capture_sink.rb +23 -19
- data/lib/statsd/instrument/client.rb +410 -306
- 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 +88 -77
- data/lib/statsd/instrument/expectation.rb +96 -96
- data/lib/statsd/instrument/helpers.rb +11 -7
- data/lib/statsd/instrument/log_sink.rb +20 -16
- data/lib/statsd/instrument/matchers.rb +93 -74
- data/lib/statsd/instrument/null_sink.rb +12 -8
- data/lib/statsd/instrument/railtie.rb +11 -7
- data/lib/statsd/instrument/rubocop.rb +8 -8
- data/lib/statsd/instrument/rubocop/measure_as_dist_argument.rb +1 -1
- data/lib/statsd/instrument/rubocop/metaprogramming_positional_arguments.rb +2 -2
- data/lib/statsd/instrument/rubocop/metric_prefix_argument.rb +1 -1
- data/lib/statsd/instrument/rubocop/metric_return_value.rb +2 -2
- data/lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb +1 -1
- data/lib/statsd/instrument/rubocop/positional_arguments.rb +4 -4
- data/lib/statsd/instrument/rubocop/singleton_configuration.rb +1 -1
- data/lib/statsd/instrument/rubocop/splat_arguments.rb +2 -2
- data/lib/statsd/instrument/statsd_datagram_builder.rb +12 -8
- data/lib/statsd/instrument/strict.rb +1 -6
- data/lib/statsd/instrument/udp_sink.rb +49 -47
- data/lib/statsd/instrument/version.rb +1 -1
- data/statsd-instrument.gemspec +4 -8
- data/test/assertions_test.rb +205 -161
- data/test/benchmark/clock_gettime.rb +1 -1
- data/test/benchmark/default_tags.rb +9 -9
- data/test/benchmark/metrics.rb +8 -8
- data/test/benchmark/tags.rb +4 -4
- data/test/capture_sink_test.rb +14 -14
- data/test/client_test.rb +96 -96
- data/test/datagram_builder_test.rb +55 -55
- data/test/datagram_test.rb +5 -5
- data/test/dogstatsd_datagram_builder_test.rb +37 -37
- data/test/environment_test.rb +30 -21
- data/test/helpers/rubocop_helper.rb +12 -9
- data/test/helpers_test.rb +15 -15
- data/test/integration_test.rb +7 -7
- data/test/log_sink_test.rb +4 -4
- data/test/matchers_test.rb +54 -54
- data/test/null_sink_test.rb +4 -4
- data/test/rubocop/measure_as_dist_argument_test.rb +2 -2
- data/test/rubocop/metaprogramming_positional_arguments_test.rb +2 -2
- data/test/rubocop/metric_prefix_argument_test.rb +2 -2
- data/test/rubocop/metric_return_value_test.rb +6 -6
- data/test/rubocop/metric_value_keyword_argument_test.rb +3 -3
- data/test/rubocop/positional_arguments_test.rb +12 -12
- data/test/rubocop/singleton_configuration_test.rb +8 -8
- data/test/rubocop/splat_arguments_test.rb +2 -2
- data/test/statsd_datagram_builder_test.rb +6 -6
- data/test/statsd_instrumentation_test.rb +122 -122
- data/test/statsd_test.rb +69 -67
- data/test/test_helper.rb +19 -10
- data/test/udp_sink_test.rb +122 -50
- metadata +12 -92
- data/.github/workflows/ci.yml +0 -56
- data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
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(
|
12
|
-
assert_raises(NotImplementedError) { @datagram_builder.d(
|
13
|
-
assert_raises(NotImplementedError) { @datagram_builder.kv(
|
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(
|
18
|
-
assert_raises(NotImplementedError) { StatsD::Instrument::StatsDDatagramBuilder.new(default_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"]) }
|
19
19
|
end
|
20
20
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
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
|
-
|
12
|
+
"OK"
|
13
13
|
else
|
14
|
-
raise
|
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
|
-
|
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,
|
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,
|
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,
|
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
|
76
|
+
ActiveMerchant::Gateway.statsd_count_if(:ssl_post, "ActiveMerchant.Gateway.if")
|
77
77
|
|
78
|
-
assert_statsd_increment(
|
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
|
88
|
-
result ==
|
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(
|
92
|
-
assert_equal
|
93
|
-
assert_equal
|
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
|
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
|
|
104
|
-
assert_statsd_increment(
|
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
|
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
|
-
assert_statsd_increment(
|
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(
|
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
|
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
|
130
|
-
result ==
|
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(
|
134
|
-
assert_equal
|
135
|
-
assert_equal
|
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(
|
139
|
-
assert_equal
|
140
|
-
assert_equal
|
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
|
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
|
|
151
|
-
assert_statsd_increment(
|
151
|
+
assert_statsd_increment("ActiveMerchant.Gateway.success") do
|
152
152
|
ActiveMerchant::UniqueGateway.new.purchase(true)
|
153
153
|
end
|
154
154
|
|
155
|
-
assert_statsd_increment(
|
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
|
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
|
-
assert_statsd_increment(
|
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
|
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(
|
177
|
-
GatewaySubClass.new.purchase(
|
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(
|
188
|
-
GatewaySubClass.new.purchase(
|
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
|
195
|
+
ActiveMerchant::Base.statsd_count(:post_with_block, "ActiveMerchant.Base.post_with_block")
|
196
196
|
|
197
|
-
assert_statsd_increment(
|
198
|
-
assert_equal
|
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
|
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
|
-
assert_statsd_measure(
|
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
|
-
assert_statsd_measure(
|
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
|
225
225
|
assert_raises(LocalJumpError) do
|
226
|
-
assert_statsd_measure(
|
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
|
231
|
+
ActiveMerchant::Base.statsd_measure(:post_with_block, "ActiveMerchant.Base.post_with_block")
|
232
232
|
|
233
|
-
assert_statsd_measure(
|
234
|
-
assert_equal
|
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
|
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
|
-
assert_statsd_measure(
|
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
|
-
assert_statsd_distribution(
|
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
|
-
assert_statsd_distribution(
|
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
|
271
271
|
assert_raises(LocalJumpError) do
|
272
|
-
assert_statsd_distribution(
|
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
|
277
|
+
ActiveMerchant::Base.statsd_distribution(:post_with_block, "ActiveMerchant.Base.post_with_block")
|
278
278
|
|
279
|
-
assert_statsd_distribution(
|
280
|
-
assert_equal
|
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
|
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
|
-
assert_statsd_distribution(
|
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
|
-
assert_statsd_distribution(
|
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
|
-
assert_statsd_increment(
|
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
|
-
assert_statsd_increment(
|
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
|
-
StatsD.singleton_client = StatsD::Instrument::Client.new(prefix:
|
332
|
-
ActiveMerchant::Gateway.singleton_class.extend
|
333
|
-
ActiveMerchant::Gateway.singleton_class.statsd_count
|
334
|
-
StatsD.singleton_client = StatsD::Instrument::Client.new(prefix:
|
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
|
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
|
345
|
-
client = StatsD::Instrument::Client.new(prefix:
|
345
|
+
client = StatsD::Instrument::Client.new(prefix: "prefix")
|
346
346
|
|
347
|
-
ActiveMerchant::Gateway.statsd_count(:ssl_post,
|
348
|
-
assert_statsd_increment(
|
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
|
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:
|
357
|
-
ActiveMerchant::Gateway.singleton_class.extend
|
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
|
-
|
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
|
-
assert_statsd_increment(
|
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
|
377
|
+
assert_scope(InstrumentedClass, :protected_and_instrumented, :protected)
|
378
378
|
|
379
|
-
assert_statsd_increment(
|
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
|
385
|
+
assert_scope(InstrumentedClass, :private_and_instrumented, :private)
|
386
386
|
|
387
|
-
assert_statsd_increment(
|
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
|
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
|