lookout-statsd 2.0.2 → 2.0.3

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
  SHA1:
3
- metadata.gz: 2baad881d1608d20884a5a33b855672ae0847d30
4
- data.tar.gz: 7f3f990fd0e4937862df3a2d5b061f5b6c01e09a
3
+ metadata.gz: d1991db3ab55ae4ba74b693dfcb600b2d809cb96
4
+ data.tar.gz: 1718da7a874889f7c94eb18e20db2ae937b97b36
5
5
  SHA512:
6
- metadata.gz: 4b4c0dbf5031e165463694bd94fb11ff6134f6a98648bd0d727764c6ac9f03717af29fdc635f81c77d834f0e48b1a46251898320209fd2c5661a0c6edbeaccb3
7
- data.tar.gz: 775570d1c333c71c6500d1826d7194e7c28521d92a398d0fe7df7d55b7b3a9c42bcc554693582b025962111d04d31210741164fcd7ea2ed93b19278c6aede06d
6
+ metadata.gz: 793034d20062c3a9a3c5014191b7fdf3e118bd5271170ab35ff3e3aa66c7a2c23541669179820581700979e7441b6d1fe0137b451faca62501c8d0ab01bcf363
7
+ data.tar.gz: 57b8807ef73cafd8c6ce406d987500b8f6b118ad02ef23f8a2875650801f0e380045b92348fbe7226bdd7fecb5703693b290f3ff7d3f2903d7b1116ccd2d2423
@@ -97,7 +97,7 @@ module Statsd
97
97
  # @example Batch two instument operations:
98
98
  # $statsd.batch do |batch|
99
99
  # batch.increment 'sys.requests'
100
- # batch.gauge('user.count', User.count)
100
+ # batch.gauge {'user.count' => User.count}
101
101
  # end
102
102
  def batch(&block)
103
103
  Batch.new(self).easy(&block)
@@ -161,7 +161,7 @@ module Statsd
161
161
  # batch = Statsd::Batch.new($statsd)
162
162
  # batch.increment 'garets'
163
163
  # batch.timing 'glork', 320
164
- # batch.gauge 'bork', 100
164
+ # batch.gauge 'bork': 100
165
165
  # batch.flush
166
166
  #
167
167
  # Batch is a subclass of Statsd, but with a constructor that proxies to a
@@ -172,14 +172,6 @@ module Statsd
172
172
  # troubles may occur and data will be lost.
173
173
  class Batch < Statsd::Client
174
174
 
175
- extend Forwardable
176
- def_delegators :@statsd,
177
- :host, :host=,
178
- :port, :port=,
179
- :prefix,
180
- :postfix,
181
- :delimiter, :delimiter=
182
-
183
175
  attr_accessor :batch_size
184
176
 
185
177
  # @param [Statsd] requires a configured Statsd instance
@@ -188,6 +180,9 @@ module Statsd
188
180
  @batch_size = statsd.batch_size
189
181
  @backlog = []
190
182
  @send_data = send_method
183
+ @host = statsd.host
184
+ @port = statsd.port
185
+ @prefix = statsd.prefix
191
186
  end
192
187
 
193
188
  # @yields [Batch] yields itself
@@ -209,4 +209,113 @@ describe Statsd::Client do
209
209
  subject
210
210
  end
211
211
  end
212
+ end
213
+
214
+ describe Statsd::Batch do
215
+ let(:c) { Statsd::Client.new :host => 'foo.com', :prefix => 'my.app', :port => 1234, :batch_size => 20 }
216
+
217
+ it 'should delegate fields correctly' do
218
+ c.batch do |b|
219
+ expect(b.host).to eql 'foo.com'
220
+ expect(b.prefix).to eql 'my.app'
221
+ expect(b.port).to eql 1234
222
+ expect(b.batch_size).to eql 20
223
+ end
224
+ end
225
+
226
+ describe '#gauge' do
227
+ it 'should apply the prefix correctly' do
228
+ c.batch do |b|
229
+ b.should_receive(:send_stats).with(["my.app.an_incrementer:2|g"])
230
+ b.gauge({'an_incrementer' => 2})
231
+ end
232
+ end
233
+ end
234
+
235
+ describe '#timing' do
236
+
237
+ before :each do
238
+ c.prefix = nil
239
+ end
240
+
241
+ it 'should pass the sample rate along' do
242
+ sample = 10
243
+ c.batch do |b|
244
+ b.should_receive(:send_stats).with(anything(), sample)
245
+ b.timing('foo', 1, sample)
246
+ end
247
+ end
248
+
249
+ it 'should use the right stat name' do
250
+ c.batch do |b|
251
+ b.should_receive(:send_stats).with('foo:1|ms', anything())
252
+ b.timing('foo', 1)
253
+ end
254
+ end
255
+
256
+ it 'should prefix its stats if it has a prefix' do
257
+ c.prefix = 'dev'
258
+ c.batch do |b|
259
+ b.should_receive(:send_stats).with('dev.foo:1|ms', anything())
260
+ b.timing('foo', 1)
261
+ end
262
+ end
263
+
264
+ it 'should wrap a block correctly' do
265
+ # Pretend our block took one second
266
+ c.batch do |b|
267
+ b.should_receive(:send_stats).with('foo:1000|ms', anything())
268
+ Time.stub_chain(:now, :to_f).and_return(1, 2)
269
+
270
+ b.timing('foo') do
271
+ true.should be true
272
+ end
273
+ end
274
+ end
275
+
276
+ it 'should return the return value from the block' do
277
+ # Pretend our block took one second
278
+ c.batch do |b|
279
+ b.should_receive(:send_stats).with('foo:1000|ms', anything())
280
+ Time.stub_chain(:now, :to_f).and_return(1, 2)
281
+
282
+ value = b.timing('foo') { 1337 }
283
+ value.should == 1337
284
+ end
285
+ end
286
+ end
287
+
288
+ describe '#increment' do
289
+ it 'should update the counter by 1' do
290
+ c.should_receive(:update_counter).with('foo', 1, anything())
291
+ c.increment('foo')
292
+ end
293
+ end
294
+
295
+ describe '#decrement' do
296
+ it 'should update the counter by -1' do
297
+ c.batch do |b|
298
+ b.should_receive(:update_counter).with('foo', -1, anything())
299
+ b.decrement('foo')
300
+ end
301
+ end
302
+ end
303
+
304
+ describe '#update_counter' do
305
+ it 'should prepend the prefix if it has one' do
306
+ c.prefix = 'dev'
307
+ c.batch do |b|
308
+ b.should_receive(:send_stats).with(['dev.foo:123|c'], anything())
309
+ b.update_counter('foo', 123)
310
+ end
311
+ end
312
+
313
+ it 'should prepend multiple prefixes if it has one' do
314
+ c.prefix = 'dev'
315
+ c.batch do |b|
316
+ b.should_receive(:send_stats).with(['dev.foo:123|c', 'dev.bar:123|c'], anything())
317
+ b.update_counter(['foo', 'bar'], 123)
318
+ end
319
+ end
320
+ end
212
321
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "lookout-statsd"
5
- s.version = "2.0.2"
5
+ s.version = "2.0.3"
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.authors = ['R. Tyler Croy', 'Andrew Coldham', 'Ben VandenBos']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookout-statsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - R. Tyler Croy
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-05-18 00:00:00.000000000 Z
13
+ date: 2016-05-20 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: A simple ruby statsd client.
16
16
  email: