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

mark_process_dead: avoid error with bad env #768

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions prometheus_client/multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ 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', os.environ.get('prometheus_multiproc_dir'))

if path is None:
# Avoid error when environment is not correctly set-up
return

for f in glob.glob(os.path.join(path, f'gauge_livesum_{pid}.db')):
os.remove(f)
for f in glob.glob(os.path.join(path, f'gauge_liveall_{pid}.db')):
Expand Down
7 changes: 6 additions & 1 deletion tests/test_multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _value_class(self):
return

def tearDown(self):
del os.environ['PROMETHEUS_MULTIPROC_DIR']
os.environ.pop('PROMETHEUS_MULTIPROC_DIR', None)
shutil.rmtree(self.tempdir)
values.ValueClass = MutexValue

Expand Down Expand Up @@ -303,6 +303,11 @@ def test_missing_gauge_file_during_merge(self):
os.path.join(self.tempdir, 'gauge_livesum_9999999.db'),
]))

def test_mark_dead_no_env(self):
del os.environ['PROMETHEUS_MULTIPROC_DIR']

mark_process_dead(123)


class TestMmapedDict(unittest.TestCase):
def setUp(self):
Expand Down