Skip to content

Commit 56bd577

Browse files
author
Daniel Magliola
authored
Merge pull request #176 from ganmacs/fix-bug-histgram-range
observed value should be stored the bucket
2 parents d5db795 + c931a04 commit 56bd577

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/prometheus/client/histogram.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def type
4747
end
4848

4949
def observe(value, labels: {})
50-
bucket = buckets.find {|upper_limit| upper_limit > value }
50+
bucket = buckets.find {|upper_limit| upper_limit >= value }
5151
bucket = "+Inf" if bucket.nil?
5252

5353
base_label_set = label_set_for(labels)

spec/prometheus/client/histogram_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,12 @@
140140
it 'returns a hash of all recorded summaries' do
141141
histogram.observe(3, labels: { status: 'bar' })
142142
histogram.observe(6, labels: { status: 'foo' })
143+
histogram.observe(10, labels: { status: 'baz' })
143144

144145
expect(histogram.values).to eql(
145146
{ status: 'bar' } => { "2.5" => 0.0, "5" => 1.0, "10" => 1.0, "+Inf" => 1.0, "sum" => 3.0 },
146147
{ status: 'foo' } => { "2.5" => 0.0, "5" => 0.0, "10" => 1.0, "+Inf" => 1.0, "sum" => 6.0 },
148+
{ status: 'baz' } => { "2.5" => 0.0, "5" => 0.0, "10" => 1.0, "+Inf" => 1.0, "sum" => 10.0 },
147149
)
148150
end
149151
end

0 commit comments

Comments
 (0)