dogstatsd-ruby 2.1.0 → 2.2.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 +55 -11
  3. metadata +13 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 481edf1969341d5a0fcca585196f32b19a0290ee
4
- data.tar.gz: 743744502b34fa5c2b53afe3e8ce0a924c1cd317
3
+ metadata.gz: c284304d148850b444a486ee039186569aae88fd
4
+ data.tar.gz: 9174ee71af5fbf618e441e8ec620333434ae35cd
5
5
  SHA512:
6
- metadata.gz: d5d5f0f2f11c3f713d4907e0dc8b89978ad2dbcb21466705b31e630102f2a36f68eb6bafad1c66a2783f010c66ee1a7f7fffa13ee3a1ca03c85357fc63b8fb56
7
- data.tar.gz: 5a746d3b48a5c31b5cbd40b06daa896c1faa7d1f8d4686cdcf69d6066bdf1fd5c81bcfaa1e08462df8b234e8a08b3bbde7f445b26819480717a0edc4bdb131be
6
+ metadata.gz: 330a64649311a33fa09bf9983ca77817ecf5413ba79318bdcc75712df0e3d0b4650a0fc714437490125e59f675144babb94fd846507bed3b51e06fe40cd45ee4
7
+ data.tar.gz: aede77d7cd0dd1b49d109016dbc405ff5ee408000689b00ae68fea2228ddd4beb4ec65fd27fcaf503249199984ac22296704d0082254589d977bfa93c3f31a2d
@@ -46,6 +46,12 @@ module Datadog
46
46
  CRITICAL = 2
47
47
  UNKNOWN = 3
48
48
 
49
+ COUNTER_TYPE = 'c'.freeze
50
+ GAUGE_TYPE = 'g'.freeze
51
+ HISTOGRAM_TYPE = 'h'.freeze
52
+ TIMING_TYPE = 'ms'.freeze
53
+ SET_TYPE = 's'.freeze
54
+
49
55
  # A namespace to prepend to all statsd calls. Defaults to no namespace.
50
56
  attr_reader :namespace
51
57
 
@@ -71,7 +77,7 @@ module Datadog
71
77
 
72
78
  # Return the current version of the library.
73
79
  def self.VERSION
74
- "2.1.0"
80
+ "2.2.0"
75
81
  end
76
82
 
77
83
  # @param [String] host your statsd host
@@ -141,7 +147,7 @@ module Datadog
141
147
  # @option opts [Numeric] :sample_rate sample rate, 1 for always
142
148
  # @option opts [Array<String>] :tags An array of tags
143
149
  def count(stat, count, opts={})
144
- send_stats stat, count, :c, opts
150
+ send_stats stat, count, COUNTER_TYPE, opts
145
151
  end
146
152
 
147
153
  # Sends an arbitary gauge value for the given stat to the statsd server.
@@ -158,7 +164,7 @@ module Datadog
158
164
  # @example Report the current user count:
159
165
  # $statsd.gauge('user.count', User.count)
160
166
  def gauge(stat, value, opts={})
161
- send_stats stat, value, :g, opts
167
+ send_stats stat, value, GAUGE_TYPE, opts
162
168
  end
163
169
 
164
170
  # Sends a value to be tracked as a histogram to the statsd server.
@@ -171,7 +177,7 @@ module Datadog
171
177
  # @example Report the current user count:
172
178
  # $statsd.histogram('user.count', User.count)
173
179
  def histogram(stat, value, opts={})
174
- send_stats stat, value, :h, opts
180
+ send_stats stat, value, HISTOGRAM_TYPE, opts
175
181
  end
176
182
 
177
183
  # Sends a timing (in ms) for the given stat to the statsd server. The
@@ -185,7 +191,7 @@ module Datadog
185
191
  # @option opts [Numeric] :sample_rate sample rate, 1 for always
186
192
  # @option opts [Array<String>] :tags An array of tags
187
193
  def timing(stat, ms, opts={})
188
- send_stats stat, ms, :ms, opts
194
+ send_stats stat, ms, TIMING_TYPE, opts
189
195
  end
190
196
 
191
197
  # Reports execution time of the provided block using {#timing}.
@@ -217,7 +223,7 @@ module Datadog
217
223
  # @example Record a unique visitory by id:
218
224
  # $statsd.set('visitors.uniques', User.id)
219
225
  def set(stat, value, opts={})
220
- send_stats stat, value, :s, opts
226
+ send_stats stat, value, SET_TYPE, opts
221
227
  end
222
228
 
223
229
 
@@ -345,6 +351,12 @@ module Datadog
345
351
  remove_pipes(tag).gsub COMMA, BLANK
346
352
  end
347
353
 
354
+ def escape_tag_content!(tag)
355
+ tag.gsub!(PIPE, BLANK)
356
+ tag.gsub!(COMMA, BLANK)
357
+ tag
358
+ end
359
+
348
360
  def remove_pipes(msg)
349
361
  msg.gsub PIPE, BLANK
350
362
  end
@@ -357,15 +369,47 @@ module Datadog
357
369
  timing(stat, ((Time.now - start) * 1000).round, opts)
358
370
  end
359
371
 
372
+ def join_array_to_str(str, array, joiner)
373
+ array.each_with_index do |item, i|
374
+ str << joiner unless i == 0
375
+ str << item
376
+ end
377
+ end
378
+
360
379
  def send_stats(stat, delta, type, opts={})
361
380
  sample_rate = opts[:sample_rate] || 1
362
381
  if sample_rate == 1 or rand < sample_rate
382
+ full_stat = ''
383
+ full_stat << @prefix if @prefix
384
+
385
+ stat = stat.is_a?(String) ? stat.dup : stat.to_s
363
386
  # Replace Ruby module scoping with '.' and reserved chars (: | @) with underscores.
364
- stat = stat.to_s.gsub(DOUBLE_COLON, DOT).tr(':|@'.freeze, UNDERSCORE)
365
- rate = "|@#{sample_rate}" unless sample_rate == 1
366
- ts = (tags || []) + (opts[:tags] || []).map {|tag| escape_tag_content(tag)}
367
- tags = "|##{ts.join(COMMA)}" unless ts.empty?
368
- send_stat "#{@prefix}#{stat}:#{delta}|#{type}#{rate}#{tags}"
387
+ stat.gsub!(DOUBLE_COLON, DOT)
388
+ stat.tr!(':|@'.freeze, UNDERSCORE)
389
+ full_stat << stat
390
+
391
+ full_stat << ':'.freeze
392
+ full_stat << delta.to_s
393
+ full_stat << PIPE
394
+ full_stat << type
395
+
396
+ unless sample_rate == 1
397
+ full_stat << PIPE
398
+ full_stat << '@'.freeze
399
+ full_stat << sample_rate.to_s
400
+ end
401
+
402
+
403
+ tag_arr = opts[:tags].to_a
404
+ tag_arr.map! { |tag| t = tag.dup; escape_tag_content!(t); t }
405
+ ts = tags.to_a + tag_arr
406
+ unless ts.empty?
407
+ full_stat << PIPE
408
+ full_stat << '#'.freeze
409
+ join_array_to_str(full_stat, ts, COMMA)
410
+ end
411
+
412
+ send_stat(full_stat)
369
413
  end
370
414
  end
371
415
 
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.1.0
4
+ version: 2.2.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: 2016-10-27 00:00:00.000000000 Z
11
+ date: 2017-01-12 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,19 +87,18 @@ 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.4.3
100
+ rubygems_version: 2.0.14.1
101
101
  signing_key:
102
102
  specification_version: 4
103
103
  summary: A Ruby DogStatsd client
104
104
  test_files: []
105
- has_rdoc: