chore: move emqx_recon to emqx_modules plugin

This commit is contained in:
Turtle 2021-06-25 15:10:45 +08:00 committed by Shawn
parent c9c6b69cc9
commit 2d1008ceaf
12 changed files with 26 additions and 300 deletions

View File

@ -14,13 +14,34 @@
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_recon_cli).
-module(emqx_mod_recon).
-export([ cmd/1
, load/0
, unload/0
-behaviour(emqx_gen_mod).
%% emqx_gen_mod callbacks
-export([ load/1
, unload/1
, description/0
]).
-export([cmd/1]).
%%--------------------------------------------------------------------
%% Load/Unload
%%--------------------------------------------------------------------
-spec(load(list()) -> ok).
load(_Env) ->
load().
-spec(unload(list()) -> ok).
unload(_Env) ->
unload().
description() ->
"EMQ X Recon Module".
load() ->
emqx_ctl:register_command(recon, {?MODULE, cmd}, []).
@ -69,4 +90,3 @@ remote_load(Module) -> remote_load(nodes(), Module).
%% after OTP 23, it crashes with 'badarg' error
remote_load([], _Module) -> ok;
remote_load(Nodes, Module) -> recon:remote_load(Nodes, Module).

View File

@ -1,31 +0,0 @@
.rebar
.eunit
deps
!deps/.placeholder
*.o
*.beam
*.plt
erl_crash.dump
ebin
!ebin/.placeholder
.exrc
log/
*.swp
*.so
.erlang.mk/
logs/
ct.coverdata
test/ct.cover.spec
.idea/
emqx_recon.iml
Mnesia.nonode@nohost/
data/
cover/
emqx_recon.d
eunit.coverdata
.DS_Store
_build/
rebar.lock
erlang.mk
rebar3.crashdump
.rebar3/

View File

@ -1,61 +0,0 @@
emqx-recon
==========
EMQ X Recon Debug/Optimize Plugin
emqx_recon.conf
----=----------
```
## Global GC Interval.
##
## Value: Duration
## - h: hour
## - m: minute
## - s: second
##
## Examples:
## - 2h: 2 hours
## - 30m: 30 minutes
## - 20s: 20 seconds
##
## Defaut: 5m
recon.gc_interval = 5m
```
Load the Plugin
---------------
```
./bin/emqx_ctl plugins load emqx_recon
```
Commands
--------
```
./bin/emqx_ctl recon
recon memory #recon_alloc:memory/2
recon allocated #recon_alloc:memory(allocated_types, current|max)
recon bin_leak #recon:bin_leak(100)
recon node_stats #recon:node_stats(10, 1000)
recon remote_load Mod #recon:remote_load(Mod)
```
GC
--
When the plugin is loaded, global GC will run periodically.
License
-------
Apache License Version 2.0
Author
------
EMQ X Team.

View File

@ -1,4 +0,0 @@
##--------------------------------------------------------------------
## Recon Plugin
##--------------------------------------------------------------------

View File

@ -1,9 +0,0 @@
%%-*- mode: erlang -*-
%% emqx-recon config mapping
%% @doc Global GC Interval
%% {@configurable}
%% {mapping, "recon.gc_interval", "emqx_recon.gc_interval", [
%% {datatype, {duration, s}}
%% ]}.

View File

@ -1,18 +0,0 @@
{deps, [
%% recon "https://github.com/ferd/recon" at root rebar.config
]}.
{edoc_opts, [{preprocess, true}]}.
{erl_opts, [warn_unused_vars,
warn_shadow_vars,
warn_unused_import,
warn_obsolete_guard,
debug_info
]}.
{xref_checks, [undefined_function_calls, undefined_functions,
locals_not_used, deprecated_function_calls,
warnings_as_errors, deprecated_functions]}.
{cover_enabled, true}.
{cover_opts, [verbose]}.
{cover_export_enabled, true}.

View File

@ -1,14 +0,0 @@
{application, emqx_recon,
[{description, "EMQ X Recon Plugin"},
{vsn, "4.4.0"}, % strict semver, bump manually!
{modules, []},
{registered, []},
{applications, [kernel,stdlib,recon]},
{mod, {emqx_recon,[]}},
{env, []},
{licenses, ["Apache-2.0"]},
{maintainers, ["EMQ X Team <contact@emqx.io>"]},
{links, [{"Homepage", "https://emqx.io/"},
{"Github", "https://github.com/emqx/emqx-recon"}
]}
]}.

View File

@ -1,41 +0,0 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_recon).
-emqx_plugin(?MODULE).
-behaviour(application).
-export([start/2, stop/1]).
-behaviour(supervisor).
-export([init/1]).
-define(APP, ?MODULE).
-define(SUP, emqx_recon_sup).
start(_StartType, _StartArgs) ->
emqx_recon_cli:load(),
supervisor:start_link({local, ?SUP}, ?MODULE, []).
stop(_State) ->
emqx_recon_cli:unload().
init([]) ->
{ok, {{one_for_one, 10, 100}, []}}.

View File

@ -1,114 +0,0 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_recon_SUITE).
-compile(nowarn_export_all).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
-define(output_patterns(V), ((V)++"")).
all() -> [{group, cli}].
groups() ->
[{cli, [sequence],
[cli_memory,
cli_allocated,
cli_bin_leak,
cli_node_stats,
cli_remote_load,
cli_usage]}
].
init_per_suite(Config) ->
emqx_ct_helpers:start_apps([emqx_recon]),
Config.
end_per_suite(_Config) ->
emqx_ct_helpers:stop_apps([emqx_recon]).
cli_memory(_) ->
mock_print(),
Output = emqx_recon_cli:cmd(["memory"]),
Zip = lists:zip(Output, [ ?output_patterns("usage/current")
, ?output_patterns("usage/max")
, ?output_patterns("used/current")
, ?output_patterns("used/max")
, ?output_patterns("allocated/current")
, ?output_patterns("allocated/max")
, ?output_patterns("unused/current")
, ?output_patterns("unused/max")
]),
%ct:pal("=======~p", [Zip]),
[?assertMatch({match, _}, re:run(Line, Match, [{capture,all,list}]))
|| {Line, Match} <- Zip],
unmock_print().
cli_allocated(_) ->
mock_print(),
Output = emqx_recon_cli:cmd(["allocated"]),
Zip = lists:zip(Output, [ ?output_patterns("binary_alloc/current")
, ?output_patterns("driver_alloc/current")
, ?output_patterns("eheap_alloc/current")
, ?output_patterns("ets_alloc/current")
, ?output_patterns("fix_alloc/current")
, ?output_patterns("ll_alloc/current")
, ?output_patterns("sl_alloc/current")
, ?output_patterns("std_alloc/current")
, ?output_patterns("temp_alloc/current")
, ?output_patterns("binary_alloc/max")
, ?output_patterns("driver_alloc/max")
, ?output_patterns("eheap_alloc/max")
, ?output_patterns("ets_alloc/max")
, ?output_patterns("fix_alloc/max")
, ?output_patterns("ll_alloc/max")
, ?output_patterns("sl_alloc/max")
, ?output_patterns("std_alloc/max")
, ?output_patterns("temp_alloc/max")
]),
ct:pal("=======~p", [Zip]),
[?assertMatch({match, _}, re:run(Line, Match, [{capture,all,list}]))
|| {Line, Match} <- Zip],
unmock_print().
cli_bin_leak(_) ->
mock_print(),
Output = emqx_recon_cli:cmd(["bin_leak"]),
[?assertMatch({match, _}, re:run(Line, "current_function", [{capture,all,list}]))
|| Line <- Output],
unmock_print().
cli_node_stats(_) ->
emqx_recon_cli:cmd(["node_stats"]).
cli_remote_load(_) ->
emqx_recon_cli:cmd(["remote_load", "emqx_recon_cli"]).
cli_usage(_) ->
emqx_recon_cli:cmd(["usage"]).
mock_print() ->
catch meck:unload(emqx_ctl),
meck:new(emqx_ctl, [non_strict, passthrough]),
meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg) end),
meck:expect(emqx_ctl, print, fun(Msg, Arg) -> emqx_ctl:format(Msg, Arg) end),
meck:expect(emqx_ctl, usage, fun(Usages) -> emqx_ctl:format_usage(Usages) end).
unmock_print() ->
meck:unload().

View File

@ -1 +1,2 @@
{emqx_mod_presence, true}.
{emqx_mod_recon, true}.

View File

@ -1,7 +1,6 @@
{emqx_management, true}.
{emqx_dashboard, true}.
{emqx_modules, {{enable_plugin_emqx_modules}}}.
{emqx_recon, {{enable_plugin_emqx_recon}}}.
{emqx_retainer, {{enable_plugin_emqx_retainer}}}.
{emqx_rule_engine, {{enable_plugin_emqx_rule_engine}}}.
{emqx_bridge_mqtt, {{enable_plugin_emqx_bridge_mqtt}}}.

View File

@ -188,7 +188,6 @@ overlay_vars_rel(RelType) ->
[ {enable_plugin_emqx_rule_engine, RelType =:= cloud}
, {enable_plugin_emqx_bridge_mqtt, RelType =:= edge}
, {enable_plugin_emqx_modules, false} %% modules is not a plugin in ce
, {enable_plugin_emqx_recon, true}
, {enable_plugin_emqx_retainer, true}
, {vm_args_file, VmArgs}
].
@ -285,7 +284,6 @@ relx_plugin_apps(ReleaseType) ->
, emqx_auth_jwt
, emqx_auth_mnesia
, emqx_web_hook
, emqx_recon
, emqx_rule_engine
, emqx_sasl
, emqx_statsd