8000 Document implications of negative observations · lvillis/client_python@13f786a · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 13f786a

Browse files
committed
Document implications of negative observations
Fixes prometheus#638. It's of course weird to talk abou negative values of an "amount". However, for the Gauge, which quite regularly will receive negative increments, the word "amount" is used, too, so I didn't want to change it everywhere to "value" or something. AFAIK the only place where negative values are rejected is indeed the Counter. Signed-off-by: beorn7 <beorn@grafana.com>
1 parent 9118c02 commit 13f786a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

prometheus_client/metrics.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,15 @@ def _metric_init(self):
441441
self._created = time.time()
442442

443443
def observe(self, amount):
444-
"""Observe the given amount."""
444+
"""Observe the given amount.
445+
446+
The amount is usually positive or zero. Negative values are
447+
accepted but prevent current versions of Prometheus from
448+
properly detecting counter resets in the sum of
449+
observations. See
450+
https://prometheus.io/docs/practices/histograms/#count-and-sum-of-observations
451+
for details.
452+
"""
445453
self._count.inc(1)
446454
self._sum.inc(amount)
447455

@@ -550,7 +558,15 @@ def _metric_init(self):
550558
)
551559

552560
def observe(self, amount):
553-
"""Observe the given amount."""
561+
"""Observe the given amount.
562+
563+
The amount is usually positive or zero. Negative values are
564+
accepted but prevent current versions of Prometheus from
565+
properly detecting counter resets in the sum of
566+
observations. See
567+
https://prometheus.io/docs/practices/histograms/#count-and-sum-of-observations
568+
for details.
569+
"""
554570
self._sum.inc(amount)
555571
for i, bound in enumerate(self._upper_bounds):
556572
if amount <= bound:

0 commit comments

Comments
 (0)
0