Skip to content

Commit

Permalink
[debug] mongoose_metrics_SUITE
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekwegr committed Oct 5, 2023
1 parent 9f1d4cd commit 45fdee8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/metrics/mongoose_metrics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,17 @@ ensure_metric(HostType, Metric, Type) ->
ensure_metric(HostType, Metric, Type, Type).

get_metric_value(HostType, Name) when is_list(Name) ->
io:format("Name: ~p", [Name]),
io:format("name_by_all_metrics_are_global(HostType, Name): ~p", [name_by_all_metrics_are_global(HostType, Name)]),
get_metric_value(name_by_all_metrics_are_global(HostType, Name));
get_metric_value(HostType, Name) ->
get_metric_value(HostType, [Name]).

get_metric_value(Metric) ->
exometer:get_value(Metric).
io:format("Metric: ~p", [Metric]),
Ret = exometer:get_value(Metric),
io:format("Ret: ~p", [Ret]),
Ret.

get_metric_values(Metric) when is_list(Metric) ->
exometer:get_values(Metric);
Expand Down
58 changes: 49 additions & 9 deletions test/mongooseim_metrics_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ init_per_suite(C) ->
gen_tcp:controlling_process(Socket, PortServer),
{ok, _Apps} = application:ensure_all_started(exometer_core),
exometer:new([carbon, packets], spiral),
%% Empty message queue for the "user" process to not pollute the metrics
Info = {user, whereis(user), process_info(whereis(user), message_queue_len)},
io:format("Info before flush init_per_suite: ~p", [Info]),
flush_queue(whereis(user)),
io:format("Info after flush init_per_suite: ~p", [Info]),
[{carbon_port, Port}, {test_sup, Sup}, {carbon_server, PortServer}, {carbon_socket, Socket} | C].

end_per_suite(C) ->
Expand Down Expand Up @@ -90,8 +95,19 @@ init_per_testcase(queued_messages_increase, C) ->
receive die -> ok
end
end,
Pids = [spawn(PidsFun) || _ <- lists:seq(1,5)],
Pids = [spawn(PidsFun) || _ <- lists:seq(1, 5)],
Info = {user, whereis(user), process_info(whereis(user), message_queue_len)},
io:format("Info before flush init_per_testcase: ~p", [Info]),
flush_queue(whereis(user)),
io:format("Info after flush init_per_testcase: ~p", [Info]),
% async_helper:wait_until(
% fun() ->
% {messages, Messages} = process_info(whereis(user), messages),
% io:format("Messages user: ~p", [Messages]),
% Messages
% end, []),
lists:foreach(fun(Pid) -> Pid ! undefined end, Pids),
% io:format("Pids: ~p", [Pids]),
[{pids, Pids} | C];
init_per_testcase(_N, C) ->
C.
Expand Down Expand Up @@ -139,19 +155,30 @@ tcp_metric_varies_with_tcp_variations(_C) ->
gen_tcp:close(Socket),
X = get_new_tcp_metric_value({ok, [{value, Y}]}).

get_all_queue_lengths() ->
Processes = processes(),
lists:map(fun(Pid) ->
{Pid, process_info(Pid, message_queue_len)}
end, Processes).

get_registered_queue_lengths() ->
RegisteredNames = registered(),
lists:map(fun(Name) ->
Pid = whereis(Name),
{Name, Pid, process_info(Pid, message_queue_len)}
end, RegisteredNames).

queued_messages_increase(_C) ->
Fun = fun(Value) ->
case Value of
[{fsm, 5}, {regular, 5}, {total, 10}] -> true;
[{fsm, 5}, {regular, 6}, {total, 11}] -> true;
_ -> false
end
end,
io:format("get_registered_queue_lengths: ~p~n", [get_registered_queue_lengths()]),
% io:format("get_all_queue_lengths: ~p~n", [get_all_queue_lengths()]),
async_helper:wait_until(
fun() ->
{ok, L} = mongoose_metrics:get_metric_value(global, processQueueLengths),
io:format("L: ~p~n~n", [L]),
lists:sort(L)
end, Fun).
end,
[{fsm, 5}, {regular, 5}, {total, 10}]
).

no_skip_metric(_C) ->
ok = mongoose_metrics:create_generic_hook_metric(<<"localhost">>, sm_register_connection_hook),
Expand Down Expand Up @@ -183,3 +210,16 @@ get_reporters_cfg(Port) ->
{api_key, ""}
]}
]}].

flush_queue(Pid) when is_pid(Pid) ->
case process_info(Pid, message_queue_len) of
{message_queue_len, 0} ->
ok;
{message_queue_len, _} ->
receive
_Any ->
flush_queue(Pid)
after 0 ->
ok
end
end.

0 comments on commit 45fdee8

Please sign in to comment.