diff --git a/apps/emqx/test/emqx_bpapi_static_checks.erl b/apps/emqx/test/emqx_bpapi_static_checks.erl index 4d742c600..8ceceb241 100644 --- a/apps/emqx/test/emqx_bpapi_static_checks.erl +++ b/apps/emqx/test/emqx_bpapi_static_checks.erl @@ -52,6 +52,11 @@ -define(RPC_FUNCTIONS, "emqx_cluster_rpc:multicall/3, emqx_cluster_rpc:multicall/5"). %% List of functions in the RPC backend modules that we can ignore: -define(IGNORED_RPC_CALLS, "gen_rpc:nodes/0"). +%% List of business-layer functions that are exempt from the checks: +-define(EXEMPTIONS, "emqx_mgmt_api:do_query/6" % Reason: legacy code. A fun and a QC query are + % passed in the args, it's futile to try to statically + % check it + ). -define(XREF, myxref). @@ -207,7 +212,7 @@ prepare(#{reldir := RelDir, plt := PLT}) -> dialyzer_plt:from_file(PLT). find_remote_calls(_Opts) -> - Query = "XC | (A - [" ?IGNORED_APPS "]:App - [" ?IGNORED_MODULES "] : Mod) + Query = "XC | (A - [" ?IGNORED_APPS "]:App - [" ?IGNORED_MODULES "]:Mod - [" ?EXEMPTIONS "]) || (([" ?RPC_MODULES "] : Mod + [" ?RPC_FUNCTIONS "]) - " ?IGNORED_RPC_CALLS ")", {ok, Calls} = xref:q(?XREF, Query), ?INFO("Calls to RPC modules ~p", [Calls]), diff --git a/apps/emqx_management/src/emqx_mgmt_api.erl b/apps/emqx_management/src/emqx_mgmt_api.erl index 6136cab3a..3ca1266eb 100644 --- a/apps/emqx_management/src/emqx_mgmt_api.erl +++ b/apps/emqx_management/src/emqx_mgmt_api.erl @@ -197,12 +197,15 @@ do_cluster_query([Node | Tail] = Nodes, Tab, Qs, QueryFun, Continuation, %% Do Query (or rpc query) %%-------------------------------------------------------------------- -%% @private +%% @private This function is exempt from BPAPI do_query(Node, Tab, Qs, {M,F}, Continuation, Limit) when Node =:= node() -> erlang:apply(M, F, [Tab, Qs, Continuation, Limit]); do_query(Node, Tab, Qs, QueryFun, Continuation, Limit) -> - rpc_call(Node, ?MODULE, do_query, - [Node, Tab, Qs, QueryFun, Continuation, Limit], 50000). + case rpc:call(Node, ?MODULE, do_query, + [Node, Tab, Qs, QueryFun, Continuation, Limit], 50000) of + {badrpc, _} = R -> {error, R}; + Ret -> Ret + end. sub_query_result(Len, Rows, Limit, Results, Meta) -> {Flag, NMeta} = judge_page_with_counting(Len, Meta), @@ -219,13 +222,6 @@ sub_query_result(Len, Rows, Limit, Results, Meta) -> end, {NMeta, NResults}. -%% @private -rpc_call(Node, M, F, A, T) -> - case rpc:call(Node, M, F, A, T) of - {badrpc, _} = R -> {error, R}; - Res -> Res - end. - %%-------------------------------------------------------------------- %% Table Select %%--------------------------------------------------------------------