dogstatsd-ruby 5.3.0 → 5.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 828679b3ff6ef3a2acce023e8b3cc5d362fe8c41ac17acee8bd2d5662ae3b2f3
4
- data.tar.gz: 0c836007b9b82eb7e0cf056f86d9426e8f43b1e1543876c53819b8e0f46c8235
3
+ metadata.gz: 539ec3d4e02bd8784df4d032b0f8e96ebb2a582b510ff5e27c6e7cfff4515926
4
+ data.tar.gz: d8ecf4c6724e491aaea6d738cc255891b55119987b1ca5665087d506552135ee
5
5
  SHA512:
6
- metadata.gz: dc31df8c212fa4ab0854075528a03729d8600fabbc2e387ec4bf4c3c712a5106600c68065d5204d082f3d9fbaeafa74c8dc6cee15c8dea03fe7de192bcfb654e
7
- data.tar.gz: 552b383c99f0071662d83991dc5e3472b0cc73125ef9fa3c558de1a59b8bf48fed3dc0d7b96e62808cf0bb044e65c4e332e569e7c9add6dcaf72a0300bfb4ca3
6
+ metadata.gz: d615efd205f7858c55b9864e1d001d607dcb39a47a26c87f5e27402b25834cf750fb3904d10d667c63a437587d38ba315d7a3c609b7709bc28a8bc8138d30eef
7
+ data.tar.gz: 254bf33695141f521d55d5f5b9c4d6b3abf2408b6b231263949094cbc2c9f531bf3ff2aea92ae0f11d505bbb8d25a789a2c0da76d9a065b713f9dc9b5b9d836d
data/README.md CHANGED
@@ -46,14 +46,14 @@ change concerning you is the new [threading model](#threading-model):
46
46
 
47
47
  In practice, it means two things:
48
48
 
49
- 1. Now that the client is buffering metrics before sending them, you have to call `Datadog::Statsd#flush(sync: true)` if you want synchronous behavior. In most cases, this is not needed, as the companion thread will automatically flush the buffered metrics if the buffer gets full or when you are closing the instance.
49
+ 1. Now that the client is buffering metrics before sending them, you have to call `Datadog::Statsd#flush(sync: true)` if you want synchronous behavior. In most cases, this is not needed, as the sender thread will automatically flush the buffered metrics if the buffer gets full or when you are closing the instance.
50
50
 
51
51
  2. You have to make sure you are either:
52
52
 
53
53
  * Using a singleton instance of the DogStatsD client instead of creating a new instance whenever you need one; this will let the buffering mechanism flush metrics regularly
54
54
  * Or properly disposing of the DogStatsD client instance when it is not needed anymore using the method `Datadog::Statsd#close`
55
55
 
56
- If you have issues with the companion thread or the buffering mode, you can instantiate a client that behaves exactly as in v4.x (i.e. no companion thread and flush on every metric submission):
56
+ If you have issues with the sender thread or the buffering mode, you can instantiate a client that behaves exactly as in v4.x (i.e. no sender thread and flush on every metric submission):
57
57
 
58
58
  ```ruby
59
59
  # Create a DogStatsD client instance using UDP
@@ -73,9 +73,9 @@ statsd.close()
73
73
 
74
74
  ### v5.x Common Pitfalls
75
75
 
76
- Version v5.x of `dogstatsd-ruby` is using a companion thread for flushing. This provides better performance, but you need to consider the following pitfalls:
76
+ Version v5.x of `dogstatsd-ruby` is using a sender thread for flushing. This provides better performance, but you need to consider the following pitfalls:
77
77
 
78
- 1. Applications that use `fork` after having created the dogstatsd instance: the child process will automatically spawn a new companion thread to flush metrics.
78
+ 1. Applications that use `fork` after having created the dogstatsd instance: the child process will automatically spawn a new sender thread to flush metrics.
79
79
 
80
80
  2. Applications that create multiple instances of the client without closing them: it is important to `#close` all instances to free the thread and the socket they are using otherwise you will leak those resources.
81
81
 
@@ -83,7 +83,7 @@ If you are using [Sidekiq](https://github.com/mperham/sidekiq), please make sure
83
83
 
84
84
  If you are using [Puma](https://github.com/puma/puma) or [Unicorn](https://yhbt.net/unicorn.git), please make sure to create the instance of DogStatsD in the workers, not in the main process before it forks to create its workers. See [this comment for more details](https://github.com/DataDog/dogstatsd-ruby/issues/179#issuecomment-845570345).
85
85
 
86
- Applications that run into issues but can't apply these recommendations should use the `single_thread` mode which disables the use of the companion thread.
86
+ Applications that run into issues but can't apply these recommendations should use the `single_thread` mode which disables the use of the sender thread.
87
87
  Here is how to instantiate a client in this mode:
88
88
 
89
89
  ```ruby
@@ -152,7 +152,7 @@ statsd.close()
152
152
 
153
153
  Starting with version 5.0, `dogstatsd-ruby` employs a new threading model where one instance of `Datadog::Statsd` can be shared between threads and where data sending is non-blocking (asynchronous).
154
154
 
155
- When you instantiate a `Datadog::Statsd`, a companion thread is spawned. This thread will be called the Sender thread, as it is modeled by the [Sender](../lib/datadog/statsd/sender.rb) class. You can make use of `single_thread: true` to disable this behavior.
155
+ When you instantiate a `Datadog::Statsd`, a sender thread is spawned. This thread will be called the Sender thread, as it is modeled by the [Sender](../lib/datadog/statsd/sender.rb) class. You can make use of `single_thread: true` to disable this behavior.
156
156
 
157
157
  This thread is stopped when you close the statsd client (`Datadog::Statsd#close`). Instantiating a lot of statsd clients without calling `#close` after they are not needed anymore will most likely lead to threads being leaked.
158
158
 
@@ -196,6 +196,12 @@ Doing so means the caller thread is blocked and waiting until the data has been
196
196
 
197
197
  This is useful when preparing to exit the application or when checking unit tests.
198
198
 
199
+ ### Thread-safety
200
+
201
+ By default, instances of `Datadog::Statsd` are thread-safe and we recommend that a single instance be reused by all application threads (even in applications that employ forking). The sole exception is the `#close` method — this method is not yet thread safe (work in progress here [#209](https://github.com/DataDog/dogstatsd-ruby/pull/209)).
202
+
203
+ When using the `single_thread: true` mode, instances of `Datadog::Statsd` are still thread-safe, but you may run into contention on heavily-threaded applications, so we don’t recommend (for performance reasons) reusing these instances.
204
+
199
205
  ## Versioning
200
206
 
201
207
  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.
@@ -12,6 +12,7 @@ module Datadog
12
12
  telemetry.reset
13
13
  end
14
14
 
15
+ # not thread safe: `Sender` instances that use this are required to properly synchronize or sequence calls to this method
15
16
  def write(payload)
16
17
  logger.debug { "Statsd: #{payload}" } if logger
17
18
 
@@ -20,7 +20,6 @@ module Datadog
20
20
  @host = host || ENV.fetch('DD_AGENT_HOST', DEFAULT_HOST)
21
21
  @port = port || ENV.fetch('DD_DOGSTATSD_PORT', DEFAULT_PORT).to_i
22
22
  @socket = nil
23
- connect
24
23
  end
25
24
 
26
25
  def close
@@ -37,7 +36,12 @@ module Datadog
37
36
  @socket.connect(host, port)
38
37
  end
39
38
 
39
+ # send_message is writing the message in the socket, it may create the socket if nil
40
+ # It is not thread-safe but since it is called by either the Sender bg thread or the
41
+ # SingleThreadSender (which is using a mutex while Flushing), only one thread must call
42
+ # it at a time.
40
43
  def send_message(message)
44
+ connect unless @socket
41
45
  @socket.send(message, 0)
42
46
  end
43
47
  end
@@ -15,7 +15,6 @@ module Datadog
15
15
 
16
16
  @socket_path = socket_path
17
17
  @socket = nil
18
- connect
19
18
  end
20
19
 
21
20
  def close
@@ -32,7 +31,12 @@ module Datadog
32
31
  @socket.connect(Socket.pack_sockaddr_un(@socket_path))
33
32
  end
34
33
 
34
+ # send_message is writing the message in the socket, it may create the socket if nil
35
+ # It is not thread-safe but since it is called by either the Sender bg thread or the
36
+ # SingleThreadSender (which is using a mutex while Flushing), only one thread must call
37
+ # it at a time.
35
38
  def send_message(message)
39
+ connect unless @socket
36
40
  @socket.sendmsg_nonblock(message)
37
41
  rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ENOENT => e
38
42
  # TODO: FIXME: This error should be considered as a retryable error in the
@@ -4,6 +4,6 @@ require_relative 'connection'
4
4
 
5
5
  module Datadog
6
6
  class Statsd
7
- VERSION = '5.3.0'
7
+ VERSION = '5.3.1'
8
8
  end
9
9
  end
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.0
4
+ version: 5.3.1
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: 2021-10-06 00:00:00.000000000 Z
12
+ date: 2021-10-21 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A Ruby DogStatsd client
15
15
  email: code@datadoghq.com
@@ -43,9 +43,9 @@ licenses:
43
43
  - MIT
44
44
  metadata:
45
45
  bug_tracker_uri: https://github.com/DataDog/dogstatsd-ruby/issues
46
- changelog_uri: https://github.com/DataDog/dogstatsd-ruby/blob/v5.3.0/CHANGELOG.md
47
- documentation_uri: https://www.rubydoc.info/gems/dogstatsd-ruby/5.3.0
48
- source_code_uri: https://github.com/DataDog/dogstatsd-ruby/tree/v5.3.0
46
+ changelog_uri: https://github.com/DataDog/dogstatsd-ruby/blob/v5.3.1/CHANGELOG.md
47
+ documentation_uri: https://www.rubydoc.info/gems/dogstatsd-ruby/5.3.1
48
+ source_code_uri: https://github.com/DataDog/dogstatsd-ruby/tree/v5.3.1
49
49
  post_install_message:
50
50
  rdoc_options: []
51
51
  require_paths: