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