Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stanchion stats test for API and command #1199

Merged
merged 2 commits into from
Jul 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions riak_test/src/rtcs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ cs_port(N) when is_integer(N) ->
cs_port(Node) ->
cs_port(rt_cs_dev:node_id(Node)).

stanchion_port() -> 9095.

riak_config(CustomConfig) ->
orddict:merge(fun(_, LHS, RHS) -> LHS ++ RHS end,
Expand Down Expand Up @@ -322,7 +323,7 @@ previous_cs_config(UserExtra, OtherApps) ->
{proxy_get, enabled},
{anonymous_user_creation, true},
{riak_pb_port, 10017},
{stanchion_port, 9095},
{stanchion_port, stanchion_port()},
{cs_version, 010300}
]
}] ++ OtherApps.
Expand All @@ -347,7 +348,7 @@ cs_config(UserExtra, OtherApps) ->
{block_get_max_retries, 1},
{proxy_get, enabled},
{anonymous_user_creation, true},
{stanchion_host, {"127.0.0.1", 9095}},
{stanchion_host, {"127.0.0.1", stanchion_port()}},
{riak_host, {"127.0.0.1", 10017}},
{cs_version, 010300}
]
Expand All @@ -372,7 +373,7 @@ previous_stanchion_config() ->
lager_config(),
{stanchion,
[
{stanchion_port, 9095},
{stanchion_port, stanchion_port()},
{riak_pb_port, 10017}
]
}].
Expand All @@ -387,11 +388,11 @@ stanchion_config() ->
lager_config(),
{stanchion,
[
{host, {"127.0.0.1", 9095}},
{host, {"127.0.0.1", stanchion_port()}},
{riak_host, {"127.0.0.1", 10017}}
]
}].

stanchion_config(UserExtra) ->
lists:foldl(fun({Key,Value}, Config0) ->
replace_stanchion_config(Key,Value,Config0)
Expand Down Expand Up @@ -438,6 +439,9 @@ riakcs_logpath(Prefix, N, File) ->
riakcscmd(Path, N, Cmd) ->
lists:flatten(io_lib:format("~s ~s", [riakcs_binpath(Path, N), Cmd])).

riakcs_statuscmd(Path, N) ->
lists:flatten(io_lib:format("~s-admin status", [riakcs_binpath(Path, N)])).

riakcs_switchcmd(Path, N, Cmd) ->
lists:flatten(io_lib:format("~s-admin stanchion ~s", [riakcs_binpath(Path, N), Cmd])).

Expand All @@ -459,6 +463,9 @@ stanchion_etcpath(Prefix) ->
stanchioncmd(Path, Cmd) ->
lists:flatten(io_lib:format("~s ~s", [stanchion_binpath(Path), Cmd])).

stanchion_statuscmd(Path) ->
lists:flatten(io_lib:format("~s-admin status", [stanchion_binpath(Path)])).

riak_root_and_vsn(current, oss) -> {?RIAK_ROOT, current};
riak_root_and_vsn(current, ee) -> {?EE_ROOT, ee_current};
riak_root_and_vsn(previous, oss) -> {?RIAK_ROOT, previous};
Expand Down Expand Up @@ -1013,10 +1020,17 @@ pbc({multibag, _} = Flavor, ObjectKind, RiakNodes, Opts) ->
rtcs_bag:pbc(Flavor, ObjectKind, RiakNodes, Opts).

make_authorization(Method, Resource, ContentType, Config, Date) ->
make_authorization(s3, Method, Resource, ContentType, Config, Date).

make_authorization(Type, Method, Resource, ContentType, Config, Date) ->
StringToSign = [Method, $\n, [], $\n, ContentType, $\n, Date, $\n, Resource],
Signature =
base64:encode_to_string(sha_mac(Config#aws_config.secret_access_key, StringToSign)),
lists:flatten(["AWS ", Config#aws_config.access_key_id, $:, Signature]).
Prefix = case Type of
s3 -> "AWS";
velvet -> "MOSS"
end,
lists:flatten([Prefix, " ", Config#aws_config.access_key_id, $:, Signature]).

sha_mac(Key,STS) -> crypto:hmac(sha, Key,STS).
sha(Bin) -> crypto:hash(sha, Bin).
Expand Down
2 changes: 1 addition & 1 deletion riak_test/tests/external_client_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cs_config() ->
{proxy_get, enabled},
{anonymous_user_creation, true},
{riak_host, {"127.0.0.1", 10017}},
{stanchion_host, {"127.0.0.1", 9095}},
{stanchion_host, {"127.0.0.1", rtcs:stanchion_port()}},
{cs_version, 010300},
{enforce_multipart_part_size, false},
{max_buckets_per_user, 300},
Expand Down
2 changes: 1 addition & 1 deletion riak_test/tests/legacy_s3_rewrite_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ cs_config() ->
{proxy_get, enabled},
{anonymous_user_creation, true},
{riak_host, {"127.0.0.1", 10017}},
{stanchion_host, {"127.0.0.1", 9095}},
{stanchion_host, {"127.0.0.1", rtcs:stanchion_port()}},
{cs_version, 010300},
{enforce_multipart_part_size, false},
{max_buckets_per_user, 150},
Expand Down
147 changes: 104 additions & 43 deletions riak_test/tests/stats_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,53 +24,22 @@
-include_lib("eunit/include/eunit.hrl").
-include_lib("erlcloud/include/erlcloud_aws.hrl").

-define(TEST_BUCKET, "riak-test-bucket").

confirm() ->
{UserConfig, {RiakNodes, _CSNodes, _Stanchion}} = rtcs:setup(1),

confirm_initial_stats(query_stats(UserConfig, rtcs:cs_port(hd(RiakNodes)))),

lager:info("creating bucket ~p", [?TEST_BUCKET]),
?assertEqual(ok, erlcloud_s3:create_bucket(?TEST_BUCKET, UserConfig)),

?assertMatch([{buckets, [[{name, ?TEST_BUCKET}, _]]}],
erlcloud_s3:list_buckets(UserConfig)),
lager:info("Confirming initial stats"),
confirm_initial_stats(cs, UserConfig, rtcs:cs_port(hd(RiakNodes))),
confirm_initial_stats(stanchion, UserConfig, rtcs:stanchion_port()),

Object = crypto:rand_bytes(500),
erlcloud_s3:put_object(?TEST_BUCKET, "object_one", Object, UserConfig),
erlcloud_s3:get_object(?TEST_BUCKET, "object_one", UserConfig),
erlcloud_s3:delete_object(?TEST_BUCKET, "object_one", UserConfig),
erlcloud_s3:list_buckets(UserConfig),
do_some_api_calls(UserConfig, "bucket1", "bucket2"),

lager:info("Confirming stats"),
Stats1 = query_stats(UserConfig, rtcs:cs_port(hd(RiakNodes))),
_Stats2 = status_cmd(),
confirm_stat_count(Stats1, <<"service_get_out_one">>, 2),
confirm_stat_count(Stats1, <<"object_get_out_one">>, 1),
confirm_stat_count(Stats1, <<"object_put_out_one">>, 1),
confirm_stat_count(Stats1, <<"object_delete_out_one">>, 1),
lager:info("Confirming stats after some operations"),
confirm_stats(cs, UserConfig, rtcs:cs_port(hd(RiakNodes))),
confirm_stats(stanchion, UserConfig, rtcs:stanchion_port()),
rtcs:pass().

status_cmd() ->
Cmd = rtcs:riakcscmd(rtcs:get_rt_config(cs, current),
1, "status"),
os:cmd(Cmd).

query_stats(UserConfig, Port) ->
lager:debug("Querying stats"),
Date = httpd_util:rfc1123_date(),
Resource = "/riak-cs/stats",
Cmd="curl -s -H 'Date: " ++ Date ++ "' -H 'Authorization: " ++
rtcs:make_authorization("GET", Resource, [], UserConfig, Date) ++ "' http://localhost:" ++
integer_to_list(Port) ++ Resource,
lager:info("Stats query cmd: ~p", [Cmd]),
Output = os:cmd(Cmd),
lager:debug("Stats output=~p~n",[Output]),
{struct, JsonData} = mochijson2:decode(Output),
JsonData.

confirm_initial_stats(StatData) ->
confirm_initial_stats(cs, UserConfig, Port) ->
StatData = query_stats(cs, UserConfig, Port),
lager:debug("length(StatData) = ~p", [length(StatData)]),
?assert(1125 < length(StatData)),
[begin
Expand All @@ -95,12 +64,104 @@ confirm_initial_stats(StatData) ->
"riakc_put_block",
"riakc_delete_block_constrained"
]],

lager:debug("~p", [proplists:get_value(<<"request_pool_workers">>, StatData)]),
?assertEqual(1, proplists:get_value(<<"velvet_create_user_in_one">>, StatData)),
?assertEqual(rtcs:request_pool_size() - 1,
proplists:get_value(<<"request_pool_workers">>, StatData)),
?assertEqual(rtcs:bucket_list_pool_size(),
proplists:get_value(<<"bucket_list_pool_workers">>, StatData)).
proplists:get_value(<<"bucket_list_pool_workers">>, StatData));

confirm_initial_stats(stanchion, UserConfig, Port) ->
Stats = query_stats(stanchion, UserConfig, Port),
lager:debug("length(Stats) = ~p", [length(Stats)]),
?assert(160 < length(Stats)),
[begin
StatKey = list_to_binary(StatType ++ "_one"),
lager:debug("StatKey: ~p~n", [StatKey]),
?assert(proplists:is_defined(StatKey, Stats)),
Value = proplists:get_value(StatKey, Stats),
?assertEqual(0, Value)
end || StatType <- ["bucket_create",
"bucket_delete",
"bucket_put_acl",
"riakc_get_cs_bucket",
"riakc_delete_cs_bucket",
"riakc_get_cs_user",
"riakc_list_all_manifest_keys",
"riakc_list_all_user_keys"
]],
confirm_stat_count(Stats, <<"user_create_one">>, 1),
confirm_stat_count(Stats, <<"riakc_put_cs_user_one">>, 1),

?assert(proplists:is_defined(<<"waiting_time_mean">>, Stats)),
?assert(proplists:is_defined(<<"waiting_time_median">>, Stats)),
?assert(proplists:is_defined(<<"waiting_time_95">>, Stats)),
?assert(proplists:is_defined(<<"waiting_time_99">>, Stats)),
?assert(proplists:is_defined(<<"waiting_time_100">>, Stats)),
?assert(proplists:is_defined(<<"sys_process_count">>, Stats)),
?assert(proplists:is_defined(<<"webmachine_mochiweb_active_sockets">>, Stats)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer adding waiting_time_(95|99|100|mean|median) to this sequence of confirmation because they're most important items in Stanchion.

ok.

confirm_stats(cs, UserConfig, Port) ->
confirm_status_cmd(cs, "service_get_in_one"),
Stats = query_stats(cs, UserConfig, Port),
confirm_stat_count(Stats, <<"service_get_out_one">>, 2),
confirm_stat_count(Stats, <<"object_get_out_one">>, 1),
confirm_stat_count(Stats, <<"object_put_out_one">>, 1),
confirm_stat_count(Stats, <<"object_delete_out_one">>, 1);
confirm_stats(stanchion, UserConfig, Port) ->
confirm_status_cmd(stanchion, "bucket_create_one"),
Stats = query_stats(stanchion, UserConfig, Port),
confirm_stat_count(Stats, <<"user_create_one">>, 1),
confirm_stat_count(Stats, <<"bucket_create_one">>, 2),
confirm_stat_count(Stats, <<"bucket_delete_one">>, 1),
confirm_stat_count(Stats, <<"riakc_put_cs_user_one">>, 1),
confirm_stat_count(Stats, <<"riakc_put_cs_bucket_one">>, 3),
%% this heavy list/gets can be reduced to ONE per delete-bucket (/-o-)/ ⌒ ┤
confirm_stat_count(Stats, <<"riakc_list_all_manifest_keys_one">>, 2).

do_some_api_calls(UserConfig, Bucket1, Bucket2) ->
?assertEqual(ok, erlcloud_s3:create_bucket(Bucket1, UserConfig)),

?assertMatch([{buckets, [[{name, Bucket1}, _]]}],
erlcloud_s3:list_buckets(UserConfig)),

Object = crypto:rand_bytes(500),
erlcloud_s3:put_object(Bucket1, "object_one", Object, UserConfig),
erlcloud_s3:get_object(Bucket1, "object_one", UserConfig),
erlcloud_s3:delete_object(Bucket1, "object_one", UserConfig),
erlcloud_s3:list_buckets(UserConfig),

?assertEqual(ok, erlcloud_s3:create_bucket(Bucket2, UserConfig)),
?assertEqual(ok, erlcloud_s3:delete_bucket(Bucket2, UserConfig)),
ok.

query_stats(Type, UserConfig, Port) ->
lager:debug("Querying stats to ~p", [Type]),
Date = httpd_util:rfc1123_date(),
{Resource, SignType} = case Type of
cs -> {"/riak-cs/stats", s3};
stanchion -> {"/stats", velvet}
end,
Cmd="curl -s -H 'Date: " ++ Date ++ "' -H 'Authorization: " ++
rtcs:make_authorization(SignType, "GET", Resource, [], UserConfig, Date) ++
"' http://localhost:" ++
integer_to_list(Port) ++ Resource,
lager:info("Stats query cmd: ~p", [Cmd]),
Output = os:cmd(Cmd),
lager:debug("Stats output=~p~n",[Output]),
{struct, JsonData} = mochijson2:decode(Output),
JsonData.

confirm_stat_count(StatData, StatType, ExpectedCount) ->
lager:debug("confirm_stat_count for ~p", [StatType]),
?assertEqual(ExpectedCount, proplists:get_value(StatType, StatData)).

confirm_status_cmd(Type, ExpectedToken) ->
Cmd = case Type of
cs ->
rtcs:riakcs_statuscmd(rtcs:get_rt_config(cs, current), 1);
stanchion ->
rtcs:stanchion_statuscmd(rtcs:get_rt_config(stanchion, current))
end,
Res = os:cmd(Cmd),
?assert(string:str(Res, ExpectedToken) > 0).
2 changes: 1 addition & 1 deletion riak_test/tests/too_large_entity_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ cs_config() ->
{proxy_get, enabled},
{anonymous_user_creation, true},
{riak_host, {"127.0.0.1", 10017}},
{stanchion_host, {"127.0.0.1", 9095}},
{stanchion_host, {"127.0.0.1", rtcs:stanchion_port()}},
{cs_version, 010300},
{max_content_length, 1000},
{enforce_multipart_part_size, false}
Expand Down