dogstatsd-ruby 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/datadog/statsd.rb +40 -15
  3. metadata +14 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c284304d148850b444a486ee039186569aae88fd
4
- data.tar.gz: 9174ee71af5fbf618e441e8ec620333434ae35cd
3
+ metadata.gz: 58a9207adf16ba8265e91fd56b6315b35ecc9b58
4
+ data.tar.gz: 9fc64d84a4b0277752bad6a5b523f1ab1ac989c2
5
5
  SHA512:
6
- metadata.gz: 330a64649311a33fa09bf9983ca77817ecf5413ba79318bdcc75712df0e3d0b4650a0fc714437490125e59f675144babb94fd846507bed3b51e06fe40cd45ee4
7
- data.tar.gz: aede77d7cd0dd1b49d109016dbc405ff5ee408000689b00ae68fea2228ddd4beb4ec65fd27fcaf503249199984ac22296704d0082254589d977bfa93c3f31a2d
6
+ metadata.gz: 89574d06e8d66f00a203d6d84b9e20f70b1d64e90fd2dfa644bdab8993a0420065b2e426d574fc0c0239fc69f49a65b0d215359c50ec2fd00dd9b9214f8c9f13
7
+ data.tar.gz: d97dc13266fe51bc7d49ebb8e56235aef70a6773e89d890ffe4774e0406489f6a7fadb43818f1000fc70f7520d6baec19d05b395c732cce9ea22ef9107597de9
@@ -64,6 +64,10 @@ module Datadog
64
64
  # Global tags to be added to every statsd call. Defaults to no tags.
65
65
  attr_reader :tags
66
66
 
67
+ # True if we should batch up data before sending it, or false if we
68
+ # want to send data immediately.
69
+ attr_reader :should_batch
70
+
67
71
  # Buffer containing the statsd message before they are sent in batch
68
72
  attr_reader :buffer
69
73
 
@@ -77,7 +81,7 @@ module Datadog
77
81
 
78
82
  # Return the current version of the library.
79
83
  def self.VERSION
80
- "2.2.0"
84
+ "3.0.0"
81
85
  end
82
86
 
83
87
  # @param [String] host your statsd host
@@ -87,12 +91,12 @@ module Datadog
87
91
  def initialize(host = DEFAULT_HOST, port = DEFAULT_PORT, opts = {}, max_buffer_size=50)
88
92
  self.host, self.port = host, port
89
93
  @prefix = nil
90
- @socket = UDPSocket.new
94
+ @socket = connect_to_socket(host, port)
91
95
  self.namespace = opts[:namespace]
92
96
  self.tags = opts[:tags]
93
97
  @buffer = Array.new
94
98
  self.max_buffer_size = max_buffer_size
95
- alias :send_stat :send_to_socket
99
+ @should_batch = false
96
100
  end
97
101
 
98
102
  def namespace=(namespace) #:nodoc:
@@ -299,10 +303,11 @@ module Datadog
299
303
  # s.increment('page.views')
300
304
  # end
301
305
  def batch()
302
- alias :send_stat :send_to_buffer
306
+ @should_batch = true
303
307
  yield self
304
308
  flush_buffer
305
- alias :send_stat :send_to_socket
309
+ ensure
310
+ @should_batch = false
306
311
  end
307
312
 
308
313
  def format_event(title, text, opts={})
@@ -329,6 +334,11 @@ module Datadog
329
334
  return event_string_data
330
335
  end
331
336
 
337
+ # Close the underlying socket
338
+ def close()
339
+ @socket.close
340
+ end
341
+
332
342
  private
333
343
 
334
344
  NEW_LINE = "\n".freeze
@@ -413,10 +423,12 @@ module Datadog
413
423
  end
414
424
  end
415
425
 
416
- def send_to_buffer(message)
417
- @buffer << message
418
- if @buffer.length >= @max_buffer_size
419
- flush_buffer
426
+ def send_stat(message)
427
+ if @should_batch
428
+ @buffer << message
429
+ flush_buffer if @buffer.length >= @max_buffer_size
430
+ else
431
+ send_to_socket(message)
420
432
  end
421
433
  end
422
434
 
@@ -425,17 +437,30 @@ module Datadog
425
437
  @buffer = Array.new
426
438
  end
427
439
 
440
+ def connect_to_socket(host, port)
441
+ socket = UDPSocket.new
442
+ socket.connect(host, port)
443
+ socket
444
+ end
445
+
428
446
  def send_to_socket(message)
429
447
  self.class.logger.debug { "Statsd: #{message}" } if self.class.logger
430
- @socket.send(message, 0, @host, @port)
448
+ @socket.send(message, 0)
431
449
  rescue => boom
450
+ # Try once to reconnect if the socket has been closed
451
+ retries ||= 1
452
+ if retries <= 1 && boom.is_a?(IOError) && boom.message =~ /closed stream/i
453
+ retries += 1
454
+ begin
455
+ @socket = connect_to_socket(host, port)
456
+ retry
457
+ rescue => e
458
+ boom = e
459
+ end
460
+ end
461
+
432
462
  self.class.logger.error { "Statsd: #{boom.class} #{boom}" } if self.class.logger
433
463
  nil
434
464
  end
435
-
436
- # Close the underlying socket
437
- def close()
438
- @socket.close
439
- end
440
465
  end
441
466
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogstatsd-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rein Henrichs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-12 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: yard
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.6.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.6.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: jeweler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.8'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.8'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: A Ruby DogStastd client
@@ -87,18 +87,19 @@ require_paths:
87
87
  - lib
88
88
  required_ruby_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
- - - '>='
90
+ - - ">="
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - '>='
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  requirements: []
99
99
  rubyforge_project:
100
- rubygems_version: 2.0.14.1
100
+ rubygems_version: 2.6.8
101
101
  signing_key:
102
102
  specification_version: 4
103
103
  summary: A Ruby DogStatsd client
104
104
  test_files: []
105
+ has_rdoc: