statsd-instrument 3.6.1 → 3.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/statsd/instrument/batched_udp_sink.rb +8 -4
- data/lib/statsd/instrument/capture_sink.rb +4 -0
- data/lib/statsd/instrument/dogstatsd_datagram_builder.rb +2 -2
- data/lib/statsd/instrument/log_sink.rb +4 -0
- data/lib/statsd/instrument/null_sink.rb +4 -0
- data/lib/statsd/instrument/udp_sink.rb +4 -0
- data/lib/statsd/instrument/version.rb +1 -1
- data/test/environment_test.rb +3 -0
- data/test/udp_sink_test.rb +74 -62
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2e01a49d8bb83318bef84628164ab1dec1047a72c1f717969a609f783d3b8be
|
4
|
+
data.tar.gz: bf308ae3bb23958705efcc39c03fa95f99b58bb33df47b7588fe4a7b22d742e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57f0022a72e600871df9f054ad4a003ed2c361287949bfa4af94789460ffa1a9257ffba1f552ac77b786d5c9dc295efb7ccd82edf632f7151d1dda365b282a61
|
7
|
+
data.tar.gz: c458ec4b7177cd746f3fd173641db3127ac97a7683f0f55ff00f84ebe5a81b827d53340566b79ea39adb7327ac967298657d23fcc5f51bd9edced6ea05314beb
|
data/CHANGELOG.md
CHANGED
@@ -55,6 +55,10 @@ module StatsD
|
|
55
55
|
@dispatcher.shutdown(*args)
|
56
56
|
end
|
57
57
|
|
58
|
+
def flush(blocking:)
|
59
|
+
@dispatcher.flush(blocking: blocking)
|
60
|
+
end
|
61
|
+
|
58
62
|
class Buffer < SizedQueue
|
59
63
|
def push_nonblock(item)
|
60
64
|
push(item, true)
|
@@ -104,10 +108,6 @@ module StatsD
|
|
104
108
|
flush(blocking: false)
|
105
109
|
end
|
106
110
|
|
107
|
-
private
|
108
|
-
|
109
|
-
NEWLINE = "\n".b.freeze
|
110
|
-
|
111
111
|
def flush(blocking:)
|
112
112
|
packet = "".b
|
113
113
|
next_datagram = nil
|
@@ -137,6 +137,10 @@ module StatsD
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
+
private
|
141
|
+
|
142
|
+
NEWLINE = "\n".b.freeze
|
143
|
+
|
140
144
|
def thread_healthcheck
|
141
145
|
# TODO: We have a race condition on JRuby / Truffle here. It could cause multiple
|
142
146
|
# dispatcher threads to be spawned, which would cause problems.
|
@@ -16,7 +16,7 @@ module StatsD
|
|
16
16
|
:d
|
17
17
|
end
|
18
18
|
|
19
|
-
#
|
19
|
+
# Constructs an event datagram.
|
20
20
|
#
|
21
21
|
# @param [String] title Event title.
|
22
22
|
# @param [String] text Event description. Newlines are allowed.
|
@@ -57,7 +57,7 @@ module StatsD
|
|
57
57
|
datagram
|
58
58
|
end
|
59
59
|
|
60
|
-
#
|
60
|
+
# Constructs a service check datagram.
|
61
61
|
#
|
62
62
|
# @param [String] name Name of the service
|
63
63
|
# @param [Symbol] status Either `:ok`, `:warning`, `:critical` or `:unknown`
|
data/test/environment_test.rb
CHANGED
@@ -57,6 +57,9 @@ class EnvironmentTest < Minitest::Test
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_client_from_env_uses_regular_udp_sink_when_flush_interval_is_0
|
60
|
+
StatsD::Instrument::Environment.any_instance.expects(:warn).with(
|
61
|
+
"STATSD_FLUSH_INTERVAL=0.0 is deprecated, please set STATSD_BUFFER_CAPACITY=0 instead.",
|
62
|
+
).once
|
60
63
|
env = StatsD::Instrument::Environment.new(
|
61
64
|
"STATSD_USE_NEW_CLIENT" => "1",
|
62
65
|
"STATSD_ENV" => "staging",
|
data/test/udp_sink_test.rb
CHANGED
@@ -122,79 +122,91 @@ module UDPSinkTests
|
|
122
122
|
end
|
123
123
|
datagrams
|
124
124
|
end
|
125
|
+
end
|
125
126
|
|
126
|
-
|
127
|
-
|
127
|
+
class UDPSinkTest < Minitest::Test
|
128
|
+
include UDPSinkTests
|
128
129
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
130
|
+
def setup
|
131
|
+
@receiver = UDPSocket.new
|
132
|
+
@receiver.bind("localhost", 0)
|
133
|
+
@host = @receiver.addr[2]
|
134
|
+
@port = @receiver.addr[1]
|
135
|
+
@sink_class = StatsD::Instrument::UDPSink
|
136
|
+
end
|
136
137
|
|
137
|
-
|
138
|
-
|
139
|
-
|
138
|
+
def teardown
|
139
|
+
@receiver.close
|
140
|
+
end
|
140
141
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
142
|
+
def test_socket_error_should_invalidate_socket
|
143
|
+
previous_logger = StatsD.logger
|
144
|
+
begin
|
145
|
+
logs = StringIO.new
|
146
|
+
StatsD.logger = Logger.new(logs)
|
147
|
+
StatsD.logger.formatter = SimpleFormatter.new
|
148
|
+
UDPSocket.stubs(:new).returns(socket = mock("socket"))
|
149
|
+
|
150
|
+
seq = sequence("connect_fail_connect_succeed")
|
151
|
+
socket.expects(:connect).with("localhost", 8125).in_sequence(seq)
|
152
|
+
socket.expects(:send).raises(Errno::EDESTADDRREQ).in_sequence(seq)
|
153
|
+
socket.expects(:close).in_sequence(seq)
|
154
|
+
socket.expects(:connect).with("localhost", 8125).in_sequence(seq)
|
155
|
+
socket.expects(:send).twice.returns(1).in_sequence(seq)
|
156
|
+
socket.expects(:close).in_sequence(seq)
|
157
|
+
|
158
|
+
udp_sink = build_sink("localhost", 8125)
|
159
|
+
udp_sink << "foo:1|c"
|
160
|
+
udp_sink << "bar:1|c"
|
161
|
+
|
162
|
+
assert_equal(
|
163
|
+
"[#{@sink_class}] Resetting connection because of " \
|
164
|
+
"Errno::EDESTADDRREQ: Destination address required\n",
|
165
|
+
logs.string,
|
166
|
+
)
|
167
|
+
ensure
|
168
|
+
StatsD.logger = previous_logger
|
169
|
+
# Make sure our fake socket is closed so that it doesn't interfere with other tests
|
170
|
+
udp_sink&.send(:invalidate_socket)
|
168
171
|
end
|
169
172
|
end
|
173
|
+
end
|
170
174
|
|
171
|
-
|
172
|
-
|
175
|
+
class BatchedUDPSinkTest < Minitest::Test
|
176
|
+
include UDPSinkTests
|
173
177
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
def teardown
|
184
|
-
@receiver.close
|
185
|
-
@sinks.each(&:shutdown)
|
186
|
-
end
|
178
|
+
def setup
|
179
|
+
@receiver = UDPSocket.new
|
180
|
+
@receiver.bind("localhost", 0)
|
181
|
+
@host = @receiver.addr[2]
|
182
|
+
@port = @receiver.addr[1]
|
183
|
+
@sink_class = StatsD::Instrument::BatchedUDPSink
|
184
|
+
@sinks = []
|
185
|
+
end
|
187
186
|
|
188
|
-
|
187
|
+
def teardown
|
188
|
+
@receiver.close
|
189
|
+
@sinks.each(&:shutdown)
|
190
|
+
end
|
189
191
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
192
|
+
def test_flush
|
193
|
+
buffer_size = 50
|
194
|
+
|
195
|
+
sink = build_sink(@host, @port, buffer_capacity: buffer_size)
|
196
|
+
dispatcher = sink.instance_variable_get(:@dispatcher)
|
197
|
+
buffer = dispatcher.instance_variable_get(:@buffer)
|
198
|
+
# Send a few datagrams to fill the buffer
|
199
|
+
(buffer_size * 2).times { |i| sink << "foo:#{i}|c" }
|
200
|
+
assert(!buffer.empty?)
|
201
|
+
sink.flush(blocking: false)
|
202
|
+
assert(buffer.empty?)
|
195
203
|
end
|
196
204
|
|
197
|
-
|
198
|
-
|
205
|
+
private
|
206
|
+
|
207
|
+
def build_sink(host = @host, port = @port, buffer_capacity: 50)
|
208
|
+
sink = @sink_class.new(host, port, buffer_capacity: buffer_capacity)
|
209
|
+
@sinks << sink
|
210
|
+
sink
|
199
211
|
end
|
200
212
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statsd-instrument
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Storimer
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2024-03-05 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: A StatsD client for Ruby apps. Provides metaprogramming methods to inject
|
16
16
|
StatsD instrumentation into your code.
|
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
|
-
rubygems_version: 3.
|
125
|
+
rubygems_version: 3.5.6
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: A StatsD client for Ruby apps
|