-
Bug
-
Resolution: Unresolved
-
Minor
-
COO 1.3.0
Description
The deduplicateAlerts and mergeIncidentsByKey functions in processAlerts.ts rely on JSON.stringify for value deduplication. This implementation results in quadratic time complexity when merging alerts from multiple sequential time range queries.
Root Cause
When merging duplicate alerts (same alertname/namespace/component/severity) from different time windows, the current logic:
- Converts ALL existing accumulated values to strings via JSON.stringify to build a comparison Set.
- Converts ALL new values to strings to check membership.
- Repeats this full serialization process for every new time range chunk received.
With N time chunks and M values per chunk, this results in *O(M × N²)* complexity regarding stringify operations, instead of the expected O(M × N).
Performance Impact
- Example:
- Processing 50 alerts with ~29,000 total values over 3 chunks triggers ~45,000 JSON.stringify/parse operations per function.
- Processing 50 alerts with ~29,000 total values over 15 chunks triggers ~175,000 JSON.stringify/parse operations per function.
- Optimal:
- Processing 50 alerts with ~29,000 values over arbitrary number of chunks triggers ~29,000 operations.
The direct performance impact estimation (time added for page load) under significant alert load (100+ alerts spread over 15 days) is TBD, partially blocked by https://issues.redhat.com/browse/OU-632.
Severity
Given the fact, that we cap up at 15 chunks for 15 days incident, the estimated 6x overhead is not huge. Yet, it could be beneficial to include the fix as part of a larger refactor.
Proposed Solution
Replace JSON.stringify deduplication with a Map or Set that uses simple string keys (template literals). This allows for O(1) lookup without re-serializing the entire existing dataset on every merge.
Implementation Strategy:
// Current (Expensive): // JSON.stringify([1733234400, "2"]) → "[1733234400,\"2\"]" // Proposed (Lightweight): // `${timestamp}_${severity}` → "1733234400_2"
Affected Files
- web/src/components/Incidents/processAlerts.ts
- deduplicateAlerts()
- mergeIncidentsByKey()