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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5e3cda783c5f0c7de2c30175ab001cef492c3ad0e0923af3d3a4840df7d6005
4
- data.tar.gz: b31685696c6e1ad8e5cd36a8115eca2363ed9a732a483534004b2163453b323a
3
+ metadata.gz: c2e01a49d8bb83318bef84628164ab1dec1047a72c1f717969a609f783d3b8be
4
+ data.tar.gz: bf308ae3bb23958705efcc39c03fa95f99b58bb33df47b7588fe4a7b22d742e9
5
5
  SHA512:
6
- metadata.gz: 658663a99a273170ad72436eae0142d707e35a8cc2bbf5befd89a7cd225db5673c5ec676e8f96a168411f443fa7d3e6b73f60c6f081067082b2003920cef264b
7
- data.tar.gz: bc8930e083ec158ca6a945186c2156a0890ebe74edb63080dc6ced9ca691498edc9d81ae746ec80477471c3b2f09d3abb95042002c0c8e7d72afeb9ab360526c
6
+ metadata.gz: 57f0022a72e600871df9f054ad4a003ed2c361287949bfa4af94789460ffa1a9257ffba1f552ac77b786d5c9dc295efb7ccd82edf632f7151d1dda365b282a61
7
+ data.tar.gz: c458ec4b7177cd746f3fd173641db3127ac97a7683f0f55ff00f84ebe5a81b827d53340566b79ea39adb7327ac967298657d23fcc5f51bd9edced6ea05314beb
data/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ section below.
6
6
 
7
7
  ## Unreleased changes
8
8
 
9
+ ## Version 3.7.0
10
+
11
+ - Add public `.flush` method to sink classes.
12
+
9
13
  ## Version 3.6.1
10
14
 
11
15
  - Fix `ArgumentError` when passing an empty Hash as tags.
@@ -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.
@@ -26,6 +26,10 @@ module StatsD
26
26
  def clear
27
27
  @datagrams.clear
28
28
  end
29
+
30
+ def flush(blocking:)
31
+ @parent.flush(blocking: blocking)
32
+ end
29
33
  end
30
34
  end
31
35
  end
@@ -16,7 +16,7 @@ module StatsD
16
16
  :d
17
17
  end
18
18
 
19
- # Constricts an event datagram.
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
- # Constricts a service check datagram.
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`
@@ -23,6 +23,10 @@ module StatsD
23
23
  logger.add(severity, "[StatsD] #{datagram.chomp}")
24
24
  self
25
25
  end
26
+
27
+ def flush(blocking:)
28
+ # noop
29
+ end
26
30
  end
27
31
  end
28
32
  end
@@ -12,6 +12,10 @@ module StatsD
12
12
  def <<(_datagram)
13
13
  self # noop
14
14
  end
15
+
16
+ def flush(blocking:)
17
+ # noop
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -53,6 +53,10 @@ module StatsD
53
53
  self
54
54
  end
55
55
 
56
+ def flush(blocking:)
57
+ # noop
58
+ end
59
+
56
60
  private
57
61
 
58
62
  def invalidate_socket
@@ -2,6 +2,6 @@
2
2
 
3
3
  module StatsD
4
4
  module Instrument
5
- VERSION = "3.6.1"
5
+ VERSION = "3.7.0"
6
6
  end
7
7
  end
@@ -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",
@@ -122,79 +122,91 @@ module UDPSinkTests
122
122
  end
123
123
  datagrams
124
124
  end
125
+ end
125
126
 
126
- class UDPSinkTest < Minitest::Test
127
- include UDPSinkTests
127
+ class UDPSinkTest < Minitest::Test
128
+ include UDPSinkTests
128
129
 
129
- def setup
130
- @receiver = UDPSocket.new
131
- @receiver.bind("localhost", 0)
132
- @host = @receiver.addr[2]
133
- @port = @receiver.addr[1]
134
- @sink_class = StatsD::Instrument::UDPSink
135
- end
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
- def teardown
138
- @receiver.close
139
- end
138
+ def teardown
139
+ @receiver.close
140
+ end
140
141
 
141
- def test_socket_error_should_invalidate_socket
142
- previous_logger = StatsD.logger
143
- begin
144
- logs = StringIO.new
145
- StatsD.logger = Logger.new(logs)
146
- StatsD.logger.formatter = SimpleFormatter.new
147
- UDPSocket.stubs(:new).returns(socket = mock("socket"))
148
-
149
- seq = sequence("connect_fail_connect_succeed")
150
- socket.expects(:connect).with("localhost", 8125).in_sequence(seq)
151
- socket.expects(:send).raises(Errno::EDESTADDRREQ).in_sequence(seq)
152
- socket.expects(:close).in_sequence(seq)
153
- socket.expects(:connect).with("localhost", 8125).in_sequence(seq)
154
- socket.expects(:send).twice.returns(1).in_sequence(seq)
155
-
156
- udp_sink = build_sink("localhost", 8125)
157
- udp_sink << "foo:1|c"
158
- udp_sink << "bar:1|c"
159
-
160
- assert_equal(
161
- "[#{@sink_class}] Resetting connection because of " \
162
- "Errno::EDESTADDRREQ: Destination address required\n",
163
- logs.string,
164
- )
165
- ensure
166
- StatsD.logger = previous_logger
167
- end
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
- module BatchedUDPSinkTests
172
- include UDPSinkTests
175
+ class BatchedUDPSinkTest < Minitest::Test
176
+ include UDPSinkTests
173
177
 
174
- def setup
175
- @receiver = UDPSocket.new
176
- @receiver.bind("localhost", 0)
177
- @host = @receiver.addr[2]
178
- @port = @receiver.addr[1]
179
- @sink_class = StatsD::Instrument::BatchedUDPSink
180
- @sinks = []
181
- end
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
- private
187
+ def teardown
188
+ @receiver.close
189
+ @sinks.each(&:shutdown)
190
+ end
189
191
 
190
- def build_sink(host = @host, port = @port)
191
- sink = @sink_class.new(host, port, buffer_capacity: 50)
192
- @sinks << sink
193
- sink
194
- end
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
- class BatchedUDPSinkTest < Minitest::Test
198
- include BatchedUDPSinkTests
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.6.1
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: 2023-11-06 00:00:00.000000000 Z
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.4.21
125
+ rubygems_version: 3.5.6
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: A StatsD client for Ruby apps