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

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

Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c84afcc
Changed alerting API endpoints urls, bodies and params to follow Kiba…
YulNaumenko May 16, 2020
2df78f4
Merge remote-tracking branch 'upstream/master' into alerting-change-u…
YulNaumenko May 26, 2020
529875e
Changed alerting REST API to keep the pattern 'alerts/alert/{id}'
YulNaumenko May 26, 2020
c016a6d
Merge branch 'master' into alerting-change-urls-to-kibana-styleguide
elasticmachine May 26, 2020
a247e1e
fixed tests
YulNaumenko May 27, 2020
d2fec71
Merge branch 'alerting-change-urls-to-kibana-styleguide' of github.co…
YulNaumenko May 27, 2020
618e90e
fixed tests
YulNaumenko May 27, 2020
edd6a1a
Merge remote-tracking branch 'upstream/master' into alerting-change-u…
YulNaumenko May 27, 2020
7676025
Fixed jest tests
YulNaumenko May 27, 2020
5bacd42
Renamed plugin from alerting to alerts
YulNaumenko May 27, 2020
62c6642
Merge remote-tracking branch 'upstream/master' into alerting-change-u…
YulNaumenko May 27, 2020
7a26f49
fixed tests
YulNaumenko May 28, 2020
40e2bb0
fixed tests
YulNaumenko May 28, 2020
b396db5
Fixed alert type check error
YulNaumenko May 28, 2020
ee17ee3
Merge remote-tracking branch 'upstream/master' into alerting-change-u…
YulNaumenko May 28, 2020
ea75836
Fixed find api
YulNaumenko May 28, 2020
1f47537
fixed type checks
YulNaumenko May 29, 2020
f486629
Merge remote-tracking branch 'upstream/master' into alerting-change-u…
YulNaumenko Jun 1, 2020
668fd32
fixed tests security issues
YulNaumenko Jun 1, 2020
7dec745
Fixed view in app
YulNaumenko Jun 1, 2020
ef62641
Merge remote-tracking branch 'upstream/master' into alerting-change-u…
YulNaumenko Jun 1, 2020
07945b4
-
YulNaumenko Jun 1, 2020
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
56 changes: 28 additions & 28 deletions x-pack/plugins/alerting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ Table of Contents
- [Example](#example)
- [Alert Navigation](#alert-navigation)
- [RESTful API](#restful-api)
- [`POST /api/alert`: Create alert](#post-apialert-create-alert)
- [`DELETE /api/alert/{id}`: Delete alert](#delete-apialertid-delete-alert)
- [`GET /api/alert/_find`: Find alerts](#get-apialertfind-find-alerts)
- [`GET /api/alert/{id}`: Get alert](#get-apialertid-get-alert)
- [`GET /api/alert/{id}/state`: Get alert state](#get-apialertidstate-get-alert-state)
- [`GET /api/alert/types`: List alert types](#get-apialerttypes-list-alert-types)
- [`PUT /api/alert/{id}`: Update alert](#put-apialertid-update-alert)
- [`POST /api/alert/{id}/_enable`: Enable an alert](#post-apialertidenable-enable-an-alert)
- [`POST /api/alert/{id}/_disable`: Disable an alert](#post-apialertiddisable-disable-an-alert)
- [`POST /api/alert/{id}/_mute_all`: Mute all alert instances](#post-apialertidmuteall-mute-all-alert-instances)
- [`POST /api/alert/{alertId}/alert_instance/{alertInstanceId}/_mute`: Mute alert instance](#post-apialertalertidalertinstancealertinstanceidmute-mute-alert-instance)
- [`POST /api/alert/{id}/_unmute_all`: Unmute all alert instances](#post-apialertidunmuteall-unmute-all-alert-instances)
- [`POST /api/alert/{alertId}/alert_instance/{alertInstanceId}/_unmute`: Unmute an alert instance](#post-apialertalertidalertinstancealertinstanceidunmute-unmute-an-alert-instance)
- [`POST /api/alert/{id}/_update_api_key`: Update alert API key](#post-apialertidupdateapikey-update-alert-api-key)
- [`POST /api/alerts/alert`: Create alert](#post-apialert-create-alert)
- [`DELETE /api/alerts/alert/{id}`: Delete alert](#delete-apialertid-delete-alert)
- [`GET /api/alerts/_find`: Find alerts](#get-apialertfind-find-alerts)
- [`GET /api/alerts/alert/{id}`: Get alert](#get-apialertid-get-alert)
- [`GET /api/alerts/alert/{id}/state`: Get alert state](#get-apialertidstate-get-alert-state)
- [`GET /api/alerts/list_alert_types`: List alert types](#get-apialerttypes-list-alert-types)
- [`PUT /api/alerts/alert/{id}`: Update alert](#put-apialertid-update-alert)
- [`POST /api/alerts/alert/{id}/_enable`: Enable an alert](#post-apialertidenable-enable-an-alert)
- [`POST /api/alerts/alert/{id}/_disable`: Disable an alert](#post-apialertiddisable-disable-an-alert)
- [`POST /api/alerts/alert/{id}/_mute_all`: Mute all alert instances](#post-apialertidmuteall-mute-all-alert-instances)
- [`POST /api/alerts/alert/{alert_id}/alert_instance/{alert_instance_id}/_mute`: Mute alert instance](#post-apialertalertidalertinstancealertinstanceidmute-mute-alert-instance)
- [`POST /api/alerts/alert/{id}/_unmute_all`: Unmute all alert instances](#post-apialertidunmuteall-unmute-all-alert-instances)
- [`POST /api/alerts/alert/{alertId}/alert_instance/{alertInstanceId}/_unmute`: Unmute an alert instance](#post-apialertalertidalertinstancealertinstanceidunmute-unmute-an-alert-instance)
- [`POST /api/alerts/alert/{id}/_update_api_key`: Update alert API key](#post-apialertidupdateapikey-update-alert-api-key)
- [Schedule Formats](#schedule-formats)
- [Alert instance factory](#alert-instance-factory)
- [Templating actions](#templating-actions)
Expand Down Expand Up @@ -352,7 +352,7 @@ You can use the `registerNavigation` api to specify as many AlertType specific h

Using an alert type requires you to create an alert that will contain parameters and actions for a given alert type. See below for CRUD operations using the API.

### `POST /api/alert`: Create alert
### `POST /api/alerts/alert`: Create alert

Payload:

Expand All @@ -367,41 +367,41 @@ Payload:
|params|The parameters to pass in to the alert type executor `params` value. This will also validate against the alert type params validator if defined.|object|
|actions|Array of the following:<br> - `group` (string): We support grouping actions in the scenario of escalations or different types of alert instances. If you don't need this, feel free to use `default` as a value.<br>- `id` (string): The id of the action saved object to execute.<br>- `params` (object): The map to the `params` the action type will receive. In order to help apply context to strings, we handle them as mustache templates and pass in a default set of context. (see templating actions).|array|

### `DELETE /api/alert/{id}`: Delete alert
### `DELETE /api/alerts/alert/{id}`: Delete alert

Params:

|Property|Description|Type|
|---|---|---|
|id|The id of the alert you're trying to delete.|string|

### `GET /api/alert/_find`: Find alerts
### `GET /api/alerts/_find`: Find alerts

Params:

See the saved objects API documentation for find. All the properties are the same except you cannot pass in `type`.

### `GET /api/alert/{id}`: Get alert
### `GET /api/alerts/alert/{id}`: Get alert

Params:

|Property|Description|Type|
|---|---|---|
|id|The id of the alert you're trying to get.|string|

### `GET /api/alert/{id}/state`: Get alert state
### `GET /api/alerts/alert/{id}/state`: Get alert state

Params:

|Property|Description|Type|
|---|---|---|
|id|The id of the alert whose state you're trying to get.|string|

### `GET /api/alert/types`: List alert types
### `GET /api/alerts/list_alert_types`: List alert types

No parameters.

### `PUT /api/alert/{id}`: Update alert
### `PUT /api/alerts/alert/{id}`: Update alert

Params:

Expand All @@ -420,31 +420,31 @@ Payload:
|params|The parameters to pass in to the alert type executor `params` value. This will also validate against the alert type params validator if defined.|object|
|actions|Array of the following:<br> - `group` (string): We support grouping actions in the scenario of escalations or different types of alert instances. If you don't need this, feel free to use `default` as a value.<br>- `id` (string): The id of the action saved object to execute.<br>- `params` (object): There map to the `params` the action type will receive. In order to help apply context to strings, we handle them as mustache templates and pass in a default set of context. (see templating actions).|array|

### `POST /api/alert/{id}/_enable`: Enable an alert
### `POST /api/alerts/alert/{id}/_enable`: Enable an alert

Params:

|Property|Description|Type|
|---|---|---|
|id|The id of the alert you're trying to enable.|string|

### `POST /api/alert/{id}/_disable`: Disable an alert
### `POST /api/alerts/alert/{id}/_disable`: Disable an alert

Params:

|Property|Description|Type|
|---|---|---|
|id|The id of the alert you're trying to disable.|string|

### `POST /api/alert/{id}/_mute_all`: Mute all alert instances
### `POST /api/alerts/alert/{id}/_mute_all`: Mute all alert instances

Params:

|Property|Description|Type|
|---|---|---|
|id|The id of the alert you're trying to mute all alert instances for.|string|

### `POST /api/alert/{alertId}/alert_instance/{alertInstanceId}/_mute`: Mute alert instance
### `POST /api/alerts/alert/{alert_id}/alert_instance/{alert_instance_id}/_mute`: Mute alert instance

Params:

Expand All @@ -453,15 +453,15 @@ Params:
|alertId|The id of the alert you're trying to mute an instance for.|string|
|alertInstanceId|The instance id of the alert instance you're trying to mute.|string|

### `POST /api/alert/{id}/_unmute_all`: Unmute all alert instances
### `POST /api/alerts/alert/{id}/_unmute_all`: Unmute all alert instances

Params:

|Property|Description|Type|
|---|---|---|
|id|The id of the alert you're trying to unmute all alert instances for.|string|

### `POST /api/alert/{alertId}/alert_instance/{alertInstanceId}/_unmute`: Unmute an alert instance
### `POST /api/alerts/alert/{alertId}/alert_instance/{alertInstanceId}/_unmute`: Unmute an alert instance

Params:

Expand All @@ -470,7 +470,7 @@ Params:
|alertId|The id of the alert you're trying to unmute an instance for.|string|
|alertInstanceId|The instance id of the alert instance you're trying to unmute.|string|

### `POST /api/alert/{id}/_update_api_key`: Update alert API key
### `POST /api/alerts/alert/{id}/_update_api_key`: Update alert API key

|Property|Description|Type|
|---|---|---|
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 @@ -20,4 +20,4 @@ export interface AlertingFrameworkHealth {
hasPermanentEncryptionKey: boolean;
}

export const BASE_ALERT_API_PATH = '/api/alert';
export const BASE_ALERT_API_PATH = '/api/alerts';
12 changes: 6 additions & 6 deletions x-pack/plugins/alerting/public/alert_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('loadAlertTypes', () => {
expect(result).toEqual(resolvedValue);
expect(http.get.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"/api/alert/types",
"/api/alerts/list_alert_types",
]
`);
});
Expand All @@ -53,7 +53,7 @@ describe('loadAlertType', () => {

expect(http.get.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"/api/alert/types",
"/api/alerts/list_alert_types",
]
`);
});
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('loadAlert', () => {
http.get.mockResolvedValueOnce(resolvedValue);

expect(await loadAlert({ http, alertId })).toEqual(resolvedValue);
expect(http.get).toHaveBeenCalledWith(`/api/alert/${alertId}`);
expect(http.get).toHaveBeenCalledWith(`/api/alerts/alert/${alertId}`);
});
});

Expand All @@ -130,7 +130,7 @@ describe('loadAlertState', () => {
http.get.mockResolvedValueOnce(resolvedValue);

expect(await loadAlertState({ http, alertId })).toEqual(resolvedValue);
expect(http.get).toHaveBeenCalledWith(`/api/alert/${alertId}/state`);
expect(http.get).toHaveBeenCalledWith(`/api/alerts/alert/${alertId}/state`);
});

test('should parse AlertInstances', async () => {
Expand Down Expand Up @@ -167,14 +167,14 @@ describe('loadAlertState', () => {
},
},
});
expect(http.get).toHaveBeenCalledWith(`/api/alert/${alertId}/state`);
expect(http.get).toHaveBeenCalledWith(`/api/alerts/alert/${alertId}/state`);
});

test('should handle empty response from api', async () => {
const alertId = uuid.v4();
http.get.mockResolvedValueOnce('');

expect(await loadAlertState({ http, alertId })).toEqual({});
expect(http.get).toHaveBeenCalledWith(`/api/alert/${alertId}/state`);
expect(http.get).toHaveBeenCalledWith(`/api/alerts/alert/${alertId}/state`);
});
});
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 @@ -16,7 +16,7 @@ import { BASE_ALERT_API_PATH, alertStateSchema } from '../common';
import { Alert, AlertType, AlertTaskState } from '../common';

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

export async function loadAlertType({
Expand All @@ -27,7 +27,7 @@ export async function loadAlertType({
id: AlertType['id'];
}): Promise<AlertType> {
const maybeAlertType = findFirst<AlertType>((type) => type.id === id)(
await http.get(`${BASE_ALERT_API_PATH}/types`)
await http.get(`${BASE_ALERT_API_PATH}/list_alert_types`)
);
if (isNone(maybeAlertType)) {
throw new Error(
Expand All @@ -49,7 +49,7 @@ export async function loadAlert({
http: HttpSetup;
alertId: string;
}): Promise<Alert> {
return await http.get(`${BASE_ALERT_API_PATH}/${alertId}`);
return await http.get(`${BASE_ALERT_API_PATH}/alert/${alertId}`);
}

type EmptyHttpResponse = '';
Expand All @@ -61,7 +61,7 @@ export async function loadAlertState({
alertId: string;
}): Promise<AlertTaskState> {
return await http
.get(`${BASE_ALERT_API_PATH}/${alertId}/state`)
.get(`${BASE_ALERT_API_PATH}/alert/${alertId}/state`)
.then((state: AlertTaskState | EmptyHttpResponse) => (state ? state : {}))
.then((state: AlertTaskState) => {
return pipe(
Expand Down
47 changes: 24 additions & 23 deletions x-pack/plugins/alerting/server/alerts_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,29 @@ interface ConstructorOptions {
preconfiguredActions: PreConfiguredAction[];
}

export interface FindOptions {
options?: {
perPage?: number;
page?: number;
search?: string;
defaultSearchOperator?: 'AND' | 'OR';
searchFields?: string[];
sortField?: string;
sortOrder?: string;
hasReference?: {
type: string;
id: string;
};
fields?: string[];
filter?: string;
export interface MuteOptions extends IndexType {
alertId: string;
alertInstanceId: string;
}

export interface FindOptions extends IndexType {
perPage?: number;
page?: number;
search?: string;
defaultSearchOperator?: 'AND' | 'OR';
searchFields?: string[];
sortField?: string;
sortOrder?: string;
hasReference?: {
type: string;
id: string;
};
fields?: string[];
filter?: string;
}

interface IndexType {
[key: string]: unknown;
}

export interface FindResult {
Expand Down Expand Up @@ -226,7 +233,7 @@ export class AlertsClient {
}
}

public async find({ options = {} }: FindOptions = {}): Promise<FindResult> {
public async find(options: FindOptions = {}): Promise<FindResult> {
const {
page,
per_page: perPage,
Expand Down Expand Up @@ -534,13 +541,7 @@ export class AlertsClient {
});
}

public async muteInstance({
alertId,
alertInstanceId,
}: {
alertId: string;
alertInstanceId: string;
}) {
public async muteInstance({ alertId, alertInstanceId }: MuteOptions) {
const { attributes, version } = await this.savedObjectsClient.get<Alert>('alert', alertId);
const mutedInstanceIds = attributes.mutedInstanceIds || [];
if (!attributes.muteAll && !mutedInstanceIds.includes(alertInstanceId)) {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/routes/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('createAlertRoute', () => {

const [config, handler] = router.post.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alert"`);
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert"`);
expect(config.options).toMatchInlineSnapshot(`
Object {
"tags": Array [
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/routes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const bodySchema = schema.object({
export const createAlertRoute = (router: IRouter, licenseState: LicenseState) => {
router.post(
{
path: BASE_ALERT_API_PATH,
path: `${BASE_ALERT_API_PATH}/alert`,
validate: {
body: bodySchema,
},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/routes/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('deleteAlertRoute', () => {

const [config, handler] = router.delete.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alert/{id}"`);
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}"`);
expect(config.options).toMatchInlineSnapshot(`
Object {
"tags": Array [
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/routes/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const paramSchema = schema.object({
export const deleteAlertRoute = (router: IRouter, licenseState: LicenseState) => {
router.delete(
{
path: `${BASE_ALERT_API_PATH}/{id}`,
path: `${BASE_ALERT_API_PATH}/alert/{id}`,
validate: {
params: paramSchema,
},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/routes/disable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('disableAlertRoute', () => {

const [config, handler] = router.post.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alert/{id}/_disable"`);
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/_disable"`);
expect(config.options).toMatchInlineSnapshot(`
Object {
"tags": Array [
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/routes/disable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const paramSchema = schema.object({
export const disableAlertRoute = (router: IRouter, licenseState: LicenseState) => {
router.post(
{
path: `${BASE_ALERT_API_PATH}/{id}/_disable`,
path: `${BASE_ALERT_API_PATH}/alert/{id}/_disable`,
validate: {
params: paramSchema,
},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/routes/enable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('enableAlertRoute', () => {

const [config, handler] = router.post.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alert/{id}/_enable"`);
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/_enable"`);
expect(config.options).toMatchInlineSnapshot(`
Object {
"tags": Array [
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/routes/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const paramSchema = schema.object({
export const enableAlertRoute = (router: IRouter, licenseState: LicenseState) => {
router.post(
{
path: `${BASE_ALERT_API_PATH}/{id}/_enable`,
path: `${BASE_ALERT_API_PATH}/alert/{id}/_enable`,
validate: {
params: paramSchema,
},
Expand Down
Loading