Merge pull request #12593 from SergeTupchiy/EMQX-11530-log-throttling-followup-trace

trace throttled events
This commit is contained in:
SergeTupchiy 2024-02-26 16:09:30 +02:00 committed by GitHub
commit 8722e6aecc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 7 deletions

View File

@ -51,7 +51,7 @@
true -> true ->
?SLOG(Level, Data, Meta); ?SLOG(Level, Data, Meta);
false -> false ->
ok ?_DO_TRACE(Level, maps:get(msg, Data), maps:merge(Data, Meta))
end end
). ).
@ -59,10 +59,8 @@
-define(TRACE_FILTER, emqx_trace_filter). -define(TRACE_FILTER, emqx_trace_filter).
-define(OWN_KEYS, [level, filters, filter_default, handlers]). -define(OWN_KEYS, [level, filters, filter_default, handlers]).
-define(TRACE(Tag, Msg, Meta), ?TRACE(debug, Tag, Msg, Meta)). %% Internal macro
-define(_DO_TRACE(Tag, Msg, Meta),
%% Only evaluate when necessary
-define(TRACE(Level, Tag, Msg, Meta), begin
case persistent_term:get(?TRACE_FILTER, []) of case persistent_term:get(?TRACE_FILTER, []) of
[] -> ok; [] -> ok;
%% We can't bind filter list to a variable because we pollute the calling scope with it. %% We can't bind filter list to a variable because we pollute the calling scope with it.
@ -70,7 +68,14 @@
%% because this adds overhead to the happy path. %% because this adds overhead to the happy path.
%% So evaluate `persistent_term:get` twice. %% So evaluate `persistent_term:get` twice.
_ -> emqx_trace:log(persistent_term:get(?TRACE_FILTER, []), Msg, (Meta)#{trace_tag => Tag}) _ -> emqx_trace:log(persistent_term:get(?TRACE_FILTER, []), Msg, (Meta)#{trace_tag => Tag})
end, end
).
-define(TRACE(Tag, Msg, Meta), ?TRACE(debug, Tag, Msg, Meta)).
%% Only evaluate when necessary
-define(TRACE(Level, Tag, Msg, Meta), begin
?_DO_TRACE(Tag, Msg, Meta),
?SLOG( ?SLOG(
Level, Level,
(emqx_trace_formatter:format_meta_map(Meta))#{msg => Msg, tag => Tag}, (emqx_trace_formatter:format_meta_map(Meta))#{msg => Msg, tag => Tag},

View File

@ -35,7 +35,9 @@ format(
ClientId = to_iolist(maps:get(clientid, Meta, "")), ClientId = to_iolist(maps:get(clientid, Meta, "")),
Peername = maps:get(peername, Meta, ""), Peername = maps:get(peername, Meta, ""),
MetaBin = format_meta(Meta, PEncode), MetaBin = format_meta(Meta, PEncode),
[Time, " [", Tag, "] ", ClientId, "@", Peername, " msg: ", Msg, ", ", MetaBin, "\n"]; Msg1 = to_iolist(Msg),
Tag1 = to_iolist(Tag),
[Time, " [", Tag1, "] ", ClientId, "@", Peername, " msg: ", Msg1, ", ", MetaBin, "\n"];
format(Event, Config) -> format(Event, Config) ->
emqx_logger_textfmt:format(Event, Config). emqx_logger_textfmt:format(Event, Config).

View File

@ -1,2 +1,8 @@
Implement log throttling. The feature reduces the number of potentially flooding logged events by Implement log throttling. The feature reduces the number of potentially flooding logged events by
dropping all but the first event within a configured time window. dropping all but the first event within a configured time window.
Throttling is applied to the following log events:
- authorization_permission_denied,
- cannot_publish_to_topic_due_to_not_authorized,
- cannot_publish_to_topic_due_to_quota_exceeded,
- connection_rejected_due_to_license_limit_reached,
- dropped_msg_due_to_mqueue_is_full.