statsd-instrument 2.3.5 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +1 -0
- data/.github/workflows/ci.yml +31 -0
- data/.gitignore +1 -0
- data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +1027 -0
- data/.rubocop.yml +21 -0
- data/CHANGELOG.md +9 -0
- data/CONTRIBUTING.md +25 -5
- data/Gemfile +2 -0
- data/Rakefile +3 -1
- data/lib/statsd-instrument.rb +2 -0
- data/lib/statsd/instrument.rb +51 -18
- data/lib/statsd/instrument/assertions.rb +24 -18
- data/lib/statsd/instrument/backend.rb +3 -2
- data/lib/statsd/instrument/backends/capture_backend.rb +2 -1
- data/lib/statsd/instrument/backends/logger_backend.rb +3 -3
- data/lib/statsd/instrument/backends/null_backend.rb +2 -0
- data/lib/statsd/instrument/backends/udp_backend.rb +18 -15
- data/lib/statsd/instrument/environment.rb +2 -0
- data/lib/statsd/instrument/helpers.rb +6 -2
- data/lib/statsd/instrument/matchers.rb +14 -11
- data/lib/statsd/instrument/metric.rb +34 -21
- data/lib/statsd/instrument/metric_expectation.rb +32 -18
- data/lib/statsd/instrument/railtie.rb +2 -1
- data/lib/statsd/instrument/version.rb +3 -1
- data/statsd-instrument.gemspec +13 -10
- data/test/assertions_test.rb +15 -4
- data/test/benchmark/default_tags.rb +47 -0
- data/test/benchmark/metrics.rb +9 -8
- data/test/benchmark/tags.rb +5 -3
- data/test/capture_backend_test.rb +4 -2
- data/test/environment_test.rb +2 -1
- data/test/helpers_test.rb +2 -1
- data/test/integration_test.rb +27 -7
- data/test/logger_backend_test.rb +10 -8
- data/test/matchers_test.rb +34 -20
- data/test/metric_test.rb +15 -4
- data/test/statsd_instrumentation_test.rb +7 -7
- data/test/statsd_test.rb +24 -15
- data/test/test_helper.rb +2 -0
- data/test/udp_backend_test.rb +3 -26
- metadata +22 -3
- data/.travis.yml +0 -12
data/test/benchmark/metrics.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'statsd-instrument'
|
2
4
|
require 'benchmark/ips'
|
3
5
|
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def helper_function
|
7
|
+
a = 10
|
8
|
+
a += a
|
9
|
+
a -= a
|
10
|
+
a * a
|
9
11
|
end
|
10
12
|
|
11
13
|
Benchmark.ips do |bench|
|
@@ -14,8 +16,8 @@ Benchmark.ips do |bench|
|
|
14
16
|
end
|
15
17
|
|
16
18
|
bench.report("measure metric benchmark") do
|
17
|
-
StatsD.measure('
|
18
|
-
|
19
|
+
StatsD.measure('helper_function') do
|
20
|
+
helper_function
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -34,5 +36,4 @@ Benchmark.ips do |bench|
|
|
34
36
|
bench.report("service check metric benchmark") do
|
35
37
|
StatsD.service_check('shipit.redis_connection', 'ok')
|
36
38
|
end
|
37
|
-
|
38
39
|
end
|
data/test/benchmark/tags.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'statsd-instrument'
|
2
4
|
require 'benchmark/ips'
|
3
5
|
|
4
6
|
Benchmark.ips do |bench|
|
5
7
|
bench.report("normalized tags with simple hash") do
|
6
|
-
StatsD::Instrument::Metric.normalize_tags(:
|
8
|
+
StatsD::Instrument::Metric.normalize_tags(tag: 'value')
|
7
9
|
end
|
8
10
|
|
9
11
|
bench.report("normalized tags with simple array") do
|
@@ -11,14 +13,14 @@ Benchmark.ips do |bench|
|
|
11
13
|
end
|
12
14
|
|
13
15
|
bench.report("normalized tags with large hash") do
|
14
|
-
StatsD::Instrument::Metric.normalize_tags(
|
16
|
+
StatsD::Instrument::Metric.normalize_tags(
|
15
17
|
mobile: true,
|
16
18
|
pod: "1",
|
17
19
|
protocol: "https",
|
18
20
|
country: "Langbortistan",
|
19
21
|
complete: true,
|
20
22
|
shop: "omg shop that has a longer name",
|
21
|
-
|
23
|
+
)
|
22
24
|
end
|
23
25
|
|
24
26
|
bench.report("normalized tags with large array") do
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class CaptureBackendTest < Minitest::Test
|
4
6
|
def setup
|
5
7
|
@backend = StatsD::Instrument::Backends::CaptureBackend.new
|
6
|
-
@metric1 = StatsD::Instrument::Metric
|
7
|
-
@metric2 = StatsD::Instrument::Metric
|
8
|
+
@metric1 = StatsD::Instrument::Metric.new(type: :c, name: 'mock.counter')
|
9
|
+
@metric2 = StatsD::Instrument::Metric.new(type: :ms, name: 'mock.measure', value: 123)
|
8
10
|
end
|
9
11
|
|
10
12
|
def test_collecting_metric
|
data/test/environment_test.rb
CHANGED
data/test/helpers_test.rb
CHANGED
data/test/integration_test.rb
CHANGED
@@ -1,20 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class IntegrationTest < Minitest::Test
|
4
|
-
|
5
6
|
def setup
|
6
|
-
@
|
7
|
+
@server = UDPSocket.new
|
8
|
+
@server.bind('localhost', 0)
|
9
|
+
port = @server.addr[1]
|
10
|
+
|
11
|
+
@old_backend = StatsD.backend
|
12
|
+
StatsD.backend = StatsD::Instrument::Backends::UDPBackend.new("localhost:#{port}")
|
7
13
|
end
|
8
|
-
|
14
|
+
|
9
15
|
def teardown
|
16
|
+
@server.close
|
10
17
|
StatsD.backend = @old_backend
|
11
18
|
end
|
12
19
|
|
13
20
|
def test_live_local_udp_socket
|
14
|
-
server = UDPSocket.new
|
15
|
-
server.bind('localhost', 31798)
|
16
|
-
|
17
21
|
StatsD.increment('counter')
|
18
|
-
assert_equal "counter:1|c", server.recvfrom(100).first
|
22
|
+
assert_equal "counter:1|c", @server.recvfrom(100).first
|
23
|
+
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
|
+
Process.waitpid(pid)
|
37
|
+
|
38
|
+
assert_equal "exiting:1|c", @server.recvfrom(100).first
|
19
39
|
end
|
20
40
|
end
|
data/test/logger_backend_test.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class LoggerBackendTest < Minitest::Test
|
4
6
|
def setup
|
5
7
|
logger = Logger.new(@io = StringIO.new)
|
6
|
-
logger.formatter = lambda { |_,_,_, msg| "#{msg}\n" }
|
8
|
+
logger.formatter = lambda { |_, _, _, msg| "#{msg}\n" }
|
7
9
|
@backend = StatsD::Instrument::Backends::LoggerBackend.new(logger)
|
8
|
-
@metric1 = StatsD::Instrument::Metric
|
9
|
-
@metric2 = StatsD::Instrument::Metric
|
10
|
+
@metric1 = StatsD::Instrument::Metric.new(type: :c, name: 'mock.counter', tags: { a: 'b', c: 'd' })
|
11
|
+
@metric2 = StatsD::Instrument::Metric.new(type: :ms, name: 'mock.measure', value: 123, sample_rate: 0.3)
|
10
12
|
end
|
11
13
|
|
12
14
|
def test_logs_metrics
|
13
15
|
@backend.collect_metric(@metric1)
|
14
|
-
assert_equal @io.string, "[StatsD] increment mock.counter:1 #a:b #c:d\n"
|
15
|
-
@io.string = ""
|
16
|
-
|
17
16
|
@backend.collect_metric(@metric2)
|
18
|
-
assert_equal @io.string
|
17
|
+
assert_equal <<~LOG, @io.string
|
18
|
+
[StatsD] increment mock.counter:1 #a:b #c:d
|
19
|
+
[StatsD] measure mock.measure:123 @0.3
|
20
|
+
LOG
|
19
21
|
end
|
20
|
-
end
|
22
|
+
end
|
data/test/matchers_test.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
require 'statsd/instrument/matchers'
|
3
5
|
|
4
6
|
class MatchersTest < Minitest::Test
|
5
7
|
def test_statsd_increment_matched
|
6
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', {})
|
8
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', {})
|
9
|
+
.matches?(lambda { StatsD.increment('counter') })
|
7
10
|
end
|
8
11
|
|
9
12
|
def test_statsd_increment_not_matched
|
10
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', {})
|
13
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', {})
|
14
|
+
.matches?(lambda { StatsD.increment('not_counter') })
|
11
15
|
end
|
12
16
|
|
13
17
|
def test_statsd_increment_compound_matched
|
@@ -31,72 +35,82 @@ class MatchersTest < Minitest::Test
|
|
31
35
|
end
|
32
36
|
|
33
37
|
def test_statsd_increment_with_times_matched
|
34
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 1)
|
38
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 1)
|
39
|
+
.matches?(lambda { StatsD.increment('counter') })
|
35
40
|
end
|
36
41
|
|
37
42
|
def test_statsd_increment_with_times_not_matched
|
38
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2)
|
43
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2)
|
44
|
+
.matches?(lambda { StatsD.increment('counter', times: 3) })
|
39
45
|
end
|
40
46
|
|
41
47
|
def test_statsd_increment_with_sample_rate_matched
|
42
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: 0.5)
|
48
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: 0.5)
|
49
|
+
.matches?(lambda { StatsD.increment('counter', sample_rate: 0.5) })
|
43
50
|
end
|
44
51
|
|
45
52
|
def test_statsd_increment_with_sample_rate_not_matched
|
46
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: 0.5)
|
53
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: 0.5)
|
54
|
+
.matches?(lambda { StatsD.increment('counter', sample_rate: 0.7) })
|
47
55
|
end
|
48
56
|
|
49
57
|
def test_statsd_increment_with_value_matched
|
50
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1)
|
58
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1)
|
59
|
+
.matches?(lambda { StatsD.increment('counter') })
|
51
60
|
end
|
52
61
|
|
53
62
|
def test_statsd_increment_with_value_matched_when_multiple_metrics
|
54
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1).matches?
|
63
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1).matches?(lambda {
|
55
64
|
StatsD.increment('counter', value: 2)
|
56
65
|
StatsD.increment('counter', value: 1)
|
57
|
-
}
|
66
|
+
})
|
58
67
|
end
|
59
68
|
|
60
69
|
def test_statsd_increment_with_value_not_matched_when_multiple_metrics
|
61
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1).matches?
|
70
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1).matches?(lambda {
|
62
71
|
StatsD.increment('counter', value: 2)
|
63
72
|
StatsD.increment('counter', value: 3)
|
64
|
-
}
|
73
|
+
})
|
65
74
|
end
|
66
75
|
|
67
76
|
def test_statsd_increment_with_value_not_matched
|
68
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 3)
|
77
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 3)
|
78
|
+
.matches?(lambda { StatsD.increment('counter') })
|
69
79
|
end
|
70
80
|
|
71
81
|
def test_statsd_increment_with_tags_matched
|
72
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a', 'b'])
|
82
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a', 'b'])
|
83
|
+
.matches?(lambda { StatsD.increment('counter', tags: ['a', 'b']) })
|
73
84
|
end
|
74
85
|
|
75
86
|
def test_statsd_increment_with_tags_not_matched
|
76
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a', 'b'])
|
87
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a', 'b'])
|
88
|
+
.matches?(lambda { StatsD.increment('counter', tags: ['c']) })
|
77
89
|
end
|
78
90
|
|
79
91
|
def test_statsd_increment_with_times_and_value_matched
|
80
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2, value: 1).matches?
|
92
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2, value: 1).matches?(lambda {
|
81
93
|
StatsD.increment('counter', value: 1)
|
82
94
|
StatsD.increment('counter', value: 1)
|
83
|
-
}
|
95
|
+
})
|
84
96
|
end
|
85
97
|
|
86
98
|
def test_statsd_increment_with_times_and_value_not_matched
|
87
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2, value: 1).matches?
|
99
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2, value: 1).matches?(lambda {
|
88
100
|
StatsD.increment('counter', value: 1)
|
89
101
|
StatsD.increment('counter', value: 2)
|
90
|
-
}
|
102
|
+
})
|
91
103
|
end
|
92
104
|
|
93
105
|
def test_statsd_increment_with_sample_rate_and_argument_matcher_matched
|
94
106
|
between_matcher = RSpec::Matchers::BuiltIn::BeBetween.new(0.4, 0.6).inclusive
|
95
|
-
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: between_matcher)
|
107
|
+
assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: between_matcher)
|
108
|
+
.matches?(lambda { StatsD.increment('counter', sample_rate: 0.5) })
|
96
109
|
end
|
97
110
|
|
98
111
|
def test_statsd_increment_with_sample_rate_and_argument_matcher_not_matched
|
99
112
|
between_matcher = RSpec::Matchers::BuiltIn::BeBetween.new(0.4, 0.6).inclusive
|
100
|
-
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: between_matcher)
|
113
|
+
refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: between_matcher)
|
114
|
+
.matches?(lambda { StatsD.increment('counter', sample_rate: 0.7) })
|
101
115
|
end
|
102
116
|
end
|
data/test/metric_test.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class MetricTest < Minitest::Test
|
4
|
-
|
5
6
|
def test_required_arguments
|
6
7
|
assert_raises(ArgumentError) { StatsD::Instrument::Metric.new(type: :c) }
|
7
8
|
assert_raises(ArgumentError) { StatsD::Instrument::Metric.new(name: 'test') }
|
@@ -41,11 +42,21 @@ class MetricTest < Minitest::Test
|
|
41
42
|
|
42
43
|
def test_handle_bad_tags
|
43
44
|
assert_equal ['ignored'], StatsD::Instrument::Metric.normalize_tags(['igno|red'])
|
44
|
-
assert_equal ['lol::class:omg::lol'], StatsD::Instrument::Metric.normalize_tags(
|
45
|
+
assert_equal ['lol::class:omg::lol'], StatsD::Instrument::Metric.normalize_tags("lol::class" => "omg::lol")
|
45
46
|
end
|
46
47
|
|
47
48
|
def test_rewrite_tags_provided_as_hash
|
48
|
-
assert_equal ['tag:value'], StatsD::Instrument::Metric.normalize_tags(:
|
49
|
-
assert_equal ['
|
49
|
+
assert_equal ['tag:value'], StatsD::Instrument::Metric.normalize_tags(tag: 'value')
|
50
|
+
assert_equal ['tag1:v1', 'tag2:v2'], StatsD::Instrument::Metric.normalize_tags(tag1: 'v1', tag2: 'v2')
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_default_tags
|
54
|
+
StatsD.stubs(:default_tags).returns(['default_tag:default_value'])
|
55
|
+
m = StatsD::Instrument::Metric.new(type: :c, name: 'counter', tags: { tag: 'value' })
|
56
|
+
assert_equal ['tag:value', 'default_tag:default_value'], m.tags
|
57
|
+
|
58
|
+
StatsD.stubs(:default_tags).returns(['tag:value'])
|
59
|
+
m = StatsD::Instrument::Metric.new(type: :c, name: 'counter', tags: { tag: 'value' })
|
60
|
+
assert_equal ['tag:value', 'tag:value'], m.tags # we don't care about duplicates
|
50
61
|
end
|
51
62
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
module ActiveMerchant; end
|
@@ -11,7 +13,7 @@ class ActiveMerchant::Base
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def post_with_block(&block)
|
14
|
-
|
16
|
+
block.call if block_given?
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -34,7 +36,7 @@ end
|
|
34
36
|
|
35
37
|
class ActiveMerchant::UniqueGateway < ActiveMerchant::Base
|
36
38
|
def ssl_post(arg)
|
37
|
-
{:
|
39
|
+
{ success: arg }
|
38
40
|
end
|
39
41
|
|
40
42
|
def purchase(arg)
|
@@ -87,7 +89,7 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
87
89
|
end
|
88
90
|
|
89
91
|
assert_statsd_increment('ActiveMerchant.Base.post_with_block') do
|
90
|
-
assert_equal 'true',
|
92
|
+
assert_equal 'true', ActiveMerchant::Base.new.post_with_block { 'true' }
|
91
93
|
assert_equal 'false', ActiveMerchant::Base.new.post_with_block { 'false' }
|
92
94
|
end
|
93
95
|
ensure
|
@@ -265,7 +267,6 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
265
267
|
ActiveMerchant::UniqueGateway.statsd_remove_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
|
266
268
|
end
|
267
269
|
|
268
|
-
|
269
270
|
def test_statsd_distribution
|
270
271
|
ActiveMerchant::UniqueGateway.statsd_distribution :ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3
|
271
272
|
|
@@ -412,10 +413,9 @@ class StatsDInstrumentationTest < Minitest::Test
|
|
412
413
|
private
|
413
414
|
|
414
415
|
def assert_scope(klass, method, expected_scope)
|
415
|
-
method_scope =
|
416
|
-
when klass.private_method_defined?(method)
|
416
|
+
method_scope = if klass.private_method_defined?(method)
|
417
417
|
:private
|
418
|
-
|
418
|
+
elsif klass.protected_method_defined?(method)
|
419
419
|
:protected
|
420
420
|
else
|
421
421
|
:public
|
data/test/statsd_test.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class StatsDTest < Minitest::Test
|
4
6
|
include StatsD::Instrument::Assertions
|
5
7
|
|
8
|
+
def teardown
|
9
|
+
StatsD.default_tags = nil
|
10
|
+
end
|
11
|
+
|
6
12
|
def test_statsd_passed_collections_to_backend
|
7
13
|
StatsD.backend.expects(:collect_metric).with(instance_of(StatsD::Instrument::Metric))
|
8
14
|
StatsD.increment('test')
|
@@ -18,7 +24,7 @@ class StatsDTest < Minitest::Test
|
|
18
24
|
end
|
19
25
|
|
20
26
|
def test_statsd_measure_with_explicit_value_and_distribution_override
|
21
|
-
metric = capture_statsd_call {
|
27
|
+
metric = capture_statsd_call { StatsD.measure('values.foobar', 42, as_dist: true) }
|
22
28
|
assert_equal :d, metric.type
|
23
29
|
end
|
24
30
|
|
@@ -32,7 +38,7 @@ class StatsDTest < Minitest::Test
|
|
32
38
|
end
|
33
39
|
|
34
40
|
def test_statsd_measure_with_explicit_value_keyword_and_distribution_override
|
35
|
-
metric = capture_statsd_call {
|
41
|
+
metric = capture_statsd_call { StatsD.measure('values.foobar', value: 42, as_dist: true) }
|
36
42
|
assert_equal :d, metric.type
|
37
43
|
end
|
38
44
|
|
@@ -41,7 +47,7 @@ class StatsDTest < Minitest::Test
|
|
41
47
|
end
|
42
48
|
|
43
49
|
def test_statsd_measure_with_explicit_value_and_sample_rate
|
44
|
-
metric = capture_statsd_call { StatsD.measure('values.foobar', 42, :
|
50
|
+
metric = capture_statsd_call { StatsD.measure('values.foobar', 42, sample_rate: 0.1) }
|
45
51
|
assert_equal 0.1, metric.sample_rate
|
46
52
|
end
|
47
53
|
|
@@ -65,7 +71,7 @@ class StatsDTest < Minitest::Test
|
|
65
71
|
assert_equal 'sarah', return_value
|
66
72
|
end
|
67
73
|
|
68
|
-
def
|
74
|
+
def test_statsd_measure_as_distribution_returns_return_value_of_block_even_if_nil
|
69
75
|
return_value = StatsD.measure('values.foobar', as_dist: true) { nil }
|
70
76
|
assert_nil return_value
|
71
77
|
end
|
@@ -75,7 +81,7 @@ class StatsDTest < Minitest::Test
|
|
75
81
|
result = nil
|
76
82
|
metric = capture_statsd_call do
|
77
83
|
lambda = -> do
|
78
|
-
StatsD.measure('values.foobar') { return 'from lambda'}
|
84
|
+
StatsD.measure('values.foobar') { return 'from lambda' }
|
79
85
|
end
|
80
86
|
|
81
87
|
result = lambda.call
|
@@ -90,14 +96,13 @@ class StatsDTest < Minitest::Test
|
|
90
96
|
result = nil
|
91
97
|
metric = capture_statsd_call do
|
92
98
|
lambda = -> do
|
93
|
-
StatsD.measure('values.foobar') { raise 'from lambda'}
|
99
|
+
StatsD.measure('values.foobar') { raise 'from lambda' }
|
94
100
|
end
|
95
101
|
|
96
102
|
begin
|
97
103
|
result = lambda.call
|
98
|
-
rescue
|
104
|
+
rescue # rubocop:disable Lint/HandleExceptions:
|
99
105
|
end
|
100
|
-
|
101
106
|
end
|
102
107
|
|
103
108
|
assert_nil result
|
@@ -114,14 +119,14 @@ class StatsDTest < Minitest::Test
|
|
114
119
|
end
|
115
120
|
|
116
121
|
def test_statsd_increment_with_hash_argument
|
117
|
-
metric = capture_statsd_call { StatsD.increment('values.foobar', :
|
122
|
+
metric = capture_statsd_call { StatsD.increment('values.foobar', tags: ['test']) }
|
118
123
|
assert_equal StatsD.default_sample_rate, metric.sample_rate
|
119
124
|
assert_equal ['test'], metric.tags
|
120
125
|
assert_equal 1, metric.value
|
121
126
|
end
|
122
127
|
|
123
128
|
def test_statsd_increment_with_value_as_keyword_argument
|
124
|
-
metric = capture_statsd_call { StatsD.increment('values.foobar', :
|
129
|
+
metric = capture_statsd_call { StatsD.increment('values.foobar', value: 2) }
|
125
130
|
assert_equal StatsD.default_sample_rate, metric.sample_rate
|
126
131
|
assert_equal 2, metric.value
|
127
132
|
end
|
@@ -196,7 +201,7 @@ class StatsDTest < Minitest::Test
|
|
196
201
|
result = nil
|
197
202
|
metric = capture_statsd_call do
|
198
203
|
lambda = -> do
|
199
|
-
StatsD.distribution('values.foobar') { return 'from lambda'}
|
204
|
+
StatsD.distribution('values.foobar') { return 'from lambda' }
|
200
205
|
end
|
201
206
|
|
202
207
|
result = lambda.call
|
@@ -212,14 +217,13 @@ class StatsDTest < Minitest::Test
|
|
212
217
|
result = nil
|
213
218
|
metric = capture_statsd_call do
|
214
219
|
lambda = -> do
|
215
|
-
StatsD.distribution('values.foobar') { raise 'from lambda'}
|
220
|
+
StatsD.distribution('values.foobar') { raise 'from lambda' }
|
216
221
|
end
|
217
222
|
|
218
223
|
begin
|
219
224
|
result = lambda.call
|
220
|
-
rescue
|
225
|
+
rescue # rubocop:disable Lint/HandleExceptions
|
221
226
|
end
|
222
|
-
|
223
227
|
end
|
224
228
|
|
225
229
|
assert_nil result
|
@@ -230,7 +234,7 @@ class StatsDTest < Minitest::Test
|
|
230
234
|
def test_statsd_distribution_with_block_and_options
|
231
235
|
StatsD::Instrument.stubs(:current_timestamp).returns(5.0, 5.0 + 1.12)
|
232
236
|
metric = capture_statsd_call do
|
233
|
-
StatsD.distribution('values.foobar', :
|
237
|
+
StatsD.distribution('values.foobar', tags: ['test'], sample_rate: 0.9) { 'foo' }
|
234
238
|
end
|
235
239
|
assert_equal 1120.0, metric.value
|
236
240
|
assert_equal 'values.foobar', metric.name
|
@@ -268,6 +272,11 @@ class StatsDTest < Minitest::Test
|
|
268
272
|
end
|
269
273
|
end
|
270
274
|
|
275
|
+
def test_statsd_default_tags_get_normalized
|
276
|
+
StatsD.default_tags = { first_tag: 'first_value', second_tag: 'second_value' }
|
277
|
+
assert_equal ['first_tag:first_value', 'second_tag:second_value'], StatsD.default_tags
|
278
|
+
end
|
279
|
+
|
271
280
|
protected
|
272
281
|
|
273
282
|
def capture_statsd_call(&block)
|