Skip to content

Commit 47794a4

Browse files
Merge pull request #1122 from basho/feature-jv-giddyup_post_debug_logs
Upload debug logs to Giddyup
2 parents cfc61ca + cfccfdd commit 47794a4

File tree

3 files changed

+71
-7
lines changed

3 files changed

+71
-7
lines changed

src/riak_test_escript.erl

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,26 +297,45 @@ run_test(Test, Outdir, TestMetaData, Report, HarnessArgs, NumTests) ->
297297
1 -> keep_them_up;
298298
_ -> rt:teardown()
299299
end,
300-
CoverageFile = rt_cover:maybe_export_coverage(Test, CoverDir, erlang:phash2(TestMetaData)),
300+
CoverageFile = rt_cover:maybe_export_coverage(Test,
301+
CoverDir,
302+
erlang:phash2(TestMetaData)),
301303
case Report of
302304
undefined -> ok;
303305
_ ->
304-
{value, {log, L}, TestResult} = lists:keytake(log, 1, SingleTestResult),
306+
{value, {log, L}, TestResult} =
307+
lists:keytake(log, 1, SingleTestResult),
305308
case giddyup:post_result(TestResult) of
306309
error -> woops;
307310
{ok, Base} ->
308311
%% Now push up the artifacts, starting with the test log
309312
giddyup:post_artifact(Base, {"riak_test.log", L}),
310-
[ giddyup:post_artifact(Base, File) || File <- rt:get_node_logs() ],
311-
[giddyup:post_artifact(Base, {filename:basename(CoverageFile) ++ ".gz",
312-
zlib:gzip(element(2,file:read_file(CoverageFile)))}) || CoverageFile /= cover_disabled ],
313-
ResultPlusGiddyUp = TestResult ++ [{giddyup_url, list_to_binary(Base)}],
314-
[ rt:post_result(ResultPlusGiddyUp, WebHook) || WebHook <- get_webhooks() ]
313+
[giddyup:post_artifact(Base, File)
314+
|| File <- rt:get_node_logs()],
315+
maybe_post_debug_logs(Base),
316+
[giddyup:post_artifact(
317+
Base,
318+
{filename:basename(CoverageFile) ++ ".gz",
319+
zlib:gzip(element(2,file:read_file(CoverageFile)))})
320+
|| CoverageFile /= cover_disabled],
321+
ResultPlusGiddyUp = TestResult ++
322+
[{giddyup_url, list_to_binary(Base)}],
323+
[rt:post_result(ResultPlusGiddyUp, WebHook) ||
324+
WebHook <- get_webhooks()]
315325
end
316326
end,
317327
rt_cover:stop(),
318328
[{coverdata, CoverageFile} | SingleTestResult].
319329

330+
maybe_post_debug_logs(Base) ->
331+
case rt_config:get(giddyup_post_debug_logs, true) of
332+
true ->
333+
[giddyup:post_artifact(Base, File)
334+
|| File <- rt:get_node_debug_logs()];
335+
_ ->
336+
false
337+
end.
338+
320339
get_webhooks() ->
321340
Hooks = lists:foldl(fun(E, Acc) -> [parse_webhook(E) | Acc] end,
322341
[],

src/rt.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,9 @@ setup_harness(Test, Args) ->
18251825
get_node_logs() ->
18261826
?HARNESS:get_node_logs().
18271827

1828+
get_node_debug_logs() ->
1829+
?HARNESS:get_node_debug_logs().
1830+
18281831
%% @doc Performs a search against the log files on `Node' and returns all
18291832
%% matching lines.
18301833
-spec search_logs(node(), Pattern::iodata()) ->

src/rtdev.erl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
-define(DEVS(N), lists:concat(["dev", N, "@127.0.0.1"])).
2727
-define(DEV(N), list_to_atom(?DEVS(N))).
2828
-define(PATH, (rt_config:get(rtdev_path))).
29+
-define(DEBUG_LOG_FILE(N),
30+
"dev" ++ integer_to_list(N) ++ "@127.0.0.1-riak-debug.tar.gz").
2931

3032
get_deps() ->
3133
lists:flatten(io_lib:format("~s/dev/dev1/lib", [relpath(current)])).
@@ -52,6 +54,17 @@ riak_admin_cmd(Path, N, Args) ->
5254
ExecName = rt_config:get(exec_name, "riak"),
5355
io_lib:format("~s/dev/dev~b/bin/~s-admin ~s", [Path, N, ExecName, ArgStr]).
5456

57+
riak_debug_cmd(Path, N, Args) ->
58+
Quoted =
59+
lists:map(fun(Arg) when is_list(Arg) ->
60+
lists:flatten([$", Arg, $"]);
61+
(_) ->
62+
erlang:error(badarg)
63+
end, Args),
64+
ArgStr = string:join(Quoted, " "),
65+
ExecName = rt_config:get(exec_name, "riak"),
66+
io_lib:format("~s/dev/dev~b/bin/~s-debug ~s", [Path, N, ExecName, ArgStr]).
67+
5568
run_git(Path, Cmd) ->
5669
lager:info("Running: ~s", [gitcmd(Path, Cmd)]),
5770
{0, Out} = cmd(gitcmd(Path, Cmd)),
@@ -765,6 +778,35 @@ get_node_logs() ->
765778
{lists:nthtail(RootLen, Filename), Port}
766779
end || Filename <- filelib:wildcard(Root ++ "/*/dev/dev*/log/*") ].
767780

781+
get_node_debug_logs() ->
782+
NodeMap = rt_config:get(rt_nodes),
783+
rt:pmap(fun(Node) ->
784+
get_node_debug_logs(Node)
785+
end,
786+
NodeMap).
787+
788+
get_node_debug_logs({_Node, NodeNum}) ->
789+
DebugLogFile = ?DEBUG_LOG_FILE(NodeNum),
790+
delete_existing_debug_log_file(DebugLogFile),
791+
Path = relpath(node_version(NodeNum)),
792+
Args = ["--logs"],
793+
Cmd = riak_debug_cmd(Path, NodeNum, Args),
794+
{ExitCode, Result} = wait_for_cmd(spawn_cmd(Cmd)),
795+
case ExitCode of
796+
0 ->
797+
DebugLogFile;
798+
_ ->
799+
exit({ExitCode, Result})
800+
end.
801+
802+
%% If the debug log file exists from a previous test run it will cause the
803+
%% `riak_debug_cmd' to fail. Therefore, delete the `DebugLogFile' if it exists.
804+
%% Note that by ignoring the return value of `file:delete/1' this function
805+
%% works whether or not the `DebugLogFile' actually exists at the time it is
806+
%% called.
807+
delete_existing_debug_log_file(DebugLogFile) ->
808+
file:delete(DebugLogFile).
809+
768810
%% @doc Performs a search against the log files on `Node' and returns all
769811
%% matching lines.
770812
-spec search_logs(node(), Pattern::iodata()) ->

0 commit comments

Comments
 (0)