fix: add authn authz metrics supervisor

This commit is contained in:
EMQ-YangM 2022-04-28 14:38:45 +08:00
parent 098598a0be
commit 6530604f40
6 changed files with 54 additions and 13 deletions

View File

@ -580,7 +580,9 @@ handle_delete_authenticator(Chain, AuthenticatorID) ->
end, end,
case do_delete_authenticators(MatchFun, Chain) of case do_delete_authenticators(MatchFun, Chain) of
[] -> {error, {not_found, {authenticator, AuthenticatorID}}}; [] -> {error, {not_found, {authenticator, AuthenticatorID}}};
[AuthenticatorID] -> ok [AuthenticatorID] ->
emqx_plugin_libs_metrics:clear_metrics(authn_metrics, AuthenticatorID),
ok
end. end.
handle_move_authenticator(Chain, AuthenticatorID, Position) -> handle_move_authenticator(Chain, AuthenticatorID, Position) ->

View File

@ -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
]
}}.

View File

@ -35,7 +35,8 @@ init([]) ->
child_spec(emqx_hooks, worker), child_spec(emqx_hooks, worker),
child_spec(emqx_stats, worker), child_spec(emqx_stats, worker),
child_spec(emqx_metrics, worker), child_spec(emqx_metrics, worker),
child_spec(emqx_ctl, worker) child_spec(emqx_ctl, worker),
child_spec(emqx_authn_authz_metrics_sup, supervisor)
] ]
}}. }}.

View File

@ -1100,7 +1100,6 @@ update_authenticator(ConfKeyPath, ChainName, AuthenticatorID, Config) ->
delete_authenticator(ConfKeyPath, ChainName, AuthenticatorID) -> delete_authenticator(ConfKeyPath, ChainName, AuthenticatorID) ->
case update_config(ConfKeyPath, {delete_authenticator, ChainName, AuthenticatorID}) of case update_config(ConfKeyPath, {delete_authenticator, ChainName, AuthenticatorID}) of
{ok, _} -> {ok, _} ->
emqx_plugin_libs_metrics:clear_metrics(authn_metrics, AuthenticatorID),
{204}; {204};
{error, {_PrePostConfigUpdate, emqx_authentication, Reason}} -> {error, {_PrePostConfigUpdate, emqx_authentication, Reason}} ->
serialize_error(Reason); serialize_error(Reason);

View File

@ -27,6 +27,5 @@ start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []). supervisor:start_link({local, ?MODULE}, ?MODULE, []).
init([]) -> init([]) ->
Metrics = emqx_plugin_libs_metrics:child_spec(authn_metrics), ChildSpecs = [],
ChildSpecs = [Metrics],
{ok, {{one_for_one, 10, 10}, ChildSpecs}}. {ok, {{one_for_one, 10, 10}, ChildSpecs}}.

View File

@ -22,7 +22,8 @@
-export([ -export([
start_link/1, start_link/1,
stop/1, stop/1,
child_spec/1 child_spec/1,
child_spec/2
]). ]).
-export([ -export([
@ -99,8 +100,11 @@
-spec child_spec(handler_name()) -> supervisor:child_spec(). -spec child_spec(handler_name()) -> supervisor:child_spec().
child_spec(Name) -> child_spec(Name) ->
child_spec(emqx_plugin_libs_metrics, Name).
child_spec(ChldName, Name) ->
#{ #{
id => emqx_plugin_libs_metrics, id => ChldName,
start => {emqx_plugin_libs_metrics, start_link, [Name]}, start => {emqx_plugin_libs_metrics, start_link, [Name]},
restart => permanent, restart => permanent,
shutdown => 5000, shutdown => 5000,