8000 helpful error message when multiprocessing dir env is unset (#206) · sonlinux/client_python@7249378 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7249378

Browse files
dbalanbrian-brazil
authored andcommitted
helpful error message when multiprocessing dir env is unset (prometheus#206)
On head it fails with: ERROR in app: Exception on /metrics [GET] AttributeError: 'NoneType' object has no attribute 'endswith' With this change: File "build/bdist.linux-x86_64/egg/prometheus_client/multiprocess.py", line 16, in __init__ raise ValueError('env prometheus_multiproc_dir is not set or not accessible') ValueError: env prometheus_multiproc_dir is not set or not accessible
1 parent 6625f89 commit 7249378

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

prometheus_client/multiprocess.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
class MultiProcessCollector(object):
1313
"""Collector for files for multi-process mode."""
1414
def __init__(self, registry, path=os.environ.get('prometheus_multiproc_dir')):
15+
if not path or not os.path.isdir(path):
16+
raise ValueError('env prometheus_multiproc_dir is not set or not a directory')
1517
self._path = path
1618
if registry:
1719
registry.register(self)

tests/test_multiprocess.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,28 @@ def test_multi_expansion(self):
158158

159159
def tearDown(self):
160160
os.unlink(self.tempfile)
161+
162+
class TestUnsetEnv(unittest.TestCase):
163+
def setUp(self):
164+
self.registry = CollectorRegistry()
165+
fp, self.tmpfl = tempfile.mkstemp()
166+
os.close(fp)
167+
168+
def test_unset_syncdir_env(self):
169+
self.assertRaises(
170+
ValueError,
171+
MultiProcessCollector,
172+
self.registry
173+
)
174+
175+
def test_file_syncpath(self):
176+
registry = CollectorRegistry()
177+
self.assertRaises(
178+
ValueError,
179+
MultiProcessCollector,
180+
registry,
181+
self.tmpfl
182+
)
183+
184+
def tearDown(self):
185+
os.remove(self.tmpfl)

0 commit comments

Comments
 (0)
0