Remove unused actions/reducers

This commit is contained in:
Tom Ratcliffe 2024-04-25 16:36:45 +01:00 committed by Tom Ratcliffe
parent a1d2a9670b
commit 341449f4f5
3 changed files with 0 additions and 103 deletions

View File

@ -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<Silence[]> {
const result = await lastValueFrom(
getBackendSrv().fetch<Silence[]>({
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<Silence> {
const result = await lastValueFrom(
getBackendSrv().fetch<Silence>({
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<void> {
await getBackendSrv().delete(
`/api/alertmanager/${getDatasourceAPIUid(alertmanagerSourceName)}/api/v2/silence/${encodeURIComponent(silenceID)}`
);
}
export async function fetchAlerts(
alertmanagerSourceName: string,
matchers?: Matcher[],

View File

@ -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<Silence[]> => {
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<void> {
return (dispatch, getStore) => {
@ -561,47 +543,6 @@ export const updateAlertManagerConfigAction = createAsyncThunk<void, UpdateAlert
)
);
export const fetchAmAlertsAction = createAsyncThunk(
'unifiedalerting/fetchAmAlerts',
(alertManagerSourceName: string): Promise<AlertmanagerAlert[]> =>
withSerializedError(fetchAlerts(alertManagerSourceName, [], true, true, true))
);
export const expireSilenceAction = (alertManagerSourceName: string, silenceId: string): ThunkResult<void> => {
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<void, UpdateSilenceActionOptions, {}>(
'unifiedalerting/updateSilence',
({ alertManagerSourceName, payload, exitOnSave, successMessage }): Promise<void> =>
withAppEvents(
withSerializedError(
(async () => {
await createOrUpdateSilence(alertManagerSourceName, payload);
if (exitOnSave) {
locationService.push(makeAMLink('/alerting/silences', alertManagerSourceName));
}
})()
),
{
successMessage,
}
)
);
export const deleteReceiverAction = (receiverName: string, alertManagerSourceName: string): ThunkResult<void> => {
return async (dispatch) => {
const config = await dispatch(

View File

@ -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',