Permalink
Browse files

Handle nil argument properly for StatsD.measure.

  • Loading branch information...
1 parent 8841d20 commit 4918143cb2de22b73e1a7e21c819711507fdfd6a @wvanbergen wvanbergen committed Feb 7, 2014
Showing with 17 additions and 3 deletions.
  1. +7 −2 lib/statsd/instrument.rb
  2. +10 −1 test/statsd_test.rb
View
@@ -132,9 +132,14 @@ def remove_from_method(method, name, action)
end
# glork:320|ms
- def self.measure(key, milli = nil, *metric_options)
+ def self.measure(key, value = nil, *metric_options)
+ if value.is_a?(Hash) && metric_options.empty?
+ metric_options = [value]
+ value = nil
+ end
+
result = nil
- ms = milli || 1000 * Benchmark.realtime do
+ ms = value || 1000 * Benchmark.realtime do
result = yield
end
View
@@ -28,7 +28,16 @@ def test_statsd_measure_with_explicit_value_and_sample_rate
def test_statsd_measure_with_benchmarked_value
Benchmark.stubs(:realtime).returns(1.12)
StatsD.expects(:collect).with(:ms, 'values.foobar', 1120.0, {})
- StatsD.measure('values.foobar', nil) do
+ StatsD.measure('values.foobar') do
+ #noop
+ end
+ end
+
+
+ def test_statsd_measure_with_benchmarked_value_and_options
+ Benchmark.stubs(:realtime).returns(1.12)
+ StatsD.expects(:collect).with(:ms, 'values.foobar', 1120.0, :sample_rate => 1.0)
+ StatsD.measure('values.foobar', :sample_rate => 1.0) do
#noop
end
end

0 comments on commit 4918143

Please sign in to comment.