Add Log::RateLimitBackend to suppress repeated log entries#1764
Add Log::RateLimitBackend to suppress repeated log entries#1764
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
|
PR Review: Auth failure rate-limiting No issues found. The implementation is correct and well-structured:
|
|
We could take it further, make it more generic, by hashing each log message, in |
ed46190 to
d846f0c
Compare
|
Made it generic but only configured it for auth logs since it adds a performance cost on every log call. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
No issues found. |
|
Maybe push this into a log backend/dispatcher instead? The motivation looks faulty, followers dont start amqp listeners. |
feeea82 to
1c0271c
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
1c0271c to
f69694a
Compare
This comment was marked as resolved.
This comment was marked as resolved.
f69694a to
18a536b
Compare
This comment was marked as resolved.
This comment was marked as resolved.
18a536b to
af12b9c
Compare
This comment was marked as resolved.
This comment was marked as resolved.
af12b9c to
a3868c0
Compare
This comment was marked as resolved.
This comment was marked as resolved.
a3868c0 to
ca3ad00
Compare
This comment was marked as resolved.
This comment was marked as resolved.
ca3ad00 to
b3407ea
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
PR Review: Log::RateLimitBackend1. Phantom source
|
PR Review: Log Rate Limit Backend1. Phantom source
|
0b9f9b6 to
ddac481
Compare
Adds a Log::Backend wrapper that suppresses repeated log entries within
a configurable window. The first occurrence of each {source, message}
pair passes through immediately. Subsequent occurrences within the window
are counted but not forwarded. When the window expires and a new entry
arrives, a summary ("… suppressed N times: <message>") is emitted first,
followed by the new entry. Pending counts are also flushed on close and
during periodic cleanup of stale keys.
Wired up in Config#setup_logger scoped to amqp.connection_factory,
mqtt.connection_factory, and auth.handler sources only, so unrelated
log traffic has no overhead.
Motivation: under connection churn, a client with wrong credentials can
generate hundreds of auth failure log lines per second, wasting CPU on
formatting and I/O. The suppression is handled transparently by the
logging layer and applies to any log source in the configured list.
Code Review1. Critical: Unintentional revert of two recent bug fixesThe PR inadvertently reverts changes from two recently merged PRs. The branch was likely created before these were merged and was rebased/merged incorrectly. a) Revert of #1772 — In b) Revert of #1760 — All Neither of these changes is mentioned in the PR description ("No changes to business logic"), confirming they are unintentional. Fix: Rebase onto current 2. Race between
|
ddac481 to
d9b52bc
Compare
PR Review: Add Log::RateLimitBackend1. Branch needs rebase — unintended reversions (Critical)The diff includes changes to
Both associated specs are also deleted. The branch needs to be rebased on 2. Race condition in
|
Summary
Log::RateLimitBackend, aLog::Backendwrapper that suppresses repeated log entries within a configurable windowConfig#setup_loggerwrapping the existing broadcast backendlog.info { "Authentication failure..." }as normalHow it works
{source, message}(null-byte delimited)Motivation
Under connection churn, a client with wrong credentials can generate hundreds of auth failure log lines per second. This wastes CPU on log formatting and I/O. Rather than tracking this in each connection factory, the suppression is handled transparently by the logging layer and applies to any log source.
Test plan
make test SPEC=spec/log/rate_limit_backend_spec.cr(9 specs)