Browse Source

fix(emqx_management): Ignore results from the nodes that are down

ieQu1 2 years ago
parent
commit
a947df1ea3
2 changed files with 19 additions and 4 deletions
  1. 13 4
      apps/emqx_management/src/emqx_mgmt_api_stats.erl
  2. 6 0
      changes/ce/fix-10369.en.md

+ 13 - 4
apps/emqx_management/src/emqx_mgmt_api_stats.erl

@@ -127,10 +127,19 @@ list(get, #{query_string := Qs}) ->
         true ->
             {200, emqx_mgmt:get_stats()};
         _ ->
-            Data = [
-                maps:from_list(emqx_mgmt:get_stats(Node) ++ [{node, Node}])
-             || Node <- running_nodes()
-            ],
+            Data = lists:foldl(
+                fun(Node, Acc) ->
+                    case emqx_mgmt:get_stats(Node) of
+                        {error, _Err} ->
+                            Acc;
+                        Stats when is_list(Stats) ->
+                            Data = maps:from_list([{node, Node} | Stats]),
+                            [Data | Acc]
+                    end
+                end,
+                [],
+                mria:running_nodes()
+            ),
             {200, Data}
     end.
 

+ 6 - 0
changes/ce/fix-10369.en.md

@@ -0,0 +1,6 @@
+Fix error `/api/v5/monitor_current` API endpoint when some EMQX nodes are down.
+
+Prior to this fix, sometimes the request returned HTTP code 500 and the following message:
+```
+{"code":"INTERNAL_ERROR","message":"error, badarg, [{erlang,'++',[{error,nodedown},[{node,'emqx@10.42.0.150'}]], ...
+```