Merge pull request #8659 from zhongwencool/fix-trace-disable-return-enoent

fix: check if trace is enabled when the file is not found
This commit is contained in:
zhongwencool 2022-08-09 09:13:31 +08:00 committed by GitHub
commit 2443c06810
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 2 deletions

View File

@ -1,5 +1,12 @@
# EMQX 4.4 Changes # EMQX 4.4 Changes
## v4.4.7
### Enhancements (synced from v4.3.18)
### Bug fixes
- Fix: Check if emqx_mod_trace is enabled when the trace file is not found.
## v4.4.5 ## v4.4.5
### Enhancements (synced from v4.3.16) ### Enhancements (synced from v4.3.16)

View File

@ -1,6 +1,6 @@
{application, emqx_plugin_libs, {application, emqx_plugin_libs,
[{description, "EMQ X Plugin utility libs"}, [{description, "EMQ X Plugin utility libs"},
{vsn, "4.4.4"}, {vsn, "4.4.5"},
{modules, []}, {modules, []},
{applications, [kernel,stdlib]}, {applications, [kernel,stdlib]},
{env, []} {env, []}

View File

@ -2,6 +2,9 @@
%% Unless you know what you are doing, DO NOT edit manually!! %% Unless you know what you are doing, DO NOT edit manually!!
{VSN, {VSN,
[ [
{"4.4.4",
[{load_module,emqx_trace,brutal_purge,soft_purge,[]},
{load_module,emqx_trace_api,brutal_purge,soft_purge,[]}]},
{"4.4.3", {"4.4.3",
[{load_module,emqx_trace,brutal_purge,soft_purge,[]}, [{load_module,emqx_trace,brutal_purge,soft_purge,[]},
{load_module,emqx_trace_api,brutal_purge,soft_purge,[]}]}, {load_module,emqx_trace_api,brutal_purge,soft_purge,[]}]},
@ -21,6 +24,9 @@
{load_module,emqx_slow_subs_api,brutal_purge,soft_purge,[]}]}, {load_module,emqx_slow_subs_api,brutal_purge,soft_purge,[]}]},
{<<".*">>,[]}], {<<".*">>,[]}],
[ [
{"4.4.4",
[{load_module,emqx_trace,brutal_purge,soft_purge,[]},
{load_module,emqx_trace_api,brutal_purge,soft_purge,[]}]},
{"4.4.3", {"4.4.3",
[{load_module,emqx_trace,brutal_purge,soft_purge,[]}, [{load_module,emqx_trace,brutal_purge,soft_purge,[]},
{load_module,emqx_trace_api,brutal_purge,soft_purge,[]}]}, {load_module,emqx_trace_api,brutal_purge,soft_purge,[]}]},

View File

@ -177,7 +177,13 @@ trace_file(File) ->
Node = atom_to_list(node()), Node = atom_to_list(node()),
case file:read_file(FileName) of case file:read_file(FileName) of
{ok, Bin} -> {ok, Node, Bin}; {ok, Bin} -> {ok, Node, Bin};
{error, Reason} -> {error, Node, Reason} {error, enoent} ->
case emqx_trace:is_enable() of
false -> {error, Node, trace_disabled};
true -> {error, Node, enoent}
end;
{error, Reason} ->
{error, Node, Reason}
end. end.
delete_files_after_send(TraceLog, Zips) -> delete_files_after_send(TraceLog, Zips) ->

View File

@ -115,6 +115,9 @@ group_trace_file(ZipDir, TraceLog, TraceFiles) ->
ok -> [FileName | Acc]; ok -> [FileName | Acc];
_ -> Acc _ -> Acc
end; end;
{error, Node, trace_disabled} ->
?LOG(warning, "emqx_mod_trace modules is disabled on ~s ~s", [Node, TraceLog]),
Acc;
{error, Node, Reason} -> {error, Node, Reason} ->
?LOG(error, "download trace log error:~p", [{Node, TraceLog, Reason}]), ?LOG(error, "download trace log error:~p", [{Node, TraceLog, Reason}]),
Acc Acc
@ -145,6 +148,8 @@ stream_log_file(#{name := Name}, Params) ->
{eof, Size} -> {eof, Size} ->
Meta = #{<<"position">> => Size, <<"bytes">> => Bytes}, Meta = #{<<"position">> => Size, <<"bytes">> => Bytes},
{ok, #{meta => Meta, items => <<"">>}}; {ok, #{meta => Meta, items => <<"">>}};
{error, trace_disabled} ->
{error, io_lib:format("trace_disable_on_~s", [Node0])};
{error, Reason} -> {error, Reason} ->
logger:log(error, "read_file_failed ~p", [{Node, Name, Reason, Position, Bytes}]), logger:log(error, "read_file_failed ~p", [{Node, Name, Reason, Position, Bytes}]),
{error, Reason}; {error, Reason};
@ -194,6 +199,11 @@ read_file(Path, Offset, Bytes) ->
after after
file:close(IoDevice) file:close(IoDevice)
end; end;
{error, enoent} ->
case emqx_trace:is_enable() of
false -> {error, trace_disabled};
true -> {error, enoent}
end;
{error, Reason} -> {error, Reason} {error, Reason} -> {error, Reason}
end. end.