Skip to content

Commit e7a8bcf

Browse files
committed
Apply review comments
1 parent 56faa7f commit e7a8bcf

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/prometheus_collector.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ collect_mf(_Registry, Callback) ->
4343
Memory)),
4444
ok.
4545
46-
collect_metrics(erlang_vm_bytes_total, Memory) ->
46+
collect_metrics(_Name, Memory) ->
4747
prometheus_model_helpers:gauge_metrics(
4848
[
4949
{[{kind, system}], proplists:get_value(system, Memory)},

test/eunit/prometheus_model_helpers_tests.erl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,27 @@ create_mf_test() ->
661661
prometheus_model_helpers:create_mf(<<"fast_path">>, <<"help">>, gauge, [PrebuiltMetric])
662662
).
663663

664+
%% Test that prometheus_metric:metrics/2 normalizes old-format ETS entries
665+
%% (2-tuple {Labels, Help}) into the new 3-tuple {Labels, HelpBin, NameBin}.
666+
%% This covers the backward-compat clause in normalize_mf_row/1, reachable
667+
%% during hot upgrades from nodes that predate the pre-computed binary change.
668+
normalize_mf_row_backward_compat_test() ->
669+
Table = ?PROMETHEUS_GAUGE_TABLE,
670+
Registry = test_compat_registry,
671+
Name = test_compat_metric,
672+
Labels = [label_a],
673+
Help = "Old format help",
674+
OldTuple = {{Registry, mf, Name}, {Labels, Help}, [], undefined, undefined},
675+
ets:insert(Table, OldTuple),
676+
try
677+
[[Name, {Labels, HelpBin, NameBin}, [], undefined, undefined]] =
678+
prometheus_metric:metrics(Table, Registry),
679+
?assertEqual(<<"Old format help">>, HelpBin),
680+
?assertEqual(<<"test_compat_metric">>, NameBin)
681+
after
682+
ets:delete(Table, {Registry, mf, Name})
683+
end.
684+
664685
collect_metrics(g1, _Data) ->
665686
prometheus_model_helpers:gauge_metric(g1_value).
666687

0 commit comments

Comments
 (0)