Skip to content

Commit

Permalink
Add sanity check for label value
Browse files Browse the repository at this point in the history
Signed-off-by: Pengfei Zhang <andysim3d@gmail.com>
  • Loading branch information
andysim3d committed Mar 3, 2024
1 parent 7a80f00 commit b226e4d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ dist
.coverage
.tox
.*cache
htmlcov
htmlcov
.vs/
2 changes: 2 additions & 0 deletions prometheus_client/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@ def info(self, val: Dict[str, str]) -> None:
raise ValueError('Overlapping labels for Info metric, metric: {} child: {}'.format(
self._labelnames, val))
with self._lock:
if any(i is None for i in val.values()):
raise ValueError('Label value cannot be None')
self._value = dict(val)

def _child_samples(self) -> Iterable[Sample]:
Expand Down
1 change: 1 addition & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ def test_info(self):

def test_labels(self):
self.assertRaises(ValueError, self.labels.labels('a').info, {'l': ''})
self.assertRaises(ValueError, self.labels.labels('a').info, {'il': None})

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

0 comments on commit b226e4d

Please sign in to comment.