Skip to content

Commit

Permalink
Add a very simple check for amoc_metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Dec 3, 2024
1 parent 016c23b commit b353dca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ci/dummy_scenario.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ test_verification_function(_) -> {true, new_value}.

-spec init() -> ok.
init() ->
ok = amoc_metrics:init(counters, dummy_scenario_metric),
ok = amoc_metrics:init(times, dummy_scenario_metric),
%% amoc follows a couple of rules during the scenario initialisation:
%% - if any parameter verification fails, amoc will not start
%% the scenario and the init/0 function is not triggered.
Expand Down Expand Up @@ -73,6 +75,8 @@ init() ->

-spec start(amoc_scenario:user_id()) -> any().
start(_Id) ->
ok = amoc_metrics:update_counter(dummy_scenario_metric, 1),
ok = amoc_metrics:update_time(dummy_scenario_metric, rand:uniform()),
%%sleep 15 minutes
timer:sleep(timer:minutes(15)),
amoc_user:stop().
8 changes: 4 additions & 4 deletions src/amoc_metrics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ start_predefined_metrics(App) ->

-spec init(type(), name()) -> ok.
init(counters, Name) ->
prometheus_counter:new([{name, Name}]);
prometheus_counter:new([{name, Name}, {help, ""}]);
init(gauge, Name) ->
prometheus_gauge:new([{name, Name}]);
prometheus_gauge:new([{name, Name}, {help, ""}]);
init(summary, Name) ->
prometheus_summary:new([{name, Name}]);
prometheus_summary:new([{name, Name}, {help, ""}]);
init(Type, Name) when histogram =:= Type; times =:= Type ->
prometheus_histogram:new([{name, Name}, {buckets, histogram_buckets()}]).
prometheus_histogram:new([{name, Name}, {buckets, histogram_buckets()}, {help, ""}]).

-spec update_counter(name()) -> ok.
update_counter(Name) ->
Expand Down
2 changes: 2 additions & 0 deletions test/scenario_template.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ some edoc
-spec init() -> ok.
init() ->
ok = amoc_metrics:init(counters, ", (atom_to_binary(Name, utf8))/binary, "),
ok.
-spec start(amoc_scenario:user_id()) -> any().
start(Id) ->
ok = amoc_metrics:update_counter(", (atom_to_binary(Name, utf8))/binary, ", 1),
amoc_user:stop().
%% generated at", ?FILE, ":", (integer_to_binary(?LINE))/binary>>).

0 comments on commit b353dca

Please sign in to comment.