statsd-instrument 2.5.0 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19c798557b1db75029e1efded949cee656fe0b33b77e3c1c13edde73be5e4957
4
- data.tar.gz: 46b43c2589e9d0628cab7d070a4163e6bfa6d54e7b03b8d85681e0bf29d2c733
3
+ metadata.gz: 921e9b4ecf3a6a74cfb1460767ba4374121723d9ef2a7bd76b747904a25a7b48
4
+ data.tar.gz: b62df176782d7aca1f24608015db7b68b610af386c7c30309517e39de3551dfe
5
5
  SHA512:
6
- metadata.gz: 6b09c458ef308d1afbf8264a44f1399a00863e607afd0ad3bd43b297976130e50663e9c4cd9fa17490ad4f283faef9f15b41fc9283bac7500b87dbd21af89a5a
7
- data.tar.gz: d52f9d40110e812ece11a3d87d52013df1f18e96f0a88ea8c1411950d17926a7936954839cb5e6d374c63745499e3f9e379607bf5432880643bb03b32b7eabb2
6
+ metadata.gz: 3d1ff5390d8cd5dc611e42dc4667894a0c82e406d92cd51d6a71ff4cd7ffa1e747e56f8f19d483c28335a4b5a616848356fc23f50787276883aafe17b043316d
7
+ data.tar.gz: 542ad17d646c28b691287db6debc18a6386a332aa148d2549c60602aaab0427bb836bd755e701495aec9db856a7fa387ddbea5de3e85f7d5c973ec9d52d3c008
data/CHANGELOG.md CHANGED
@@ -6,7 +6,70 @@ section below.
6
6
 
7
7
  ### Unreleased changes
8
8
 
9
- _Nothing yet_
9
+ - Several improvements to `StatsD.event` and `StatsD.service_check` (both are
10
+ Datadog-only). The previous implementation would sometimes construct invalid
11
+ datagrams based on the input. The method signatures have been made more
12
+ explicit, and documentation of these methods is now also more clear.
13
+
14
+ - Slight behaviour change when using the `assert_statsd_*` assertion methods in
15
+ combination with `assert_raises`: we now do not allow the block passed to the
16
+ `assert_statsd_` call to raise an exception. This may cause tests to fail that
17
+ previousloy were succeeding.
18
+
19
+ Consider the following example:
20
+
21
+ ``` ruby
22
+ assert_raises(RuntimeError)
23
+ assert_statsd_increment('foo') do
24
+ raise 'something unexpected'
25
+ end
26
+ end
27
+ ```
28
+
29
+ In versions before 2.3.3, the assert `assert_statsd_*` calls would silently
30
+ pass when an exception would occur, which would later be handled by
31
+ `assert_raises`. So the test would pass, even though no `foo` metric would be
32
+ emitted.
33
+
34
+ Version 2.3.3 changed this by failing the test because no metric was being
35
+ emitted. However, this would hide the the exception from the assertion message,
36
+ complicating debugging efforts.
37
+
38
+ Now, we fail the test because an unexpected exception occured inside the block.
39
+ This means that the following test will fail:
40
+
41
+ ``` ruby
42
+ assert_raises(RuntimeError)
43
+ assert_statsd_increment('foo') do
44
+ StatsD.increment('foo')
45
+ raise 'something unexpected'
46
+ end
47
+ end
48
+ ```
49
+
50
+ To fix, you will need to nest the `assert_raises` inside the block passed to
51
+ `assert_statsd_instrument` so that `assert_statsd_increment` will not see any
52
+ exceptions:
53
+
54
+ ``` ruby
55
+ assert_statsd_increment('foo') do
56
+ assert_raises(RuntimeError)
57
+ StatsD.increment('foo')
58
+ raise 'something unexpected'
59
+ end
60
+ end
61
+ ```
62
+
63
+ See #193, #184, and #166 for more information.
64
+
65
+ ## Version 2.5.1
66
+
67
+ - **Bugfix:** when using metaprogramming methods, changes to `StatsD.prefix` after
68
+ the metaprogramming method was evaluated would not be respected. This
69
+ unfortunately is quite common when you set the StatsD prefix inside an
70
+ initializer. This issue is now addressed: the prefix is evaluated at the
71
+ mopment the metric is emitted, not when the metaprogramming method is being
72
+ evaluated. (#202)
10
73
 
11
74
  ## Version 2.5.0
12
75
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module StatsD
4
4
  module Instrument
5
- VERSION = "2.5.0"
5
+ VERSION = "2.5.1"
6
6
  end
7
7
  end
@@ -92,11 +92,12 @@ module StatsD
92
92
  # @param metric_options (see StatsD#measure)
93
93
  # @return [void]
94
94
  def statsd_measure(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil, as_dist: false,
95
- sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: StatsD.prefix, no_prefix: false)
95
+ sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: nil, no_prefix: false)
96
96
 
97
97
  add_to_method(method, name, :measure) do
98
98
  define_method(method) do |*args, &block|
99
99
  key = StatsD::Instrument.generate_metric_name(name, self, *args)
100
+ prefix ||= StatsD.prefix
100
101
  StatsD.measure(
101
102
  key, sample_rate: sample_rate, tags: tags, prefix: prefix, no_prefix: no_prefix, as_dist: as_dist
102
103
  ) do
@@ -115,11 +116,12 @@ module StatsD
115
116
  # @return [void]
116
117
  # @note Supported by the datadog implementation only (in beta)
117
118
  def statsd_distribution(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil,
118
- sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: StatsD.prefix, no_prefix: false)
119
+ sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: nil, no_prefix: false)
119
120
 
120
121
  add_to_method(method, name, :distribution) do
121
122
  define_method(method) do |*args, &block|
122
123
  key = StatsD::Instrument.generate_metric_name(name, self, *args)
124
+ prefix ||= StatsD.prefix
123
125
  StatsD.distribution(key, sample_rate: sample_rate, tags: tags, prefix: prefix, no_prefix: no_prefix) do
124
126
  super(*args, &block)
125
127
  end
@@ -143,7 +145,7 @@ module StatsD
143
145
  # @return [void]
144
146
  # @see #statsd_count_if
145
147
  def statsd_count_success(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil,
146
- sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: StatsD.prefix, no_prefix: false)
148
+ sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: nil, no_prefix: false)
147
149
 
148
150
  add_to_method(method, name, :count_success) do
149
151
  define_method(method) do |*args, &block|
@@ -164,6 +166,7 @@ module StatsD
164
166
  ensure
165
167
  suffix = truthiness == false ? 'failure' : 'success'
166
168
  key = "#{StatsD::Instrument.generate_metric_name(name, self, *args)}.#{suffix}"
169
+ prefix ||= StatsD.prefix
167
170
  StatsD.increment(key, sample_rate: sample_rate, tags: tags, prefix: prefix, no_prefix: no_prefix)
168
171
  end
169
172
  end
@@ -183,7 +186,7 @@ module StatsD
183
186
  # @return [void]
184
187
  # @see #statsd_count_success
185
188
  def statsd_count_if(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil,
186
- sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: StatsD.prefix, no_prefix: false)
189
+ sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: nil, no_prefix: false)
187
190
 
188
191
  add_to_method(method, name, :count_if) do
189
192
  define_method(method) do |*args, &block|
@@ -204,6 +207,7 @@ module StatsD
204
207
  ensure
205
208
  if truthiness
206
209
  key = StatsD::Instrument.generate_metric_name(name, self, *args)
210
+ prefix ||= StatsD.prefix
207
211
  StatsD.increment(key, sample_rate: sample_rate, tags: tags, prefix: prefix, no_prefix: no_prefix)
208
212
  end
209
213
  end
@@ -221,11 +225,12 @@ module StatsD
221
225
  # @param metric_options (see #statsd_measure)
222
226
  # @return [void]
223
227
  def statsd_count(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil,
224
- sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: StatsD.prefix, no_prefix: false)
228
+ sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: nil, no_prefix: false)
225
229
 
226
230
  add_to_method(method, name, :count) do
227
231
  define_method(method) do |*args, &block|
228
232
  key = StatsD::Instrument.generate_metric_name(name, self, *args)
233
+ prefix ||= StatsD.prefix
229
234
  StatsD.increment(key, sample_rate: sample_rate, tags: tags, prefix: prefix, no_prefix: no_prefix)
230
235
  super(*args, &block)
231
236
  end
@@ -337,6 +337,48 @@ class StatsDInstrumentationTest < Minitest::Test
337
337
  ActiveMerchant::Gateway.singleton_class.statsd_remove_count :sync, 'ActiveMerchant.Gateway.sync'
338
338
  end
339
339
 
340
+ def test_statsd_respects_global_prefix_changes
341
+ StatsD.prefix = 'Foo'
342
+ ActiveMerchant::Gateway.singleton_class.extend StatsD::Instrument
343
+ ActiveMerchant::Gateway.singleton_class.statsd_count :sync, 'ActiveMerchant.Gateway.sync'
344
+ StatsD.prefix = 'Quc'
345
+
346
+ statsd_calls = capture_statsd_calls { ActiveMerchant::Gateway.sync }
347
+ assert_equal 1, statsd_calls.length
348
+ assert_equal "Quc.ActiveMerchant.Gateway.sync", statsd_calls.first.name
349
+ ensure
350
+ StatsD.prefix = nil
351
+ ActiveMerchant::Gateway.singleton_class.statsd_remove_count :sync, 'ActiveMerchant.Gateway.sync'
352
+ end
353
+
354
+ def test_statsd_macro_can_overwrite_prefix
355
+ StatsD.prefix = 'Foo'
356
+ ActiveMerchant::Gateway.singleton_class.extend StatsD::Instrument
357
+ ActiveMerchant::Gateway.singleton_class.statsd_measure :sync, 'ActiveMerchant.Gateway.sync', prefix: 'Bar'
358
+ StatsD.prefix = 'Quc'
359
+
360
+ statsd_calls = capture_statsd_calls { ActiveMerchant::Gateway.sync }
361
+ assert_equal 1, statsd_calls.length
362
+ assert_equal "Bar.ActiveMerchant.Gateway.sync", statsd_calls.first.name
363
+ ensure
364
+ StatsD.prefix = nil
365
+ ActiveMerchant::Gateway.singleton_class.statsd_remove_measure :sync, 'ActiveMerchant.Gateway.sync'
366
+ end
367
+
368
+ def test_statsd_macro_can_disable_prefix
369
+ StatsD.prefix = 'Foo'
370
+ ActiveMerchant::Gateway.singleton_class.extend StatsD::Instrument
371
+ ActiveMerchant::Gateway.singleton_class.statsd_count_success :sync, 'ActiveMerchant.Gateway.sync', no_prefix: true
372
+ StatsD.prefix = 'Quc'
373
+
374
+ statsd_calls = capture_statsd_calls { ActiveMerchant::Gateway.sync }
375
+ assert_equal 1, statsd_calls.length
376
+ assert_equal "ActiveMerchant.Gateway.sync.success", statsd_calls.first.name
377
+ ensure
378
+ StatsD.prefix = nil
379
+ ActiveMerchant::Gateway.singleton_class.statsd_remove_count_success :sync, 'ActiveMerchant.Gateway.sync'
380
+ end
381
+
340
382
  def test_statsd_doesnt_change_method_scope_of_public_method
341
383
  assert_scope InstrumentedClass, :public_and_instrumented, :public
342
384
 
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.5.0
4
+ version: 2.5.1
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-09-27 00:00:00.000000000 Z
13
+ date: 2019-10-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake