Permalink
Browse files

Merge pull request #33 from Shopify/set_support

add set support
  • Loading branch information...
2 parents bcb8a5a + c2590f8 commit 6a04a6875d94da89b9c6c217298bd591977643f8 @wvanbergen wvanbergen committed Feb 6, 2014
Showing with 20 additions and 0 deletions.
  1. +7 −0 lib/statsd/instrument.rb
  2. +13 −0 test/statsd_test.rb
View
@@ -156,6 +156,11 @@ def self.histogram(key, value, sample_rate_or_epoch = default_sample_rate, tags
collect(key, value, :h, sample_rate_or_epoch, tags)
end
+ # uniques:765|s
+ def self.set(key, value, sample_rate_or_epoch = default_sample_rate, tags = nil)
+ collect(key, value, :s, sample_rate_or_epoch, tags)
+ end
+
private
def self.invalidate_socket
@@ -209,6 +214,8 @@ def self.generate_packet(k, v, op, sample_rate = default_sample_rate, tags = nil
when :h
raise NotImplementedError, "Histograms only supported on DataDog implementation." unless self.implementation == :datadog
command << '|h'
+ when :s
+ command << '|s'
end
command << "|@#{sample_rate}" if sample_rate < 1 || (self.implementation == :statsite && sample_rate > 1)
View
@@ -38,6 +38,11 @@ def test_statsd_gauge
StatsD.gauge('values.foobar', 12)
end
+ def test_statsd_set
+ StatsD.expects(:collect).with('values.foobar', 12, :s, 1.0, nil)
+ StatsD.set('values.foobar', 12)
+ end
+
def test_statsd_histogram_on_datadog
StatsD.stubs(:implementation).returns(:datadog)
StatsD.expects(:collect).with('values.hg', 12.33, :h, 0.2, ['tag_123', 'key-name:value123'])
@@ -76,6 +81,14 @@ def test_supports_gauge_syntax
StatsD.gauge('fooy', 42, 0.01)
end
+ def test_supports_set_syntax
+ StatsD.expects(:write_packet).with('unique:10.0.0.10|s')
+ StatsD.set('unique', '10.0.0.10')
+
+ StatsD.expects(:write_packet).with('unique:10.0.0.10|s|@0.01')
+ StatsD.set('unique', '10.0.0.10', 0.01)
+ end
+
def test_support_timing_syntax
StatsD.expects(:write_packet).with('duration:1.23|ms')
StatsD.measure('duration', 1.23)

0 comments on commit 6a04a68

Please sign in to comment.