fix: reduce status_and_metrics
This commit is contained in:
parent
4c93a71446
commit
b33b3f6eee
|
@ -756,10 +756,13 @@ list_authenticator(ChainName, ConfKeyPath, AuthenticatorID) ->
|
|||
AuthenticatorsConfig = get_raw_config_with_defaults(ConfKeyPath),
|
||||
case find_config(AuthenticatorID, AuthenticatorsConfig) of
|
||||
{ok, AuthenticatorConfig} ->
|
||||
StatusAndMetrics = lookup_from_all_nodes(ChainName, AuthenticatorID),
|
||||
Fun = fun ({Key, Val}, Map) -> maps:put(Key, Val, Map) end,
|
||||
AppendList = [{id, AuthenticatorID}, {status_and_metrics, StatusAndMetrics}],
|
||||
{200, lists:foldl(Fun, convert_certs(AuthenticatorConfig), AppendList)};
|
||||
case lookup_from_all_nodes(ChainName, AuthenticatorID) of
|
||||
{ok, StatusAndMetrics} ->
|
||||
Fun = fun ({Key, Val}, Map) -> maps:put(Key, Val, Map) end,
|
||||
AppendList = [{id, AuthenticatorID} | maps:to_list(StatusAndMetrics)],
|
||||
{200, lists:foldl(Fun, convert_certs(AuthenticatorConfig), AppendList)};
|
||||
{error, ErrorMsg} -> {500, ErrorMsg}
|
||||
end;
|
||||
{error, Reason} ->
|
||||
serialize_error(Reason)
|
||||
end.
|
||||
|
@ -797,14 +800,15 @@ lookup_from_all_nodes(ChainName, AuthenticatorID) ->
|
|||
AggregateStatus = aggregate_status(maps:values(StatusMap)),
|
||||
AggregateMetrics = aggregate_metrics(maps:values(MetricsMap)),
|
||||
Fun = fun(_, V1) -> restructure_map(V1) end,
|
||||
#{node_status => StatusMap,
|
||||
node_metrics => maps:map(Fun, MetricsMap),
|
||||
node_error => ErrorMap,
|
||||
status => AggregateStatus,
|
||||
metrics => restructure_map(AggregateMetrics)
|
||||
{ok, #{node_status => StatusMap,
|
||||
node_metrics => maps:map(Fun, MetricsMap),
|
||||
node_error => ErrorMap,
|
||||
status => AggregateStatus,
|
||||
metrics => restructure_map(AggregateMetrics)
|
||||
}
|
||||
};
|
||||
{error, ErrL} ->
|
||||
{error_msg('INTERNAL_ERROR', ErrL)}
|
||||
{error, error_msg('INTERNAL_ERROR', ErrL)}
|
||||
end.
|
||||
|
||||
aggregate_status([]) -> error_some_strange_happen;
|
||||
|
|
|
@ -183,15 +183,13 @@ test_authenticator(PathPrefix) ->
|
|||
{<<"rate_max">>, 0.0},
|
||||
{<<"success">>, 0}],
|
||||
EqualFun = fun ({M, V}) ->
|
||||
?assertEqual(V, LookFun([<<"status_and_metrics">>,
|
||||
<<"metrics">>,
|
||||
?assertEqual(V, LookFun([<<"metrics">>,
|
||||
M]
|
||||
)
|
||||
) end,
|
||||
lists:map(EqualFun, MetricsList),
|
||||
?assertEqual(<<"connected">>,
|
||||
LookFun([<<"status_and_metrics">>,
|
||||
<<"status">>
|
||||
LookFun([<<"status">>
|
||||
])),
|
||||
{ok, 404, _} = request(
|
||||
get,
|
||||
|
|
|
@ -230,9 +230,13 @@ source(get, #{bindings := #{type := Type}}) ->
|
|||
[Source] ->
|
||||
case emqx_authz:lookup(Type) of
|
||||
#{annotations := #{id := ResourceId }} ->
|
||||
StatusAndMetrics = lookup_from_all_nodes(ResourceId),
|
||||
{200, maps:put(status_and_metrics, StatusAndMetrics, read_certs(Source))};
|
||||
_ -> {200, maps:put(status_and_metrics, resource_not_found, read_certs(Source))}
|
||||
case lookup_from_all_nodes(ResourceId) of
|
||||
{ok, StatusAndMetrics} ->
|
||||
Fun = fun ({Key, Val}, Map) -> maps:put(Key, Val, Map) end,
|
||||
{200, lists:foldl(Fun, read_certs(Source), maps:to_list(StatusAndMetrics))};
|
||||
{error, ErrorMsg} -> {500, ErrorMsg}
|
||||
end;
|
||||
_ -> {200, read_certs(Source)}
|
||||
end
|
||||
end;
|
||||
source(put, #{bindings := #{type := <<"file">>}, body := #{<<"type">> := <<"file">>,
|
||||
|
@ -292,14 +296,15 @@ lookup_from_all_nodes(ResourceId) ->
|
|||
AggregateStatus = aggregate_status(maps:values(StatusMap)),
|
||||
AggregateMetrics = aggregate_metrics(maps:values(MetricsMap)),
|
||||
Fun = fun(_, V1) -> restructure_map(V1) end,
|
||||
#{node_status => StatusMap,
|
||||
node_metrics => maps:map(Fun, MetricsMap),
|
||||
node_error => ErrorMap,
|
||||
status => AggregateStatus,
|
||||
metrics => restructure_map(AggregateMetrics)
|
||||
};
|
||||
{ok, #{node_status => StatusMap,
|
||||
node_metrics => maps:map(Fun, MetricsMap),
|
||||
node_error => ErrorMap,
|
||||
status => AggregateStatus,
|
||||
metrics => restructure_map(AggregateMetrics)
|
||||
}
|
||||
};
|
||||
{error, ErrL} ->
|
||||
{error_msg('INTERNAL_ERROR', ErrL)}
|
||||
{error, error_msg('INTERNAL_ERROR', ErrL)}
|
||||
end.
|
||||
|
||||
aggregate_status([]) -> error_some_strange_happen;
|
||||
|
|
|
@ -186,8 +186,7 @@ t_api(_) ->
|
|||
EqualFun = fun (RList) ->
|
||||
fun ({M, V}) ->
|
||||
?assertEqual(V,
|
||||
LookupVal([<<"status_and_metrics">>,
|
||||
<<"metrics">>, M],
|
||||
LookupVal([<<"metrics">>, M],
|
||||
RList)
|
||||
)
|
||||
end
|
||||
|
@ -218,10 +217,6 @@ t_api(_) ->
|
|||
{ok, 204, _} = request(put, uri(["authorization", "sources", "http"]),
|
||||
?SOURCE1#{<<"enable">> := false}),
|
||||
{ok, 200, Result3} = request(get, uri(["authorization", "sources", "http"]), []),
|
||||
{ok, RList3} = emqx_json:safe_decode(Result3),
|
||||
?assertEqual(<<"resource_not_found">>,
|
||||
LookupVal([<<"status_and_metrics">>
|
||||
], RList3)),
|
||||
?assertMatch(#{<<"type">> := <<"http">>, <<"enable">> := false}, jsx:decode(Result3)),
|
||||
|
||||
Keyfile = emqx_common_test_helpers:app_path(
|
||||
|
|
Loading…
Reference in New Issue