diff options
author | Thomas Stephens <thomas@ustudio.com> | 2013-04-26 16:00:05 -0500 |
---|---|---|
committer | Thomas Stephens <thomas@ustudio.com> | 2013-04-26 16:00:05 -0500 |
commit | b8c3dc423a62aba80742cb9025455e49851842e3 (patch) | |
tree | 283fd03236a66d4aa342bbe5d8d2ce4bae06b3ec | |
parent | f28f6c988fc087388577cd5e8df28ca8d648c0e3 (diff) | |
download | pystatsd-b8c3dc423a62aba80742cb9025455e49851842e3.tar.gz |
Adding the 'set' data type to the client
-rw-r--r-- | statsd/client.py | 6 | ||||
-rw-r--r-- | statsd/tests.py | 12 |
2 files changed, 18 insertions, 0 deletions
diff --git a/statsd/client.py b/statsd/client.py index e88d23a..9d34bed 100644 --- a/statsd/client.py +++ b/statsd/client.py @@ -78,6 +78,12 @@ class StatsClient(object): if data is not None: self._after(data) + def set(self, stat, value, rate=1): + """Set a set value.""" + data = self._prepare(stat, '%s|s' % value, rate) + if data is not None: + self._after(data) + def _prepare(self, stat, value, rate=1): if rate < 1: if random.random() < rate: diff --git a/statsd/tests.py b/statsd/tests.py index 59e8f24..fb9a882 100644 --- a/statsd/tests.py +++ b/statsd/tests.py @@ -146,6 +146,18 @@ def test_gauge_delta(): _sock_check(sc, 4, 'foo:-1.3|g') +def test_set(): + sc = _client() + sc.set('foo', 10) + _sock_check(sc, 1, 'foo:10|s') + + sc.set('foo', 2.3) + _sock_check(sc, 2, 'foo:2.3|s') + + sc.set('foo', 2.3, 0.5) + _sock_check(sc, 3, 'foo:2.3|s|@0.5') + + @mock.patch.object(random, 'random', lambda: -1) def test_timing(): sc = _client() |