Skip to content

Commit

Permalink
mark_process_dead respects old env var
Browse files Browse the repository at this point in the history
Some users use mark_process_dead without going through any of the
__init__() logic which sets the new environment variable.

Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
  • Loading branch information
csmarchbanks committed Apr 7, 2021
1 parent 7bbf86f commit 1d68ee7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion prometheus_client/multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def collect(self):
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')
path = os.environ.get('PROMETHEUS_MULTIPROC_DIR', 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))):
Expand Down
8 changes: 6 additions & 2 deletions tests/test_multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def setUp(self):
self.tempdir = tempfile.mkdtemp()

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

Expand All @@ -48,6 +48,10 @@ def test_deprecation_warning(self):
assert issubclass(w[-1].category, DeprecationWarning)
assert "PROMETHEUS_MULTIPROC_DIR" in str(w[-1].message)

def test_mark_process_dead_respects_lowercase(self):
os.environ['prometheus_multiproc_dir'] = self.tempdir
mark_process_dead(123)


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

0 comments on commit 1d68ee7

Please sign in to comment.