Skip to content

Commit

Permalink
Merge pull request #226 from prometheus/beorn7/doc
Browse files Browse the repository at this point in the history
Document implications of negative observations
  • Loading branch information
Sinjo committed Jun 1, 2021
2 parents f4ce120 + 5c67aa6 commit 9c79b94
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/prometheus/client/histogram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Prometheus
module Client
# A histogram samples observations (usually things like request durations
# or response sizes) and counts them in configurable buckets. It also
# provides a sum of all observed values.
# provides a total count and sum of all observed values.
class Histogram < Metric
# DEFAULT_BUCKETS are the default Histogram buckets. The default buckets
# are tailored to broadly measure the response time (in seconds) of a
Expand Down Expand Up @@ -54,6 +54,12 @@ def type
:histogram
end

# Records a given value. The recorded value is usually positive
# or zero. A negative value is accepted but prevents 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.
def observe(value, labels: {})
bucket = buckets.find {|upper_limit| upper_limit >= value }
bucket = "+Inf" if bucket.nil?
Expand Down
7 changes: 6 additions & 1 deletion lib/prometheus/client/summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ def type
:summary
end

# Records a given value.
# Records a given value. The recorded value is usually positive
# or zero. A negative value is accepted but prevents 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.
def observe(value, labels: {})
base_label_set = label_set_for(labels)

Expand Down

0 comments on commit 9c79b94

Please sign in to comment.