fix: incorrect behavior in audit logs during stop and start of EMQX

This commit is contained in:
zhongwencool 2023-12-12 14:29:39 +08:00
parent 4fc14fb4ba
commit e2e7f96515
2 changed files with 33 additions and 21 deletions

View File

@ -336,30 +336,42 @@ audit_log(Level, From, Log) ->
{error, _} -> {error, _} ->
ignore; ignore;
{ok, {Mod, Fun}} -> {ok, {Mod, Fun}} ->
try case prune_unnecessary_log(Log) of
apply(Mod, Fun, [Level, From, normalize_audit_log_args(Log)]) false -> ok;
catch {ok, Log1} -> apply_audit_command(Log1, Mod, Fun, Level, From)
_:{aborted, {no_exists, emqx_audit}} -> end
case Log of end.
#{cmd := cluster, args := ["leave"]} ->
ok; apply_audit_command(Log, Mod, Fun, Level, From) ->
_ -> try
?LOG_ERROR(#{ apply(Mod, Fun, [Level, From, Log])
msg => "ctl_command_crashed", catch
reason => "emqx_audit table not found", _:{aborted, {no_exists, emqx_audit}} ->
log => normalize_audit_log_args(Log), case Log of
from => From #{cmd := cluster, args := [<<"leave">>]} ->
}) ok;
end; _ ->
_:Reason:Stacktrace ->
?LOG_ERROR(#{ ?LOG_ERROR(#{
msg => "ctl_command_crashed", msg => "ctl_command_crashed",
stacktrace => Stacktrace, reason => "emqx_audit table not found",
reason => Reason, log => Log,
log => normalize_audit_log_args(Log),
from => From from => From
}) })
end end;
_:Reason:Stacktrace ->
?LOG_ERROR(#{
msg => "ctl_command_crashed",
stacktrace => Stacktrace,
reason => Reason,
log => Log,
from => From
})
end.
prune_unnecessary_log(Log) ->
case normalize_audit_log_args(Log) of
#{args := [<<"emqx:is_running()">>]} -> false;
Log1 -> {ok, Log1}
end. end.
audit_level(ok, _Duration) -> info; audit_level(ok, _Duration) -> info;

View File

@ -69,7 +69,7 @@ graceful() ->
graceful_wait() -> graceful_wait() ->
?AUDIT(alert, #{ ?AUDIT(alert, #{
cmd => emqx, cmd => emqx,
args => ["stop"], args => [<<"stop">>],
version => emqx_release:version(), version => emqx_release:version(),
from => cli, from => cli,
duration_ms => element(1, erlang:statistics(wall_clock)) duration_ms => element(1, erlang:statistics(wall_clock))