mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
Alerting: Fix refetching grafana rules on alert list panel (#72242)
This commit is contained in:
parent
da31b8083a
commit
e094adb5a1
@ -135,18 +135,53 @@ export function UnifiedAlertList(props: PanelProps<UnifiedAlertListOptions>) {
|
||||
[parsedOptions.alertInstanceLabelFilter]
|
||||
);
|
||||
|
||||
// If the datasource is not defined we should NOT skip the query
|
||||
// Undefined dataSourceName means that there is no datasource filter applied and we should fetch all the rules
|
||||
const shouldFetchGrafanaRules = !dataSourceName || dataSourceName === GRAFANA_RULES_SOURCE_NAME;
|
||||
|
||||
//For grafana managed rules, get the result using RTK Query to avoid the need of using the redux store
|
||||
//See https://github.com/grafana/grafana/pull/70482
|
||||
const {
|
||||
currentData: grafanaPromRules = [],
|
||||
isLoading: grafanaRulesLoading,
|
||||
refetch: refetchGrafanaPromRules,
|
||||
} = usePrometheusRulesByNamespaceQuery(
|
||||
{
|
||||
limitAlerts: limitInstances ? INSTANCES_DISPLAY_LIMIT : undefined,
|
||||
matcher: matcherList,
|
||||
state: stateList,
|
||||
},
|
||||
{ skip: !shouldFetchGrafanaRules }
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
//we need promRules and rulerRules for getting the uid when creating the alert link in panel in case of being a rulerRule.
|
||||
if (!promRulesRequests.loading) {
|
||||
fetchPromAndRuler({ dispatch, limitInstances, matcherList, dataSourceName, stateList });
|
||||
}
|
||||
const sub = dashboard?.events.subscribe(TimeRangeUpdatedEvent, () =>
|
||||
fetchPromAndRuler({ dispatch, limitInstances, matcherList, dataSourceName, stateList })
|
||||
);
|
||||
const sub = dashboard?.events.subscribe(TimeRangeUpdatedEvent, () => {
|
||||
if (shouldFetchGrafanaRules) {
|
||||
refetchGrafanaPromRules();
|
||||
}
|
||||
|
||||
if (!dataSourceName || dataSourceName !== GRAFANA_RULES_SOURCE_NAME) {
|
||||
fetchPromAndRuler({ dispatch, limitInstances, matcherList, dataSourceName, stateList });
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
sub?.unsubscribe();
|
||||
};
|
||||
}, [dispatch, dashboard, matcherList, stateList, limitInstances, dataSourceName, promRulesRequests.loading]);
|
||||
}, [
|
||||
dispatch,
|
||||
dashboard,
|
||||
matcherList,
|
||||
stateList,
|
||||
limitInstances,
|
||||
dataSourceName,
|
||||
refetchGrafanaPromRules,
|
||||
shouldFetchGrafanaRules,
|
||||
promRulesRequests.loading,
|
||||
]);
|
||||
|
||||
const handleInstancesLimit = (limit: boolean) => {
|
||||
if (limit) {
|
||||
@ -158,18 +193,7 @@ export function UnifiedAlertList(props: PanelProps<UnifiedAlertListOptions>) {
|
||||
}
|
||||
};
|
||||
|
||||
//For grafana managed rules, get the result using RTK Query to avoid the need of using the redux store
|
||||
//See https://github.com/grafana/grafana/pull/70482
|
||||
const { currentData: promRules = [], isLoading: grafanaRulesLoading } = usePrometheusRulesByNamespaceQuery(
|
||||
{
|
||||
limitAlerts: limitInstances ? INSTANCES_DISPLAY_LIMIT : undefined,
|
||||
matcher: matcherList,
|
||||
state: stateList,
|
||||
},
|
||||
{ skip: dataSourceName !== GRAFANA_RULES_SOURCE_NAME }
|
||||
);
|
||||
|
||||
const combinedRules = useCombinedRuleNamespaces(undefined, promRules);
|
||||
const combinedRules = useCombinedRuleNamespaces(undefined, grafanaPromRules);
|
||||
|
||||
const someRulerRulesDispatched = isAsyncRequestMapSlicePartiallyDispatched(rulerRulesRequests);
|
||||
const haveResults = isAsyncRequestMapSlicePartiallyFulfilled(promRulesRequests);
|
||||
|
Loading…
Reference in New Issue
Block a user