Skip to content

Commit

Permalink
MB-47869: Fix CE/EE service listing and ram quotas
Browse files Browse the repository at this point in the history
The UI already filters out enterprise-only services in newer versions,
but ns_server continued to return data for eventing and analytics in
CE mode. This patch fixes that as well as the tests that broke due to
this change.

Change-Id: I76072c80121a4038ee7b71305a73111c601ca6c5
Reviewed-on: http://review.couchbase.org/c/ns_server/+/159550
Well-Formed: Build Bot <build@couchbase.com>
Reviewed-by: Steve Watanabe <steve.watanabe@couchbase.com>
Tested-by: Build Bot <build@couchbase.com>
  • Loading branch information
bryandmc committed Aug 19, 2021
1 parent a55f63d commit cdcd59f
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 48 deletions.
110 changes: 72 additions & 38 deletions src/auto_failover_logic.erl
Expand Up @@ -537,8 +537,24 @@ service_failover_min_node_count(backup) ->


-ifdef(TEST).
mock_out_compat_mode(Fun) ->
mock_out_compat_mode(Fun, true).

mock_out_compat_mode(Fun, Val) ->
meck:new(cluster_compat_mode, [passthrough]),
meck:expect(cluster_compat_mode, is_enterprise, fun () -> Val end),
Resp = try
Fun()
catch Error ->
throw(Error)
after
meck:unload(cluster_compat_mode)
end,
Resp.

service_failover_min_node_count_test() ->
Services = ns_cluster_membership:supported_services(),
Services = mock_out_compat_mode(
?cut(ns_cluster_membership:supported_services())),
lists:foreach(
fun (Service) ->
true = is_integer(service_failover_min_node_count(Service))
Expand Down Expand Up @@ -581,13 +597,15 @@ expect_mail_down_warnings(Nodes, {Actions, State}) ->
State.

basic_kv_1_test() ->
functools:chain(
test_init(3),
[?cut(expect_no_actions(test_frame(1, [a, b, c], [], _))),
?cut(expect_failover(b, test_frame(6, [a, b, c], [b], _)))]).
mock_out_compat_mode(
?cut(functools:chain(
test_init(3),
[?cut(expect_no_actions(test_frame(1, [a, b, c], [], _))),
?cut(expect_failover(b, test_frame(6, [a, b, c], [b], _)))]))).

basic_kv_2_test() ->
expect_failover(b, test_frame(7, [a, b, c], [b], test_init(4))).
mock_out_compat_mode(
?cut(expect_failover(b, test_frame(7, [a, b, c], [b], test_init(4))))).

min_size_test_body(Threshold) ->
{Actions, State} = test_frame(Threshold + 3, [a, b], [b],
Expand All @@ -596,51 +614,67 @@ min_size_test_body(Threshold) ->
test_frame(30, [a, b], [b], State).

min_size_test() ->
min_size_test_body(2),
min_size_test_body(3),
min_size_test_body(4).
mock_out_compat_mode(
fun () ->
min_size_test_body(2),
min_size_test_body(3),
min_size_test_body(4)
end).

min_size_and_increasing_test() ->
S = expect_no_actions(min_size_test_body(2)),
expect_failover(b, test_frame(5, [a, b, c], [b], S)).
mock_out_compat_mode(
fun () ->
S = expect_no_actions(min_size_test_body(2)),
expect_failover(b, test_frame(5, [a, b, c], [b], S))
end).

other_down_test() ->
Nodes = [a, b, c],
functools:chain(
test_init(3),
[?cut(expect_no_actions(test_frame(5, Nodes, [b], _))),
?cut(expect_mail_down_warnings([b], test_frame(1, Nodes, [b, c], _))),
?cut(expect_failover(b, test_frame(2, Nodes, [b], _))),
?cut(expect_no_actions(test_frame(1, Nodes, [b, c], _))),
?cut(expect_failover(b, test_frame(1, Nodes, [b], _)))]).
mock_out_compat_mode(
?cut(functools:chain(
test_init(3),
[?cut(expect_no_actions(test_frame(5, Nodes, [b], _))),
?cut(expect_mail_down_warnings([b], test_frame(1, Nodes, [b, c], _))),
?cut(expect_failover(b, test_frame(2, Nodes, [b], _))),
?cut(expect_no_actions(test_frame(1, Nodes, [b, c], _))),
?cut(expect_failover(b, test_frame(1, Nodes, [b], _)))]))).

two_down_at_same_time_test() ->
Nodes = [a, b, c, d],
functools:chain(
test_init(3),
[?cut(expect_no_actions(test_frame(3, Nodes, [b, c], _))),
?cut(expect_mail_down_warnings([b, c],
test_frame(1, Nodes, [b, c], _)))]).
mock_out_compat_mode(
?cut(functools:chain(
test_init(3),
[?cut(expect_no_actions(test_frame(3, Nodes, [b, c], _))),
?cut(expect_mail_down_warnings([b, c],
test_frame(1, Nodes, [b, c], _)))]))).

multiple_mail_down_warning_test() ->
Nodes = [a, b, c],
functools:chain(
test_init(3),
[?cut(expect_no_actions(test_frame(4, Nodes, [b], _))),
?cut(expect_mail_down_warnings([b], test_frame(1, Nodes, [b, c], _))),
%% Make sure not every tick sends out a message
?cut(expect_no_actions(test_frame(2, Nodes, [b, c], _))),
?cut(expect_mail_down_warnings([c], test_frame(1, Nodes, [b, c], _)))]).
mock_out_compat_mode(
?cut(functools:chain(
test_init(3),
[?cut(expect_no_actions(test_frame(4, Nodes, [b], _))),
?cut(expect_mail_down_warnings([b],
test_frame(1, Nodes, [b, c], _))),
%% Make sure not every tick sends out a message
?cut(expect_no_actions(test_frame(2, Nodes, [b, c], _))),
?cut(
expect_mail_down_warnings([c],
test_frame(1, Nodes, [b, c], _)))]))).

%% Test if mail_down_warning is sent again if node was up in between
mail_down_warning_down_up_down_test() ->
Nodes = [a, b, c],
functools:chain(
test_init(3),
[?cut(expect_no_actions(test_frame(4, Nodes, [b], _))),
?cut(expect_mail_down_warnings([b], test_frame(1, Nodes, [b, c], _))),
%% Node is up again
?cut(expect_no_actions(test_frame(1, Nodes, [], _))),
?cut(expect_no_actions(test_frame(3, Nodes, [b], _))),
?cut(expect_mail_down_warnings([b], test_frame(1, Nodes, [b, c], _)))]).
mock_out_compat_mode(
?cut(functools:chain(
test_init(3),
[?cut(expect_no_actions(test_frame(4, Nodes, [b], _))),
?cut(expect_mail_down_warnings([b],
test_frame(1, Nodes, [b, c], _))),
%% Node is up again
?cut(expect_no_actions(test_frame(1, Nodes, [], _))),
?cut(expect_no_actions(test_frame(3, Nodes, [b], _))),
?cut(expect_mail_down_warnings([b],
test_frame(1, Nodes, [b, c], _)))]))).

-endif.
5 changes: 4 additions & 1 deletion src/menelaus_web_cluster.erl
Expand Up @@ -982,11 +982,14 @@ do_handle_set_recovery_type(Req, Type, Params) ->

-ifdef(TEST).
parse_validate_services_list_test() ->
meck:new(cluster_compat_mode, [passthrough]),
meck:expect(cluster_compat_mode, is_enterprise, fun () -> true end),
{error, _} = parse_validate_services_list(""),
?assertEqual({ok, [index, kv, n1ql]}, parse_validate_services_list("n1ql,kv,index")),
{ok, [kv]} = parse_validate_services_list("kv"),
{error, _} = parse_validate_services_list("n1ql,kv,s"),
?assertMatch({error, _}, parse_validate_services_list("neeql,kv")).
?assertMatch({error, _}, parse_validate_services_list("neeql,kv")),
meck:unload(cluster_compat_mode).

hostname_parsing_test() ->
Urls = [" \t\r\nhttp://host:1025\n\r\t ",
Expand Down
6 changes: 5 additions & 1 deletion src/ns_cluster.erl
Expand Up @@ -1500,6 +1500,10 @@ join_marker_path() ->
community_allowed_topologies_test() ->
%% Test to help catch changes in community topologies that don't
%% maintain backwards compatibility
meck:new(cluster_compat_mode, [passthrough]),
meck:expect(cluster_compat_mode, is_enterprise, fun () -> false end),
?assertEqual(community_allowed_topologies(),
[[kv],[index,kv,n1ql],[fts,index,kv,n1ql]]).
[[kv],[index,kv,n1ql],[fts,index,kv,n1ql]]),
meck:unload(cluster_compat_mode).

-endif.
55 changes: 47 additions & 8 deletions src/ns_cluster_membership.erl
Expand Up @@ -479,8 +479,14 @@ filter_services_by_version(Version, ServicesTable) ->
end, ServicesTable).

supported_services_for_version(ClusterVersion) ->
filter_services_by_version(ClusterVersion, services_by_version()).

Invalid =
case cluster_compat_mode:is_enterprise() of
true ->
[];
false ->
enterprise_only_services()
end,
filter_services_by_version(ClusterVersion, services_by_version()) -- Invalid.

cluster_supported_services() ->
supported_services_for_version(cluster_compat_mode:get_compat_version()).
Expand Down Expand Up @@ -605,13 +611,46 @@ attach_node_uuids(Nodes, Config) ->
end, Nodes).

-ifdef(TEST).
mock_out_compat_mode(Fun) ->
mock_out_compat_mode(Fun, true).

mock_out_compat_mode(Fun, Val) ->
meck:new(cluster_compat_mode, [passthrough]),
meck:expect(cluster_compat_mode, is_enterprise, fun () -> Val end),
Resp = try
Fun()
catch Error ->
throw(Error)
after
meck:unload(cluster_compat_mode)
end,
Resp.

supported_services_for_version_test() ->
?assertEqual(lists:sort([fts,kv,index,n1ql,cbas,eventing,backup]),
lists:sort(supported_services_for_version(
?VERSION_70))).
mock_out_compat_mode(
?cut(?assertEqual(
lists:sort([fts,kv,index,n1ql,cbas,eventing,backup]),
lists:sort(supported_services_for_version(
?VERSION_70))))).

topology_aware_services_for_version_test() ->
?assertEqual(lists:sort([fts,index,cbas,eventing,backup]),
lists:sort(topology_aware_services_for_version(
?VERSION_70))).
mock_out_compat_mode(
?cut(?assertEqual(lists:sort([fts,index,cbas,eventing,backup]),
lists:sort(topology_aware_services_for_version(
?VERSION_70))))).

community_services_test() ->
mock_out_compat_mode(
?cut(
?assertEqual(
lists:sort([fts,kv,index,n1ql]),
lists:sort(supported_services_for_version(?VERSION_NEO)))),
false).

enterprise_services_test() ->
mock_out_compat_mode(
?cut(
?assertEqual(
lists:sort([backup,cbas,eventing,fts,kv,index,n1ql]),
lists:sort(supported_services_for_version(?VERSION_NEO))))).
-endif.

0 comments on commit cdcd59f

Please sign in to comment.