From b8e2c7638225e0c8eab69653cb18bd806a528083 Mon Sep 17 00:00:00 2001 From: DDDHuang <44492639+DDDHuang@users.noreply.github.com> Date: Tue, 12 Apr 2022 15:10:26 +0800 Subject: [PATCH 1/5] fix: remove routes --- apps/emqx/src/emqx_router_helper.erl | 1 - apps/emqx/src/emqx_stats.erl | 7 -- apps/emqx/test/emqx_proper_types.erl | 4 +- apps/emqx_dashboard/README.md | 89 +------------------ .../emqx_dashboard/include/emqx_dashboard.hrl | 2 +- .../src/emqx_dashboard_monitor.erl | 2 +- .../src/emqx_dashboard_monitor_api.erl | 4 +- apps/emqx_management/src/emqx_mgmt.erl | 16 +--- .../src/emqx_mgmt_api_stats.erl | 6 -- ...pi_routes.erl => emqx_mgmt_api_topics.erl} | 30 +++---- apps/emqx_management/src/emqx_mgmt_cli.erl | 20 ++--- apps/emqx_prometheus/README.md | 4 - apps/emqx_prometheus/src/emqx_prometheus.erl | 8 -- 13 files changed, 34 insertions(+), 159 deletions(-) rename apps/emqx_management/src/{emqx_mgmt_api_routes.erl => emqx_mgmt_api_topics.erl} (88%) diff --git a/apps/emqx/src/emqx_router_helper.erl b/apps/emqx/src/emqx_router_helper.erl index fe7f5548c..1340848ec 100644 --- a/apps/emqx/src/emqx_router_helper.erl +++ b/apps/emqx/src/emqx_router_helper.erl @@ -178,7 +178,6 @@ stats_fun() -> undefined -> ok; Size -> - emqx_stats:setstat('routes.count', 'routes.max', Size), emqx_stats:setstat('topics.count', 'topics.max', Size) end. diff --git a/apps/emqx/src/emqx_stats.erl b/apps/emqx/src/emqx_stats.erl index fc3a1b6e7..7d9854811 100644 --- a/apps/emqx/src/emqx_stats.erl +++ b/apps/emqx/src/emqx_stats.erl @@ -116,12 +116,6 @@ 'subscriptions.shared.max' ]). -%% Route stats --define(ROUTE_STATS, [ - 'routes.count', - 'routes.max' -]). - %% Retained stats -define(RETAINED_STATS, [ 'retained.count', @@ -213,7 +207,6 @@ init(#{tick_ms := TickMs}) -> ?CHANNEL_STATS, ?SESSION_STATS, ?PUBSUB_STATS, - ?ROUTE_STATS, ?RETAINED_STATS ]), true = ets:insert(?TAB, [{Name, 0} || Name <- Stats]), diff --git a/apps/emqx/test/emqx_proper_types.erl b/apps/emqx/test/emqx_proper_types.erl index 1b0972dd6..b56140288 100644 --- a/apps/emqx/test/emqx_proper_types.erl +++ b/apps/emqx/test/emqx_proper_types.erl @@ -328,9 +328,7 @@ systopic_stats() -> <<"subscriptions/shared/max">>, <<"subscriptions/shared/count">>, <<"topics/max">>, - <<"topics/count">>, - <<"routes/max">>, - <<"routes/count">> + <<"topics/count">> ], ?LET( {Nodename, T}, diff --git a/apps/emqx_dashboard/README.md b/apps/emqx_dashboard/README.md index 96c607a50..7466b5afe 100644 --- a/apps/emqx_dashboard/README.md +++ b/apps/emqx_dashboard/README.md @@ -1,88 +1 @@ - -emqx-dashboard -============== - -EMQX Dashboard - -REST API --------- - -The prefix of REST API is '/api/v4/'. - -Method | Path | Description --------|---------------------------------------|------------------------------------ -GET | /nodes/ | A list of nodes in the cluster -GET | /nodes/:node | Lookup a node in the cluster -GET | /brokers/ | A list of brokers in the cluster -GET | /brokers/:node | Get broker info of a node -GET | /metrics/ | A list of metrics of all nodes in the cluster -GET | /nodes/:node/metrics/ | A list of metrics of a node -GET | /stats/ | A list of stats of all nodes in the cluster -GET | /nodes/:node/stats/ | A list of stats of a node -GET | /nodes/:node/clients/ | A list of clients on a node -GET | /listeners/ | A list of listeners in the cluster -GET | /nodes/:node/listeners | A list of listeners on the node -GET | /nodes/:node/sessions/ | A list of sessions on a node -GET | /subscriptions/:clientid | A list of subscriptions of a client -GET | /nodes/:node/subscriptions/:clientid | A list of subscriptions of a client on the node -GET | /nodes/:node/subscriptions/ | A list of subscriptions on a node -PUT | /clients/:clientid/clean_authz_cache | Clean Authorization cache of a client -GET | /configs/ | Get all configs -GET | /nodes/:node/configs/ | Get all configs of a node -GET | /nodes/:node/plugin_configs/:plugin | Get configurations of a plugin on the node -DELETE | /clients/:clientid | Kick out a client -GET | /alarms/:node | List alarms of a node -GET | /alarms/ | List all alarms -GET | /plugins/ | List all plugins in the cluster -GET | /nodes/:node/plugins/ | List all plugins on a node -GET | /routes/ | List routes -POST | /nodes/:node/plugins/:plugin/load | Load a plugin -GET | /clients/:clientid | Lookup a client in the cluster -GET | nodes/:node/clients/:clientid | Lookup a client on node -GET | nodes/:node/sessions/:clientid | Lookup a session in the cluster -GET | nodes/:node/sessions/:clientid | Lookup a session on the node -POST | /mqtt/publish | Publish a MQTT message -POST | /mqtt/subscribe | Subscribe a topic -POST | /nodes/:node/plugins/:plugin/unload | Unload a plugin -POST | /mqtt/unsubscribe | Unsubscribe a topic -PUT | /configs/:app | Update config of an application in the cluster -PUT | /nodes/:node/configs/:app | Update config of an application on a node -PUT | /nodes/:node/plugin_configs/:plugin | Update configurations of a plugin on the node - -Build ------ - -make && make ct - -Configuration ------------- - -``` -dashboard.listener = 18083 - -dashboard.listener.acceptors = 2 - -dashboard.listener.max_clients = 512 -``` - -Load Plugin ------------ - -``` -./bin/emqx_ctl plugins load emqx_dashboard -``` - -Login ------ - -URL: http://host:18083 - -Username: admin - -Password: public - -License -------- - -Apache License Version 2.0 - +# TODO: Doc diff --git a/apps/emqx_dashboard/include/emqx_dashboard.hrl b/apps/emqx_dashboard/include/emqx_dashboard.hrl index de0682039..c49ac8fc9 100644 --- a/apps/emqx_dashboard/include/emqx_dashboard.hrl +++ b/apps/emqx_dashboard/include/emqx_dashboard.hrl @@ -59,7 +59,7 @@ -define(GAUGE_SAMPLER_LIST, [ subscriptions - , routes + , topics , connections ]). diff --git a/apps/emqx_dashboard/src/emqx_dashboard_monitor.erl b/apps/emqx_dashboard/src/emqx_dashboard_monitor.erl index 706458eed..52c2c25af 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_monitor.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_monitor.erl @@ -352,7 +352,7 @@ count_map(M1, M2) -> lists:foldl(Fun, #{}, ?SAMPLER_LIST). value(connections) -> emqx_stats:getstat('connections.count'); -value(routes) -> emqx_stats:getstat('routes.count'); +value(topics) -> emqx_stats:getstat('topics.count'); value(subscriptions) -> emqx_stats:getstat('subscriptions.count'); value(received) -> emqx_metrics:val('messages.received'); value(received_bytes) -> emqx_metrics:val('bytes.received'); diff --git a/apps/emqx_dashboard/src/emqx_dashboard_monitor_api.erl b/apps/emqx_dashboard/src/emqx_dashboard_monitor_api.erl index 5fb65f84e..35597c9ec 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_monitor_api.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_monitor_api.erl @@ -148,8 +148,8 @@ swagger_desc(dropped) -> swagger_desc_format("Dropped messages "); swagger_desc(subscriptions) -> <<"Subscriptions at the time of sampling." " Can only represent the approximate state">>; -swagger_desc(routes) -> - <<"Routes at the time of sampling." +swagger_desc(topics) -> + <<"Count topics at the time of sampling." " Can only represent the approximate state">>; swagger_desc(connections) -> <<"Connections at the time of sampling." diff --git a/apps/emqx_management/src/emqx_mgmt.erl b/apps/emqx_management/src/emqx_mgmt.erl index 8261808da..fecf77070 100644 --- a/apps/emqx_management/src/emqx_mgmt.erl +++ b/apps/emqx_management/src/emqx_mgmt.erl @@ -71,10 +71,6 @@ , do_list_subscriptions/0 ]). -%% Routes --export([ lookup_routes/1 - ]). - %% PubSub -export([ subscribe/2 , do_subscribe/2 @@ -183,8 +179,8 @@ get_stats() -> GlobalStatsKeys = [ 'retained.count' , 'retained.max' - , 'routes.count' - , 'routes.max' + , 'topics.count' + , 'topics.max' , 'subscriptions.shared.count' , 'subscriptions.shared.max' ], @@ -357,13 +353,6 @@ lookup_subscriptions(ClientId) -> lookup_subscriptions(Node, ClientId) -> wrap_rpc(emqx_broker_proto_v1:list_client_subscriptions(Node, ClientId)). -%%-------------------------------------------------------------------- -%% Routes -%%-------------------------------------------------------------------- - -lookup_routes(Topic) -> - emqx_router:lookup_routes(Topic). - %%-------------------------------------------------------------------- %% PubSub %%-------------------------------------------------------------------- @@ -470,6 +459,7 @@ delete_banned(Who) -> item(subscription, {{Topic, ClientId}, Options}) -> #{topic => Topic, clientid => ClientId, options => Options}; + %% TODO: may be delete item(route, #route{topic = Topic, dest = Node}) -> #{topic => Topic, node => Node}; item(route, {Topic, Node}) -> diff --git a/apps/emqx_management/src/emqx_mgmt_api_stats.erl b/apps/emqx_management/src/emqx_mgmt_api_stats.erl index ee28e8f73..af233ef17 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_stats.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_stats.erl @@ -93,12 +93,6 @@ fields(node_stats_data) -> , { 'retained.max' , mk( integer(), #{ desc => <<"Historical maximum number of retained messages">> , example => 0})} - , { 'routes.count' - , mk( integer(), #{ desc => <<"Number of current routes">> - , example => 0})} - , { 'routes.max' - , mk( integer(), #{ desc => <<"Historical maximum number of routes">> - , example => 0})} , { 'sessions.count' , mk( integer(), #{ desc => <<"Number of current sessions">> , example => 0})} diff --git a/apps/emqx_management/src/emqx_mgmt_api_routes.erl b/apps/emqx_management/src/emqx_mgmt_api_topics.erl similarity index 88% rename from apps/emqx_management/src/emqx_mgmt_api_routes.erl rename to apps/emqx_management/src/emqx_mgmt_api_topics.erl index 4f1e42109..249879c62 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_routes.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_topics.erl @@ -14,7 +14,7 @@ %% limitations under the License. %%-------------------------------------------------------------------- --module(emqx_mgmt_api_routes). +-module(emqx_mgmt_api_topics). -include_lib("emqx/include/emqx.hrl"). -include_lib("typerefl/include/types.hrl"). @@ -28,28 +28,28 @@ , fields/1 ]). --export([ routes/2 - , route/2 +-export([ topics/2 + , topic/2 ]). -export([ query/4]). -define(TOPIC_NOT_FOUND, 'TOPIC_NOT_FOUND'). --define(ROUTES_QSCHEMA, [{<<"topic">>, binary}, {<<"node">>, atom}]). +-define(TOPICS_QUERY_SCHEMA, [{<<"topic">>, binary}, {<<"node">>, atom}]). api_spec() -> emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true, translate_body => true}). paths() -> - ["/routes", "/routes/:topic"]. + ["/topics", "/topics/:topic"]. -schema("/routes") -> +schema("/topics") -> #{ - 'operationId' => routes, + 'operationId' => topics, get => #{ - description => <<"EMQX Topics List">>, + description => <<"Topics list">>, parameters => [ topic_param(query), node_param(), @@ -64,11 +64,11 @@ schema("/routes") -> } } }; -schema("/routes/:topic") -> +schema("/topics/:topic") -> #{ - 'operationId' => route, + 'operationId' => topic, get => #{ - description => <<"EMQX Topic List">>, + description => <<"Lookup topic info by name">>, parameters => [topic_param(path)], responses => #{ 200 => hoconsc:mk(hoconsc:ref(topic), #{}), @@ -94,21 +94,21 @@ fields(meta) -> %%%============================================================================================== %% parameters trans -routes(get, #{query_string := Qs}) -> +topics(get, #{query_string := Qs}) -> do_list(generate_topic(Qs)). -route(get, #{bindings := Bindings}) -> +topic(get, #{bindings := Bindings}) -> lookup(generate_topic(Bindings)). %%%============================================================================================== %% api apply do_list(Params) -> Response = emqx_mgmt_api:node_query( - node(), Params, emqx_route, ?ROUTES_QSCHEMA, {?MODULE, query}), + node(), Params, emqx_route, ?TOPICS_QUERY_SCHEMA, {?MODULE, query}), emqx_mgmt_util:generate_response(Response). lookup(#{topic := Topic}) -> - case emqx_mgmt:lookup_routes(Topic) of + case emqx_router:lookup_routes(Topic) of [] -> {404, #{code => ?TOPIC_NOT_FOUND, message => <<"Topic not found">>}}; [Route] -> diff --git a/apps/emqx_management/src/emqx_mgmt_cli.erl b/apps/emqx_management/src/emqx_mgmt_cli.erl index 232011319..4dadd3460 100644 --- a/apps/emqx_management/src/emqx_mgmt_cli.erl +++ b/apps/emqx_management/src/emqx_mgmt_cli.erl @@ -31,7 +31,7 @@ broker/1, cluster/1, clients/1, - routes/1, + topics/1, subscriptions/1, plugins/1, listeners/1, @@ -164,17 +164,17 @@ if_client(ClientId, Fun) -> end. %%-------------------------------------------------------------------- -%% @doc Routes Command +%% @doc Topics Command -routes(["list"]) -> +topics(["list"]) -> dump(emqx_route); -routes(["show", Topic]) -> +topics(["show", Topic]) -> Routes = ets:lookup(emqx_route, bin(Topic)), - [print({emqx_route, Route}) || Route <- Routes]; -routes(_) -> + [print({emqx_topic, Route}) || Route <- Routes]; +topics(_) -> emqx_ctl:usage([ - {"routes list", "List all routes"}, - {"routes show ", "Show a route"} + {"topics list", "List all topics"}, + {"topics show ", "Show a topic"} ]). subscriptions(["list"]) -> @@ -750,9 +750,9 @@ print({client, {ClientId, ChanPid}}) -> end, [format(K, maps:get(K, Info1)) || K <- InfoKeys] ); -print({emqx_route, #route{topic = Topic, dest = {_, Node}}}) -> +print({emqx_topic, #route{topic = Topic, dest = {_, Node}}}) -> emqx_ctl:print("~ts -> ~ts~n", [Topic, Node]); -print({emqx_route, #route{topic = Topic, dest = Node}}) -> +print({emqx_topic, #route{topic = Topic, dest = Node}}) -> emqx_ctl:print("~ts -> ~ts~n", [Topic, Node]); print(#plugin{name = Name, descr = Descr, active = Active}) -> emqx_ctl:print( diff --git a/apps/emqx_prometheus/README.md b/apps/emqx_prometheus/README.md index 6c4461118..ddff9774c 100644 --- a/apps/emqx_prometheus/README.md +++ b/apps/emqx_prometheus/README.md @@ -218,10 +218,6 @@ emqx_connections_max 0 emqx_retained_count 3 # TYPE emqx_retained_max gauge emqx_retained_max 3 -# TYPE emqx_routes_count gauge -emqx_routes_count 0 -# TYPE emqx_routes_max gauge -emqx_routes_max 0 # TYPE emqx_sessions_count gauge emqx_sessions_count 0 # TYPE emqx_sessions_max gauge diff --git a/apps/emqx_prometheus/src/emqx_prometheus.erl b/apps/emqx_prometheus/src/emqx_prometheus.erl index f45fb6ae7..df5598637 100644 --- a/apps/emqx_prometheus/src/emqx_prometheus.erl +++ b/apps/emqx_prometheus/src/emqx_prometheus.erl @@ -248,12 +248,6 @@ emqx_collect(emqx_subscriptions_shared_count, Stats) -> emqx_collect(emqx_subscriptions_shared_max, Stats) -> gauge_metric(?C('subscriptions.shared.max', Stats)); -%% routes -emqx_collect(emqx_routes_count, Stats) -> - gauge_metric(?C('routes.count', Stats)); -emqx_collect(emqx_routes_max, Stats) -> - gauge_metric(?C('routes.max', Stats)); - %% retained emqx_collect(emqx_retained_count, Stats) -> gauge_metric(?C('retained.count', Stats)); @@ -517,8 +511,6 @@ emqx_stats() -> , emqx_subscriptions_max , emqx_subscriptions_shared_count , emqx_subscriptions_shared_max - , emqx_routes_count - , emqx_routes_max , emqx_retained_count , emqx_retained_max ]. From 322bdffea9b547cb356358f0e8283bf057a56b9a Mon Sep 17 00:00:00 2001 From: DDDHuang <44492639+DDDHuang@users.noreply.github.com> Date: Wed, 13 Apr 2022 14:10:09 +0800 Subject: [PATCH 2/5] fix: bad api path 404 response --- apps/emqx_dashboard/src/emqx_dashboard.erl | 1 + .../src/emqx_dashboard_bad_api.erl | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 apps/emqx_dashboard/src/emqx_dashboard_bad_api.erl diff --git a/apps/emqx_dashboard/src/emqx_dashboard.erl b/apps/emqx_dashboard/src/emqx_dashboard.erl index a0b733d33..513d7ff50 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard.erl @@ -61,6 +61,7 @@ start_listeners(Listeners) -> }}}, Dispatch = [ {"/", cowboy_static, {priv_file, emqx_dashboard, "www/index.html"}} , {"/static/[...]", cowboy_static, {priv_dir, emqx_dashboard, "www/static"}} + , {?BASE_PATH ++ "/[...]", emqx_dashboard_bad_api, []} , {'_', cowboy_static, {priv_file, emqx_dashboard, "www/index.html"}} ], BaseMinirest = #{ diff --git a/apps/emqx_dashboard/src/emqx_dashboard_bad_api.erl b/apps/emqx_dashboard/src/emqx_dashboard_bad_api.erl new file mode 100644 index 000000000..3121174a7 --- /dev/null +++ b/apps/emqx_dashboard/src/emqx_dashboard_bad_api.erl @@ -0,0 +1,29 @@ +%%-------------------------------------------------------------------- +%% Copyright (c) 2020-2022 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_dashboard_bad_api). + +-include_lib("emqx/include/logger.hrl"). + +-export([init/2]). + +init(Req0, State) -> + ?SLOG(warning, #{msg => "unexpected_api_access", request => Req0}), + Req = cowboy_req:reply(404, + #{<<"content-type">> => <<"application/json">>}, + <<"{\"code\": \"API_NOT_EXIST\", \"message\": \"Request Path Not Found\"}">>, + Req0), + {ok, Req, State}. From 9ef179598580faf3649b83f9aba1247af9448e10 Mon Sep 17 00:00:00 2001 From: DDDHuang <44492639+DDDHuang@users.noreply.github.com> Date: Wed, 13 Apr 2022 14:23:04 +0800 Subject: [PATCH 3/5] fix: add bad api test --- .../test/emqx_dashboard_bad_api_SUITE.erl | 74 +++++++++++++++++++ ...ITE.erl => emqx_mgmt_api_topics_SUITE.erl} | 9 ++- 2 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 apps/emqx_dashboard/test/emqx_dashboard_bad_api_SUITE.erl rename apps/emqx_management/test/{emqx_mgmt_api_routes_SUITE.erl => emqx_mgmt_api_topics_SUITE.erl} (91%) diff --git a/apps/emqx_dashboard/test/emqx_dashboard_bad_api_SUITE.erl b/apps/emqx_dashboard/test/emqx_dashboard_bad_api_SUITE.erl new file mode 100644 index 000000000..341ba5691 --- /dev/null +++ b/apps/emqx_dashboard/test/emqx_dashboard_bad_api_SUITE.erl @@ -0,0 +1,74 @@ +%%-------------------------------------------------------------------- +%% Copyright (c) 2020-2022 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_dashboard_bad_api_SUITE). + +-compile(nowarn_export_all). +-compile(export_all). + +-include_lib("emqx/include/http_api.hrl"). + +-include_lib("eunit/include/eunit.hrl"). + +-define(SERVER, "http://127.0.0.1:18083/api/v5"). + +all() -> + emqx_common_test_helpers:all(?MODULE). + +init_per_suite(Config) -> + mria:start(), + application:load(emqx_dashboard), + emqx_common_test_helpers:start_apps([emqx_conf, emqx_dashboard], fun set_special_configs/1), + Config. + +set_special_configs(emqx_dashboard) -> + Config = #{ + default_username => <<"admin">>, + default_password => <<"public">>, + listeners => [#{ + protocol => http, + port => 18083 + }] + }, + emqx_config:put([emqx_dashboard], Config), + ok; +set_special_configs(_) -> + ok. + +end_per_suite(Config) -> + end_suite(), + Config. + +end_suite() -> + application:unload(emqx_management), + emqx_common_test_helpers:stop_apps([emqx_dashboard]). + +t_bad_api_path(_) -> + Url = ?SERVER ++ "/for/test/some/path/not/exist", + {error,{"HTTP/1.1", 404, "Not Found"}} = request(Url), + ok. + +request(Url) -> + Request = {Url, []}, + case httpc:request(get, Request, [], []) of + {error, Reason} -> + {error, Reason}; + {ok, {{"HTTP/1.1", Code, _}, _, Return} } + when Code >= 200 andalso Code =< 299 -> + {ok, emqx_json:decode(Return, [return_maps])}; + {ok, {Reason, _, _}} -> + {error, Reason} + end. diff --git a/apps/emqx_management/test/emqx_mgmt_api_routes_SUITE.erl b/apps/emqx_management/test/emqx_mgmt_api_topics_SUITE.erl similarity index 91% rename from apps/emqx_management/test/emqx_mgmt_api_routes_SUITE.erl rename to apps/emqx_management/test/emqx_mgmt_api_topics_SUITE.erl index 460ce55d7..f6536c3b1 100644 --- a/apps/emqx_management/test/emqx_mgmt_api_routes_SUITE.erl +++ b/apps/emqx_management/test/emqx_mgmt_api_topics_SUITE.erl @@ -13,7 +13,7 @@ %% See the License for the specific language governing permissions and %% limitations under the License. %%-------------------------------------------------------------------- --module(emqx_mgmt_api_routes_SUITE). +-module(emqx_mgmt_api_topics_SUITE). -compile(export_all). -compile(nowarn_export_all). @@ -36,7 +36,8 @@ t_nodes_api(_) -> {ok, _} = emqtt:connect(Client), {ok, _, _} = emqtt:subscribe(Client, Topic), - Path = emqx_mgmt_api_test_util:api_path(["routes"]), + %% list all + Path = emqx_mgmt_api_test_util:api_path(["topics"]), {ok, Response} = emqx_mgmt_api_test_util:request_api(get, Path), RoutesData = emqx_json:decode(Response, [return_maps]), Meta = maps:get(<<"meta">>, RoutesData), @@ -48,8 +49,8 @@ t_nodes_api(_) -> ?assertEqual(Topic, maps:get(<<"topic">>, Route)), ?assertEqual(atom_to_binary(node(), utf8), maps:get(<<"node">>, Route)), - %% get routes/:topic - RoutePath = emqx_mgmt_api_test_util:api_path(["routes", Topic]), + %% get topics/:topic + RoutePath = emqx_mgmt_api_test_util:api_path(["topics", Topic]), {ok, RouteResponse} = emqx_mgmt_api_test_util:request_api(get, RoutePath), RouteData = emqx_json:decode(RouteResponse, [return_maps]), ?assertEqual(Topic, maps:get(<<"topic">>, RouteData)), From bf827cffa871b2b14f29cd285e188cea0aefe503 Mon Sep 17 00:00:00 2001 From: DDDHuang <44492639+DDDHuang@users.noreply.github.com> Date: Wed, 13 Apr 2022 15:51:39 +0800 Subject: [PATCH 4/5] fix: authn bad examples --- apps/emqx_authn/src/emqx_authn_api.erl | 45 ++++++++++--------- .../src/emqx_dashboard_swagger.erl | 5 +-- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/apps/emqx_authn/src/emqx_authn_api.erl b/apps/emqx_authn/src/emqx_authn_api.erl index 2d72f9245..d053b1c4b 100644 --- a/apps/emqx_authn/src/emqx_authn_api.erl +++ b/apps/emqx_authn/src/emqx_authn_api.erl @@ -1412,17 +1412,9 @@ authenticator_examples() -> status_metrics_example() -> #{ - metrics => #{ - matched => 0, - success => 0, - failed => 0, - rate => 0.0, - rate_last5m => 0.0, - rate_max => 0.0 - }, - node_metrics => [ - #{ - node => node(), + status_metrics => #{ + summary => <<"Authn status metrics">>, + value => #{ metrics => #{ matched => 0, success => 0, @@ -1430,16 +1422,29 @@ status_metrics_example() -> rate => 0.0, rate_last5m => 0.0, rate_max => 0.0 - } + }, + node_metrics => [ + #{ + node => node(), + metrics => #{ + matched => 0, + success => 0, + failed => 0, + rate => 0.0, + rate_last5m => 0.0, + rate_max => 0.0 + } + } + ], + status => connected, + node_status => [ + #{ + node => node(), + status => connected + } + ] } - ], - status => connected, - node_status => [ - #{ - node => node(), - status => connected - } - ] + } }. request_user_create_examples() -> diff --git a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl index f8fe6450c..a4bbe74fa 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl @@ -109,10 +109,7 @@ schema_with_example(Type, Example) -> -spec(schema_with_examples(hocon_schema:type(), map()) -> hocon_schema:field_schema_map()). schema_with_examples(Type, Examples) -> - %% Swagger can dynamically distinguish if there are multiple examples. - %% But explicitly declaring examples as plural - %% may cause some example structures to be incorrectly identified. - schema_with_example(Type, Examples). + hoconsc:mk(Type, #{examples => #{<<"examples">> => Examples}}). -spec(error_codes(list(atom())) -> hocon_schema:fields()). error_codes(Codes) -> From 1edf9fd0864827860424284b07bde1d0b8ac4581 Mon Sep 17 00:00:00 2001 From: DDDHuang <44492639+DDDHuang@users.noreply.github.com> Date: Wed, 13 Apr 2022 15:59:22 +0800 Subject: [PATCH 5/5] chore: rm some useless mgmt func --- apps/emqx_management/src/emqx_mgmt.erl | 28 +++----------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/apps/emqx_management/src/emqx_mgmt.erl b/apps/emqx_management/src/emqx_mgmt.erl index fecf77070..b460b69b4 100644 --- a/apps/emqx_management/src/emqx_mgmt.erl +++ b/apps/emqx_management/src/emqx_mgmt.erl @@ -93,23 +93,13 @@ ]). %% Common Table API --export([ item/2 - , max_row_limit/0 +-export([ max_row_limit/0 ]). --export([ return/0 - , return/1]). - -define(APP, emqx_management). -elvis([{elvis_style, god_modules, disable}]). -%% TODO: remove these function after all api use minirest version 1.X -return() -> - ok. -return(_Response) -> - ok. - %%-------------------------------------------------------------------- %% Node Info %%-------------------------------------------------------------------- @@ -331,7 +321,8 @@ call_client(Node, ClientId, Req) -> do_list_subscriptions() -> case check_row_limit([mqtt_subproperty]) of false -> throw(max_row_limit); - ok -> [item(subscription, Sub) || Sub <- ets:tab2list(mqtt_subproperty)] + ok -> [#{topic => Topic, clientid => ClientId, options => Options} + || {{Topic, ClientId}, Options} <- ets:tab2list(mqtt_subproperty)] end. list_subscriptions(Node) -> @@ -452,19 +443,6 @@ create_banned(Banned) -> delete_banned(Who) -> emqx_banned:delete(Who). -%%-------------------------------------------------------------------- -%% Common Table API -%%-------------------------------------------------------------------- - -item(subscription, {{Topic, ClientId}, Options}) -> - #{topic => Topic, clientid => ClientId, options => Options}; - - %% TODO: may be delete -item(route, #route{topic = Topic, dest = Node}) -> - #{topic => Topic, node => Node}; -item(route, {Topic, Node}) -> - #{topic => Topic, node => Node}. - %%-------------------------------------------------------------------- %% Internal Functions. %%--------------------------------------------------------------------