diff --git a/prometheus_client/metrics.py b/prometheus_client/metrics.py index ef2e23fa..24f323d5 100644 --- a/prometheus_client/metrics.py +++ b/prometheus_client/metrics.py @@ -63,10 +63,7 @@ def _raise_if_not_observable(self): # a counter, will fail if the metric is not observable, because only if a # metric is observable will the value be initialized. if not self._is_observable(): - raise ValueError( - '%s metric is not observable. This is likely because the metric requires ' - 'that labels be applied before performing the operation' % str(self._type) - ) + raise ValueError('%s metric is missing label values' % str(self._type)) def _is_parent(self): return self._labelnames and not self._labelvalues @@ -249,11 +246,8 @@ def _metric_init(self): def inc(self, amount=1): """Increment counter by the given amount.""" - self._raise_if_not_observable() - if amount < 0: raise ValueError('Counters can only be incremented by non-negative amounts.') - self._value.inc(amount) def count_exceptions(self, exception=Exception): diff --git a/tests/test_core.py b/tests/test_core.py index 6fe290e1..0b6c39a4 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -76,15 +76,7 @@ def test_count_exceptions_not_observable(self): try: counter.count_exceptions() except ValueError as e: - self.assertIn('metric is not observable', str(e)) - - def test_inc_not_observable(self): - counter = Counter('counter', 'help', labelnames=('label',), registry=self.registry) - - try: - counter.count_exceptions() - except ValueError as e: - self.assertIn('metric is not observable', str(e)) + self.assertIn('missing label values', str(e)) class TestGauge(unittest.TestCase):