Skip to content

Commit

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

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 4535ce0

Please sign in to comment.