Merge pull request #8275 from zhongwencool/zip-trace
fix: clean trace zip file after download
This commit is contained in:
commit
193595ad61
|
@ -5,6 +5,8 @@
|
||||||
### Enhancements (synced from v4.3.16)
|
### Enhancements (synced from v4.3.16)
|
||||||
* HTTP API `mqtt/publish` support to publish with properties and user_properties.
|
* HTTP API `mqtt/publish` support to publish with properties and user_properties.
|
||||||
|
|
||||||
|
### Bug fixes
|
||||||
|
- Clean trace zip files when file has been downloaded.
|
||||||
|
|
||||||
## v4.4.4
|
## v4.4.4
|
||||||
|
|
||||||
|
|
|
@ -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.3"},
|
{vsn, "4.4.4"},
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{applications, [kernel,stdlib]},
|
{applications, [kernel,stdlib]},
|
||||||
{env, []}
|
{env, []}
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
%% -*- mode: erlang -*-
|
%% -*- mode: erlang -*-
|
||||||
%% 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.2",[{load_module,emqx_plugin_libs_ssl,brutal_purge,soft_purge,[]}]},
|
[
|
||||||
|
{"4.4.3",
|
||||||
|
[{load_module,emqx_trace,brutal_purge,soft_purge,[]},
|
||||||
|
{load_module,emqx_trace_api,brutal_purge,soft_purge,[]}]},
|
||||||
|
{"4.4.2",[
|
||||||
|
{load_module,emqx_plugin_libs_ssl,brutal_purge,soft_purge,[]},
|
||||||
|
{load_module,emqx_trace,brutal_purge,soft_purge,[]},
|
||||||
|
{load_module,emqx_trace_api,brutal_purge,soft_purge,[]}]},
|
||||||
{"4.4.1",
|
{"4.4.1",
|
||||||
[{load_module,emqx_plugin_libs_ssl,brutal_purge,soft_purge,[]},
|
[{load_module,emqx_plugin_libs_ssl,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_trace,brutal_purge,soft_purge,[]},
|
{load_module,emqx_trace,brutal_purge,soft_purge,[]},
|
||||||
|
@ -13,7 +20,14 @@
|
||||||
{update,emqx_slow_subs,{advanced,["4.4.0"]}},
|
{update,emqx_slow_subs,{advanced,["4.4.0"]}},
|
||||||
{load_module,emqx_slow_subs_api,brutal_purge,soft_purge,[]}]},
|
{load_module,emqx_slow_subs_api,brutal_purge,soft_purge,[]}]},
|
||||||
{<<".*">>,[]}],
|
{<<".*">>,[]}],
|
||||||
[{"4.4.2",[{load_module,emqx_plugin_libs_ssl,brutal_purge,soft_purge,[]}]},
|
[
|
||||||
|
{"4.4.3",
|
||||||
|
[{load_module,emqx_trace,brutal_purge,soft_purge,[]},
|
||||||
|
{load_module,emqx_trace_api,brutal_purge,soft_purge,[]}]},
|
||||||
|
{"4.4.2",
|
||||||
|
[{load_module,emqx_plugin_libs_ssl,brutal_purge,soft_purge,[]},
|
||||||
|
{load_module,emqx_trace,brutal_purge,soft_purge,[]},
|
||||||
|
{load_module,emqx_trace_api,brutal_purge,soft_purge,[]}]},
|
||||||
{"4.4.1",
|
{"4.4.1",
|
||||||
[{load_module,emqx_plugin_libs_ssl,brutal_purge,soft_purge,[]},
|
[{load_module,emqx_plugin_libs_ssl,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_trace,brutal_purge,soft_purge,[]},
|
{load_module,emqx_trace,brutal_purge,soft_purge,[]},
|
||||||
|
|
|
@ -226,7 +226,8 @@ handle_info({'DOWN', _Ref, process, Pid, _Reason}, State = #{monitors := Monitor
|
||||||
case maps:take(Pid, Monitors) of
|
case maps:take(Pid, Monitors) of
|
||||||
error -> {noreply, State};
|
error -> {noreply, State};
|
||||||
{Files, NewMonitors} ->
|
{Files, NewMonitors} ->
|
||||||
lists:foreach(fun file:delete/1, Files),
|
ZipDir = emqx_trace:zip_dir(),
|
||||||
|
lists:foreach(fun(F) -> file:delete(filename:join([ZipDir, F])) end, Files),
|
||||||
{noreply, State#{monitors => NewMonitors}}
|
{noreply, State#{monitors => NewMonitors}}
|
||||||
end;
|
end;
|
||||||
handle_info({timeout, TRef, update_trace},
|
handle_info({timeout, TRef, update_trace},
|
||||||
|
@ -403,7 +404,7 @@ fill_default(Trace = #?TRACE{end_at = undefined, start_at = StartAt}) ->
|
||||||
fill_default(Trace#?TRACE{end_at = StartAt + 10 * 60});
|
fill_default(Trace#?TRACE{end_at = StartAt + 10 * 60});
|
||||||
fill_default(Trace) -> Trace.
|
fill_default(Trace) -> Trace.
|
||||||
|
|
||||||
-define(NAME_RE, "^[A-Za-z]+[A-Za-z0-9-_]*$").
|
-define(NAME_RE, "^[0-9A-Za-z]+[A-Za-z0-9-_]*$").
|
||||||
|
|
||||||
to_trace(#{name := Name} = Trace, Rec) ->
|
to_trace(#{name := Name} = Trace, Rec) ->
|
||||||
case re:run(Name, ?NAME_RE) of
|
case re:run(Name, ?NAME_RE) of
|
||||||
|
|
|
@ -97,9 +97,9 @@ download_zip_log(#{name := Name}, _Param) ->
|
||||||
ZipDir = emqx_trace:zip_dir(),
|
ZipDir = emqx_trace:zip_dir(),
|
||||||
Zips = group_trace_file(ZipDir, TraceLog, TraceFiles),
|
Zips = group_trace_file(ZipDir, TraceLog, TraceFiles),
|
||||||
ZipFileName0 = binary_to_list(Name) ++ ".zip",
|
ZipFileName0 = binary_to_list(Name) ++ ".zip",
|
||||||
ZipFileName = filename:join([Zips, ZipFileName0]),
|
ZipFileName = filename:join([ZipDir, ZipFileName0]),
|
||||||
{ok, ZipFile} = zip:zip(ZipFileName, Zips, [{cwd, ZipDir}]),
|
{ok, ZipFile} = zip:zip(ZipFileName, Zips, [{cwd, ZipDir}]),
|
||||||
emqx_trace:delete_files_after_send(ZipFileName, Zips),
|
emqx_trace:delete_files_after_send(ZipFileName0, Zips),
|
||||||
{ok, ZipFile};
|
{ok, ZipFile};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
|
|
|
@ -133,7 +133,7 @@ t_create_failed(_Config) ->
|
||||||
InvalidPackets4 = [{<<"name">>, <<"/test">>}, {<<"clientid">>, <<"t">>},
|
InvalidPackets4 = [{<<"name">>, <<"/test">>}, {<<"clientid">>, <<"t">>},
|
||||||
{<<"type">>, <<"clientid">>}],
|
{<<"type">>, <<"clientid">>}],
|
||||||
{error, Reason9} = emqx_trace:create(InvalidPackets4),
|
{error, Reason9} = emqx_trace:create(InvalidPackets4),
|
||||||
?assertEqual(<<"Name should be ^[A-Za-z]+[A-Za-z0-9-_]*$">>, iolist_to_binary(Reason9)),
|
?assertEqual(<<"Name should be ^[0-9A-Za-z]+[A-Za-z0-9-_]*$">>, iolist_to_binary(Reason9)),
|
||||||
|
|
||||||
?assertEqual({error, "type=[topic,clientid,ip_address] required"},
|
?assertEqual({error, "type=[topic,clientid,ip_address] required"},
|
||||||
emqx_trace:create([{<<"name">>, <<"test-name">>}, {<<"clientid">>, <<"good">>}])),
|
emqx_trace:create([{<<"name">>, <<"test-name">>}, {<<"clientid">>, <<"good">>}])),
|
||||||
|
|
Loading…
Reference in New Issue