Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiProcessCollector.collect() crashing on missing files #425

Closed
xavfernandez opened this issue Jun 13, 2019 · 0 comments · Fixed by #424
Closed

MultiProcessCollector.collect() crashing on missing files #425

xavfernandez opened this issue Jun 13, 2019 · 0 comments · Fixed by #424

Comments

@xavfernandez
Copy link
Contributor

Hello,

When you've used a lot of pids and have a lot of metrics files lying around, there is a high probability that mark_process_dead

def mark_process_dead(pid, path=None):
"""Do bookkeeping for when one process dies in a multi-process setup."""
if path is None:
path = os.environ.get('prometheus_multiproc_dir')
for f in glob.glob(os.path.join(path, 'gauge_livesum_{0}.db'.format(pid))):
os.remove(f)
for f in glob.glob(os.path.join(path, 'gauge_liveall_{0}.db'.format(pid))):
os.remove(f)

will be called between the glob.glob call and the self.merge one:
files = glob.glob(os.path.join(self._path, '*.db'))
return self.merge(files, accumulate=True)

leading to:

$ prometheus_multiproc_dir=/tmp/prometheus_metrics python
Python 3.7.3 (default, May  8 2019, 05:31:59)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from prometheus_client import multiprocess
>>> from prometheus_client import generate_latest, CollectorRegistry
>>> registry = CollectorRegistry()
>>> multiprocess.MultiProcessCollector(registry)
<prometheus_client.multiprocess.MultiProcessCollector object at 0x7ffb0b1efa58>
>>> data = generate_latest(registry)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/home/grocker/app.venv/lib/python3.7/site-packages/prometheus_client/exposition.py", line 89, in generate_latest
   for metric in registry.collect():
 File "/home/grocker/app.venv/lib/python3.7/site-packages/prometheus_client/registry.py", line 75, in collect
   for metric in collector.collect():
 File "/home/grocker/app.venv/lib/python3.7/site-packages/prometheus_client/multiprocess.py", line 30, in collect
   return self.merge(files, accumulate=True)
 File "/home/grocker/app.venv/lib/python3.7/site-packages/prometheus_client/multiprocess.py", line 43, in merge
   d = MmapedDict(f, read_mode=True)
 File "/home/grocker/app.venv/lib/python3.7/site-packages/prometheus_client/mmap_dict.py", line 39, in __init__
   self._f = open(filename, 'rb' if read_mode else 'a+b')
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/prometheus_metrics/gauge_livesum_37367.db'

An easy fix could be #424.

xavfernandez added a commit to Polyconseil/client_python that referenced this issue Jun 18, 2019
Fixes prometheus#425

Signed-off-by: Xavier Fernandez <xavier.fernandez@polyconseil.fr>
brian-brazil pushed a commit that referenced this issue Jun 18, 2019
Fixes #425

Signed-off-by: Xavier Fernandez <xavier.fernandez@polyconseil.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant