fix(metrics): adjust metrics count codes

This commit is contained in:
firest 2022-07-01 10:00:43 +08:00
parent 7f18969f1e
commit 9ce2dbb77a
1 changed files with 10 additions and 4 deletions

View File

@ -225,7 +225,16 @@ authenticate(#{listener := Listener, protocol := Protocol} = Credential, _AuthRe
inc_authenticate_metric('authentication.success.anonymous'), 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'), inc_authenticate_metric('authentication.success.anonymous'),
@ -614,7 +623,6 @@ handle_create_authenticator(Chain, Config, Providers) ->
end. end.
do_authenticate(_ChainName, [], _) -> do_authenticate(_ChainName, [], _) ->
inc_authenticate_metric('authentication.failure'),
{stop, {error, not_authorized}}; {stop, {error, not_authorized}};
do_authenticate( do_authenticate(
ChainName, [#authenticator{id = ID, provider = Provider, state = State} | More], Credential ChainName, [#authenticator{id = ID, provider = Provider, state = State} | More], Credential
@ -633,10 +641,8 @@ do_authenticate(
%% {error, Reason} %% {error, Reason}
case Result of case Result of
{ok, _} -> {ok, _} ->
inc_authenticate_metric('authentication.success'),
emqx_metrics_worker:inc(authn_metrics, MetricsID, success); emqx_metrics_worker:inc(authn_metrics, MetricsID, success);
{error, _} -> {error, _} ->
inc_authenticate_metric('authentication.failure'),
emqx_metrics_worker:inc(authn_metrics, MetricsID, failed); emqx_metrics_worker:inc(authn_metrics, MetricsID, failed);
_ -> _ ->
ok ok