diff --git a/swift/common/middleware/proxy_logging.py b/swift/common/middleware/proxy_logging.py index 6bdaa9ca39..90eb2f7ab8 100644 --- a/swift/common/middleware/proxy_logging.py +++ b/swift/common/middleware/proxy_logging.py @@ -356,7 +356,7 @@ class ProxyLoggingMiddleware(object): except IndexError: stat_type = 'object' else: - stat_type = req.environ.get('swift.source') + stat_type = req.environ.get('swift.source') or 'UNKNOWN' return stat_type def statsd_metric_name(self, req, status_int, method): diff --git a/test/unit/common/middleware/test_proxy_logging.py b/test/unit/common/middleware/test_proxy_logging.py index 2a98fe6699..598e2eb999 100644 --- a/test/unit/common/middleware/test_proxy_logging.py +++ b/test/unit/common/middleware/test_proxy_logging.py @@ -454,8 +454,9 @@ class TestProxyLogging(unittest.TestCase): self.assertEqual(log_parts[4], '/path') self.assertEqual(log_parts[5], 'HTTP/1.0') self.assertEqual(log_parts[6], '503') - # but we don't get metrics!? - self.assertFalse(app.access_logger.statsd_client.calls) + # we can also expect error metrics + self.assertTiming('UNKNOWN.GET.503.timing', app, + exp_timing=700.0) def test_middleware_exception(self): self.logger = debug_logger() @@ -473,8 +474,9 @@ class TestProxyLogging(unittest.TestCase): self.assertEqual(log_parts[4], '/path') self.assertEqual(log_parts[5], 'HTTP/1.0') self.assertEqual(log_parts[6], '500') - # but we don't get metrics!? - self.assertFalse(app.access_logger.statsd_client.calls) + # we can also expect error metrics + self.assertTiming('UNKNOWN.GET.500.timing', app, + exp_timing=200.0) def test_middleware_error(self): class ErrorFakeApp(object):