Jelajahi Sumber

fix: add authn authz metrics supervisor

EMQ-YangM 3 tahun lalu
induk
melakukan
6530604f40

+ 3 - 1
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) ->

+ 36 - 0
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
+        ]
+    }}.

+ 2 - 1
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)
         ]
     }}.
 

+ 0 - 1
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);

+ 1 - 2
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}}.

+ 12 - 8
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) ->