proxy-logging: Clean up some timing assertions

Related-Change: I526bbcc59c9eb5923c3784d5d06bc38998cb48db
Change-Id: I820339934f895557ebcde4bb32168b0cfc494948
This commit is contained in:
Tim Burke 2024-09-05 13:31:03 -07:00
parent 99e1c019b5
commit 7be25604db

View File

@ -286,23 +286,46 @@ class TestProxyLogging(unittest.TestCase):
app = proxy_logging.ProxyLoggingMiddleware(
FakeApp(), {}, logger=self.logger)
for url in ['/', '/foo', '/foo/bar', '/v1', '/v1.0']:
self.logger.clear()
req = Request.blank(url, environ={'REQUEST_METHOD': 'GET'})
resp = app(req.environ, start_response)
# get body
b''.join(resp)
self.assertEqual([], app.access_logger.log_dict['timing'])
self.assertEqual([], app.access_logger.log_dict['update_stats'])
self.assertEqual(
[(('UNKNOWN.GET.200.first-byte.timing', mock.ANY), {}),
(('UNKNOWN.GET.200.timing', mock.ANY), {})],
app.access_logger.statsd_client.calls['timing'])
self.assertEqual(
[(('UNKNOWN.GET.200.xfer', mock.ANY), {})],
app.access_logger.statsd_client.calls['update_stats'])
def test_log_request_stat_type_bad(self):
for bad_path in ['', '/', '/bad', '/baddy/mc_badderson', '/v1',
'/v1/', '/v1.0', '/v1.0/']:
app = proxy_logging.ProxyLoggingMiddleware(
FakeApp(), {}, logger=self.logger)
app = proxy_logging.ProxyLoggingMiddleware(
FakeApp(), {}, logger=self.logger)
for bad_path, prefix in [
('', 'UNKNOWN'),
('/', 'UNKNOWN'),
('/bad', 'UNKNOWN'),
('/baddy/mc_badderson', 'UNKNOWN'),
('/v1', 'UNKNOWN'),
('/v1/', 'UNKNOWN'),
('/v1.0', 'UNKNOWN'),
('/v1.0/', 'UNKNOWN'),
('/v1.0//', 'UNKNOWN'),
('/v1.0//c', 'UNKNOWN'),
('/v1.0/a//', 'account'),
('/v1.0/a//o', 'object'),
]:
req = Request.blank(bad_path, environ={'REQUEST_METHOD': 'GET'})
now = 10000.0
app.log_request(req, 123, 7, 13, now, now + 2.71828182846)
self.assertEqual([], app.access_logger.log_dict['timing'])
self.assertEqual([], app.access_logger.log_dict['update_stats'])
self.assertEqual(
[((prefix + '.GET.123.timing', 2718.2818284600216), {})],
app.access_logger.statsd_client.calls['timing'])
self.assertEqual(
[((prefix + '.GET.123.xfer', 20), {})],
app.access_logger.statsd_client.calls['update_stats'])
app.access_logger.clear()
def test_log_request_stat_type_good(self):
"""
@ -405,11 +428,12 @@ class TestProxyLogging(unittest.TestCase):
stub_times = [18.0, 20.71828182846]
iter_response = app(req.environ, lambda *_: None)
self.assertEqual(b'7654321', b''.join(iter_response))
self.assertEqual([], app.access_logger.log_dict['timing'])
self.assertEqual([],
app.access_logger.log_dict['timing_since'])
self.assertEqual([],
app.access_logger.log_dict['update_stats'])
self.assertEqual(
[], app.access_logger.statsd_client.calls['timing'])
self.assertEqual(
[], app.access_logger.statsd_client.calls['timing_since'])
self.assertEqual(
[], app.access_logger.statsd_client.calls['update_stats'])
# PUT (no first-byte timing!)
self.logger.clear()