Skip to content

Commit

Permalink
observed value should be stored the bucket
Browse files Browse the repository at this point in the history
whose value is same as the observed value
  • Loading branch information
ganmacs committed Jan 8, 2020
1 parent 7129453 commit 7550f3b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions 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 @@ -47,7 +47,7 @@ def type
end

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

base_label_set = label_set_for(labels)
Expand Down
2 changes: 2 additions & 0 deletions spec/prometheus/client/histogram_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@
it 'returns a hash of all recorded summaries' do
histogram.observe(3, labels: { status: 'bar' })
histogram.observe(6, labels: { status: 'foo' })
histogram.observe(10, labels: { status: 'baz' })

expect(histogram.values).to eql(
{ status: 'bar' } => { "2.5" => 0.0, "5" => 1.0, "10" => 1.0, "+Inf" => 1.0, "sum" => 3.0 },
{ status: 'foo' } => { "2.5" => 0.0, "5" => 0.0, "10" => 1.0, "+Inf" => 1.0, "sum" => 6.0 },
{ status: 'baz' } => { "2.5" => 0.0, "5" => 0.0, "10" => 1.0, "+Inf" => 1.0, "sum" => 10.0 },
)
end
end
Expand Down

0 comments on commit 7550f3b

Please sign in to comment.