Skip to content

Commit

Permalink
Merge pull request #658 from prometheus/beorn7/doc
Browse files Browse the repository at this point in the history
Document implications of negative observations
  • Loading branch information
csmarchbanks committed May 28, 2021
2 parents 9118c02 + 13f786a commit e18828f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions prometheus_client/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,15 @@ def _metric_init(self):
self._created = time.time()

def observe(self, amount):
"""Observe the given amount."""
"""Observe the given amount.
The amount is usually positive or zero. Negative values are
accepted but prevent current versions of Prometheus from
properly detecting counter resets in the sum of
observations. See
https://prometheus.io/docs/practices/histograms/#count-and-sum-of-observations
for details.
"""
self._count.inc(1)
self._sum.inc(amount)

Expand Down Expand Up @@ -550,7 +558,15 @@ def _metric_init(self):
)

def observe(self, amount):
"""Observe the given amount."""
"""Observe the given amount.
The amount is usually positive or zero. Negative values are
accepted but prevent current versions of Prometheus from
properly detecting counter resets in the sum of
observations. See
https://prometheus.io/docs/practices/histograms/#count-and-sum-of-observations
for details.
"""
self._sum.inc(amount)
for i, bound in enumerate(self._upper_bounds):
if amount <= bound:
Expand Down

0 comments on commit e18828f

Please sign in to comment.