Alerting: Only show "misconfigured" warning for templates if AM is not Grafana (#95596)

This commit is contained in:
Tom Ratcliffe 2024-11-04 14:20:35 +00:00 committed by GitHub
parent e43bec2cd8
commit 2c57ecc085
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 70 additions and 29 deletions

View File

@ -91,7 +91,26 @@ const attemptDeleteContactPoint = async (name: string) => {
return user.click(await screen.findByRole('button', { name: /delete contact point/i })); return user.click(await screen.findByRole('button', { name: /delete contact point/i }));
}; };
const alertManager = mockDataSource<AlertManagerDataSourceJsonData>({
name: VANILLA_ALERTMANAGER_DATASOURCE_UID,
uid: VANILLA_ALERTMANAGER_DATASOURCE_UID,
type: DataSourceType.Alertmanager,
jsonData: {
implementation: AlertManagerImplementation.prometheus,
handleGrafanaManagedAlerts: true,
},
});
const mimirDatasource = mockDataSource({
type: DataSourceType.Alertmanager,
name: MIMIR_DATASOURCE_UID,
uid: MIMIR_DATASOURCE_UID,
});
describe('contact points', () => { describe('contact points', () => {
beforeEach(() => {
setupDataSources(alertManager, mimirDatasource);
});
describe('Contact points with Grafana managed alertmanager', () => { describe('Contact points with Grafana managed alertmanager', () => {
beforeEach(() => { beforeEach(() => {
grantUserPermissions([ grantUserPermissions([
@ -127,9 +146,14 @@ describe('contact points', () => {
}); });
describe('templates tab', () => { describe('templates tab', () => {
it('shows a warning when a template is misconfigured', async () => { it('does not show a warning for a "misconfigured" template', async () => {
renderWithProvider(<ContactPointsPageContents />, { initialEntries: ['/?tab=templates'] }); renderWithProvider(
expect((await screen.findAllByText(/^misconfigured$/i))[0]).toBeInTheDocument(); <ContactPointsPageContents />,
{ initialEntries: ['/?tab=templates'] },
{ alertmanagerSourceName: GRAFANA_RULES_SOURCE_NAME }
);
await screen.findByText(/create notification templates/i);
expect(screen.queryByText(/^misconfigured$/i)).not.toBeInTheDocument();
}); });
}); });
@ -328,13 +352,6 @@ describe('contact points', () => {
AccessControlAction.AlertingNotificationsExternalRead, AccessControlAction.AlertingNotificationsExternalRead,
AccessControlAction.AlertingNotificationsExternalWrite, AccessControlAction.AlertingNotificationsExternalWrite,
]); ]);
setupDataSources(
mockDataSource({
type: DataSourceType.Alertmanager,
name: MIMIR_DATASOURCE_UID,
uid: MIMIR_DATASOURCE_UID,
})
);
}); });
it('should show / hide loading states, have the right actions enabled', async () => { it('should show / hide loading states, have the right actions enabled', async () => {
@ -367,6 +384,17 @@ describe('contact points', () => {
expect(button).toBeEnabled(); expect(button).toBeEnabled();
}); });
}); });
describe('templates tab', () => {
it('shows a warning when a template is misconfigured', async () => {
renderWithProvider(
<ContactPointsPageContents />,
{ initialEntries: ['/?tab=templates'] },
{ alertmanagerSourceName: MIMIR_DATASOURCE_UID }
);
expect((await screen.findAllByText(/^misconfigured$/i))[0]).toBeInTheDocument();
});
});
}); });
describe('Vanilla Alertmanager ', () => { describe('Vanilla Alertmanager ', () => {
@ -376,23 +404,11 @@ describe('contact points', () => {
AccessControlAction.AlertingNotificationsExternalRead, AccessControlAction.AlertingNotificationsExternalRead,
AccessControlAction.AlertingNotificationsExternalWrite, AccessControlAction.AlertingNotificationsExternalWrite,
]); ]);
const alertManager = mockDataSource<AlertManagerDataSourceJsonData>({
name: VANILLA_ALERTMANAGER_DATASOURCE_UID,
uid: VANILLA_ALERTMANAGER_DATASOURCE_UID,
type: DataSourceType.Alertmanager,
jsonData: {
implementation: AlertManagerImplementation.prometheus,
handleGrafanaManagedAlerts: true,
},
});
setupDataSources(alertManager);
}); });
it("should not allow any editing because it's not supported", async () => { it("should not allow any editing because it's not supported", async () => {
const { user } = renderWithProvider(<ContactPointsPageContents />, undefined, { const { user } = renderWithProvider(<ContactPointsPageContents />, undefined, {
alertmanagerSourceName: VANILLA_ALERTMANAGER_DATASOURCE_UID, alertmanagerSourceName: alertManager.name,
}); });
await waitForElementToBeRemoved(screen.queryByText('Loading...')); await waitForElementToBeRemoved(screen.queryByText('Loading...'));

View File

@ -1,18 +1,41 @@
{ {
"template_files": {}, "template_files": {
"misconfigured-template": "{{ define 'misconfigured template' }} Template that is defined in template_files but not templates {{ end }}"
},
"alertmanager_config": { "alertmanager_config": {
"global": {}, "global": {},
"mute_time_intervals": [], "mute_time_intervals": [],
"receivers": [ "receivers": [
{ {
"email_configs": [ "email_configs": [
{ "require_tls": false, "send_resolved": true, "to": "foo@bar.com" }, {
{ "require_tls": false, "send_resolved": true, "to": "foo@bar.com" } "require_tls": false,
"send_resolved": true,
"to": "foo@bar.com"
},
{
"require_tls": false,
"send_resolved": true,
"to": "foo@bar.com"
}
], ],
"name": "mixed", "name": "mixed",
"webhook_configs": [{ "send_resolved": true, "url": "https://foo.bar/" }] "webhook_configs": [
{
"send_resolved": true,
"url": "https://foo.bar/"
}
]
}, },
{ "name": "some webhook", "webhook_configs": [{ "send_resolved": true, "url": "https://foo.bar/" }] } {
"name": "some webhook",
"webhook_configs": [
{
"send_resolved": true,
"url": "https://foo.bar/"
}
]
}
], ],
"route": { "route": {
"continue": false, "continue": false,

View File

@ -5,6 +5,7 @@ import { Badge, ConfirmModal, Tooltip, useStyles2 } from '@grafana/ui';
import { useAppNotification } from 'app/core/copy/appNotification'; import { useAppNotification } from 'app/core/copy/appNotification';
import { t, Trans } from 'app/core/internationalization'; import { t, Trans } from 'app/core/internationalization';
import { CodeText } from 'app/features/alerting/unified/components/common/TextVariants'; import { CodeText } from 'app/features/alerting/unified/components/common/TextVariants';
import { GRAFANA_RULES_SOURCE_NAME } from 'app/features/alerting/unified/utils/datasource';
import { Authorize } from '../../components/Authorize'; import { Authorize } from '../../components/Authorize';
import { AlertmanagerAction } from '../../hooks/useAbilities'; import { AlertmanagerAction } from '../../hooks/useAbilities';
@ -114,6 +115,7 @@ interface TemplateRowProps {
function TemplateRow({ notificationTemplate, idx, alertManagerName, onDeleteClick }: TemplateRowProps) { function TemplateRow({ notificationTemplate, idx, alertManagerName, onDeleteClick }: TemplateRowProps) {
const tableStyles = useStyles2(getAlertTableStyles); const tableStyles = useStyles2(getAlertTableStyles);
const isGrafanaAlertmanager = alertManagerName === GRAFANA_RULES_SOURCE_NAME;
const [isExpanded, setIsExpanded] = useState(false); const [isExpanded, setIsExpanded] = useState(false);
const { isProvisioned } = useNotificationTemplateMetadata(notificationTemplate); const { isProvisioned } = useNotificationTemplateMetadata(notificationTemplate);
@ -128,7 +130,7 @@ function TemplateRow({ notificationTemplate, idx, alertManagerName, onDeleteClic
</td> </td>
<td> <td>
{name} {isProvisioned && <ProvisioningBadge />}{' '} {name} {isProvisioned && <ProvisioningBadge />}{' '}
{missing && ( {missing && !isGrafanaAlertmanager && (
<Tooltip <Tooltip
content={ content={
<> <>