statsd-instrument 2.8.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +16 -7
  3. data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +6 -6
  4. data/CHANGELOG.md +28 -6
  5. data/CONTRIBUTING.md +3 -3
  6. data/README.md +11 -11
  7. data/lib/statsd/instrument.rb +33 -18
  8. data/lib/statsd/instrument/assertions.rb +7 -7
  9. data/lib/statsd/instrument/backend.rb +1 -1
  10. data/lib/statsd/instrument/client.rb +11 -10
  11. data/lib/statsd/instrument/datagram.rb +1 -2
  12. data/lib/statsd/instrument/datagram_builder.rb +1 -1
  13. data/lib/statsd/instrument/dogstatsd_datagram.rb +88 -0
  14. data/lib/statsd/instrument/dogstatsd_datagram_builder.rb +4 -0
  15. data/lib/statsd/instrument/expectation.rb +37 -1
  16. data/lib/statsd/instrument/legacy_client.rb +5 -5
  17. data/lib/statsd/instrument/metric.rb +2 -2
  18. data/lib/statsd/instrument/rubocop/metaprogramming_positional_arguments.rb +1 -1
  19. data/lib/statsd/instrument/rubocop/positional_arguments.rb +6 -6
  20. data/lib/statsd/instrument/rubocop/singleton_configuration.rb +1 -1
  21. data/lib/statsd/instrument/strict.rb +37 -17
  22. data/lib/statsd/instrument/version.rb +1 -1
  23. data/test/assertions_on_legacy_client_test.rb +1 -1
  24. data/test/assertions_test.rb +26 -1
  25. data/test/capture_sink_test.rb +1 -1
  26. data/test/client_test.rb +5 -5
  27. data/test/compatibility/dogstatsd_datagram_compatibility_test.rb +1 -1
  28. data/test/datagram_builder_test.rb +1 -1
  29. data/test/deprecations_test.rb +8 -1
  30. data/test/dogstatsd_datagram_builder_test.rb +41 -4
  31. data/test/environment_test.rb +1 -1
  32. data/test/integration_test.rb +1 -1
  33. data/test/log_sink_test.rb +1 -1
  34. data/test/null_sink_test.rb +1 -1
  35. data/test/rubocop/metric_prefix_argument_test.rb +1 -1
  36. data/test/rubocop/positional_arguments_test.rb +3 -3
  37. data/test/statsd_instrumentation_test.rb +11 -0
  38. data/test/statsd_test.rb +2 -9
  39. data/test/udp_backend_test.rb +3 -0
  40. data/test/udp_sink_test.rb +1 -1
  41. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a8a68ce2f902140d3efb1526ae9295949002c0cf2c6922544e0215f58b2bfc7
4
- data.tar.gz: 273baedb9f0446ec0919e707d858d6543d4a585331e15c683da04673a4e60cee
3
+ metadata.gz: 28a52ac92cfb09e796f1eb8af9fde1a701255e61ac7377d32a7f6e92569c0e05
4
+ data.tar.gz: bae7f0b29a3ce2ed62486a0866e592ca29ac5d18c11ad0815e7cb71991de50a8
5
5
  SHA512:
6
- metadata.gz: 8b90db7e6b18013c889e5ecd1243f9035a8fa5781634daffbaa028157859a2a6d7652a3ef5d110ccb3fe2b28b91f5c7c434e0e086d62472c2175a0838009ff81
7
- data.tar.gz: 0a694681d1dde4799f082bc515594d43da648d115571b0d5ab4456e2df4a1ab3973c7e99e90379fab6112f834e4f43cf5fdc3b593f82fe737e61d3e4a50c4f1d
6
+ metadata.gz: 87f9772a163d3ed4f400203f83db6c39dc946b75e21288fdd7a6ab7aa5b43646fcfa2fd3564d61b2795d192bcc82ae196dc1ec765d465b098620b9bcaf05c013
7
+ data.tar.gz: d74cc5375319064d64e23e8fd1a6bf7583781783d296c12fb1ae233e45ddaecff8dd4bbfa9c1bf912fcd48daacb8f47511b019d4bf26b74a2ca235267054012b
@@ -9,17 +9,26 @@ jobs:
9
9
  strategy:
10
10
  fail-fast: false
11
11
  matrix:
12
- platform: [ubuntu-18.04, windows-2019, macOS-10.14]
12
+ # Windows started failing on the following command for some reason.
13
+ #
14
+ # gem install bundler && bundle install --jobs 4 --retry 3
15
+ # ~~
16
+ # The token '&&' is not a valid statement separator in this version.
17
+ #
18
+ # Temporarily disable Windows builds to unblock CI.
19
+ #
20
+ # platform: [ubuntu-18.04, windows-2019, macOS-10.14]
21
+ platform: [ubuntu-18.04, macOS-10.14]
13
22
  ruby: [2.3, 2.4, 2.5, 2.6]
14
23
 
15
24
  exclude:
16
25
  # The Windows environment does not support older Ruby versions. We only test against the latest version
17
- - platform: windows-2019
18
- ruby: 2.3
19
- - platform: windows-2019
20
- ruby: 2.4
21
- - platform: windows-2019
22
- ruby: 2.5
26
+ # - platform: windows-2019
27
+ # ruby: 2.3
28
+ # - platform: windows-2019
29
+ # ruby: 2.4
30
+ # - platform: windows-2019
31
+ # ruby: 2.5
23
32
 
24
33
  # On macOS, we only test against the Ruby version macOS ships with (2.3)
25
34
  - platform: macOS-10.14
@@ -819,13 +819,13 @@ Layout/TrailingWhitespace:
819
819
  Style/UnlessElse:
820
820
  Enabled: true
821
821
 
822
- Style/UnneededCapitalW:
822
+ Style/RedundantCapitalW:
823
823
  Enabled: true
824
824
 
825
- Style/UnneededInterpolation:
825
+ Style/RedundantInterpolation:
826
826
  Enabled: true
827
827
 
828
- Style/UnneededPercentQ:
828
+ Style/RedundantPercentQ:
829
829
  Enabled: true
830
830
 
831
831
  Style/VariableInterpolation:
@@ -956,13 +956,13 @@ Lint/UnderscorePrefixedVariableName:
956
956
  Lint/UnifiedInteger:
957
957
  Enabled: true
958
958
 
959
- Lint/UnneededCopDisableDirective:
959
+ Lint/RedundantCopDisableDirective:
960
960
  Enabled: true
961
961
 
962
- Lint/UnneededCopEnableDirective:
962
+ Lint/RedundantCopEnableDirective:
963
963
  Enabled: true
964
964
 
965
- Lint/UnneededSplatExpansion:
965
+ Lint/RedundantSplatExpansion:
966
966
  Enabled: true
967
967
 
968
968
  Lint/UnreachableCode:
@@ -6,7 +6,29 @@ section below.
6
6
 
7
7
  ### Unreleased changes
8
8
 
9
- _Nothing yet_
9
+ - ⚠️ **DEPRECATION:** The `StatsD.key_value` metric method is deprecated
10
+ and will be removed in version 3.0. The new client does not have StatSite
11
+ support. Due to the lack of active contributors that can port this metric
12
+ type to the new client, we have decided to drop it until somebody else
13
+ steps up and re-adds it to the new client.
14
+ - Fix: metaprogramming methods will send metrics to the client assifgned to
15
+ `StatsD.singleton_client` when the metric is emitted, rather than the client
16
+ when the metaprogramming method was called.
17
+ - Metric methods (e.g. `StatsD.increment`) on the new client will now return a
18
+ `VOID` object that evaluates to `true` rather than nil. This is for better
19
+ backwards compatibility with the legacy client.
20
+ - Add support for variadic arguments to `assert_no_statsd_calls`. This allows
21
+ consolidation of assertions about specific metrics. For example:
22
+ ```diff
23
+ -assert_no_statsd_calls('foo') do
24
+ - assert_no_statsd_calls('bar') do
25
+ - assert_no_statsd_calls('biz.baz') do
26
+ +assert_no_statsd_calls('foo', 'bar', 'biz.baz') do
27
+ # do work...
28
+ - end
29
+ - end
30
+ end
31
+ ```
10
32
 
11
33
  ## Version 2.8.0
12
34
 
@@ -16,7 +38,7 @@ _Nothing yet_
16
38
  However, if you are, you can capture StatsD datagrams using the
17
39
  `capture_statsd_datagrams` method, and run your own assertions on the list.
18
40
  - ⚠️ 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
41
+ experiment with the new client. However, at this point there are better ways
20
42
  to do this.
21
43
  - You can set `StatsD.singleton_client` to a new client, which causes the
22
44
  calls to the StatsD singleton to be handled by a new client. If you set
@@ -36,7 +58,7 @@ This release has some small fixes related to the new client only:
36
58
  - Make it easier to instantiate new clients by specifying an implementation
37
59
  (e.g. `datadog`) rather than a DatagramBuilder class.
38
60
  - Change `NullSink#sample?` to always return `true`, so it's easier to verify
39
- business rules by using a different DatabagramBuilder in test suites.
61
+ business rules by using a different DatagramBuilder in test suites.
40
62
 
41
63
  ## Version 2.7.0
42
64
 
@@ -56,7 +78,7 @@ and fix deprecations in your code base.
56
78
  calls on the `StatsD` singleton will be delegated to this legacy client.
57
79
  - By setting `STATSD_USE_NEW_CLIENT` as environment variable, these method
58
80
  calls will be delegated to an instance of the new client instead. This
59
- client is configured using the existing `STATD_*` environment variables,
81
+ client is configured using the existing `STATSD_*` environment variables,
60
82
  like `STATSD_ADDR` and `STATSD_IMPLEMENTATION`.
61
83
  - You can also assign a custom client to `StatsD.singleton_client`.
62
84
 
@@ -188,7 +210,7 @@ deprecated patterns. See below for more info.
188
210
  - Slight behaviour change when using the `assert_statsd_*` assertion methods in
189
211
  combination with `assert_raises`: we now do not allow the block passed to the
190
212
  `assert_statsd_` call to raise an exception. This may cause tests to fail that
191
- previousloy were succeeding.
213
+ previously were succeeding.
192
214
 
193
215
  Consider the following example:
194
216
 
@@ -318,7 +340,7 @@ s
318
340
 
319
341
  ``` ruby
320
342
  # In your Gemfile
321
- gem 'statd-instrument', require: 'statsd/instrument/strict'
343
+ gem 'statsd-instrument', require: 'statsd/instrument/strict'
322
344
 
323
345
  # Or, in your test helper:
324
346
  require 'statsd/instrument/strict'
@@ -4,7 +4,7 @@ This project is MIT licensed.
4
4
 
5
5
  > **Note**: this project is currently not actively maintained, but is heavily used in production.
6
6
  > As a result, pull requests and issues may not be responded to. Also, due to the limited time we have
7
- > avaibale to work on this library, we cannot accept PRs that do not maintain backwards compatibility,
7
+ > available to work on this library, we cannot accept PRs that do not maintain backwards compatibility,
8
8
  > or PRs that would affect the performance of the hot code paths.
9
9
 
10
10
  ## Reporting issues
@@ -28,9 +28,9 @@ Some notes:
28
28
  - Make sure to follow to coding style. This is enforced by Rubocop
29
29
  - Make sure your changes are properly documented using [yardoc syntax](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md).
30
30
  - Add an entry to the "unreleased changes" section of [CHANGELOG.md](./CHANGELOG.md).
31
- - **Do not** update `StatsD::Instrument::VERSION`. This will be done during the release prodecure.
31
+ - **Do not** update `StatsD::Instrument::VERSION`. This will be done during the release procedure.
32
32
 
33
- ### On perfomance & benchmarking
33
+ ### On performance & benchmarking
34
34
 
35
35
  This gem is used in production at Shopify, and is used to instrument some of
36
36
  our hottest code paths. This means that we are very careful about not
data/README.md CHANGED
@@ -15,7 +15,7 @@ project](http://github.com/etsy/statsd).
15
15
 
16
16
  ## Configuration
17
17
 
18
- It's recommended to configure this librray by setting environment variables.
18
+ It's recommended to configure this library by setting environment variables.
19
19
  The following environment variables are supported:
20
20
 
21
21
  - `STATSD_ADDR`: (default `localhost:8125`) The address to send the StatsD UDP
@@ -27,7 +27,7 @@ The following environment variables are supported:
27
27
  explicitly, this will be determined based on other environment variables,
28
28
  like `RAILS_ENV` or `ENV`. The library will behave differently:
29
29
 
30
- - In the **production** and **staging** environment, thre librray will
30
+ - In the **production** and **staging** environment, thre library will
31
31
  actually send UDP packets.
32
32
  - In the **test** environment, it will swallow all calls, but allows you to
33
33
  capture them for testing purposes. See below for notes on writing tests.
@@ -41,7 +41,7 @@ The following environment variables are supported:
41
41
  - `STATSD_PREFIX`: The prefix to apply to all metric names. This can be
42
42
  overridden in a metric method call.
43
43
  - `STATSD_DEFAULT_TAGS`: A comma-separated list of tags to apply to all metrics.
44
- (Note: tags are not supported by all iomplementations.)
44
+ (Note: tags are not supported by all implementations.)
45
45
 
46
46
  ## StatsD keys
47
47
 
@@ -110,28 +110,28 @@ StatsD.histogram('Order.value', order.value_in_usd.to_f tags: { source: 'POS' })
110
110
 
111
111
  Because you are counting unique values, the results of using a sampling value less than 1.0 can lead to unexpected, hard to interpret results.
112
112
 
113
- *Note: This is only supported by the beta datadog implementatation.*
113
+ *Note: This is only supported by the beta datadog implementation.*
114
114
 
115
115
  #### StatsD.distribution
116
116
 
117
- A modified gauge that submits a distribution of values over a sample period. Arithmetic and statistical calculations (percetiles, average, etc.) on the data set are peformed server side rather than client side like a histogram.
117
+ A modified gauge that submits a distribution of values over a sample period. Arithmetic and statistical calculations (percentiles, average, etc.) on the data set are performed server side rather than client side like a histogram.
118
118
 
119
119
  ```ruby
120
120
  StatsD.distribution('shipit.redis_connection', 3)
121
121
  ```
122
122
 
123
- *Note: This is only supported by the beta datadog implementatation.*
123
+ *Note: This is only supported by the beta datadog implementation.*
124
124
 
125
125
  #### StatsD.event
126
126
 
127
- An event is a (title, text) tuple that can be used to correlate metrics with something that occured within the system.
127
+ An event is a (title, text) tuple that can be used to correlate metrics with something that occurred within the system.
128
128
  This is a good fit for instance to correlate response time variation with a deploy of the new code.
129
129
 
130
130
  ```ruby
131
131
  StatsD.event('shipit.deploy', 'started', sample_rate: 1.0)
132
132
  ```
133
133
 
134
- *Note: This is only supported by the [datadog implementatation](https://docs.datadoghq.com/guides/dogstatsd/#events).*
134
+ *Note: This is only supported by the [datadog implementation](https://docs.datadoghq.com/guides/dogstatsd/#events).*
135
135
 
136
136
  Events support additional metadata such as `date_happened`, `hostname`, `aggregation_key`, `priority`, `source_type_name`, `alert_type`.
137
137
 
@@ -143,7 +143,7 @@ An event is a (check_name, status) tuple that can be used to monitor the status
143
143
  StatsD.service_check('shipit.redis_connection', 'ok')
144
144
  ```
145
145
 
146
- *Note: This is only supported by the [datadog implementatation](https://docs.datadoghq.com/guides/dogstatsd/#service-checks).*
146
+ *Note: This is only supported by the [datadog implementation](https://docs.datadoghq.com/guides/dogstatsd/#service-checks).*
147
147
 
148
148
  Service checks support additional metadata such as `timestamp`, `hostname`, `message`.
149
149
 
@@ -272,12 +272,12 @@ class MyTestcase < Minitest::Test
272
272
  end
273
273
 
274
274
  def test_no_udp_traffic
275
- # Verifies no StatsD calls occured at all.
275
+ # Verifies no StatsD calls occurred at all.
276
276
  assert_no_statsd_calls do
277
277
  do_some_work
278
278
  end
279
279
 
280
- # Verifies no StatsD calls occured for the given metric.
280
+ # Verifies no StatsD calls occurred for the given metric.
281
281
  assert_no_statsd_calls('metric_name') do
282
282
  do_some_work
283
283
  end
@@ -89,7 +89,7 @@ module StatsD
89
89
  extend self
90
90
 
91
91
  # The StatsD::Instrument module provides metaprogramming methods to instrument your methods with
92
- # StatsD metrics. E.g., yopu can create counters on how often a method is called, how often it is
92
+ # StatsD metrics. E.g., you can create counters on how often a method is called, how often it is
93
93
  # successful, the duration of the methods call, etc.
94
94
  module Instrument
95
95
  # @private
@@ -139,8 +139,9 @@ module StatsD
139
139
  # callable to dynamically generate a metric name
140
140
  # @param metric_options (see StatsD#measure)
141
141
  # @return [void]
142
- def statsd_measure(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil, as_dist: false,
143
- sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: nil, no_prefix: false)
142
+ def statsd_measure(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil,
143
+ as_dist: false, sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg,
144
+ prefix: nil, no_prefix: false, client: nil)
144
145
 
145
146
  if as_dist
146
147
  return statsd_distribution(method, name, # rubocop:disable StatsD/MetricPrefixArgument
@@ -149,9 +150,10 @@ module StatsD
149
150
 
150
151
  add_to_method(method, name, :measure) do
151
152
  define_method(method) do |*args, &block|
152
- prefix ||= StatsD.prefix unless no_prefix
153
+ client ||= StatsD.singleton_client
154
+ prefix ||= client.prefix unless no_prefix
153
155
  key = StatsD::Instrument.generate_metric_name(prefix, name, self, *args)
154
- StatsD.measure(key, sample_rate: sample_rate, tags: tags, no_prefix: true) do
156
+ client.measure(key, sample_rate: sample_rate, tags: tags, no_prefix: true) do
155
157
  super(*args, &block)
156
158
  end
157
159
  end
@@ -167,13 +169,15 @@ module StatsD
167
169
  # @return [void]
168
170
  # @note Supported by the datadog implementation only (in beta)
169
171
  def statsd_distribution(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil,
170
- sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: nil, no_prefix: false)
172
+ sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg,
173
+ prefix: nil, no_prefix: false, client: nil)
171
174
 
172
175
  add_to_method(method, name, :distribution) do
173
176
  define_method(method) do |*args, &block|
174
- prefix ||= StatsD.prefix unless no_prefix
177
+ client ||= StatsD.singleton_client
178
+ prefix ||= client.prefix unless no_prefix
175
179
  key = StatsD::Instrument.generate_metric_name(prefix, name, self, *args)
176
- StatsD.distribution(key, sample_rate: sample_rate, tags: tags, no_prefix: true) do
180
+ client.distribution(key, sample_rate: sample_rate, tags: tags, no_prefix: true) do
177
181
  super(*args, &block)
178
182
  end
179
183
  end
@@ -192,11 +196,12 @@ module StatsD
192
196
  # @yield You can pass a block to this method if you want to define yourself what is a successful call
193
197
  # based on the return value of the method.
194
198
  # @yieldparam result The return value of the instrumented method.
195
- # @yieldreturn [Boolean] Return true iff the return value is consisered a success, false otherwise.
199
+ # @yieldreturn [Boolean] Return true iff the return value is considered a success, false otherwise.
196
200
  # @return [void]
197
201
  # @see #statsd_count_if
198
202
  def statsd_count_success(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil,
199
- sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: nil, no_prefix: false)
203
+ sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg,
204
+ prefix: nil, no_prefix: false, client: nil)
200
205
 
201
206
  add_to_method(method, name, :count_success) do
202
207
  define_method(method) do |*args, &block|
@@ -215,10 +220,12 @@ module StatsD
215
220
  end
216
221
  result
217
222
  ensure
223
+ client ||= StatsD.singleton_client
218
224
  suffix = truthiness == false ? 'failure' : 'success'
219
- prefix ||= StatsD.prefix unless no_prefix
225
+ prefix ||= client.prefix unless no_prefix
220
226
  key = StatsD::Instrument.generate_metric_name(prefix, name, self, *args)
221
- StatsD.increment("#{key}.#{suffix}", sample_rate: sample_rate, tags: tags, no_prefix: true)
227
+ client.increment("#{key}.#{suffix}",
228
+ sample_rate: sample_rate, tags: tags, no_prefix: true)
222
229
  end
223
230
  end
224
231
  end
@@ -237,7 +244,8 @@ module StatsD
237
244
  # @return [void]
238
245
  # @see #statsd_count_success
239
246
  def statsd_count_if(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil,
240
- sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: nil, no_prefix: false)
247
+ sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg,
248
+ prefix: nil, no_prefix: false, client: nil)
241
249
 
242
250
  add_to_method(method, name, :count_if) do
243
251
  define_method(method) do |*args, &block|
@@ -257,9 +265,10 @@ module StatsD
257
265
  result
258
266
  ensure
259
267
  if truthiness
260
- prefix ||= StatsD.prefix unless no_prefix
268
+ client ||= StatsD.singleton_client
269
+ prefix ||= client.prefix unless no_prefix
261
270
  key = StatsD::Instrument.generate_metric_name(prefix, name, self, *args)
262
- StatsD.increment(key, sample_rate: sample_rate, tags: tags, no_prefix: true)
271
+ client.increment(key, sample_rate: sample_rate, tags: tags, no_prefix: true)
263
272
  end
264
273
  end
265
274
  end
@@ -276,13 +285,15 @@ module StatsD
276
285
  # @param metric_options (see #statsd_measure)
277
286
  # @return [void]
278
287
  def statsd_count(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil,
279
- sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg, prefix: nil, no_prefix: false)
288
+ sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg,
289
+ prefix: nil, no_prefix: false, client: nil)
280
290
 
281
291
  add_to_method(method, name, :count) do
282
292
  define_method(method) do |*args, &block|
283
- prefix ||= StatsD.prefix unless no_prefix
293
+ client ||= StatsD.singleton_client
294
+ prefix ||= client.prefix unless no_prefix
284
295
  key = StatsD::Instrument.generate_metric_name(prefix, name, self, *args)
285
- StatsD.increment(key, sample_rate: sample_rate, tags: tags, no_prefix: true)
296
+ client.increment(key, sample_rate: sample_rate, tags: tags, no_prefix: true)
286
297
  super(*args, &block)
287
298
  end
288
299
  end
@@ -333,6 +344,10 @@ module StatsD
333
344
  remove_from_method(method, name, :distribution)
334
345
  end
335
346
 
347
+ VoidClass = Class.new(BasicObject)
348
+ private_constant :VoidClass
349
+ VOID = VoidClass.new
350
+
336
351
  private
337
352
 
338
353
  def statsd_instrumentation_for(method, name, action)
@@ -5,7 +5,7 @@
5
5
  #
6
6
  # Every metric type has its own assertion method, like {#assert_statsd_increment}
7
7
  # to assert `StatsD.increment` calls. You can also assert other properties of the
8
- # metric that was emitted, lioke the sample rate or presence of tags.
8
+ # metric that was emitted, like the sample rate or presence of tags.
9
9
  # To check for the absence of metrics, use {#assert_no_statsd_calls}.
10
10
  #
11
11
  # @example Check for metric properties:
@@ -44,21 +44,21 @@ module StatsD::Instrument::Assertions
44
44
 
45
45
  # Asserts no metric occurred during the execution of the provided block.
46
46
  #
47
- # @param [String] metric_name (default: nil) The metric name that is not allowed
48
- # to happen inside the block. If this is set to `nil`, the assertion will fail
49
- # if any metric occurs.
47
+ # @param [Array<String>] metric_names (default: []) The metric names that are not
48
+ # allowed to happen inside the block. If this is set to `[]`, the assertion
49
+ # will fail if any metric occurs.
50
50
  # @yield A block in which the specified metric should not occur. This block
51
51
  # should not raise any exceptions.
52
52
  # @return [void]
53
53
  # @raise [Minitest::Assertion] If an exception occurs, or if any metric (with the
54
- # provided name, or any), occurred during the execution of the provided block.
55
- def assert_no_statsd_calls(metric_name = nil, datagrams: nil, client: nil, &block)
54
+ # provided names, or any), occurred during the execution of the provided block.
55
+ def assert_no_statsd_calls(*metric_names, datagrams: nil, client: nil, &block)
56
56
  if datagrams.nil?
57
57
  raise LocalJumpError, "assert_no_statsd_calls requires a block" unless block_given?
58
58
  datagrams = capture_statsd_datagrams_with_exception_handling(client: client, &block)
59
59
  end
60
60
 
61
- datagrams.select! { |m| m.name == metric_name } if metric_name
61
+ datagrams.select! { |metric| metric_names.include?(metric.name) } unless metric_names.empty?
62
62
  assert(datagrams.empty?, "No StatsD calls for metric #{datagrams.map(&:name).join(', ')} expected.")
63
63
  end
64
64
 
@@ -8,7 +8,7 @@ class StatsD::Instrument::Backend
8
8
  # @param metric [StatsD::Instrument::Metric] The metric to collect
9
9
  # @return [void]
10
10
  def collect_metric(_metric)
11
- raise NotImplementedError, "Use a concerete backend implementation"
11
+ raise NotImplementedError, "Use a concrete backend implementation"
12
12
  end
13
13
  end
14
14
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'statsd/instrument/datagram'
4
+ require 'statsd/instrument/dogstatsd_datagram'
4
5
  require 'statsd/instrument/datagram_builder'
5
6
  require 'statsd/instrument/statsd_datagram_builder'
6
7
  require 'statsd/instrument/dogstatsd_datagram_builder'
@@ -105,7 +106,7 @@ class StatsD::Instrument::Client
105
106
  # @return [void]
106
107
  def increment(name, value = 1, sample_rate: nil, tags: nil, no_prefix: false)
107
108
  sample_rate ||= @default_sample_rate
108
- return unless sample?(sample_rate)
109
+ return StatsD::Instrument::VOID unless sample?(sample_rate)
109
110
  emit(datagram_builder(no_prefix: no_prefix).c(name, value, sample_rate, tags))
110
111
  end
111
112
 
@@ -122,7 +123,7 @@ class StatsD::Instrument::Client
122
123
  end
123
124
 
124
125
  sample_rate ||= @default_sample_rate
125
- return unless sample?(sample_rate)
126
+ return StatsD::Instrument::VOID unless sample?(sample_rate)
126
127
  emit(datagram_builder(no_prefix: no_prefix).ms(name, value, sample_rate, tags))
127
128
  end
128
129
 
@@ -141,7 +142,7 @@ class StatsD::Instrument::Client
141
142
  # @return [void]
142
143
  def gauge(name, value, sample_rate: nil, tags: nil, no_prefix: false)
143
144
  sample_rate ||= @default_sample_rate
144
- return unless sample?(sample_rate)
145
+ return StatsD::Instrument::VOID unless sample?(sample_rate)
145
146
  emit(datagram_builder(no_prefix: no_prefix).g(name, value, sample_rate, tags))
146
147
  end
147
148
 
@@ -154,7 +155,7 @@ class StatsD::Instrument::Client
154
155
  # @return [void]
155
156
  def set(name, value, sample_rate: nil, tags: nil, no_prefix: false)
156
157
  sample_rate ||= @default_sample_rate
157
- return unless sample?(sample_rate)
158
+ return StatsD::Instrument::VOID unless sample?(sample_rate)
158
159
  emit(datagram_builder(no_prefix: no_prefix).s(name, value, sample_rate, tags))
159
160
  end
160
161
 
@@ -162,7 +163,7 @@ class StatsD::Instrument::Client
162
163
  # values.
163
164
  #
164
165
  # @note The distribution metric type is not available on all implementations.
165
- # A `NotImplemetedError` will be raised if you call this method, but
166
+ # A `NotImplementedError` will be raised if you call this method, but
166
167
  # the active implementation does not support it.
167
168
  #
168
169
  # @param name (see #increment)
@@ -176,14 +177,14 @@ class StatsD::Instrument::Client
176
177
  end
177
178
 
178
179
  sample_rate ||= @default_sample_rate
179
- return unless sample?(sample_rate)
180
+ return StatsD::Instrument::VOID unless sample?(sample_rate)
180
181
  emit(datagram_builder(no_prefix: no_prefix).d(name, value, sample_rate, tags))
181
182
  end
182
183
 
183
184
  # Emits a histogram metric, which builds a histogram of the reported values.
184
185
  #
185
186
  # @note The histogram metric type is not available on all implementations.
186
- # A `NotImplemetedError` will be raised if you call this method, but
187
+ # A `NotImplementedError` will be raised if you call this method, but
187
188
  # the active implementation does not support it.
188
189
  #
189
190
  # @param name (see #increment)
@@ -193,7 +194,7 @@ class StatsD::Instrument::Client
193
194
  # @return [void]
194
195
  def histogram(name, value, sample_rate: nil, tags: nil, no_prefix: false)
195
196
  sample_rate ||= @default_sample_rate
196
- return unless sample?(sample_rate)
197
+ return StatsD::Instrument::VOID unless sample?(sample_rate)
197
198
  emit(datagram_builder(no_prefix: no_prefix).h(name, value, sample_rate, tags))
198
199
  end
199
200
 
@@ -208,7 +209,7 @@ class StatsD::Instrument::Client
208
209
  # use the preferred metric type of the implementation. The default is `:ms`.
209
210
  # Generally, you should not have to set this.
210
211
  # @yield The latency (execution time) of the block
211
- # @return The return value of the proivded block will be passed through.
212
+ # @return The return value of the provided block will be passed through.
212
213
  def latency(name, sample_rate: nil, tags: nil, metric_type: nil, no_prefix: false)
213
214
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
214
215
  begin
@@ -342,6 +343,6 @@ class StatsD::Instrument::Client
342
343
 
343
344
  def emit(datagram)
344
345
  @sink << datagram
345
- nil
346
+ StatsD::Instrument::VOID
346
347
  end
347
348
  end