Merge pull request #7227 from EMQ-YangM/upm4

fix(emqx_bridge_api): fix aggregate_metrics
This commit is contained in:
Xinyu Liu 2022-03-08 11:35:48 +08:00 committed by GitHub
commit 591d5f02d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 8 deletions

View File

@ -401,12 +401,12 @@ collect_status(Bridges) ->
[maps:with([node, status], B) || B <- Bridges].
aggregate_status(AllStatus) ->
AllConnected = lists:all(fun (#{status := connected}) -> true;
(_) -> false
end, AllStatus),
case AllConnected of
true -> connected;
false -> disconnected
Head = fun ([A | _]) -> A end,
HeadVal = maps:get(status, Head(AllStatus), connecting),
AllRes = lists:all(fun (#{status := Val}) -> Val == HeadVal end, AllStatus),
case AllRes of
true -> HeadVal;
false -> inconsistent
end.
collect_metrics(Bridges) ->
@ -423,13 +423,12 @@ aggregate_metrics(AllMetrics) ->
format_resp(#{id := Id, raw_config := RawConf,
resource_data := #{status := Status, metrics := Metrics}}) ->
{Type, BridgeName} = emqx_bridge:parse_bridge_id(Id),
IsConnected = fun(connected) -> connected; (_) -> disconnected end,
RawConf#{
id => Id,
type => Type,
name => maps:get(<<"name">>, RawConf, BridgeName),
node => node(),
status => IsConnected(Status),
status => Status,
metrics => format_metrics(Metrics)
}.