Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move current alert HTTP APIs to legacy folder #93943

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions api_docs/alerting.json
Original file line number Diff line number Diff line change
Expand Up @@ -955,21 +955,21 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/plugin.ts",
"lineNumber": 112
"lineNumber": 94
}
}
],
"tags": [],
"returnComment": [],
"source": {
"path": "x-pack/plugins/alerting/server/plugin.ts",
"lineNumber": 104
"lineNumber": 86
}
}
],
"source": {
"path": "x-pack/plugins/alerting/server/plugin.ts",
"lineNumber": 103
"lineNumber": 85
},
"initialIsOpen": false
},
Expand All @@ -988,7 +988,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/plugin.ts",
"lineNumber": 124
"lineNumber": 106
},
"signature": [
"() => Set<",
Expand Down Expand Up @@ -1044,15 +1044,15 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/plugin.ts",
"lineNumber": 125
"lineNumber": 107
}
}
],
"tags": [],
"returnComment": [],
"source": {
"path": "x-pack/plugins/alerting/server/plugin.ts",
"lineNumber": 125
"lineNumber": 107
}
},
{
Expand All @@ -1063,7 +1063,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/plugin.ts",
"lineNumber": 126
"lineNumber": 108
},
"signature": [
"() => Promise<",
Expand All @@ -1080,7 +1080,7 @@
],
"source": {
"path": "x-pack/plugins/alerting/server/plugin.ts",
"lineNumber": 123
"lineNumber": 105
},
"initialIsOpen": false
}
Expand Down Expand Up @@ -2991,32 +2991,32 @@
"initialIsOpen": false
},
{
"id": "def-common.DefaultActionGroupId",
"type": "Type",
"label": "DefaultActionGroupId",
"tags": [],
"id": "def-common.BASE_ALERT_API_PATH",
"type": "string",
"label": "BASE_ALERT_API_PATH",
"description": [],
"source": {
"path": "x-pack/plugins/alerting/common/index.ts",
"lineNumber": 27
"path": "x-pack/plugins/alerting/common/builtin_action_groups.ts",
"lineNumber": 11
},
"signature": [
"\"/api/alerts\""
"\"default\""
],
"initialIsOpen": false
},
{
"id": "def-common.DefaultActionGroupId",
"type": "Type",
"label": "DefaultActionGroupId",
"tags": [],
"id": "def-common.LEGACY_BASE_ALERT_API_PATH",
"type": "string",
"label": "LEGACY_BASE_ALERT_API_PATH",
"description": [],
"source": {
"path": "x-pack/plugins/alerting/common/builtin_action_groups.ts",
"lineNumber": 11
"path": "x-pack/plugins/alerting/common/index.ts",
"lineNumber": 27
},
"signature": [
"\"default\""
"\"/api/alerts\""
],
"initialIsOpen": false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ import {
import { withRouter, RouteComponentProps } from 'react-router-dom';
import { CoreStart } from 'kibana/public';
import { isEmpty } from 'lodash';
import { Alert, AlertTaskState, BASE_ALERT_API_PATH } from '../../../../plugins/alerting/common';
import { ALERTING_EXAMPLE_APP_ID } from '../../common/constants';
import {
Alert,
AlertTaskState,
LEGACY_BASE_ALERT_API_PATH,
} from '../../../../plugins/alerting/common';

type Props = RouteComponentProps & {
http: CoreStart['http'];
Expand All @@ -34,10 +38,10 @@ export const ViewAlertPage = withRouter(({ http, id }: Props) => {

useEffect(() => {
if (!alert) {
http.get(`${BASE_ALERT_API_PATH}/alert/${id}`).then(setAlert);
http.get(`${LEGACY_BASE_ALERT_API_PATH}/alert/${id}`).then(setAlert);
}
if (!alertState) {
http.get(`${BASE_ALERT_API_PATH}/alert/${id}/state`).then(setAlertState);
http.get(`${LEGACY_BASE_ALERT_API_PATH}/alert/${id}/state`).then(setAlertState);
}
}, [alert, alertState, http, id]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ import {
import { withRouter, RouteComponentProps } from 'react-router-dom';
import { CoreStart } from 'kibana/public';
import { isEmpty } from 'lodash';
import { Alert, AlertTaskState, BASE_ALERT_API_PATH } from '../../../../plugins/alerting/common';
import { ALERTING_EXAMPLE_APP_ID, AlwaysFiringParams } from '../../common/constants';
import {
Alert,
AlertTaskState,
LEGACY_BASE_ALERT_API_PATH,
} from '../../../../plugins/alerting/common';

type Props = RouteComponentProps & {
http: CoreStart['http'];
Expand All @@ -40,10 +44,10 @@ export const ViewPeopleInSpaceAlertPage = withRouter(({ http, id }: Props) => {

useEffect(() => {
if (!alert) {
http.get(`${BASE_ALERT_API_PATH}/alert/${id}`).then(setAlert);
http.get(`${LEGACY_BASE_ALERT_API_PATH}/alert/${id}`).then(setAlert);
}
if (!alertState) {
http.get(`${BASE_ALERT_API_PATH}/alert/${id}/state`).then(setAlertState);
http.get(`${LEGACY_BASE_ALERT_API_PATH}/alert/${id}/state`).then(setAlertState);
}
}, [alert, alertState, http, id]);

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ export interface AlertingFrameworkHealth {
alertingFrameworkHeath: AlertsHealth;
}

export const BASE_ALERT_API_PATH = '/api/alerts';
export const LEGACY_BASE_ALERT_API_PATH = '/api/alerts';
export const ALERTS_FEATURE_ID = 'alerts';
8 changes: 4 additions & 4 deletions x-pack/plugins/alerting/public/alert_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import { HttpSetup } from 'kibana/public';
import { i18n } from '@kbn/i18n';
import { BASE_ALERT_API_PATH } from '../common';
import { LEGACY_BASE_ALERT_API_PATH } from '../common';
import type { Alert, AlertType } from '../common';

export async function loadAlertTypes({ http }: { http: HttpSetup }): Promise<AlertType[]> {
return await http.get(`${BASE_ALERT_API_PATH}/list_alert_types`);
return await http.get(`${LEGACY_BASE_ALERT_API_PATH}/list_alert_types`);
}

export async function loadAlertType({
Expand All @@ -22,7 +22,7 @@ export async function loadAlertType({
id: AlertType['id'];
}): Promise<AlertType> {
const maybeAlertType = ((await http.get(
`${BASE_ALERT_API_PATH}/list_alert_types`
`${LEGACY_BASE_ALERT_API_PATH}/list_alert_types`
)) as AlertType[]).find((type) => type.id === id);
if (!maybeAlertType) {
throw new Error(
Expand All @@ -44,5 +44,5 @@ export async function loadAlert({
http: HttpSetup;
alertId: string;
}): Promise<Alert> {
return await http.get(`${BASE_ALERT_API_PATH}/alert/${alertId}`);
return await http.get(`${LEGACY_BASE_ALERT_API_PATH}/alert/${alertId}`);
}
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

export { parseDuration, validateDurationSchema } from '../../common/parse_duration';
export { LicenseState } from './license_state';
export { ILicenseState, LicenseState } from './license_state';
export { validateAlertTypeParams } from './validate_alert_type_params';
export { getAlertNotifyWhenType } from './get_alert_notify_when_type';
export { ErrorWithReason, getReasonFromError, isErrorWithReason } from './error_with_reason';
Expand Down
38 changes: 2 additions & 36 deletions x-pack/plugins/alerting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,7 @@ import {
} from '../../../../src/core/server';
import type { AlertingRequestHandlerContext } from './types';

import {
aggregateAlertRoute,
createAlertRoute,
deleteAlertRoute,
findAlertRoute,
getAlertRoute,
getAlertStateRoute,
getAlertInstanceSummaryRoute,
listAlertTypesRoute,
updateAlertRoute,
enableAlertRoute,
disableAlertRoute,
updateApiKeyRoute,
muteAllAlertRoute,
unmuteAllAlertRoute,
muteAlertInstanceRoute,
unmuteAlertInstanceRoute,
healthRoute,
} from './routes';
import { defineRoutes } from './routes';
import { LICENSE_TYPE, LicensingPluginSetup, LicensingPluginStart } from '../../licensing/server';
import {
PluginSetupContract as ActionsPluginSetupContract,
Expand Down Expand Up @@ -267,23 +249,7 @@ export class AlertingPlugin {
// Routes
const router = core.http.createRouter<AlertingRequestHandlerContext>();
// Register routes
aggregateAlertRoute(router, this.licenseState);
createAlertRoute(router, this.licenseState);
deleteAlertRoute(router, this.licenseState);
findAlertRoute(router, this.licenseState);
getAlertRoute(router, this.licenseState);
getAlertStateRoute(router, this.licenseState);
getAlertInstanceSummaryRoute(router, this.licenseState);
listAlertTypesRoute(router, this.licenseState);
updateAlertRoute(router, this.licenseState);
enableAlertRoute(router, this.licenseState);
disableAlertRoute(router, this.licenseState);
updateApiKeyRoute(router, this.licenseState);
muteAllAlertRoute(router, this.licenseState);
unmuteAllAlertRoute(router, this.licenseState);
muteAlertInstanceRoute(router, this.licenseState);
unmuteAlertInstanceRoute(router, this.licenseState);
healthRoute(router, this.licenseState, plugins.encryptedSavedObjects);
defineRoutes(router, this.licenseState, plugins.encryptedSavedObjects);

return {
registerType<
Expand Down
30 changes: 13 additions & 17 deletions x-pack/plugins/alerting/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@
* 2.0.
*/

export { aggregateAlertRoute } from './aggregate';
export { createAlertRoute } from './create';
export { deleteAlertRoute } from './delete';
export { findAlertRoute } from './find';
export { getAlertRoute } from './get';
export { getAlertStateRoute } from './get_alert_state';
export { getAlertInstanceSummaryRoute } from './get_alert_instance_summary';
export { listAlertTypesRoute } from './list_alert_types';
export { updateAlertRoute } from './update';
export { enableAlertRoute } from './enable';
export { disableAlertRoute } from './disable';
export { updateApiKeyRoute } from './update_api_key';
export { muteAlertInstanceRoute } from './mute_instance';
export { unmuteAlertInstanceRoute } from './unmute_instance';
export { muteAllAlertRoute } from './mute_all';
export { unmuteAllAlertRoute } from './unmute_all';
export { healthRoute } from './health';
import { IRouter } from 'kibana/server';
import { ILicenseState } from '../lib';
import { defineLegacyRoutes } from './legacy';
import { AlertingRequestHandlerContext } from '../types';
import { EncryptedSavedObjectsPluginSetup } from '../../../encrypted_saved_objects/server';

export function defineRoutes(
router: IRouter<AlertingRequestHandlerContext>,
licenseState: ILicenseState,
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup
) {
defineLegacyRoutes(router, licenseState, encryptedSavedObjects);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import { aggregateAlertRoute } from './aggregate';
import { httpServiceMock } from 'src/core/server/mocks';
import { licenseStateMock } from '../lib/license_state.mock';
import { verifyApiAccess } from '../lib/license_api_access';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { alertsClientMock } from '../alerts_client.mock';
import { licenseStateMock } from '../../lib/license_state.mock';
import { verifyApiAccess } from '../../lib/license_api_access';
import { mockHandlerArguments } from './../_mock_handler_arguments';
import { alertsClientMock } from '../../alerts_client.mock';

const alertsClient = alertsClientMock.create();

jest.mock('../lib/license_api_access.ts', () => ({
jest.mock('../../lib/license_api_access.ts', () => ({
verifyApiAccess: jest.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/

import { schema } from '@kbn/config-schema';
import type { AlertingRouter } from '../types';
import { ILicenseState } from '../lib/license_state';
import { verifyApiAccess } from '../lib/license_api_access';
import { BASE_ALERT_API_PATH } from '../../common';
import { renameKeys } from './lib/rename_keys';
import { FindOptions } from '../alerts_client';
import type { AlertingRouter } from '../../types';
import { ILicenseState } from '../../lib/license_state';
import { verifyApiAccess } from '../../lib/license_api_access';
import { LEGACY_BASE_ALERT_API_PATH } from '../../../common';
import { renameKeys } from './../lib/rename_keys';
import { FindOptions } from '../../alerts_client';

// config definition
const querySchema = schema.object({
Expand All @@ -36,7 +36,7 @@ const querySchema = schema.object({
export const aggregateAlertRoute = (router: AlertingRouter, licenseState: ILicenseState) => {
router.get(
{
path: `${BASE_ALERT_API_PATH}/_aggregate`,
path: `${LEGACY_BASE_ALERT_API_PATH}/_aggregate`,
validate: {
query: querySchema,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

import { createAlertRoute } from './create';
import { httpServiceMock } from 'src/core/server/mocks';
import { licenseStateMock } from '../lib/license_state.mock';
import { verifyApiAccess } from '../lib/license_api_access';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { alertsClientMock } from '../alerts_client.mock';
import { Alert } from '../../common/alert';
import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled';
import { licenseStateMock } from '../../lib/license_state.mock';
import { verifyApiAccess } from '../../lib/license_api_access';
import { mockHandlerArguments } from './../_mock_handler_arguments';
import { alertsClientMock } from '../../alerts_client.mock';
import { Alert } from '../../../common/alert';
import { AlertTypeDisabledError } from '../../lib/errors/alert_type_disabled';

const alertsClient = alertsClientMock.create();

jest.mock('../lib/license_api_access.ts', () => ({
jest.mock('../../lib/license_api_access.ts', () => ({
verifyApiAccess: jest.fn(),
}));

Expand Down
Loading