stats: Round timings at 4 decimal places

It seems unreasonable to expect timings to be accurate to sub-100ns
resolution.

Why 4 places? We already had some tests for proxy-logging that would
assertAlmostEqual to that many places.

Change-Id: Ic7a0c4a416a46eb5198d7cce103358d677ec94ab
This commit is contained in:
Tim Burke 2023-10-12 14:02:39 -07:00 committed by Tim Burke
parent 002ad59c9e
commit 20ff642154
2 changed files with 5 additions and 1 deletions

View File

@ -1499,7 +1499,7 @@ class StatsdClient(object):
def _timing(self, metric, timing_ms, sample_rate):
# This method was added to disagregate timing metrics when testing
return self._send(metric, timing_ms, 'ms', sample_rate)
return self._send(metric, round(timing_ms, 4), 'ms', sample_rate)
def timing(self, metric, timing_ms, sample_rate=None):
return self._timing(metric, timing_ms, sample_rate)

View File

@ -5516,6 +5516,10 @@ class TestStatsdLoggingDelegation(unittest.TestCase):
self.assertStat('pfx.some.operation:4900.0|ms|@0.972',
self.logger.timing, 'some.operation', 4.9 * 1000,
sample_rate=0.972)
self.assertStat(
'pfx.some.hi-res.operation:3141.5927|ms|@0.367879441171',
self.logger.timing, 'some.hi-res.operation',
3.141592653589793 * 1000, sample_rate=0.367879441171)
self.assertStatMatches(r'pfx\.another\.op:\d+\.\d+\|ms|@0.972',
self.logger.timing_since, 'another.op',
time.time(), sample_rate=0.972)