Skip to content

Commit

Permalink
feat: enable log throttling for potentially flooding log events
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeTupchiy committed Feb 19, 2024
1 parent 5e611bf commit 5714bd5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
10 changes: 8 additions & 2 deletions apps/emqx/src/emqx_access_control.erl
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,14 @@ log_result(#{username := Username}, Topic, Action, From, Result) ->
}
end,
case Result of
allow -> ?SLOG(info, (LogMeta())#{msg => "authorization_permission_allowed"});
deny -> ?SLOG(info, (LogMeta())#{msg => "authorization_permission_denied"})
allow ->
?SLOG(info, (LogMeta())#{msg => "authorization_permission_allowed"});
deny ->
?SLOG_THROTTLE(
authorization_permission_denied,
warning,
(LogMeta())#{msg => "authorization_permission_denied"}
)
end.

%% @private Format authorization rules source.
Expand Down
10 changes: 6 additions & 4 deletions apps/emqx/src/emqx_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,9 @@ process_publish(Packet = ?PUBLISH_PACKET(QoS, Topic, PacketId), Channel) ->
Msg = packet_to_message(NPacket, NChannel),
do_publish(PacketId, Msg, NChannel);
{error, Rc = ?RC_NOT_AUTHORIZED, NChannel} ->
?SLOG(
info,
?SLOG_THROTTLE(
cannot_publish_not_authorized,
warning,
#{
msg => "cannot_publish_to_topic",
reason => emqx_reason_codes:name(Rc)
Expand All @@ -635,8 +636,9 @@ process_publish(Packet = ?PUBLISH_PACKET(QoS, Topic, PacketId), Channel) ->
handle_out(disconnect, Rc, NChannel)
end;
{error, Rc = ?RC_QUOTA_EXCEEDED, NChannel} ->
?SLOG(
info,
?SLOG_THROTTLE(
cannot_publish_quota_exceeded,
warning,
#{
msg => "cannot_publish_to_topic",
reason => emqx_reason_codes:name(Rc)
Expand Down
5 changes: 3 additions & 2 deletions apps/emqx/src/emqx_session_events.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ handle_event(ClientInfo, {dropped, Msg, #{reason := queue_full, logctx := Ctx}})
ok = emqx_metrics:inc('delivery.dropped.queue_full'),
ok = inc_pd('send_msg.dropped', 1),
ok = inc_pd('send_msg.dropped.queue_full', 1),
?SLOG(
info,
?SLOG_THROTTLE(
dropped_msg_mqueue_full,
warning,
Ctx#{
msg => "dropped_msg_due_to_mqueue_is_full",
payload => Msg#message.payload
Expand Down
8 changes: 7 additions & 1 deletion apps/emqx_conf/src/emqx_conf_schema.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,13 @@ fields("log_throttling") ->
sc(
hoconsc:array(atom()),
#{
default => [],
default => [
authorization_permission_denied,
cannot_publish_not_authorized,
cannot_publish_quota_exceeded,
conn_rejected_license_limit_reached,
dropped_msg_mqueue_full
],
importance => ?IMPORTANCE_HIDDEN
}
)}
Expand Down
6 changes: 5 additions & 1 deletion apps/emqx_license/src/emqx_license.erl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ check(_ConnInfo, AckProps) ->
{ok, #{max_connections := MaxClients}} ->
case check_max_clients_exceeded(MaxClients) of
true ->
?SLOG(info, #{msg => "connection_rejected_due_to_license_limit_reached"}),
?SLOG_THROTTLE(
conn_rejected_license_limit_reached,
error,
#{msg => "connection_rejected_due_to_license_limit_reached"}
),
{stop, {error, ?RC_QUOTA_EXCEEDED}};
false ->
{ok, AckProps}
Expand Down

0 comments on commit 5714bd5

Please sign in to comment.