Skip to content

Upgrade OTP versions, supporting now only 26/27/28 and adapting to enhancements #184

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
merged 3 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ on:

jobs:
test:
name: OTP ${{matrix.otp}}
name: OTP ${{matrix.otp}} - rebar3 ${{matrix.rebar3}}
strategy:
matrix:
otp: ['27', '26', '25']
rebar3: ['3.24.0']
otp: ['28', '27', '26']
rebar3: ['3.24', '3.25']
runs-on: 'ubuntu-24.04'
env:
OTPVER: ${{ matrix.otp }}
Expand All @@ -28,18 +28,17 @@ jobs:
- run: rebar3 compile
- run: rebar3 lint
- run: rebar3 xref
- run: rebar3 dialyzer
- run: rebar3 eunit
- run: rebar3 fmt --check
if: ${{ matrix.otp == '27' }}
if: ${{ matrix.otp == '28' }}
- run: rebar3 ex_doc
if: ${{ matrix.otp == '27' }}
- run: rebar3 dialyzer
if: ${{ matrix.otp == '27' }}
if: ${{ matrix.otp == '28' }}
- run: rebar3 do cover, covertool generate
if: ${{ matrix.otp == '27' }}
if: ${{ matrix.otp == '28' }}
- name: Upload code coverage
uses: codecov/codecov-action@v5
if: ${{ matrix.otp == '27' }}
if: ${{ matrix.otp == '28' }}
with:
files: _build/test/covertool/prometheus.covertool.xml
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
10 changes: 6 additions & 4 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
%% -*- mode: erlang -*-
{minimum_otp_vsn, "26"}.

{erl_opts, [
debug_info,
warn_unused_vars,
Expand All @@ -13,9 +15,8 @@
warn_obsolete_guard,
strict_validation,
warn_export_vars,
warn_exported_vars,
warn_exported_vars
%warn_missing_spec, warn_untyped_record, <- Added dynamically for OTP >=27 in rebar.config.script
{platform_define, "^(2|3)", recent_otp}
]}.

{deps, [
Expand Down Expand Up @@ -119,15 +120,16 @@
filter => "*.erl",
rules => [
{elvis_text_style, line_length, #{limit => 120, skip_comments => false}},
{elvis_style, consistent_generic_type, #{preferred_type => term}},
{elvis_style, invalid_dynamic_call, #{
ignore => [
prometheus_misc,
prometheus_registry,
prometheus_sup
]
}},
{elvis_style, god_modules, #{limit => 54}},
{elvis_style, dont_repeat_yourself, #{min_complexity => 50}}
{elvis_style, god_modules, #{limit => 40}},
{elvis_style, dont_repeat_yourself, #{min_complexity => 15}}
],
ruleset => erl_files
},
Expand Down
5 changes: 0 additions & 5 deletions src/collectors/vm/prometheus_vm_statistics_collector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ metrics() ->
"except that real time is measured.", WallclockTime}
].

-ifdef(recent_otp).
dirty_stat() ->
try
SO = erlang:system_info(schedulers_online),
Expand All @@ -156,10 +155,6 @@ dirty_stat() ->
catch
_:_ -> [undefined, undefined]
end.
-else.
dirty_stat() ->
[undefined, undefined].
-endif.

enabled_metrics() ->
application:get_env(prometheus, vm_statistics_collector_metrics, all).
Expand Down
24 changes: 14 additions & 10 deletions src/metrics/prometheus_gauge.erl
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,15 @@ set_to_current_time(Registry, Name, LabelValues) ->
set(Registry, Name, LabelValues, os:system_time(seconds)).

?DOC(#{equiv => track_inprogress(default, Name, [], Fun)}).
-spec track_inprogress(prometheus_metric:name(), fun(() -> any())) -> any().
-spec track_inprogress(prometheus_metric:name(), fun(() -> dynamic())) -> dynamic().
track_inprogress(Name, Fun) ->
track_inprogress(default, Name, [], Fun).

?DOC(#{equiv => track_inprogress(default, Name, LabelValues, Fun)}).
-spec track_inprogress(prometheus_metric:name(), prometheus_metric:label_values(), fun(() -> any())) ->
any().
-spec track_inprogress(Name, LabelValues, Fun) -> dynamic() when
Name :: prometheus_metric:name(),
LabelValues :: prometheus_metric:label_values(),
Fun :: fun(() -> dynamic()).
track_inprogress(Name, LabelValues, Fun) ->
track_inprogress(default, Name, LabelValues, Fun).

Expand All @@ -354,11 +356,11 @@ Raises:
* `{invalid_metric_arity, Present, Expected}` error if labels count mismatch.
* `{invalid_value, Value, Message}` if `Fun` isn't a function.
""").
-spec track_inprogress(Registry, Name, LabelValues, Fun) -> any() when
-spec track_inprogress(Registry, Name, LabelValues, Fun) -> dynamic() when
Registry :: prometheus_registry:registry(),
Name :: prometheus_metric:name(),
LabelValues :: prometheus_metric:label_values(),
Fun :: fun(() -> any()).
Fun :: fun(() -> dynamic()).
track_inprogress(Registry, Name, LabelValues, Fun) when is_function(Fun, 0) ->
inc(Registry, Name, LabelValues, 1),
try
Expand All @@ -370,13 +372,15 @@ track_inprogress(_Registry, _Name, _LabelValues, Fun) ->
erlang:error({invalid_value, Fun, "track_inprogress accepts only functions"}).

?DOC(#{equiv => set_duration(default, Name, [], Fun)}).
-spec set_duration(prometheus_metric:name(), fun(() -> any())) -> any().
-spec set_duration(prometheus_metric:name(), fun(() -> dynamic())) -> dynamic().
set_duration(Name, Fun) ->
set_duration(default, Name, [], Fun).

?DOC(#{equiv => set_duration(default, Name, LabelValues, Fun)}).
-spec set_duration(prometheus_metric:name(), prometheus_metric:label_values(), fun(() -> any())) ->
any().
-spec set_duration(Name, LabelValues, Fun) -> dynamic() when
Name :: prometheus_metric:name(),
LabelValues :: prometheus_metric:label_values(),
Fun :: fun(() -> dynamic()).
set_duration(Name, LabelValues, Fun) ->
set_duration(default, Name, LabelValues, Fun).

Expand All @@ -390,11 +394,11 @@ Raises:
* `{invalid_metric_arity, Present, Expected}` error if labels count mismatch.
* `{invalid_value, Value, Message}` if `Fun` isn't a function.
""").
-spec set_duration(Registry, Name, LabelValues, Fun) -> any() when
-spec set_duration(Registry, Name, LabelValues, Fun) -> dynamic() when
Registry :: prometheus_registry:registry(),
Name :: prometheus_metric:name(),
LabelValues :: prometheus_metric:label_values(),
Fun :: fun(() -> any()).
Fun :: fun(() -> dynamic()).
set_duration(Registry, Name, LabelValues, Fun) when is_function(Fun, 0) ->
Start = erlang:monotonic_time(),
try
Expand Down
30 changes: 15 additions & 15 deletions src/metrics/prometheus_histogram.erl
Original file line number Diff line number Diff line change
Expand Up @@ -241,25 +241,23 @@ Raises:
Count :: integer().
observe_n(Registry, Name, LabelValues, Value, Count) when is_integer(Value), is_integer(Count) ->
Key = key(Registry, Name, LabelValues),
try ets:lookup_element(?TABLE, Key, ?BOUNDS_POS) of
Buckets ->
case ets:lookup_element(?TABLE, Key, ?BOUNDS_POS, undefined) of
undefined ->
insert_metric(Registry, Name, LabelValues, Value, Count, fun observe_n/5);
Buckets when is_tuple(Buckets) ->
BucketPosition = prometheus_buckets:position(Buckets, Value),
Spec = [{?ISUM_POS, Value * Count}, {?BUCKETS_START + BucketPosition, Count}],
ets:update_counter(?TABLE, Key, Spec)
catch
error:badarg ->
insert_metric(Registry, Name, LabelValues, Value, Count, fun observe_n/5)
end,
ok;
observe_n(Registry, Name, LabelValues, Value, Count) when is_float(Value), is_integer(Count) ->
Key = key(Registry, Name, LabelValues),
try ets:lookup_element(?TABLE, Key, ?BOUNDS_POS) of
Buckets ->
case ets:lookup_element(?TABLE, Key, ?BOUNDS_POS, undefined) of
undefined ->
insert_metric(Registry, Name, LabelValues, Value, Count, fun observe_n/5);
Buckets when is_tuple(Buckets) ->
BucketPosition = prometheus_buckets:position(Buckets, Value),
fobserve_impl(Key, Buckets, BucketPosition, Value, Count)
catch
error:badarg ->
insert_metric(Registry, Name, LabelValues, Value, Count, fun observe_n/5)
end;
observe_n(_Registry, _Name, _LabelValues, Value, Count) when is_number(Value) ->
erlang:error({invalid_count, Count, "observe_n accepts only integer counts"});
Expand Down Expand Up @@ -305,13 +303,15 @@ pobserve(_Registry, _Name, _LabelValues, _Buckets, _Pos, Value) ->
erlang:error({invalid_value, Value, "pobserve accepts only numbers"}).

?DOC(#{equiv => observe_duration(default, Name, [], Fun)}).
-spec observe_duration(prometheus_metric:name(), fun(() -> term())) -> term().
-spec observe_duration(prometheus_metric:name(), fun(() -> dynamic())) -> dynamic().
observe_duration(Name, Fun) ->
observe_duration(default, Name, [], Fun).

?DOC(#{equiv => observe_duration(default, Name, LabelValues, Fun)}).
-spec observe_duration(prometheus_metric:name(), prometheus_metric:label_values(), fun(() -> term())) ->
term().
-spec observe_duration(Name, LabelValues, Fun) -> dynamic() when
Name :: prometheus_metric:name(),
LabelValues :: prometheus_metric:label_values(),
Fun :: fun(() -> dynamic()).
observe_duration(Name, LabelValues, Fun) ->
observe_duration(default, Name, LabelValues, Fun).

Expand All @@ -323,11 +323,11 @@ Raises:
* `{invalid_metric_arity, Present, Expected}` error if labels count mismatch.
* `{invalid_value, Value, Message}` if `Fun` isn't a function.
""").
-spec observe_duration(Registry, Name, LabelValues, Fun) -> any() when
-spec observe_duration(Registry, Name, LabelValues, Fun) -> dynamic() when
Registry :: prometheus_registry:registry(),
Name :: prometheus_metric:name(),
LabelValues :: prometheus_metric:label_values(),
Fun :: fun(() -> any()).
Fun :: fun(() -> dynamic()).
observe_duration(Registry, Name, LabelValues, Fun) when is_function(Fun, 0) ->
Start = erlang:monotonic_time(),
try
Expand Down
12 changes: 7 additions & 5 deletions src/metrics/prometheus_quantile_summary.erl
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,15 @@ observe(_Registry, _Name, _LabelValues, Value) ->
erlang:error({invalid_value, Value, "observe accepts only numbers"}).

?DOC(#{equiv => observe_duration(default, Name, [], Fun)}).
-spec observe_duration(prometheus_metric:name(), fun(() -> term())) -> term().
-spec observe_duration(prometheus_metric:name(), fun(() -> dynamic())) -> dynamic().
observe_duration(Name, Fun) ->
observe_duration(default, Name, [], Fun).

?DOC(#{equiv => observe_duration(default, Name, LabelValues, Fun)}).
-spec observe_duration(prometheus_metric:name(), prometheus_metric:label_values(), fun(() -> term())) ->
term().
-spec observe_duration(Name, LabelValues, Value) -> dynamic() when
Name :: prometheus_metric:name(),
LabelValues :: prometheus_metric:label_values(),
Value :: fun(() -> dynamic()).
observe_duration(Name, LabelValues, Fun) ->
observe_duration(default, Name, LabelValues, Fun).

Expand All @@ -226,11 +228,11 @@ Raises:
* `{invalid_metric_arity, Present, Expected}` error if labels count mismatch.
* `{invalid_value, Value, Message}` if `Fun` isn't a function.
""").
-spec observe_duration(Registry, Name, LabelValues, Value) -> T when
-spec observe_duration(Registry, Name, LabelValues, Value) -> dynamic() when
Registry :: prometheus_registry:registry(),
Name :: prometheus_metric:name(),
LabelValues :: prometheus_metric:label_values(),
Value :: fun(() -> T).
Value :: fun(() -> dynamic()).
observe_duration(Registry, Name, LabelValues, Fun) when is_function(Fun) ->
Start = erlang:monotonic_time(),
try
Expand Down
12 changes: 7 additions & 5 deletions src/metrics/prometheus_summary.erl
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,15 @@ observe(_Registry, _Name, _LabelValues, Value) ->
erlang:error({invalid_value, Value, "observe accepts only numbers"}).

?DOC(#{equiv => observe_duration(default, Name, [], Fun)}).
-spec observe_duration(prometheus_metric:name(), fun(() -> term())) -> term().
-spec observe_duration(prometheus_metric:name(), fun(() -> dynamic())) -> dynamic().
observe_duration(Name, Fun) ->
observe_duration(default, Name, [], Fun).

?DOC(#{equiv => observe_duration(default, Name, LabelValues, Fun)}).
-spec observe_duration(prometheus_metric:name(), prometheus_metric:label_values(), fun(() -> term())) ->
term().
-spec observe_duration(Name, LabelValues, Fun) -> dynamic() when
Name :: prometheus_metric:name(),
LabelValues :: prometheus_metric:label_values(),
Fun :: fun(() -> dynamic()).
observe_duration(Name, LabelValues, Fun) ->
observe_duration(default, Name, LabelValues, Fun).

Expand All @@ -202,11 +204,11 @@ Raises:
* `{invalid_metric_arity, Present, Expected}` error if labels count mismatch.
* `{invalid_value, Value, Message}` if `Fun` isn't a function.
""").
-spec observe_duration(Registry, Name, LabelValues, Fun) -> any() when
-spec observe_duration(Registry, Name, LabelValues, Fun) -> dynamic() when
Registry :: prometheus_registry:registry(),
Name :: prometheus_metric:name(),
LabelValues :: prometheus_metric:label_values(),
Fun :: fun(() -> any()).
Fun :: fun(() -> dynamic()).
observe_duration(Registry, Name, LabelValues, Fun) when is_function(Fun) ->
Start = erlang:monotonic_time(),
try
Expand Down
12 changes: 6 additions & 6 deletions src/prometheus.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

-behaviour(application).

-type label_name() :: term().
-type label_value() :: term().
-type label_name() :: dynamic().
-type label_value() :: dynamic().
-type label() :: {label_name(), label_value()}.
-type pre_rendered_labels() :: binary().
-type labels() :: [label()] | #{label_name() => label_value()} | pre_rendered_labels().
Expand Down Expand Up @@ -59,16 +59,16 @@
-export([start/2, stop/1]).
-export([start/0, stop/0]).

-spec start(application:start_type(), term()) -> supervisor:startlink_ret().
-spec start(application:start_type(), dynamic()) -> supervisor:startlink_ret().
start(_StartType, _StartArgs) ->
prometheus_sup:start_link().

-spec stop(term()) -> ok.
-spec stop(dynamic()) -> ok.
stop(_State) ->
ok.

?DOC(false).
-spec start() -> ok | {error, term()}.
-spec start() -> ok | {error, dynamic()}.
start() ->
case application:ensure_all_started(?MODULE) of
{ok, _} ->
Expand All @@ -78,6 +78,6 @@ start() ->
end.

?DOC(false).
-spec stop() -> ok | {error, term()}.
-spec stop() -> ok | {error, dynamic()}.
stop() ->
application:stop(?MODULE).
4 changes: 2 additions & 2 deletions src/prometheus_collector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ create_gauge(Name, Help, Data) ->
-type collector() :: atom().

?DOC("Data associated with a collector").
-type data() :: any().
-type data() :: dynamic().

?DOC("Callback for `collect_mf/3`").
-type collect_mf_callback() :: fun((prometheus_model:'MetricFamily'()) -> any()).
-type collect_mf_callback() :: fun((prometheus_model:'MetricFamily'()) -> dynamic()).

?DOC("Should call `Callback` for each `MetricFamily` of this collector").
-callback collect_mf(Registry, Callback) -> ok when
Expand Down
Loading