Alerting: Tidy up some leftover logic from pre-alertingApiServer (#104776)

pull/103450/head^2
Tom Ratcliffe 2 months ago committed by GitHub
parent a7fe77cdbf
commit 67214c0a56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 100
      public/app/features/alerting/unified/RuleList.test.tsx
  2. 12
      public/app/features/alerting/unified/api/alertmanagerApi.ts
  3. 4
      public/app/features/alerting/unified/components/alertmanager-entities/MuteTimingsSelector.tsx
  4. 65
      public/app/features/alerting/unified/components/contact-points/useContactPoints.ts
  5. 21
      public/app/features/alerting/unified/components/mute-timings/useMuteTimings.tsx
  6. 4
      public/app/features/alerting/unified/components/receivers/form/GrafanaReceiverForm.tsx
  7. 18
      public/app/features/alerting/unified/mockApi.ts
  8. 2
      public/app/features/alerting/unified/mocks/server/all-handlers.ts
  9. 22
      public/app/features/alerting/unified/mocks/server/handlers/notifications.ts

@ -1,6 +1,4 @@
import { SerializedError } from '@reduxjs/toolkit';
import userEvent from '@testing-library/user-event';
import { SetupServer } from 'msw/node';
import { TestProvider } from 'test/helpers/TestProvider';
import { render, screen, waitFor, within } from 'test/test-utils';
import { byRole, byTestId, byText } from 'testing-library-selector';
@ -9,11 +7,10 @@ import { PluginExtensionTypes } from '@grafana/data';
import { selectors } from '@grafana/e2e-selectors';
import { locationService, setAppEvents, usePluginLinks } from '@grafana/runtime';
import appEvents from 'app/core/app_events';
import { mockUserApi, setupMswServer } from 'app/features/alerting/unified/mockApi';
import { setupMswServer } from 'app/features/alerting/unified/mockApi';
import { setAlertmanagerChoices } from 'app/features/alerting/unified/mocks/server/configure';
import * as actions from 'app/features/alerting/unified/state/actions';
import { setupDataSources } from 'app/features/alerting/unified/testSetup/datasources';
import { getMockUser } from 'app/features/users/__mocks__/userMocks';
import { AlertmanagerChoice } from 'app/plugins/datasource/alertmanager/types';
import { AccessControlAction } from 'app/types';
import { PromAlertingRuleState, PromApplication } from 'app/types/unified-alerting-dto';
@ -134,16 +131,11 @@ const ui = {
},
};
const server = setupMswServer();
const configureMockServer = (server: SetupServer) => {
mockUserApi(server).user(getMockUser());
setAlertmanagerChoices(AlertmanagerChoice.All, 1);
};
setupMswServer();
describe('RuleList', () => {
beforeEach(() => {
configureMockServer(server);
setAlertmanagerChoices(AlertmanagerChoice.All, 1);
grantUserPermissions([
AccessControlAction.AlertingRuleRead,
AccessControlAction.AlertingRuleUpdate,
@ -242,7 +234,7 @@ describe('RuleList', () => {
mocks.api.fetchRulerRules.mockRejectedValue({ status: 500, data: { message: 'Server error' } });
await renderRuleList();
const { user } = await renderRuleList();
await waitFor(() => expect(mocks.api.fetchRules).toHaveBeenCalledTimes(4));
const groups = await ui.ruleGroup.findAll();
@ -259,7 +251,7 @@ describe('RuleList', () => {
expect(errors).not.toHaveTextContent(
'Failed to load rules state from Prometheus-broken: this datasource is broken'
);
await userEvent.click(ui.moreErrorsButton.get());
await user.click(ui.moreErrorsButton.get());
expect(errors).toHaveTextContent('Failed to load rules state from Prometheus-broken: this datasource is broken');
});
@ -338,7 +330,7 @@ describe('RuleList', () => {
}
});
await renderRuleList();
const { user } = await renderRuleList();
const groups = await ui.ruleGroup.findAll();
expect(groups).toHaveLength(2);
@ -354,7 +346,7 @@ describe('RuleList', () => {
// expand second group to see rules table
expect(ui.rulesTable.query()).not.toBeInTheDocument();
await userEvent.click(ui.groupCollapseToggle.get(groups[1]));
await user.click(ui.groupCollapseToggle.get(groups[1]));
const table = await ui.rulesTable.find(groups[1]);
// check that rule rows are rendered properly
@ -376,7 +368,7 @@ describe('RuleList', () => {
expect(byText('Labels').query()).not.toBeInTheDocument();
// expand alert details
await userEvent.click(ui.ruleCollapseToggle.get(ruleRows[1]));
await user.click(ui.ruleCollapseToggle.get(ruleRows[1]));
const ruleDetails = ui.expandedContent.get(ruleRows[1]);
const labels = byTestId('label-value').getAll(ruleDetails);
@ -397,17 +389,17 @@ describe('RuleList', () => {
expect(instanceRows![1]).toHaveTextContent('Firingfoobazseverityerror2021-03-18 08:47:05');
// expand details of an instance
await userEvent.click(ui.ruleCollapseToggle.get(instanceRows![0]));
await user.click(ui.ruleCollapseToggle.get(instanceRows![0]));
const alertDetails = byTestId(selectors.components.AlertRules.expandedContent).get(instanceRows[0]);
expect(alertDetails).toHaveTextContent('Value2e+10');
expect(alertDetails).toHaveTextContent('messagefirst alert message');
// collapse everything again
await userEvent.click(ui.ruleCollapseToggle.get(instanceRows![0]));
await user.click(ui.ruleCollapseToggle.get(instanceRows![0]));
expect(byTestId(selectors.components.AlertRules.expandedContent).query(instanceRows[0])).not.toBeInTheDocument();
await userEvent.click(ui.ruleCollapseToggle.getAll(ruleRows[1])[0]);
await userEvent.click(ui.groupCollapseToggle.get(groups[1]));
await user.click(ui.ruleCollapseToggle.getAll(ruleRows[1])[0]);
await user.click(ui.groupCollapseToggle.get(groups[1]));
expect(ui.rulesTable.query()).not.toBeInTheDocument();
});
@ -511,49 +503,49 @@ describe('RuleList', () => {
}
});
await renderRuleList();
const { user } = await renderRuleList();
const groups = await ui.ruleGroup.findAll();
expect(groups).toHaveLength(2);
const filterInput = ui.rulesFilterInput.get();
await userEvent.type(filterInput, 'label:foo=bar{Enter}');
await user.type(filterInput, 'label:foo=bar{Enter}');
// Input is debounced so wait for it to be visible
await waitFor(() => expect(filterInput).toHaveValue('label:foo=bar'));
// Group doesn't contain matching labels
await waitFor(() => expect(ui.ruleGroup.queryAll()).toHaveLength(1));
await userEvent.click(ui.groupCollapseToggle.get(groups[0]));
await user.click(ui.groupCollapseToggle.get(groups[0]));
const ruleRows = ui.ruleRow.getAll(groups[0]);
expect(ruleRows).toHaveLength(1);
await userEvent.click(ui.ruleCollapseToggle.get(ruleRows[0]));
await user.click(ui.ruleCollapseToggle.get(ruleRows[0]));
const ruleDetails = ui.expandedContent.get(ruleRows[0]);
const labels = byTestId('label-value').getAll(ruleDetails);
expect(labels[0]).toHaveTextContent('severitywarning');
expect(labels[1]).toHaveTextContent('foobar');
// Check for different label matchers
await userEvent.clear(filterInput);
await userEvent.type(filterInput, 'label:foo!=bar label:foo!=baz{Enter}');
await user.clear(filterInput);
await user.type(filterInput, 'label:foo!=bar label:foo!=baz{Enter}');
// Group doesn't contain matching labels
await waitFor(() => expect(ui.ruleGroup.queryAll()).toHaveLength(1));
await waitFor(() => expect(ui.ruleGroup.get()).toHaveTextContent('group-2'));
await userEvent.clear(filterInput);
await userEvent.type(filterInput, 'label:"foo=~b.+"{Enter}');
await user.clear(filterInput);
await user.type(filterInput, 'label:"foo=~b.+"{Enter}');
await waitFor(() => expect(ui.ruleGroup.queryAll()).toHaveLength(2));
await userEvent.clear(filterInput);
await userEvent.type(filterInput, 'label:region=US{Enter}');
await user.clear(filterInput);
await user.type(filterInput, 'label:region=US{Enter}');
await waitFor(() => expect(ui.ruleGroup.queryAll()).toHaveLength(1));
await waitFor(() => expect(ui.ruleGroup.get()).toHaveTextContent('group-2'));
});
it.skip('uses entire group when reordering after filtering', async () => {
const user = userEvent.setup();
const { user } = await renderRuleList();
mocks.api.discoverFeaturesByUid.mockResolvedValue({
application: PromApplication.Cortex,
@ -591,7 +583,7 @@ describe('RuleList', () => {
const [firstReorderButton] = await screen.findAllByLabelText(/reorder/i);
const filterInput = ui.rulesFilterInput.get();
await userEvent.type(filterInput, 'alert1a{Enter}');
await user.type(filterInput, 'alert1a{Enter}');
await user.click(firstReorderButton);
@ -627,9 +619,7 @@ describe('RuleList', () => {
});
test('resuming paused alert rule', async () => {
const user = userEvent.setup();
renderRuleList();
const { user } = await renderRuleList();
// Expand the paused rule group so we can assert the rule state
await user.click(await ui.pausedRuleGroup.find());
@ -675,7 +665,7 @@ describe('RuleList', () => {
Promise.resolve(dataSourceName === testDatasources.prom.name ? someRulerRules : {})
);
await renderRuleList();
const { user } = await renderRuleList();
expect(await ui.rulesFilterInput.find()).toHaveValue('');
@ -685,7 +675,7 @@ describe('RuleList', () => {
expect(groups).toHaveLength(3);
// open edit dialog
await userEvent.click(ui.editCloudGroupIcon.get(groups[0]));
await user.click(ui.editCloudGroupIcon.get(groups[0]));
await waitFor(() => expect(ui.editGroupModal.dialog.get()).toBeInTheDocument());
@ -696,18 +686,20 @@ describe('RuleList', () => {
}
testCase('rename both lotex namespace and group', async () => {
const { user } = await renderRuleList();
// make changes to form
await userEvent.clear(ui.editGroupModal.namespaceInput.get());
await userEvent.type(ui.editGroupModal.namespaceInput.get(), 'super namespace');
await user.clear(ui.editGroupModal.namespaceInput.get());
await user.type(ui.editGroupModal.namespaceInput.get(), 'super namespace');
await userEvent.clear(ui.editGroupModal.ruleGroupInput.get());
await userEvent.type(ui.editGroupModal.ruleGroupInput.get(), 'super group');
await user.clear(ui.editGroupModal.ruleGroupInput.get());
await user.type(ui.editGroupModal.ruleGroupInput.get(), 'super group');
await userEvent.clear(ui.editGroupModal.intervalInput.get());
await userEvent.type(ui.editGroupModal.intervalInput.get(), '5m');
await user.clear(ui.editGroupModal.intervalInput.get());
await user.type(ui.editGroupModal.intervalInput.get(), '5m');
// submit, check that appropriate calls were made
await userEvent.click(ui.editGroupModal.saveButton.get());
await user.click(ui.editGroupModal.saveButton.get());
await waitFor(() => expect(ui.editGroupModal.namespaceInput.query()).not.toBeInTheDocument());
@ -715,15 +707,17 @@ describe('RuleList', () => {
});
testCase('rename just the lotex group', async () => {
const { user } = await renderRuleList();
// make changes to form
await userEvent.clear(ui.editGroupModal.ruleGroupInput.get());
await userEvent.type(ui.editGroupModal.ruleGroupInput.get(), 'super group');
await user.clear(ui.editGroupModal.ruleGroupInput.get());
await user.type(ui.editGroupModal.ruleGroupInput.get(), 'super group');
await userEvent.clear(ui.editGroupModal.intervalInput.get());
await userEvent.type(ui.editGroupModal.intervalInput.get(), '5m');
await user.clear(ui.editGroupModal.intervalInput.get());
await user.type(ui.editGroupModal.intervalInput.get(), '5m');
// submit, check that appropriate calls were made
await userEvent.click(ui.editGroupModal.saveButton.get());
await user.click(ui.editGroupModal.saveButton.get());
await waitFor(() => expect(ui.editGroupModal.namespaceInput.query()).not.toBeInTheDocument());
@ -731,12 +725,14 @@ describe('RuleList', () => {
});
testCase('edit lotex group eval interval, no renaming', async () => {
const { user } = await renderRuleList();
// make changes to form
await userEvent.clear(ui.editGroupModal.intervalInput.get());
await userEvent.type(ui.editGroupModal.intervalInput.get(), '5m');
await user.clear(ui.editGroupModal.intervalInput.get());
await user.type(ui.editGroupModal.intervalInput.get(), '5m');
// submit, check that appropriate calls were made
await userEvent.click(ui.editGroupModal.saveButton.get());
await user.click(ui.editGroupModal.saveButton.get());
await waitFor(() => expect(ui.editGroupModal.namespaceInput.query()).not.toBeInTheDocument());

@ -12,9 +12,7 @@ import {
ExternalAlertmanagersConnectionStatus,
ExternalAlertmanagersStatusResponse,
GrafanaAlertingConfiguration,
GrafanaManagedContactPoint,
Matcher,
MuteTimeInterval,
} from '../../../../plugins/datasource/alertmanager/types';
import { NotifierDTO } from '../../../../types';
import { withPerformanceLogging } from '../Analytics';
@ -293,15 +291,5 @@ export const alertmanagerApi = alertingApi.injectEndpoints({
},
providesTags: ['ContactPointsStatus'],
}),
// Grafana Managed Alertmanager only
// TODO: Remove as part of migration to k8s API for receivers
getContactPointsList: build.query<GrafanaManagedContactPoint[], void>({
query: () => ({ url: '/api/v1/notifications/receivers' }),
providesTags: ['ContactPoint'],
}),
getMuteTimingList: build.query<MuteTimeInterval[], void>({
query: () => ({ url: '/api/v1/notifications/time-intervals' }),
providesTags: ['AlertmanagerConfiguration'],
}),
}),
});

@ -1,7 +1,7 @@
import { SelectableValue } from '@grafana/data';
import { MultiSelect, MultiSelectCommonProps } from '@grafana/ui';
import { t } from 'app/core/internationalization';
import { useSelectableMuteTimings } from 'app/features/alerting/unified/components/mute-timings/useMuteTimings';
import { useMuteTimings } from 'app/features/alerting/unified/components/mute-timings/useMuteTimings';
import { BaseAlertmanagerArgs } from 'app/features/alerting/unified/types/hooks';
import { timeIntervalToString } from 'app/features/alerting/unified/utils/alertmanager';
import { MuteTimeInterval } from 'app/plugins/datasource/alertmanager/types';
@ -17,7 +17,7 @@ const MuteTimingsSelector = ({
alertmanager,
selectProps,
}: BaseAlertmanagerArgs & { selectProps: MultiSelectCommonProps<string> }) => {
const { data } = useSelectableMuteTimings({ alertmanager, skip: selectProps.disabled });
const { data } = useMuteTimings({ alertmanager, skip: selectProps.disabled });
const muteTimingOptions = data?.map((value) => mapMuteTiming(value)) || [];

@ -37,7 +37,6 @@ const RECEIVER_STATUS_POLLING_INTERVAL = 10 * 1000; // 10 seconds
const {
useGetAlertmanagerConfigurationQuery,
useGetContactPointsListQuery,
useGetContactPointsStatusQuery,
useGrafanaNotifiersQuery,
useLazyGetAlertmanagerConfigurationQuery,
@ -104,33 +103,6 @@ const useK8sContactPoints = (...[hookParams, queryOptions]: Parameters<typeof us
});
};
/**
* Fetch contact points for Grafana Alertmanager, either from the k8s API,
* or the `/notifications/receivers` endpoint
*/
const useFetchGrafanaContactPoints = ({ skip }: Skippable = {}) => {
const namespace = getAPINamespace();
const useK8sApi = shouldUseK8sApi(GRAFANA_RULES_SOURCE_NAME);
const grafanaResponse = useGetContactPointsListQuery(undefined, {
skip: skip || useK8sApi,
selectFromResult: (result) => {
const data = result.data?.map((item) => ({
...item,
provisioned: item.grafana_managed_receiver_configs?.some((item) => item.provenance),
}));
return {
...result,
data,
currentData: data,
};
},
});
const k8sResponse = useK8sContactPoints({ namespace }, { skip: skip || !useK8sApi });
return useK8sApi ? k8sResponse : grafanaResponse;
};
type GrafanaFetchOptions = {
/**
* Should we fetch and include status information about each contact point?
@ -152,10 +124,11 @@ export const useGrafanaContactPoints = ({
fetchPolicies,
skip,
}: GrafanaFetchOptions & Skippable = {}) => {
const namespace = getAPINamespace();
const potentiallySkip = { skip };
const onCallResponse = useOnCallIntegrations(potentiallySkip);
const alertNotifiers = useGrafanaNotifiersQuery(undefined, potentiallySkip);
const contactPointsListResponse = useFetchGrafanaContactPoints(potentiallySkip);
const contactPointsListResponse = useK8sContactPoints({ namespace }, potentiallySkip);
const contactPointsStatusResponse = useGetContactPointsStatusQuery(undefined, {
...defaultOptions,
@ -232,9 +205,8 @@ const useGetGrafanaContactPoint = (
queryOptions?: Parameters<typeof useReadNamespacedReceiverQuery>[1]
) => {
const namespace = getAPINamespace();
const useK8sApi = shouldUseK8sApi(GRAFANA_RULES_SOURCE_NAME);
const k8sResponse = useReadNamespacedReceiverQuery(
return useReadNamespacedReceiverQuery(
{ namespace, name },
{
...queryOptions,
@ -246,16 +218,9 @@ const useGetGrafanaContactPoint = (
currentData: data,
};
},
skip: queryOptions?.skip || !useK8sApi,
skip: queryOptions?.skip,
}
);
const grafanaResponse = useGetAlertmanagerContactPoint(
{ alertmanager: GRAFANA_RULES_SOURCE_NAME, name },
{ skip: queryOptions?.skip || useK8sApi }
);
return useK8sApi ? k8sResponse : grafanaResponse;
};
export const useGetContactPoint = ({ alertmanager, name }: { alertmanager: string; name: string }) => {
@ -347,16 +312,13 @@ type CreateContactPointArgs = ContactPointOperationArgs;
export const useCreateContactPoint = ({ alertmanager }: BaseAlertmanagerArgs) => {
const isGrafanaAlertmanager = alertmanager === GRAFANA_RULES_SOURCE_NAME;
const useK8sApi = shouldUseK8sApi(alertmanager);
const { createOnCallIntegrations } = useOnCallIntegration();
const [createGrafanaContactPoint] = useCreateNamespacedReceiverMutation();
const [produceNewAlertmanagerConfiguration] = useProduceNewAlertmanagerConfiguration();
const updateK8sAPI = useAsync(async ({ contactPoint }: CreateContactPointArgs) => {
const contactPointWithMaybeOnCall = isGrafanaAlertmanager
? await createOnCallIntegrations(contactPoint)
: contactPoint;
const contactPointWithMaybeOnCall = await createOnCallIntegrations(contactPoint);
const namespace = getAPINamespace();
const contactPointToUse = grafanaContactPointToK8sReceiver(contactPointWithMaybeOnCall);
@ -368,15 +330,11 @@ export const useCreateContactPoint = ({ alertmanager }: BaseAlertmanagerArgs) =>
});
const updateAlertmanagerConfiguration = useAsync(async ({ contactPoint }: CreateContactPointArgs) => {
const contactPointWithMaybeOnCall = isGrafanaAlertmanager
? await createOnCallIntegrations(contactPoint)
: contactPoint;
const action = addReceiverAction(contactPointWithMaybeOnCall);
const action = addReceiverAction(contactPoint);
return produceNewAlertmanagerConfiguration(action);
});
return useK8sApi ? updateK8sAPI : updateAlertmanagerConfiguration;
return isGrafanaAlertmanager ? updateK8sAPI : updateAlertmanagerConfiguration;
};
type UpdateContactPointArgsK8s = ContactPointOperationArgs & {
@ -429,13 +387,12 @@ export const useUpdateContactPoint = ({ alertmanager }: BaseAlertmanagerArgs) =>
};
export const useValidateContactPoint = ({ alertmanager }: BaseAlertmanagerArgs) => {
const useK8sApi = shouldUseK8sApi(alertmanager);
const [getConfig] = useLazyGetAlertmanagerConfigurationQuery();
// If we're using the kubernetes API, then we let the API response handle the validation instead
// as we don't expect to be able to fetch the intervals via the AM config
if (useK8sApi) {
// If we're updating the Grafana AM entities,
// then we let the API response handle the validation instead
// as we don't expect to be able to fetch the contact points via the AM config
if (alertmanager === GRAFANA_RULES_SOURCE_NAME) {
return () => undefined;
}

@ -8,7 +8,6 @@ import {
IoK8SApimachineryPkgApisMetaV1ObjectMeta,
} from 'app/features/alerting/unified/openapi/timeIntervalsApi.gen';
import { BaseAlertmanagerArgs, Skippable } from 'app/features/alerting/unified/types/hooks';
import { GRAFANA_RULES_SOURCE_NAME } from 'app/features/alerting/unified/utils/datasource';
import { PROVENANCE_NONE } from 'app/features/alerting/unified/utils/k8s/constants';
import {
encodeFieldSelector,
@ -26,7 +25,7 @@ import {
updateMuteTimingAction,
} from '../../reducers/alertmanager/muteTimings';
const { useLazyGetAlertmanagerConfigurationQuery, useGetMuteTimingListQuery } = alertmanagerApi;
const { useLazyGetAlertmanagerConfigurationQuery } = alertmanagerApi;
const {
useLazyListNamespacedTimeIntervalQuery,
useCreateNamespacedTimeIntervalMutation,
@ -304,21 +303,3 @@ export const useValidateMuteTiming = ({ alertmanager }: BaseAlertmanagerArgs) =>
});
};
};
/**
* @deprecated This will be deprecated by the K8S API.
* Once that is enabled by default, this method should be removed and `useMuteTimings` should always be used instead
*/
export const useSelectableMuteTimings = ({ alertmanager, skip }: BaseAlertmanagerArgs & Skippable) => {
const useK8sApi = shouldUseK8sApi(alertmanager);
const useDeprecatedEndpoint = alertmanager === GRAFANA_RULES_SOURCE_NAME && !useK8sApi;
/** Fetch from the (to be deprecated) specific endpoint for time-intervals */
const deprecatedMuteTimingsResponse = useGetMuteTimingListQuery(undefined, {
skip: skip || !useDeprecatedEndpoint,
});
const fetchMuteTimings = useMuteTimings({ alertmanager, skip: skip || useDeprecatedEndpoint });
return useDeprecatedEndpoint ? deprecatedMuteTimingsResponse : fetchMuteTimings;
};

@ -20,7 +20,6 @@ import { useDispatch } from 'app/types';
import { alertmanagerApi } from '../../../api/alertmanagerApi';
import { testReceiversAction } from '../../../state/actions';
import { GrafanaChannelValues, ReceiverFormValues } from '../../../types/receiver-form';
import { shouldUseK8sApi } from '../../../utils/k8s/utils';
import {
formChannelValuesToGrafanaChannelConfig,
formValuesToGrafanaReceiver,
@ -54,7 +53,6 @@ const { useGrafanaNotifiersQuery } = alertmanagerApi;
export const GrafanaReceiverForm = ({ contactPoint, readOnly = false, editMode }: Props) => {
const dispatch = useDispatch();
const useK8sAPI = shouldUseK8sApi(GRAFANA_RULES_SOURCE_NAME);
const [createContactPoint] = useCreateContactPoint({
alertmanager: GRAFANA_RULES_SOURCE_NAME,
});
@ -92,7 +90,7 @@ export const GrafanaReceiverForm = ({ contactPoint, readOnly = false, editMode }
try {
if (editMode) {
if (useK8sAPI && contactPoint && contactPoint.id) {
if (contactPoint && contactPoint.id) {
await updateContactPoint.execute({
contactPoint: newReceiver,
id: contactPoint.id,

@ -8,7 +8,7 @@ import {
setupAlertmanagerStatusMapDefaultState,
} from 'app/features/alerting/unified/mocks/server/entities/alertmanagers';
import { resetRoutingTreeMap } from 'app/features/alerting/unified/mocks/server/entities/k8s/routingtrees';
import { DashboardDTO, FolderDTO, OrgUser } from 'app/types';
import { DashboardDTO, FolderDTO } from 'app/types';
import {
PromRulesResponse,
RulerGrafanaRuleDTO,
@ -228,22 +228,6 @@ export function mockFolderApi(server: SetupServer) {
};
}
export function mockSearchApi(server: SetupServer) {
return {
search: (results: DashboardSearchItem[]) => {
server.use(http.get(`/api/search`, () => HttpResponse.json(results)));
},
};
}
export function mockUserApi(server: SetupServer) {
return {
user: (user: OrgUser) => {
server.use(http.get(`/api/user`, () => HttpResponse.json(user)));
},
};
}
export function mockDashboardApi(server: SetupServer) {
return {
search: (results: DashboardSearchItem[]) => {

@ -14,7 +14,6 @@ import routingTreeK8sHandlers from 'app/features/alerting/unified/mocks/server/h
import templatesK8sHandlers from 'app/features/alerting/unified/mocks/server/handlers/k8s/templates.k8s';
import timeIntervalK8sHandlers from 'app/features/alerting/unified/mocks/server/handlers/k8s/timeIntervals.k8s';
import mimirRulerHandlers from 'app/features/alerting/unified/mocks/server/handlers/mimirRuler';
import notificationsHandlers from 'app/features/alerting/unified/mocks/server/handlers/notifications';
import pluginsHandlers from 'app/features/alerting/unified/mocks/server/handlers/plugins';
import allPluginHandlers from 'app/features/alerting/unified/mocks/server/handlers/plugins/all-plugin-handlers';
import provisioningHandlers from 'app/features/alerting/unified/mocks/server/handlers/provisioning';
@ -37,7 +36,6 @@ const allHandlers = [
...provisioningHandlers,
...silenceHandlers,
...searchHandlers,
...notificationsHandlers,
...allPluginHandlers,

@ -1,22 +0,0 @@
import { HttpResponse, http } from 'msw';
import { getAlertmanagerConfig } from 'app/features/alerting/unified/mocks/server/entities/alertmanagers';
import { GRAFANA_RULES_SOURCE_NAME } from 'app/features/alerting/unified/utils/datasource';
const getNotificationReceiversHandler = () =>
http.get('/api/v1/notifications/receivers', () => {
const receivers = getAlertmanagerConfig(GRAFANA_RULES_SOURCE_NAME).alertmanager_config.receivers || [];
return HttpResponse.json(receivers);
});
const getTimeIntervalsHandler = () =>
http.get('/api/v1/notifications/time-intervals', () => {
const intervals = getAlertmanagerConfig(GRAFANA_RULES_SOURCE_NAME).alertmanager_config.time_intervals;
return HttpResponse.json(intervals);
});
const handlers = [getNotificationReceiversHandler(), getTimeIntervalsHandler()];
export default handlers;
Loading…
Cancel
Save