Skip to content

Commit

Permalink
fix wording and take out of inc function
Browse files Browse the repository at this point in the history
Signed-off-by: AlexPadron <alexp@kensho.com>
  • Loading branch information
a-padron committed Aug 19, 2019
1 parent 38cd675 commit 09c7835
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
8 changes: 1 addition & 7 deletions prometheus_client/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 1 addition & 9 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 09c7835

Please sign in to comment.