-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
138 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
%%% @doc Instrumentation tests that don't fit into the XMPP-specific test suites | ||
|
||
-module(instrument_SUITE). | ||
-include_lib("eunit/include/eunit.hrl"). | ||
|
||
-compile([export_all, nowarn_export_all]). | ||
|
||
-import(distributed_helper, [mim/0, mim2/0, rpc/4]). | ||
-import(domain_helper, [host_type/1]). | ||
-import(mongooseimctl_helper, [rpc_call/3]). | ||
|
||
all() -> | ||
[{group, cets}, | ||
{group, system}]. | ||
|
||
groups() -> | ||
[{cets, [], cets_cases()}, | ||
{system, [parallel], system_cases()}]. | ||
|
||
cets_cases() -> | ||
[cets_info]. | ||
|
||
system_cases() -> | ||
[system_up_time, | ||
system_tcp_ports, | ||
system_process_queue_lengths, | ||
system_info, | ||
system_memory, | ||
system_dist_data]. | ||
|
||
init_per_suite(Config) -> | ||
Config1 = mongoose_helper:backup_and_set_config_option( | ||
Config, [instrumentation, probe_interval], 1), | ||
restart_probes(), | ||
Config1. | ||
|
||
end_per_suite(Config) -> | ||
mongoose_helper:restore_config_option(Config, [instrumentation, probe_interval]), | ||
restart_probes(). | ||
|
||
init_per_group(cets, Config) -> | ||
case rpc_call(mongoose_config, lookup_opt, [[internal_databases, cets]]) of | ||
{error, not_found} -> | ||
{skip, "CETS is not configured"}; | ||
{ok, _} -> | ||
instrument_helper:start([{cets_info, #{}}]), | ||
Config | ||
end; | ||
init_per_group(system, Config) -> | ||
instrument_helper:start(instrument_helper:declared_events(mongoose_system_probe, [])), | ||
Config. | ||
|
||
end_per_group(_, _Config) -> | ||
instrument_helper:stop(). | ||
|
||
init_per_testcase(_, Config) -> | ||
Config. | ||
|
||
cets_info(_Config) -> | ||
instrument_helper:wait_and_assert_new(cets_info, #{}, fun check_cets_info/1). | ||
|
||
%% Check that values are integers and there are no unknown fields | ||
check_cets_info(Res) -> | ||
lists:all(fun(Name) -> is_integer(maps:get(Name, Res)) end, cets_metrics_names()) | ||
andalso #{} =:= maps:without(cets_metrics_names(), Res). | ||
|
||
cets_metrics_names() -> | ||
[available_nodes, | ||
unavailable_nodes, | ||
joined_nodes, | ||
discovered_nodes, | ||
discovery_works, | ||
remote_nodes_without_disco, | ||
remote_nodes_with_unknown_tables, | ||
remote_unknown_tables, | ||
remote_nodes_with_missing_tables, | ||
remote_missing_tables, | ||
conflict_nodes, | ||
conflict_tables]. | ||
|
||
system_up_time(_Config) -> | ||
instrument_helper:wait_and_assert_new(system_up_time, #{}, | ||
fun(#{seconds := Seconds}) -> Seconds > 0 end). | ||
|
||
system_tcp_ports(_Config) -> | ||
instrument_helper:wait_and_assert_new(system_tcp_ports, #{}, | ||
fun(#{count := Count}) -> Count > 0 end). | ||
|
||
system_process_queue_lengths(_Config) -> | ||
instrument_helper:wait_and_assert_new(system_process_queue_lengths, #{}, | ||
fun(#{total := Total}) -> Total >= 0 end). | ||
|
||
system_info(_Config) -> | ||
instrument_helper:wait_and_assert_new(system_info, #{}, fun check_system_info/1). | ||
|
||
%% There should be at least one process, port and ETS, and limits shouldn't be reached. | ||
check_system_info(#{port_count := PortCount, port_limit := PortLimit, | ||
process_count := ProcessCount, process_limit := ProcessLimit, | ||
ets_count := ETSCount, ets_limit := ETSLimit}) | ||
when PortCount > 0, PortLimit > PortCount, | ||
ProcessCount > 0, ProcessLimit > ProcessCount, | ||
ETSCount > 0, ETSLimit > ETSCount -> | ||
true. | ||
|
||
system_memory(_Config) -> | ||
instrument_helper:wait_and_assert_new(system_memory, #{}, fun check_system_memory/1). | ||
|
||
%% There should be all types of memory consumption, with the constraints explained | ||
%% in the docs for erlang:memory/0. | ||
check_system_memory( | ||
#{total := Total, atom := Atom, atom_used := AtomUsed, binary := Binary, code := Code, ets := ETS, | ||
processes := Processes, processes_used := ProcessesUsed, system := System}) | ||
when Total =:= Processes + System, Atom >= AtomUsed, AtomUsed > 0, Binary > 0, Code > 0, ETS > 0, | ||
Processes >= ProcessesUsed, System >= Atom + Binary + ETS -> | ||
true. | ||
|
||
system_dist_data(_Config) -> | ||
instrument_helper:wait_and_assert_new(system_dist_data, #{}, fun check_system_dist_data/1). | ||
|
||
%% There should be data sent and received already, and 2 connections at least (mim2, mim3). | ||
check_system_dist_data( | ||
#{connections := Connections, recv_oct := RecvOct, recv_cnt := RecvCnt, recv_max := RecvMax, | ||
send_oct := SendOct, send_cnt := SendCnt, send_max := SendMax, send_pend := SendPend}) | ||
when Connections >= 2, RecvOct > RecvCnt, RecvCnt > 0, RecvMax > 0, | ||
SendOct > SendCnt, SendCnt > 0, SendMax > 0, SendPend >= 0 -> | ||
true. | ||
|
||
restart_probes() -> | ||
lists:foreach(fun restart/1, [mongoose_instrument_probe_cets, mongoose_system_probe]). | ||
|
||
restart(Module) -> | ||
rpc_call(Module, stop, []), | ||
rpc_call(Module, start, []). |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters