fix: 'ComFun' missing parameter
This commit is contained in:
parent
184554246c
commit
2d553d711f
|
@ -197,7 +197,6 @@ covert_keys_to_atom(BinKeyMap, Conv) ->
|
||||||
).
|
).
|
||||||
|
|
||||||
%% copy from maps.erl OTP24.0
|
%% copy from maps.erl OTP24.0
|
||||||
-compile({inline, [error_with_info/2]}).
|
|
||||||
merge_with(Combiner, Map1, Map2) when
|
merge_with(Combiner, Map1, Map2) when
|
||||||
is_map(Map1),
|
is_map(Map1),
|
||||||
is_map(Map2),
|
is_map(Map2),
|
||||||
|
|
|
@ -89,7 +89,8 @@
|
||||||
delete_user/3,
|
delete_user/3,
|
||||||
find_user/3,
|
find_user/3,
|
||||||
update_user/4,
|
update_user/4,
|
||||||
serialize_error/1
|
serialize_error/1,
|
||||||
|
aggregate_metrics/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-elvis([{elvis_style, god_modules, disable}]).
|
-elvis([{elvis_style, god_modules, disable}]).
|
||||||
|
@ -992,7 +993,7 @@ aggregate_metrics([]) ->
|
||||||
empty_metrics_and_status;
|
empty_metrics_and_status;
|
||||||
aggregate_metrics([HeadMetrics | AllMetrics]) ->
|
aggregate_metrics([HeadMetrics | AllMetrics]) ->
|
||||||
CombinerFun =
|
CombinerFun =
|
||||||
fun ComFun(Val1, Val2) ->
|
fun ComFun(_Key, Val1, Val2) ->
|
||||||
case erlang:is_map(Val1) of
|
case erlang:is_map(Val1) of
|
||||||
true -> emqx_map_lib:merge_with(ComFun, Val1, Val2);
|
true -> emqx_map_lib:merge_with(ComFun, Val1, Val2);
|
||||||
false -> Val1 + Val2
|
false -> Val1 + Val2
|
||||||
|
|
|
@ -119,6 +119,23 @@ t_listener_authenticator_move(_) ->
|
||||||
t_listener_authenticator_import_users(_) ->
|
t_listener_authenticator_import_users(_) ->
|
||||||
test_authenticator_import_users(["listeners", ?TCP_DEFAULT]).
|
test_authenticator_import_users(["listeners", ?TCP_DEFAULT]).
|
||||||
|
|
||||||
|
t_aggregate_metrics(_) ->
|
||||||
|
Metrics = #{ 'emqx@node1.emqx.io' => #{metrics =>
|
||||||
|
#{failed => 0,matched => 1,rate => 0.0,
|
||||||
|
rate_last5m => 0.0,rate_max => 0.1,
|
||||||
|
success => 1}
|
||||||
|
},
|
||||||
|
'emqx@node2.emqx.io' => #{metrics =>
|
||||||
|
#{failed => 0,matched => 1,rate => 0.0,
|
||||||
|
rate_last5m => 0.0,rate_max => 0.1,
|
||||||
|
success => 1}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Res = emqx_authn_api:aggregate_metrics(maps:values(Metrics)),
|
||||||
|
?assertEqual(#{metrics =>
|
||||||
|
#{failed => 0,matched => 2,rate => 0.0,rate_last5m => 0.0,
|
||||||
|
rate_max => 0.2,success => 2}}, Res).
|
||||||
|
|
||||||
test_authenticators(PathPrefix) ->
|
test_authenticators(PathPrefix) ->
|
||||||
ValidConfig = emqx_authn_test_lib:http_example(),
|
ValidConfig = emqx_authn_test_lib:http_example(),
|
||||||
{ok, 200, _} = request(
|
{ok, 200, _} = request(
|
||||||
|
|
|
@ -46,7 +46,8 @@
|
||||||
-export([
|
-export([
|
||||||
sources/2,
|
sources/2,
|
||||||
source/2,
|
source/2,
|
||||||
move_source/2
|
move_source/2,
|
||||||
|
aggregate_metrics/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
api_spec() ->
|
api_spec() ->
|
||||||
|
@ -373,7 +374,7 @@ aggregate_metrics([]) ->
|
||||||
empty_metrics_and_status;
|
empty_metrics_and_status;
|
||||||
aggregate_metrics([HeadMetrics | AllMetrics]) ->
|
aggregate_metrics([HeadMetrics | AllMetrics]) ->
|
||||||
CombinerFun =
|
CombinerFun =
|
||||||
fun ComFun(Val1, Val2) ->
|
fun ComFun(_Key, Val1, Val2) ->
|
||||||
case erlang:is_map(Val1) of
|
case erlang:is_map(Val1) of
|
||||||
true -> emqx_map_lib:merge_with(ComFun, Val1, Val2);
|
true -> emqx_map_lib:merge_with(ComFun, Val1, Val2);
|
||||||
false -> Val1 + Val2
|
false -> Val1 + Val2
|
||||||
|
|
|
@ -448,6 +448,23 @@ t_move_source(_) ->
|
||||||
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
t_aggregate_metrics(_) ->
|
||||||
|
Metrics = #{ 'emqx@node1.emqx.io' => #{metrics =>
|
||||||
|
#{failed => 0,matched => 1,rate => 0.0,
|
||||||
|
rate_last5m => 0.0,rate_max => 0.1,
|
||||||
|
success => 1}
|
||||||
|
},
|
||||||
|
'emqx@node2.emqx.io' => #{metrics =>
|
||||||
|
#{failed => 0,matched => 1,rate => 0.0,
|
||||||
|
rate_last5m => 0.0,rate_max => 0.1,
|
||||||
|
success => 1}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Res = emqx_authn_api:aggregate_metrics(maps:values(Metrics)),
|
||||||
|
?assertEqual(#{metrics =>
|
||||||
|
#{failed => 0,matched => 2,rate => 0.0,rate_last5m => 0.0,
|
||||||
|
rate_max => 0.2,success => 2}}, Res).
|
||||||
|
|
||||||
get_sources(Result) ->
|
get_sources(Result) ->
|
||||||
maps:get(<<"sources">>, jsx:decode(Result), []).
|
maps:get(<<"sources">>, jsx:decode(Result), []).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue