dogstatsd-ruby 5.1.0 → 5.2.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 +4 -4
- data/README.md +42 -3
- data/lib/datadog/statsd.rb +6 -0
- data/lib/datadog/statsd/forwarder.rb +3 -1
- data/lib/datadog/statsd/single_thread_sender.rb +31 -0
- data/lib/datadog/statsd/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9abfaabd9be58a320dd8cc8d1d4998ac287daa08e68ab894054cf2910f5f3133
|
4
|
+
data.tar.gz: 88ebf4ef472f7663897c06fa3e5753a17c12722bc1a58f8aa4e9fb0a3ace07c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 199527bd5e9d39d94be3cabf28dc5f4d8913c4d3f746a6018a22c9ed13440c34d77fc11b363f47f9e2fd325974005fdc3567a223de4669b388ced99c3cd0750f
|
7
|
+
data.tar.gz: 0da25bafef540e4d36be8cae9c1fbb1f11c6aea94415828941aa9c34877db75166574f41b5e1a0829c71285f958162133d0f592a34619ce066e14c97ea86fd4d
|
data/README.md
CHANGED
@@ -51,9 +51,37 @@ call the method `Datadog::Statsd#flush` if you want to force the sending of metr
|
|
51
51
|
|
52
52
|
2. You have to make sure you are either:
|
53
53
|
|
54
|
-
* using singletons instances of the DogStatsD client and not allocating one each time you need one, letting the buffering mechanism flush metrics,
|
54
|
+
* using singletons instances of the DogStatsD client and not allocating one each time you need one, letting the buffering mechanism flush metrics, it's still a bad solution if the process later forks (see related section below). Or,
|
55
55
|
* properly closing your DogStatsD client instance when it is not needed anymore using the method `Datadog::Statsd#close` to release the resources used by the instance and to close the socket
|
56
56
|
|
57
|
+
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):
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
# Import the library
|
61
|
+
require 'datadog/statsd'
|
62
|
+
|
63
|
+
# Create a DogStatsD client instance using UDP
|
64
|
+
statsd = Datadog::Statsd.new('localhost', 8125, single_thread: true, buffer_max_payload_size: 1)
|
65
|
+
...
|
66
|
+
# to close the instance is not necessary in this case since metrics are flushed on submission
|
67
|
+
# but it is still a good practice and it explicitely closes the socket
|
68
|
+
statsd.close()
|
69
|
+
```
|
70
|
+
|
71
|
+
or
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
# Import the library
|
75
|
+
require 'datadog/statsd'
|
76
|
+
|
77
|
+
# Create a DogStatsD client instance using UDS
|
78
|
+
statsd = Datadog::Statsd.new(socket_path: '/path/to/socket/file', single_thread: true, buffer_max_payload_size: 1)
|
79
|
+
...
|
80
|
+
# to close the instance is not necessary in this case since metrics are flushed on submission
|
81
|
+
# but it is still a good practice and it explicitely closes the socket
|
82
|
+
statsd.close()
|
83
|
+
```
|
84
|
+
|
57
85
|
### v5.x Common Pitfalls
|
58
86
|
|
59
87
|
Version v5.x of `dogstatsd-ruby` is using a companion thread for preemptive flushing, it brings better performances for application having a high-throughput of statsd metrics, but it comes with new pitfalls:
|
@@ -65,7 +93,18 @@ If you are using [Sidekiq](https://github.com/mperham/sidekiq), please make sure
|
|
65
93
|
|
66
94
|
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).
|
67
95
|
|
68
|
-
Applications that are in these situations
|
96
|
+
Applications that are in these situations but can't apply these recommendations should enable the `single_thread` mode which does not use a companion thread. Here is how to instantiate a client in this mode:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
# Import the library
|
100
|
+
require 'datadog/statsd'
|
101
|
+
|
102
|
+
# Create a DogStatsD client instance.
|
103
|
+
statsd = Datadog::Statsd.new('localhost', 8125, single_thread: true)
|
104
|
+
...
|
105
|
+
# release resources used by the client instance and flush last metrics
|
106
|
+
statsd.close()
|
107
|
+
```
|
69
108
|
|
70
109
|
### Origin detection over UDP
|
71
110
|
|
@@ -122,7 +161,7 @@ statsd = Datadog::Statsd.new('localhost', 8125, buffer_max_payload_size: 4096)
|
|
122
161
|
|
123
162
|
On versions greater than 5.0, we changed the threading model of the library so that one instance of `Datadog::Statsd` could be shared between threads and so that the writes in the socket are non blocking.
|
124
163
|
|
125
|
-
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.
|
164
|
+
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. Please use `single_thread: true` while creating an instance if you don't want to or can't use a companion thread.
|
126
165
|
|
127
166
|
This thread is stopped when you close the statsd client (`Datadog::Statsd#close`). It also means that allocating a lot of statsd clients without closing them properly when not used anymore
|
128
167
|
could lead to a thread leak (even though they will be sleeping, blocked on IO).
|
data/lib/datadog/statsd.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative 'statsd/uds_connection'
|
|
8
8
|
require_relative 'statsd/message_buffer'
|
9
9
|
require_relative 'statsd/serialization'
|
10
10
|
require_relative 'statsd/sender'
|
11
|
+
require_relative 'statsd/single_thread_sender'
|
11
12
|
require_relative 'statsd/forwarder'
|
12
13
|
|
13
14
|
# = Datadog::Statsd: A DogStatsd client (https://www.datadoghq.com)
|
@@ -70,6 +71,7 @@ module Datadog
|
|
70
71
|
# @option [Integer] buffer_max_pool_size max messages to buffer
|
71
72
|
# @option [String] socket_path unix socket path
|
72
73
|
# @option [Float] default sample rate if not overridden
|
74
|
+
# @option [Boolean] single_thread flushes the metrics on the main thread instead of in a companion thread
|
73
75
|
def initialize(
|
74
76
|
host = nil,
|
75
77
|
port = nil,
|
@@ -85,6 +87,8 @@ module Datadog
|
|
85
87
|
|
86
88
|
logger: nil,
|
87
89
|
|
90
|
+
single_thread: false,
|
91
|
+
|
88
92
|
telemetry_enable: true,
|
89
93
|
telemetry_flush_interval: DEFAULT_TELEMETRY_FLUSH_INTERVAL
|
90
94
|
)
|
@@ -105,6 +109,8 @@ module Datadog
|
|
105
109
|
global_tags: tags,
|
106
110
|
logger: logger,
|
107
111
|
|
112
|
+
single_thread: single_thread,
|
113
|
+
|
108
114
|
buffer_max_payload_size: buffer_max_payload_size,
|
109
115
|
buffer_max_pool_size: buffer_max_pool_size,
|
110
116
|
buffer_overflowing_stategy: buffer_overflowing_stategy,
|
@@ -18,6 +18,8 @@ module Datadog
|
|
18
18
|
telemetry_flush_interval: nil,
|
19
19
|
global_tags: [],
|
20
20
|
|
21
|
+
single_thread: false,
|
22
|
+
|
21
23
|
logger: nil
|
22
24
|
)
|
23
25
|
@transport_type = socket_path.nil? ? :udp : :uds
|
@@ -53,7 +55,7 @@ module Datadog
|
|
53
55
|
overflowing_stategy: buffer_overflowing_stategy,
|
54
56
|
)
|
55
57
|
|
56
|
-
@sender = Sender.new(buffer)
|
58
|
+
@sender = single_thread ? SingleThreadSender.new(buffer) : Sender.new(buffer)
|
57
59
|
@sender.start
|
58
60
|
end
|
59
61
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
class Statsd
|
5
|
+
class SingleThreadSender
|
6
|
+
def initialize(message_buffer)
|
7
|
+
@message_buffer = message_buffer
|
8
|
+
end
|
9
|
+
|
10
|
+
def add(message)
|
11
|
+
@message_buffer.add(message)
|
12
|
+
end
|
13
|
+
|
14
|
+
def flush(*)
|
15
|
+
@message_buffer.flush()
|
16
|
+
end
|
17
|
+
|
18
|
+
# Compatibility with `Sender`
|
19
|
+
def start()
|
20
|
+
end
|
21
|
+
|
22
|
+
# Compatibility with `Sender`
|
23
|
+
def stop()
|
24
|
+
end
|
25
|
+
|
26
|
+
# Compatibility with `Sender`
|
27
|
+
def rendez_vous()
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
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.
|
4
|
+
version: 5.2.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: 2021-
|
12
|
+
date: 2021-07-01 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Ruby DogStatsd client
|
15
15
|
email: code@datadoghq.com
|
@@ -32,6 +32,7 @@ files:
|
|
32
32
|
- lib/datadog/statsd/serialization/service_check_serializer.rb
|
33
33
|
- lib/datadog/statsd/serialization/stat_serializer.rb
|
34
34
|
- lib/datadog/statsd/serialization/tag_serializer.rb
|
35
|
+
- lib/datadog/statsd/single_thread_sender.rb
|
35
36
|
- lib/datadog/statsd/telemetry.rb
|
36
37
|
- lib/datadog/statsd/udp_connection.rb
|
37
38
|
- lib/datadog/statsd/uds_connection.rb
|
@@ -41,9 +42,9 @@ licenses:
|
|
41
42
|
- MIT
|
42
43
|
metadata:
|
43
44
|
bug_tracker_uri: https://github.com/DataDog/dogstatsd-ruby/issues
|
44
|
-
changelog_uri: https://github.com/DataDog/dogstatsd-ruby/blob/v5.
|
45
|
-
documentation_uri: https://www.rubydoc.info/gems/dogstatsd-ruby/5.
|
46
|
-
source_code_uri: https://github.com/DataDog/dogstatsd-ruby/tree/v5.
|
45
|
+
changelog_uri: https://github.com/DataDog/dogstatsd-ruby/blob/v5.2.0/CHANGELOG.md
|
46
|
+
documentation_uri: https://www.rubydoc.info/gems/dogstatsd-ruby/5.2.0
|
47
|
+
source_code_uri: https://github.com/DataDog/dogstatsd-ruby/tree/v5.2.0
|
47
48
|
post_install_message:
|
48
49
|
rdoc_options: []
|
49
50
|
require_paths:
|