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