Skip to content

Timing is expected in ms, but timing_since sends μs. #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pystatsd/statsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ def __init__(self, host='localhost', port=8125, prefix=None):

def timing_since(self, stat, start, sample_rate=1):
"""
Log timing information as the number of microseconds since the provided time float
Log timing information as the number of milliseconds since the provided time float
>>> start = time.time()
>>> # do stuff
>>> statsd_client.timing_since('some.time', start)
"""
self.timing(stat, int((time.time() - start) * 1000000), sample_rate)
self.timing(stat, (time.time() - start) * 1000, sample_rate)

def timing(self, stat, time, sample_rate=1):
"""
Log timing information for a single stat
Log timing information for a single stat, in milliseconds
>>> statsd_client.timing('some.time',500)
"""
stats = {stat: "%f|ms" % time}
Expand Down
11 changes: 5 additions & 6 deletions tests/client.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,15 @@ def test_basic_client_timing(self):
bytes(stat_str, 'utf-8'), self.addr)

def test_basic_client_timing_since(self):
ts = (1971, 6, 29, 4, 13, 0, 0, 0, -1)
now = time.mktime(ts)
# add 5 seconds
ts = (1971, 6, 29, 4, 13, 5, 0, 0, -1)
then = time.mktime(ts)
# arbitrary start timestamp value
now = 1000.00
# five and a half seconds later
then = now + 5.5
mock_time_patcher = mock.patch('time.time', return_value=now)
mock_time_patcher.start()

stat = 'pystatsd.unittests.test_basic_client_timing_since.time'
stat_str = stat + ':-5000000.000000|ms'
stat_str = stat + ':-5500.000000|ms'

self.client.timing_since(stat, then)

Expand Down