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:
parent
015cbaac86
commit
d405465b32
@ -353,26 +353,22 @@ class ProxyLoggingMiddleware(object):
|
|||||||
if not valid_api_version(version):
|
if not valid_api_version(version):
|
||||||
raise ValueError
|
raise ValueError
|
||||||
except ValueError:
|
except ValueError:
|
||||||
version, acc, cont, obj = None, None, None, None
|
acc, cont, obj = None, None, None
|
||||||
return acc, cont, obj
|
return acc, cont, obj
|
||||||
|
|
||||||
def get_metric_name_type(self, req):
|
def get_metric_name_type(self, req):
|
||||||
swift_path = req.environ.get('swift.backend_path', req.path)
|
swift_path = req.environ.get('swift.backend_path', req.path)
|
||||||
acc, cont, obj = self.get_aco_from_path(swift_path)
|
acc, cont, obj = self.get_aco_from_path(swift_path)
|
||||||
|
if obj:
|
||||||
|
return 'object'
|
||||||
|
if cont:
|
||||||
|
return 'container'
|
||||||
if acc:
|
if acc:
|
||||||
try:
|
return 'account'
|
||||||
stat_type = [None, 'account', 'container',
|
return req.environ.get('swift.source') or 'UNKNOWN'
|
||||||
'object'][swift_path.strip('/').count('/')]
|
|
||||||
except IndexError:
|
|
||||||
stat_type = 'object'
|
|
||||||
else:
|
|
||||||
stat_type = req.environ.get('swift.source') or 'UNKNOWN'
|
|
||||||
return stat_type
|
|
||||||
|
|
||||||
def statsd_metric_name(self, req, status_int, method):
|
def statsd_metric_name(self, req, status_int, method):
|
||||||
stat_type = self.get_metric_name_type(req)
|
stat_type = self.get_metric_name_type(req)
|
||||||
if stat_type is None:
|
|
||||||
return None
|
|
||||||
stat_method = method if method in self.valid_methods \
|
stat_method = method if method in self.valid_methods \
|
||||||
else 'BAD_METHOD'
|
else 'BAD_METHOD'
|
||||||
return '.'.join((stat_type, stat_method, str(status_int)))
|
return '.'.join((stat_type, stat_method, str(status_int)))
|
||||||
|
Loading…
Reference in New Issue
Block a user