Skip to content

Commit c18da48

Browse files
authored
Alerting: Separate overlapping legacy and UA alerting routes (grafana#76517)
* Separate overlapping legacy and UA alerting routes api/alert-notifiers, alerting/list, and alerting/notifications existed in both legacy and UA. Rename legacy route paths and nav ids to be independent of UA ones.
1 parent 935ecdd commit c18da48

File tree

15 files changed

+100
-49
lines changed

15 files changed

+100
-49
lines changed

pkg/api/alerting.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,18 @@ func (hs *HTTPServer) GetAlert(c *contextmodel.ReqContext) response.Response {
239239
return response.JSON(http.StatusOK, &res)
240240
}
241241

242-
func (hs *HTTPServer) GetAlertNotifiers(ngalertEnabled bool) func(*contextmodel.ReqContext) response.Response {
242+
func (hs *HTTPServer) GetLegacyAlertNotifiers() func(*contextmodel.ReqContext) response.Response {
243243
return func(_ *contextmodel.ReqContext) response.Response {
244-
if ngalertEnabled {
245-
return response.JSON(http.StatusOK, channels_config.GetAvailableNotifiers())
246-
}
247-
// TODO(codesome): This wont be required in 8.0 since ngalert
248-
// will be enabled by default with no disabling. This is to be removed later.
249244
return response.JSON(http.StatusOK, alerting.GetNotifiers())
250245
}
251246
}
252247

248+
func (hs *HTTPServer) GetAlertNotifiers() func(*contextmodel.ReqContext) response.Response {
249+
return func(_ *contextmodel.ReqContext) response.Response {
250+
return response.JSON(http.StatusOK, channels_config.GetAvailableNotifiers())
251+
}
252+
}
253+
253254
// swagger:route GET /alert-notifications/lookup legacy_alerts_notification_channels getAlertNotificationLookup
254255
//
255256
// Get all notification channels (lookup).

pkg/api/api.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import (
4747
"github.com/grafana/grafana/pkg/services/serviceaccounts"
4848
"github.com/grafana/grafana/pkg/services/user"
4949
"github.com/grafana/grafana/pkg/setting"
50-
"github.com/grafana/grafana/pkg/web"
5150
)
5251

5352
var plog = log.New("api")
@@ -514,15 +513,14 @@ func (hs *HTTPServer) registerRoutes() {
514513
alertsRoute.Get("/states-for-dashboard", routing.Wrap(hs.GetAlertStatesForDashboard))
515514
}, requestmeta.SetOwner(requestmeta.TeamAlerting))
516515

517-
var notifiersAuthHandler web.Handler
518-
if hs.Cfg.UnifiedAlerting.IsEnabled() {
519-
notifiersAuthHandler = reqSignedIn
520-
} else {
521-
notifiersAuthHandler = reqEditorRole
522-
}
516+
// Unified Alerting
517+
apiRoute.Get("/alert-notifiers", reqSignedIn, requestmeta.SetOwner(requestmeta.TeamAlerting), routing.Wrap(
518+
hs.GetAlertNotifiers()),
519+
)
523520

524-
apiRoute.Get("/alert-notifiers", notifiersAuthHandler, requestmeta.SetOwner(requestmeta.TeamAlerting), routing.Wrap(
525-
hs.GetAlertNotifiers(hs.Cfg.UnifiedAlerting.IsEnabled())),
521+
// Legacy
522+
apiRoute.Get("/alert-notifiers-legacy", reqEditorRole, requestmeta.SetOwner(requestmeta.TeamAlerting), routing.Wrap(
523+
hs.GetLegacyAlertNotifiers()),
526524
)
527525

528526
apiRoute.Group("/alert-notifications", func(alertNotifications routing.RouteRegister) {

pkg/services/navtree/navtreeimpl/navtree.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,12 @@ func (s *ServiceImpl) buildDashboardNavLinks(c *contextmodel.ReqContext) []*navt
394394
func (s *ServiceImpl) buildLegacyAlertNavLinks(c *contextmodel.ReqContext) *navtree.NavLink {
395395
var alertChildNavs []*navtree.NavLink
396396
alertChildNavs = append(alertChildNavs, &navtree.NavLink{
397-
Text: "Alert rules", Id: "alert-list", Url: s.cfg.AppSubURL + "/alerting/list", Icon: "list-ul",
397+
Text: "Alert rules", Id: "alert-list-legacy", Url: s.cfg.AppSubURL + "/alerting-legacy/list", Icon: "list-ul",
398398
})
399399

400400
if c.SignedInUser.HasRole(roletype.RoleEditor) {
401401
alertChildNavs = append(alertChildNavs, &navtree.NavLink{
402-
Text: "Notification channels", Id: "channels", Url: s.cfg.AppSubURL + "/alerting/notifications",
402+
Text: "Notification channels", Id: "channels", Url: s.cfg.AppSubURL + "/alerting-legacy/notifications",
403403
Icon: "comment-alt-share",
404404
})
405405
}
@@ -411,7 +411,7 @@ func (s *ServiceImpl) buildLegacyAlertNavLinks(c *contextmodel.ReqContext) *navt
411411
Icon: "bell",
412412
Children: alertChildNavs,
413413
SortWeight: navtree.WeightAlerting,
414-
Url: s.cfg.AppSubURL + "/alerting",
414+
Url: s.cfg.AppSubURL + "/alerting-legacy",
415415
}
416416

417417
return &alertNav

public/app/core/utils/navBarItem-translations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export function getNavTitle(navId: string | undefined) {
6161
return t('nav.alerting-home.title', 'Home');
6262
case 'alert-list':
6363
return t('nav.alerting-list.title', 'Alert rules');
64+
case 'alert-list-legacy':
65+
return t('nav.alert-list-legacy.title', 'Alert rules');
6466
case 'receivers':
6567
return t('nav.alerting-receivers.title', 'Contact points');
6668
case 'am-routes':

public/app/features/alerting/AlertRuleList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class AlertRuleListUnconnected extends PureComponent<Props> {
9595
const { alertRules, search, isLoading } = this.props;
9696

9797
return (
98-
<Page navId="alert-list">
98+
<Page navId="alert-list-legacy">
9999
<Page.Contents isLoading={isLoading}>
100100
<div className="page-action-bar">
101101
<div className="gf-form gf-form--grow">
@@ -117,7 +117,7 @@ export class AlertRuleListUnconnected extends PureComponent<Props> {
117117
</div>
118118
<div className="page-action-bar__spacer" />
119119
{config.unifiedAlertingEnabled && (
120-
<LinkButton variant="primary" href="alerting/ng/new">
120+
<LinkButton variant="primary" href="alerting-legacy/ng/new">
121121
Add NG Alert
122122
</LinkButton>
123123
)}

public/app/features/alerting/NotificationsListPage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const NotificationsListPage: FC = () => {
5757
<>
5858
<div className="page-action-bar">
5959
<div className="page-action-bar__spacer" />
60-
<LinkButton icon="channel-add" href="alerting/notification/new">
60+
<LinkButton icon="channel-add" href="alerting-legacy/notification/new">
6161
New channel
6262
</LinkButton>
6363
</div>
@@ -75,10 +75,10 @@ const NotificationsListPage: FC = () => {
7575
{notifications.map((notification) => (
7676
<tr key={notification.id}>
7777
<td className="link-td">
78-
<a href={`alerting/notification/${notification.id}/edit`}>{notification.name}</a>
78+
<a href={`alerting-legacy/notification/${notification.id}/edit`}>{notification.name}</a>
7979
</td>
8080
<td className="link-td">
81-
<a href={`alerting/notification/${notification.id}/edit`}>{notification.type}</a>
81+
<a href={`alerting-legacy/notification/${notification.id}/edit`}>{notification.type}</a>
8282
</td>
8383
<td className="text-right">
8484
<HorizontalGroup justify="flex-end">
@@ -108,7 +108,7 @@ const NotificationsListPage: FC = () => {
108108
<EmptyListCTA
109109
title="There are no notification channels defined yet"
110110
buttonIcon="channel-add"
111-
buttonLink="alerting/notification/new"
111+
buttonLink="alerting-legacy/notification/new"
112112
buttonTitle="Add channel"
113113
proTip="You can include images in your alert notifications."
114114
proTipLink="http://docs.grafana.org/alerting/notifications/"

public/app/features/alerting/components/NotificationChannelForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export const NotificationChannelForm = ({
106106
<Button type="button" variant="secondary" onClick={() => onTestChannel(getValues())}>
107107
Test
108108
</Button>
109-
<a href={`${config.appSubUrl}/alerting/notifications`}>
109+
<a href={`${config.appSubUrl}/alerting-legacy/notifications`}>
110110
<Button type="button" variant="secondary">
111111
Back
112112
</Button>

public/app/features/alerting/routes.tsx

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { uniq } from 'lodash';
22
import React from 'react';
3+
import { Redirect, RouteComponentProps } from 'react-router-dom';
34

45
import { SafeDynamicImport } from 'app/core/components/DynamicImports/SafeDynamicImport';
56
import { NavLandingPage } from 'app/core/components/NavLandingPage/NavLandingPage';
@@ -14,73 +15,79 @@ const commonRoutes: RouteDescriptor[] = [];
1415
const legacyRoutes: RouteDescriptor[] = [
1516
...commonRoutes,
1617
{
17-
path: '/alerting',
18+
path: '/alerting-legacy',
1819
component: () => <NavLandingPage navId="alerting-legacy" />,
1920
},
2021
{
21-
path: '/alerting/list',
22+
path: '/alerting-legacy/list',
2223
component: SafeDynamicImport(
23-
() => import(/* webpackChunkName: "AlertRuleListIndex" */ 'app/features/alerting/AlertRuleList')
24+
() => import(/* webpackChunkName: "AlertRuleListLegacyIndex" */ 'app/features/alerting/AlertRuleList')
2425
),
2526
},
2627
{
27-
path: '/alerting/ng/list',
28+
path: '/alerting-legacy/ng/list',
2829
component: SafeDynamicImport(
29-
() => import(/* webpackChunkName: "AlertRuleList" */ 'app/features/alerting/AlertRuleList')
30+
() => import(/* webpackChunkName: "AlertRuleListLegacy" */ 'app/features/alerting/AlertRuleList')
3031
),
3132
},
3233
{
33-
path: '/alerting/notifications',
34+
path: '/alerting-legacy/notifications',
3435
roles: config.unifiedAlertingEnabled ? () => ['Editor', 'Admin'] : undefined,
3536
component: SafeDynamicImport(
36-
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
37+
() => import(/* webpackChunkName: "NotificationsListLegacyPage" */ 'app/features/alerting/NotificationsListPage')
3738
),
3839
},
3940
{
40-
path: '/alerting/notifications/templates/new',
41+
path: '/alerting-legacy/notifications/templates/new',
4142
roles: () => ['Editor', 'Admin'],
4243
component: SafeDynamicImport(
43-
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
44+
() => import(/* webpackChunkName: "NotificationsListLegacyPage" */ 'app/features/alerting/NotificationsListPage')
4445
),
4546
},
4647
{
47-
path: '/alerting/notifications/templates/:id/edit',
48+
path: '/alerting-legacy/notifications/templates/:id/edit',
4849
roles: () => ['Editor', 'Admin'],
4950
component: SafeDynamicImport(
50-
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
51+
() => import(/* webpackChunkName: "NotificationsListLegacyPage" */ 'app/features/alerting/NotificationsListPage')
5152
),
5253
},
5354
{
54-
path: '/alerting/notifications/receivers/new',
55+
path: '/alerting-legacy/notifications/receivers/new',
5556
roles: () => ['Editor', 'Admin'],
5657
component: SafeDynamicImport(
57-
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
58+
() => import(/* webpackChunkName: "NotificationsListLegacyPage" */ 'app/features/alerting/NotificationsListPage')
5859
),
5960
},
6061
{
61-
path: '/alerting/notifications/receivers/:id/edit',
62+
path: '/alerting-legacy/notifications/receivers/:id/edit',
6263
roles: () => ['Editor', 'Admin'],
6364
component: SafeDynamicImport(
64-
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
65+
() => import(/* webpackChunkName: "NotificationsListLegacyPage" */ 'app/features/alerting/NotificationsListPage')
6566
),
6667
},
6768
{
68-
path: '/alerting/notifications/global-config',
69+
path: '/alerting-legacy/notifications/global-config',
6970
roles: () => ['Admin', 'Editor'],
7071
component: SafeDynamicImport(
71-
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
72+
() => import(/* webpackChunkName: "NotificationsListLegacyPage" */ 'app/features/alerting/NotificationsListPage')
7273
),
7374
},
7475
{
75-
path: '/alerting/notification/new',
76+
path: '/alerting-legacy/notification/new',
7677
component: SafeDynamicImport(
77-
() => import(/* webpackChunkName: "NewNotificationChannel" */ 'app/features/alerting/NewNotificationChannelPage')
78+
() =>
79+
import(
80+
/* webpackChunkName: "NewNotificationChannelLegacy" */ 'app/features/alerting/NewNotificationChannelPage'
81+
)
7882
),
7983
},
8084
{
81-
path: '/alerting/notification/:id/edit',
85+
path: '/alerting-legacy/notification/:id/edit',
8286
component: SafeDynamicImport(
83-
() => import(/* webpackChunkName: "EditNotificationChannel"*/ 'app/features/alerting/EditNotificationChannelPage')
87+
() =>
88+
import(
89+
/* webpackChunkName: "EditNotificationChannelLegacy"*/ 'app/features/alerting/EditNotificationChannelPage'
90+
)
8491
),
8592
},
8693
];
@@ -295,7 +302,32 @@ export function getAlertingRoutes(cfg = config): RouteDescriptor[] {
295302
if (cfg.unifiedAlertingEnabled) {
296303
return unifiedRoutes;
297304
} else if (cfg.alertingEnabled) {
298-
return legacyRoutes;
305+
// Redirect old overlapping legacy routes to new separate ones to minimize unintended 404s.
306+
const redirects = [
307+
{
308+
path: '/alerting',
309+
component: () => <Redirect to={'/alerting-legacy'} />,
310+
},
311+
{
312+
path: '/alerting/list',
313+
component: () => <Redirect to={'/alerting-legacy/list'} />,
314+
},
315+
{
316+
path: '/alerting/notifications',
317+
component: () => <Redirect to={'/alerting-legacy/notifications'} />,
318+
},
319+
{
320+
path: '/alerting/notification/new',
321+
component: () => <Redirect to={'/alerting-legacy/notification/new'} />,
322+
},
323+
{
324+
path: '/alerting/notification/:id/edit',
325+
component: (props: RouteComponentProps<{ id: string }>) => (
326+
<Redirect to={'/alerting-legacy/notification/:id/edit'.replace(':id', props.match.params.id)} />
327+
),
328+
},
329+
];
330+
return [...legacyRoutes, ...redirects];
299331
}
300332

301333
const uniquePaths = uniq([...legacyRoutes, ...unifiedRoutes].map((route) => route.path));

public/app/features/alerting/state/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function createNotificationChannel(data: any): ThunkResult<Promise<void>>
2626
try {
2727
await getBackendSrv().post(`/api/alert-notifications`, data);
2828
dispatch(notifyApp(createSuccessNotification('Notification created')));
29-
locationService.push('/alerting/notifications');
29+
locationService.push('/alerting-legacy/notifications');
3030
} catch (error) {
3131
if (isFetchError(error)) {
3232
dispatch(notifyApp(createErrorNotification(error.data.error)));
@@ -57,7 +57,7 @@ export function testNotificationChannel(data: any): ThunkResult<void> {
5757

5858
export function loadNotificationTypes(): ThunkResult<void> {
5959
return async (dispatch) => {
60-
const alertNotifiers: NotifierDTO[] = await getBackendSrv().get(`/api/alert-notifiers`);
60+
const alertNotifiers: NotifierDTO[] = await getBackendSrv().get(`/api/alert-notifiers-legacy`);
6161

6262
const notificationTypes = alertNotifiers.sort((o1, o2) => {
6363
if (o1.name > o2.name) {

public/locales/de-DE/grafana.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,9 @@
671671
"subtitle": "Serverweite Einstellungen und Zugriff auf Ressourcen wie Organisationen, Benutzer und Lizenzen verwalten",
672672
"title": "Server-Administrator"
673673
},
674+
"alert-list-legacy": {
675+
"title": ""
676+
},
674677
"alerting": {
675678
"subtitle": "Informiere dich über Probleme in deinen Systemen kurz nach deren Auftreten",
676679
"title": "Meldungen"

0 commit comments

Comments
 (0)