-
Notifications
You must be signed in to change notification settings - Fork 53
OU-1040: feat/absolute start dates #749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
898ae22
ba22dfb
97d076a
6497191
d857007
b8f4ed7
0c54136
9923c13
a5864d2
04c8326
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| /* eslint-disable react-hooks/exhaustive-deps */ | ||
| import { useMemo, useState, useEffect, useCallback } from 'react'; | ||
| import { useSafeFetch } from '../console/utils/safe-fetch-hook'; | ||
| import { createAlertsQuery, fetchDataForIncidentsAndAlerts } from './api'; | ||
| import { createAlertsQuery, fetchDataForIncidentsAndAlerts, fetchInstantData } from './api'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { | ||
| Bullseye, | ||
|
|
@@ -46,7 +46,9 @@ import { | |
| setAlertsAreLoading, | ||
| setAlertsData, | ||
| setAlertsTableData, | ||
| setAlertsTimestamps, | ||
| setFilteredIncidentsData, | ||
| setIncidentsTimestamps, | ||
| setIncidentPageFilterType, | ||
| setIncidents, | ||
| setIncidentsActiveFilters, | ||
|
|
@@ -146,6 +148,10 @@ const IncidentsPage = () => { | |
| (state: MonitoringState) => state.plugins.mcp.incidentsData.filteredIncidentsData, | ||
| ); | ||
|
|
||
| const incidentsTimestamps = useSelector( | ||
| (state: MonitoringState) => state.plugins.mcp.incidentsData.incidentsTimestamps, | ||
| ); | ||
|
|
||
| const selectedGroupId = incidentsActiveFilters.groupId?.[0] ?? undefined; | ||
|
|
||
| const incidentPageFilterTypeSelected = useSelector( | ||
|
|
@@ -229,49 +235,74 @@ const IncidentsPage = () => { | |
| }, [incidentsActiveFilters.days]); | ||
|
|
||
| useEffect(() => { | ||
| (async () => { | ||
| const currentTime = incidentsLastRefreshTime; | ||
| Promise.all( | ||
| timeRanges.map(async (range) => { | ||
| const response = await fetchDataForIncidentsAndAlerts( | ||
| safeFetch, | ||
| range, | ||
| createAlertsQuery(incidentForAlertProcessing), | ||
| ); | ||
| return response.data.result; | ||
| }), | ||
| ) | ||
| .then((results) => { | ||
| const prometheusResults = results.flat(); | ||
| const alerts = convertToAlerts( | ||
| prometheusResults, | ||
| incidentForAlertProcessing, | ||
| currentTime, | ||
| ); | ||
| // Guard: don't process if no incidents selected or timeRanges not ready | ||
| if (incidentForAlertProcessing.length === 0 || timeRanges.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| const currentTime = incidentsLastRefreshTime; | ||
|
|
||
| // Fetch timestamps and alerts in parallel, but wait for both before processing | ||
| const timestampsPromise = Promise.all( | ||
|
PeterYurkovich marked this conversation as resolved.
Outdated
|
||
| ['min_over_time(timestamp(ALERTS{alertstate="firing"})[15d:5m])'].map(async (query) => { | ||
| const response = await fetchInstantData(safeFetch, query); | ||
| return response.data.result; | ||
| }), | ||
| ); | ||
|
|
||
| const alertsPromise = Promise.all( | ||
| timeRanges.map(async (range) => { | ||
| const response = await fetchDataForIncidentsAndAlerts( | ||
| safeFetch, | ||
| range, | ||
| createAlertsQuery(incidentForAlertProcessing), | ||
| ); | ||
| return response.data.result; | ||
| }), | ||
| ); | ||
|
|
||
| Promise.all([timestampsPromise, alertsPromise]) | ||
| .then(([timestampsResults, alertsResults]) => { | ||
| // Dispatch timestamps to store | ||
| const fetchedAlertsTimestamps = { | ||
| minOverTime: timestampsResults[0], | ||
| }; | ||
| dispatch( | ||
| setAlertsTimestamps({ | ||
| alertsTimestamps: fetchedAlertsTimestamps, | ||
| }), | ||
| ); | ||
|
|
||
| const prometheusResults = alertsResults.flat(); | ||
| const alerts = convertToAlerts( | ||
| prometheusResults, | ||
| incidentForAlertProcessing, | ||
| currentTime, | ||
| fetchedAlertsTimestamps, | ||
| ); | ||
| dispatch( | ||
| setAlertsData({ | ||
| alertsData: alerts, | ||
| }), | ||
| ); | ||
| if (rules && alerts) { | ||
| dispatch( | ||
| setAlertsData({ | ||
| alertsData: alerts, | ||
| setAlertsTableData({ | ||
| alertsTableData: groupAlertsForTable(alerts, rules), | ||
| }), | ||
| ); | ||
| if (rules && alerts) { | ||
| dispatch( | ||
| setAlertsTableData({ | ||
| alertsTableData: groupAlertsForTable(alerts, rules), | ||
| }), | ||
| ); | ||
| } | ||
| if (!isEmpty(filteredData)) { | ||
| dispatch(setAlertsAreLoading({ alertsAreLoading: false })); | ||
| } else { | ||
| dispatch(setAlertsAreLoading({ alertsAreLoading: true })); | ||
| } | ||
| }) | ||
| .catch((err) => { | ||
| // eslint-disable-next-line no-console | ||
| console.log(err); | ||
| }); | ||
| })(); | ||
| }, [incidentForAlertProcessing]); | ||
| } | ||
| if (!isEmpty(filteredData)) { | ||
| dispatch(setAlertsAreLoading({ alertsAreLoading: false })); | ||
| } else { | ||
| dispatch(setAlertsAreLoading({ alertsAreLoading: true })); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }) | ||
| .catch((err) => { | ||
| // eslint-disable-next-line no-console | ||
| console.log(err); | ||
|
PeterYurkovich marked this conversation as resolved.
Outdated
|
||
| }); | ||
| }, [incidentForAlertProcessing, timeRanges, rules]); | ||
|
Comment on lines
232
to
+283
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 259 passes Proposed fix- }, [incidentForAlertProcessing, timeRanges, rules]);
+ }, [incidentForAlertProcessing, timeRanges, rules, daysSpan]);🤖 Prompt for AI Agents |
||
|
|
||
| useEffect(() => { | ||
| if (!isInitialized) return; | ||
|
|
@@ -294,14 +325,34 @@ const IncidentsPage = () => { | |
| ? `cluster_health_components_map{group_id='${selectedGroupId}'}` | ||
| : 'cluster_health_components_map'; | ||
|
|
||
| Promise.all( | ||
| // Fetch timestamps and incidents in parallel, but wait for both before processing | ||
| const timestampsPromise = Promise.all( | ||
|
PeterYurkovich marked this conversation as resolved.
Outdated
|
||
| ['min_over_time(timestamp(cluster_health_components_map)[15d:5m])'].map(async (query) => { | ||
|
PeterYurkovich marked this conversation as resolved.
Outdated
|
||
| const response = await fetchInstantData(safeFetch, query); | ||
| return response.data.result; | ||
| }), | ||
| ); | ||
|
|
||
| const incidentsPromise = Promise.all( | ||
| calculatedTimeRanges.map(async (range) => { | ||
| const response = await fetchDataForIncidentsAndAlerts(safeFetch, range, incidentsQuery); | ||
| return response.data.result; | ||
| }), | ||
| ) | ||
| .then((results) => { | ||
| const prometheusResults = results.flat(); | ||
| ); | ||
|
|
||
| Promise.all([timestampsPromise, incidentsPromise]) | ||
| .then(([timestampsResults, incidentsResults]) => { | ||
| // Dispatch timestamps to store | ||
| const fetchedTimestamps = { | ||
| minOverTime: timestampsResults[0], | ||
| }; | ||
| dispatch( | ||
| setIncidentsTimestamps({ | ||
| incidentsTimestamps: fetchedTimestamps, | ||
| }), | ||
| ); | ||
|
|
||
| const prometheusResults = incidentsResults.flat(); | ||
| const incidents = convertToIncidents(prometheusResults, currentTime); | ||
|
|
||
| // Update the raw, unfiltered incidents state | ||
|
|
@@ -317,7 +368,10 @@ const IncidentsPage = () => { | |
| setIncidentsAreLoading(false); | ||
|
|
||
| if (isGroupSelected) { | ||
| setIncidentForAlertProcessing(processIncidentsForAlerts(prometheusResults)); | ||
| // Use fetchedTimestamps directly instead of stale closure value | ||
| setIncidentForAlertProcessing( | ||
| processIncidentsForAlerts(prometheusResults, fetchedTimestamps), | ||
| ); | ||
| dispatch(setAlertsAreLoading({ alertsAreLoading: true })); | ||
| } else { | ||
| closeDropDownFilters(); | ||
|
|
@@ -638,6 +692,7 @@ const IncidentsPage = () => { | |
| <StackItem> | ||
| <IncidentsChart | ||
| incidentsData={filteredData} | ||
| incidentsTimestamps={incidentsTimestamps} | ||
| chartDays={timeRanges.length} | ||
| theme={theme} | ||
| selectedGroupId={selectedGroupId} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.