From 20ff6421546f9d16ae06068849c03e7e98ca6a07 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Thu, 12 Oct 2023 14:02:39 -0700 Subject: [PATCH] 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 --- swift/common/utils/__init__.py | 2 +- test/unit/common/test_utils.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/swift/common/utils/__init__.py b/swift/common/utils/__init__.py index c4b5e43d9c..6af137bb2e 100644 --- a/swift/common/utils/__init__.py +++ b/swift/common/utils/__init__.py @@ -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) diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py index 8513ba69e8..0d022ab150 100644 --- a/test/unit/common/test_utils.py +++ b/test/unit/common/test_utils.py @@ -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)