Skip to content

Commit

Permalink
Use binary search for histogram buckets
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Ilchenko <[email protected]>
  • Loading branch information
simpl1g committed Nov 3, 2024
1 parent 5514b2b commit 100f46c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/prometheus/client/histogram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def type
# 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 = buckets.bsearch { |upper_limit| upper_limit >= value }
bucket = "+Inf" if bucket.nil?

base_label_set = label_set_for(labels)
Expand Down

0 comments on commit 100f46c

Please sign in to comment.