diff --git a/public/app/features/alerting/unified/api/alertmanager.ts b/public/app/features/alerting/unified/api/alertmanager.ts index 27d080a6c4a..3d5bee320a4 100644 --- a/public/app/features/alerting/unified/api/alertmanager.ts +++ b/public/app/features/alerting/unified/api/alertmanager.ts @@ -11,8 +11,6 @@ import { ExternalAlertmanagersResponse, Matcher, Receiver, - Silence, - SilenceCreatePayload, TestReceiversAlert, TestReceiversPayload, TestReceiversResult, @@ -79,40 +77,6 @@ export async function deleteAlertManagerConfig(alertManagerSourceName: string): ); } -export async function fetchSilences(alertManagerSourceName: string): Promise { - const result = await lastValueFrom( - getBackendSrv().fetch({ - url: `/api/alertmanager/${getDatasourceAPIUid(alertManagerSourceName)}/api/v2/silences`, - showErrorAlert: false, - showSuccessAlert: false, - }) - ); - return result.data; -} - -// returns the new silence ID. Even in the case of an update, a new silence is created and the previous one expired. -export async function createOrUpdateSilence( - alertmanagerSourceName: string, - payload: SilenceCreatePayload -): Promise { - const result = await lastValueFrom( - getBackendSrv().fetch({ - url: `/api/alertmanager/${getDatasourceAPIUid(alertmanagerSourceName)}/api/v2/silences`, - data: payload, - showErrorAlert: false, - showSuccessAlert: false, - method: 'POST', - }) - ); - return result.data; -} - -export async function expireSilence(alertmanagerSourceName: string, silenceID: string): Promise { - await getBackendSrv().delete( - `/api/alertmanager/${getDatasourceAPIUid(alertmanagerSourceName)}/api/v2/silence/${encodeURIComponent(silenceID)}` - ); -} - export async function fetchAlerts( alertmanagerSourceName: string, matchers?: Matcher[], diff --git a/public/app/features/alerting/unified/state/actions.ts b/public/app/features/alerting/unified/state/actions.ts index caf8d9db0a0..d362b7282b9 100644 --- a/public/app/features/alerting/unified/state/actions.ts +++ b/public/app/features/alerting/unified/state/actions.ts @@ -4,15 +4,12 @@ import { isEmpty } from 'lodash'; import { locationService } from '@grafana/runtime'; import { logMeasurement } from '@grafana/runtime/src/utils/logging'; import { - AlertmanagerAlert, AlertManagerCortexConfig, AlertmanagerGroup, ExternalAlertmanagerConfig, ExternalAlertmanagersResponse, Matcher, Receiver, - Silence, - SilenceCreatePayload, TestReceiversAlert, } from 'app/plugins/datasource/alertmanager/types'; import { FolderDTO, NotifierDTO, StoreState, ThunkResult } from 'app/types'; @@ -45,14 +42,10 @@ import { } from '../Analytics'; import { addAlertManagers, - createOrUpdateSilence, deleteAlertManagerConfig, - expireSilence, fetchAlertGroups, - fetchAlerts, fetchExternalAlertmanagerConfig, fetchExternalAlertmanagers, - fetchSilences, testReceivers, updateAlertManagerConfig, } from '../api/alertmanager'; @@ -204,17 +197,6 @@ export function fetchPromAndRulerRulesAction({ }; } -export const fetchSilencesAction = createAsyncThunk( - 'unifiedalerting/fetchSilences', - (alertManagerSourceName: string): Promise => { - const fetchSilencesWithLogging = withPerformanceLogging('unifiedalerting/fetchSilences', fetchSilences, { - dataSourceName: alertManagerSourceName, - }); - - return withSerializedError(fetchSilencesWithLogging(alertManagerSourceName)); - } -); - // this will only trigger ruler rules fetch if rules are not loaded yet and request is not in flight export function fetchRulerRulesIfNotFetchedYet(rulesSourceName: string): ThunkResult { return (dispatch, getStore) => { @@ -561,47 +543,6 @@ export const updateAlertManagerConfigAction = createAsyncThunk => - withSerializedError(fetchAlerts(alertManagerSourceName, [], true, true, true)) -); - -export const expireSilenceAction = (alertManagerSourceName: string, silenceId: string): ThunkResult => { - return async (dispatch) => { - await withAppEvents(expireSilence(alertManagerSourceName, silenceId), { - successMessage: 'Silence expired.', - }); - dispatch(fetchSilencesAction(alertManagerSourceName)); - dispatch(fetchAmAlertsAction(alertManagerSourceName)); - }; -}; - -type UpdateSilenceActionOptions = { - alertManagerSourceName: string; - payload: SilenceCreatePayload; - exitOnSave: boolean; - successMessage?: string; -}; - -export const createOrUpdateSilenceAction = createAsyncThunk( - 'unifiedalerting/updateSilence', - ({ alertManagerSourceName, payload, exitOnSave, successMessage }): Promise => - withAppEvents( - withSerializedError( - (async () => { - await createOrUpdateSilence(alertManagerSourceName, payload); - if (exitOnSave) { - locationService.push(makeAMLink('/alerting/silences', alertManagerSourceName)); - } - })() - ), - { - successMessage, - } - ) -); - export const deleteReceiverAction = (receiverName: string, alertManagerSourceName: string): ThunkResult => { return async (dispatch) => { const config = await dispatch( diff --git a/public/app/features/alerting/unified/state/reducers.ts b/public/app/features/alerting/unified/state/reducers.ts index c6e2c1c531b..8783f479877 100644 --- a/public/app/features/alerting/unified/state/reducers.ts +++ b/public/app/features/alerting/unified/state/reducers.ts @@ -3,10 +3,8 @@ import { combineReducers } from 'redux'; import { createAsyncMapSlice, createAsyncSlice } from '../utils/redux'; import { - createOrUpdateSilenceAction, deleteAlertManagerConfigAction, fetchAlertGroupsAction, - fetchAmAlertsAction, fetchEditableRuleAction, fetchExternalAlertmanagersAction, fetchExternalAlertmanagersConfigAction, @@ -16,7 +14,6 @@ import { fetchPromRulesAction, fetchRulerRulesAction, fetchRulesSourceBuildInfoAction, - fetchSilencesAction, saveRuleFormAction, testReceiversAction, updateAlertManagerConfigAction, @@ -32,8 +29,6 @@ export const reducer = combineReducers({ promRules: createAsyncMapSlice('promRules', fetchPromRulesAction, ({ rulesSourceName }) => rulesSourceName).reducer, rulerRules: createAsyncMapSlice('rulerRules', fetchRulerRulesAction, ({ rulesSourceName }) => rulesSourceName) .reducer, - silences: createAsyncMapSlice('silences', fetchSilencesAction, (alertManagerSourceName) => alertManagerSourceName) - .reducer, ruleForm: combineReducers({ saveRule: createAsyncSlice('saveRule', saveRuleFormAction).reducer, existingRule: createAsyncSlice('existingRule', fetchEditableRuleAction).reducer, @@ -41,9 +36,6 @@ export const reducer = combineReducers({ grafanaNotifiers: createAsyncSlice('grafanaNotifiers', fetchGrafanaNotifiersAction).reducer, saveAMConfig: createAsyncSlice('saveAMConfig', updateAlertManagerConfigAction).reducer, deleteAMConfig: createAsyncSlice('deleteAMConfig', deleteAlertManagerConfigAction).reducer, - updateSilence: createAsyncSlice('updateSilence', createOrUpdateSilenceAction).reducer, - amAlerts: createAsyncMapSlice('amAlerts', fetchAmAlertsAction, (alertManagerSourceName) => alertManagerSourceName) - .reducer, folders: createAsyncMapSlice('folders', fetchFolderAction, (uid) => uid).reducer, amAlertGroups: createAsyncMapSlice( 'amAlertGroups',