K-Phoen / backstage-plugin-opsgenie

OpsGenie plugin for Backstage
MIT License
35 stars 37 forks source link

[Analytics] fails to render when incident impactStartDate are on 1st or 2nd of January #116

Open pizzqc opened 1 year ago

pizzqc commented 1 year ago

Plugin Version: 0.6.3 Backstage Version: 1.6.0

Starting in the new year 2023, we started having the backstage opsgenie Analytics tab to stop working and generating a bunch of undefined errors.

Digging into the code a little, we can see that a date in early January result into being classified as Week 52 of 2023 instead of Week 1. Which then leads to an issue when trying to increment the incidentsBuckets since week w52 - 2023 wasn't initialized to 0. (incidentsBuckets[week].total += 1;)

index-8e608a93.esm.js:269 Uncaught TypeError: Cannot read properties of undefined (reading 'total')
    at eval (index-8e608a93.esm.js:269:1)
    at Array.forEach (<anonymous>)
    at AnalitycsApi.incidentsByWeekAndHours (index-8e608a93.esm.js:266:1)
    at Graph$3 (index-8e608a93.esm.js:1194:1)
    at renderWithHooks (react-dom.development.js:14985:1)
    at mountIndeterminateComponent (react-dom.development.js:17811:1)
    at beginWork (react-dom.development.js:19049:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
    at invokeGuardedCallback (react-dom.development.js:4056:1)

Steps to reproduce

  1. Make sure to have an incident in OpsGenie that has an impactStartDate in early January. (i.e.: impactStartDate: "2023-01-02T03:00:38.787Z")
  2. Open the /opsgenie/analytics page

Error: Cannot read properties of undefined (reading 'total')

pizzqc commented 1 year ago

One easy solution could be to use week() instead of isoWeek() which might be better suited for this code logic.

the ISO week counter starts from the week with the first Thursday of the year. So, if the first day of the year is Saturday, it belongs to the last week of the previous year.

image