fix: format code
This commit is contained in:
parent
5b0ee30d72
commit
4365de9ad5
|
@ -579,7 +579,8 @@ handle_delete_authenticator(Chain, AuthenticatorID) ->
|
|||
ID =:= AuthenticatorID
|
||||
end,
|
||||
case do_delete_authenticators(MatchFun, Chain) of
|
||||
[] -> {error, {not_found, {authenticator, AuthenticatorID}}};
|
||||
[] ->
|
||||
{error, {not_found, {authenticator, AuthenticatorID}}};
|
||||
[AuthenticatorID] ->
|
||||
emqx_plugin_libs_metrics:clear_metrics(authn_metrics, AuthenticatorID),
|
||||
ok
|
||||
|
@ -612,8 +613,12 @@ handle_create_authenticator(Chain, Config, Providers) ->
|
|||
Chain#chain{authenticators = NAuthenticators}
|
||||
),
|
||||
|
||||
ok = emqx_plugin_libs_metrics:create_metrics(authn_metrics, AuthenticatorID,
|
||||
[matched, success, failed, ignore], [matched]),
|
||||
ok = emqx_plugin_libs_metrics:create_metrics(
|
||||
authn_metrics,
|
||||
AuthenticatorID,
|
||||
[matched, success, failed, ignore],
|
||||
[matched]
|
||||
),
|
||||
{ok, serialize_authenticator(Authenticator)};
|
||||
{error, Reason} ->
|
||||
{error, Reason}
|
||||
|
@ -639,7 +644,8 @@ do_authenticate([#authenticator{id = ID, provider = Provider, state = State} | M
|
|||
emqx_plugin_libs_metrics:inc(authn_metrics, ID, success);
|
||||
{error, _} ->
|
||||
emqx_plugin_libs_metrics:inc(authn_metrics, ID, failed);
|
||||
_ -> ok
|
||||
_ ->
|
||||
ok
|
||||
end,
|
||||
{stop, Result}
|
||||
catch
|
||||
|
|
|
@ -28,9 +28,11 @@ start_link() ->
|
|||
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, {
|
||||
{ok,
|
||||
{
|
||||
{one_for_one, 10, 100},
|
||||
[ AuthnMetrics,
|
||||
[
|
||||
AuthnMetrics,
|
||||
AuthzMetrics
|
||||
]
|
||||
}}.
|
||||
|
|
|
@ -902,8 +902,12 @@ create_authenticator(ConfKeyPath, ChainName, Config) ->
|
|||
raw_config := AuthenticatorsConfig
|
||||
}} ->
|
||||
{ok, AuthenticatorConfig} = find_config(ID, AuthenticatorsConfig),
|
||||
ok = emqx_plugin_libs_metrics:create_metrics(authn_metrics, ID,
|
||||
[matched, success, failed, ignore], [matched]),
|
||||
ok = emqx_plugin_libs_metrics:create_metrics(
|
||||
authn_metrics,
|
||||
ID,
|
||||
[matched, success, failed, ignore],
|
||||
[matched]
|
||||
),
|
||||
{200, maps:put(id, ID, convert_certs(fill_defaults(AuthenticatorConfig)))};
|
||||
{error, {_PrePostConfigUpdate, emqx_authentication, Reason}} ->
|
||||
serialize_error(Reason);
|
||||
|
@ -975,7 +979,8 @@ lookup_from_all_nodes(ChainName, AuthenticatorID) ->
|
|||
HelpFun = fun(M, Name) -> lists:map(MKMap(Name), maps:to_list(M)) end,
|
||||
{200, #{
|
||||
node_resource_metrics => HelpFun(maps:map(Fun, ResourceMetricsMap), metrics),
|
||||
resource_metrics => case maps:size(AggregateResourceMetrics) of
|
||||
resource_metrics =>
|
||||
case maps:size(AggregateResourceMetrics) of
|
||||
0 -> #{};
|
||||
_ -> restructure_map(AggregateResourceMetrics)
|
||||
end,
|
||||
|
@ -1052,7 +1057,7 @@ restructure_map(#{
|
|||
restructure_map(#{
|
||||
counters := #{failed := Failed, matched := Match, success := Succ},
|
||||
rate := #{matched := #{current := Rate, last5m := Rate5m, max := RateMax}}
|
||||
}) ->
|
||||
}) ->
|
||||
#{
|
||||
matched => Match,
|
||||
success => Succ,
|
||||
|
|
|
@ -89,7 +89,6 @@ backend(Name) ->
|
|||
|
||||
fields("metrics_status_fields") ->
|
||||
[
|
||||
|
||||
{"resource_metrics", mk(ref(?MODULE, "resource_metrics"), #{desc => ?DESC("metrics")})},
|
||||
{"node_resource_metrics",
|
||||
mk(
|
||||
|
@ -124,7 +123,6 @@ fields("metrics") ->
|
|||
{"rate_max", mk(float(), #{desc => ?DESC("rate_max")})},
|
||||
{"rate_last5m", mk(float(), #{desc => ?DESC("rate_last5m")})}
|
||||
];
|
||||
|
||||
fields("resource_metrics") ->
|
||||
[
|
||||
{"matched", mk(integer(), #{desc => ?DESC("matched")})},
|
||||
|
@ -139,7 +137,6 @@ fields("node_metrics") ->
|
|||
node_name(),
|
||||
{"metrics", mk(ref(?MODULE, "metrics"), #{desc => ?DESC("metrics")})}
|
||||
];
|
||||
|
||||
fields("node_resource_metrics") ->
|
||||
[
|
||||
node_name(),
|
||||
|
@ -150,7 +147,6 @@ fields("node_status") ->
|
|||
node_name(),
|
||||
{"status", mk(status(), #{desc => ?DESC("node_status")})}
|
||||
];
|
||||
|
||||
fields("node_error") ->
|
||||
[
|
||||
node_name(),
|
||||
|
|
|
@ -303,29 +303,32 @@ test_authenticator_users(PathPrefix) ->
|
|||
),
|
||||
|
||||
{ok, Client} = emqtt:start_link(
|
||||
[ {username, <<"u_event">>}
|
||||
, {clientid, <<"c_event">>}
|
||||
, {proto_ver, v5}
|
||||
, {properties, #{'Session-Expiry-Interval' => 60}}
|
||||
]),
|
||||
[
|
||||
{username, <<"u_event">>},
|
||||
{clientid, <<"c_event">>},
|
||||
{proto_ver, v5},
|
||||
{properties, #{'Session-Expiry-Interval' => 60}}
|
||||
]
|
||||
),
|
||||
|
||||
process_flag(trap_exit, true),
|
||||
?assertMatch({error, _}, emqtt:connect(Client)),
|
||||
timer:sleep(300),
|
||||
|
||||
|
||||
UsersUri0 = uri(PathPrefix ++ [?CONF_NS, "password_based:built_in_database", "status"]),
|
||||
{ok, 200, PageData0} = request(get, UsersUri0),
|
||||
case PathPrefix of
|
||||
[] ->
|
||||
#{ <<"metrics">> := #{
|
||||
#{
|
||||
<<"metrics">> := #{
|
||||
<<"matched">> := 1,
|
||||
<<"success">> := 0,
|
||||
<<"ignore">> := 1
|
||||
}
|
||||
} = jiffy:decode(PageData0, [return_maps]);
|
||||
["listeners",'tcp:default'] ->
|
||||
#{ <<"metrics">> := #{
|
||||
["listeners", 'tcp:default'] ->
|
||||
#{
|
||||
<<"metrics">> := #{
|
||||
<<"matched">> := 1,
|
||||
<<"success">> := 0,
|
||||
<<"ignore">> := 1
|
||||
|
@ -360,26 +363,30 @@ test_authenticator_users(PathPrefix) ->
|
|||
),
|
||||
|
||||
{ok, Client1} = emqtt:start_link(
|
||||
[ {username, <<"u1">>}
|
||||
, {password, <<"p1">>}
|
||||
, {clientid, <<"c_event">>}
|
||||
, {proto_ver, v5}
|
||||
, {properties, #{'Session-Expiry-Interval' => 60}}
|
||||
]),
|
||||
[
|
||||
{username, <<"u1">>},
|
||||
{password, <<"p1">>},
|
||||
{clientid, <<"c_event">>},
|
||||
{proto_ver, v5},
|
||||
{properties, #{'Session-Expiry-Interval' => 60}}
|
||||
]
|
||||
),
|
||||
{ok, _} = emqtt:connect(Client1),
|
||||
timer:sleep(300),
|
||||
UsersUri01 = uri(PathPrefix ++ [?CONF_NS, "password_based:built_in_database", "status"]),
|
||||
{ok, 200, PageData01} = request(get, UsersUri01),
|
||||
case PathPrefix of
|
||||
[] ->
|
||||
#{ <<"metrics">> := #{
|
||||
#{
|
||||
<<"metrics">> := #{
|
||||
<<"matched">> := 2,
|
||||
<<"success">> := 1,
|
||||
<<"ignore">> := 1
|
||||
}
|
||||
} = jiffy:decode(PageData01, [return_maps]);
|
||||
["listeners",'tcp:default'] ->
|
||||
#{ <<"metrics">> := #{
|
||||
["listeners", 'tcp:default'] ->
|
||||
#{
|
||||
<<"metrics">> := #{
|
||||
<<"matched">> := 2,
|
||||
<<"success">> := 1,
|
||||
<<"ignore">> := 1
|
||||
|
|
Loading…
Reference in New Issue