Skip to content

Commit 18fe0bf

Browse files
author
Brett Hazen
committed
Get GiddyUp consuming riak_test.log
- Have lager fire up an extra handler for each test run - Place lager output in riak_test.log and upload to GiddyUp - Remove rt.hrl and move the rt_webhook record into giddyup.erl - Remove unused GiddyUp code from escript - Let the test_runner know the name of the log directory so it knows where to put the riak_test.log - Add separate flag to rt_reporter to indicate the need to upload files to GiddyUp - Always copy log files to local directory before uploading to GiddyUp
1 parent 0a0e574 commit 18fe0bf

23 files changed

+125
-164
lines changed

include/rt.hrl

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/giddyup.erl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121

2222
-export([get_suite/1, post_result/1, post_artifact/2]).
2323
-define(STREAM_CHUNK_SIZE, 8192).
24-
-include("rt.hrl").
24+
25+
-record(rt_webhook, {
26+
name :: string(),
27+
url :: string(),
28+
headers=[] :: [{atom(), string()}]
29+
}).
2530

2631
-spec get_suite(string()) -> [{atom(), term()}].
2732
get_suite(Platform) ->

src/riak_test_escript.erl

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
%% @private
2222
-module(riak_test_escript).
23-
-include("rt.hrl").
2423
%% TODO: Temporary build workaround, remove!!
2524
-compile(export_all).
2625
-export([main/1]).
@@ -426,49 +425,7 @@ match_group_attributes(Attributes, Groups) ->
426425
%% TestCount) ||
427426
%% {Test, TestMetaData} <- Tests],
428427

429-
publish_report(_SingleTestResult, _CoverFile, undefined) ->
430-
ok;
431-
publish_report(SingleTestResult, CoverFile, _Report) ->
432-
{value, {log, Log}, TestResult} = lists:keytake(log, 1, SingleTestResult),
433-
publish_artifacts(TestResult,
434-
Log,
435-
CoverFile,
436-
giddyup:post_result(TestResult)).
437-
438-
publish_artifacts(_TestResult, _Log, _CoverFile, error) ->
439-
whoomp; %% there it is
440-
publish_artifacts(TestResult, Log, CoverFile, {ok, Base}) ->
441-
%% Now push up the artifacts, starting with the test log
442-
giddyup:post_artifact(Base, {"riak_test.log", Log}),
443-
[giddyup:post_artifact(Base, File) || File <- rt:get_node_logs()],
444-
post_cover_artifact(Base, CoverFile),
445-
ResultPlusGiddyUp = TestResult ++ [{giddyup_url, list_to_binary(Base)}],
446-
[rt:post_result(ResultPlusGiddyUp, WebHook) || WebHook <- get_webhooks()].
447-
448-
post_cover_artifact(_Base, cover_disabled) ->
449-
ok;
450-
post_cover_artifact(Base, CoverFile) ->
451-
CoverArchiveName = filename:basename(CoverFile) ++ ".gz",
452-
CoverArchive = zlib:gzip(element(2, file:read_file(CoverFile))),
453-
giddyup:post_artifact(Base, {CoverArchiveName, CoverArchive}).
454-
455-
get_webhooks() ->
456-
Hooks = lists:foldl(fun(E, Acc) -> [parse_webhook(E) | Acc] end,
457-
[],
458-
rt_config:get(webhooks, [])),
459-
lists:filter(fun(E) -> E =/= undefined end, Hooks).
460-
461-
parse_webhook(Props) ->
462-
Url = proplists:get_value(url, Props),
463-
case is_list(Url) of
464-
true ->
465-
#rt_webhook{url= Url,
466-
name=proplists:get_value(name, Props, "Webhook"),
467-
headers=proplists:get_value(headers, Props, [])};
468-
false ->
469-
lager:error("Invalid configuration for webhook : ~p", Props),
470-
undefined
471-
end.
428+
472429

473430
backend_list(Backend) when is_atom(Backend) ->
474431
atom_to_list(Backend);

src/riak_test_executor.erl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ init([Tests, LogDir, Platform, UpgradeList, NotifyPid]) ->
6363

6464
ContinueOnFail = rt_config:get(continue_on_fail),
6565

66-
LogLocation = case Platform of
67-
undefined -> LogDir;
68-
_ -> giddyup
66+
UploadToGiddyUp = case Platform of
67+
undefined -> false;
68+
_ -> true
6969
end,
70-
{ok, Reporter} = rt_reporter:start_link(LogLocation, NotifyPid),
70+
{ok, Reporter} = rt_reporter:start_link(UploadToGiddyUp, LogDir, NotifyPid),
7171

7272
lager:notice("Starting the Riak Test executor in ~p execution mode", [ExecutionMode]),
7373
State = #state{pending_tests=Tests,
@@ -169,14 +169,15 @@ launch_test({nodes, Nodes, NodeMap}, State) ->
169169
runner_pids=Pids,
170170
running_tests=Running,
171171
continue_on_fail=ContinueOnFail,
172-
reporter_pid=ReporterPid} = State,
172+
reporter_pid=ReporterPid,
173+
log_dir=LogDir} = State,
173174
NextTestModule = rt_test_plan:get_module(NextTestPlan),
174175
lager:debug("Executing test ~p in mode ~p", [NextTestModule, ExecutionMode]),
175176
{NextTestPlan, TestProps} = lists:keyfind(NextTestPlan, 1, PropertiesList),
176177
UpdTestProps = rt_properties:set([{node_map, NodeMap}, {node_ids, Nodes}],
177178
TestProps),
178179
{RunnerPids, RunningTests} = run_test(ExecutionMode, NextTestPlan, UpdTestProps,
179-
Pids, Running, ContinueOnFail, ReporterPid),
180+
Pids, Running, ContinueOnFail, ReporterPid, LogDir),
180181
UpdState = State#state{pending_tests=RestPending,
181182
execution_mode=ExecutionMode,
182183
runner_pids=RunnerPids,
@@ -318,11 +319,11 @@ override_props(State) ->
318319
[{upgrade_path, UpgradeList}]
319320
end.
320321

321-
-spec run_test(parallel | serial, atom(), proplists:proplist(), [pid()], [rt_test_plan:test_plan()], boolean(), pid()) -> {[pid()], [atom()]}.
322-
run_test(parallel, TestPlan, Properties, RunningPids, RunningTests, ContinueOnFail, ReporterPid) ->
323-
Pid = spawn_link(riak_test_runner, start, [TestPlan, Properties, ContinueOnFail, ReporterPid]),
322+
-spec run_test(parallel | serial, atom(), proplists:proplist(), [pid()], [rt_test_plan:test_plan()], boolean(), pid(), string()) -> {[pid()], [atom()]}.
323+
run_test(parallel, TestPlan, Properties, RunningPids, RunningTests, ContinueOnFail, ReporterPid, LogDir) ->
324+
Pid = spawn_link(riak_test_runner, start, [TestPlan, Properties, ContinueOnFail, ReporterPid, LogDir]),
324325
{[Pid | RunningPids], [TestPlan | RunningTests]};
325-
run_test(serial, TestPlan, Properties, RunningPids, RunningTests, ContinueOnFail, ReporterPid) ->
326-
riak_test_runner:start(TestPlan, Properties, ContinueOnFail, ReporterPid),
326+
run_test(serial, TestPlan, Properties, RunningPids, RunningTests, ContinueOnFail, ReporterPid, LogDir) ->
327+
riak_test_runner:start(TestPlan, Properties, ContinueOnFail, ReporterPid, LogDir),
327328
{RunningPids, RunningTests}.
328329

src/riak_test_runner.erl

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
-behavior(gen_fsm).
2525

2626
%% API
27-
-export([start/4,
27+
-export([start/5,
2828
send_event/2,
2929
stop/0]).
3030

@@ -48,7 +48,6 @@
4848
terminate/3,
4949
code_change/4]).
5050

51-
-include("rt.hrl").
5251
-include_lib("eunit/include/eunit.hrl").
5352

5453
-type test_type() :: {new | old}.
@@ -70,7 +69,8 @@
7069
remaining_versions :: [string()],
7170
test_results :: [term()],
7271
continue_on_fail :: boolean(),
73-
reporter_pid :: pid()}).
72+
log_dir :: string(),
73+
reporter_pids :: pid()}).
7474

7575
-deprecated([{metadata,0,next_major_release}]).
7676

@@ -79,8 +79,8 @@
7979
%%%===================================================================
8080

8181
%% @doc Start the test runner
82-
start(TestPlan, Properties, ContinueOnFail, ReporterPid) ->
83-
Args = [TestPlan, Properties, ContinueOnFail, ReporterPid],
82+
start(TestPlan, Properties, ContinueOnFail, ReporterPids, LogDir) ->
83+
Args = [TestPlan, Properties, ContinueOnFail, ReporterPids, LogDir],
8484
gen_fsm:start_link(?MODULE, Args, []).
8585

8686
send_event(Pid, Msg) ->
@@ -103,7 +103,7 @@ metadata() ->
103103

104104
%% @doc Read the storage schedule and go to idle.
105105
%% compose_test_datum(Version, Project, undefined, undefined) ->
106-
init([TestPlan, Properties, ContinueOnFail, ReporterPid]) ->
106+
init([TestPlan, Properties, ContinueOnFail, ReporterPid, LogDir]) ->
107107
lager:debug("Started riak_test_runnner with pid ~p (continue on fail: ~p)", [self(), ContinueOnFail]),
108108
Project = list_to_binary(rt_config:get(rt_project, "undefined")),
109109
Backend = rt_test_plan:get(backend, TestPlan),
@@ -144,7 +144,8 @@ init([TestPlan, Properties, ContinueOnFail, ReporterPid]) ->
144144
prereq_check=PreReqCheck,
145145
group_leader=group_leader(),
146146
continue_on_fail=ContinueOnFail,
147-
reporter_pid=ReporterPid},
147+
reporter_pids=ReporterPid,
148+
log_dir=LogDir},
148149
{ok, setup, State, 0}.
149150

150151
%% @doc there are no all-state events for this fsm
@@ -219,19 +220,22 @@ setup(_Event, _State) ->
219220
ok.
220221

221222
execute({nodes_deployed, _}, State) ->
222-
#state{test_module=TestModule,
223+
#state{test_plan=TestPlan,
224+
test_module=TestModule,
223225
test_type=TestType,
224226
properties=Properties,
225227
setup_modfun=SetupModFun,
226228
confirm_modfun=ConfirmModFun,
227-
test_timeout=TestTimeout} = State,
229+
test_timeout=TestTimeout,
230+
log_dir=OutDir} = State,
228231
lager:notice("Running ~s", [TestModule]),
229232
lager:notice("Properties: ~p", [Properties]),
230233

231234
StartTime = os:timestamp(),
232235
%% Perform test setup which includes clustering of the nodes if
233236
%% required by the test properties. The cluster information is placed
234237
%% into the properties record and returned by the `setup' function.
238+
start_lager_backend(rt_test_plan:get_name(TestPlan), OutDir),
235239
SetupResult = maybe_setup_test(TestModule, TestType, SetupModFun, Properties),
236240
UpdState = maybe_execute_test(SetupResult, TestModule, TestType, ConfirmModFun, StartTime, State),
237241

@@ -451,10 +455,22 @@ function_name(FunName, TestModule, Arity, Default) when is_atom(TestModule) ->
451455
{Default, FunName}
452456
end.
453457

454-
%% remove_lager_backend() ->
455-
%% gen_event:delete_handler(lager_event, lager_file_backend, []),
456-
%% gen_event:delete_handler(lager_event, riak_test_lager_backend, []).
458+
start_lager_backend(TestName, Outdir) ->
459+
LogLevel = rt_config:get(lager_level, info),
460+
case Outdir of
461+
undefined -> ok;
462+
_ ->
463+
gen_event:add_handler(lager_event, lager_file_backend,
464+
{filename:join([Outdir, TestName, "riak_test.log"]),
465+
LogLevel, 10485760, "$D0", 1}),
466+
lager:set_loglevel(lager_file_backend, LogLevel)
467+
end,
468+
gen_event:add_handler(lager_event, riak_test_lager_backend, [LogLevel, false]),
469+
lager:set_loglevel(riak_test_lager_backend, LogLevel).
457470

471+
stop_lager_backend() ->
472+
gen_event:delete_handler(lager_event, lager_file_backend, []),
473+
gen_event:delete_handler(lager_event, riak_test_lager_backend, []).
458474

459475
%% A return of `fail' must be converted to a non normal exit since
460476
%% status is determined by `rec_loop'.
@@ -508,6 +524,8 @@ report_cleanup_and_notify(Result, CleanUp, State=#state{test_plan=TestPlan,
508524
ResultMessage = test_result_message(Result),
509525
rt_reporter:send_result(test_result({TestPlan, ResultMessage, Duration})),
510526
maybe_cleanup(CleanUp, State),
527+
{ok, Logs} = stop_lager_backend(),
528+
_Log = unicode:characters_to_binary(Logs),
511529
Notification = {test_complete, TestPlan, self(), ResultMessage},
512530
riak_test_executor:send_event(Notification).
513531

src/rt.erl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
%% multiple independent tests.
2626
-module(rt).
2727
-deprecated(module).
28-
-include("rt.hrl").
2928
-include_lib("eunit/include/eunit.hrl").
3029

3130
-compile(export_all).
@@ -64,7 +63,7 @@
6463
expect_in_log/2,
6564
get_deps/0,
6665
get_ip/1,
67-
get_node_logs/1,
66+
get_node_logs/3,
6867
get_replica/5,
6968
get_ring/1,
7069
get_version/0,
@@ -1081,9 +1080,9 @@ setup_harness(_Test, _Args) ->
10811080

10821081
%% @doc Copy all of the nodes' log files to a local dir or
10831082
%% open a port to each file to upload to GiddyUp
1084-
-spec(get_node_logs(string() | giddyup) -> list()).
1085-
get_node_logs(DestDir) ->
1086-
rt2:get_node_logs(DestDir).
1083+
-spec(get_node_logs(boolean(), string(), string()) -> list()).
1084+
get_node_logs(UploadToGiddyUp, LogFile, DestDir) ->
1085+
rt2:get_node_logs(UploadToGiddyUp, LogFile, DestDir).
10871086

10881087
check_ibrowse() ->
10891088
rt2:check_ibrowse().

src/rt2.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
%% Please extend this module with new functions that prove useful between
2525
%% multiple independent tests.
2626
-module(rt2).
27-
-include("rt.hrl").
2827
-include_lib("eunit/include/eunit.hrl").
2928

3029
-compile(export_all).
@@ -39,7 +38,7 @@
3938
expect_in_log/2,
4039
get_deps/0,
4140
get_ip/1,
42-
get_node_logs/1,
41+
get_node_logs/3,
4342
get_replica/5,
4443
get_version/0,
4544
is_mixed_cluster/1,
@@ -611,8 +610,8 @@ setup_harness(Test, Args) ->
611610

612611
%% @doc Downloads any extant log files from the harness's running
613612
%% nodes.
614-
get_node_logs(DestDir) ->
615-
rt_harness:get_node_logs(DestDir).
613+
get_node_logs(UploadToGiddyUp, LogFile, DestDir) ->
614+
rt_harness:get_node_logs(UploadToGiddyUp, LogFile, DestDir).
616615

617616
check_ibrowse() ->
618617
try sys:get_status(ibrowse) of
@@ -630,6 +629,7 @@ check_ibrowse() ->
630629
%%% Bucket Types Functions
631630
%%%===================================================================
632631

632+
%% TODO: Determine if this can leverage riak_test_runner:start_lager_backend/2
633633
%% @doc Set up in memory log capture to check contents in a test.
634634
setup_log_capture(Nodes) when is_list(Nodes) ->
635635
rt:load_modules_on_nodes([riak_test_lager_backend], Nodes),

src/rt_aae.erl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
-export([wait_until_aae_trees_built/1]).
2525

26-
-include("rt.hrl").
27-
2826
wait_until_aae_trees_built(Nodes) ->
2927
lager:info("Wait until AAE builds all partition trees across ~p", [Nodes]),
3028
BuiltFun = fun() -> lists:foldl(aae_tree_built_fun(), true, Nodes) end,

src/rt_backend.erl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
%%
1919
%% -------------------------------------------------------------------
2020
-module(rt_backend).
21-
-include("rt.hrl").
2221
-include_lib("eunit/include/eunit.hrl").
2322

2423
-compile(export_all).

src/rt_bucket_types.erl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
wait_until_bucket_type_status/3,
2828
wait_until_bucket_props/3]).
2929

30-
-include("rt.hrl").
31-
3230
%% Specify the bucket_types field for the properties record. The list
3331
%% of bucket types may have two forms, a bucket_type or a pair
3432
%% consisting of an integer and a bucket_type. The latter form

0 commit comments

Comments
 (0)