Skip to content

Commit

Permalink
[RAM] Add HTTP versioning to resolve, snooze, and unsnooze APIs (elas…
Browse files Browse the repository at this point in the history
…tic#168886)

## Summary

**REOPENED version of elastic#163359, git
history got too complicated and triggered too many codeowners**

Part of elastic#157883

Converts `_resolve`, `_snooze`, `_unsnooze` to new HTTP versioned model


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
Zacqary and kibanamachine authored Oct 31, 2023
1 parent 3cf19b2 commit ce430e5
Show file tree
Hide file tree
Showing 89 changed files with 1,059 additions and 561 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export const rRuleResponseSchema = schema.object({
byweekday: schema.maybe(schema.arrayOf(schema.oneOf([schema.string(), schema.number()]))),
bymonth: schema.maybe(schema.arrayOf(schema.number())),
bysetpos: schema.maybe(schema.arrayOf(schema.number())),
bymonthday: schema.arrayOf(schema.number()),
byyearday: schema.arrayOf(schema.number()),
byweekno: schema.arrayOf(schema.number()),
byhour: schema.arrayOf(schema.number()),
byminute: schema.arrayOf(schema.number()),
bysecond: schema.arrayOf(schema.number()),
bymonthday: schema.maybe(schema.arrayOf(schema.number())),
byyearday: schema.maybe(schema.arrayOf(schema.number())),
byweekno: schema.maybe(schema.arrayOf(schema.number())),
byhour: schema.maybe(schema.arrayOf(schema.number())),
byminute: schema.maybe(schema.arrayOf(schema.number())),
bysecond: schema.maybe(schema.arrayOf(schema.number())),
});
14 changes: 2 additions & 12 deletions x-pack/plugins/alerting/common/routes/rule/apis/bulk_edit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,14 @@
* 2.0.
*/

export {
ruleSnoozeScheduleSchema,
bulkEditOperationsSchema,
bulkEditRulesRequestBodySchema,
} from './schemas/latest';
export type {
RuleSnoozeSchedule,
BulkEditRulesRequestBody,
BulkEditRulesResponse,
} from './types/latest';
export { bulkEditOperationsSchema, bulkEditRulesRequestBodySchema } from './schemas/latest';
export type { BulkEditRulesRequestBody, BulkEditRulesResponse } from './types/latest';

export {
ruleSnoozeScheduleSchema as ruleSnoozeScheduleSchemaV1,
bulkEditOperationsSchema as bulkEditOperationsSchemaV1,
bulkEditRulesRequestBodySchema as bulkEditRulesRequestBodySchemaV1,
} from './schemas/v1';
export type {
RuleSnoozeSchedule as RuleSnoozeScheduleV1,
BulkEditRulesRequestBody as BulkEditRulesRequestBodyV1,
BulkEditRulesResponse as BulkEditRulesResponseV1,
} from './types/v1';
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,10 @@
*/

import { schema } from '@kbn/config-schema';
import { validateDurationV1, validateNotifyWhenV1 } from '../../../validation';
import { validateSnoozeScheduleV1 } from '../validation';
import { validateDurationV1 } from '../../../validation';
import { rRuleRequestSchemaV1 } from '../../../../r_rule';
import { ruleNotifyWhenV1 } from '../../../response';

const notifyWhenSchema = schema.oneOf(
[
schema.literal(ruleNotifyWhenV1.CHANGE),
schema.literal(ruleNotifyWhenV1.ACTIVE),
schema.literal(ruleNotifyWhenV1.THROTTLE),
],
{ validate: validateNotifyWhenV1 }
);
import { notifyWhenSchemaV1, scheduleIdsSchemaV1 } from '../../../response';
import { ruleSnoozeScheduleSchemaV1 } from '../../../request';

export const scheduleIdsSchema = schema.maybe(schema.arrayOf(schema.string()));

Expand All @@ -28,15 +19,6 @@ export const ruleSnoozeScheduleSchema = schema.object({
rRule: rRuleRequestSchemaV1,
});

const ruleSnoozeScheduleSchemaWithValidation = schema.object(
{
id: schema.maybe(schema.string()),
duration: schema.number(),
rRule: rRuleRequestSchemaV1,
},
{ validate: validateSnoozeScheduleV1 }
);

const ruleActionSchema = schema.object({
group: schema.string(),
id: schema.string(),
Expand All @@ -46,7 +28,7 @@ const ruleActionSchema = schema.object({
schema.object({
summary: schema.boolean(),
throttle: schema.nullable(schema.string()),
notifyWhen: notifyWhenSchema,
notifyWhen: notifyWhenSchemaV1,
})
),
});
Expand Down Expand Up @@ -80,17 +62,17 @@ export const bulkEditOperationsSchema = schema.arrayOf(
schema.object({
operation: schema.literal('set'),
field: schema.literal('notifyWhen'),
value: notifyWhenSchema,
value: notifyWhenSchemaV1,
}),
schema.object({
operation: schema.oneOf([schema.literal('set')]),
field: schema.literal('snoozeSchedule'),
value: ruleSnoozeScheduleSchemaWithValidation,
value: ruleSnoozeScheduleSchemaV1,
}),
schema.object({
operation: schema.oneOf([schema.literal('delete')]),
field: schema.literal('snoozeSchedule'),
value: schema.maybe(scheduleIdsSchema),
value: schema.maybe(scheduleIdsSchemaV1),
}),
schema.object({
operation: schema.literal('set'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
*/
import type { TypeOf } from '@kbn/config-schema';
import { RuleParamsV1, RuleResponseV1 } from '../../../response';
import { ruleSnoozeScheduleSchemaV1, bulkEditRulesRequestBodySchemaV1 } from '..';
import { bulkEditRulesRequestBodySchemaV1 } from '..';

export type RuleSnoozeSchedule = TypeOf<typeof ruleSnoozeScheduleSchemaV1>;
export type BulkEditRulesRequestBody = TypeOf<typeof bulkEditRulesRequestBodySchemaV1>;

interface BulkEditActionSkippedResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

export {
notifyWhenSchema,
actionFrequencySchema,
actionAlertsFilterSchema,
actionSchema,
Expand All @@ -23,7 +22,6 @@ export type {
} from './types/latest';

export {
notifyWhenSchema as notifyWhenSchemaV1,
actionFrequencySchema as actionFrequencySchemaV1,
actionAlertsFilterSchema as actionAlertsFilterSchemaV1,
actionSchema as actionSchemaV1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,12 @@
*/

import { schema } from '@kbn/config-schema';
import { ruleNotifyWhenV1 } from '../../../response';
import {
validateNotifyWhenV1,
validateDurationV1,
validateHoursV1,
validateTimezoneV1,
} from '../../../validation';

export const notifyWhenSchema = schema.oneOf(
[
schema.literal(ruleNotifyWhenV1.CHANGE),
schema.literal(ruleNotifyWhenV1.ACTIVE),
schema.literal(ruleNotifyWhenV1.THROTTLE),
],
{ validate: validateNotifyWhenV1 }
);
import { validateDurationV1, validateHoursV1, validateTimezoneV1 } from '../../../validation';
import { notifyWhenSchemaV1 } from '../../../response';

export const actionFrequencySchema = schema.object({
summary: schema.boolean(),
notify_when: notifyWhenSchema,
notify_when: notifyWhenSchemaV1,
throttle: schema.nullable(schema.string({ validate: validateDurationV1 })),
});

Expand Down Expand Up @@ -91,7 +77,7 @@ export const createBodySchema = schema.object({
interval: schema.string({ validate: validateDurationV1 }),
}),
actions: schema.arrayOf(actionSchema, { defaultValue: [] }),
notify_when: schema.maybe(schema.nullable(notifyWhenSchema)),
notify_when: schema.maybe(schema.nullable(notifyWhenSchemaV1)),
});

export const createParamsSchema = schema.object({
Expand Down
14 changes: 14 additions & 0 deletions x-pack/plugins/alerting/common/routes/rule/apis/resolve/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { resolveParamsSchema } from './schemas/latest';

export { resolveParamsSchema as resolveParamsSchemaV1 } from './schemas/v1';

export type { ResolveRuleResponse } from './types/latest';

export type { ResolveRuleResponse as ResolveRuleResponseV1 } from './types/v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { schema } from '@kbn/config-schema';

export const resolveParamsSchema = schema.object({
id: schema.string(),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { RuleParamsV1, RuleResponseV1 } from '../../../response';

export interface ResolveRuleResponse<Params extends RuleParamsV1 = never> {
body: RuleResponseV1<Params>;
}
13 changes: 13 additions & 0 deletions x-pack/plugins/alerting/common/routes/rule/apis/snooze/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { snoozeParamsSchema, snoozeBodySchema } from './schemas/latest';

export {
snoozeParamsSchema as snoozeParamsSchemaV1,
snoozeBodySchema as snoozeBodySchemaV1,
} from './schemas/v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { schema } from '@kbn/config-schema';
import { ruleSnoozeScheduleSchemaV1 } from '../../../request';

export const snoozeParamsSchema = schema.object({
id: schema.string(),
});

export const snoozeBodySchema = schema.object({
snooze_schedule: ruleSnoozeScheduleSchemaV1,
});
13 changes: 13 additions & 0 deletions x-pack/plugins/alerting/common/routes/rule/apis/unsnooze/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { unsnoozeParamsSchema, unsnoozeBodySchema } from './schemas/latest';

export {
unsnoozeParamsSchema as unsnoozeParamsSchemaV1,
unsnoozeBodySchema as unsnoozeBodySchemaV1,
} from './schemas/v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { schema } from '@kbn/config-schema';

export const unsnoozeParamsSchema = schema.object({
id: schema.string(),
});

const scheduleIdsSchema = schema.maybe(schema.arrayOf(schema.string()));

export const unsnoozeBodySchema = schema.object({
schedule_ids: scheduleIdsSchema,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './v1';
38 changes: 38 additions & 0 deletions x-pack/plugins/alerting/common/routes/rule/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export {
ruleNotifyWhen,
ruleLastRunOutcomeValues,
ruleExecutionStatusValues,
ruleExecutionStatusErrorReason,
ruleExecutionStatusWarningReason,
} from './constants/latest';

export type {
RuleNotifyWhen,
RuleLastRunOutcomeValues,
RuleExecutionStatusValues,
RuleExecutionStatusErrorReason,
RuleExecutionStatusWarningReason,
} from './constants/latest';

export {
ruleNotifyWhen as ruleNotifyWhenV1,
ruleLastRunOutcomeValues as ruleLastRunOutcomeValuesV1,
ruleExecutionStatusValues as ruleExecutionStatusValuesV1,
ruleExecutionStatusErrorReason as ruleExecutionStatusErrorReasonV1,
ruleExecutionStatusWarningReason as ruleExecutionStatusWarningReasonV1,
} from './constants/v1';

export type {
RuleNotifyWhen as RuleNotifyWhenV1,
RuleLastRunOutcomeValues as RuleLastRunOutcomeValuesV1,
RuleExecutionStatusValues as RuleExecutionStatusValuesV1,
RuleExecutionStatusErrorReason as RuleExecutionStatusErrorReasonV1,
RuleExecutionStatusWarningReason as RuleExecutionStatusWarningReasonV1,
} from './constants/v1';
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
* 2.0.
*/

export { validateSnoozeSchedule } from './validate_snooze_schedule/latest';
export { ruleSnoozeScheduleSchema } from './schemas/latest';

export { validateSnoozeSchedule as validateSnoozeScheduleV1 } from './validate_snooze_schedule/v1';
export { ruleSnoozeScheduleSchema as ruleSnoozeScheduleSchemaV1 } from './schemas/v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './v1';
19 changes: 19 additions & 0 deletions x-pack/plugins/alerting/common/routes/rule/request/schemas/v1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { schema } from '@kbn/config-schema';
import { rRuleRequestSchemaV1 } from '../../../r_rule';
import { validateSnoozeScheduleV1 } from '../../validation';

export const ruleSnoozeScheduleSchema = schema.object(
{
id: schema.maybe(schema.string()),
duration: schema.number(),
rRule: rRuleRequestSchemaV1,
},
{ validate: validateSnoozeScheduleV1 }
);
Loading

0 comments on commit ce430e5

Please sign in to comment.