From e61ebd4b0623537e97ab90c4ff8a4923e9966aa8 Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Mon, 6 Nov 2023 15:51:36 +0100 Subject: [PATCH] Alerting: Do not show missing integration while loading oncall plugin status (#77710) --- .../components/contact-points/useContactPoints.tsx | 14 +++++++++++--- .../unified/components/contact-points/utils.ts | 2 +- .../grafanaAppReceivers/useReceiversMetadata.ts | 9 +++++++-- 3 files changed, 19 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 555341a9f76..4b70e5d6e2f 100644 --- a/public/app/features/alerting/unified/components/contact-points/useContactPoints.tsx +++ b/public/app/features/alerting/unified/components/contact-points/useContactPoints.tsx @@ -7,7 +7,7 @@ import { produce } from 'immer'; import { remove } from 'lodash'; import { alertmanagerApi } from '../../api/alertmanagerApi'; -import { onCallApi } from '../../api/onCallApi'; +import { onCallApi, OnCallIntegrationDTO } from '../../api/onCallApi'; import { usePluginBridge } from '../../hooks/usePluginBridge'; import { useAlertmanager } from '../../state/AlertmanagerContext'; import { SupportedPlugin } from '../../types/pluginBridges'; @@ -29,7 +29,7 @@ const RECEIVER_STATUS_POLLING_INTERVAL = 10 * 1000; // 10 seconds */ export function useContactPointsWithStatus() { const { selectedAlertmanager, isGrafanaAlertmanager } = useAlertmanager(); - const { installed: onCallPluginInstalled = false, loading: onCallPluginStatusLoading } = usePluginBridge( + const { installed: onCallPluginInstalled, loading: onCallPluginStatusLoading } = usePluginBridge( SupportedPlugin.OnCall ); @@ -55,6 +55,14 @@ export function useContactPointsWithStatus() { skip: !onCallPluginInstalled || !isGrafanaAlertmanager, }); + // null = no installed, undefined = loading, [n] is installed with integrations + let onCallMetadata: null | undefined | OnCallIntegrationDTO[] = undefined; + if (onCallPluginInstalled) { + onCallMetadata = onCallIntegrations ?? []; + } else if (onCallPluginInstalled === false) { + onCallMetadata = null; + } + // fetch the latest config from the Alertmanager const fetchAlertmanagerConfiguration = alertmanagerApi.endpoints.getAlertmanagerConfiguration.useQuery( selectedAlertmanager!, @@ -68,7 +76,7 @@ export function useContactPointsWithStatus() { result.data, fetchContactPointsStatus.data, fetchReceiverMetadata.data, - onCallPluginInstalled ? onCallIntegrations ?? [] : null + onCallMetadata ) : [], }), diff --git a/public/app/features/alerting/unified/components/contact-points/utils.ts b/public/app/features/alerting/unified/components/contact-points/utils.ts index 414d7bbc00c..79a71733fb7 100644 --- a/public/app/features/alerting/unified/components/contact-points/utils.ts +++ b/public/app/features/alerting/unified/components/contact-points/utils.ts @@ -96,7 +96,7 @@ export function enhanceContactPointsWithMetadata( result: AlertManagerCortexConfig, status: ReceiversStateDTO[] = [], notifiers: NotifierDTO[] = [], - onCallIntegrations: OnCallIntegrationDTO[] | null + onCallIntegrations: OnCallIntegrationDTO[] | undefined | null ): ContactPointWithMetadata[] { const contactPoints = result.alertmanager_config.receivers ?? []; diff --git a/public/app/features/alerting/unified/components/receivers/grafanaAppReceivers/useReceiversMetadata.ts b/public/app/features/alerting/unified/components/receivers/grafanaAppReceivers/useReceiversMetadata.ts index 8f00947029e..13a85df9d6c 100644 --- a/public/app/features/alerting/unified/components/receivers/grafanaAppReceivers/useReceiversMetadata.ts +++ b/public/app/features/alerting/unified/components/receivers/grafanaAppReceivers/useReceiversMetadata.ts @@ -48,13 +48,18 @@ export const useReceiversMetadata = (receivers: Receiver[]): Map