Alerting: Do not show missing integration while loading oncall plugin status (#77710)

pull/77543/head
Gilles De Mey 2 years ago committed by GitHub
parent 901a6bfa69
commit e61ebd4b06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      public/app/features/alerting/unified/components/contact-points/useContactPoints.tsx
  2. 2
      public/app/features/alerting/unified/components/contact-points/utils.ts
  3. 9
      public/app/features/alerting/unified/components/receivers/grafanaAppReceivers/useReceiversMetadata.ts

@ -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
)
: [],
}),

@ -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 ?? [];

@ -48,13 +48,18 @@ export const useReceiversMetadata = (receivers: Receiver[]): Map<Receiver, Recei
});
return result;
}, [isOnCallEnabled, receivers, onCallIntegrations]);
}, [receivers, isOnCallEnabled, onCallIntegrations]);
};
export function getOnCallMetadata(
onCallIntegrations: OnCallIntegrationDTO[] | null,
onCallIntegrations: OnCallIntegrationDTO[] | undefined | null,
receiver: GrafanaManagedReceiverConfig
): ReceiverPluginMetadata {
// oncall status is still loading
if (onCallIntegrations === undefined) {
return onCallReceiverMeta;
}
// indication that onCall is not enabled
if (onCallIntegrations == null) {
return {

Loading…
Cancel
Save