statsd-ruby 1.3.0 → 1.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
  SHA1:
3
- metadata.gz: e4f5fc1d6357476dfd6402b233f22f43907c9fd7
4
- data.tar.gz: 6210b9a5fc2b4221d0cf4cb3a1b11a4e9b6fdb14
3
+ metadata.gz: 91ca6f8d710ca7a0a0fadccd48293a804e652c0d
4
+ data.tar.gz: 24f9b37eb4a6fa239d1e80073ef3879f09f85909
5
5
  SHA512:
6
- metadata.gz: a71f111d63ae9d67eb355aa8f692bffa86336632a83e4f3947e148c208169ad379f2ef614498f9c89dec926dab79c5766c623b53fea38cb7a58976ad4c8b75c0
7
- data.tar.gz: d4cb7379bf93758dec529e682f30724ff68a3d2f02c1acc3b6393256bebf0dcd04d988db05c3c346dae21901e63f6aa4092f47b6c98831e791a491acb3c59a97
6
+ metadata.gz: 505b5f1250aeb05e0c23a8b6d9822d4ca331db53504f906ce19c9d2802bb8d5d48f8bdc1fc0aa1170ef9b9b6f31d9eb838161db17271a84325a503adbaa03bda
7
+ data.tar.gz: ac00437d8f1e752db7989e7adecf174db970f27181312a19ad47216504f38a2cb0af4f51830a130454fa6bc3ad82e052ba7c495a9dc709b1878a82b762bd0ff0
@@ -2,14 +2,13 @@
2
2
  language: ruby
3
3
 
4
4
  rvm:
5
- - 1.9.3
6
5
  - 2.0.0
7
6
  - 2.1
8
7
  - 2.2
9
8
  - 2.3.0
9
+ - 2.4.0
10
10
  - rbx-2
11
11
  - jruby
12
- - jruby-head
13
12
  - ruby-head
14
13
 
15
14
  sudo: false
@@ -19,3 +18,4 @@ matrix:
19
18
  - rvm: rbx-2
20
19
  - rvm: ruby-head
21
20
  - rvm: jruby
21
+ - rvm: jruby-head
@@ -52,18 +52,20 @@ Run the specs with <tt>rake spec</tt>
52
52
  == Contributors
53
53
 
54
54
  * Rein Henrichs
55
- * Ray Krueger
56
- * Jeremy Kemper
57
- * Ryan Tomayko
58
- * Gabriel Burt
59
- * Rick Olson
60
- * Trae Robrock
55
+ * Alex Williams
56
+ * Andrew Meyer
57
+ * Chris Gaffney
58
+ * Cody Cutrer
61
59
  * Corey Donohoe
62
- * James Tucker
63
60
  * Dotan Nahum
61
+ * Erez Rabih
64
62
  * Eric Chapweske
63
+ * Gabriel Burt
65
64
  * Hannes Georg
65
+ * James Tucker
66
+ * Jeremy Kemper
66
67
  * John Nunemaker
68
+ * Lann Martin
67
69
  * Mahesh Murthy
68
70
  * Manu J
69
71
  * Matt Sanford
@@ -73,7 +75,11 @@ Run the specs with <tt>rake spec</tt>
73
75
  * Peter Mounce
74
76
  * Ray Krueger
75
77
  * Reed Lipman
78
+ * rick
79
+ * Ryan Tomayko
80
+ * Schuyler Erle
76
81
  * Thomas Whaples
82
+ * Trae Robrock
77
83
 
78
84
  == Copyright
79
85
 
@@ -53,13 +53,15 @@ class Statsd
53
53
  :postfix,
54
54
  :delimiter, :delimiter=
55
55
 
56
- attr_accessor :batch_size
56
+ attr_accessor :batch_size, :batch_byte_size
57
57
 
58
58
  # @param [Statsd] requires a configured Statsd instance
59
59
  def initialize(statsd)
60
60
  @statsd = statsd
61
61
  @batch_size = statsd.batch_size
62
+ @batch_byte_size = statsd.batch_byte_size
62
63
  @backlog = []
64
+ @backlog_bytesize = 0
63
65
  end
64
66
 
65
67
  # @yields [Batch] yields itself
@@ -77,14 +79,26 @@ class Statsd
77
79
  unless @backlog.empty?
78
80
  @statsd.send_to_socket @backlog.join("\n")
79
81
  @backlog.clear
82
+ @backlog_bytesize = 0
80
83
  end
81
84
  end
82
85
 
83
86
  protected
84
87
 
85
88
  def send_to_socket(message)
89
+ # this message wouldn't fit; flush the queue. note that we don't have
90
+ # to do this for message based flushing, because we're incrementing by
91
+ # one, so the post-queue check will always catch it
92
+ if (@batch_byte_size && @backlog_bytesize + message.bytesize + 1 > @batch_byte_size)
93
+ flush
94
+ end
86
95
  @backlog << message
87
- if @backlog.size >= @batch_size
96
+ @backlog_bytesize += message.bytesize
97
+ # skip the interleaved newline for the first item
98
+ @backlog_bytesize += 1 if @backlog.length != 1
99
+ # if we're precisely full now, flush
100
+ if (@batch_size && @backlog.size == @batch_size) ||
101
+ (@batch_byte_size && @backlog_bytesize == @batch_byte_size)
88
102
  flush
89
103
  end
90
104
  end
@@ -244,9 +258,12 @@ class Statsd
244
258
  # StatsD namespace prefix, generated from #namespace
245
259
  attr_reader :prefix
246
260
 
247
- # The default batch size for new batches (default: 10)
261
+ # The default batch size for new batches. Set to nil to use batch_byte_size (default: 10)
248
262
  attr_accessor :batch_size
249
263
 
264
+ # The default batch size, in bytes, for new batches (default: default nil; use batch_size)
265
+ attr_accessor :batch_byte_size
266
+
250
267
  # a postfix to append to all metrics
251
268
  attr_reader :postfix
252
269
 
@@ -267,6 +284,7 @@ class Statsd
267
284
  self.delimiter = "."
268
285
  @prefix = nil
269
286
  @batch_size = 10
287
+ @batch_byte_size = nil
270
288
  @postfix = nil
271
289
  @socket = nil
272
290
  @protocol = protocol || :udp
@@ -6,6 +6,7 @@ SimpleCov.start
6
6
  require 'minitest/autorun'
7
7
  require 'statsd'
8
8
  require 'logger'
9
+ require 'timeout'
9
10
 
10
11
  class FakeUDPSocket
11
12
  def initialize
@@ -212,7 +212,7 @@ describe Statsd do
212
212
  describe "when the sample rate is less than a random value [0,1]" do
213
213
  before { class << @statsd; def rand; 1; end; end } # ensure no delivery
214
214
  it "should not send" do
215
- @statsd.timing('foobar', 500, 0.5).must_equal nil
215
+ assert_nil @statsd.timing('foobar', 500, 0.5)
216
216
  end
217
217
  end
218
218
 
@@ -279,7 +279,7 @@ describe Statsd do
279
279
  [nil, false, ''].each do |value|
280
280
  @statsd.postfix = 'a postfix'
281
281
  @statsd.postfix = value
282
- @statsd.postfix.must_equal nil
282
+ assert_nil @statsd.postfix
283
283
  end
284
284
  end
285
285
  end
@@ -345,7 +345,7 @@ describe Statsd do
345
345
  end
346
346
 
347
347
  it "should ignore socket errors" do
348
- @statsd.increment('foobar').must_equal nil
348
+ assert_nil @statsd.increment('foobar')
349
349
  end
350
350
 
351
351
  it "should log socket errors" do
@@ -359,12 +359,24 @@ describe Statsd do
359
359
  @statsd.batch_size.must_equal 10
360
360
  end
361
361
 
362
+ it "should have a default batch byte size of nil" do
363
+ assert_nil @statsd.batch_byte_size
364
+ end
365
+
362
366
  it "should have a modifiable batch size" do
363
367
  @statsd.batch_size = 7
364
368
  @statsd.batch_size.must_equal 7
365
369
  @statsd.batch do |b|
366
370
  b.batch_size.must_equal 7
367
371
  end
372
+
373
+ @statsd.batch_size = nil
374
+ @statsd.batch_byte_size = 1472
375
+ @statsd.batch do |b|
376
+ assert_nil b.batch_size
377
+ b.batch_byte_size.must_equal 1472
378
+ end
379
+
368
380
  end
369
381
 
370
382
  it "should flush the batch at the batch size or at the end of the block" do
@@ -381,6 +393,34 @@ describe Statsd do
381
393
  @socket.recv.must_equal [(["foobar:1|c"] * 2).join("\n")]
382
394
  end
383
395
 
396
+ it "should flush based on batch byte size" do
397
+ @statsd.batch do |b|
398
+ b.batch_size = nil
399
+ b.batch_byte_size = 22
400
+
401
+ # The first two should flush, the last will be flushed when the
402
+ # block is done.
403
+ 3.times { b.increment('foobar') }
404
+
405
+ @socket.recv.must_equal [(["foobar:1|c"] * 2).join("\n")]
406
+ end
407
+
408
+ @socket.recv.must_equal ["foobar:1|c"]
409
+ end
410
+
411
+ it "should flush immediately when the queue is exactly a batch size" do
412
+ @statsd.batch do |b|
413
+ b.batch_size = nil
414
+ b.batch_byte_size = 21
415
+
416
+ # The first two should flush, the last will be flushed when the
417
+ # block is done.
418
+ 2.times { b.increment('foobar') }
419
+
420
+ @socket.recv.must_equal [(["foobar:1|c"] * 2).join("\n")]
421
+ end
422
+ end
423
+
384
424
  it "should not flush to the socket if the backlog is empty" do
385
425
  batch = Statsd::Batch.new(@statsd)
386
426
  batch.flush
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- Gem::Specification.new("statsd-ruby", "1.3.0") do |s|
4
- s.authors = ["Rein Henrichs"]
3
+ Gem::Specification.new("statsd-ruby", "1.4.0") do |s|
4
+ s.authors = `git log --format='%aN' | sort -u`.split("\n")
5
5
  s.email = "reinh@reinh.com"
6
6
 
7
7
  s.summary = "A Ruby StatsD client"
metadata CHANGED
@@ -1,14 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsd-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
+ - Alex Williams
8
+ - Andrew Meyer
9
+ - Chris Gaffney
10
+ - Cody Cutrer
11
+ - Corey Donohoe
12
+ - Dotan Nahum
13
+ - Erez Rabih
14
+ - Eric Chapweske
15
+ - Gabriel Burt
16
+ - Hannes Georg
17
+ - James Tucker
18
+ - Jeremy Kemper
19
+ - John Nunemaker
20
+ - Lann Martin
21
+ - Mahesh Murthy
22
+ - Manu J
23
+ - Matt Sanford
24
+ - Nate Bird
25
+ - Noah Lorang
26
+ - Oscar Del Ben
27
+ - Peter Mounce
28
+ - Ray Krueger
29
+ - Reed Lipman
7
30
  - Rein Henrichs
31
+ - rick
32
+ - Ryan Tomayko
33
+ - Schuyler Erle
34
+ - Thomas Whaples
35
+ - Trae Robrock
8
36
  autorequire:
9
37
  bindir: bin
10
38
  cert_chain: []
11
- date: 2016-01-17 00:00:00.000000000 Z
39
+ date: 2017-03-29 00:00:00.000000000 Z
12
40
  dependencies:
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: minitest
@@ -115,4 +143,3 @@ test_files:
115
143
  - spec/helper.rb
116
144
  - spec/statsd_admin_spec.rb
117
145
  - spec/statsd_spec.rb
118
- has_rdoc: