From 7b415cf79e479086a4eed6860a4b6218adb01ee4 Mon Sep 17 00:00:00 2001 From: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com> Date: Fri, 16 Feb 2024 15:15:02 +0100 Subject: [PATCH] Alerting: Skip fetching receivers status in the alert rule form (#82892) --- .../contact-points/useContactPoints.tsx | 17 ++++++++++++----- .../simplifiedRouting/AlertManagerRouting.tsx | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/public/app/features/alerting/unified/components/contact-points/useContactPoints.tsx b/public/app/features/alerting/unified/components/contact-points/useContactPoints.tsx index 5ab23e150e3..8d6ca99a720 100644 --- a/public/app/features/alerting/unified/components/contact-points/useContactPoints.tsx +++ b/public/app/features/alerting/unified/components/contact-points/useContactPoints.tsx @@ -29,11 +29,18 @@ const RECEIVER_STATUS_POLLING_INTERVAL = 10 * 1000; // 10 seconds */ interface UseContactPointsWithStatusOptions { includePoliciesCount: boolean; + receiverStatusPollingInterval?: number; } -export function useContactPointsWithStatus( - { includePoliciesCount }: UseContactPointsWithStatusOptions = { includePoliciesCount: true } -) { +const defaultHookOptions = { + includePoliciesCount: true, + receiverStatusPollingInterval: RECEIVER_STATUS_POLLING_INTERVAL, +}; + +export function useContactPointsWithStatus({ + includePoliciesCount, + receiverStatusPollingInterval, +}: UseContactPointsWithStatusOptions = defaultHookOptions) { const { selectedAlertmanager, isGrafanaAlertmanager } = useAlertmanager(); const { installed: onCallPluginInstalled, loading: onCallPluginStatusLoading } = usePluginBridge( SupportedPlugin.OnCall @@ -43,8 +50,8 @@ export function useContactPointsWithStatus( const fetchContactPointsStatus = alertmanagerApi.endpoints.getContactPointsStatus.useQuery(undefined, { refetchOnFocus: true, refetchOnReconnect: true, - // re-fetch status every so often for up-to-date information - pollingInterval: RECEIVER_STATUS_POLLING_INTERVAL, + // re-fetch status every so often for up-to-date information, allow disabling by passing "receiverStatusPollingInterval: 0" + pollingInterval: receiverStatusPollingInterval, // skip fetching receiver statuses if not Grafana AM skip: !isGrafanaAlertmanager, }); diff --git a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/AlertManagerRouting.tsx b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/AlertManagerRouting.tsx index 94ee0b3be3f..2012a49ec4a 100644 --- a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/AlertManagerRouting.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/AlertManagerRouting.tsx @@ -29,7 +29,7 @@ export function AlertManagerManualRouting({ alertManager }: AlertManagerManualRo error: errorInContactPointStatus, contactPoints, refetchReceivers, - } = useContactPointsWithStatus({ includePoliciesCount: false }); + } = useContactPointsWithStatus({ includePoliciesCount: false, receiverStatusPollingInterval: 0 }); const [selectedContactPointWithMetadata, setSelectedContactPointWithMetadata] = useState< ContactPointWithMetadata | undefined >();