From b833a10a0c511ee58c39282f0538f9f39d555761 Mon Sep 17 00:00:00 2001 From: Matt Jacobson Date: Mon, 10 Nov 2025 21:15:51 -0500 Subject: [PATCH] Fix alert rule route preview and irmHooks use of route api --- .../useAlertmanagerNotificationRoutingPreview.ts | 12 +++++++++--- .../features/gops/configuration-tracker/irmHooks.ts | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/useAlertmanagerNotificationRoutingPreview.ts b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/useAlertmanagerNotificationRoutingPreview.ts index 2f95fe40d52..548a4b442bc 100644 --- a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/useAlertmanagerNotificationRoutingPreview.ts +++ b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/useAlertmanagerNotificationRoutingPreview.ts @@ -8,18 +8,24 @@ import { useRouteGroupsMatcher } from '../../../useRouteGroupsMatcher'; import { addUniqueIdentifierToRoute } from '../../../utils/amroutes'; import { GRAFANA_RULES_SOURCE_NAME } from '../../../utils/datasource'; import { normalizeRoute } from '../../../utils/notification-policies'; +import { NAMED_ROOT_LABEL_NAME } from '../../../api/routesApi'; export const useAlertmanagerNotificationRoutingPreview = (alertmanager: string, instances: Labels[]) => { + // if a NAMED_ROOT_LABEL_NAME label exists, then we only match to that route. + const routeName = useMemo(() => { + const routeNameLabel = instances.find((instance) => instance[NAMED_ROOT_LABEL_NAME]); + return routeNameLabel?.[NAMED_ROOT_LABEL_NAME]; + }, [instances]); + const { - data: currentData, + data: defaultPolicy, isLoading: isPoliciesLoading, error: policiesError, - } = useNotificationPolicyRoute({ alertmanager }); + } = useNotificationPolicyRoute({ alertmanager }, routeName); // this function will use a web worker to compute matching routes const { matchInstancesToRoutes } = useRouteGroupsMatcher(); - const [defaultPolicy] = currentData ?? []; const rootRoute = useMemo(() => { if (!defaultPolicy) { return; diff --git a/public/app/features/gops/configuration-tracker/irmHooks.ts b/public/app/features/gops/configuration-tracker/irmHooks.ts index e65ccf44652..5726b13b2f1 100644 --- a/public/app/features/gops/configuration-tracker/irmHooks.ts +++ b/public/app/features/gops/configuration-tracker/irmHooks.ts @@ -61,7 +61,7 @@ function useGetConfigurationForApps() { const { data: rootRoute, isLoading: isLoadingDefaultContactPoint } = useNotificationPolicyRoute({ alertmanager: GRAFANA_RULES_SOURCE_NAME, }); - const defaultContactpoint = rootRoute?.[0].receiver || ''; + const defaultContactpoint = rootRoute?.receiver || ''; const { isDone: isCreateAlertRuleDone, isLoading: isLoadingAlertCreatedDone } = useIsCreateAlertRuleDone(); // configuration checks for incidents const {