Merge pull request #7781 from HJianBo/rename-acl-metrics

feat(metrics): refactor authz metrics name
This commit is contained in:
JianBo He 2022-04-29 16:52:43 +08:00 committed by GitHub
commit d36d27c533
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 20 deletions

View File

@ -50,7 +50,7 @@ authorize(ClientInfo, PubSub, Topic) ->
true -> check_authorization_cache(ClientInfo, PubSub, Topic);
false -> do_authorize(ClientInfo, PubSub, Topic)
end,
inc_acl_metrics(Result),
inc_authz_metrics(Result),
Result.
check_authorization_cache(ClientInfo, PubSub, Topic) ->
@ -64,7 +64,7 @@ check_authorization_cache(ClientInfo, PubSub, Topic) ->
'client.check_authz_complete',
[ClientInfo, PubSub, Topic, AuthzResult, cache]
),
inc_acl_metrics(cache_hit),
inc_authz_metrics(cache_hit),
AuthzResult
end.
@ -80,10 +80,10 @@ run_hooks(Name, Args, Acc) ->
ok = emqx_metrics:inc(Name),
emqx_hooks:run_fold(Name, Args, Acc).
-compile({inline, [inc_acl_metrics/1]}).
inc_acl_metrics(allow) ->
emqx_metrics:inc('client.acl.allow');
inc_acl_metrics(deny) ->
emqx_metrics:inc('client.acl.deny');
inc_acl_metrics(cache_hit) ->
emqx_metrics:inc('client.acl.cache_hit').
-compile({inline, [inc_authz_metrics/1]}).
inc_authz_metrics(allow) ->
emqx_metrics:inc('client.authorization.allow');
inc_authz_metrics(deny) ->
emqx_metrics:inc('client.authorization.deny');
inc_authz_metrics(cache_hit) ->
emqx_metrics:inc('client.authorization.cache_hit').

View File

@ -255,9 +255,9 @@
%% Statistic metrics for ACL checking
-define(STASTS_ACL_METRICS, [
{counter, 'client.acl.allow'},
{counter, 'client.acl.deny'},
{counter, 'client.acl.cache_hit'}
{counter, 'client.authorization.allow'},
{counter, 'client.authorization.deny'},
{counter, 'client.authorization.cache_hit'}
]).
%% Overload protetion counters
@ -677,9 +677,9 @@ reserved_idx('session.resumed') -> 221;
reserved_idx('session.takenover') -> 222;
reserved_idx('session.discarded') -> 223;
reserved_idx('session.terminated') -> 224;
reserved_idx('client.acl.allow') -> 300;
reserved_idx('client.acl.deny') -> 301;
reserved_idx('client.acl.cache_hit') -> 302;
reserved_idx('client.authorization.allow') -> 300;
reserved_idx('client.authorization.deny') -> 301;
reserved_idx('client.authorization.cache_hit') -> 302;
reserved_idx('olp.delay.ok') -> 400;
reserved_idx('olp.delay.timeout') -> 401;
reserved_idx('olp.hbn') -> 402;

View File

@ -52,9 +52,9 @@
-type sources() :: [source()].
-define(METRIC_ALLOW, 'client.authorize.allow').
-define(METRIC_DENY, 'client.authorize.deny').
-define(METRIC_NOMATCH, 'client.authorize.nomatch').
-define(METRIC_ALLOW, 'client.authorization.matched.allow').
-define(METRIC_DENY, 'client.authorization.matched.deny').
-define(METRIC_NOMATCH, 'client.authorization.nomatch').
-define(METRICS, [?METRIC_ALLOW, ?METRIC_DENY, ?METRIC_NOMATCH]).

View File

@ -245,7 +245,7 @@ t_check_expire(_Config) ->
Payload = #{
<<"username">> => <<"username">>,
<<"acl">> => #{<<"sub">> => [<<"a/b">>]},
<<"exp">> => erlang:system_time(second) + 1
<<"exp">> => erlang:system_time(second) + 5
},
JWT = generate_jws(Payload),
@ -270,7 +270,7 @@ t_check_expire(_Config) ->
emqtt:unsubscribe(C, <<"a/b">>)
),
timer:sleep(2000),
timer:sleep(6000),
?assertMatch(
{ok, #{}, [?RC_NOT_AUTHORIZED]},