From 93ef6766ef10f25f10134c2ae1a1edcc2a756634 Mon Sep 17 00:00:00 2001 From: JianBo He Date: Sat, 13 Jan 2024 14:26:31 +0800 Subject: [PATCH] chore: apply suggestions from code review Co-authored-by: Zaiming (Stone) Shi --- .../src/emqx_mgmt_api_cluster.erl | 16 ++++++++-------- apps/emqx_management/src/emqx_mgmt_cluster.erl | 6 +++--- changes/ce/feat-12267.en.md | 3 ++- rel/i18n/emqx_mgmt_api_cluster.hocon | 4 ++-- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/apps/emqx_management/src/emqx_mgmt_api_cluster.erl b/apps/emqx_management/src/emqx_mgmt_api_cluster.erl index 1a46c0b36..d14b372ab 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_cluster.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_cluster.erl @@ -27,7 +27,7 @@ cluster_topology/2, invite_node/2, invite_node_async/2, - get_invitation_view/2, + get_invitation_status/2, force_leave/2, join/1, connected_replicants/0 @@ -179,7 +179,7 @@ fields(invitation_view) -> {succeed, ?HOCON( ?ARRAY(?REF(node_invitation_succeed)), - #{desc => <<"A list of information about nodes that were successfully invited">>} + #{desc => <<"A list of information about nodes which are successfully invited">>} )}, {in_progress, ?HOCON( @@ -198,7 +198,7 @@ fields(node_invitation_failed) -> {reason, ?HOCON( binary(), - #{desc => <<"Failed reason">>, example => <<"Bad RPC to target node">>} + #{desc => <<"Failure reason">>, example => <<"Bad RPC to target node">>} )} ]; fields(node_invitation_succeed) -> @@ -208,7 +208,7 @@ fields(node_invitation_succeed) -> ?HOCON( emqx_utils_calendar:epoch_millisecond(), #{ - desc => <<"The end time of the invitation task, in millisecond">>, + desc => <<"The time of the async invitation result is received, millisecond precision epoch">>, example => <<"1705044829915">> } )} @@ -224,7 +224,7 @@ fields(node_invitation_in_progress) -> ?HOCON( emqx_utils_calendar:epoch_millisecond(), #{ - desc => <<"The start time of the invitation task, in millisecond">>, + desc => <<"The start timestamp of the invitation, millisecond precision epoch">>, example => <<"1705044829915">> } )} @@ -289,15 +289,15 @@ invite_node(put, #{bindings := #{node := Node0}, body := Body}) -> Node = ekka_node:parse_name(binary_to_list(Node0)), case maps:get(<<"timeout">>, Body, ?DEFAULT_INVITE_TIMEOUT) of T when not is_integer(T) -> - {400, #{code => 'BAD_REQUEST', message => <<"timeout must be integer">>}}; + {400, #{code => 'BAD_REQUEST', message => <<"timeout must be an integer">>}}; T when T < 5000 -> - {400, #{code => 'BAD_REQUEST', message => <<"timeout can't less than 5000ms">>}}; + {400, #{code => 'BAD_REQUEST', message => <<"timeout cannot be less than 5000ms">>}}; Timeout -> case emqx_mgmt_cluster_proto_v3:invite_node(Node, node(), Timeout) of ok -> {200}; ignore -> - {400, #{code => 'BAD_REQUEST', message => <<"Can't invite self">>}}; + {400, #{code => 'BAD_REQUEST', message => <<"Cannot invite self">>}}; {badrpc, Error} -> {400, #{code => 'BAD_REQUEST', message => error_message(Error)}}; {error, Error} -> diff --git a/apps/emqx_management/src/emqx_mgmt_cluster.erl b/apps/emqx_management/src/emqx_mgmt_cluster.erl index 12c0c8dbc..818e79452 100644 --- a/apps/emqx_management/src/emqx_mgmt_cluster.erl +++ b/apps/emqx_management/src/emqx_mgmt_cluster.erl @@ -45,14 +45,14 @@ invite_async(Node) -> JoinTo = node(), case Node =/= JoinTo of true -> - gen_server:call(?MODULE, {invite_async, Node, JoinTo}); + gen_server:call(?MODULE, {invite_async, Node, JoinTo}, infinity); false -> ignore end. -spec invitation_view() -> map(). invitation_view() -> - gen_server:call(?MODULE, invitation_view). + gen_server:call(?MODULE, invitation_view, infinity). %%-------------------------------------------------------------------- %% gen_server callbacks @@ -196,4 +196,4 @@ is_succeed_result(Result) -> end. format_error_reason(Term) -> - iolist_to_binary(io_lib:format("~p", [Term])). + iolist_to_binary(io_lib:format("~0p", [Term])). diff --git a/changes/ce/feat-12267.en.md b/changes/ce/feat-12267.en.md index fbc88847c..5574918a4 100644 --- a/changes/ce/feat-12267.en.md +++ b/changes/ce/feat-12267.en.md @@ -1,4 +1,5 @@ Add a new `timeout` parameter to the `cluster/:node/invite` interface. Previously the default timeout was 5s which would often be caused by HTTP API calls due to emqx taking too long to join cluster. -Add a new endpoint `/cluster/:node/invite_async` to support an asynchronous way to invite nodes to join the cluster. +Add a new endpoint `/cluster/:node/invite_async` to support an asynchronous way to invite nodes to join the cluster, +and a new endpoint `cluster/invitation` to inspect the join status. diff --git a/rel/i18n/emqx_mgmt_api_cluster.hocon b/rel/i18n/emqx_mgmt_api_cluster.hocon index 9b7d782fe..55ce17a9e 100644 --- a/rel/i18n/emqx_mgmt_api_cluster.hocon +++ b/rel/i18n/emqx_mgmt_api_cluster.hocon @@ -16,9 +16,9 @@ invite_node.label: """Invite node to cluster""" invite_node_async.desc: -"""Asynchronously invite the target node to join the cluster""" +"""Send a join invitation to a node to join the cluster but do not wait for the join result. Join status can be retrieved with `GET api//invitation`""" invite_node_async.label: -"""Asynchronously invite the target node to join the cluster""" +"""Asynchronously invite""" force_remove_node.desc: """Force leave node from cluster"""