Fix a mistake with allowing reuse of name in @timed()

pull/142/head
Mike Lang 5 years ago
parent 1ef15780df
commit 4d5157cdb5

@ -91,8 +91,8 @@ def timed(name=None,
# can't safely assign to name inside closure, we use a new _name variable instead # can't safely assign to name inside closure, we use a new _name variable instead
_name = fn.__name__ if name is None else name _name = fn.__name__ if name is None else name
if name in metrics: if _name in metrics:
latency, cputime = metrics[name] latency, cputime = metrics[_name]
else: else:
latency = prom.Histogram( latency = prom.Histogram(
"{}_latency".format(_name), "{}_latency".format(_name),
@ -106,9 +106,9 @@ def timed(name=None,
labels.keys() + ['error', 'type'], labels.keys() + ['error', 'type'],
buckets=buckets, buckets=buckets,
) )
metrics[name] = latency, cputime metrics[_name] = latency, cputime
if normalize: if normalize:
normname = '{} normalized'.format(name) normname = '{} normalized'.format(_name)
if normname in metrics: if normname in metrics:
normal_latency, normal_cputime = metrics[normname] normal_latency, normal_cputime = metrics[normname]
else: else:

Loading…
Cancel
Save