Permalink
Browse files

Merge pull request #16 from hornairs/master

Allow StatsD.measure to accept a sample_rate like the other operations.
  • Loading branch information...
2 parents 3f67670 + 0674f3a commit 9c43c98ddb99105c4bef94a20ce9b9cb80c59270 @jstorimer jstorimer committed Jul 9, 2012
Showing with 11 additions and 5 deletions.
  1. +3 −3 lib/statsd/instrument.rb
  2. +8 −2 test/statsd-instrument_test.rb
@@ -15,7 +15,7 @@ class << self
:prefix, :implementation
end
self.enabled = true
- self.default_sample_rate = 1
+ self.default_sample_rate = 1.0
self.implementation = :statsd
TimeoutClass = defined?(::SystemTimer) ? ::SystemTimer : ::Timeout
@@ -100,13 +100,13 @@ def add_to_method(method, name, action, &block)
end
# glork:320|ms
- def self.measure(key, milli = nil)
+ def self.measure(key, milli = nil, sample_rate = default_sample_rate)
result = nil
ms = milli || Benchmark.ms do
result = yield
end
- write(key, ms, :ms)
+ write(key, ms, :ms, sample_rate)
result
end
@@ -139,7 +139,7 @@ def test_statsd_count_with_method_receiving_block
def test_statsd_measure
ActiveMerchant::UniqueGateway.statsd_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
- StatsD.expects(:write).with('ActiveMerchant.Gateway.ssl_post', is_a(Float), :ms).returns({:success => true})
+ StatsD.expects(:write).with('ActiveMerchant.Gateway.ssl_post', is_a(Float), :ms, is_a(Numeric)).returns({:success => true})
ActiveMerchant::UniqueGateway.new.purchase(true)
end
@@ -257,11 +257,17 @@ def test_statsd_prefix
end
def test_statsd_measure_with_explicit_value
- StatsD.expects(:write).with('values.foobar', 42, :ms)
+ StatsD.expects(:write).with('values.foobar', 42, :ms, is_a(Numeric))
StatsD.measure('values.foobar', 42)
end
+ def test_statsd_measure_with_explicit_value_and_sample_rate
+ StatsD.expects(:write).with('values.foobar', 42, :ms, 0.1)
+
+ StatsD.measure('values.foobar', 42, 0.1)
+ end
+
def test_statsd_gauge
StatsD.expects(:write).with('values.foobar', 12, :g, 1)

0 comments on commit 9c43c98

Please sign in to comment.