8000 helpful error message when multiprocessing dir env is unset by dbalan · Pull Request #206 · prometheus/client_python · GitHub
[go: up one dir, main page]

Skip to content

helpful error message when multiprocessing dir env is unset #206

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

Merged
merged 3 commits into from
Oct 26, 2017
Merged
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
2 changes: 2 additions & 0 deletions prometheus_client/multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
class MultiProcessCollector(object):
"""Collector for files for multi-process mode."""
def __init__(self, registry, path=os.environ.get('prometheus_multiproc_dir')):
if not path or not os.path.isdir(path):
raise ValueError('env prometheus_multiproc_dir is not set or not a directory')
self._path = path
if registry:
registry.register(self)
Expand Down
25 changes: 25 additions & 0 deletions tests/test_multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,28 @@ def test_multi_expansion(self):

def tearDown(self):
os.unlink(self.tempfile)

class TestUnsetEnv(unittest.TestCase):
def setUp(self):
self.registry = CollectorRegistry()
fp, self.tmpfl = tempfile.mkstemp()
os.close(fp)

def test_unset_syncdir_env(self):
self.assertRaises(
ValueError,
MultiProcessCollector,
self.registry
)

def test_file_syncpath(self):
registry = CollectorRegistry()
self.assertRaises(
ValueError,
MultiProcessCollector,
registry,
self.tmpfl
)

def tearDown(self):
os.remove(self.tmpfl)
0