Merge pull request #8352 from lafirest/fix/authn_metrics
feat(metrics): optimize client.authenticate
This commit is contained in:
commit
5cf2e7c839
|
@ -5,11 +5,17 @@
|
||||||
[{load_module,emqx_channel,brutal_purge,soft_purge,[]},
|
[{load_module,emqx_channel,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_schema,brutal_purge,soft_purge,[]},
|
{load_module,emqx_schema,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_release,brutal_purge,soft_purge,[]},
|
{load_module,emqx_release,brutal_purge,soft_purge,[]},
|
||||||
|
{load_module,emqx_access_control,brutal_purge,soft_purge,[]},
|
||||||
|
{load_module,emqx_authentication,brutal_purge,soft_purge,[]},
|
||||||
|
{load_module,emqx_metrics,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_relup}]},
|
{load_module,emqx_relup}]},
|
||||||
{<<".*">>,[]}],
|
{<<".*">>,[]}],
|
||||||
[{"5.0.0",
|
[{"5.0.0",
|
||||||
[{load_module,emqx_channel,brutal_purge,soft_purge,[]},
|
[{load_module,emqx_channel,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_schema,brutal_purge,soft_purge,[]},
|
{load_module,emqx_schema,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_release,brutal_purge,soft_purge,[]},
|
{load_module,emqx_release,brutal_purge,soft_purge,[]},
|
||||||
|
{load_module,emqx_access_control,brutal_purge,soft_purge,[]},
|
||||||
|
{load_module,emqx_authentication,brutal_purge,soft_purge,[]},
|
||||||
|
{load_module,emqx_metrics,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_relup}]},
|
{load_module,emqx_relup}]},
|
||||||
{<<".*">>,[]}]}.
|
{<<".*">>,[]}]}.
|
||||||
|
|
|
@ -215,17 +215,29 @@ when
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
|
||||||
authenticate(#{enable_authn := false}, _AuthResult) ->
|
authenticate(#{enable_authn := false}, _AuthResult) ->
|
||||||
|
inc_authenticate_metric('authentication.success.anonymous'),
|
||||||
ignore;
|
ignore;
|
||||||
authenticate(#{listener := Listener, protocol := Protocol} = Credential, _AuthResult) ->
|
authenticate(#{listener := Listener, protocol := Protocol} = Credential, _AuthResult) ->
|
||||||
case get_authenticators(Listener, global_chain(Protocol)) of
|
case get_authenticators(Listener, global_chain(Protocol)) of
|
||||||
{ok, ChainName, Authenticators} ->
|
{ok, ChainName, Authenticators} ->
|
||||||
case get_enabled(Authenticators) of
|
case get_enabled(Authenticators) of
|
||||||
[] ->
|
[] ->
|
||||||
|
inc_authenticate_metric('authentication.success.anonymous'),
|
||||||
ignore;
|
ignore;
|
||||||
NAuthenticators ->
|
NAuthenticators ->
|
||||||
do_authenticate(ChainName, NAuthenticators, Credential)
|
Result = do_authenticate(ChainName, NAuthenticators, Credential),
|
||||||
|
inc_authenticate_metric(
|
||||||
|
case Result of
|
||||||
|
{stop, {ok, _}} ->
|
||||||
|
'authentication.success';
|
||||||
|
_ ->
|
||||||
|
'authentication.failure'
|
||||||
|
end
|
||||||
|
),
|
||||||
|
Result
|
||||||
end;
|
end;
|
||||||
none ->
|
none ->
|
||||||
|
inc_authenticate_metric('authentication.success.anonymous'),
|
||||||
ignore
|
ignore
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -902,3 +914,9 @@ to_list(M) when is_map(M) -> [M];
|
||||||
to_list(L) when is_list(L) -> L.
|
to_list(L) when is_list(L) -> L.
|
||||||
|
|
||||||
call(Call) -> gen_server:call(?MODULE, Call, infinity).
|
call(Call) -> gen_server:call(?MODULE, Call, infinity).
|
||||||
|
|
||||||
|
inc_authenticate_metric('authentication.success.anonymous' = Metric) ->
|
||||||
|
emqx_metrics:inc(Metric),
|
||||||
|
emqx_metrics:inc('authentication.success');
|
||||||
|
inc_authenticate_metric(Metric) ->
|
||||||
|
emqx_metrics:inc(Metric).
|
||||||
|
|
|
@ -260,6 +260,13 @@
|
||||||
{counter, 'authorization.cache_hit'}
|
{counter, 'authorization.cache_hit'}
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
%% Statistic metrics for auth checking
|
||||||
|
-define(STASTS_AUTHN_METRICS, [
|
||||||
|
{counter, 'authentication.success'},
|
||||||
|
{counter, 'authentication.success.anonymous'},
|
||||||
|
{counter, 'authentication.failure'}
|
||||||
|
]).
|
||||||
|
|
||||||
%% Overload protetion counters
|
%% Overload protetion counters
|
||||||
-define(OLP_METRICS, [
|
-define(OLP_METRICS, [
|
||||||
{counter, 'olp.delay.ok'},
|
{counter, 'olp.delay.ok'},
|
||||||
|
@ -543,6 +550,7 @@ init([]) ->
|
||||||
?CLIENT_METRICS,
|
?CLIENT_METRICS,
|
||||||
?SESSION_METRICS,
|
?SESSION_METRICS,
|
||||||
?STASTS_ACL_METRICS,
|
?STASTS_ACL_METRICS,
|
||||||
|
?STASTS_AUTHN_METRICS,
|
||||||
?OLP_METRICS
|
?OLP_METRICS
|
||||||
]),
|
]),
|
||||||
% Store reserved indices
|
% Store reserved indices
|
||||||
|
@ -690,6 +698,9 @@ reserved_idx('session.terminated') -> 224;
|
||||||
reserved_idx('authorization.allow') -> 300;
|
reserved_idx('authorization.allow') -> 300;
|
||||||
reserved_idx('authorization.deny') -> 301;
|
reserved_idx('authorization.deny') -> 301;
|
||||||
reserved_idx('authorization.cache_hit') -> 302;
|
reserved_idx('authorization.cache_hit') -> 302;
|
||||||
|
reserved_idx('authentication.success') -> 310;
|
||||||
|
reserved_idx('authentication.success.anonymous') -> 311;
|
||||||
|
reserved_idx('authentication.failure') -> 312;
|
||||||
reserved_idx('olp.delay.ok') -> 400;
|
reserved_idx('olp.delay.ok') -> 400;
|
||||||
reserved_idx('olp.delay.timeout') -> 401;
|
reserved_idx('olp.delay.timeout') -> 401;
|
||||||
reserved_idx('olp.hbn') -> 402;
|
reserved_idx('olp.hbn') -> 402;
|
||||||
|
|
Loading…
Reference in New Issue