Skip to content

Commit 770b6a9

Browse files
committed
Add sanity check for label value
Signed-off-by: Pengfei Zhang <andysim3d@gmail.com>
1 parent 7a80f00 commit 770b6a9

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ dist
77
.coverage
88
.tox
99
.*cache
10-
htmlcov
10+
htmlcov
11+
.vs/

prometheus_client/metrics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,8 @@ def info(self, val: Dict[str, str]) -> None:
706706
raise ValueError('Overlapping labels for Info metric, metric: {} child: {}'.format(
707707
self._labelnames, val))
708708
with self._lock:
709+
if any( i is None for i in val.values() ):
710+
raise ValueError('Label value cannot be None')
709711
self._value = dict(val)
710712

711713
def _child_samples(self) -> Iterable[Sample]:

tests/test_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ def test_info(self):
534534

535535
def test_labels(self):
536536
self.assertRaises(ValueError, self.labels.labels('a').info, {'l': ''})
537+
self.assertRaises(ValueError, self.labels.labels('a').info, {'il': None})
537538

538539
self.labels.labels('a').info({'foo': 'bar'})
539540
self.assertEqual(1, self.registry.get_sample_value('il_info', {'l': 'a', 'foo': 'bar'}))

0 commit comments

Comments
 (0)