Skip to content

Commit

Permalink
Changed alerting API endpoints urls, bodies and params to follow Kiba…
Browse files Browse the repository at this point in the history
…na STYLEGUIDE (#66838)

* Changed alerting API endpoints urls, bodies and params to follow Kibana STYLEGUIDE

* Changed alerting REST API to keep the pattern 'alerts/alert/{id}'

* fixed tests

* fixed tests

* Fixed jest tests

* Renamed plugin from alerting to alerts

* fixed tests

* fixed tests

* Fixed alert type check error

* Fixed find api

* fixed type checks

* fixed tests security issues

* Fixed view in app

* -

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
YulNaumenko and elasticmachine authored Jun 2, 2020
1 parent 78d5026 commit ce45dad
Show file tree
Hide file tree
Showing 317 changed files with 766 additions and 734 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
/x-pack/plugins/telemetry_collection_xpack/ @elastic/pulse

# Kibana Alerting Services
/x-pack/plugins/alerting/ @elastic/kibana-alerting-services
/x-pack/plugins/alerts/ @elastic/kibana-alerting-services
/x-pack/plugins/actions/ @elastic/kibana-alerting-services
/x-pack/plugins/event_log/ @elastic/kibana-alerting-services
/x-pack/plugins/task_manager/ @elastic/kibana-alerting-services
Expand Down
2 changes: 1 addition & 1 deletion examples/alerting_example/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"kibanaVersion": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["triggers_actions_ui", "charts", "data", "alerting", "actions"],
"requiredPlugins": ["triggers_actions_ui", "charts", "data", "alerts", "actions"],
"optionalPlugins": []
}
8 changes: 4 additions & 4 deletions examples/alerting_example/public/alert_types/astros.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import {
import { i18n } from '@kbn/i18n';
import { flatten } from 'lodash';
import { ALERTING_EXAMPLE_APP_ID, Craft, Operator } from '../../common/constants';
import { SanitizedAlert } from '../../../../x-pack/plugins/alerting/common';
import { PluginSetupContract as AlertingSetup } from '../../../../x-pack/plugins/alerting/public';
import { SanitizedAlert } from '../../../../x-pack/plugins/alerts/common';
import { PluginSetupContract as AlertingSetup } from '../../../../x-pack/plugins/alerts/public';
import { AlertTypeModel } from '../../../../x-pack/plugins/triggers_actions_ui/public';

export function registerNavigation(alerting: AlertingSetup) {
alerting.registerNavigation(
export function registerNavigation(alerts: AlertingSetup) {
alerts.registerNavigation(
ALERTING_EXAMPLE_APP_ID,
'example.people-in-space',
(alert: SanitizedAlert) => `/astros/${alert.id}`
Expand Down
10 changes: 5 additions & 5 deletions examples/alerting_example/public/alert_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

import { registerNavigation as registerPeopleInSpaceNavigation } from './astros';
import { ALERTING_EXAMPLE_APP_ID } from '../../common/constants';
import { SanitizedAlert } from '../../../../x-pack/plugins/alerting/common';
import { PluginSetupContract as AlertingSetup } from '../../../../x-pack/plugins/alerting/public';
import { SanitizedAlert } from '../../../../x-pack/plugins/alerts/common';
import { PluginSetupContract as AlertingSetup } from '../../../../x-pack/plugins/alerts/public';

export function registerNavigation(alerting: AlertingSetup) {
export function registerNavigation(alerts: AlertingSetup) {
// register default navigation
alerting.registerDefaultNavigation(
alerts.registerDefaultNavigation(
ALERTING_EXAMPLE_APP_ID,
(alert: SanitizedAlert) => `/alert/${alert.id}`
);

registerPeopleInSpaceNavigation(alerting);
registerPeopleInSpaceNavigation(alerts);
}
2 changes: 1 addition & 1 deletion examples/alerting_example/public/components/view_alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
Alert,
AlertTaskState,
BASE_ALERT_API_PATH,
} from '../../../../x-pack/plugins/alerting/common';
} from '../../../../x-pack/plugins/alerts/common';
import { ALERTING_EXAMPLE_APP_ID } from '../../common/constants';

type Props = RouteComponentProps & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
Alert,
AlertTaskState,
BASE_ALERT_API_PATH,
} from '../../../../x-pack/plugins/alerting/common';
} from '../../../../x-pack/plugins/alerts/common';
import { ALERTING_EXAMPLE_APP_ID } from '../../common/constants';

type Props = RouteComponentProps & {
Expand Down
10 changes: 5 additions & 5 deletions examples/alerting_example/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { Plugin, CoreSetup, AppMountParameters } from 'kibana/public';
import { PluginSetupContract as AlertingSetup } from '../../../x-pack/plugins/alerting/public';
import { PluginSetupContract as AlertingSetup } from '../../../x-pack/plugins/alerts/public';
import { ChartsPluginStart } from '../../../src/plugins/charts/public';
import { TriggersAndActionsUIPublicPluginSetup } from '../../../x-pack/plugins/triggers_actions_ui/public';
import { DataPublicPluginStart } from '../../../src/plugins/data/public';
Expand All @@ -30,12 +30,12 @@ export type Setup = void;
export type Start = void;

export interface AlertingExamplePublicSetupDeps {
alerting: AlertingSetup;
alerts: AlertingSetup;
triggers_actions_ui: TriggersAndActionsUIPublicPluginSetup;
}

export interface AlertingExamplePublicStartDeps {
alerting: AlertingSetup;
alerts: AlertingSetup;
triggers_actions_ui: TriggersAndActionsUIPublicPluginSetup;
charts: ChartsPluginStart;
data: DataPublicPluginStart;
Expand All @@ -44,7 +44,7 @@ export interface AlertingExamplePublicStartDeps {
export class AlertingExamplePlugin implements Plugin<Setup, Start, AlertingExamplePublicSetupDeps> {
public setup(
core: CoreSetup<AlertingExamplePublicStartDeps, Start>,
{ alerting, triggers_actions_ui }: AlertingExamplePublicSetupDeps
{ alerts, triggers_actions_ui }: AlertingExamplePublicSetupDeps
) {
core.application.register({
id: 'AlertingExample',
Expand All @@ -59,7 +59,7 @@ export class AlertingExamplePlugin implements Plugin<Setup, Start, AlertingExamp
triggers_actions_ui.alertTypeRegistry.register(getAlwaysFiringAlertType());
triggers_actions_ui.alertTypeRegistry.register(getPeopleInSpaceAlertType());

registerNavigation(alerting);
registerNavigation(alerts);
}

public start() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import uuid from 'uuid';
import { range } from 'lodash';
import { AlertType } from '../../../../x-pack/plugins/alerting/server';
import { AlertType } from '../../../../x-pack/plugins/alerts/server';
import { DEFAULT_INSTANCES_TO_GENERATE, ALERTING_EXAMPLE_APP_ID } from '../../common/constants';

export const alertType: AlertType = {
Expand Down
2 changes: 1 addition & 1 deletion examples/alerting_example/server/alert_types/astros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import axios from 'axios';
import { AlertType } from '../../../../x-pack/plugins/alerting/server';
import { AlertType } from '../../../../x-pack/plugins/alerts/server';
import { Operator, Craft, ALERTING_EXAMPLE_APP_ID } from '../../common/constants';

interface PeopleInSpace {
Expand Down
10 changes: 5 additions & 5 deletions examples/alerting_example/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
*/

import { Plugin, CoreSetup } from 'kibana/server';
import { PluginSetupContract as AlertingSetup } from '../../../x-pack/plugins/alerting/server';
import { PluginSetupContract as AlertingSetup } from '../../../x-pack/plugins/alerts/server';

import { alertType as alwaysFiringAlert } from './alert_types/always_firing';
import { alertType as peopleInSpaceAlert } from './alert_types/astros';

// this plugin's dependendencies
export interface AlertingExampleDeps {
alerting: AlertingSetup;
alerts: AlertingSetup;
}

export class AlertingExamplePlugin implements Plugin<void, void, AlertingExampleDeps> {
public setup(core: CoreSetup, { alerting }: AlertingExampleDeps) {
alerting.registerType(alwaysFiringAlert);
alerting.registerType(peopleInSpaceAlert);
public setup(core: CoreSetup, { alerts }: AlertingExampleDeps) {
alerts.registerType(alwaysFiringAlert);
alerts.registerType(peopleInSpaceAlert);
}

public start() {}
Expand Down
2 changes: 1 addition & 1 deletion rfcs/text/0003_handler_interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ application.registerApp({
});

// Alerting
alerting.registerType({
alerts.registerType({
id: 'myAlert',
async execute(context, params, state) {
const indexPatterns = await context.core.savedObjects.find('indexPattern');
Expand Down
2 changes: 1 addition & 1 deletion x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"xpack.actions": "plugins/actions",
"xpack.advancedUiActions": "plugins/advanced_ui_actions",
"xpack.uiActionsEnhanced": "examples/ui_actions_enhanced_examples",
"xpack.alerting": "plugins/alerting",
"xpack.alerts": "plugins/alerts",
"xpack.alertingBuiltins": "plugins/alerting_builtins",
"xpack.apm": ["legacy/plugins/apm", "plugins/apm"],
"xpack.beatsManagement": ["legacy/plugins/beats_management", "plugins/beats_management"],
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/monitoring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { KIBANA_ALERTING_ENABLED } from '../../../plugins/monitoring/common/cons
*/
const deps = ['kibana', 'elasticsearch', 'xpack_main'];
if (KIBANA_ALERTING_ENABLED) {
deps.push(...['alerting', 'actions']);
deps.push(...['alerts', 'actions']);
}
export const monitoring = (kibana: any) => {
return new kibana.Plugin({
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Table of Contents
- [Executor](#executor)
- [Example](#example)
- [RESTful API](#restful-api)
- [`POST /api/action`: Create action](#post-apiaction-create-action)
- [`POST /api/actions/action`: Create action](#post-apiaction-create-action)
- [`DELETE /api/actions/action/{id}`: Delete action](#delete-apiactionid-delete-action)
- [`GET /api/actions`: Get all actions](#get-apiactiongetall-get-all-actions)
- [`GET /api/actions/action/{id}`: Get action](#get-apiactionid-get-action)
Expand Down Expand Up @@ -163,7 +163,7 @@ The built-in email action type provides a good example of creating an action typ

Using an action type requires an action to be created that will contain and encrypt configuration for a given action type. See below for CRUD operations using the API.

### `POST /api/action`: Create action
### `POST /api/actions/action`: Create action

Payload:

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting_builtins/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# alerting_builtins plugin

This plugin provides alertTypes shipped with Kibana for use with the
[the alerting plugin](../alerting/README.md). When enabled, it will register
[the alerts plugin](../alerts/README.md). When enabled, it will register
the built-in alertTypes with the alerting plugin, register associated HTTP
routes, etc.

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting_builtins/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"server": true,
"version": "8.0.0",
"kibanaVersion": "kibana",
"requiredPlugins": ["alerting"],
"requiredPlugins": ["alerts"],
"configPath": ["xpack", "alerting_builtins"],
"ui": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { register as registerIndexThreshold } from './index_threshold';
interface RegisterBuiltInAlertTypesParams {
service: Service;
router: IRouter;
alerting: AlertingSetup;
alerts: AlertingSetup;
baseRoute: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { i18n } from '@kbn/i18n';
import { Params } from './alert_type_params';
import { AlertExecutorOptions } from '../../../../alerting/server';
import { AlertExecutorOptions } from '../../../../alerts/server';

// alert type context provided to actions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export function getService() {
interface RegisterParams {
service: Service;
router: IRouter;
alerting: AlertingSetup;
alerts: AlertingSetup;
baseRoute: string;
}

export function register(params: RegisterParams) {
const { service, router, alerting, baseRoute } = params;
const { service, router, alerts, baseRoute } = params;

alerting.registerType(getAlertType(service));
alerts.registerType(getAlertType(service));

const baseBuiltInRoute = `${baseRoute}/index_threshold`;
registerRoutes({ service, router, baseRoute: baseBuiltInRoute });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { i18n } from '@kbn/i18n';
import { times } from 'lodash';
import { parseDuration } from '../../../../../alerting/server';
import { parseDuration } from '../../../../../alerts/server';
import { MAX_INTERVALS } from '../index';

// dates as numbers are epoch millis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { i18n } from '@kbn/i18n';
import { schema, TypeOf } from '@kbn/config-schema';

import { parseDuration } from '../../../../../alerting/server';
import { parseDuration } from '../../../../../alerts/server';
import { MAX_INTERVALS } from '../index';
import { CoreQueryParamsSchemaProperties, validateCoreQueryBody } from './core_query_types';
import {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/alerting_builtins/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { AlertingBuiltinsPlugin } from './plugin';
import { coreMock } from '../../../../src/core/server/mocks';
import { alertsMock } from '../../../plugins/alerting/server/mocks';
import { alertsMock } from '../../alerts/server/mocks';

describe('AlertingBuiltins Plugin', () => {
describe('setup()', () => {
Expand All @@ -22,7 +22,7 @@ describe('AlertingBuiltins Plugin', () => {

it('should register built-in alert types', async () => {
const alertingSetup = alertsMock.createSetup();
await plugin.setup(coreSetup, { alerting: alertingSetup });
await plugin.setup(coreSetup, { alerts: alertingSetup });

expect(alertingSetup.registerType).toHaveBeenCalledTimes(1);

Expand All @@ -44,7 +44,7 @@ describe('AlertingBuiltins Plugin', () => {

it('should return a service in the expected shape', async () => {
const alertingSetup = alertsMock.createSetup();
const service = await plugin.setup(coreSetup, { alerting: alertingSetup });
const service = await plugin.setup(coreSetup, { alerts: alertingSetup });

expect(typeof service.indexThreshold.timeSeriesQuery).toBe('function');
});
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/alerting_builtins/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export class AlertingBuiltinsPlugin implements Plugin<IService, IService> {
};
}

public async setup(core: CoreSetup, { alerting }: AlertingBuiltinsDeps): Promise<IService> {
public async setup(core: CoreSetup, { alerts }: AlertingBuiltinsDeps): Promise<IService> {
registerBuiltInAlertTypes({
service: this.service,
router: core.http.createRouter(),
alerting,
alerts,
baseRoute: '/api/alerting_builtins',
});
return this.service;
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/alerting_builtins/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { Logger, ScopedClusterClient } from '../../../../src/core/server';
import { PluginSetupContract as AlertingSetup } from '../../alerting/server';
import { PluginSetupContract as AlertingSetup } from '../../alerts/server';
import { getService as getServiceIndexThreshold } from './alert_types/index_threshold';

export { Logger, IRouter } from '../../../../src/core/server';
Expand All @@ -14,11 +14,11 @@ export {
PluginSetupContract as AlertingSetup,
AlertType,
AlertExecutorOptions,
} from '../../alerting/server';
} from '../../alerts/server';

// this plugin's dependendencies
export interface AlertingBuiltinsDeps {
alerting: AlertingSetup;
alerts: AlertingSetup;
}

// external service exposed through plugin setup/start
Expand Down
Loading

0 comments on commit ce45dad

Please sign in to comment.