Class BrowserGate.RejectionLog
java.lang.Object
com.iizix.jetty.BrowserGate.RejectionLog
- Enclosing class:
BrowserGate
The INFO line of a rejected load, throttled to one per User-Agent per interval, so that production shows how many users the sorry page reaches without a bot filling the log.
The line carries the entry name, the appID and the User-Agent, both truncated and with every control character replaced by '?', and nothing else: no address, no header, no cookie. The throttle is keyed by that truncated User-Agent and holds at most its capacity of them; when full, the entries older than the interval go first, then the eldest. An evicted User-Agent may therefore log again within the interval, which bounds memory rather than lines: a client that changes its User-Agent on every request gets a line per request whatever the throttle does.
- Author:
- Christopher Mindus
Constructor Summary
ConstructorsConstructorDescriptionRejectionLog(LongSupplier clock, int capacity, Consumer<String> sink) Creates a rejection log.Method Summary
Modifier and TypeMethodDescriptionbooleanlog(BrowserGate.Entry entry, String userAgent, String appID) Logs a rejected load, unless the same User-Agent was logged less than an interval ago.intsize()Gets the number of User-Agents remembered.
Constructor Details
RejectionLog
Creates a rejection log.- Parameters:
clock- The clock in milliseconds,System::currentTimeMillisin production.capacity- The most User-Agents remembered, at least 1.sink- Receives each line.- Throws:
IllegalArgumentException- If the capacity is below 1.
Method Details
log
Logs a rejected load, unless the same User-Agent was logged less than an interval ago.- Parameters:
entry- The entry that rejected the Browser, null when it passed: nothing is logged.userAgent- The User-Agent header, null for none.appID- The appID of the request, null for none.- Returns:
- true when a line was written.
size
public int size()Gets the number of User-Agents remembered.- Returns:
- The size, never above the capacity.