statsd-instrument 2.9.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +14 -21
  3. data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +15 -15
  4. data/CHANGELOG.md +44 -0
  5. data/benchmark/send-metrics-to-dev-null-log +5 -2
  6. data/benchmark/send-metrics-to-local-udp-receiver +8 -6
  7. data/lib/statsd/instrument.rb +79 -146
  8. data/lib/statsd/instrument/assertions.rb +12 -24
  9. data/lib/statsd/instrument/client.rb +125 -35
  10. data/lib/statsd/instrument/environment.rb +1 -23
  11. data/lib/statsd/instrument/expectation.rb +12 -16
  12. data/lib/statsd/instrument/helpers.rb +1 -30
  13. data/lib/statsd/instrument/matchers.rb +0 -1
  14. data/lib/statsd/instrument/railtie.rb +0 -4
  15. data/lib/statsd/instrument/strict.rb +12 -123
  16. data/lib/statsd/instrument/version.rb +1 -1
  17. data/test/assertions_test.rb +21 -9
  18. data/test/client_test.rb +11 -0
  19. data/test/environment_test.rb +1 -37
  20. data/test/integration_test.rb +9 -24
  21. data/test/statsd_instrumentation_test.rb +25 -50
  22. data/test/statsd_test.rb +6 -31
  23. data/test/test_helper.rb +1 -1
  24. metadata +2 -24
  25. data/benchmark/datagram-client +0 -40
  26. data/lib/statsd/instrument/backend.rb +0 -18
  27. data/lib/statsd/instrument/backends/capture_backend.rb +0 -32
  28. data/lib/statsd/instrument/backends/logger_backend.rb +0 -20
  29. data/lib/statsd/instrument/backends/null_backend.rb +0 -9
  30. data/lib/statsd/instrument/backends/udp_backend.rb +0 -152
  31. data/lib/statsd/instrument/legacy_client.rb +0 -301
  32. data/lib/statsd/instrument/metric.rb +0 -155
  33. data/test/assertions_on_legacy_client_test.rb +0 -344
  34. data/test/capture_backend_test.rb +0 -26
  35. data/test/compatibility/dogstatsd_datagram_compatibility_test.rb +0 -161
  36. data/test/deprecations_test.rb +0 -139
  37. data/test/logger_backend_test.rb +0 -22
  38. data/test/metric_test.rb +0 -47
  39. data/test/udp_backend_test.rb +0 -228
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28a52ac92cfb09e796f1eb8af9fde1a701255e61ac7377d32a7f6e92569c0e05
4
- data.tar.gz: bae7f0b29a3ce2ed62486a0866e592ca29ac5d18c11ad0815e7cb71991de50a8
3
+ metadata.gz: 9e941d77f1b0893b2a919f8c36e902e119c657338e6a4e8b45fc5eaa7b5a05a3
4
+ data.tar.gz: f80105adf47e4379a59716bd7bb46080db3ed9751edf9ef21ef64689ce39920a
5
5
  SHA512:
6
- metadata.gz: 87f9772a163d3ed4f400203f83db6c39dc946b75e21288fdd7a6ab7aa5b43646fcfa2fd3564d61b2795d192bcc82ae196dc1ec765d465b098620b9bcaf05c013
7
- data.tar.gz: d74cc5375319064d64e23e8fd1a6bf7583781783d296c12fb1ae233e45ddaecff8dd4bbfa9c1bf912fcd48daacb8f47511b019d4bf26b74a2ca235267054012b
6
+ metadata.gz: 3518393ed260edb75f138168afad1e0f1cbd604bf12511dd73596b84d1721d0008cae138cfdef03291895bd4f8b861dd18b641dcfda093e84976a0d446da5bd3
7
+ data.tar.gz: 4fd2bc2646b88b497802103eaed1538234e37619ef35363ed061b43ce100dd4d59f03de037b5b766c46e8937b7c926fbba2a0dba7f10d5610fae43e2c31f17f2
@@ -4,24 +4,17 @@ on: push
4
4
 
5
5
  jobs:
6
6
  test:
7
- name: Ruby ${{ matrix.ruby }} on ${{ matrix.platform }}
8
- runs-on: ${{ matrix.platform }}
7
+ name: Ruby ${{ matrix.ruby }} on ubuntu-18.04
8
+ runs-on: ubuntu-18.04
9
9
  strategy:
10
10
  fail-fast: false
11
11
  matrix:
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]
22
- ruby: [2.3, 2.4, 2.5, 2.6]
23
-
24
- exclude:
12
+ # Windows on macOS builds started failing, so they are disabled for noew
13
+
14
+ ruby: [2.4, 2.5, 2.6]
15
+ # platform: [windows-2019, macOS-10.14, ubuntu-18.04]
16
+
17
+ # exclude:
25
18
  # The Windows environment does not support older Ruby versions. We only test against the latest version
26
19
  # - platform: windows-2019
27
20
  # ruby: 2.3
@@ -31,12 +24,12 @@ jobs:
31
24
  # ruby: 2.5
32
25
 
33
26
  # On macOS, we only test against the Ruby version macOS ships with (2.3)
34
- - platform: macOS-10.14
35
- ruby: 2.4
36
- - platform: macOS-10.14
37
- ruby: 2.5
38
- - platform: macOS-10.14
39
- ruby: 2.6
27
+ # - platform: macOS-10.14
28
+ # ruby: 2.4
29
+ # - platform: macOS-10.14
30
+ # ruby: 2.5
31
+ # - platform: macOS-10.14
32
+ # ruby: 2.6
40
33
 
41
34
  steps:
42
35
  - uses: actions/checkout@v1
@@ -20,7 +20,7 @@ Style/Alias:
20
20
  - prefer_alias
21
21
  - prefer_alias_method
22
22
 
23
- Layout/AlignHash:
23
+ Layout/HashAlignment:
24
24
  EnforcedHashRocketStyle: key
25
25
  EnforcedColonStyle: key
26
26
  EnforcedLastArgumentHashStyle: ignore_implicit
@@ -30,7 +30,7 @@ Layout/AlignHash:
30
30
  - ignore_implicit
31
31
  - ignore_explicit
32
32
 
33
- Layout/AlignParameters:
33
+ Layout/ParameterAlignment:
34
34
  EnforcedStyle: with_fixed_indentation
35
35
  SupportedStyles:
36
36
  - with_first_parameter
@@ -172,7 +172,7 @@ Naming/FileName:
172
172
  Regex:
173
173
  IgnoreExecutableScripts: true
174
174
 
175
- Layout/IndentFirstArgument:
175
+ Layout/FirstArgumentIndentation:
176
176
  EnforcedStyle: consistent
177
177
  SupportedStyles:
178
178
  - consistent
@@ -225,7 +225,7 @@ Layout/IndentationConsistency:
225
225
  Layout/IndentationWidth:
226
226
  Width: 2
227
227
 
228
- Layout/IndentFirstArrayElement:
228
+ Layout/FirstArrayElementIndentation:
229
229
  EnforcedStyle: consistent
230
230
  SupportedStyles:
231
231
  - special_inside_parentheses
@@ -233,10 +233,10 @@ Layout/IndentFirstArrayElement:
233
233
  - align_brackets
234
234
  IndentationWidth:
235
235
 
236
- Layout/IndentAssignment:
236
+ Layout/AssignmentIndentation:
237
237
  IndentationWidth:
238
238
 
239
- Layout/IndentFirstHashElement:
239
+ Layout/FirstHashElementIndentation:
240
240
  EnforcedStyle: consistent
241
241
  SupportedStyles:
242
242
  - special_inside_parentheses
@@ -340,9 +340,9 @@ Style/PercentQLiterals:
340
340
  Naming/PredicateName:
341
341
  NamePrefix:
342
342
  - is_
343
- NamePrefixBlacklist:
343
+ ForbiddenPrefixes:
344
344
  - is_
345
- NameWhitelist:
345
+ AllowedMethods:
346
346
  - is_a?
347
347
  Exclude:
348
348
  - 'spec/**/*'
@@ -467,7 +467,7 @@ Style/TernaryParentheses:
467
467
  - require_no_parentheses
468
468
  AllowSafeAssignment: true
469
469
 
470
- Layout/TrailingBlankLines:
470
+ Layout/TrailingEmptyLines:
471
471
  EnforcedStyle: final_newline
472
472
  SupportedStyles:
473
473
  - final_newline
@@ -478,7 +478,7 @@ Style/TrivialAccessors:
478
478
  AllowPredicates: true
479
479
  AllowDSLWriters: false
480
480
  IgnoreClassMethods: false
481
- Whitelist:
481
+ AllowedMethods:
482
482
  - to_ary
483
483
  - to_a
484
484
  - to_c
@@ -561,7 +561,7 @@ Lint/UnusedMethodArgument:
561
561
  Naming/AccessorMethodName:
562
562
  Enabled: true
563
563
 
564
- Layout/AlignArray:
564
+ Layout/ArrayAlignment:
565
565
  Enabled: true
566
566
 
567
567
  Style/ArrayJoin:
@@ -840,7 +840,7 @@ Style/WhileUntilDo:
840
840
  Style/ZeroLengthPredicate:
841
841
  Enabled: true
842
842
 
843
- Layout/IndentHeredoc:
843
+ Layout/HeredocIndentation:
844
844
  EnforcedStyle: squiggly
845
845
 
846
846
  Lint/AmbiguousOperator:
@@ -864,7 +864,7 @@ Lint/DeprecatedClassMethods:
864
864
  Lint/DuplicateMethods:
865
865
  Enabled: true
866
866
 
867
- Lint/DuplicatedKey:
867
+ Lint/DuplicateHashKey:
868
868
  Enabled: true
869
869
 
870
870
  Lint/EachWithObjectArgument:
@@ -891,7 +891,7 @@ Lint/FloatOutOfRange:
891
891
  Lint/FormatParameterMismatch:
892
892
  Enabled: true
893
893
 
894
- Lint/HandleExceptions:
894
+ Lint/SuppressedException:
895
895
  AllowComments: true
896
896
 
897
897
  Lint/ImplicitStringConcatenation:
@@ -947,7 +947,7 @@ Lint/ShadowedException:
947
947
  Lint/ShadowingOuterLocalVariable:
948
948
  Enabled: true
949
949
 
950
- Lint/StringConversionInInterpolation:
950
+ Lint/RedundantStringCoercion:
951
951
  Enabled: true
952
952
 
953
953
  Lint/UnderscorePrefixedVariableName:
@@ -6,6 +6,50 @@ section below.
6
6
 
7
7
  ### Unreleased changes
8
8
 
9
+ _Nothing yet_
10
+
11
+ ## Version 3.0.0
12
+
13
+ This version makes the new client that was added in version 2.6+ the default
14
+ client, and removes the legacy client.
15
+
16
+ - All previously deprecated functionality has been removed (since version 2.5,
17
+ see below).
18
+ - Support for the StatSite implementation has been dropped.
19
+ - Support for Ruby version older than 2.4 has been dropped.
20
+ - The default implementation has been changed to DataDog. To use the standard
21
+ StatsD implementation (which was the default in v2), set the
22
+ `STATSD_IMPLEMENTATION` environment variable to `statsd`.
23
+
24
+ To upgrade, follow the following process:
25
+
26
+ 1. Upgrade to version 2.9.2.
27
+ 2. Switch to the new client by setting the `STATSD_USE_NEW_CLIENT` environment
28
+ variable to 1.
29
+ - You may want to use the Rubocop rules that ship with this library, and
30
+ strict mode to find and fix deprecated usage patterns. See below for more
31
+ information about strict mode and the available Rubocop rules.
32
+ 3. Upgrade to version 3.0.0, and unset `STATSD_USE_NEW_CLIENT`.
33
+
34
+ ## Version 2.9.2
35
+
36
+ - Allow providing a value as second positional argument to `assert_statsd_*`
37
+ methods, rather than as keyword argument. This matches the arguments to the
38
+ StatsD metric call.
39
+ ``` ruby
40
+ assert_statsd_increment('batch_size', 10) do
41
+ StatsD.increment('batch_size', 10)
42
+ end
43
+ ```
44
+
45
+ ## Version 2.9.1
46
+
47
+ - The `VOID` object being returned by metric methods (e.g. `StatsD.increment`)
48
+ is now a subclass of `Object` rather than `BasicObject`, which means that
49
+ common methods will work as expected (`#class`, `#tap`).
50
+
51
+ ## Version 2.9.0
52
+
9
53
  - ⚠️ **DEPRECATION:** The `StatsD.key_value` metric method is deprecated
10
54
  and will be removed in version 3.0. The new client does not have StatSite
11
55
  support. Due to the lack of active contributors that can port this metric
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'bundler/setup'
5
+ require 'tmpdir'
5
6
  require 'benchmark/ips'
6
7
 
7
8
  revision = %x(git rev-parse HEAD).rstrip
@@ -25,8 +26,10 @@ report = Benchmark.ips do |bench|
25
26
  StatsD.measure('StatsD.measure') { 1 + 1 }
26
27
  StatsD.gauge('StatsD.gauge', 12.0, tags: ["foo:bar", "quc"])
27
28
  StatsD.set('StatsD.set', 'value', tags: { foo: 'bar', baz: 'quc' })
28
- StatsD.event('StasD.event', "12345")
29
- StatsD.service_check("StatsD.service_check", "ok")
29
+ if StatsD.singleton_client.datagram_builder_class == StatsD::Instrument::DogStatsDDatagramBuilder
30
+ StatsD.event('StasD.event', "12345")
31
+ StatsD.service_check("StatsD.service_check", "ok")
32
+ end
30
33
  end
31
34
 
32
35
  # Store the results in between runs
@@ -3,7 +3,9 @@
3
3
 
4
4
  require 'bundler/setup'
5
5
  require 'benchmark/ips'
6
+ require 'tmpdir'
6
7
  require 'socket'
8
+ require 'statsd-instrument'
7
9
 
8
10
  revision = %x(git rev-parse HEAD).rstrip
9
11
  master_revision = %x(git rev-parse origin/master).rstrip
@@ -20,11 +22,11 @@ FileUtils.mkdir_p(File.dirname(intermediate_results_filename))
20
22
  receiver = UDPSocket.new
21
23
  receiver.bind('localhost', 0)
22
24
 
23
- ENV['ENV'] = "production"
24
- ENV['STATSD_ADDR'] = "#{receiver.addr[2]}:#{receiver.addr[1]}"
25
- ENV['STATSD_IMPLEMENTATION'] ||= 'datadog'
26
-
27
- require 'statsd-instrument'
25
+ StatsD.singleton_client = StatsD::Instrument::Environment.new(
26
+ 'STATSD_ADDR' => "#{receiver.addr[2]}:#{receiver.addr[1]}",
27
+ 'STATSD_IMPLEMENTATION' => 'dogstatsd',
28
+ 'STATSD_ENV' => 'production',
29
+ ).client
28
30
 
29
31
  report = Benchmark.ips do |bench|
30
32
  bench.report("StatsD metrics to local UDP receiver (branch: #{branch}, sha: #{revision[0, 7]})") do
@@ -32,7 +34,7 @@ report = Benchmark.ips do |bench|
32
34
  StatsD.measure('StatsD.measure') { 1 + 1 }
33
35
  StatsD.gauge('StatsD.gauge', 12.0, tags: ["foo:bar", "quc"])
34
36
  StatsD.set('StatsD.set', 'value', tags: { foo: 'bar', baz: 'quc' })
35
- if StatsD.backend.implementation == :datadog
37
+ if StatsD.singleton_client.datagram_builder_class == StatsD::Instrument::DogStatsDDatagramBuilder
36
38
  StatsD.event('StasD.event', "12345")
37
39
  StatsD.service_check("StatsD.service_check", "ok")
38
40
  end
@@ -4,90 +4,14 @@ require 'socket'
4
4
  require 'logger'
5
5
  require 'forwardable'
6
6
 
7
- # The StatsD module contains low-level metrics for collecting metrics and sending them to the backend.
7
+ # The `StatsD` module contains low-level metrics for collecting metrics and
8
+ # sending them to the backend.
8
9
  #
9
- # @!attribute client
10
- # @return [StatsD::Instrument::Backend] The client that will handle singleton method calls in the next
11
- # major version of this library.
12
- # @note This new Client implementation is intended to become the new default in
13
- # the next major release of this library. While this class may already be functional,
14
- # we provide no guarantees about the API and the behavior may change.
15
- #
16
- # @!attribute backend
17
- # The backend that is being used to emit the metrics.
18
- # @return [StatsD::Instrument::Backend] the currently active backend. If there is no active backend
19
- # yet, it will call {StatsD::Instrument::Environment#default_backend} to obtain a
20
- # default backend for the environment.
21
- # @see StatsD::Instrument::Environment#default_backend
22
- # @deprecated
23
- #
24
- # @!attribute prefix
25
- # The prefix to apply to metric names. This can be useful to group all the metrics
26
- # for an application in a shared StatsD server.
27
- #
28
- # When using a prefix a dot will be included automatically to separate the prefix
29
- # from the metric name.
30
- #
31
- # @return [String, nil] The prefix, or <tt>nil</tt> when no prefix is used
32
- # @see StatsD::Instrument::Metric#name
33
- # @deprecated
34
- #
35
- # @!attribute default_sample_rate
36
- # The sample rate to use if the sample rate is unspecified for a metric call.
37
- # @return [Float] Default is 1.0.
38
- # @deprecated
39
- #
40
- # @!attribute logger
41
- # The logger to use in case of any errors. The logger is also used as default logger
42
- # for the LoggerBackend (although this can be overwritten).
43
- # @see StatsD::Instrument::Backends::LoggerBackend
44
- # @return [Logger]
45
- #
46
- # @!attribute default_tags
47
- # The tags to apply to all metrics.
48
- # @return [Array<String>, Hash<String, String>, nil] The default tags, or <tt>nil</tt> when no default tags is used
49
- # @deprecated
50
- #
51
- # @!attribute legacy_singleton_client
52
- # @nodoc
53
- # @deprecated
54
- #
55
- # @!attribute singleton_client
56
- # @nodoc
57
- # @deprecated
58
- #
59
- # @!method measure(name, value = nil, sample_rate: nil, tags: nil, &block)
60
- # (see StatsD::Instrument::LegacyClient#measure)
61
- #
62
- # @!method increment(name, value = 1, sample_rate: nil, tags: nil)
63
- # (see StatsD::Instrument::LegacyClient#increment)
64
- #
65
- # @!method gauge(name, value, sample_rate: nil, tags: nil)
66
- # (see StatsD::Instrument::LegacyClient#gauge)
67
- #
68
- # @!method set(name, value, sample_rate: nil, tags: nil)
69
- # (see StatsD::Instrument::LegacyClient#set)
70
- #
71
- # @!method histogram(name, value, sample_rate: nil, tags: nil)
72
- # (see StatsD::Instrument::LegacyClient#histogram)
73
- #
74
- # @!method distribution(name, value = nil, sample_rate: nil, tags: nil, &block)
75
- # (see StatsD::Instrument::LegacyClient#distribution)
76
- #
77
- # @!method key_value(name, value)
78
- # (see StatsD::Instrument::LegacyClient#key_value)
79
- #
80
- # @!method event(title, text, tags: nil, hostname: nil, timestamp: nil, aggregation_key: nil, priority: nil, source_type_name: nil, alert_type: nil) # rubocop:disable Metrics/LineLength
81
- # (see StatsD::Instrument::LegacyClient#event)
82
- #
83
- # @!method service_check(name, status, tags: nil, hostname: nil, timestamp: nil, message: nil)
84
- # (see StatsD::Instrument::LegacyClient#service_check)
85
- #
86
- # @see StatsD::Instrument <tt>StatsD::Instrument</tt> contains module to instrument
10
+ # @see .singleton_client Metric method calls on the `StatsD` singleton will
11
+ # be handled by the client assigned to `StatsD.singleton_client`.
12
+ # @see StatsD::Instrument `StatsD::Instrument` contains module to instrument
87
13
  # existing methods with StatsD metrics
88
14
  module StatsD
89
- extend self
90
-
91
15
  # The StatsD::Instrument module provides metaprogramming methods to instrument your methods with
92
16
  # StatsD metrics. E.g., you can create counters on how often a method is called, how often it is
93
17
  # successful, the duration of the methods call, etc.
@@ -103,11 +27,11 @@ module StatsD
103
27
  end
104
28
  end
105
29
 
30
+ # Generates a metric name for an instrumented method.
106
31
  # @private
107
- def self.generate_metric_name(prefix, key, callee, *args)
108
- name = key.respond_to?(:call) ? key.call(callee, args).gsub('::', '.') : key.gsub('::', '.')
109
- name = "#{prefix}.#{name}" if prefix
110
- name
32
+ # @return [String]
33
+ def self.generate_metric_name(name, callee, *args)
34
+ name.respond_to?(:call) ? name.call(callee, args).gsub('::', '.') : name.gsub('::', '.')
111
35
  end
112
36
 
113
37
  # Even though this method is considered private, and is no longer used internally,
@@ -139,21 +63,12 @@ module StatsD
139
63
  # callable to dynamically generate a metric name
140
64
  # @param metric_options (see StatsD#measure)
141
65
  # @return [void]
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)
145
-
146
- if as_dist
147
- return statsd_distribution(method, name, # rubocop:disable StatsD/MetricPrefixArgument
148
- sample_rate: sample_rate, tags: tags, prefix: prefix, no_prefix: no_prefix)
149
- end
150
-
66
+ def statsd_measure(method, name, sample_rate: nil, tags: nil, no_prefix: false, client: nil)
151
67
  add_to_method(method, name, :measure) do
152
68
  define_method(method) do |*args, &block|
153
69
  client ||= StatsD.singleton_client
154
- prefix ||= client.prefix unless no_prefix
155
- key = StatsD::Instrument.generate_metric_name(prefix, name, self, *args)
156
- client.measure(key, sample_rate: sample_rate, tags: tags, no_prefix: true) do
70
+ key = StatsD::Instrument.generate_metric_name(name, self, *args)
71
+ client.measure(key, sample_rate: sample_rate, tags: tags, no_prefix: no_prefix) do
157
72
  super(*args, &block)
158
73
  end
159
74
  end
@@ -168,16 +83,12 @@ module StatsD
168
83
  # @param metric_options (see StatsD#measure)
169
84
  # @return [void]
170
85
  # @note Supported by the datadog implementation only (in beta)
171
- def statsd_distribution(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil,
172
- sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg,
173
- prefix: nil, no_prefix: false, client: nil)
174
-
86
+ def statsd_distribution(method, name, sample_rate: nil, tags: nil, no_prefix: false, client: nil)
175
87
  add_to_method(method, name, :distribution) do
176
88
  define_method(method) do |*args, &block|
177
89
  client ||= StatsD.singleton_client
178
- prefix ||= client.prefix unless no_prefix
179
- key = StatsD::Instrument.generate_metric_name(prefix, name, self, *args)
180
- client.distribution(key, sample_rate: sample_rate, tags: tags, no_prefix: true) do
90
+ key = StatsD::Instrument.generate_metric_name(name, self, *args)
91
+ client.distribution(key, sample_rate: sample_rate, tags: tags, no_prefix: no_prefix) do
181
92
  super(*args, &block)
182
93
  end
183
94
  end
@@ -199,10 +110,7 @@ module StatsD
199
110
  # @yieldreturn [Boolean] Return true iff the return value is considered a success, false otherwise.
200
111
  # @return [void]
201
112
  # @see #statsd_count_if
202
- def statsd_count_success(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil,
203
- sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg,
204
- prefix: nil, no_prefix: false, client: nil)
205
-
113
+ def statsd_count_success(method, name, sample_rate: nil, tags: nil, no_prefix: false, client: nil)
206
114
  add_to_method(method, name, :count_success) do
207
115
  define_method(method) do |*args, &block|
208
116
  begin
@@ -222,10 +130,8 @@ module StatsD
222
130
  ensure
223
131
  client ||= StatsD.singleton_client
224
132
  suffix = truthiness == false ? 'failure' : 'success'
225
- prefix ||= client.prefix unless no_prefix
226
- key = StatsD::Instrument.generate_metric_name(prefix, name, self, *args)
227
- client.increment("#{key}.#{suffix}",
228
- sample_rate: sample_rate, tags: tags, no_prefix: true)
133
+ key = StatsD::Instrument.generate_metric_name(name, self, *args)
134
+ client.increment("#{key}.#{suffix}", sample_rate: sample_rate, tags: tags, no_prefix: no_prefix)
229
135
  end
230
136
  end
231
137
  end
@@ -243,10 +149,7 @@ module StatsD
243
149
  # @yieldreturn (see #statsd_count_success)
244
150
  # @return [void]
245
151
  # @see #statsd_count_success
246
- def statsd_count_if(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil,
247
- sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg,
248
- prefix: nil, no_prefix: false, client: nil)
249
-
152
+ def statsd_count_if(method, name, sample_rate: nil, tags: nil, no_prefix: false, client: nil)
250
153
  add_to_method(method, name, :count_if) do
251
154
  define_method(method) do |*args, &block|
252
155
  begin
@@ -266,9 +169,8 @@ module StatsD
266
169
  ensure
267
170
  if truthiness
268
171
  client ||= StatsD.singleton_client
269
- prefix ||= client.prefix unless no_prefix
270
- key = StatsD::Instrument.generate_metric_name(prefix, name, self, *args)
271
- client.increment(key, sample_rate: sample_rate, tags: tags, no_prefix: true)
172
+ key = StatsD::Instrument.generate_metric_name(name, self, *args)
173
+ client.increment(key, sample_rate: sample_rate, tags: tags, no_prefix: no_prefix)
272
174
  end
273
175
  end
274
176
  end
@@ -284,16 +186,12 @@ module StatsD
284
186
  # @param name (see #statsd_measure)
285
187
  # @param metric_options (see #statsd_measure)
286
188
  # @return [void]
287
- def statsd_count(method, name, deprecated_sample_rate_arg = nil, deprecated_tags_arg = nil,
288
- sample_rate: deprecated_sample_rate_arg, tags: deprecated_tags_arg,
289
- prefix: nil, no_prefix: false, client: nil)
290
-
189
+ def statsd_count(method, name, sample_rate: nil, tags: nil, no_prefix: false, client: nil)
291
190
  add_to_method(method, name, :count) do
292
191
  define_method(method) do |*args, &block|
293
192
  client ||= StatsD.singleton_client
294
- prefix ||= client.prefix unless no_prefix
295
- key = StatsD::Instrument.generate_metric_name(prefix, name, self, *args)
296
- client.increment(key, sample_rate: sample_rate, tags: tags, no_prefix: true)
193
+ key = StatsD::Instrument.generate_metric_name(name, self, *args)
194
+ client.increment(key, sample_rate: sample_rate, tags: tags, no_prefix: no_prefix)
297
195
  super(*args, &block)
298
196
  end
299
197
  end
@@ -344,9 +242,9 @@ module StatsD
344
242
  remove_from_method(method, name, :distribution)
345
243
  end
346
244
 
347
- VoidClass = Class.new(BasicObject)
245
+ VoidClass = Class.new
348
246
  private_constant :VoidClass
349
- VOID = VoidClass.new
247
+ VOID = VoidClass.new.freeze
350
248
 
351
249
  private
352
250
 
@@ -395,33 +293,68 @@ module StatsD
395
293
  end
396
294
  end
397
295
 
398
- attr_accessor :logger
399
- attr_writer :singleton_client
296
+ class << self
297
+ extend Forwardable
400
298
 
401
- extend Forwardable
299
+ # The logger to use in case of any errors.
300
+ #
301
+ # @return [Logger]
302
+ # @see StatsD::Instrument::LogSink
303
+ attr_accessor :logger
402
304
 
403
- def legacy_singleton_client
404
- StatsD::Instrument::LegacyClient.singleton
405
- end
305
+ # The StatsD client that handles method calls on the StatsD singleton.
306
+ #
307
+ # E.g. a call to `StatsD.increment` will be handled by this client.
308
+ #
309
+ # @return [StatsD::Instrument::Client]
310
+ attr_writer :singleton_client
406
311
 
407
- def singleton_client
408
- @singleton_client ||= StatsD::Instrument::Environment.current.client
409
- end
312
+ # The StatsD client that handles method calls on the StatsD singleton
313
+ # @return [StatsD::Instrument::Client]
314
+ def singleton_client
315
+ @singleton_client ||= StatsD::Instrument::Environment.current.client
316
+ end
410
317
 
411
- # Singleton methods will be delegated to the singleton client.
412
- def_delegators :singleton_client, :increment, :gauge, :set, :measure,
413
- :histogram, :distribution, :key_value, :event, :service_check
318
+ # @!method measure(name, value = nil, sample_rate: nil, tags: nil, &block)
319
+ # (see StatsD::Instrument::Client#measure)
320
+ #
321
+ # @!method increment(name, value = 1, sample_rate: nil, tags: nil)
322
+ # (see StatsD::Instrument::Client#increment)
323
+ #
324
+ # @!method gauge(name, value, sample_rate: nil, tags: nil)
325
+ # (see StatsD::Instrument::Client#gauge)
326
+ #
327
+ # @!method set(name, value, sample_rate: nil, tags: nil)
328
+ # (see StatsD::Instrument::Client#set)
329
+ #
330
+ # @!method histogram(name, value, sample_rate: nil, tags: nil)
331
+ # (see StatsD::Instrument::Client#histogram)
332
+ #
333
+ # @!method distribution(name, value = nil, sample_rate: nil, tags: nil, &block)
334
+ # (see StatsD::Instrument::Client#distribution)
335
+ #
336
+ # @!method event(title, text, tags: nil, hostname: nil, timestamp: nil, aggregation_key: nil, priority: nil, source_type_name: nil, alert_type: nil) # rubocop:disable Metrics/LineLength
337
+ # (see StatsD::Instrument::Client#event)
338
+ #
339
+ # @!method service_check(name, status, tags: nil, hostname: nil, timestamp: nil, message: nil)
340
+ # (see StatsD::Instrument::Client#service_check)
414
341
 
415
- # Deprecated methods will be delegated to the legacy client
416
- def_delegators :legacy_singleton_client, :default_tags, :default_tags=,
417
- :default_sample_rate, :default_sample_rate=, :prefix, :prefix=, :backend, :backend=
342
+ def_delegators :singleton_client, :increment, :gauge, :set, :measure,
343
+ :histogram, :distribution, :event, :service_check
344
+ end
418
345
  end
419
346
 
420
347
  require 'statsd/instrument/version'
421
- require 'statsd/instrument/metric'
422
- require 'statsd/instrument/legacy_client'
423
- require 'statsd/instrument/backend'
424
348
  require 'statsd/instrument/client'
349
+ require 'statsd/instrument/datagram'
350
+ require 'statsd/instrument/dogstatsd_datagram'
351
+ require 'statsd/instrument/datagram_builder'
352
+ require 'statsd/instrument/statsd_datagram_builder'
353
+ require 'statsd/instrument/dogstatsd_datagram_builder'
354
+ require 'statsd/instrument/null_sink'
355
+ require 'statsd/instrument/udp_sink'
356
+ require 'statsd/instrument/capture_sink'
357
+ require 'statsd/instrument/log_sink'
425
358
  require 'statsd/instrument/environment'
426
359
  require 'statsd/instrument/helpers'
427
360
  require 'statsd/instrument/assertions'