From a3746aac7364d87775babe4d407e7f080fcb446b Mon Sep 17 00:00:00 2001 From: Nathan Witmer Date: Tue, 29 Jul 2014 20:09:37 -0600 Subject: [PATCH 1/3] Send floating point milliseconds in time block To match what the available back-ends support. --- lib/statsd.rb | 2 +- spec/statsd_spec.rb | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/statsd.rb b/lib/statsd.rb index dfddf1d..0877c78 100644 --- a/lib/statsd.rb +++ b/lib/statsd.rb @@ -89,7 +89,7 @@ def timing(stat, ms, sample_rate=1); send stat, ms, 'ms', sample_rate end def time(stat, sample_rate=1) start = Time.now result = yield - timing(stat, ((Time.now - start) * 1000).round, sample_rate) + timing(stat, (Time.now - start) * 1000, sample_rate) result end diff --git a/spec/statsd_spec.rb b/spec/statsd_spec.rb index 6c6523c..ab6c582 100644 --- a/spec/statsd_spec.rb +++ b/spec/statsd_spec.rb @@ -71,7 +71,11 @@ def socket; @socket ||= FakeUDPSocket.new end describe "#time" do it "should format the message according to the statsd spec" do @statsd.time('foobar') { sleep(0.001); 'test' } - @statsd.socket.recv.must_equal ['foobar:1|ms'] + data = @statsd.socket.recv + key, value, unit = data.first.split(/[:|]/) + key.must_equal "foobar" + value.must_match /^\d\.\d{3}$/ + unit.must_equal "ms" end it "should return the result of the block" do @@ -84,7 +88,12 @@ def socket; @socket ||= FakeUDPSocket.new end it "should format the message according to the statsd spec" do result = @statsd.time('foobar', 0.5) { sleep(0.001); 'test' } - @statsd.socket.recv.must_equal ['foobar:1|ms|@0.5'] + data = @statsd.socket.recv + key, value, unit, frequency = data.first.split(/[:|]/) + key.must_equal "foobar" + value.must_match /^\d\.\d{3}$/ + unit.must_equal "ms" + frequency.must_equal "@0.5" end end end From abef030eb4c8defad396fe2ca87f7dec5058e6b6 Mon Sep 17 00:00:00 2001 From: Nathan Witmer Date: Tue, 29 Jul 2014 20:10:56 -0600 Subject: [PATCH 2/3] Bump version to 0.3.0.github.3 --- statsd-ruby.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/statsd-ruby.gemspec b/statsd-ruby.gemspec index 8853f5f..120261b 100644 --- a/statsd-ruby.gemspec +++ b/statsd-ruby.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{statsd-ruby} - s.version = "0.3.0.github.2" + s.version = "0.3.0.github.3" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Rein Henrichs"] From 66937efc669e2ce23056521adc84b1ab00fa4d6d Mon Sep 17 00:00:00 2001 From: Nathan Witmer Date: Wed, 30 Jul 2014 09:54:35 -0600 Subject: [PATCH 3/3] Round milliseconds to 5 decimal places To prevent potential problems with repeating decimals, e.g. 0.3333333333333. --- lib/statsd.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/statsd.rb b/lib/statsd.rb index 0877c78..e3bfff5 100644 --- a/lib/statsd.rb +++ b/lib/statsd.rb @@ -89,7 +89,7 @@ def timing(stat, ms, sample_rate=1); send stat, ms, 'ms', sample_rate end def time(stat, sample_rate=1) start = Time.now result = yield - timing(stat, (Time.now - start) * 1000, sample_rate) + timing(stat, ((Time.now - start) * 1000).round(5), sample_rate) result end