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
This commit is contained in:
Tim Burke 2024-09-04 12:34:57 -07:00
parent 015cbaac86
commit d405465b32

View File

@ -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)))