dogstatsd-ruby 5.3.3 → 5.4.0

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: aa6ffb63549958aaa8ec14103abbd51082bd945e31d20f0148571ee2c90350b3
4
- data.tar.gz: ef1361556ae6de5beb22523187c94ffe7285278918f47d671464b52708ae6973
3
+ metadata.gz: d780ad7a840c021ee3cb31a9e8b512ef7ccff4b82b14be9e300206d3a07cc61e
4
+ data.tar.gz: 2da798fe3a84f313c5c84655136597c562e3dc1bfaa24f8ba6441ef722c7cc45
5
5
  SHA512:
6
- metadata.gz: ba586784b291adaf8a2eaa7a5b866f7931f2c887cb372a69a715f51c0c36a34fba1480cb2ecfd8bbf9573052c2839724fb6389cfa81e157a280e0a75ba0b7072
7
- data.tar.gz: 7c2210e57a96e50825362dcedeaa686af6497f85941a9b7dab2a8ca67bbb7cec999d4f13015c5aab90b1a21cb824f5d8c3902cf5dd1421b3a54763a501f441b8
6
+ metadata.gz: 8f92d7dab8099d571c291e26497020e53087ccdbeecfd84d955778f484112f9b94fb0f4ec7d043b9efabd5d249333168fa44e4fe6e54ba4c9541447b92983ceb
7
+ data.tar.gz: 8dadc086c84a821d4a1b1824a25ea4861bdf0b6a36cfcf8c50a8d06e19d6853c35974dbefb03fedc9ccd7a3f57ff13a19d206c5eef152c1aa5ffbc1f789da1bc
data/README.md CHANGED
@@ -213,7 +213,13 @@ When using the `single_thread: true` mode, instances of `Datadog::Statsd` are st
213
213
 
214
214
  ## Versioning
215
215
 
216
- This Ruby gem is using [Semantic Versioning](https://guides.rubygems.org/patterns/#semantic-versioning) but please note that supported Ruby versions can change in a minor release of this library. As much as possible, we will add a "future deprecation" message in the minor release preceding the one dropping the support.
216
+ This Ruby gem is using [Semantic Versioning](https://guides.rubygems.org/patterns/#semantic-versioning) but please note that supported Ruby versions can change in a minor release of this library.
217
+ As much as possible, we will add a "future deprecation" message in the minor release preceding the one dropping the support.
218
+
219
+ ## Ruby Versions
220
+
221
+ This gem supports and is tested on Ruby minor versions 2.1 through 3.1.
222
+ Support for Ruby 2.0 was dropped in version 5.4.0.
217
223
 
218
224
  ## Credits
219
225
 
@@ -42,8 +42,8 @@ module Datadog
42
42
  not_both_error_message:
43
43
  "Both UDP (DD_AGENT_HOST/DD_DOGSTATSD_PORT #{ENV['DD_AGENT_HOST']}:#{ENV['DD_DOGSTATSD_PORT']}) " +
44
44
  "and UDS (DD_DOGSTATSD_SOCKET #{ENV['DD_DOGSTATSD_SOCKET']}) environment variables are set. " +
45
- "Set only one or the other." %
46
- [ENV['DD_AGENT_HOST'], ENV['DD_DOGSTATSD_PORT'], ENV['DD_DOGSTATSD_SOCKET']])
45
+ "Set only one or the other.",
46
+ )
47
47
  end
48
48
 
49
49
  def initialize_with_defaults()
@@ -4,6 +4,6 @@ require_relative 'connection'
4
4
 
5
5
  module Datadog
6
6
  class Statsd
7
- VERSION = '5.3.3'
7
+ VERSION = '5.4.0'
8
8
  end
9
9
  end
@@ -13,9 +13,6 @@ require_relative 'statsd/single_thread_sender'
13
13
  require_relative 'statsd/forwarder'
14
14
  require_relative 'statsd/timer'
15
15
 
16
- $deprecation_message_mutex = Mutex.new
17
- $deprecation_message_done = false
18
-
19
16
  # = Datadog::Statsd: A DogStatsd client (https://www.datadoghq.com)
20
17
  #
21
18
  # @example Set up a global Statsd client for a server on localhost:8125
@@ -116,19 +113,6 @@ module Datadog
116
113
  @serializer = Serialization::Serializer.new(prefix: @prefix, global_tags: tags)
117
114
  @sample_rate = sample_rate
118
115
 
119
- # deprecation message for ruby < 2.1.0 users as we will drop support for ruby 2.0
120
- # in dogstatsd-ruby 5.4.0
121
- # TODO(remy): remove this message and the two global vars used in dogstatd-ruby 5.4.0
122
- if RUBY_VERSION < '2.1.0' && $deprecation_message_mutex.try_lock && !$deprecation_message_done
123
- if logger != nil
124
- logger.warn { "deprecation: dogstatsd-ruby will drop support of Ruby < 2.1.0 in a next minor release" }
125
- else
126
- puts("warning: deprecation: dogstatsd-ruby will drop support of Ruby < 2.1.0 in a next minor release")
127
- end
128
- $deprecation_message_done = true
129
- $deprecation_message_mutex.unlock
130
- end
131
-
132
116
  @forwarder = Forwarder.new(
133
117
  connection_cfg: ConnectionCfg.new(
134
118
  host: host,
@@ -154,12 +138,13 @@ module Datadog
154
138
 
155
139
  # yield a new instance to a block and close it when done
156
140
  # for short-term use-cases that don't want to close the socket manually
157
- def self.open(*args)
158
- instance = new(*args)
141
+ # TODO: replace with ... once we are on ruby 2.7
142
+ def self.open(*args, **kwargs)
143
+ instance = new(*args, **kwargs)
159
144
 
160
145
  yield instance
161
146
  ensure
162
- instance.close
147
+ instance.close if instance
163
148
  end
164
149
 
165
150
  # Sends an increment (count = 1) for the given stat to the statsd server.
@@ -167,6 +152,7 @@ module Datadog
167
152
  # @param [String] stat stat name
168
153
  # @param [Hash] opts the options to create the metric with
169
154
  # @option opts [Numeric] :sample_rate sample rate, 1 for always
155
+ # @option opts [Boolean] :pre_sampled If true, the client assumes the caller has already sampled metrics at :sample_rate, and doesn't perform sampling.
170
156
  # @option opts [Array<String>] :tags An array of tags
171
157
  # @option opts [Numeric] :by increment value, default 1
172
158
  # @see #count
@@ -181,6 +167,7 @@ module Datadog
181
167
  # @param [String] stat stat name
182
168
  # @param [Hash] opts the options to create the metric with
183
169
  # @option opts [Numeric] :sample_rate sample rate, 1 for always
170
+ # @option opts [Boolean] :pre_sampled If true, the client assumes the caller has already sampled metrics at :sample_rate, and doesn't perform sampling.
184
171
  # @option opts [Array<String>] :tags An array of tags
185
172
  # @option opts [Numeric] :by decrement value, default 1
186
173
  # @see #count
@@ -196,13 +183,14 @@ module Datadog
196
183
  # @param [Integer] count count
197
184
  # @param [Hash] opts the options to create the metric with
198
185
  # @option opts [Numeric] :sample_rate sample rate, 1 for always
186
+ # @option opts [Boolean] :pre_sampled If true, the client assumes the caller has already sampled metrics at :sample_rate, and doesn't perform sampling.
199
187
  # @option opts [Array<String>] :tags An array of tags
200
188
  def count(stat, count, opts = EMPTY_OPTIONS)
201
189
  opts = { sample_rate: opts } if opts.is_a?(Numeric)
202
190
  send_stats(stat, count, COUNTER_TYPE, opts)
203
191
  end
204
192
 
205
- # Sends an arbitary gauge value for the given stat to the statsd server.
193
+ # Sends an arbitrary gauge value for the given stat to the statsd server.
206
194
  #
207
195
  # This is useful for recording things like available disk space,
208
196
  # memory usage, and the like, which have different semantics than
@@ -212,6 +200,7 @@ module Datadog
212
200
  # @param [Numeric] value gauge value.
213
201
  # @param [Hash] opts the options to create the metric with
214
202
  # @option opts [Numeric] :sample_rate sample rate, 1 for always
203
+ # @option opts [Boolean] :pre_sampled If true, the client assumes the caller has already sampled metrics at :sample_rate, and doesn't perform sampling.
215
204
  # @option opts [Array<String>] :tags An array of tags
216
205
  # @example Report the current user count:
217
206
  # $statsd.gauge('user.count', User.count)
@@ -226,6 +215,7 @@ module Datadog
226
215
  # @param [Numeric] value histogram value.
227
216
  # @param [Hash] opts the options to create the metric with
228
217
  # @option opts [Numeric] :sample_rate sample rate, 1 for always
218
+ # @option opts [Boolean] :pre_sampled If true, the client assumes the caller has already sampled metrics at :sample_rate, and doesn't perform sampling.
229
219
  # @option opts [Array<String>] :tags An array of tags
230
220
  # @example Report the current user count:
231
221
  # $statsd.histogram('user.count', User.count)
@@ -239,6 +229,7 @@ module Datadog
239
229
  # @param [Numeric] value distribution value.
240
230
  # @param [Hash] opts the options to create the metric with
241
231
  # @option opts [Numeric] :sample_rate sample rate, 1 for always
232
+ # @option opts [Boolean] :pre_sampled If true, the client assumes the caller has already sampled metrics at :sample_rate, and doesn't perform sampling.
242
233
  # @option opts [Array<String>] :tags An array of tags
243
234
  # @example Report the current user count:
244
235
  # $statsd.distribution('user.count', User.count)
@@ -255,6 +246,7 @@ module Datadog
255
246
  # @param [Integer] ms timing in milliseconds
256
247
  # @param [Hash] opts the options to create the metric with
257
248
  # @option opts [Numeric] :sample_rate sample rate, 1 for always
249
+ # @option opts [Boolean] :pre_sampled If true, the client assumes the caller has already sampled metrics at :sample_rate, and doesn't perform sampling.
258
250
  # @option opts [Array<String>] :tags An array of tags
259
251
  def timing(stat, ms, opts = EMPTY_OPTIONS)
260
252
  opts = { sample_rate: opts } if opts.is_a?(Numeric)
@@ -269,6 +261,7 @@ module Datadog
269
261
  # @param [String] stat stat name
270
262
  # @param [Hash] opts the options to create the metric with
271
263
  # @option opts [Numeric] :sample_rate sample rate, 1 for always
264
+ # @option opts [Boolean] :pre_sampled If true, the client assumes the caller has already sampled metrics at :sample_rate, and doesn't perform sampling.
272
265
  # @option opts [Array<String>] :tags An array of tags
273
266
  # @yield The operation to be timed
274
267
  # @see #timing
@@ -288,6 +281,7 @@ module Datadog
288
281
  # @param [Numeric] value set value.
289
282
  # @param [Hash] opts the options to create the metric with
290
283
  # @option opts [Numeric] :sample_rate sample rate, 1 for always
284
+ # @option opts [Boolean] :pre_sampled If true, the client assumes the caller has already sampled metrics at :sample_rate, and doesn't perform sampling.
291
285
  # @option opts [Array<String>] :tags An array of tags
292
286
  # @example Record a unique visitory by id:
293
287
  # $statsd.set('visitors.uniques', User.id)
@@ -399,17 +393,10 @@ module Datadog
399
393
  attr_reader :serializer
400
394
  attr_reader :forwarder
401
395
 
402
- PROCESS_TIME_SUPPORTED = (RUBY_VERSION >= '2.1.0')
403
396
  EMPTY_OPTIONS = {}.freeze
404
397
 
405
- if PROCESS_TIME_SUPPORTED
406
- def now
407
- Process.clock_gettime(Process::CLOCK_MONOTONIC)
408
- end
409
- else
410
- def now
411
- Time.now.to_f
412
- end
398
+ def now
399
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
413
400
  end
414
401
 
415
402
  def send_stats(stat, delta, type, opts = EMPTY_OPTIONS)
@@ -417,7 +404,7 @@ module Datadog
417
404
 
418
405
  sample_rate = opts[:sample_rate] || @sample_rate || 1
419
406
 
420
- if sample_rate == 1 || rand <= sample_rate
407
+ if sample_rate == 1 || opts[:pre_sampled] || rand <= sample_rate
421
408
  full_stat = serializer.to_stat(stat, delta, type, tags: opts[:tags], sample_rate: sample_rate)
422
409
 
423
410
  forwarder.send_message(full_stat)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogstatsd-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.3
4
+ version: 5.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rein Henrichs
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-02-02 00:00:00.000000000 Z
12
+ date: 2022-03-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A Ruby DogStatsd client
15
15
  email: code@datadoghq.com
@@ -44,9 +44,9 @@ licenses:
44
44
  - MIT
45
45
  metadata:
46
46
  bug_tracker_uri: https://github.com/DataDog/dogstatsd-ruby/issues
47
- changelog_uri: https://github.com/DataDog/dogstatsd-ruby/blob/v5.3.3/CHANGELOG.md
48
- documentation_uri: https://www.rubydoc.info/gems/dogstatsd-ruby/5.3.3
49
- source_code_uri: https://github.com/DataDog/dogstatsd-ruby/tree/v5.3.3
47
+ changelog_uri: https://github.com/DataDog/dogstatsd-ruby/blob/v5.4.0/CHANGELOG.md
48
+ documentation_uri: https://www.rubydoc.info/gems/dogstatsd-ruby/5.4.0
49
+ source_code_uri: https://github.com/DataDog/dogstatsd-ruby/tree/v5.4.0
50
50
  post_install_message: |2+
51
51
 
52
52
  If you are upgrading from v4.x of the dogstatsd-ruby library, note the major change to the threading model:
@@ -59,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 2.0.0
62
+ version: 2.1.0
63
63
  required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ">="