Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(emqx_mgmt): format stoped nodes correctly #10044

Merged
merged 4 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion apps/emqx_management/src/emqx_mgmt.erl
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]) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes we only have one logger handler that has file backend.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not assume that, it returns the first one.

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
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
@@ -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
@@ -0,0 +1 @@
修复 v5.0.18 引入的一个节点信息序列化时发生的错误。