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

This commit is contained in:
Gilles De Mey
2023-11-06 15:51:36 +01:00
committed by GitHub
parent 901a6bfa69
commit e61ebd4b06
3 changed files with 19 additions and 6 deletions
@@ -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 {