feat(olp): rename olp mgmt API

on -> enable
off -> disable
This commit is contained in:
William Yang 2021-10-13 08:54:50 +02:00
parent 58033c083d
commit 23fc8afc50
3 changed files with 19 additions and 19 deletions

View File

@ -27,8 +27,8 @@
%% exports for O&M %% exports for O&M
-export([ status/0 -export([ status/0
, on/0 , enable/0
, off/0 , disable/0
]). ]).
-type cfg_key() :: -type cfg_key() ::
@ -97,13 +97,13 @@ status() ->
is_overloaded(). is_overloaded().
%% @doc turn off backgroud runq check. %% @doc turn off backgroud runq check.
-spec off() -> ok | {error, timeout}. -spec disable() -> ok | {error, timeout}.
off() -> disable() ->
load_ctl:stop_runq_flagman(5000). load_ctl:stop_runq_flagman(5000).
%% @doc turn on backgroud runq check. %% @doc turn on backgroud runq check.
-spec on() -> {ok, pid()} | {error, running | restarting | disabled}. -spec enable() -> {ok, pid()} | {error, running | restarting | disabled}.
on() -> enable() ->
case load_ctl:restart_runq_flagman() of case load_ctl:restart_runq_flagman() of
{error, disabled} -> {error, disabled} ->
OldCfg = load_ctl:get_config(), OldCfg = load_ctl:get_config(),

View File

@ -34,7 +34,7 @@ end_per_suite(_Config) ->
emqx_ct_helpers:stop_apps([]). emqx_ct_helpers:stop_apps([]).
init_per_testcase(_, Config) -> init_per_testcase(_, Config) ->
emqx_olp:on(), emqx_olp:enable(),
case wait_for(fun() -> lc_sup:whereis_runq_flagman() end, 10) of case wait_for(fun() -> lc_sup:whereis_runq_flagman() end, 10) of
true -> ok; true -> ok;
false -> false ->
@ -51,11 +51,11 @@ init_per_testcase(_, Config) ->
Config. Config.
%% Test that olp could be enabled/disabled globally %% Test that olp could be enabled/disabled globally
t_off_on(_Config) -> t_disable_enable(_Config) ->
Old = load_ctl:whereis_runq_flagman(), Old = load_ctl:whereis_runq_flagman(),
ok = emqx_olp:off(), ok = emqx_olp:disable(),
?assert(not is_process_alive(Old)), ?assert(not is_process_alive(Old)),
{ok, Pid} = emqx_olp:on(), {ok, Pid} = emqx_olp:enable(),
timer:sleep(1000), timer:sleep(1000),
?assert(is_process_alive(Pid)). ?assert(is_process_alive(Pid)).

View File

@ -505,16 +505,16 @@ olp(["status"]) ->
false -> "not overloaded" false -> "not overloaded"
end, end,
emqx_ctl:print("~p is ~s ~n", [node(), S]); emqx_ctl:print("~p is ~s ~n", [node(), S]);
olp(["off"]) -> olp(["disable"]) ->
Res = emqx_olp:off(), Res = emqx_olp:disable(),
emqx_ctl:print("Turn off overload protetion ~p : ~p ~n", [node(), Res]); emqx_ctl:print("Disable overload protetion ~p : ~p ~n", [node(), Res]);
olp(["on"]) -> olp(["enable"]) ->
Res = emqx_olp:on(), Res = emqx_olp:enable(),
emqx_ctl:print("Turn on overload protection ~p : ~p ~n", [node(), Res]); emqx_ctl:print("Enable overload protection ~p : ~p ~n", [node(), Res]);
olp(_) -> olp(_) ->
emqx_ctl:usage([{"olp status", "Return OLP status if system is overloaded"}, emqx_ctl:usage([{"olp status", "Return OLP status if system is overloaded"},
{"olp on", "Turn on overload protection"}, {"olp enable", "Enable overload protection"},
{"olp off", "Turn off overload protection"} {"olp disable", "Disable overload protection"}
]). ]).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------