Permalink
Browse files

Add timer and counter aliases.

  • Loading branch information...
1 parent e252fab commit fed935c37c11f5906b041b9232682445d0dbb5ec @wvanbergen wvanbergen committed Feb 7, 2014
Showing with 14 additions and 3 deletions.
  1. +4 −2 lib/statsd/instrument.rb
  2. +10 −1 test/statsd_test.rb
View
6 lib/statsd/instrument.rb
@@ -147,8 +147,10 @@ def measure(key, value = nil, *metric_options)
result
end
+ alias_method :timer, :measure
+
# gorets:1|c
- def counter(key, value = 1, *metric_options)
+ def increment(key, value = 1, *metric_options)
if value.is_a?(Hash) && metric_options.empty?
metric_options = [value]
value = 1
@@ -157,7 +159,7 @@ def counter(key, value = 1, *metric_options)
collect(:c, key, value, hash_argument(metric_options))
end
- alias_method :increment, :counter
+ alias_method :counter, :increment
# gaugor:333|g
# guagor:1234|kv|@1339864935 (statsite)
View
11 test/statsd_test.rb
@@ -33,7 +33,6 @@ def test_statsd_measure_with_benchmarked_value
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)
@@ -42,6 +41,11 @@ def test_statsd_measure_with_benchmarked_value_and_options
end
end
+ def test_statsd_timer_as_alias_for_measure
+ StatsD.expects(:collect).with(:ms, 'values.foobar', 42, {})
+ StatsD.timer('values.foobar', 42)
+ end
+
def test_statsd_increment_with_hash_argument
StatsD.expects(:collect).with(:c, 'values.foobar', 1, :tags => ['test'])
StatsD.increment('values.foobar', :tags => ['test'])
@@ -52,6 +56,11 @@ def test_statsd_increment_with_multiple_arguments
StatsD.increment('values.foobar', 12, nil, ['test'])
end
+ def test_statsd_counter_as_alias_for_increment
+ StatsD.expects(:collect).with(:c, 'values.foobar', 12, :sample_rate => nil, :tags => ['test'])
+ StatsD.counter('values.foobar', 12, nil, ['test'])
+ end
+
def test_statsd_gauge
StatsD.expects(:collect).with(:g, 'values.foobar', 12, {})
StatsD.gauge('values.foobar', 12)

0 comments on commit fed935c

Please sign in to comment.