Skip to content

Commit

Permalink
Merge pull request #7 from esl/prometheus
Browse files Browse the repository at this point in the history
Test amoc_metrics
  • Loading branch information
chrzaszcz authored Dec 3, 2024
2 parents f4c785f + 0aacafc commit 312bd22
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 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(1 bsl 16)),
%%sleep 15 minutes
timer:sleep(timer:minutes(15)),
amoc_user:stop().
1 change: 1 addition & 0 deletions ci/test_run_scenario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ worker_status=( '"amoc_status":"up"'
'"interarrival":"50"' )
get_status amoc-worker-1 | contains "${worker_status[@]}"
get_status amoc-worker-2 | contains "${worker_status[@]}"
retry 60 curl 'http://localhost:9090/api/v1/query?query=\{__name__="dummy_scenario_metric"\}' | contains "success"
10 changes: 5 additions & 5 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 All @@ -51,7 +51,7 @@ update_gauge(Name, Value) ->

-spec update_time(name(), integer()) -> ok.
update_time(Name, Value) ->
prometheus_summary:observe(Name, Value).
prometheus_histogram:observe(Name, Value).

-spec collect_mf(prometheus_registry:registry(), prometheus_collector:collect_mf_callback()) -> ok.
collect_mf(_Registry, Callback) ->
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 312bd22

Please sign in to comment.