Merge pull request #9303 from zhongwencool/trace-record-time

fix: create trace sometime failed by end_at time has already passed
This commit is contained in:
zhongwencool 2022-11-21 17:20:26 +08:00 committed by GitHub
commit f121e76e51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 8 deletions

View File

@ -38,7 +38,8 @@
delete/1,
clear/0,
update/2,
check/0
check/0,
now_second/0
]).
-export([
@ -287,7 +288,7 @@ insert_new_trace(Trace) ->
transaction(fun emqx_trace_dl:insert_new_trace/1, [Trace]).
update_trace(Traces) ->
Now = erlang:system_time(second),
Now = now_second(),
{_Waiting, Running, Finished} = classify_by_time(Traces, Now),
disable_finished(Finished),
Started = emqx_trace_handler:running(),
@ -455,7 +456,7 @@ ensure_map(Trace) when is_list(Trace) ->
).
fill_default(Trace = #?TRACE{start_at = undefined}) ->
fill_default(Trace#?TRACE{start_at = erlang:system_time(second)});
fill_default(Trace#?TRACE{start_at = now_second()});
fill_default(Trace = #?TRACE{end_at = undefined, start_at = StartAt}) ->
fill_default(Trace#?TRACE{end_at = StartAt + 10 * 60});
fill_default(Trace) ->
@ -493,7 +494,7 @@ to_trace(#{start_at := StartAt} = Trace, Rec) ->
{ok, Sec} = to_system_second(StartAt),
to_trace(maps:remove(start_at, Trace), Rec#?TRACE{start_at = Sec});
to_trace(#{end_at := EndAt} = Trace, Rec) ->
Now = erlang:system_time(second),
Now = now_second(),
case to_system_second(EndAt) of
{ok, Sec} when Sec > Now ->
to_trace(maps:remove(end_at, Trace), Rec#?TRACE{end_at = Sec});
@ -517,8 +518,7 @@ validate_ip_address(IP) ->
end.
to_system_second(Sec) ->
Now = erlang:system_time(second),
{ok, erlang:max(Now, Sec)}.
{ok, erlang:max(now_second(), Sec)}.
zip_dir() ->
filename:join([trace_dir(), "zip"]).
@ -570,3 +570,6 @@ filter_cli_handler(Names) ->
end,
Names
).
now_second() ->
os:system_time(second).

View File

@ -30,7 +30,7 @@
-include("emqx_trace.hrl").
%%================================================================================
%% API funcions
%% API functions
%%================================================================================
%% Introduced in 5.0
@ -43,7 +43,7 @@ update(Name, Enable) ->
[#?TRACE{enable = Enable}] ->
ok;
[Rec] ->
case erlang:system_time(second) >= Rec#?TRACE.end_at of
case emqx_trace:now_second() >= Rec#?TRACE.end_at of
false -> mnesia:write(?TRACE, Rec#?TRACE{enable = Enable}, write);
true -> mnesia:abort(finished)
end

View File

@ -19,6 +19,8 @@
## Bug fixes
- Fix create trace sometime failed by end_at time has already passed. [#9303](https://github.com/emqx/emqx/pull/9303)
- Return 404 for status of unknown authenticator in `/authenticator/{id}/status` [#9328](https://github.com/emqx/emqx/pull/9328).
- Fix that JWT ACL rules are only applied if an `exp` claim is set [#9368](https://github.com/emqx/emqx/pull/9368).

View File

@ -17,6 +17,8 @@
## 修复
- 修复创建追踪日志时偶尔会报`end_at time has already passed`错误,导致创建失败。[#9303](https://github.com/emqx/emqx/pull/9303)
- 通过 `/authenticator/{id}/status` 请求未知认证器的状态时,将会返回 404。
- 修复 JWT ACL 规则只在设置了超期时间时才生效的问题 [#9368](https://github.com/emqx/emqx/pull/9368)。