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, {
|
||||
{one_for_one, 10, 100},
|
||||
[ AuthnMetrics,
|
||||
AuthzMetrics
|
||||
]
|
||||
}}.
|
||||
{ok,
|
||||
{
|
||||
{one_for_one, 10, 100},
|
||||
[
|
||||
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);
|
||||
|
@ -934,11 +938,11 @@ list_authenticator(_, ConfKeyPath, AuthenticatorID) ->
|
|||
|
||||
resource_provider() ->
|
||||
[
|
||||
emqx_authn_mysql,
|
||||
emqx_authn_pgsql,
|
||||
emqx_authn_mongodb,
|
||||
emqx_authn_redis,
|
||||
emqx_authn_http
|
||||
emqx_authn_mysql,
|
||||
emqx_authn_pgsql,
|
||||
emqx_authn_mongodb,
|
||||
emqx_authn_redis,
|
||||
emqx_authn_http
|
||||
].
|
||||
|
||||
lookup_from_local_node(ChainName, AuthenticatorID) ->
|
||||
|
@ -975,10 +979,11 @@ 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
|
||||
0 -> #{};
|
||||
_ -> restructure_map(AggregateResourceMetrics)
|
||||
end,
|
||||
resource_metrics =>
|
||||
case maps:size(AggregateResourceMetrics) of
|
||||
0 -> #{};
|
||||
_ -> restructure_map(AggregateResourceMetrics)
|
||||
end,
|
||||
node_metrics => HelpFun(maps:map(Fun, MetricsMap), metrics),
|
||||
metrics => restructure_map(AggregateMetrics),
|
||||
|
||||
|
@ -1022,17 +1027,17 @@ aggregate_metrics([HeadMetrics | AllMetrics]) ->
|
|||
make_result_map(ResList) ->
|
||||
Fun =
|
||||
fun(Elem, {StatusMap, MetricsMap, ResourceMetricsMap, ErrorMap}) ->
|
||||
case Elem of
|
||||
{ok, {NodeId, Status, Metrics, ResourceMetrics}} ->
|
||||
{
|
||||
maps:put(NodeId, Status, StatusMap),
|
||||
maps:put(NodeId, Metrics, MetricsMap),
|
||||
maps:put(NodeId, ResourceMetrics, ResourceMetricsMap),
|
||||
ErrorMap
|
||||
};
|
||||
{error, {NodeId, Reason}} ->
|
||||
{StatusMap, MetricsMap, ResourceMetricsMap, maps:put(NodeId, Reason, ErrorMap)}
|
||||
end
|
||||
case Elem of
|
||||
{ok, {NodeId, Status, Metrics, ResourceMetrics}} ->
|
||||
{
|
||||
maps:put(NodeId, Status, StatusMap),
|
||||
maps:put(NodeId, Metrics, MetricsMap),
|
||||
maps:put(NodeId, ResourceMetrics, ResourceMetricsMap),
|
||||
ErrorMap
|
||||
};
|
||||
{error, {NodeId, Reason}} ->
|
||||
{StatusMap, MetricsMap, ResourceMetricsMap, maps:put(NodeId, Reason, ErrorMap)}
|
||||
end
|
||||
end,
|
||||
lists:foldl(Fun, {maps:new(), maps:new(), maps:new(), maps:new()}, ResList).
|
||||
|
||||
|
@ -1050,17 +1055,17 @@ restructure_map(#{
|
|||
rate_max => RateMax
|
||||
};
|
||||
restructure_map(#{
|
||||
counters := #{failed := Failed, matched := Match, success := Succ},
|
||||
rate := #{matched := #{current := Rate, last5m := Rate5m, max := RateMax}}
|
||||
}) ->
|
||||
counters := #{failed := Failed, matched := Match, success := Succ},
|
||||
rate := #{matched := #{current := Rate, last5m := Rate5m, max := RateMax}}
|
||||
}) ->
|
||||
#{
|
||||
matched => Match,
|
||||
success => Succ,
|
||||
failed => Failed,
|
||||
rate => Rate,
|
||||
rate_last5m => Rate5m,
|
||||
rate_max => RateMax
|
||||
};
|
||||
matched => Match,
|
||||
success => Succ,
|
||||
failed => Failed,
|
||||
rate => Rate,
|
||||
rate_last5m => Rate5m,
|
||||
rate_max => RateMax
|
||||
};
|
||||
restructure_map(Error) ->
|
||||
Error.
|
||||
|
||||
|
|
|
@ -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,22 +123,20 @@ 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")})},
|
||||
{"success", mk(integer(), #{desc => ?DESC("success")})},
|
||||
{"failed", mk(integer(), #{desc => ?DESC("failed")})},
|
||||
{"rate", mk(float(), #{desc => ?DESC("rate")})},
|
||||
{"rate_max", mk(float(), #{desc => ?DESC("rate_max")})},
|
||||
{"rate_last5m", mk(float(), #{desc => ?DESC("rate_last5m")})}
|
||||
{"matched", mk(integer(), #{desc => ?DESC("matched")})},
|
||||
{"success", mk(integer(), #{desc => ?DESC("success")})},
|
||||
{"failed", mk(integer(), #{desc => ?DESC("failed")})},
|
||||
{"rate", mk(float(), #{desc => ?DESC("rate")})},
|
||||
{"rate_max", mk(float(), #{desc => ?DESC("rate_max")})},
|
||||
{"rate_last5m", mk(float(), #{desc => ?DESC("rate_last5m")})}
|
||||
];
|
||||
fields("node_metrics") ->
|
||||
[
|
||||
node_name(),
|
||||
{"metrics", mk(ref(?MODULE, "metrics"), #{desc => ?DESC("metrics")})}
|
||||
];
|
||||
|
||||
fields("node_resource_metrics") ->
|
||||
[
|
||||
node_name(),
|
||||
|
@ -150,11 +147,10 @@ fields("node_status") ->
|
|||
node_name(),
|
||||
{"status", mk(status(), #{desc => ?DESC("node_status")})}
|
||||
];
|
||||
|
||||
fields("node_error") ->
|
||||
[
|
||||
node_name(),
|
||||
{"error", mk(string(), #{desc => ?DESC("node_error")})}
|
||||
node_name(),
|
||||
{"error", mk(string(), #{desc => ?DESC("node_error")})}
|
||||
].
|
||||
|
||||
status() ->
|
||||
|
|
|
@ -303,34 +303,37 @@ 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">> := #{
|
||||
<<"matched">> := 1,
|
||||
<<"success">> := 0,
|
||||
<<"ignore">> := 1
|
||||
}
|
||||
} = jiffy:decode(PageData0, [return_maps]);
|
||||
["listeners",'tcp:default'] ->
|
||||
#{ <<"metrics">> := #{
|
||||
<<"matched">> := 1,
|
||||
<<"success">> := 0,
|
||||
<<"ignore">> := 1
|
||||
}
|
||||
} = jiffy:decode(PageData0, [return_maps])
|
||||
#{
|
||||
<<"metrics">> := #{
|
||||
<<"matched">> := 1,
|
||||
<<"success">> := 0,
|
||||
<<"ignore">> := 1
|
||||
}
|
||||
} = jiffy:decode(PageData0, [return_maps]);
|
||||
["listeners", 'tcp:default'] ->
|
||||
#{
|
||||
<<"metrics">> := #{
|
||||
<<"matched">> := 1,
|
||||
<<"success">> := 0,
|
||||
<<"ignore">> := 1
|
||||
}
|
||||
} = jiffy:decode(PageData0, [return_maps])
|
||||
end,
|
||||
|
||||
InvalidUsers = [
|
||||
|
@ -360,31 +363,35 @@ 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">> := #{
|
||||
<<"matched">> := 2,
|
||||
<<"success">> := 1,
|
||||
<<"ignore">> := 1
|
||||
}
|
||||
} = jiffy:decode(PageData01, [return_maps]);
|
||||
["listeners",'tcp:default'] ->
|
||||
#{ <<"metrics">> := #{
|
||||
<<"matched">> := 2,
|
||||
<<"success">> := 1,
|
||||
<<"ignore">> := 1
|
||||
}
|
||||
} = jiffy:decode(PageData01, [return_maps])
|
||||
#{
|
||||
<<"metrics">> := #{
|
||||
<<"matched">> := 2,
|
||||
<<"success">> := 1,
|
||||
<<"ignore">> := 1
|
||||
}
|
||||
} = jiffy:decode(PageData01, [return_maps]);
|
||||
["listeners", 'tcp:default'] ->
|
||||
#{
|
||||
<<"metrics">> := #{
|
||||
<<"matched">> := 2,
|
||||
<<"success">> := 1,
|
||||
<<"ignore">> := 1
|
||||
}
|
||||
} = jiffy:decode(PageData01, [return_maps])
|
||||
end,
|
||||
|
||||
{ok, 200, Page1Data} = request(get, UsersUri ++ "?page=1&limit=2"),
|
||||
|
|
|
@ -104,13 +104,13 @@ child_spec(Name) ->
|
|||
|
||||
child_spec(ChldName, Name) ->
|
||||
#{
|
||||
id => ChldName,
|
||||
start => {emqx_plugin_libs_metrics, start_link, [Name]},
|
||||
restart => permanent,
|
||||
shutdown => 5000,
|
||||
type => worker,
|
||||
modules => [emqx_plugin_libs_metrics]
|
||||
}.
|
||||
id => ChldName,
|
||||
start => {emqx_plugin_libs_metrics, start_link, [Name]},
|
||||
restart => permanent,
|
||||
shutdown => 5000,
|
||||
type => worker,
|
||||
modules => [emqx_plugin_libs_metrics]
|
||||
}.
|
||||
|
||||
-spec create_metrics(handler_name(), metric_id(), [atom()]) -> ok | {error, term()}.
|
||||
create_metrics(Name, Id, Metrics) ->
|
||||
|
|
Loading…
Reference in New Issue