lookout-statsd 3.0.0 → 3.2.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
  SHA1:
3
- data.tar.gz: 7a997f961f7e49bc67f2987e0afc4b831630b244
4
- metadata.gz: bcf20394e43bbf29ac3831d0f103f5cb1732be47
3
+ metadata.gz: 242c2e64f28a0bd1cda881eb66c29266ed252495
4
+ data.tar.gz: 6908899a20d708998dd44d43c970f4d6b4041a8f
5
5
  SHA512:
6
- data.tar.gz: d7a5153f7f8453991f87d48c58e697914c1050ca91a9e68927d91ba84a835c47e8c996ece0cfbbc8eb9459e201f12913edf09464e317b2a0b13e4ab87e930b12
7
- metadata.gz: c0b58cc86a12178b2a6e58d17d6de15ef2fac204ad6402e6da7744de10bed5c9182054b5a4aba4b13321c9951a34b6a34c1cc442a5bbf673beb6c74465d8a7d9
6
+ metadata.gz: bb16f079fcf070e6ddd2b5f9ecd3900b1ade9439aca1042fbaffa6208d64ac871f8721d4bda43ba7408fdaf31818ebd7e02341dc62ef36ec2cf92a3e5145b4e7
7
+ data.tar.gz: 39e7f363c2d2e65365012ab10c74b60d266a8b01adbb67f7a6790d9ed31e22f2224240cd2d7ea48cbb8dccd6e2a560fe8b09f629859b76b5d59260b9b7750011
@@ -77,6 +77,15 @@ module Lookout
77
77
  value
78
78
  end
79
79
 
80
+ # +stat+ to log timing for, from provided block
81
+ def time(stat, sample_rate = 1)
82
+ start_time = Time.now.to_f
83
+ value = yield
84
+ ensure
85
+ timing(stat, ((Time.now.to_f - start_time) * 1000).floor, sample_rate)
86
+ value
87
+ end
88
+
80
89
  # +stats+ can be a string or an array of strings
81
90
  def increment(stats, sample_rate = 1)
82
91
  update_counter stats, 1, sample_rate
@@ -94,6 +103,8 @@ module Lookout
94
103
  send_stats(stats.map { |s| "#{p}#{s}:#{delta}|c" }, sample_rate)
95
104
  end
96
105
 
106
+ alias_method :count, :update_counter
107
+
97
108
  # +stat_or_stats+ may either be a Hash OR a String. If it's a
98
109
  # String, then value must be specified. Other statsd client gems
99
110
  # have mostly standardized on using the String+value format, but
@@ -158,6 +158,32 @@ describe Lookout::StatsdClient do
158
158
  end
159
159
  end
160
160
 
161
+ describe '#time' do
162
+ let(:c) { Lookout::StatsdClient.new }
163
+ let(:value) { 1337 }
164
+ let(:sample_rate) { 3 }
165
+
166
+ before :each do
167
+ # Pretend our block took one second
168
+ Time.stub_chain(:now, :to_f).and_return(1, 2)
169
+ end
170
+
171
+ it 'should wrap a block correctly' do
172
+ expect(c).to receive(:timing).with('foo', 1000, 1)
173
+ c.time('foo') { true }
174
+ end
175
+
176
+ it 'should pass along sample rate' do
177
+ expect(c).to receive(:timing).with('foo', 1000, sample_rate)
178
+ c.time('foo', sample_rate) { true }
179
+ end
180
+
181
+ it 'should return the return value from the block' do
182
+ value = c.time('foo') { value }
183
+ expect(value).to eq value
184
+ end
185
+ end
186
+
161
187
  describe '#increment' do
162
188
  let(:c) { Lookout::StatsdClient.new }
163
189
 
@@ -192,6 +218,15 @@ describe Lookout::StatsdClient do
192
218
  end
193
219
  end
194
220
 
221
+ describe '#count' do
222
+ let(:c) { Lookout::StatsdClient.new }
223
+
224
+ it 'should behave like update_counter' do
225
+ c.should_receive(:send_stats).with(['foo:123|c'], 1)
226
+ c.update_counter('foo', 123, 1)
227
+ end
228
+ end
229
+
195
230
  describe '#gauge' do
196
231
  let(:c) { Lookout::StatsdClient.new }
197
232
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "lookout-statsd"
5
- s.version = "3.0.0"
5
+ s.version = "3.2.0"
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: 3.0.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - R. Tyler Croy
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2016-07-13 00:00:00 Z
14
+ date: 2016-07-18 00:00:00 Z
15
15
  dependencies: []
16
16
 
17
17
  description: A simple ruby statsd client.