From d405465b32a58376764dd4b0e3d7d32f2540b44e Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Wed, 4 Sep 2024 12:34:57 -0700 Subject: [PATCH] trivial: Use already-parsed a/c/o We don't need to go counting slashes or catching IndexErrors; we've already done all the path-parsing we need to do. This also makes it clear that stat_type can never be None. Change-Id: I25f91b1943b91c7429219c3b5a4280abe9bef5b3 --- swift/common/middleware/proxy_logging.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/swift/common/middleware/proxy_logging.py b/swift/common/middleware/proxy_logging.py index 5618c6535a..330adb7624 100644 --- a/swift/common/middleware/proxy_logging.py +++ b/swift/common/middleware/proxy_logging.py @@ -353,26 +353,22 @@ class ProxyLoggingMiddleware(object): if not valid_api_version(version): raise ValueError except ValueError: - version, acc, cont, obj = None, None, None, None + acc, cont, obj = None, None, None return acc, cont, obj def get_metric_name_type(self, req): swift_path = req.environ.get('swift.backend_path', req.path) acc, cont, obj = self.get_aco_from_path(swift_path) + if obj: + return 'object' + if cont: + return 'container' if acc: - try: - stat_type = [None, 'account', 'container', - 'object'][swift_path.strip('/').count('/')] - except IndexError: - stat_type = 'object' - else: - stat_type = req.environ.get('swift.source') or 'UNKNOWN' - return stat_type + return 'account' + return req.environ.get('swift.source') or 'UNKNOWN' def statsd_metric_name(self, req, status_int, method): stat_type = self.get_metric_name_type(req) - if stat_type is None: - return None stat_method = method if method in self.valid_methods \ else 'BAD_METHOD' return '.'.join((stat_type, stat_method, str(status_int)))