Skip to content

Commit b8f4ed7

Browse files
committed
feat: edge case when 5m aggregated timestamp is greater than current datapoint
1 parent d857007 commit b8f4ed7

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

web/src/components/Incidents/IncidentsChart/IncidentsChart.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ import {
3434
createIncidentsChartBars,
3535
generateDateArray,
3636
matchTimestampMetricForIncident,
37-
<<<<<<< HEAD
3837
roundDateToInterval,
39-
=======
4038
roundTimestampToFiveMinutes,
41-
>>>>>>> 55a5bc3 (feat: round absolute start dates to 5 minutes boundaries)
4239
} from '../utils';
4340
import { dateTimeFormatter, timeFormatter } from '../../console/utils/datetime';
4441
import { useTranslation } from 'react-i18next';

web/src/components/Incidents/utils.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
getCurrentTime,
3-
insertPaddingPointsForChart, roundDateToInterval,
3+
insertPaddingPointsForChart,
4+
roundDateToInterval,
45
matchTimestampMetricForIncident,
56
roundTimestampToFiveMinutes,
67
} from './utils';

web/src/components/Incidents/utils.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ export const createIncidentsChartBars = (incident: Incident, dateArray: SpanDate
339339
const severity = getSeverityName(groupedData[i][2]);
340340
const isLastElement = i === groupedData.length - 1;
341341

342+
// to avoid certain edge cases the startDate should
343+
// be the minimum between alert.firstTimestamp and groupedData[i][0]
344+
const startDate = Math.min(incident.firstTimestamp, groupedData[i][0]);
345+
342346
data.push({
343347
y0: new Date(groupedData[i][0] * 1000),
344348
y: new Date(groupedData[i][1] * 1000),
@@ -348,7 +352,7 @@ export const createIncidentsChartBars = (incident: Incident, dateArray: SpanDate
348352
componentList: incident.componentList || [],
349353
group_id: incident.group_id,
350354
nodata: groupedData[i][2] === 'nodata' ? true : false,
351-
startDate: new Date(roundTimestampToFiveMinutes(incident.firstTimestamp) * 1000),
355+
startDate: new Date(roundTimestampToFiveMinutes(startDate) * 1000),
352356
fill:
353357
severity === 'Critical'
354358
? barChartColorScheme.critical
@@ -407,10 +411,14 @@ export const createAlertsChartBars = (alert: IncidentsDetailsAlert): AlertsChart
407411
for (let i = 0; i < groupedData.length; i++) {
408412
const isLastElement = i === groupedData.length - 1;
409413

414+
// to avoid certain edge cases the startDate should
415+
// be the minimum between alert.firstTimestamp and groupedData[i][0]
416+
const startDate = Math.min(alert.firstTimestamp, groupedData[i][0]);
417+
410418
data.push({
411419
y0: new Date(groupedData[i][0] * 1000),
412420
y: new Date(groupedData[i][1] * 1000),
413-
startDate: new Date(roundTimestampToFiveMinutes(alert.firstTimestamp) * 1000),
421+
startDate: new Date(roundTimestampToFiveMinutes(startDate) * 1000),
414422
x: alert.x,
415423
severity: alert.severity[0].toUpperCase() + alert.severity.slice(1),
416424
name: alert.alertname,

0 commit comments

Comments
 (0)