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, ExternalAlertmanagersResponse,
Matcher, Matcher,
Receiver, Receiver,
Silence,
SilenceCreatePayload,
TestReceiversAlert, TestReceiversAlert,
TestReceiversPayload, TestReceiversPayload,
TestReceiversResult, 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( export async function fetchAlerts(
alertmanagerSourceName: string, alertmanagerSourceName: string,
matchers?: Matcher[], matchers?: Matcher[],

View File

@ -4,15 +4,12 @@ import { isEmpty } from 'lodash';
import { locationService } from '@grafana/runtime'; import { locationService } from '@grafana/runtime';
import { logMeasurement } from '@grafana/runtime/src/utils/logging'; import { logMeasurement } from '@grafana/runtime/src/utils/logging';
import { import {
AlertmanagerAlert,
AlertManagerCortexConfig, AlertManagerCortexConfig,
AlertmanagerGroup, AlertmanagerGroup,
ExternalAlertmanagerConfig, ExternalAlertmanagerConfig,
ExternalAlertmanagersResponse, ExternalAlertmanagersResponse,
Matcher, Matcher,
Receiver, Receiver,
Silence,
SilenceCreatePayload,
TestReceiversAlert, TestReceiversAlert,
} from 'app/plugins/datasource/alertmanager/types'; } from 'app/plugins/datasource/alertmanager/types';
import { FolderDTO, NotifierDTO, StoreState, ThunkResult } from 'app/types'; import { FolderDTO, NotifierDTO, StoreState, ThunkResult } from 'app/types';
@ -45,14 +42,10 @@ import {
} from '../Analytics'; } from '../Analytics';
import { import {
addAlertManagers, addAlertManagers,
createOrUpdateSilence,
deleteAlertManagerConfig, deleteAlertManagerConfig,
expireSilence,
fetchAlertGroups, fetchAlertGroups,
fetchAlerts,
fetchExternalAlertmanagerConfig, fetchExternalAlertmanagerConfig,
fetchExternalAlertmanagers, fetchExternalAlertmanagers,
fetchSilences,
testReceivers, testReceivers,
updateAlertManagerConfig, updateAlertManagerConfig,
} from '../api/alertmanager'; } 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 // 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> { export function fetchRulerRulesIfNotFetchedYet(rulesSourceName: string): ThunkResult<void> {
return (dispatch, getStore) => { 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> => { export const deleteReceiverAction = (receiverName: string, alertManagerSourceName: string): ThunkResult<void> => {
return async (dispatch) => { return async (dispatch) => {
const config = await dispatch( const config = await dispatch(

View File

@ -3,10 +3,8 @@ import { combineReducers } from 'redux';
import { createAsyncMapSlice, createAsyncSlice } from '../utils/redux'; import { createAsyncMapSlice, createAsyncSlice } from '../utils/redux';
import { import {
createOrUpdateSilenceAction,
deleteAlertManagerConfigAction, deleteAlertManagerConfigAction,
fetchAlertGroupsAction, fetchAlertGroupsAction,
fetchAmAlertsAction,
fetchEditableRuleAction, fetchEditableRuleAction,
fetchExternalAlertmanagersAction, fetchExternalAlertmanagersAction,
fetchExternalAlertmanagersConfigAction, fetchExternalAlertmanagersConfigAction,
@ -16,7 +14,6 @@ import {
fetchPromRulesAction, fetchPromRulesAction,
fetchRulerRulesAction, fetchRulerRulesAction,
fetchRulesSourceBuildInfoAction, fetchRulesSourceBuildInfoAction,
fetchSilencesAction,
saveRuleFormAction, saveRuleFormAction,
testReceiversAction, testReceiversAction,
updateAlertManagerConfigAction, updateAlertManagerConfigAction,
@ -32,8 +29,6 @@ export const reducer = combineReducers({
promRules: createAsyncMapSlice('promRules', fetchPromRulesAction, ({ rulesSourceName }) => rulesSourceName).reducer, promRules: createAsyncMapSlice('promRules', fetchPromRulesAction, ({ rulesSourceName }) => rulesSourceName).reducer,
rulerRules: createAsyncMapSlice('rulerRules', fetchRulerRulesAction, ({ rulesSourceName }) => rulesSourceName) rulerRules: createAsyncMapSlice('rulerRules', fetchRulerRulesAction, ({ rulesSourceName }) => rulesSourceName)
.reducer, .reducer,
silences: createAsyncMapSlice('silences', fetchSilencesAction, (alertManagerSourceName) => alertManagerSourceName)
.reducer,
ruleForm: combineReducers({ ruleForm: combineReducers({
saveRule: createAsyncSlice('saveRule', saveRuleFormAction).reducer, saveRule: createAsyncSlice('saveRule', saveRuleFormAction).reducer,
existingRule: createAsyncSlice('existingRule', fetchEditableRuleAction).reducer, existingRule: createAsyncSlice('existingRule', fetchEditableRuleAction).reducer,
@ -41,9 +36,6 @@ export const reducer = combineReducers({
grafanaNotifiers: createAsyncSlice('grafanaNotifiers', fetchGrafanaNotifiersAction).reducer, grafanaNotifiers: createAsyncSlice('grafanaNotifiers', fetchGrafanaNotifiersAction).reducer,
saveAMConfig: createAsyncSlice('saveAMConfig', updateAlertManagerConfigAction).reducer, saveAMConfig: createAsyncSlice('saveAMConfig', updateAlertManagerConfigAction).reducer,
deleteAMConfig: createAsyncSlice('deleteAMConfig', deleteAlertManagerConfigAction).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, folders: createAsyncMapSlice('folders', fetchFolderAction, (uid) => uid).reducer,
amAlertGroups: createAsyncMapSlice( amAlertGroups: createAsyncMapSlice(
'amAlertGroups', 'amAlertGroups',