Package com.ultikits.ultitools.manager
Class ErrorReportCollector
java.lang.Object
com.ultikits.ultitools.manager.ErrorReportCollector
Collects, deduplicates, and rate-limits error reports before they reach the WebSocket.
Three-layer protection against DB bloat: 1. Fingerprint dedup within 5-minute window 2. Max 10 unique errors per batch cycle 3. Sampling after 10 total occurrences of same error
This class NEVER uses java.util.logging.Logger to prevent circular logging. All internal error output uses System.err.
- Since:
- 6.2.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classError report data structure. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentHashMap<String, ErrorReportCollector.ErrorReport> private intprivate booleanprivate final ConcurrentLinkedQueue<ErrorReportCollector.ErrorReport> private static final intprivate final ConcurrentHashMap<String, AtomicInteger> private static final intprivate static final intprivate static final intprivate static final intprivate intprivate intprivate doubleprivate ScheduledExecutorService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidCapture current server state (TPS, memory, player count).private StringcomputeFingerprint(Throwable throwable) Compute a fingerprint for dedup: hash of (exception class + top N stack frame method:line).private booleancomputeIsFramework(Throwable throwable, String moduleName) Determine whether an error originates from the UltiTools framework itself (as opposed to a plugin module loaded by the framework).private ErrorReportCollector.ErrorReportcreateReport(Throwable throwable, String fingerprint, String moduleName, TriggerContext ctx) Create an ErrorReport from a throwable.com.google.gson.JsonArraydrainErrors(int max) Drain errors into a JsonArray for batch_update.private StringformatStackTrace(Throwable throwable) Format stack trace to string, truncated to MAX_STACK_TRACE_LENGTH.voidinit()Initialize the collector and start the dedup window reset scheduler.booleanCheck if error reporting is enabled.voidLoad configuration from UltiTools config.yml.voidreportError(Throwable throwable, String moduleName, TriggerContext ctx) Report an error.private voidReset the dedup window — allows the same error to be reported again.voidshutdown()Shutdown the collector.
-
Field Details
-
MAX_QUEUE_SIZE
private static final int MAX_QUEUE_SIZE- See Also:
-
MAX_MESSAGE_LENGTH
private static final int MAX_MESSAGE_LENGTH- See Also:
-
MAX_STACK_TRACE_LENGTH
private static final int MAX_STACK_TRACE_LENGTH- See Also:
-
MAX_STACK_FRAMES
private static final int MAX_STACK_FRAMES- See Also:
-
FINGERPRINT_STACK_FRAMES
private static final int FINGERPRINT_STACK_FRAMES- See Also:
-
enabled
private volatile boolean enabled -
dedupWindowSeconds
private volatile int dedupWindowSeconds -
maxErrorsPerBatch
private volatile int maxErrorsPerBatch -
sampleAfterCount
private volatile int sampleAfterCount -
sampleRate
private volatile double sampleRate -
dedupMap
-
errorQueue
-
lifetimeCounters
-
scheduler
-
-
Constructor Details
-
ErrorReportCollector
public ErrorReportCollector()
-
-
Method Details
-
init
public void init()Initialize the collector and start the dedup window reset scheduler. -
shutdown
public void shutdown()Shutdown the collector. -
loadConfiguration
public void loadConfiguration()Load configuration from UltiTools config.yml. -
reportError
Report an error. Thread-safe. Returns immediately if disabled.- Parameters:
throwable- the exceptionmoduleName- which UltiTools module caused it (e.g., "UltiChat")ctx- trigger context (who/what caused this)
-
drainErrors
public com.google.gson.JsonArray drainErrors(int max) Drain errors into a JsonArray for batch_update. Layer 2: returns at most maxErrorsPerBatch, sorted by count descending. Performs a final dedup pass to merge entries with the same fingerprint.- Parameters:
max- maximum number of errors to drain- Returns:
- JsonArray of error reports
-
resetDedupWindow
private void resetDedupWindow()Reset the dedup window — allows the same error to be reported again. -
computeFingerprint
Compute a fingerprint for dedup: hash of (exception class + top N stack frame method:line). -
createReport
private ErrorReportCollector.ErrorReport createReport(Throwable throwable, String fingerprint, String moduleName, TriggerContext ctx) Create an ErrorReport from a throwable. -
captureServerState
Capture current server state (TPS, memory, player count). -
formatStackTrace
Format stack trace to string, truncated to MAX_STACK_TRACE_LENGTH. -
computeIsFramework
Determine whether an error originates from the UltiTools framework itself (as opposed to a plugin module loaded by the framework).A framework error satisfies BOTH: 1. The top stack frame's class is in the com.ultikits.ultitools package. 2. The module name indicates the framework (null, empty, or "UltiTools").
-
isEnabled
public boolean isEnabled()Check if error reporting is enabled.- Returns:
- true if enabled
-