Skip to content

Commit 09c7835

Browse files
committed
fix wording and take out of inc function
Signed-off-by: AlexPadron <alexp@kensho.com>
1 parent 38cd675 commit 09c7835

File tree

2 files changed

+2
-16
lines changed

2 files changed

+2
-16
lines changed

prometheus_client/metrics.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ def _raise_if_not_observable(self):
6363
# a counter, will fail if the metric is not observable, because only if a
6464
# metric is observable will the value be initialized.
6565
if not self._is_observable():
66-
raise ValueError(
67-
'%s metric is not observable. This is likely because the metric requires '
68-
'that labels be applied before performing the operation' % str(self._type)
69-
)
66+
raise ValueError('%s metric is missing label values' % str(self._type))
7067

7168
def _is_parent(self):
7269
return self._labelnames and not self._labelvalues
@@ -249,11 +246,8 @@ def _metric_init(self):
249246

250247
def inc(self, amount=1):
251248
"""Increment counter by the given amount."""
252-
self._raise_if_not_observable()
253-
254249
if amount < 0:
255250
raise ValueError('Counters can only be incremented by non-negative amounts.')
256-
257251
self._value.inc(amount)
258252

259253
def count_exceptions(self, exception=Exception):

tests/test_core.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,7 @@ def test_count_exceptions_not_observable(self):
7676
try:
7777
counter.count_exceptions()
7878
except ValueError as e:
79-
self.assertIn('metric is not observable', str(e))
80-
81-
def test_inc_not_observable(self):
82-
counter = Counter('counter', 'help', labelnames=('label',), registry=self.registry)
83-
84-
try:
85-
counter.count_exceptions()
86-
except ValueError as e:
87-
self.assertIn('metric is not observable', str(e))
79+
self.assertIn('missing label values', str(e))
8880

8981

9082
class TestGauge(unittest.TestCase):

0 commit comments

Comments
 (0)