statsd-instrument 2.7.1 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -1
- data/lib/statsd/instrument.rb +2 -6
- data/lib/statsd/instrument/client.rb +36 -14
- data/lib/statsd/instrument/environment.rb +8 -18
- data/lib/statsd/instrument/expectation.rb +4 -14
- data/lib/statsd/instrument/version.rb +1 -1
- data/test/assertions_on_legacy_client_test.rb +0 -32
- data/test/assertions_test.rb +1 -33
- data/test/client_test.rb +51 -0
- data/test/environment_test.rb +18 -37
- data/test/helpers_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a8a68ce2f902140d3efb1526ae9295949002c0cf2c6922544e0215f58b2bfc7
|
4
|
+
data.tar.gz: 273baedb9f0446ec0919e707d858d6543d4a585331e15c683da04673a4e60cee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b90db7e6b18013c889e5ecd1243f9035a8fa5781634daffbaa028157859a2a6d7652a3ef5d110ccb3fe2b28b91f5c7c434e0e086d62472c2175a0838009ff81
|
7
|
+
data.tar.gz: 0a694681d1dde4799f082bc515594d43da648d115571b0d5ab4456e2df4a1ab3973c7e99e90379fab6112f834e4f43cf5fdc3b593f82fe737e61d3e4a50c4f1d
|
data/CHANGELOG.md
CHANGED
@@ -6,7 +6,26 @@ section below.
|
|
6
6
|
|
7
7
|
### Unreleased changes
|
8
8
|
|
9
|
-
_Nothing
|
9
|
+
_Nothing yet_
|
10
|
+
|
11
|
+
## Version 2.8.0
|
12
|
+
|
13
|
+
- ⚠️ Remove support for `assert_statsd_*(..., ignore_tags: ...)`. This feature
|
14
|
+
was never documented, and the only use case we were aware of has been
|
15
|
+
addressed since. It's highly unlikely that you are using this feature.
|
16
|
+
However, if you are, you can capture StatsD datagrams using the
|
17
|
+
`capture_statsd_datagrams` method, and run your own assertions on the list.
|
18
|
+
- ⚠️ Remove `StatsD.client`. This was added in version 2.6.0 in order to
|
19
|
+
experiment with the new client. However, at this point thereare better ways
|
20
|
+
to do this.
|
21
|
+
- You can set `StatsD.singleton_client` to a new client, which causes the
|
22
|
+
calls to the StatsD singleton to be handled by a new client. If you set
|
23
|
+
`STATSD_USE_NEW_CLIENT`, it will be initialized to a new client.
|
24
|
+
- If that doesn't work for you, you can instantiate a client using
|
25
|
+
`StatsD::Instrument::Client.from_env` and assign it to a variable of your
|
26
|
+
own choosing.
|
27
|
+
- Fix some compatibility issues when using `assert_statsd_*` methods when
|
28
|
+
using a new client with prefix.
|
10
29
|
|
11
30
|
## Version 2.7.1
|
12
31
|
|
data/lib/statsd/instrument.rb
CHANGED
@@ -381,7 +381,7 @@ module StatsD
|
|
381
381
|
end
|
382
382
|
|
383
383
|
attr_accessor :logger
|
384
|
-
attr_writer :
|
384
|
+
attr_writer :singleton_client
|
385
385
|
|
386
386
|
extend Forwardable
|
387
387
|
|
@@ -390,11 +390,7 @@ module StatsD
|
|
390
390
|
end
|
391
391
|
|
392
392
|
def singleton_client
|
393
|
-
@singleton_client ||= StatsD::Instrument::Environment.
|
394
|
-
end
|
395
|
-
|
396
|
-
def client
|
397
|
-
@client ||= StatsD::Instrument::Environment.from_env.default_client
|
393
|
+
@singleton_client ||= StatsD::Instrument::Environment.current.client
|
398
394
|
end
|
399
395
|
|
400
396
|
# Singleton methods will be delegated to the singleton client.
|
@@ -15,15 +15,48 @@ require 'statsd/instrument/log_sink'
|
|
15
15
|
# next major release of this library. While this class may already be functional,
|
16
16
|
# we provide no guarantees about the API and the behavior may change.
|
17
17
|
class StatsD::Instrument::Client
|
18
|
+
class << self
|
19
|
+
def from_env(
|
20
|
+
env = StatsD::Instrument::Environment.current,
|
21
|
+
prefix: env.statsd_prefix,
|
22
|
+
default_sample_rate: env.statsd_sample_rate,
|
23
|
+
default_tags: env.statsd_default_tags,
|
24
|
+
implementation: env.statsd_implementation,
|
25
|
+
sink: env.default_sink_for_environment,
|
26
|
+
datagram_builder_class: datagram_builder_class_for_implementation(implementation)
|
27
|
+
)
|
28
|
+
new(
|
29
|
+
prefix: prefix,
|
30
|
+
default_sample_rate: default_sample_rate,
|
31
|
+
default_tags: default_tags,
|
32
|
+
implementation: implementation,
|
33
|
+
sink: sink,
|
34
|
+
datagram_builder_class: datagram_builder_class,
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
# @private
|
39
|
+
def datagram_builder_class_for_implementation(implementation)
|
40
|
+
case implementation.to_s
|
41
|
+
when 'statsd'
|
42
|
+
StatsD::Instrument::StatsDDatagramBuilder
|
43
|
+
when 'datadog', 'dogstatsd'
|
44
|
+
StatsD::Instrument::DogStatsDDatagramBuilder
|
45
|
+
else
|
46
|
+
raise NotImplementedError, "No implementation for #{statsd_implementation}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
18
51
|
attr_reader :sink, :datagram_builder_class, :prefix, :default_tags, :default_sample_rate
|
19
52
|
|
20
53
|
def initialize(
|
21
|
-
sink: StatsD::Instrument::NullSink.new,
|
22
54
|
prefix: nil,
|
23
|
-
default_sample_rate: 1,
|
55
|
+
default_sample_rate: 1.0,
|
24
56
|
default_tags: nil,
|
25
57
|
implementation: 'datadog',
|
26
|
-
|
58
|
+
sink: StatsD::Instrument::NullSink.new,
|
59
|
+
datagram_builder_class: self.class.datagram_builder_class_for_implementation(implementation)
|
27
60
|
)
|
28
61
|
@sink = sink
|
29
62
|
@datagram_builder_class = datagram_builder_class
|
@@ -35,17 +68,6 @@ class StatsD::Instrument::Client
|
|
35
68
|
@datagram_builder = { false => nil, true => nil }
|
36
69
|
end
|
37
70
|
|
38
|
-
def datagram_builder_class_from_implementation(implementation)
|
39
|
-
case implementation.to_s
|
40
|
-
when 'statsd'
|
41
|
-
StatsD::Instrument::StatsDDatagramBuilder
|
42
|
-
when 'datadog', 'dogstatsd'
|
43
|
-
StatsD::Instrument::DogStatsDDatagramBuilder
|
44
|
-
else
|
45
|
-
raise NotImplementedError, "No implementation for #{statsd_implementation}"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
71
|
# @!group Metric Methods
|
50
72
|
|
51
73
|
# Emits a counter metric.
|
@@ -4,8 +4,8 @@
|
|
4
4
|
# which this library is active. It will use different default values based on the environment.
|
5
5
|
class StatsD::Instrument::Environment
|
6
6
|
class << self
|
7
|
-
def
|
8
|
-
@
|
7
|
+
def current
|
8
|
+
@current ||= StatsD::Instrument::Environment.new(ENV)
|
9
9
|
end
|
10
10
|
|
11
11
|
# Detects the current environment, either by asking Rails, or by inspecting environment variables.
|
@@ -16,7 +16,7 @@ class StatsD::Instrument::Environment
|
|
16
16
|
#
|
17
17
|
# @return [String] The detected environment.
|
18
18
|
def environment
|
19
|
-
|
19
|
+
current.environment
|
20
20
|
end
|
21
21
|
|
22
22
|
# Instantiates a default backend for the current environment.
|
@@ -26,7 +26,7 @@ class StatsD::Instrument::Environment
|
|
26
26
|
def default_backend
|
27
27
|
case environment
|
28
28
|
when 'production', 'staging'
|
29
|
-
StatsD::Instrument::Backends::UDPBackend.new(
|
29
|
+
StatsD::Instrument::Backends::UDPBackend.new(current.statsd_addr, current.statsd_implementation)
|
30
30
|
when 'test'
|
31
31
|
StatsD::Instrument::Backends::NullBackend.new
|
32
32
|
else
|
@@ -45,9 +45,9 @@ class StatsD::Instrument::Environment
|
|
45
45
|
#
|
46
46
|
# @return [void]
|
47
47
|
def setup
|
48
|
-
StatsD.prefix =
|
49
|
-
StatsD.default_tags =
|
50
|
-
StatsD.default_sample_rate =
|
48
|
+
StatsD.prefix = current.statsd_prefix
|
49
|
+
StatsD.default_tags = current.statsd_default_tags
|
50
|
+
StatsD.default_sample_rate = current.statsd_sample_rate
|
51
51
|
StatsD.logger = Logger.new($stderr)
|
52
52
|
end
|
53
53
|
end
|
@@ -97,22 +97,12 @@ class StatsD::Instrument::Environment
|
|
97
97
|
|
98
98
|
def client
|
99
99
|
if env.key?('STATSD_USE_NEW_CLIENT')
|
100
|
-
|
100
|
+
StatsD::Instrument::Client.from_env(self)
|
101
101
|
else
|
102
102
|
StatsD::Instrument::LegacyClient.singleton
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
def default_client
|
107
|
-
@default_client ||= StatsD::Instrument::Client.new(
|
108
|
-
sink: default_sink_for_environment,
|
109
|
-
implementation: statsd_implementation,
|
110
|
-
default_sample_rate: statsd_sample_rate,
|
111
|
-
prefix: statsd_prefix,
|
112
|
-
default_tags: statsd_default_tags,
|
113
|
-
)
|
114
|
-
end
|
115
|
-
|
116
106
|
def default_sink_for_environment
|
117
107
|
case environment
|
118
108
|
when 'production', 'staging'
|
@@ -33,15 +33,15 @@ class StatsD::Instrument::Expectation
|
|
33
33
|
end
|
34
34
|
|
35
35
|
attr_accessor :times, :type, :name, :value, :sample_rate, :tags
|
36
|
-
attr_reader :ignore_tags
|
37
36
|
|
38
|
-
def initialize(type:, name:, value: nil,
|
37
|
+
def initialize(client: StatsD.singleton_client, type:, name:, value: nil,
|
38
|
+
sample_rate: nil, tags: nil, no_prefix: false, times: 1)
|
39
|
+
|
39
40
|
@type = type
|
40
|
-
@name =
|
41
|
+
@name = client.prefix ? "#{client.prefix}.#{name}" : name unless no_prefix
|
41
42
|
@value = normalized_value_for_type(type, value) if value
|
42
43
|
@sample_rate = sample_rate
|
43
44
|
@tags = StatsD::Instrument::Metric.normalize_tags(tags)
|
44
|
-
@ignore_tags = StatsD::Instrument::Metric.normalize_tags(ignore_tags)
|
45
45
|
@times = times
|
46
46
|
end
|
47
47
|
|
@@ -61,16 +61,6 @@ class StatsD::Instrument::Expectation
|
|
61
61
|
if tags
|
62
62
|
expected_tags = Set.new(tags)
|
63
63
|
actual_tags = Set.new(actual_metric.tags)
|
64
|
-
|
65
|
-
if ignore_tags
|
66
|
-
ignored_tags = Set.new(ignore_tags) - expected_tags
|
67
|
-
actual_tags -= ignored_tags
|
68
|
-
|
69
|
-
if ignore_tags.is_a?(Array)
|
70
|
-
actual_tags.delete_if { |key| ignore_tags.include?(key.split(":").first) }
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
64
|
return expected_tags.subset?(actual_tags)
|
75
65
|
end
|
76
66
|
true
|
@@ -98,38 +98,6 @@ class AssertionsOnLegacyClientTest < Minitest::Test
|
|
98
98
|
StatsD.increment('counter', sample_rate: 0.5, tags: ['a', 'b'])
|
99
99
|
end
|
100
100
|
|
101
|
-
assert_raises(Minitest::Assertion) do
|
102
|
-
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: ['a', 'b'], ignore_tags: ['b']) do
|
103
|
-
StatsD.increment('counter', sample_rate: 0.5, tags: ['a'])
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: ['a'], ignore_tags: ['b']) do
|
108
|
-
StatsD.increment('counter', sample_rate: 0.5, tags: ['a', 'b'])
|
109
|
-
end
|
110
|
-
|
111
|
-
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: ['a'], ignore_tags: ['b']) do
|
112
|
-
StatsD.increment('counter', sample_rate: 0.5, tags: ['a'])
|
113
|
-
end
|
114
|
-
|
115
|
-
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: { a: 1 }, ignore_tags: { b: 2 }) do
|
116
|
-
StatsD.increment('counter', sample_rate: 0.5, tags: { a: 1, b: 2 })
|
117
|
-
end
|
118
|
-
|
119
|
-
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: { a: 1 }, ignore_tags: { b: 2 }) do
|
120
|
-
StatsD.increment('counter', sample_rate: 0.5, tags: { a: 1, b: 3 })
|
121
|
-
end
|
122
|
-
|
123
|
-
assert_raises(Minitest::Assertion) do
|
124
|
-
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: { a: 1, b: 3 }, ignore_tags: ['b']) do
|
125
|
-
StatsD.increment('counter', sample_rate: 0.5, tags: { a: 1, b: 2 })
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: { a: 1 }, ignore_tags: ['b']) do
|
130
|
-
StatsD.increment('counter', sample_rate: 0.5, tags: { a: 1, b: 2 })
|
131
|
-
end
|
132
|
-
|
133
101
|
assert_raises(Minitest::Assertion) do
|
134
102
|
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: ['a', 'b']) do
|
135
103
|
StatsD.increment('counter', sample_rate: 0.2, tags: ['c'])
|
data/test/assertions_test.rb
CHANGED
@@ -6,7 +6,7 @@ class AssertionsTest < Minitest::Test
|
|
6
6
|
def setup
|
7
7
|
@old_client = StatsD.singleton_client
|
8
8
|
env = StatsD::Instrument::Environment.new('STATSD_IMPLEMENTATION' => 'datadog')
|
9
|
-
StatsD.singleton_client = env
|
9
|
+
StatsD.singleton_client = StatsD::Instrument::Client.from_env(env)
|
10
10
|
|
11
11
|
test_class = Class.new(Minitest::Test)
|
12
12
|
test_class.send(:include, StatsD::Instrument::Assertions)
|
@@ -99,38 +99,6 @@ class AssertionsTest < Minitest::Test
|
|
99
99
|
StatsD.increment('counter', sample_rate: 0.5, tags: ['a', 'b'])
|
100
100
|
end
|
101
101
|
|
102
|
-
assert_raises(Minitest::Assertion) do
|
103
|
-
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: ['a', 'b'], ignore_tags: ['b']) do
|
104
|
-
StatsD.increment('counter', sample_rate: 0.5, tags: ['a'])
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: ['a'], ignore_tags: ['b']) do
|
109
|
-
StatsD.increment('counter', sample_rate: 0.5, tags: ['a', 'b'])
|
110
|
-
end
|
111
|
-
|
112
|
-
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: ['a'], ignore_tags: ['b']) do
|
113
|
-
StatsD.increment('counter', sample_rate: 0.5, tags: ['a'])
|
114
|
-
end
|
115
|
-
|
116
|
-
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: { a: 1 }, ignore_tags: { b: 2 }) do
|
117
|
-
StatsD.increment('counter', sample_rate: 0.5, tags: { a: 1, b: 2 })
|
118
|
-
end
|
119
|
-
|
120
|
-
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: { a: 1 }, ignore_tags: { b: 2 }) do
|
121
|
-
StatsD.increment('counter', sample_rate: 0.5, tags: { a: 1, b: 3 })
|
122
|
-
end
|
123
|
-
|
124
|
-
assert_raises(Minitest::Assertion) do
|
125
|
-
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: { a: 1, b: 3 }, ignore_tags: ['b']) do
|
126
|
-
StatsD.increment('counter', sample_rate: 0.5, tags: { a: 1, b: 2 })
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: { a: 1 }, ignore_tags: ['b']) do
|
131
|
-
StatsD.increment('counter', sample_rate: 0.5, tags: { a: 1, b: 2 })
|
132
|
-
end
|
133
|
-
|
134
102
|
assert_raises(Minitest::Assertion) do
|
135
103
|
@test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: ['a', 'b']) do
|
136
104
|
StatsD.increment('counter', sample_rate: 0.2, tags: ['c'])
|
data/test/client_test.rb
CHANGED
@@ -8,6 +8,57 @@ class ClientTest < Minitest::Test
|
|
8
8
|
@dogstatsd_client = StatsD::Instrument::Client.new(implementation: 'datadog')
|
9
9
|
end
|
10
10
|
|
11
|
+
def test_client_from_env
|
12
|
+
env = StatsD::Instrument::Environment.new(
|
13
|
+
'STATSD_ENV' => 'production',
|
14
|
+
'STATSD_SAMPLE_RATE' => '0.1',
|
15
|
+
'STATSD_PREFIX' => 'foo',
|
16
|
+
'STATSD_DEFAULT_TAGS' => 'shard:1,env:production',
|
17
|
+
'STATSD_IMPLEMENTATION' => 'statsd',
|
18
|
+
'STATSD_ADDR' => '1.2.3.4:8125',
|
19
|
+
)
|
20
|
+
client = StatsD::Instrument::Client.from_env(env)
|
21
|
+
|
22
|
+
assert_equal 0.1, client.default_sample_rate
|
23
|
+
assert_equal 'foo', client.prefix
|
24
|
+
assert_equal ['shard:1', 'env:production'], client.default_tags
|
25
|
+
assert_equal StatsD::Instrument::StatsDDatagramBuilder, client.datagram_builder_class
|
26
|
+
|
27
|
+
assert_kind_of StatsD::Instrument::UDPSink, client.sink
|
28
|
+
assert_equal '1.2.3.4', client.sink.host
|
29
|
+
assert_equal 8125, client.sink.port
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_client_from_env_has_sensible_defaults
|
33
|
+
env = StatsD::Instrument::Environment.new({})
|
34
|
+
client = StatsD::Instrument::Client.from_env(env)
|
35
|
+
|
36
|
+
assert_equal 1.0, client.default_sample_rate
|
37
|
+
assert_nil client.prefix
|
38
|
+
assert_nil client.default_tags
|
39
|
+
assert_equal StatsD::Instrument::DogStatsDDatagramBuilder, client.datagram_builder_class
|
40
|
+
assert_kind_of StatsD::Instrument::LogSink, client.sink
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_client_from_env_with_overrides
|
44
|
+
env = StatsD::Instrument::Environment.new(
|
45
|
+
'STATSD_SAMPLE_RATE' => '0.1',
|
46
|
+
'STATSD_PREFIX' => 'foo',
|
47
|
+
'STATSD_DEFAULT_TAGS' => 'shard:1,env:production',
|
48
|
+
'STATSD_IMPLEMENTATION' => 'statsd',
|
49
|
+
'STATSD_ADDR' => '1.2.3.4:8125',
|
50
|
+
)
|
51
|
+
client = StatsD::Instrument::Client.from_env(env,
|
52
|
+
prefix: 'bar', implementation: 'dogstatsd', sink: StatsD::Instrument::NullSink.new)
|
53
|
+
|
54
|
+
assert_equal 0.1, client.default_sample_rate
|
55
|
+
assert_equal 'bar', client.prefix
|
56
|
+
assert_equal ['shard:1', 'env:production'], client.default_tags
|
57
|
+
assert_equal StatsD::Instrument::DogStatsDDatagramBuilder, client.datagram_builder_class
|
58
|
+
|
59
|
+
assert_kind_of StatsD::Instrument::NullSink, client.sink
|
60
|
+
end
|
61
|
+
|
11
62
|
def test_capture
|
12
63
|
inner_datagrams = nil
|
13
64
|
|
data/test/environment_test.rb
CHANGED
@@ -62,52 +62,33 @@ class EnvironmentTest < Minitest::Test
|
|
62
62
|
assert_equal 'development', env.environment
|
63
63
|
end
|
64
64
|
|
65
|
-
def
|
66
|
-
env = StatsD::Instrument::Environment.new(
|
67
|
-
assert_kind_of StatsD::Instrument::
|
65
|
+
def test_legacy_client_is_default_client
|
66
|
+
env = StatsD::Instrument::Environment.new({})
|
67
|
+
assert_kind_of StatsD::Instrument::LegacyClient, env.client
|
68
68
|
end
|
69
69
|
|
70
|
-
def
|
71
|
-
env = StatsD::Instrument::Environment.new('
|
72
|
-
assert_kind_of StatsD::Instrument::
|
70
|
+
def test_client_returns_new_client_if_envcironment_asks_for_it
|
71
|
+
env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1')
|
72
|
+
assert_kind_of StatsD::Instrument::Client, env.client
|
73
73
|
end
|
74
74
|
|
75
|
-
def
|
76
|
-
env = StatsD::Instrument::Environment.new('STATSD_ENV' => '
|
77
|
-
assert_kind_of StatsD::Instrument::
|
75
|
+
def test_client_from_env_uses_log_sink_in_development_environment
|
76
|
+
env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1', 'STATSD_ENV' => 'development')
|
77
|
+
assert_kind_of StatsD::Instrument::LogSink, env.client.sink
|
78
78
|
end
|
79
79
|
|
80
|
-
def
|
81
|
-
env = StatsD::Instrument::Environment.new('STATSD_ENV' => '
|
82
|
-
assert_kind_of StatsD::Instrument::
|
80
|
+
def test_client_from_env_uses_null_sink_in_test_environment
|
81
|
+
env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1', 'STATSD_ENV' => 'test')
|
82
|
+
assert_kind_of StatsD::Instrument::NullSink, env.client.sink
|
83
83
|
end
|
84
84
|
|
85
|
-
def
|
86
|
-
env = StatsD::Instrument::Environment.new(
|
87
|
-
|
88
|
-
'STATSD_IMPLEMENTATION' => 'datadog',
|
89
|
-
'STATSD_ADDR' => 'foo:8125',
|
90
|
-
'STATSD_SAMPLE_RATE' => "0.1",
|
91
|
-
'STATSD_PREFIX' => "foo",
|
92
|
-
'STATSD_DEFAULT_TAGS' => "foo,bar:baz",
|
93
|
-
)
|
94
|
-
|
95
|
-
assert_equal StatsD::Instrument::DogStatsDDatagramBuilder, env.default_client.datagram_builder_class
|
96
|
-
assert_equal 'foo', env.default_client.sink.host
|
97
|
-
assert_equal 8125, env.default_client.sink.port
|
98
|
-
assert_equal 0.1, env.default_client.default_sample_rate
|
99
|
-
assert_equal "foo", env.default_client.prefix
|
100
|
-
assert_equal ["foo", "bar:baz"], env.default_client.default_tags
|
85
|
+
def test_client_from_env_uses_udp_sink_in_staging_environment
|
86
|
+
env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1', 'STATSD_ENV' => 'staging')
|
87
|
+
assert_kind_of StatsD::Instrument::UDPSink, env.client.sink
|
101
88
|
end
|
102
89
|
|
103
|
-
def
|
104
|
-
env = StatsD::Instrument::Environment.new('STATSD_ENV' => 'production')
|
105
|
-
|
106
|
-
assert_equal StatsD::Instrument::DogStatsDDatagramBuilder, env.default_client.datagram_builder_class
|
107
|
-
assert_equal 'localhost', env.default_client.sink.host
|
108
|
-
assert_equal 8125, env.default_client.sink.port
|
109
|
-
assert_equal 1.0, env.default_client.default_sample_rate
|
110
|
-
assert_nil env.default_client.prefix
|
111
|
-
assert_nil env.default_client.default_tags
|
90
|
+
def test_client_from_env_uses_udp_sink_in_production_environment
|
91
|
+
env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1', 'STATSD_ENV' => 'production')
|
92
|
+
assert_kind_of StatsD::Instrument::UDPSink, env.client.sink
|
112
93
|
end
|
113
94
|
end
|
data/test/helpers_test.rb
CHANGED
@@ -25,7 +25,7 @@ class HelpersTest < Minitest::Test
|
|
25
25
|
|
26
26
|
def test_capture_metrics_with_new_client
|
27
27
|
@old_client = StatsD.singleton_client
|
28
|
-
StatsD.singleton_client = StatsD.
|
28
|
+
StatsD.singleton_client = StatsD::Instrument::Client.new
|
29
29
|
|
30
30
|
StatsD.increment('counter')
|
31
31
|
metrics = @test_case.capture_statsd_datagrams do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statsd-instrument
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Storimer
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-10-
|
13
|
+
date: 2019-10-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|