statsd-instrument 2.4.0 → 2.5.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/benchmark.yml +32 -0
- data/.github/workflows/ci.yml +24 -8
- data/.rubocop.yml +24 -0
- data/CHANGELOG.md +116 -3
- data/CONTRIBUTING.md +8 -6
- data/Gemfile +3 -0
- data/Rakefile +1 -1
- data/benchmark/README.md +29 -0
- data/benchmark/send-metrics-to-dev-null-log +47 -0
- data/benchmark/send-metrics-to-local-udp-receiver +57 -0
- data/lib/statsd/instrument.rb +126 -94
- data/lib/statsd/instrument/assertions.rb +69 -37
- data/lib/statsd/instrument/backends/capture_backend.rb +2 -0
- data/lib/statsd/instrument/helpers.rb +12 -8
- data/lib/statsd/instrument/metric.rb +56 -42
- data/lib/statsd/instrument/rubocop/metaprogramming_positional_arguments.rb +46 -0
- data/lib/statsd/instrument/rubocop/metric_return_value.rb +31 -0
- data/lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb +45 -0
- data/lib/statsd/instrument/rubocop/positional_arguments.rb +99 -0
- data/lib/statsd/instrument/rubocop/splat_arguments.rb +37 -0
- data/lib/statsd/instrument/strict.rb +145 -0
- data/lib/statsd/instrument/version.rb +1 -1
- data/test/assertions_test.rb +37 -0
- data/test/benchmark/clock_gettime.rb +27 -0
- data/test/benchmark/default_tags.rb +1 -1
- data/test/deprecations_test.rb +86 -0
- data/test/helpers/rubocop_helper.rb +47 -0
- data/test/integration_test.rb +6 -2
- data/test/matchers_test.rb +9 -9
- data/test/metric_test.rb +3 -18
- data/test/rubocop/metaprogramming_positional_arguments_test.rb +58 -0
- data/test/rubocop/metric_return_value_test.rb +78 -0
- data/test/rubocop/metric_value_keyword_argument_test.rb +39 -0
- data/test/rubocop/positional_arguments_test.rb +110 -0
- data/test/rubocop/splat_arguments_test.rb +27 -0
- data/test/statsd_instrumentation_test.rb +77 -86
- data/test/statsd_test.rb +32 -65
- data/test/test_helper.rb +12 -1
- data/test/udp_backend_test.rb +8 -0
- metadata +28 -2
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'statsd/instrument/rubocop/metaprogramming_positional_arguments'
|
5
|
+
|
6
|
+
module Rubocop
|
7
|
+
class MetaprogrammingPositionalArgumentsTest < Minitest::Test
|
8
|
+
include RubocopHelper
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@cop = RuboCop::Cop::StatsD::MetaprogrammingPositionalArguments.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_ok_with_two_arguments
|
15
|
+
assert_no_offenses("ClassName.statsd_count_if(:method, 'metric') { foo }")
|
16
|
+
assert_no_offenses("ClassName.statsd_measure :method, 'metric'")
|
17
|
+
assert_no_offenses(<<~RUBY)
|
18
|
+
class Foo
|
19
|
+
statsd_count :method, 'metric'
|
20
|
+
end
|
21
|
+
RUBY
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_ok_with_keyword_arguments_and_blocks
|
25
|
+
assert_no_offenses("ClassName.statsd_measure :method, 'metric', foo: 'bar'")
|
26
|
+
assert_no_offenses("ClassName.statsd_count_success(:method, 'metric', **kwargs)")
|
27
|
+
assert_no_offenses("ClassName.statsd_measure(:method, 'metric', foo: 'bar', &block)")
|
28
|
+
assert_no_offenses(<<~RUBY)
|
29
|
+
class Foo
|
30
|
+
statsd_count_if(:method, 'metric', foo: 'bar', baz: 'quc') do |result|
|
31
|
+
result == 'ok'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
RUBY
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_offense_with_positional_arguments
|
38
|
+
assert_offense("ClassName.statsd_measure(:method, 'metric', 1)")
|
39
|
+
assert_offense("ClassName.statsd_measure(:method, 'metric', 1, ['tag'])")
|
40
|
+
assert_offense("ClassName.statsd_measure(:method, 'metric', 1, tag: 'value')")
|
41
|
+
assert_offense(<<~RUBY)
|
42
|
+
class Foo
|
43
|
+
extend StatsD::Instrument
|
44
|
+
statsd_measure(:method, 'metric', 1)
|
45
|
+
end
|
46
|
+
RUBY
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_offense_with_splat
|
50
|
+
assert_offense("ClassName.statsd_measure(:method, 'metric', *options)")
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_offense_with_constant_or_method_as_third_argument
|
54
|
+
assert_offense("ClassName.statsd_measure(:method, 'metric', SAMPLE_RATE_CONSTANT)")
|
55
|
+
assert_offense("ClassName.statsd_measure(:method, 'metric', method_returning_a_hash)")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'statsd/instrument/rubocop/metric_return_value'
|
5
|
+
|
6
|
+
module Rubocop
|
7
|
+
class MetricReturnValueTest < Minitest::Test
|
8
|
+
include RubocopHelper
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@cop = RuboCop::Cop::StatsD::MetricReturnValue.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_ok_for_non_metric_method
|
15
|
+
assert_no_offenses('backend = StatsD.backend')
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_ok_as_naked_statement
|
19
|
+
assert_no_offenses("StatsD.increment('foo')")
|
20
|
+
assert_no_offenses("StatsD.measure('foo') { foo }")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_ok_as_multiple_statement
|
24
|
+
assert_no_offenses <<~RUBY
|
25
|
+
StatsD.increment 'foo'
|
26
|
+
StatsD.increment 'bar'
|
27
|
+
RUBY
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_ok_inside_block
|
31
|
+
assert_no_offenses <<~RUBY
|
32
|
+
block do
|
33
|
+
StatsD.measure
|
34
|
+
end
|
35
|
+
RUBY
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_ok_when_passing_a_block_as_param
|
39
|
+
assert_no_offenses("block_result = StatsD.measure('foo', &block)")
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_ok_when_passing_a_curly_braces_block
|
43
|
+
assert_no_offenses("block_result = StatsD.measure('foo') { measure_me }")
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_ok_when_passing_do_end_block
|
47
|
+
assert_no_offenses <<~RUBY
|
48
|
+
block_result = StatsD.measure('foo') do
|
49
|
+
return_something_useful
|
50
|
+
end
|
51
|
+
RUBY
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_offense_in_assignment
|
55
|
+
assert_offense("metric = StatsD.increment('foo')")
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_offense_in_multi_assignment
|
59
|
+
assert_offense("foo, metric = bar, StatsD.increment('foo')")
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_offense_in_hash
|
63
|
+
assert_offense("{ metric: StatsD.increment('foo') }")
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_offense_in_method_call
|
67
|
+
assert_offense("process(StatsD.increment('foo'))")
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_offense_when_returning
|
71
|
+
assert_offense("return StatsD.increment('foo')")
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_offense_when_yielding
|
75
|
+
assert_offense("yield StatsD.increment('foo')")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'statsd/instrument/rubocop/metric_value_keyword_argument'
|
5
|
+
|
6
|
+
module Rubocop
|
7
|
+
class MetricValueKeywordArgumentTest < Minitest::Test
|
8
|
+
include RubocopHelper
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@cop = RuboCop::Cop::StatsD::MetricValueKeywordArgument.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_ok_for_method_without_arguments
|
15
|
+
assert_no_offenses("StatsD.increment")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_ok_for_non_metric_method
|
19
|
+
assert_no_offenses("StatsD.backend('foo', value: 1)")
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_ok_with_no_keywords
|
23
|
+
assert_no_offenses("StatsD.increment('foo', 1)")
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_ok_with_no_matching_keyword
|
27
|
+
assert_no_offenses("StatsD.increment('foo', 1, tags: ['foo'])")
|
28
|
+
assert_no_offenses("StatsD.increment('foo', 1, tags: { value: 'bar' })")
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_offense_with_value_keyword
|
32
|
+
assert_offense("StatsD.increment('foo', value: 1)")
|
33
|
+
assert_offense("StatsD.increment('foo', :value => 1)")
|
34
|
+
assert_offense("StatsD.increment('foo', 'value' => 1)")
|
35
|
+
assert_offense("StatsD.increment('foo', sample_rate: 0.1, value: 1, tags: ['foo'])")
|
36
|
+
assert_offense("StatsD.increment('foo', value: 1, &block)")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'statsd/instrument/rubocop/positional_arguments'
|
5
|
+
|
6
|
+
module Rubocop
|
7
|
+
class PositionalArgumentsTest < Minitest::Test
|
8
|
+
include RubocopHelper
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@cop = RuboCop::Cop::StatsD::PositionalArguments.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_no_offenses
|
15
|
+
assert_no_offenses("StatsD.increment 'foo'")
|
16
|
+
assert_no_offenses("StatsD.gauge('foo', 2)")
|
17
|
+
assert_no_offenses("StatsD.increment('foo', 2, tags: ['foo:bar'])")
|
18
|
+
assert_no_offenses("StatsD.increment('foo', 2, sample_rate: 0.1, tags: { foo: 'bar' })")
|
19
|
+
assert_no_offenses("StatsD.increment('foo', 2) { foo }")
|
20
|
+
assert_no_offenses("StatsD.increment('foo', 2, &block)")
|
21
|
+
assert_no_offenses("StatsD.gauge('foo', 2, **kwargs)")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_no_offense_for_now_when_using_value_keyword_argumenr
|
25
|
+
assert_no_offenses("StatsD.increment 'foo', value: 3")
|
26
|
+
assert_no_offenses("StatsD.increment 'foo', value: 3, sample_rate: 0.5")
|
27
|
+
assert_no_offenses("StatsD.increment('foo', value: 3, tags: ['foo']) { foo }")
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_offense_when_using_method_or_constant
|
31
|
+
assert_offense("StatsD.gauge('foo', 2, SAMPLE_RATE_CONSTANT)")
|
32
|
+
assert_offense("StatsD.gauge('foo', 2, method_ruturning_a_hash)")
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_offense_when_using_local_variable
|
36
|
+
assert_offense("lambda { |x| StatsD.gauge('foo', 2, x) }")
|
37
|
+
assert_offense(<<~RUBY)
|
38
|
+
x = foo
|
39
|
+
StatsD.gauge('foo', 2, x)
|
40
|
+
RUBY
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_offense_when_using_splat
|
44
|
+
assert_offense("StatsD.gauge('foo', 2, *options)")
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_no_autocorrect_when_using_method_or_constant
|
48
|
+
assert_no_autocorrect("StatsD.gauge('foo', 2, SAMPLE_RATE_CONSTANT)")
|
49
|
+
assert_no_autocorrect("StatsD.gauge('foo', 2, method_ruturning_a_hash)")
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_autocorrect_only_sample_rate
|
53
|
+
corrected = autocorrect_source("StatsD.increment('foo', 2, 0.5)")
|
54
|
+
assert_equal "StatsD.increment('foo', 2, sample_rate: 0.5)", corrected
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_autocorrect_only_sample_rate_as_int
|
58
|
+
corrected = autocorrect_source("StatsD.increment('foo', 2, 1)")
|
59
|
+
assert_equal "StatsD.increment('foo', 2, sample_rate: 1)", corrected
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_autocorrect_only_tags
|
63
|
+
corrected = autocorrect_source("StatsD.increment('foo', 2, nil, ['foo', 'bar'])")
|
64
|
+
assert_equal "StatsD.increment('foo', 2, tags: ['foo', 'bar'])", corrected
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_autocorrect_sample_rate_and_tags_as_array
|
68
|
+
corrected = autocorrect_source("StatsD.increment('foo', 2, 0.5, ['foo', 'bar'])")
|
69
|
+
assert_equal "StatsD.increment('foo', 2, sample_rate: 0.5, tags: ['foo', 'bar'])", corrected
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_autocorrect_sample_rate_and_tags_as_hash_with_curly_braces
|
73
|
+
corrected = autocorrect_source("StatsD.increment('foo', 2, 0.5, { foo: 'bar' })")
|
74
|
+
assert_equal "StatsD.increment('foo', 2, sample_rate: 0.5, tags: { foo: 'bar' })", corrected
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_autocorrect_sample_rate_and_tags_as_hash_without_curly_braces
|
78
|
+
corrected = autocorrect_source("StatsD.increment('foo', 2, 0.5, foo: 'bar')")
|
79
|
+
assert_equal "StatsD.increment('foo', 2, sample_rate: 0.5, tags: { foo: 'bar' })", corrected
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_autocorrect_sample_rate_and_block_pass
|
83
|
+
corrected = autocorrect_source("StatsD.distribution('foo', 2, 0.5, &block)")
|
84
|
+
assert_equal "StatsD.distribution('foo', 2, sample_rate: 0.5, &block)", corrected
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_autocorrect_sample_rate_tags_and_block_pass
|
88
|
+
corrected = autocorrect_source("StatsD.measure('foo', 2, nil, foo: 'bar', &block)")
|
89
|
+
assert_equal "StatsD.measure('foo', 2, tags: { foo: 'bar' }, &block)", corrected
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_autocorrect_sample_rate_and_curly_braces_block
|
93
|
+
corrected = autocorrect_source("StatsD.measure('foo', 2, 0.5) { foo }")
|
94
|
+
assert_equal "StatsD.measure('foo', 2, sample_rate: 0.5) { foo }", corrected
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_autocorrect_sample_rate_and_do_end_block
|
98
|
+
corrected = autocorrect_source(<<~RUBY)
|
99
|
+
StatsD.distribution 'foo', 124, 0.6, ['bar'] do
|
100
|
+
foo
|
101
|
+
end
|
102
|
+
RUBY
|
103
|
+
assert_equal <<~RUBY, corrected
|
104
|
+
StatsD.distribution 'foo', 124, sample_rate: 0.6, tags: ['bar'] do
|
105
|
+
foo
|
106
|
+
end
|
107
|
+
RUBY
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'statsd/instrument/rubocop/splat_arguments'
|
5
|
+
|
6
|
+
module Rubocop
|
7
|
+
class SplatArgumentsTest < Minitest::Test
|
8
|
+
include RubocopHelper
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@cop = RuboCop::Cop::StatsD::SplatArguments.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_no_offenses
|
15
|
+
assert_no_offenses("StatsD.increment 'foo'")
|
16
|
+
assert_no_offenses("StatsD.gauge('foo', 2, tags: 'foo')")
|
17
|
+
assert_no_offenses("StatsD.measure('foo', 2, **kwargs)")
|
18
|
+
assert_no_offenses("StatsD.measure('foo', 2, **kwargs) { }")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_offenses
|
22
|
+
assert_offense("StatsD.increment(*increment_arguments)")
|
23
|
+
assert_offense("StatsD.gauge('foo', 2, *options)")
|
24
|
+
assert_offense("StatsD.measure('foo', 2, *options, &block)")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -2,74 +2,74 @@
|
|
2
2
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
'OK'
|
10
|
-
else
|
11
|
-
raise 'Not OK'
|
12
|
-
end
|
13
|
-
end
|
5
|
+
class StatsDInstrumentationTest < Minitest::Test
|
6
|
+
module ActiveMerchant
|
7
|
+
class Base
|
8
|
+
extend StatsD::Instrument
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
def ssl_post(arg)
|
11
|
+
if arg
|
12
|
+
'OK'
|
13
|
+
else
|
14
|
+
raise 'Not OK'
|
15
|
+
end
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
rescue
|
25
|
-
false
|
26
|
-
end
|
18
|
+
def post_with_block(&block)
|
19
|
+
block.call if block_given?
|
20
|
+
end
|
21
|
+
end
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
class Gateway < Base
|
24
|
+
def purchase(arg)
|
25
|
+
ssl_post(arg)
|
26
|
+
true
|
27
|
+
rescue
|
28
|
+
false
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
31
|
+
def self.sync
|
32
|
+
true
|
33
|
+
end
|
34
|
+
end
|
36
35
|
|
37
|
-
class
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
class UniqueGateway < Base
|
37
|
+
def ssl_post(arg)
|
38
|
+
{ success: arg }
|
39
|
+
end
|
41
40
|
|
42
|
-
|
43
|
-
|
41
|
+
def purchase(arg)
|
42
|
+
ssl_post(arg)
|
43
|
+
end
|
44
|
+
end
|
44
45
|
end
|
45
|
-
end
|
46
46
|
|
47
|
-
class GatewaySubClass < ActiveMerchant::Gateway
|
48
|
-
|
47
|
+
class GatewaySubClass < ActiveMerchant::Gateway
|
48
|
+
def metric_name
|
49
|
+
'subgateway'
|
50
|
+
end
|
51
|
+
end
|
49
52
|
|
50
|
-
class InstrumentedClass
|
51
|
-
|
53
|
+
class InstrumentedClass
|
54
|
+
extend StatsD::Instrument
|
52
55
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
+
def public_and_instrumented
|
57
|
+
end
|
58
|
+
statsd_count :public_and_instrumented, 'InstrumentedClass.public_and_instrumented'
|
56
59
|
|
57
|
-
|
60
|
+
protected
|
58
61
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
+
def protected_and_instrumented
|
63
|
+
end
|
64
|
+
statsd_count :protected_and_instrumented, 'InstrumentedClass.protected_and_instrumented'
|
62
65
|
|
63
|
-
|
66
|
+
private
|
64
67
|
|
65
|
-
|
68
|
+
def private_and_instrumented
|
69
|
+
end
|
70
|
+
statsd_count :private_and_instrumented, 'InstrumentedClass.private_and_instrumented'
|
66
71
|
end
|
67
|
-
statsd_count :private_and_instrumented, 'InstrumentedClass.private_and_instrumented'
|
68
|
-
end
|
69
72
|
|
70
|
-
ActiveMerchant::Base.extend StatsD::Instrument
|
71
|
-
|
72
|
-
class StatsDInstrumentationTest < Minitest::Test
|
73
73
|
include StatsD::Instrument::Assertions
|
74
74
|
|
75
75
|
def test_statsd_count_if
|
@@ -110,7 +110,7 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def test_statsd_count_success
|
113
|
-
ActiveMerchant::Gateway.statsd_count_success :ssl_post, 'ActiveMerchant.Gateway', 0.5
|
113
|
+
ActiveMerchant::Gateway.statsd_count_success :ssl_post, 'ActiveMerchant.Gateway', sample_rate: 0.5
|
114
114
|
|
115
115
|
assert_statsd_increment('ActiveMerchant.Gateway.success', sample_rate: 0.5, times: 1) do
|
116
116
|
ActiveMerchant::Gateway.new.purchase(true)
|
@@ -170,11 +170,22 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
170
170
|
end
|
171
171
|
|
172
172
|
def test_statsd_count_with_name_as_lambda
|
173
|
-
metric_namer = lambda { |object, args| object.
|
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
|
+
end
|
179
|
+
ensure
|
180
|
+
ActiveMerchant::Gateway.statsd_remove_count(:ssl_post, metric_namer)
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_statsd_count_with_name_as_proc
|
184
|
+
metric_namer = proc { |object, args| "#{object.metric_name}.#{args.first}" }
|
185
|
+
ActiveMerchant::Gateway.statsd_count(:ssl_post, metric_namer)
|
186
|
+
|
187
|
+
assert_statsd_increment('subgateway.foo') do
|
188
|
+
GatewaySubClass.new.purchase('foo')
|
178
189
|
end
|
179
190
|
ensure
|
180
191
|
ActiveMerchant::Gateway.statsd_remove_count(:ssl_post, metric_namer)
|
@@ -227,37 +238,17 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
227
238
|
ActiveMerchant::Base.statsd_remove_measure :post_with_block, 'ActiveMerchant.Base.post_with_block'
|
228
239
|
end
|
229
240
|
|
230
|
-
def
|
231
|
-
ActiveMerchant::UniqueGateway.statsd_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post', 1
|
232
|
-
|
233
|
-
assert_statsd_measure('ActiveMerchant.Gateway.ssl_post') do
|
234
|
-
ActiveMerchant::UniqueGateway.new.purchase(true)
|
235
|
-
end
|
236
|
-
ensure
|
237
|
-
ActiveMerchant::UniqueGateway.statsd_remove_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_statsd_measure_with_value_and_options
|
241
|
-
ActiveMerchant::UniqueGateway.statsd_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post', 1, sample_rate: 0.45
|
241
|
+
def test_statsd_measure_with_sample_rate
|
242
|
+
ActiveMerchant::UniqueGateway.statsd_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1
|
242
243
|
|
243
|
-
assert_statsd_measure('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.
|
244
|
+
assert_statsd_measure('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1) do
|
244
245
|
ActiveMerchant::UniqueGateway.new.purchase(true)
|
245
246
|
end
|
246
247
|
ensure
|
247
248
|
ActiveMerchant::UniqueGateway.statsd_remove_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
|
248
249
|
end
|
249
250
|
|
250
|
-
def
|
251
|
-
ActiveMerchant::UniqueGateway.statsd_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post', 1, as_dist: true
|
252
|
-
|
253
|
-
assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post') do
|
254
|
-
ActiveMerchant::UniqueGateway.new.purchase(true)
|
255
|
-
end
|
256
|
-
ensure
|
257
|
-
ActiveMerchant::UniqueGateway.statsd_remove_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
|
258
|
-
end
|
259
|
-
|
260
|
-
def test_statsd_measure_without_value_as_distribution
|
251
|
+
def test_statsd_measure_as_distribution
|
261
252
|
ActiveMerchant::UniqueGateway.statsd_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post', as_dist: true
|
262
253
|
|
263
254
|
assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post') do
|
@@ -304,20 +295,20 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
304
295
|
ActiveMerchant::Base.statsd_remove_distribution :post_with_block, 'ActiveMerchant.Base.post_with_block'
|
305
296
|
end
|
306
297
|
|
307
|
-
def
|
308
|
-
ActiveMerchant::UniqueGateway.statsd_distribution :ssl_post, 'ActiveMerchant.Gateway.ssl_post',
|
298
|
+
def test_statsd_distribution_with_tags
|
299
|
+
ActiveMerchant::UniqueGateway.statsd_distribution :ssl_post, 'ActiveMerchant.Gateway.ssl_post', tags: ['foo']
|
309
300
|
|
310
|
-
assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post') do
|
301
|
+
assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post', tags: ['foo']) do
|
311
302
|
ActiveMerchant::UniqueGateway.new.purchase(true)
|
312
303
|
end
|
313
304
|
ensure
|
314
305
|
ActiveMerchant::UniqueGateway.statsd_remove_distribution :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
|
315
306
|
end
|
316
307
|
|
317
|
-
def
|
318
|
-
ActiveMerchant::UniqueGateway.statsd_distribution :ssl_post, 'ActiveMerchant.Gateway.ssl_post',
|
308
|
+
def test_statsd_distribution_with_sample_rate
|
309
|
+
ActiveMerchant::UniqueGateway.statsd_distribution :ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1
|
319
310
|
|
320
|
-
assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.
|
311
|
+
assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1) do
|
321
312
|
ActiveMerchant::UniqueGateway.new.purchase(true)
|
322
313
|
end
|
323
314
|
ensure
|