Skip to content

Commit

Permalink
Merge pull request #10044 from zmstone/0228-fix-node-info-format
Browse files Browse the repository at this point in the history
fix(emqx_mgmt): format stoped nodes correctly
  • Loading branch information
zmstone committed Mar 1, 2023
2 parents f619f4f + c616192 commit fdc0ad6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
21 changes: 20 additions & 1 deletion apps/emqx_management/src/emqx_mgmt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,28 @@ node_info() ->
uptime => proplists:get_value(uptime, BrokerInfo),
version => iolist_to_binary(proplists:get_value(version, BrokerInfo)),
edition => emqx_release:edition_longstr(),
role => mria_rlog:role()
role => mria_rlog:role(),
log_path => log_path(),
sys_path => iolist_to_binary(code:root_dir())
}.

log_path() ->
RootDir = code:root_dir(),
Configs = logger:get_handler_config(),
case get_log_path(Configs) of
undefined ->
<<"log.file_handler.default.enable is false, not logging to file.">>;
Path ->
iolist_to_binary(filename:join(RootDir, Path))
end.

get_log_path([#{config := #{file := Path}} | _LoggerConfigs]) ->
filename:dirname(Path);
get_log_path([_LoggerConfig | LoggerConfigs]) ->
get_log_path(LoggerConfigs);
get_log_path([]) ->
undefined.

get_sys_memory() ->
case os:type() of
{unix, linux} ->
Expand Down
27 changes: 4 additions & 23 deletions apps/emqx_management/src/emqx_mgmt_api_nodes.erl
Original file line number Diff line number Diff line change
Expand Up @@ -293,31 +293,12 @@ get_stats(Node) ->
%% internal function

format(_Node, Info = #{memory_total := Total, memory_used := Used}) ->
RootDir = list_to_binary(code:root_dir()),
LogPath =
case log_path() of
undefined ->
<<"log.file_handler.default.enable is false,only log to console">>;
Path ->
filename:join(RootDir, Path)
end,
Info#{
memory_total := emqx_mgmt_util:kmg(Total),
memory_used := emqx_mgmt_util:kmg(Used),
sys_path => RootDir,
log_path => LogPath
}.

log_path() ->
Configs = logger:get_handler_config(),
get_log_path(Configs).

get_log_path([#{config := #{file := Path}} | _LoggerConfigs]) ->
filename:dirname(Path);
get_log_path([_LoggerConfig | LoggerConfigs]) ->
get_log_path(LoggerConfigs);
get_log_path([]) ->
undefined.
memory_used := emqx_mgmt_util:kmg(Used)
};
format(_Node, Info) when is_map(Info) ->
Info.

node_error() ->
emqx_dashboard_swagger:error_codes([?SOURCE_ERROR], <<"Node error">>).
1 change: 1 addition & 0 deletions changes/ce/fix-10044.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix node information formatter for stopped nodes in the cluster.
1 change: 1 addition & 0 deletions changes/ce/fix-10044.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
修复 v5.0.18 引入的一个节点信息序列化时发生的错误。

0 comments on commit fdc0ad6

Please sign in to comment.