8000 Reduce unnecessary metric creation in loop (#256) · sonlinux/client_python@e2a5061 · GitHub
[go: up one dir, main page]

Skip to content

Commit e2a5061

Browse files
umaxbrian-brazil
authored andcommitted
Reduce unnecessary metric creation in loop (prometheus#256)
1 parent 55f1055 commit e2a5061

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

prometheus_client/multiprocess.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ def collect(self):
2828
d = core._MmapedDict(f)
2929
for key, value in d.read_all_values():
3030
metric_name, name, labelnames, labelvalues = json.loads(key)
31-
metrics.setdefault(metric_name, core.Metric(metric_name, 'Multiprocess metric', typ))
32-
metric = metrics[metric_name]
31+
32+
metric = metrics.get(metric_name)
33+
if metric is None:
34+
metric = core.Metric(metric_name, 'Multiprocess metric', typ)
35+
metrics[metric_name] = metric
36+
3337
if typ == 'gauge':
3438
pid = parts[2][:-3]
3539
metric._multiprocess_mode = parts[1]

0 commit comments

Comments
 (0)
0