Repository navigation
Parse histogram buckets such as .005 and 1e-3 as numbers #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Watson1978
merged 2 commits into
fluent:master
from
RaphaelFakhri:fix-histogram-bucket-parsing
Nov 7, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| require 'spec_helper' | ||
|
|
||
| describe Fluent::Plugin::Prometheus::Histogram do | ||
| let(:registry) { ::Prometheus::Client::Registry.new } | ||
|
|
||
| def build_histogram(buckets) | ||
| element = Fluent::Config::Element.new( | ||
| 'metric', '', | ||
| { | ||
| 'name' => 'histogram_buckets', | ||
| 'type' => 'histogram', | ||
| 'desc' => 'Something foo.', | ||
| 'key' => 'foo', | ||
| 'buckets' => buckets, | ||
| }, | ||
| [] | ||
| ) | ||
| Fluent::Plugin::Prometheus::Histogram.new(element, registry, {}, {}) | ||
| end | ||
|
|
||
| def buckets_of(buckets) | ||
| build_histogram(buckets) | ||
| registry.get(:histogram_buckets).buckets | ||
| end | ||
|
|
||
| it 'keeps integer and decimal buckets' do | ||
| expect(buckets_of('0.1, 1, 5, 10')).to eql([0.1, 1, 5, 10]) | ||
| end | ||
|
|
||
| it 'keeps buckets of three or more digits as floats, as before' do | ||
| expect(buckets_of('10, 100, 1000')).to eql([10, 100.0, 1000.0]) | ||
| end | ||
|
|
||
| it 'keeps signed integer buckets as integers' do | ||
| expect(buckets_of('-5, 0, +5')).to eql([-5, 0, 5]) | ||
| end | ||
|
|
||
| it 'parses decimal buckets without a leading zero' do | ||
| expect(buckets_of('.005, .01, .025')).to eql([0.005, 0.01, 0.025]) | ||
| end | ||
|
|
||
| it 'parses buckets in exponent notation' do | ||
| expect(buckets_of('1e-3, 1e-2, 1.5e2')).to eql([0.001, 0.01, 150.0]) | ||
| end | ||
|
|
||
| it 'refuses a bucket which is not a number' do | ||
| expect { build_histogram('0.1, abc') } | ||
| .to raise_error(Fluent::ConfigError, /buckets in <metric> histogram_buckets must be numbers/) | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SHOULD:
eqcannot catch thelechange inlib/fluent/plugin/prometheus.rb, because[1.0] == [1]is true in Ruby. Please useeqland add the cases from that comment. With this PR as is, the two new examples fail:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in be8b6c5. The examples use
eql, and the two new ones fail on the previous commit and pass now.bundle exec rspecpasses (184 examples).