Skip to content

Commit 759cf0c

Browse files
authored
Merge pull request #4416 from esl/fix-truncated-html-log
Fix truncated html log This PR addresses "MIM-2348 Logs are truncated on CI in the links. Increase max_no_bytes to 10 megabytes" Proposed changes include: Increase size of maximum log file size from 2MB to 10MB. Disable detailed logs for global distribution - this would reduce amount of logs. And still there is too much noise in logs from GD trying to stop connections - changed the loglevel, if connections are stopped because of shutdown. Enable logs for mim2/mim3 - but without printing INIT/DONE for tests (that is configurable). Reason is to debug clustering logic, which is often fails on CI nowadays. We used to disable html logs for mim2/mim3 because it breaks --one-node flag in test-runner. But now we check if the node is running, and if not - the hook would not do anything. Example of INIT/DONE: INIT suite=mod_http_upload_SUITE group=mod_http_upload_s3 testcase=get_url_ends_with_filename DONE suite=mod_http_upload_SUITE group=mod_http_upload_s3 testcase=get_url_ends_with_filename
2 parents d8bb43d + 97088ea commit 759cf0c

File tree

8 files changed

+85
-25
lines changed

8 files changed

+85
-25
lines changed

big_tests/default.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@
130130
%% ct_mongoose_hook will:
131131
%% * ensure preset & mim_data_dir values are passed to ct Config
132132
%% * check server's purity after SUITE
133-
{ct_hooks, [ct_groups_summary_hook, ct_tty_hook, ct_mongoose_hook, ct_progress_hook,
133+
{ct_hooks, [ct_groups_summary_hook, ct_tty_hook,
134+
ct_mongoose_hook,
135+
{ct_mongoose_log_hook, [{host, mim2}, {print_init_and_done_for_testcases, false}]},
136+
{ct_mongoose_log_hook, [{host, mim3}, {print_init_and_done_for_testcases, false}]},
137+
ct_progress_hook,
134138
ct_markdown_errors_hook, ct_mongoose_log_hook]}.
135139

136140
%% since test-runner.sh can be executed with the --one-node option,

big_tests/dynamic_domains.spec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@
174174
%% * ensure preset & mim_data_dir values are passed to ct Config
175175
%% * check server's purity after SUITE
176176
{ct_hooks, [ct_groups_summary_hook, ct_tty_hook, ct_mongoose_hook, ct_progress_hook,
177-
ct_markdown_errors_hook, ct_mongoose_log_hook]}.
177+
ct_markdown_errors_hook,
178+
ct_mongoose_log_hook,
179+
{ct_mongoose_log_hook, [{host, mim2}, {print_init_and_done_for_testcases, false}]},
180+
{ct_mongoose_log_hook, [{host, mim3}, {print_init_and_done_for_testcases, false}]}]}.
178181

179182
%% since test-runner.sh can be executed with the --one-node option,
180183
%% log collection is enabled by default for host mim1 only.

big_tests/mam.spec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
%% ct_mongoose_hook will:
2424
%% * ensure preset & mim_data_dir values are passed to ct Config
2525
%% * check server's purity after SUITE
26-
{ct_hooks, [ct_groups_summary_hook, ct_tty_hook, ct_mongoose_hook, ct_progress_hook,
26+
{ct_hooks, [ct_groups_summary_hook, ct_tty_hook, ct_mongoose_hook,
27+
ct_progress_hook,
28+
{ct_mongoose_log_hook, [{host, mim2}, {print_init_and_done_for_testcases, false}]},
29+
{ct_mongoose_log_hook, [{host, mim3}, {print_init_and_done_for_testcases, false}]},
2730
ct_markdown_errors_hook, ct_mongoose_log_hook]}.
2831

2932
%% since test-runner.sh can be executed with the --one-node option,

big_tests/src/ct_mongoose_log_hook.erl

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
-export([pre_init_per_testcase/3]).
3434
-export([post_end_per_testcase/4]).
3535

36-
-record(state, { node_name, reader, writer,
36+
-record(state, { print_init_and_done_for_testcases,
37+
node_name, reader, writer,
3738
current_line_num, out_file, url_file, group, suite,
3839
log_flags = [] }).
3940
-include_lib("exml/include/exml.hrl").
@@ -48,30 +49,42 @@ id(Opts) ->
4849
init(_Id, Opts) ->
4950
Node = connect_mim_node(Opts),
5051
LogFlags = proplists:get_value(log, Opts, [suite]),
51-
{ok, #state{ node_name=Node, log_flags=LogFlags }}.
52+
PrintInitDone = proplists:get_value(print_init_and_done_for_testcases, Opts),
53+
{ok, #state{ node_name=Node, log_flags=LogFlags,
54+
print_init_and_done_for_testcases = PrintInitDone }}.
5255

5356
%% @doc Called before init_per_suite is called.
54-
pre_init_per_suite(Suite,Config,State) ->
57+
pre_init_per_suite(_Suite, Config, State = #state{node_name = undefined}) ->
58+
{Config, State};
59+
pre_init_per_suite(Suite, Config, State) ->
5560
maybe_print_log_on_mim_node(suite, starting, Suite, State),
5661
{Config, State#state{group=no_group, suite=Suite}}.
5762

5863
%% @doc Called before end_per_suite.
59-
post_end_per_suite(Suite,_Config,Return,State) ->
64+
post_end_per_suite(_Suite, Config, Return, State = #state{node_name = undefined}) ->
65+
{Config, State};
66+
post_end_per_suite(Suite, _Config, Return, State) ->
6067
maybe_print_log_on_mim_node(suite, finishing, Suite, State),
6168
{Return, State#state{suite=no_suite}}.
6269

6370
%% @doc Called before each init_per_group.
64-
pre_init_per_group(Group,Config,State) ->
71+
pre_init_per_group(_Group, Config, State = #state{node_name = undefined}) ->
72+
{Config, State};
73+
pre_init_per_group(Group, Config, State) ->
6574
maybe_print_log_on_mim_node(group, starting, Group, State),
6675
{Config, State#state{group=Group}}.
6776

6877
%% @doc Called after each end_per_group.
69-
post_end_per_group(Group,_Config,Return,State) ->
78+
post_end_per_group(_Group, _Config, Return, State = #state{node_name = undefined}) ->
79+
{Return, State};
80+
post_end_per_group(Group, _Config, Return, State) ->
7081
maybe_print_log_on_mim_node(group, finishing, Group, State),
7182
{Return, State#state{group=no_group}}.
7283

7384
%% @doc Called before each test case.
74-
pre_init_per_testcase(TC,Config,State=#state{}) ->
85+
pre_init_per_testcase(_TC, Config, State = #state{node_name = undefined}) ->
86+
{Config, State};
87+
pre_init_per_testcase(TC, Config, State=#state{}) ->
7588
maybe_print_log_on_mim_node(testcase, starting, TC, State),
7689
Dog = test_server:timetrap(test_server:seconds(10)),
7790
State3 = ensure_initialized(Config, State),
@@ -80,14 +93,18 @@ pre_init_per_testcase(TC,Config,State=#state{}) ->
8093
{Config, State4}.
8194

8295
%% @doc Called after each test case.
83-
post_end_per_testcase(TC,_Config,Return,State) ->
96+
post_end_per_testcase(_TC, _Config, Return, State = #state{node_name = undefined}) ->
97+
{Return, State};
98+
post_end_per_testcase(TC, _Config, Return, State) ->
8499
Dog = test_server:timetrap(test_server:seconds(10)),
85100
State2 = post_insert_line_numbers_into_report(State, TC),
86101
test_server:timetrap_cancel(Dog),
87102
maybe_print_log_on_mim_node(testcase, finishing, TC, State),
88103
{Return, State2 }.
89104

90105
%% @doc Called when the scope of the CTH is done
106+
terminate(State = #state{node_name = undefined}) ->
107+
State;
91108
terminate(State) ->
92109
insert_line_numbers_into_report(State).
93110

@@ -183,7 +200,7 @@ pre_insert_line_numbers_into_report(State=#state{node_name=Node, reader=Reader,
183200
Message = io_lib:format(
184201
"<font color=gray>INIT suite=~p group=~p testcase=~p</font>~n",
185202
[Suite, Group, TC]),
186-
file:write(Writer, Message),
203+
maybe_file_write(State, Writer, Message),
187204
State#state{current_line_num=CurrentLineNum2}.
188205

189206
post_insert_line_numbers_into_report(State=#state{writer=undefined}, _TC) ->
@@ -192,12 +209,17 @@ post_insert_line_numbers_into_report(State=#state{node_name=Node, reader=Reader,
192209
current_line_num=CurrentLineNum, url_file=UrlFile,
193210
group=Group, suite=Suite}, TC) ->
194211
CurrentLineNum2 = read_and_write_lines(Node, Reader, Writer, CurrentLineNum),
195-
add_log_link_to_line(UrlFile, CurrentLineNum2, Node, " when finished"),
212+
case CurrentLineNum of
213+
CurrentLineNum2 ->
214+
skip; %% Reduce noise in logs because nothing was logged
215+
_ ->
216+
add_log_link_to_line(UrlFile, CurrentLineNum2, Node, " when finished")
217+
end,
196218
%% Write a message after the main part
197219
Message = io_lib:format(
198220
"<font color=gray>DONE suite=~p group=~p testcase=~p</font>~n",
199221
[Suite, Group, TC]),
200-
file:write(Writer, Message),
222+
maybe_file_write(State, Writer, Message),
201223
State#state{current_line_num=CurrentLineNum2}.
202224

203225
insert_line_numbers_into_report(State=#state{node_name=Node, reader=Reader, writer=Writer,
@@ -288,9 +310,13 @@ connect_mim_node(HookOpts) ->
288310
erlang:set_cookie(Node, Cookie),
289311
%% this log message lands at misc_io.log.html file
290312
ct:pal("connecting to the '~p' node (cookie: '~p')", [Node, Cookie]),
291-
%% crash if cannot connect to the node
292-
true = net_kernel:connect_node(Node),
293-
Node.
313+
case net_kernel:connect_node(Node) of
314+
true ->
315+
Node;
316+
_ ->
317+
%% Could happen if we test not with all nodes enabled.
318+
undefined
319+
end.
294320

295321
maybe_print_log_on_mim_node(Type, Event, Name, #state{log_flags = LogFlags, node_name = Node}) ->
296322
ValidEvents = [starting, finishing],
@@ -307,3 +333,8 @@ maybe_print_log_on_mim_node(Type, Event, Name, #state{log_flags = LogFlags, node
307333
_ ->
308334
ok
309335
end.
336+
337+
maybe_file_write(State = #state{print_init_and_done_for_testcases = true}, Writer, Message) ->
338+
file:write(Writer, Message);
339+
maybe_file_write(_State, _Writer, _Message) ->
340+
ok.

big_tests/tests/mod_global_distrib_SUITE.erl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,11 +1441,17 @@ print_sessions_debug_info(NodeName) ->
14411441
%% -----------------------------------------------------------------------
14421442
%% Custom log levels for GD modules during the tests
14431443

1444+
%% Set it to true, if you need to debug GD on CI
1445+
detailed_logging() ->
1446+
false.
1447+
14441448
enable_logging() ->
1445-
mim_loglevel:enable_logging(test_hosts(), custom_loglevels()).
1449+
detailed_logging() andalso
1450+
mim_loglevel:enable_logging(test_hosts(), custom_loglevels()).
14461451

14471452
disable_logging() ->
1448-
mim_loglevel:disable_logging(test_hosts(), custom_loglevels()).
1453+
detailed_logging() andalso
1454+
mim_loglevel:disable_logging(test_hosts(), custom_loglevels()).
14491455

14501456
custom_loglevels() ->
14511457
%% for "s2s connection to muc.localhost not found" debugging

rel/files/app.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
file => "{{mongooseim_log_dir}}/mongooseim.log",
4343
type => wrap,
4444
max_no_files => 5,
45-
max_no_bytes => 2097152,
45+
max_no_bytes => 10485760, %% 10 Megabytes
4646
sync_mode_qlen => 2000, % If sync_mode_qlen is set to the same value as drop_mode_qlen,
4747
drop_mode_qlen => 2000, % synchronous mode is disabled. That is, the handler always runs
4848
flush_qlen => 5000, % in asynchronous mode, unless dropping or flushing is invoked.

src/global_distrib/mod_global_distrib_connection.erl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,14 @@ code_change(_OldVsn, State, _Extra) ->
108108
{ok, State}.
109109

110110
terminate(Reason, State) ->
111-
?LOG_ERROR(#{what => gd_outgoing_socket_error,
112-
reason => Reason, peer => State#state.peer, conn_id => State#state.conn_id}),
111+
case Reason of
112+
shutdown ->
113+
?LOG_INFO(#{what => gd_outgoing_socket_error,
114+
reason => Reason, peer => State#state.peer, conn_id => State#state.conn_id});
115+
_ ->
116+
?LOG_ERROR(#{what => gd_outgoing_socket_error,
117+
reason => Reason, peer => State#state.peer, conn_id => State#state.conn_id})
118+
end,
113119
mongoose_instrument:execute(?GLOBAL_DISTRIB_OUTGOING_CLOSED, #{}, #{count => 1, host => State#state.host}),
114120
catch mod_global_distrib_transport:close(State#state.socket),
115121
ignore.

src/global_distrib/mod_global_distrib_receiver.erl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,16 @@ code_change(_Version, State, _Extra) ->
135135
{ok, State}.
136136

137137
terminate(Reason, State) ->
138-
?LOG_WARNING(#{what => gd_incoming_socket_closed,
139-
peer => State#state.peer, server => State#state.host,
140-
reason => Reason, conn_id => State#state.conn_id}),
138+
case Reason of
139+
normal ->
140+
?LOG_INFO(#{what => gd_incoming_socket_closed,
141+
peer => State#state.peer, server => State#state.host,
142+
reason => Reason, conn_id => State#state.conn_id});
143+
_ ->
144+
?LOG_WARNING(#{what => gd_incoming_socket_closed,
145+
peer => State#state.peer, server => State#state.host,
146+
reason => Reason, conn_id => State#state.conn_id})
147+
end,
141148
mongoose_instrument:execute(?GLOBAL_DISTRIB_INCOMING_CLOSED, #{},
142149
#{count => 1, host => State#state.host}),
143150
catch mod_global_distrib_transport:close(State#state.socket),

0 commit comments

Comments
 (0)