statsd-instrument 2.9.2 → 3.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +0 -11
- data/benchmark/send-metrics-to-dev-null-log +4 -2
- data/benchmark/send-metrics-to-local-udp-receiver +7 -6
- data/lib/statsd/instrument.rb +35 -69
- data/lib/statsd/instrument/assertions.rb +14 -14
- data/lib/statsd/instrument/client.rb +0 -10
- data/lib/statsd/instrument/environment.rb +1 -23
- data/lib/statsd/instrument/expectation.rb +14 -14
- data/lib/statsd/instrument/helpers.rb +1 -30
- data/lib/statsd/instrument/railtie.rb +0 -4
- data/lib/statsd/instrument/strict.rb +12 -118
- data/lib/statsd/instrument/version.rb +1 -1
- data/test/assertions_test.rb +9 -21
- data/test/client_test.rb +11 -0
- data/test/environment_test.rb +1 -37
- data/test/integration_test.rb +9 -24
- data/test/statsd_instrumentation_test.rb +25 -50
- data/test/statsd_test.rb +2 -29
- metadata +4 -26
- data/benchmark/datagram-client +0 -40
- data/lib/statsd/instrument/backend.rb +0 -18
- data/lib/statsd/instrument/backends/capture_backend.rb +0 -32
- data/lib/statsd/instrument/backends/logger_backend.rb +0 -20
- data/lib/statsd/instrument/backends/null_backend.rb +0 -9
- data/lib/statsd/instrument/backends/udp_backend.rb +0 -152
- data/lib/statsd/instrument/legacy_client.rb +0 -301
- data/lib/statsd/instrument/metric.rb +0 -155
- data/test/assertions_on_legacy_client_test.rb +0 -344
- data/test/capture_backend_test.rb +0 -26
- data/test/compatibility/dogstatsd_datagram_compatibility_test.rb +0 -161
- data/test/deprecations_test.rb +0 -139
- data/test/logger_backend_test.rb +0 -22
- data/test/metric_test.rb +0 -47
- data/test/udp_backend_test.rb +0 -228
@@ -3,38 +3,9 @@
|
|
3
3
|
module StatsD::Instrument::Helpers
|
4
4
|
def capture_statsd_datagrams(client: nil, &block)
|
5
5
|
client ||= StatsD.singleton_client
|
6
|
-
|
7
|
-
when StatsD.legacy_singleton_client
|
8
|
-
capture_statsd_metrics_on_legacy_client(&block)
|
9
|
-
when StatsD::Instrument::Client
|
10
|
-
client.capture(&block)
|
11
|
-
else
|
12
|
-
raise ArgumentError, "Don't know how to capture StatsD datagrams from #{client.inspect}!"
|
13
|
-
end
|
6
|
+
client.capture(&block)
|
14
7
|
end
|
15
8
|
|
16
9
|
# For backwards compatibility
|
17
10
|
alias_method :capture_statsd_calls, :capture_statsd_datagrams
|
18
|
-
|
19
|
-
def capture_statsd_metrics_on_legacy_client(&block)
|
20
|
-
capture_backend = StatsD::Instrument::Backends::CaptureBackend.new
|
21
|
-
with_capture_backend(capture_backend, &block)
|
22
|
-
capture_backend.collected_metrics
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def with_capture_backend(backend)
|
28
|
-
if StatsD.legacy_singleton_client.backend.is_a?(StatsD::Instrument::Backends::CaptureBackend)
|
29
|
-
backend.parent = StatsD.legacy_singleton_client.backend
|
30
|
-
end
|
31
|
-
|
32
|
-
old_backend = StatsD.legacy_singleton_client.backend
|
33
|
-
begin
|
34
|
-
StatsD.legacy_singleton_client.backend = backend
|
35
|
-
yield
|
36
|
-
ensure
|
37
|
-
StatsD.legacy_singleton_client.backend = old_backend
|
38
|
-
end
|
39
|
-
end
|
40
11
|
end
|
@@ -8,8 +8,4 @@ class StatsD::Instrument::Railtie < Rails::Railtie
|
|
8
8
|
initializer 'statsd-instrument.use_rails_logger' do
|
9
9
|
::StatsD.logger = Rails.logger
|
10
10
|
end
|
11
|
-
|
12
|
-
initializer 'statsd-instrument.setup_backend', after: 'statsd-instrument.use_rails_logger' do
|
13
|
-
::StatsD.backend = ::StatsD::Instrument::Environment.default_backend
|
14
|
-
end
|
15
11
|
end
|
@@ -55,9 +55,7 @@ module StatsD
|
|
55
55
|
super
|
56
56
|
end
|
57
57
|
|
58
|
-
def service_check(name, status, tags: nil, no_prefix: false,
|
59
|
-
hostname: nil, timestamp: nil, message: nil)
|
60
|
-
|
58
|
+
def service_check(name, status, tags: nil, no_prefix: false, hostname: nil, timestamp: nil, message: nil)
|
61
59
|
super
|
62
60
|
end
|
63
61
|
|
@@ -106,133 +104,30 @@ module StatsD
|
|
106
104
|
end
|
107
105
|
end
|
108
106
|
|
109
|
-
module VoidCollectMetric
|
110
|
-
protected
|
111
|
-
|
112
|
-
def collect_metric(type, name, value, sample_rate:, tags: nil, prefix:, metadata: nil)
|
113
|
-
super
|
114
|
-
StatsD::Instrument::VOID
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
107
|
module StrictMetaprogramming
|
119
|
-
def statsd_measure(method, name, sample_rate: nil, tags: nil,
|
120
|
-
no_prefix: false, client: StatsD.singleton_client)
|
121
|
-
|
108
|
+
def statsd_measure(method, name, sample_rate: nil, tags: nil, no_prefix: false, client: nil)
|
122
109
|
check_method_and_metric_name(method, name)
|
123
|
-
|
124
|
-
# Unfortunately, we have to inline the new method implementation because we have to fix the
|
125
|
-
# Stats.measure call to not use the `as_dist` and `prefix` arguments.
|
126
|
-
add_to_method(method, name, :measure) do
|
127
|
-
define_method(method) do |*args, &block|
|
128
|
-
key = StatsD::Instrument.generate_metric_name(nil, name, self, *args)
|
129
|
-
client.measure(key, sample_rate: sample_rate, tags: tags, no_prefix: no_prefix) do
|
130
|
-
super(*args, &block)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
110
|
+
super
|
134
111
|
end
|
135
112
|
|
136
|
-
def statsd_distribution(method, name, sample_rate: nil, tags: nil,
|
137
|
-
no_prefix: false, client: StatsD.singleton_client)
|
138
|
-
|
113
|
+
def statsd_distribution(method, name, sample_rate: nil, tags: nil, no_prefix: false, client: nil)
|
139
114
|
check_method_and_metric_name(method, name)
|
140
|
-
|
141
|
-
# Unfortunately, we have to inline the new method implementation because we have to fix the
|
142
|
-
# Stats.distribution call to not use the `prefix` argument.
|
143
|
-
|
144
|
-
add_to_method(method, name, :distribution) do
|
145
|
-
define_method(method) do |*args, &block|
|
146
|
-
key = StatsD::Instrument.generate_metric_name(nil, name, self, *args)
|
147
|
-
client.distribution(key, sample_rate: sample_rate, tags: tags, no_prefix: no_prefix) do
|
148
|
-
super(*args, &block)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
115
|
+
super
|
152
116
|
end
|
153
117
|
|
154
|
-
def statsd_count_success(method, name, sample_rate: nil, tags: nil,
|
155
|
-
no_prefix: false, client: StatsD.singleton_client)
|
156
|
-
|
118
|
+
def statsd_count_success(method, name, sample_rate: nil, tags: nil, no_prefix: false, client: nil)
|
157
119
|
check_method_and_metric_name(method, name)
|
158
|
-
|
159
|
-
# Unfortunately, we have to inline the new method implementation because we have to fix the
|
160
|
-
# Stats.increment call to not use the `prefix` argument.
|
161
|
-
|
162
|
-
add_to_method(method, name, :count_success) do
|
163
|
-
define_method(method) do |*args, &block|
|
164
|
-
begin
|
165
|
-
truthiness = result = super(*args, &block)
|
166
|
-
rescue
|
167
|
-
truthiness = false
|
168
|
-
raise
|
169
|
-
else
|
170
|
-
if block_given?
|
171
|
-
begin
|
172
|
-
truthiness = yield(result)
|
173
|
-
rescue
|
174
|
-
truthiness = false
|
175
|
-
end
|
176
|
-
end
|
177
|
-
result
|
178
|
-
ensure
|
179
|
-
suffix = truthiness == false ? 'failure' : 'success'
|
180
|
-
key = "#{StatsD::Instrument.generate_metric_name(nil, name, self, *args)}.#{suffix}"
|
181
|
-
client.increment(key, sample_rate: sample_rate, tags: tags, no_prefix: no_prefix)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
120
|
+
super
|
185
121
|
end
|
186
122
|
|
187
|
-
def statsd_count_if(method, name, sample_rate: nil, tags: nil,
|
188
|
-
no_prefix: false, client: StatsD.singleton_client)
|
189
|
-
|
123
|
+
def statsd_count_if(method, name, sample_rate: nil, tags: nil, no_prefix: false, client: nil)
|
190
124
|
check_method_and_metric_name(method, name)
|
191
|
-
|
192
|
-
# Unfortunately, we have to inline the new method implementation because we have to fix the
|
193
|
-
# Stats.increment call to not use the `prefix` argument.
|
194
|
-
|
195
|
-
add_to_method(method, name, :count_if) do
|
196
|
-
define_method(method) do |*args, &block|
|
197
|
-
begin
|
198
|
-
truthiness = result = super(*args, &block)
|
199
|
-
rescue
|
200
|
-
truthiness = false
|
201
|
-
raise
|
202
|
-
else
|
203
|
-
if block_given?
|
204
|
-
begin
|
205
|
-
truthiness = yield(result)
|
206
|
-
rescue
|
207
|
-
truthiness = false
|
208
|
-
end
|
209
|
-
end
|
210
|
-
result
|
211
|
-
ensure
|
212
|
-
if truthiness
|
213
|
-
key = StatsD::Instrument.generate_metric_name(nil, name, self, *args)
|
214
|
-
client.increment(key, sample_rate: sample_rate, tags: tags, no_prefix: no_prefix)
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
125
|
+
super
|
219
126
|
end
|
220
127
|
|
221
|
-
def statsd_count(method, name, sample_rate: nil, tags: nil,
|
222
|
-
no_prefix: false, client: StatsD.singleton_client)
|
223
|
-
|
128
|
+
def statsd_count(method, name, sample_rate: nil, tags: nil, no_prefix: false, client: nil)
|
224
129
|
check_method_and_metric_name(method, name)
|
225
|
-
|
226
|
-
# Unfortunately, we have to inline the new method implementation because we have to fix the
|
227
|
-
# Stats.increment call to not use the `prefix` argument.
|
228
|
-
|
229
|
-
add_to_method(method, name, :count) do
|
230
|
-
define_method(method) do |*args, &block|
|
231
|
-
key = StatsD::Instrument.generate_metric_name(nil, name, self, *args)
|
232
|
-
client.increment(key, sample_rate: sample_rate, tags: tags, no_prefix: no_prefix)
|
233
|
-
super(*args, &block)
|
234
|
-
end
|
235
|
-
end
|
130
|
+
super
|
236
131
|
end
|
237
132
|
|
238
133
|
private
|
@@ -250,6 +145,5 @@ module StatsD
|
|
250
145
|
end
|
251
146
|
end
|
252
147
|
|
253
|
-
StatsD.
|
254
|
-
StatsD::Instrument::LegacyClient.prepend(StatsD::Instrument::VoidCollectMetric)
|
148
|
+
StatsD::Instrument::Client.prepend(StatsD::Instrument::Strict)
|
255
149
|
StatsD::Instrument.prepend(StatsD::Instrument::StrictMetaprogramming)
|
data/test/assertions_test.rb
CHANGED
@@ -132,55 +132,43 @@ class AssertionsTest < Minitest::Test
|
|
132
132
|
end
|
133
133
|
|
134
134
|
def test_assert_statsd_gauge_call_with_numeric_value
|
135
|
-
@test_case.assert_statsd_gauge('gauge', 42) do
|
135
|
+
@test_case.assert_statsd_gauge('gauge', value: 42) do
|
136
136
|
StatsD.gauge('gauge', 42)
|
137
137
|
end
|
138
138
|
|
139
|
-
@test_case.assert_statsd_gauge('gauge', '42') do
|
139
|
+
@test_case.assert_statsd_gauge('gauge', value: '42') do
|
140
140
|
StatsD.gauge('gauge', 42)
|
141
141
|
end
|
142
142
|
|
143
143
|
assert_raises(Minitest::Assertion) do
|
144
|
-
@test_case.assert_statsd_gauge('gauge', 42) do
|
144
|
+
@test_case.assert_statsd_gauge('gauge', value: 42) do
|
145
145
|
StatsD.gauge('gauge', 45)
|
146
146
|
end
|
147
147
|
end
|
148
|
-
|
149
|
-
@test_case.assert_statsd_gauge('gauge', value: 42) do
|
150
|
-
StatsD.gauge('gauge', 42)
|
151
|
-
end
|
152
148
|
end
|
153
149
|
|
154
150
|
def test_assert_statsd_set_call_with_string_value
|
155
|
-
@test_case.assert_statsd_set('set', 12345) do
|
151
|
+
@test_case.assert_statsd_set('set', value: 12345) do
|
156
152
|
StatsD.set('set', '12345')
|
157
153
|
end
|
158
154
|
|
159
|
-
@test_case.assert_statsd_set('set', '12345') do
|
155
|
+
@test_case.assert_statsd_set('set', value: '12345') do
|
160
156
|
StatsD.set('set', '12345')
|
161
157
|
end
|
162
158
|
|
163
|
-
@test_case.assert_statsd_set('set', 12345) do
|
159
|
+
@test_case.assert_statsd_set('set', value: 12345) do
|
164
160
|
StatsD.set('set', 12345)
|
165
161
|
end
|
166
162
|
|
167
|
-
@test_case.assert_statsd_set('set', '12345') do
|
163
|
+
@test_case.assert_statsd_set('set', value: '12345') do
|
168
164
|
StatsD.set('set', 12345)
|
169
165
|
end
|
170
166
|
|
171
167
|
assert_raises(Minitest::Assertion) do
|
172
|
-
@test_case.assert_statsd_set('set', '42') do
|
168
|
+
@test_case.assert_statsd_set('set', value: '42') do
|
173
169
|
StatsD.set('set', 45)
|
174
170
|
end
|
175
171
|
end
|
176
|
-
|
177
|
-
@test_case.assert_statsd_set('set', value: 12345) do
|
178
|
-
StatsD.set('set', '12345')
|
179
|
-
end
|
180
|
-
|
181
|
-
@test_case.assert_statsd_set('set', 'wrong_value', value: 12345) do
|
182
|
-
StatsD.set('set', '12345')
|
183
|
-
end
|
184
172
|
end
|
185
173
|
|
186
174
|
def test_tags_will_match_subsets
|
@@ -297,7 +285,7 @@ class AssertionsTest < Minitest::Test
|
|
297
285
|
end
|
298
286
|
|
299
287
|
foo_1_metric = StatsD::Instrument::Expectation.increment('counter', times: 2, tags: ['foo:1'])
|
300
|
-
foo_2_metric = StatsD::Instrument::Expectation.increment('counter',
|
288
|
+
foo_2_metric = StatsD::Instrument::Expectation.increment('counter', tags: ['foo:2'])
|
301
289
|
@test_case.assert_statsd_expectations([foo_1_metric, foo_2_metric]) do
|
302
290
|
StatsD.increment('counter', tags: { foo: 1 })
|
303
291
|
StatsD.increment('counter', tags: { foo: 1 })
|
data/test/client_test.rb
CHANGED
@@ -186,6 +186,17 @@ class ClientTest < Minitest::Test
|
|
186
186
|
assert_equal "bar", datagrams[1].name
|
187
187
|
end
|
188
188
|
|
189
|
+
def test_default_tags_normalization
|
190
|
+
client = StatsD::Instrument::Client.new(default_tags: { first_tag: 'f|irst_value', second_tag: 'sec,ond_value' })
|
191
|
+
datagrams = client.capture do
|
192
|
+
client.increment('bar', tags: ['th|ird_#,tag'])
|
193
|
+
end
|
194
|
+
|
195
|
+
assert_includes datagrams.first.tags, 'first_tag:first_value'
|
196
|
+
assert_includes datagrams.first.tags, 'second_tag:second_value'
|
197
|
+
assert_includes datagrams.first.tags, 'third_#tag'
|
198
|
+
end
|
199
|
+
|
189
200
|
def test_sampling
|
190
201
|
mock_sink = mock('sink')
|
191
202
|
mock_sink.stubs(:sample?).returns(false, true, false, false, true)
|
data/test/environment_test.rb
CHANGED
@@ -5,37 +5,6 @@ require 'test_helper'
|
|
5
5
|
module Rails; end
|
6
6
|
|
7
7
|
class EnvironmentTest < Minitest::Test
|
8
|
-
def setup
|
9
|
-
ENV['STATSD_ADDR'] = nil
|
10
|
-
ENV['IMPLEMENTATION'] = nil
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_default_backend_uses_logger_in_development_environment
|
14
|
-
StatsD::Instrument::Environment.stubs(:environment).returns('development')
|
15
|
-
assert_instance_of StatsD::Instrument::Backends::LoggerBackend, StatsD::Instrument::Environment.default_backend
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_default_backend_uses_null_backend_in_test_environment
|
19
|
-
StatsD::Instrument::Environment.stubs(:environment).returns('test')
|
20
|
-
assert_instance_of StatsD::Instrument::Backends::NullBackend, StatsD::Instrument::Environment.default_backend
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_default_backend_uses_udp_backend_in_production_environment
|
24
|
-
StatsD::Instrument::Environment.stubs(:environment).returns('production')
|
25
|
-
assert_instance_of StatsD::Instrument::Backends::UDPBackend, StatsD::Instrument::Environment.default_backend
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_default_backend_uses_environment_variables_in_production_environment
|
29
|
-
StatsD::Instrument::Environment.stubs(:environment).returns('production')
|
30
|
-
ENV['STATSD_ADDR'] = '127.0.0.1:1234'
|
31
|
-
ENV['STATSD_IMPLEMENTATION'] = 'datadog'
|
32
|
-
|
33
|
-
backend = StatsD::Instrument::Environment.default_backend
|
34
|
-
assert_equal '127.0.0.1', backend.host
|
35
|
-
assert_equal 1234, backend.port
|
36
|
-
assert_equal :datadog, backend.implementation
|
37
|
-
end
|
38
|
-
|
39
8
|
def test_environment_prefers_statsd_env_if_available
|
40
9
|
env = StatsD::Instrument::Environment.new(
|
41
10
|
'STATSD_ENV' => 'set_from_STATSD_ENV',
|
@@ -62,13 +31,8 @@ class EnvironmentTest < Minitest::Test
|
|
62
31
|
assert_equal 'development', env.environment
|
63
32
|
end
|
64
33
|
|
65
|
-
def
|
34
|
+
def test_client_returns_client_instance
|
66
35
|
env = StatsD::Instrument::Environment.new({})
|
67
|
-
assert_kind_of StatsD::Instrument::LegacyClient, env.client
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_client_returns_new_client_if_environment_asks_for_it
|
71
|
-
env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1')
|
72
36
|
assert_kind_of StatsD::Instrument::Client, env.client
|
73
37
|
end
|
74
38
|
|
data/test/integration_test.rb
CHANGED
@@ -6,39 +6,24 @@ class IntegrationTest < Minitest::Test
|
|
6
6
|
def setup
|
7
7
|
@server = UDPSocket.new
|
8
8
|
@server.bind('localhost', 0)
|
9
|
-
port = @server.addr[1]
|
10
9
|
|
11
|
-
@
|
12
|
-
|
10
|
+
@env = StatsD::Instrument::Environment.new(
|
11
|
+
'STATSD_ADDR' => "#{@server.addr[2]}:#{@server.addr[1]}",
|
12
|
+
'STATSD_IMPLEMENTATION' => 'dogstatsd',
|
13
|
+
'STATSD_ENV' => 'production',
|
14
|
+
)
|
15
|
+
|
16
|
+
@old_client = StatsD.singleton_client
|
17
|
+
StatsD.singleton_client = @env.client
|
13
18
|
end
|
14
19
|
|
15
20
|
def teardown
|
21
|
+
StatsD.singleton_client = @old_client
|
16
22
|
@server.close
|
17
|
-
StatsD.backend = @old_backend
|
18
23
|
end
|
19
24
|
|
20
25
|
def test_live_local_udp_socket
|
21
26
|
StatsD.increment('counter')
|
22
27
|
assert_equal "counter:1|c", @server.recvfrom(100).first
|
23
28
|
end
|
24
|
-
|
25
|
-
def test_synchronize_in_exit_handler_handles_thread_error_and_exits_cleanly
|
26
|
-
pid = fork do
|
27
|
-
Signal.trap('TERM') do
|
28
|
-
StatsD.increment('exiting')
|
29
|
-
Process.exit!(0)
|
30
|
-
end
|
31
|
-
|
32
|
-
sleep 100
|
33
|
-
end
|
34
|
-
|
35
|
-
Process.kill('TERM', pid)
|
36
|
-
_, exit_status = Process.waitpid2(pid)
|
37
|
-
|
38
|
-
assert_equal 0, exit_status, "The forked process did not exit cleanly"
|
39
|
-
assert_equal "exiting:1|c", @server.recvfrom_nonblock(100).first
|
40
|
-
|
41
|
-
rescue NotImplementedError
|
42
|
-
pass("Fork is not implemented on #{RUBY_PLATFORM}")
|
43
|
-
end
|
44
29
|
end
|
@@ -326,30 +326,42 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
326
326
|
end
|
327
327
|
|
328
328
|
def test_statsd_respects_global_prefix_changes
|
329
|
-
|
329
|
+
old_client = StatsD.singleton_client
|
330
|
+
|
331
|
+
StatsD.singleton_client = StatsD::Instrument::Client.new(prefix: 'Foo')
|
330
332
|
ActiveMerchant::Gateway.singleton_class.extend StatsD::Instrument
|
331
333
|
ActiveMerchant::Gateway.singleton_class.statsd_count :sync, 'ActiveMerchant.Gateway.sync'
|
332
|
-
StatsD.
|
334
|
+
StatsD.singleton_client = StatsD::Instrument::Client.new(prefix: 'Quc')
|
333
335
|
|
334
|
-
|
335
|
-
assert_equal 1,
|
336
|
-
assert_equal "Quc.ActiveMerchant.Gateway.sync",
|
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
339
|
ensure
|
338
|
-
StatsD.
|
340
|
+
StatsD.singleton_client = old_client
|
339
341
|
ActiveMerchant::Gateway.singleton_class.statsd_remove_count :sync, 'ActiveMerchant.Gateway.sync'
|
340
342
|
end
|
341
343
|
|
344
|
+
def test_statsd_count_with_injected_client
|
345
|
+
client = StatsD::Instrument::Client.new(prefix: 'prefix')
|
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
|
349
|
+
ActiveMerchant::Gateway.new.purchase(true)
|
350
|
+
end
|
351
|
+
ensure
|
352
|
+
ActiveMerchant::Gateway.statsd_remove_count :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
|
353
|
+
end
|
354
|
+
|
342
355
|
def test_statsd_macro_can_disable_prefix
|
343
|
-
StatsD.prefix
|
356
|
+
client = StatsD::Instrument::Client.new(prefix: 'foo')
|
344
357
|
ActiveMerchant::Gateway.singleton_class.extend StatsD::Instrument
|
345
|
-
ActiveMerchant::Gateway.singleton_class.statsd_count_success
|
346
|
-
|
358
|
+
ActiveMerchant::Gateway.singleton_class.statsd_count_success(:sync,
|
359
|
+
'ActiveMerchant.Gateway.sync', no_prefix: true, client: client)
|
347
360
|
|
348
|
-
|
349
|
-
assert_equal 1,
|
350
|
-
assert_equal "ActiveMerchant.Gateway.sync.success",
|
361
|
+
datagrams = client.capture { ActiveMerchant::Gateway.sync }
|
362
|
+
assert_equal 1, datagrams.length
|
363
|
+
assert_equal "ActiveMerchant.Gateway.sync.success", datagrams.first.name
|
351
364
|
ensure
|
352
|
-
StatsD.prefix = nil
|
353
365
|
ActiveMerchant::Gateway.singleton_class.statsd_remove_count_success :sync, 'ActiveMerchant.Gateway.sync'
|
354
366
|
end
|
355
367
|
|
@@ -417,43 +429,6 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
417
429
|
end
|
418
430
|
end
|
419
431
|
|
420
|
-
def test_statsd_measure_with_new_client
|
421
|
-
old_client = StatsD.singleton_client
|
422
|
-
StatsD.singleton_client = StatsD::Instrument::Client.new
|
423
|
-
|
424
|
-
ActiveMerchant::UniqueGateway.statsd_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3
|
425
|
-
assert_statsd_measure('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3) do
|
426
|
-
ActiveMerchant::UniqueGateway.new.purchase(true)
|
427
|
-
end
|
428
|
-
ensure
|
429
|
-
ActiveMerchant::UniqueGateway.statsd_remove_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
|
430
|
-
StatsD.singleton_client = old_client
|
431
|
-
end
|
432
|
-
|
433
|
-
def test_statsd_count_with_new_client
|
434
|
-
old_client = StatsD.singleton_client
|
435
|
-
StatsD.singleton_client = StatsD::Instrument::Client.new
|
436
|
-
|
437
|
-
ActiveMerchant::Gateway.statsd_count :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
|
438
|
-
assert_statsd_increment('ActiveMerchant.Gateway.ssl_post') do
|
439
|
-
ActiveMerchant::Gateway.new.purchase(true)
|
440
|
-
end
|
441
|
-
ensure
|
442
|
-
ActiveMerchant::Gateway.statsd_remove_count :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
|
443
|
-
StatsD.singleton_client = old_client
|
444
|
-
end
|
445
|
-
|
446
|
-
def test_statsd_count_with_injected_client
|
447
|
-
client = StatsD::Instrument::Client.new(prefix: 'prefix')
|
448
|
-
|
449
|
-
ActiveMerchant::Gateway.statsd_count(:ssl_post, 'ActiveMerchant.Gateway.ssl_post', client: client)
|
450
|
-
assert_statsd_increment('prefix.ActiveMerchant.Gateway.ssl_post', client: client) do
|
451
|
-
ActiveMerchant::Gateway.new.purchase(true)
|
452
|
-
end
|
453
|
-
ensure
|
454
|
-
ActiveMerchant::Gateway.statsd_remove_count :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
|
455
|
-
end
|
456
|
-
|
457
432
|
private
|
458
433
|
|
459
434
|
def assert_scope(klass, method, expected_scope)
|