Skip to content

Commit

Permalink
Merge pull request #9303 from zhongwencool/trace-record-time
Browse files Browse the repository at this point in the history
fix: create trace sometime failed by end_at time has already passed
  • Loading branch information
zhongwencool committed Nov 21, 2022
2 parents c391ae6 + 4e97344 commit f121e76
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
15 changes: 9 additions & 6 deletions apps/emqx/src/emqx_trace/emqx_trace.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
delete/1,
clear/0,
update/2,
check/0
check/0,
now_second/0
]).

-export([
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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) ->
Expand Down Expand Up @@ -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});
Expand All @@ -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"]).
Expand Down Expand Up @@ -570,3 +570,6 @@ filter_cli_handler(Names) ->
end,
Names
).

now_second() ->
os:system_time(second).
4 changes: 2 additions & 2 deletions apps/emqx/src/emqx_trace/emqx_trace_dl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
-include("emqx_trace.hrl").

%%================================================================================
%% API funcions
%% API functions
%%================================================================================

%% Introduced in 5.0
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions changes/v5.0.11-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 2 additions & 0 deletions changes/v5.0.11-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f121e76

Please sign in to comment.