Skip to content

Commit c314f68

Browse files
authored
Merge pull request #188 from prometheus-erl/promtool
Run promtool in CI. Fixes #135.
2 parents 6516353 + 908d5b6 commit c314f68

17 files changed

+308
-134
lines changed

.github/workflows/main.yml

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,22 @@ jobs:
1515
strategy:
1616
matrix:
1717
otp: ['28', '27', '26']
18-
rebar3: ['3.24', '3.25']
18+
rebar3: ['3.25']
1919
runs-on: 'ubuntu-24.04'
20-
env:
21-
OTPVER: ${{ matrix.otp }}
2220
steps:
2321
- uses: actions/checkout@v4
2422
- uses: erlef/setup-beam@v1
2523
with:
2624
otp-version: ${{matrix.otp}}
2725
rebar3-version: ${{matrix.rebar3}}
2826
- run: rebar3 compile
27+
- run: rebar3 fmt --check
28+
if: ${{ matrix.otp == '28' }}
2929
- run: rebar3 lint
3030
- run: rebar3 xref
3131
- run: rebar3 dialyzer
3232
- run: rebar3 eunit
33-
- run: rebar3 fmt --check
34-
if: ${{ matrix.otp == '28' }}
3533
- run: rebar3 ex_doc
36-
if: ${{ matrix.otp == '28' }}
3734
- run: rebar3 do cover, covertool generate
3835
if: ${{ matrix.otp == '28' }}
3936
- name: Upload code coverage
@@ -44,3 +41,42 @@ jobs:
4441
token: ${{ secrets.CODECOV_TOKEN }}
4542
fail_ci_if_error: true
4643
verbose: true
44+
45+
promtool:
46+
name: promtool
47+
runs-on: 'ubuntu-24.04'
48+
steps:
49+
- uses: actions/setup-go@v5
50+
with:
51+
go-version: 'stable'
52+
- run: |
53+
# Fetch latest version
54+
TAG=$(curl -s https://api.github.com/repos/prometheus/prometheus/releases | jq -r '.[] | .tag_name' | head -n 1)
55+
echo $TAG
56+
# Remove the `v` prefix
57+
VERSION=$(echo $TAG | sed 's/v//')
58+
echo $VERSION
59+
# Check CPU architecture
60+
ARCH=$(uname -s | tr A-Z a-z)-$(uname -m | sed 's/x86_64/amd64/')
61+
echo $ARCH
62+
# Download the release
63+
curl -L -O https://github.com/prometheus/prometheus/releases/download/$TAG/prometheus-$VERSION.$ARCH.tar.gz
64+
# Extract the file
65+
tar -xvzf prometheus-$VERSION.$ARCH.tar.gz
66+
# Move promtool
67+
mv prometheus-$VERSION.$ARCH/promtool /usr/local/bin
68+
# Verify if promtool is installed
69+
promtool --version
70+
# Delete downloaded files
71+
rm -rf prometheus-$VERSION.$ARCH
72+
rm -rf prometheus-$VERSION.$ARCH.tar.gz
73+
- uses: actions/checkout@v4
74+
- uses: erlef/setup-beam@v1
75+
with:
76+
otp-version: '28'
77+
rebar3-version: '3.25'
78+
- run: rebar3 compile
79+
- run: |
80+
set -e
81+
set -o pipefail
82+
erl -pa _build/default/lib/prometheus/ebin -pa _build/default/lib/ddskerl/ebin -noshell -eval '{ok, _} = application:ensure_all_started(prometheus), ok = io:format(standard_io, "~s~n", [prometheus_text_format:format()]), halt().' | promtool check metrics

rebar.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
undefined_function_calls,
3131
undefined_functions,
3232
locals_not_used,
33-
deprecated_function_calls,
34-
deprecated_functions
33+
{deprecated_function_calls, next_major_release},
34+
{deprecated_functions, next_major_release}
3535
]}.
3636

3737
{dialyzer, [

src/collectors/mnesia/prometheus_mnesia_collector.erl

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ Collects Mnesia metrics mainly using `mnesia:system_info/1`.
2424
* `erlang_mnesia_transaction_coordinators`
2525
Type: gauge.
2626
Number of coordinator transactions.
27-
* `erlang_mnesia_failed_transactions`
27+
* `erlang_mnesia_failed_transactions_total`
2828
Type: counter.
2929
Number of failed (i.e. aborted) transactions.
30-
* `erlang_mnesia_committed_transactions`
30+
* `erlang_mnesia_committed_transactions_total`
3131
Type: gauge.
3232
Number of committed transactions.
33-
* `erlang_mnesia_logged_transactions`
33+
* `erlang_mnesia_logged_transactions_total`
3434
Type: counter.
3535
Number of transactions logged.
36-
* `erlang_mnesia_restarted_transactions`
36+
* `erlang_mnesia_restarted_transactions_total`
3737
Type: counter.
3838
Total number of transaction restarts.
3939
* `erlang_mnesia_memory_usage_bytes`
@@ -56,10 +56,10 @@ Available options:
5656
- `lock_queue` for `erlang_mnesia_lock_queue`;
5757
- `transaction_participants` for `erlang_mnesia_transaction_participants`;
5858
- `transaction_coordinators` for `erlang_mnesia_transaction_coordinators`;
59-
- `transaction_failures` for `erlang_mnesia_failed_transactions`;
60-
- `transaction_commits` for `erlang_mnesia_committed_transactions`;
61-
- `transaction_log_writes` for `erlang_mnesia_logged_transactions`;
62-
- `transaction_restarts` for `erlang_mnesia_restarted_transactions`;
59+
- `transaction_failures` for `erlang_mnesia_failed_transactions_total`;
60+
- `transaction_commits` for `erlang_mnesia_committed_transactions_total`;
61+
- `transaction_log_writes` for `erlang_mnesia_logged_transactions_total`;
62+
- `transaction_restarts` for `erlang_mnesia_restarted_transactions_total`;
6363
- `memory_usage_bytes` for `erlang_mnesia_memory_usage_bytes`.
6464
6565
By default all metrics are enabled.
@@ -88,7 +88,7 @@ collect_mf(_Registry, Callback) ->
8888
case mnesia_running() of
8989
true ->
9090
EnabledMetrics = enabled_metrics(),
91-
Metrics = metrics(EnabledMetrics),
91+
Metrics = prometheus_collectors_compat:pre_promtool_compat(metrics(EnabledMetrics)),
9292
[
9393
add_metric_family(Metric, Callback)
9494
|| {Name, _, _, _} = Metric <- Metrics, metric_enabled(Name, EnabledMetrics)
@@ -118,16 +118,17 @@ metrics(EnabledMetrics) ->
118118
{transaction_coordinators, gauge, "Number of coordinator transactions.", fun() ->
119119
Coordinators
120120
end},
121-
{failed_transactions, counter, "Number of failed (i.e. aborted) transactions.", fun() ->
122-
mnesia:system_info(transaction_failures)
123-
end},
124-
{committed_transactions, counter, "Number of committed transactions.", fun() ->
121+
{failed_transactions_total, counter, "Number of failed (i.e. aborted) transactions.",
122+
fun() ->
123+
mnesia:system_info(transaction_failures)
124+
end},
125+
{committed_transactions_total, counter, "Number of committed transactions.", fun() ->
125126
mnesia:system_info(transaction_commits)
126127
end},
127-
{logged_transactions, counter, "Number of transactions logged.", fun() ->
128+
{logged_transactions_total, counter, "Number of transactions logged.", fun() ->
128129
mnesia:system_info(transaction_log_writes)
129130
end},
130-
{restarted_transactions, counter, "Total number of transaction restarts.", fun() ->
131+
{restarted_transactions_total, counter, "Total number of transaction restarts.", fun() ->
131132
mnesia:system_info(transaction_restarts)
132133
end},
133134
{memory_usage_bytes, gauge, "Total number of bytes allocated by all mnesia tables", fun() ->
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
-module(prometheus_collectors_compat).
2+
-if(?OTP_RELEASE >= 27).
3+
-define(MODULEDOC(Str), -moduledoc(Str)).
4+
-define(DOC(Str), -doc(Str)).
5+
-else.
6+
-define(MODULEDOC(Str), -compile([])).
7+
-define(DOC(Str), -compile([])).
8+
-endif.
9+
10+
?MODULEDOC("""
11+
Compatibility with previous collector metric names.
12+
13+
Up to version 6.0, some default collector metrics did not have `promtool` compliant names.
14+
The issue was fixed in version 6.0. This module is a compatibility layer for the old names.
15+
16+
It is disabled by default, to configure you need to set
17+
```erlang
18+
{prometheus, [
19+
{collectors_compat, true}
20+
]}
21+
```
22+
23+
This will be supported only for one major version.
24+
""").
25+
?MODULEDOC(#{deprecated => ~"Kept for compatibility and scheduled to be removed on the next major"}).
26+
27+
-export([pre_promtool_compat/1]).
28+
-deprecated([{'_', '_', next_major_release}]).
29+
30+
?DOC(false).
31+
-spec pre_promtool_compat([dynamic()]) -> [dynamic()].
32+
pre_promtool_compat(Metrics) ->
33+
case is_enabled() of
34+
true ->
35+
lists:map(fun pre_promtool_compat_fun/1, Metrics);
36+
_ ->
37+
Metrics
38+
end.
39+
40+
pre_promtool_compat_fun({failed_transactions_total, counter, Help, Fun}) ->
41+
{failed_transactions, counter, Help, Fun};
42+
pre_promtool_compat_fun({committed_transactions_total, counter, Help, Fun}) ->
43+
{committed_transactions, counter, Help, Fun};
44+
pre_promtool_compat_fun({logged_transactions_total, counter, Help, Fun}) ->
45+
{logged_transactions, counter, Help, Fun};
46+
pre_promtool_compat_fun({restarted_transactions_total, counter, Help, Fun}) ->
47+
{restarted_transactions, counter, Help, Fun};
48+
pre_promtool_compat_fun({atom_bytes, gauge, Help, Value}) ->
49+
{atom_bytes_total, gauge, Help, Value};
50+
pre_promtool_compat_fun({bytes, gauge, Help, Value}) ->
51+
{bytes_total, gauge, Help, Value};
52+
pre_promtool_compat_fun({processes_bytes, gauge, Help, Value}) ->
53+
{processes_bytes_total, gauge, Help, Value};
54+
pre_promtool_compat_fun({system_bytes, gauge, Help, Value}) ->
55+
{system_bytes_total, gauge, Help, Value};
56+
pre_promtool_compat_fun({context_switches_total, counter, Help, Value}) ->
57+
{context_switches, counter, Help, Value};
58+
pre_promtool_compat_fun({garbage_collection_number_of_gcs_total, counter, Help, Value}) ->
59+
{garbage_collection_number_of_gcs, counter, Help, Value};
60+
pre_promtool_compat_fun({garbage_collection_bytes_reclaimed_total, counter, Help, Value}) ->
61+
{garbage_collection_bytes_reclaimed, counter, Help, Value};
62+
pre_promtool_compat_fun({garbage_collection_words_reclaimed_total, counter, Help, Value}) ->
63+
{garbage_collection_words_reclaimed, counter, Help, Value};
64+
pre_promtool_compat_fun({runtime_seconds_total, counter, Help, Value}) ->
65+
{runtime_milliseconds, counter, Help, Value};
66+
pre_promtool_compat_fun({wallclock_time_seconds_total, counter, Help, Value}) ->
67+
{wallclock_time_milliseconds, counter, Help, Value};
68+
pre_promtool_compat_fun({ports, gauge, Help}) ->
69+
{port_count, gauge, Help};
70+
pre_promtool_compat_fun({processes, gauge, Help}) ->
71+
{process_count, gauge, Help};
72+
pre_promtool_compat_fun({atoms, gauge, Help}) ->
73+
{atom_count, gauge, Help};
74+
pre_promtool_compat_fun(Metric) ->
75+
Metric.
76+
77+
-spec is_enabled() -> dynamic().
78+
is_enabled() ->
79+
application:get_env(prometheus, collectors_compat, false).

src/collectors/vm/prometheus_vm_memory_collector.erl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Collects information about memory dynamically allocated by the Erlang emulator u
1313
1414
### Exported metrics
1515
16-
* `erlang_vm_memory_atom_bytes_total{usage=\"free|used\"}`
16+
* `erlang_vm_memory_atom_bytes{usage=\"free|used\"}`
1717
Type: gauge.
1818
The total amount of memory currently allocated for atoms.
1919
This memory is part of the memory presented as system memory.
20-
* `erlang_vm_memory_bytes_total{kind=\"system|processes\"}`
20+
* `erlang_vm_memory_bytes{kind=\"system|processes\"}`
2121
Type: gauge.
2222
The total amount of memory currently allocated.
2323
This is the same as the sum of the memory size for processes and system.
@@ -27,10 +27,10 @@ Collects information about memory dynamically allocated by the Erlang emulator u
2727
* `erlang_vm_memory_ets_tables`
2828
Type: gauge.
2929
Erlang VM ETS Tables count.
30-
* `erlang_vm_memory_processes_bytes_total{usage=\"free|used\"}`
30+
* `erlang_vm_memory_processes_bytes{usage=\"free|used\"}`
3131
Type: gauge.
3232
The total amount of memory currently allocated for the Erlang processes.
33-
* `erlang_vm_memory_system_bytes_total{usage=\"atom|binary|code|ets|other\"}`
33+
* `erlang_vm_memory_system_bytes{usage=\"atom|binary|code|ets|other\"}`
3434
Type: gauge.
3535
The total amount of memory currently allocated for the emulator that is not directly related
3636
to any Erlang process. Memory presented as processes is not included in this memory.
@@ -42,12 +42,12 @@ of the `prometheus` app environment.
4242
4343
Available options:
4444
45-
* `atom_bytes_total` for `erlang_vm_memory_atom_bytes_total`.
46-
* `bytes_total` for `erlang_vm_memory_bytes_total`.
45+
* `atom_bytes` for `erlang_vm_memory_atom_bytes`.
46+
* `bytes` for `erlang_vm_memory_bytes`.
4747
* `dets_tables` for `erlang_vm_dets_tables`.
4848
* `ets_tables` for `erlang_vm_ets_tables`.
49-
* `processes_bytes_total` for `erlang_vm_memory_processes_bytes_total`.
50-
* `system_bytes_total` for `erlang_vm_memory_system_bytes_total`.
49+
* `processes_bytes` for `erlang_vm_memory_processes_bytes`.
50+
* `system_bytes` for `erlang_vm_memory_system_bytes`.
5151
5252
By default all metrics are enabled.
5353
""").
@@ -70,7 +70,7 @@ deregister_cleanup(_) ->
7070
_Registry :: prometheus_registry:registry(),
7171
Callback :: prometheus_collector:collect_mf_callback().
7272
collect_mf(_Registry, Callback) ->
73-
Metrics = metrics(),
73+
Metrics = prometheus_collectors_compat:pre_promtool_compat(metrics()),
7474
EnabledMetrics = enabled_metrics(),
7575
[
7676
add_metric_family(Metric, Callback)
@@ -88,7 +88,7 @@ add_metric_family({Name, Type, Help, Metrics}, Callback) ->
8888
metrics() ->
8989
Data = erlang:memory(),
9090
[
91-
{atom_bytes_total, gauge,
91+
{atom_bytes, gauge,
9292
"The total amount of memory currently allocated "
9393
"for atoms. This memory is part of the memory "
9494
"presented as system memory.", [
@@ -98,7 +98,7 @@ metrics() ->
9898
proplists:get_value(atom, Data) - proplists:get_value(atom_used, Data)
9999
}
100100
]},
101-
{bytes_total, gauge,
101+
{bytes, gauge,
102102
"The total amount of memory currently allocated. "
103103
"This is the same as the sum of the memory size "
104104
"for processes and system.", [
@@ -107,7 +107,7 @@ metrics() ->
107107
]},
108108
{dets_tables, gauge, "Erlang VM DETS Tables count.", length(dets:all())},
109109
{ets_tables, gauge, "Erlang VM ETS Tables count.", length(ets:all())},
110-
{processes_bytes_total, gauge,
110+
{processes_bytes, gauge,
111111
"The total amount of memory currently allocated "
112112
"for the Erlang processes.", [
113113
{[{usage, used}], proplists:get_value(processes_used, Data)},
@@ -116,7 +116,7 @@ metrics() ->
116116
proplists:get_value(processes, Data) - proplists:get_value(processes_used, Data)
117117
}
118118
]},
119-
{system_bytes_total, gauge,
119+
{system_bytes, gauge,
120120
"The total amount of memory currently allocated "
121121
"for the emulator that is not directly related "
122122
"to any Erlang process. Memory presented as processes "

src/collectors/vm/prometheus_vm_msacc_collector.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
?MODULEDOC("""
1111
Collects microstate accounting metrics using
1212
[`erlang:statistics(microstate_accounting)`]
13-
(http://erlang.org/doc/man/erlang.html#statistics_microstate_accounting).
13+
(https://erlang.org/doc/man/erlang.html#statistics_microstate_accounting).
1414
1515
In order for values to increase, microstate accounting must be enabled.
1616
This is done by calling `erlang:system_flag(microstate_accounting, true).`
@@ -82,7 +82,7 @@ of the `prometheus` app environment.
8282
8383
Options are the same as MSAcc_Thread_State return type from
8484
[`erlang:statistics(microstate_accounting)`]
85-
(http://erlang.org/doc/man/erlang.html#statistics_microstate_accounting)
85+
(https://erlang.org/doc/man/erlang.html#statistics_microstate_accounting)
8686
with `_seconds_total` as the suffix:
8787
8888
* `aux_seconds_total` for `erlang_vm_msacc_aux_seconds_total`.

0 commit comments

Comments
 (0)