Uploaded image for project: 'Observability UI'
  1. Observability UI
  2. OU-1120

[Incidents] 100+ Alerts in an Incident do not Load (Math.MAX() stack limit)

XMLWordPrintable

    • None
    • None
    • None
    • None
    • None
    • None

      Description

      The application is experiencing crashes when processing large datasets of incident alerts (specifically scenarios involving 80+ alerts with ~300,000 timestamp values).

      The root cause is the use of the spread operator (...) within Math.max and Math.min. When applied to large arrays, JavaScript attempts to push all array elements onto the call stack as arguments, exceeding the browser's stack limit.

      Impact

      • Error Thrown: RangeError: Maximum call stack size exceeded
      • User Experience: The application crashes or fails to render the Incidents view when data volume is high.
      • Location: /web/src/components/Incidents/

      Problematic Code Pattern

      The following pattern causes the stack overflow when timestamps contains >100k items:

      // CRASHES with large arrays
      const incidentFirstTimestamp = Math.min(...timestamps);
      const incidentLastTimestamp = Math.max(...timestamps);
      
      // Also seen as:
      Math.max(...incident.values.map((v) => v[0]));
      

      Proposed Solution

      Refactor the code to use .reduce(). This approach runs in the heap rather than the call stack, using O(1) stack space regardless of array size.

      Replace the spread syntax with:

      // Find Max
      const max = values.reduce((m, v) => (v[0] > m ? v[0] : m), -Infinity);
      
      // Find Min
      const min = values.reduce((m, v) => (v[0] < m ? v[0] : m), Infinity);
      

      Scope of Changes

      The following files in /web/src/components/Incidents/ require refactoring:

      • processAlerts.ts
        • convertToAlerts()
        • mergeIncidentsByKey()
      • processIncidents.ts
        • getIncidents()
      • utils.ts
        • sortByEarliestTimestamp()
      • IncidentsTable.tsx
        • getMinStartDate()

              drajnoha@redhat.com David Rajnoha
              drajnoha@redhat.com David Rajnoha
              None
              None
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: