diff --git a/lib/prometheus/client/histogram.rb b/lib/prometheus/client/histogram.rb index 7c32d016..29f540b6 100644 --- a/lib/prometheus/client/histogram.rb +++ b/lib/prometheus/client/histogram.rb @@ -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) diff --git a/spec/prometheus/client/histogram_spec.rb b/spec/prometheus/client/histogram_spec.rb index 0f871703..48aaa62a 100644 --- a/spec/prometheus/client/histogram_spec.rb +++ b/spec/prometheus/client/histogram_spec.rb @@ -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