Alerting: Disable simplified routing when internal alert manager is disabled (#90648)
* Disable simplified routing when internal alert manager is disabled * address pr review comments * add test * remove unnecessary mocks
This commit is contained in:
@@ -5,7 +5,9 @@ import { useFormContext } from 'react-hook-form';
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { config } from '@grafana/runtime';
|
||||
import { Icon, RadioButtonGroup, Stack, Text, useStyles2 } from '@grafana/ui';
|
||||
import { AlertmanagerChoice } from 'app/plugins/datasource/alertmanager/types';
|
||||
|
||||
import { alertmanagerApi } from '../../api/alertmanagerApi';
|
||||
import { RuleFormType, RuleFormValues } from '../../types/rule-form';
|
||||
import { GRAFANA_RULES_SOURCE_NAME } from '../../utils/datasource';
|
||||
|
||||
@@ -25,6 +27,15 @@ enum RoutingOptions {
|
||||
ContactPoint = 'contact point',
|
||||
}
|
||||
|
||||
function useHasInternalAlertmanagerEnabled() {
|
||||
const { useGetGrafanaAlertingConfigurationStatusQuery } = alertmanagerApi;
|
||||
const { currentData: amChoiceStatus } = useGetGrafanaAlertingConfigurationStatusQuery(undefined);
|
||||
return (
|
||||
amChoiceStatus?.alertmanagersChoice === AlertmanagerChoice.Internal ||
|
||||
amChoiceStatus?.alertmanagersChoice === AlertmanagerChoice.All
|
||||
);
|
||||
}
|
||||
|
||||
export const NotificationsStep = ({ alertUid }: NotificationsStepProps) => {
|
||||
const { watch, getValues, setValue } = useFormContext<RuleFormValues>();
|
||||
const styles = useStyles2(getStyles);
|
||||
@@ -35,7 +46,10 @@ export const NotificationsStep = ({ alertUid }: NotificationsStepProps) => {
|
||||
const dataSourceName = watch('dataSourceName') ?? GRAFANA_RULES_SOURCE_NAME;
|
||||
const simplifiedRoutingToggleEnabled = config.featureToggles.alertingSimplifiedRouting ?? false;
|
||||
const shouldRenderpreview = type === RuleFormType.grafana;
|
||||
const shouldAllowSimplifiedRouting = type === RuleFormType.grafana && simplifiedRoutingToggleEnabled;
|
||||
const hasInternalAlertmanagerEnabled = useHasInternalAlertmanagerEnabled();
|
||||
|
||||
const shouldAllowSimplifiedRouting =
|
||||
type === RuleFormType.grafana && simplifiedRoutingToggleEnabled && hasInternalAlertmanagerEnabled;
|
||||
|
||||
function onCloseLabelsEditor(
|
||||
labelsToUpdate?: Array<{
|
||||
|
||||
+10
@@ -14,6 +14,7 @@ import * as ruler from 'app/features/alerting/unified/api/ruler';
|
||||
import * as useContactPoints from 'app/features/alerting/unified/components/contact-points/useContactPoints';
|
||||
import { setupMswServer } from 'app/features/alerting/unified/mockApi';
|
||||
import { grantUserPermissions, mockDataSource } from 'app/features/alerting/unified/mocks';
|
||||
import { setAlertmanagerChoices } from 'app/features/alerting/unified/mocks/server/configure';
|
||||
import { AlertmanagerProvider } from 'app/features/alerting/unified/state/AlertmanagerContext';
|
||||
import * as utils_config from 'app/features/alerting/unified/utils/config';
|
||||
import {
|
||||
@@ -25,6 +26,7 @@ import {
|
||||
import { getDefaultQueries } from 'app/features/alerting/unified/utils/rule-form';
|
||||
import { searchFolders } from 'app/features/manage-dashboards/state/actions';
|
||||
import { DashboardSearchHit, DashboardSearchItemType } from 'app/features/search/types';
|
||||
import { AlertmanagerChoice } from 'app/plugins/datasource/alertmanager/types';
|
||||
import { AccessControlAction } from 'app/types';
|
||||
import { GrafanaAlertStateDecision } from 'app/types/unified-alerting-dto';
|
||||
|
||||
@@ -160,6 +162,14 @@ describe('Can create a new grafana managed alert unsing simplified routing', ()
|
||||
expect(mocks.api.setRulerRuleGroup).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
it('simplified routing is not available when Grafana AM is not enabled', async () => {
|
||||
config.featureToggles.alertingSimplifiedRouting = true;
|
||||
setAlertmanagerChoices(AlertmanagerChoice.External, 1);
|
||||
renderSimplifiedRuleEditor();
|
||||
await waitForElementToBeRemoved(screen.getAllByTestId('Spinner'));
|
||||
|
||||
expect(ui.inputs.simplifiedRouting.contactPointRouting.query()).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('can create new grafana managed alert when using simplified routing and selecting a contact point', async () => {
|
||||
const contactPointsAvailable: ContactPointWithMetadata[] = [
|
||||
|
||||
Reference in New Issue
Block a user