diff --git a/apps/emqx/src/emqx_authentication.erl b/apps/emqx/src/emqx_authentication.erl index 0b5948955..418e4fd78 100644 --- a/apps/emqx/src/emqx_authentication.erl +++ b/apps/emqx/src/emqx_authentication.erl @@ -580,7 +580,9 @@ handle_delete_authenticator(Chain, AuthenticatorID) -> end, case do_delete_authenticators(MatchFun, Chain) of [] -> {error, {not_found, {authenticator, AuthenticatorID}}}; - [AuthenticatorID] -> ok + [AuthenticatorID] -> + emqx_plugin_libs_metrics:clear_metrics(authn_metrics, AuthenticatorID), + ok end. handle_move_authenticator(Chain, AuthenticatorID, Position) -> diff --git a/apps/emqx/src/emqx_authn_authz_metrics_sup.erl b/apps/emqx/src/emqx_authn_authz_metrics_sup.erl new file mode 100644 index 000000000..569e4a69f --- /dev/null +++ b/apps/emqx/src/emqx_authn_authz_metrics_sup.erl @@ -0,0 +1,36 @@ +%%-------------------------------------------------------------------- +%% Copyright (c) 2018-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_authn_authz_metrics_sup). + +-behaviour(supervisor). + +-export([start_link/0]). + +-export([init/1]). + +start_link() -> + supervisor:start_link({local, ?MODULE}, ?MODULE, []). + +init([]) -> + AuthnMetrics = emqx_plugin_libs_metrics:child_spec(emqx_authn_metrics, authn_metrics), + AuthzMetrics = emqx_plugin_libs_metrics:child_spec(eqmx_authz_metrics, authz_metrics), + {ok, { + {one_for_one, 10, 100}, + [ AuthnMetrics, + AuthzMetrics + ] + }}. diff --git a/apps/emqx/src/emqx_kernel_sup.erl b/apps/emqx/src/emqx_kernel_sup.erl index 654c5e223..3c8b5d1d3 100644 --- a/apps/emqx/src/emqx_kernel_sup.erl +++ b/apps/emqx/src/emqx_kernel_sup.erl @@ -35,7 +35,8 @@ init([]) -> child_spec(emqx_hooks, worker), child_spec(emqx_stats, worker), child_spec(emqx_metrics, worker), - child_spec(emqx_ctl, worker) + child_spec(emqx_ctl, worker), + child_spec(emqx_authn_authz_metrics_sup, supervisor) ] }}. diff --git a/apps/emqx_authn/src/emqx_authn_api.erl b/apps/emqx_authn/src/emqx_authn_api.erl index 9302ee722..e509ca532 100644 --- a/apps/emqx_authn/src/emqx_authn_api.erl +++ b/apps/emqx_authn/src/emqx_authn_api.erl @@ -1100,7 +1100,6 @@ update_authenticator(ConfKeyPath, ChainName, AuthenticatorID, Config) -> delete_authenticator(ConfKeyPath, ChainName, AuthenticatorID) -> case update_config(ConfKeyPath, {delete_authenticator, ChainName, AuthenticatorID}) of {ok, _} -> - emqx_plugin_libs_metrics:clear_metrics(authn_metrics, AuthenticatorID), {204}; {error, {_PrePostConfigUpdate, emqx_authentication, Reason}} -> serialize_error(Reason); diff --git a/apps/emqx_authn/src/emqx_authn_sup.erl b/apps/emqx_authn/src/emqx_authn_sup.erl index 6dbe605fe..d88acfacc 100644 --- a/apps/emqx_authn/src/emqx_authn_sup.erl +++ b/apps/emqx_authn/src/emqx_authn_sup.erl @@ -27,6 +27,5 @@ start_link() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []). init([]) -> - Metrics = emqx_plugin_libs_metrics:child_spec(authn_metrics), - ChildSpecs = [Metrics], + ChildSpecs = [], {ok, {{one_for_one, 10, 10}, ChildSpecs}}. diff --git a/apps/emqx_plugin_libs/src/emqx_plugin_libs_metrics.erl b/apps/emqx_plugin_libs/src/emqx_plugin_libs_metrics.erl index d3cc3e63c..a438d3078 100644 --- a/apps/emqx_plugin_libs/src/emqx_plugin_libs_metrics.erl +++ b/apps/emqx_plugin_libs/src/emqx_plugin_libs_metrics.erl @@ -22,7 +22,8 @@ -export([ start_link/1, stop/1, - child_spec/1 + child_spec/1, + child_spec/2 ]). -export([ @@ -99,14 +100,17 @@ -spec child_spec(handler_name()) -> supervisor:child_spec(). child_spec(Name) -> + child_spec(emqx_plugin_libs_metrics, Name). + +child_spec(ChldName, Name) -> #{ - id => emqx_plugin_libs_metrics, - start => {emqx_plugin_libs_metrics, start_link, [Name]}, - restart => permanent, - shutdown => 5000, - type => worker, - modules => [emqx_plugin_libs_metrics] - }. + id => ChldName, + start => {emqx_plugin_libs_metrics, start_link, [Name]}, + restart => permanent, + shutdown => 5000, + type => worker, + modules => [emqx_plugin_libs_metrics] + }. -spec create_metrics(handler_name(), metric_id(), [atom()]) -> ok | {error, term()}. create_metrics(Name, Id, Metrics) ->