Skip to content

Commit

Permalink
Merge d872743 into 260e51a
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrencejones committed Jan 14, 2020
2 parents 260e51a + d872743 commit ab38d57
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/prometheus/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@ def self.registry
def self.config
@config ||= Config.new
end

def self.linear_buckets(start:, width:, count:)
count.times.map { |idx| start.to_f + idx * width }
end

def self.exponential_buckets(start:, factor: 2, count:)
count.times.map { |idx| start.to_f * factor ** idx }
end
end
end
16 changes: 16 additions & 0 deletions spec/prometheus/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,20 @@
expect(Prometheus::Client.registry).to eql(Prometheus::Client.registry)
end
end

describe ".linear_buckets" do
it "generates buckets" do
expect(described_class.linear_buckets(start: 1, width: 2, count: 5)).to eql(
[1.0, 3.0, 5.0, 7.0, 9.0]
)
end
end

describe ".exponential_buckets" do
it "generates buckets" do
expect(described_class.exponential_buckets(start: 1, factor: 2, count: 5)).to eql(
[1.0, 2.0, 4.0, 8.0, 16.0]
)
end
end
end

0 comments on commit ab38d57

Please sign in to comment.