Skip to content

Commit

Permalink
Merge pull request #21 from yordis/closes-14
Browse files Browse the repository at this point in the history
feat: allow to set the default bucket calculator
  • Loading branch information
rkallos authored Dec 23, 2024
2 parents 6516644 + 7319c79 commit fb1fd6f
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions lib/peep/buckets.ex
Original file line number Diff line number Diff line change
@@ -1,20 +1,58 @@
defmodule Peep.Buckets do
@default_module Peep.Buckets.Exponential
@reporter_option :peep_bucket_calculator

@moduledoc """
A behavior for histogram bucketing strategies.
If no bucketing strategy is provided (i.e. #{@reporter_option} is not set in
:reporter_options for a `%Telemetry.Metrics.Distribution{}`, then the default
is `#{@default_module}`.
You can pass a bucketing strategy to a distribution metric in your metrics:
```elixir
def metrics do
[
distribution([:bandit, :request, :stop, :duration],
tags: [],
unit: {:native, :millisecond},
reporter_options: [
peep_bucket_calculator: Peep.Buckets.PowersOfTen
]
)
]
end
If no bucketing strategy is provided is not set in :reporter_options for a
`%Telemetry.Metrics.Distribution{}`, then the default is
`Peep.Buckets.Exponential`.
You can change the default bucket calculator, set `:bucket_calculator` in your
config.
```elixir
config :peep, bucket_calculator: Peep.Buckets.PowersOfTen
```
## Custom Buckets
If you want custom bucket boundaries, there is `Peep.Buckets.Custom`, which
uses pattern matching to assign sample measurements to buckets.
Example:
```elixir
defmodule MyApp.MyBucket do
use Peep.Buckets.Custom,
buckets: [10, 100, 1_000]
end
```
"""

alias Telemetry.Metrics

@default_module Application.compile_env(
:peep,
:bucket_calculator,
Peep.Buckets.Exponential
)

@reporter_option :peep_bucket_calculator

@type config :: map

@callback config(Metrics.Distribution.t()) :: config
Expand Down

0 comments on commit fb1fd6f

Please sign in to comment.