Skip to content

Commit

Permalink
Raise exception when logging to non-observable Enum (prometheus#501)
Browse files Browse the repository at this point in the history
Signed-off-by: jxpp <jxpp@chigui.re>
  • Loading branch information
jxpp committed Feb 29, 2020
1 parent 56a8a53 commit 27fbe5f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions prometheus_client/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ def _metric_init(self):

def state(self, state):
"""Set enum metric state."""
self._raise_if_not_observable()
with self._lock:
self._value = self._states.index(state)

Expand Down
1 change: 1 addition & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ def test_labels(self):
self.assertEqual(0, self.registry.get_sample_value('el', {'l': 'a', 'el': 'a'}))
self.assertEqual(0, self.registry.get_sample_value('el', {'l': 'a', 'el': 'b'}))
self.assertEqual(1, self.registry.get_sample_value('el', {'l': 'a', 'el': 'c'}))
self.assertRaises(ValueError, self.labels.state, 'a')

def test_overlapping_labels(self):
with pytest.raises(ValueError):
Expand Down

0 comments on commit 27fbe5f

Please sign in to comment.