feat(authz/prometheus): add authz cache_miss counter

This commit is contained in:
Zaiming (Stone) Shi 2024-01-18 08:33:57 +01:00
parent 85b6a3454c
commit 556092b7d0
4 changed files with 11 additions and 3 deletions

View File

@ -135,6 +135,7 @@ is_username_defined(_) -> false.
check_authorization_cache(ClientInfo, Action, Topic) ->
case emqx_authz_cache:get_authz_cache(Action, Topic) of
not_found ->
inc_authz_metrics(cache_miss),
AuthzResult = do_authorize(ClientInfo, Action, Topic),
emqx_authz_cache:put_authz_cache(Action, Topic, AuthzResult),
AuthzResult;
@ -219,7 +220,9 @@ inc_authz_metrics(allow) ->
inc_authz_metrics(deny) ->
emqx_metrics:inc('authorization.deny');
inc_authz_metrics(cache_hit) ->
emqx_metrics:inc('authorization.cache_hit').
emqx_metrics:inc('authorization.cache_hit');
inc_authz_metrics(cache_miss) ->
emqx_metrics:inc('authorization.cache_miss').
inc_authn_metrics(error) ->
emqx_metrics:inc('authentication.failure');

View File

@ -258,7 +258,8 @@
-define(STASTS_ACL_METRICS, [
{counter, 'authorization.allow'},
{counter, 'authorization.deny'},
{counter, 'authorization.cache_hit'}
{counter, 'authorization.cache_hit'},
{counter, 'authorization.cache_miss'}
]).
%% Statistic metrics for auth checking
@ -702,6 +703,7 @@ reserved_idx('session.terminated') -> 224;
reserved_idx('authorization.allow') -> 300;
reserved_idx('authorization.deny') -> 301;
reserved_idx('authorization.cache_hit') -> 302;
reserved_idx('authorization.cache_miss') -> 303;
reserved_idx('authentication.success') -> 310;
reserved_idx('authentication.success.anonymous') -> 311;
reserved_idx('authentication.failure') -> 312;

View File

@ -2,7 +2,7 @@
{application, emqx_prometheus, [
{description, "Prometheus for EMQX"},
% strict semver, bump manually!
{vsn, "5.0.18"},
{vsn, "5.0.19"},
{modules, []},
{registered, [emqx_prometheus_sup]},
{applications, [kernel, stdlib, prometheus, emqx, emqx_management]},

View File

@ -486,6 +486,8 @@ emqx_collect(emqx_authorization_deny, Stats) ->
counter_metric(?C('authorization.deny', Stats));
emqx_collect(emqx_authorization_cache_hit, Stats) ->
counter_metric(?C('authorization.cache_hit', Stats));
emqx_collect(emqx_authorization_cache_miss, Stats) ->
counter_metric(?C('authorization.cache_miss', Stats));
emqx_collect(emqx_authorization_superuser, Stats) ->
counter_metric(?C('authorization.superuser', Stats));
emqx_collect(emqx_authorization_nomatch, Stats) ->
@ -591,6 +593,7 @@ emqx_metrics_acl() ->
emqx_authorization_allow,
emqx_authorization_deny,
emqx_authorization_cache_hit,
emqx_authorization_cache_miss,
emqx_authorization_superuser,
emqx_authorization_nomatch,
emqx_authorization_matched_allow,