-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[RAM][HTTP Versioning] Version Rule Bulk Edit Endpoint #161912
Merged
JiaweiWu
merged 7 commits into
elastic:main
from
JiaweiWu:issue-161395-bulk-edit-endpoint-versioning
Jul 25, 2023
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fd85b66
Initial commit
JiaweiWu da9f2d8
Merge branch 'main' into issue-161395-bulk-edit-endpoint-versioning
kibanamachine bdd7b37
Fix E2E test
JiaweiWu 50d8e5a
Merge branch 'main' into issue-161395-bulk-edit-endpoint-versioning
kibanamachine abfd8fa
Fix unit tests
JiaweiWu 0fe9e01
Fix naming
JiaweiWu 8ce4b83
Fix merge conflict
JiaweiWu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
|
||
export { rRuleSchema } from './schemas/latest'; | ||
export type { RRule } from './types/latest'; | ||
|
||
export { rRuleSchema as rRuleSchemaV1 } from './schemas/v1'; | ||
export type { RRule as RRuleV1 } from './types/latest'; |
File renamed without changes.
51 changes: 51 additions & 0 deletions
51
x-pack/plugins/alerting/common/routes/r_rule/schemas/v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 { | ||
validateStartDateV1, | ||
validateEndDateV1, | ||
createValidateRecurrenceByV1, | ||
} from '../validation'; | ||
|
||
export const rRuleSchema = schema.object({ | ||
dtstart: schema.string({ validate: validateStartDateV1 }), | ||
tzid: schema.string(), | ||
freq: schema.maybe( | ||
schema.oneOf([schema.literal(0), schema.literal(1), schema.literal(2), schema.literal(3)]) | ||
), | ||
interval: schema.maybe( | ||
schema.number({ | ||
validate: (interval: number) => { | ||
if (interval < 1) return 'rRule interval must be > 0'; | ||
}, | ||
}) | ||
), | ||
until: schema.maybe(schema.string({ validate: validateEndDateV1 })), | ||
count: schema.maybe( | ||
schema.number({ | ||
validate: (count: number) => { | ||
if (count < 1) return 'rRule count must be > 0'; | ||
}, | ||
}) | ||
), | ||
byweekday: schema.maybe( | ||
schema.arrayOf(schema.string(), { | ||
validate: createValidateRecurrenceByV1('byweekday'), | ||
}) | ||
), | ||
bymonthday: schema.maybe( | ||
schema.arrayOf(schema.number(), { | ||
validate: createValidateRecurrenceByV1('bymonthday'), | ||
}) | ||
), | ||
bymonth: schema.maybe( | ||
schema.arrayOf(schema.number(), { | ||
validate: createValidateRecurrenceByV1('bymonth'), | ||
}) | ||
), | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* 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 type { TypeOf } from '@kbn/config-schema'; | ||
import { rRuleSchemaV1 } from '..'; | ||
|
||
export type RRule = TypeOf<typeof rRuleSchemaV1>; |
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/alerting/common/routes/r_rule/validation/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { validateStartDate } from './validate_start_date/latest'; | ||
export { validateEndDate } from './validate_end_date/latest'; | ||
export { createValidateRecurrenceBy } from './validate_recurrence_by/latest'; | ||
|
||
export { validateStartDate as validateStartDateV1 } from './validate_start_date/v1'; | ||
export { validateEndDate as validateEndDateV1 } from './validate_end_date/v1'; | ||
export { createValidateRecurrenceBy as createValidateRecurrenceByV1 } from './validate_recurrence_by/v1'; |
File renamed without changes.
13 changes: 13 additions & 0 deletions
13
x-pack/plugins/alerting/common/routes/r_rule/validation/validate_end_date/v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 const validateEndDate = (date: string) => { | ||
const parsedValue = Date.parse(date); | ||
if (isNaN(parsedValue)) return `Invalid date: ${date}`; | ||
if (parsedValue <= Date.now()) return `Invalid snooze date as it is in the past: ${date}`; | ||
return; | ||
}; |
File renamed without changes.
16 changes: 16 additions & 0 deletions
16
x-pack/plugins/alerting/common/routes/r_rule/validation/validate_recurrence_by/v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* 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 const validateRecurrenceBy = <T>(name: string, array: T[]) => { | ||
if (array.length === 0) { | ||
return `rRule ${name} cannot be empty`; | ||
} | ||
}; | ||
|
||
export const createValidateRecurrenceBy = <T>(name: string) => { | ||
return (array: T[]) => validateRecurrenceBy(name, array); | ||
}; |
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
x-pack/plugins/alerting/common/routes/r_rule/validation/validate_start_date/v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
|
||
export const validateStartDate = (date: string) => { | ||
const parsedValue = Date.parse(date); | ||
if (isNaN(parsedValue)) return `Invalid date: ${date}`; | ||
return; | ||
}; |
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/alerting/common/routes/rule/apis/bulk_edit/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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 { | ||
ruleSnoozeScheduleSchema, | ||
bulkEditOperationsSchema, | ||
bulkEditRulesRequestBodySchema, | ||
} from './schemas/latest'; | ||
export type { | ||
RuleSnoozeSchedule, | ||
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'; |
File renamed without changes.
107 changes: 107 additions & 0 deletions
107
x-pack/plugins/alerting/common/routes/rule/apis/bulk_edit/schemas/v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* 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 { validateDurationV1, validateNotifyWhenV1 } from '../../../validation'; | ||
import { validateSnoozeScheduleV1 } from '../validation'; | ||
import { rRuleSchemaV1 } 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 } | ||
); | ||
|
||
export const scheduleIdsSchema = schema.maybe(schema.arrayOf(schema.string())); | ||
|
||
export const ruleSnoozeScheduleSchema = schema.object({ | ||
id: schema.maybe(schema.string()), | ||
duration: schema.number(), | ||
rRule: rRuleSchemaV1, | ||
}); | ||
|
||
const ruleSnoozeScheduleSchemaWithValidation = schema.object( | ||
{ | ||
id: schema.maybe(schema.string()), | ||
duration: schema.number(), | ||
rRule: rRuleSchemaV1, | ||
}, | ||
{ validate: validateSnoozeScheduleV1 } | ||
); | ||
|
||
const ruleActionSchema = schema.object({ | ||
group: schema.string(), | ||
id: schema.string(), | ||
params: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }), | ||
uuid: schema.maybe(schema.string()), | ||
frequency: schema.maybe( | ||
schema.object({ | ||
summary: schema.boolean(), | ||
throttle: schema.nullable(schema.string()), | ||
notifyWhen: notifyWhenSchema, | ||
}) | ||
), | ||
}); | ||
|
||
export const bulkEditOperationsSchema = schema.arrayOf( | ||
schema.oneOf([ | ||
schema.object({ | ||
operation: schema.oneOf([ | ||
schema.literal('add'), | ||
schema.literal('delete'), | ||
schema.literal('set'), | ||
]), | ||
field: schema.literal('tags'), | ||
value: schema.arrayOf(schema.string()), | ||
}), | ||
schema.object({ | ||
operation: schema.oneOf([schema.literal('add'), schema.literal('set')]), | ||
field: schema.literal('actions'), | ||
value: schema.arrayOf(ruleActionSchema), | ||
}), | ||
schema.object({ | ||
operation: schema.literal('set'), | ||
field: schema.literal('schedule'), | ||
value: schema.object({ interval: schema.string({ validate: validateDurationV1 }) }), | ||
}), | ||
schema.object({ | ||
operation: schema.literal('set'), | ||
field: schema.literal('throttle'), | ||
value: schema.nullable(schema.string()), | ||
}), | ||
schema.object({ | ||
operation: schema.literal('set'), | ||
field: schema.literal('notifyWhen'), | ||
value: notifyWhenSchema, | ||
}), | ||
schema.object({ | ||
operation: schema.oneOf([schema.literal('set')]), | ||
field: schema.literal('snoozeSchedule'), | ||
value: ruleSnoozeScheduleSchemaWithValidation, | ||
}), | ||
schema.object({ | ||
operation: schema.oneOf([schema.literal('delete')]), | ||
field: schema.literal('snoozeSchedule'), | ||
value: schema.maybe(scheduleIdsSchema), | ||
}), | ||
schema.object({ | ||
operation: schema.literal('set'), | ||
field: schema.literal('apiKey'), | ||
}), | ||
]), | ||
{ minSize: 1 } | ||
); | ||
|
||
export const bulkEditRulesRequestBodySchema = schema.object({ | ||
filter: schema.maybe(schema.string()), | ||
ids: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })), | ||
operations: bulkEditOperationsSchema, | ||
}); |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/common/routes/rule/apis/bulk_edit/types/latest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
36 changes: 36 additions & 0 deletions
36
x-pack/plugins/alerting/common/routes/rule/apis/bulk_edit/types/v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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 type { TypeOf } from '@kbn/config-schema'; | ||
import { RuleParamsV1, RuleResponseV1 } from '../../../response'; | ||
import { ruleSnoozeScheduleSchemaV1, bulkEditRulesRequestBodySchemaV1 } from '..'; | ||
|
||
export type RuleSnoozeSchedule = TypeOf<typeof ruleSnoozeScheduleSchemaV1>; | ||
export type BulkEditRulesRequestBody = TypeOf<typeof bulkEditRulesRequestBodySchemaV1>; | ||
|
||
interface BulkEditActionSkippedResult { | ||
id: RuleResponseV1['id']; | ||
name?: RuleResponseV1['name']; | ||
skip_reason: 'RULE_NOT_MODIFIED'; | ||
} | ||
|
||
interface BulkEditOperationError { | ||
message: string; | ||
status?: number; | ||
rule: { | ||
id: string; | ||
name: string; | ||
}; | ||
} | ||
|
||
export interface BulkEditRulesResponse<Params extends RuleParamsV1 = never> { | ||
body: { | ||
rules: Array<RuleResponseV1<Params>>; | ||
skipped: BulkEditActionSkippedResult[]; | ||
errors: BulkEditOperationError[]; | ||
total: number; | ||
}; | ||
} |
10 changes: 10 additions & 0 deletions
10
x-pack/plugins/alerting/common/routes/rule/apis/bulk_edit/validation/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* 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 { validateSnoozeSchedule } from './validate_snooze_schedule/latest'; | ||
|
||
export { validateSnoozeSchedule as validateSnoozeScheduleV1 } from './validate_snooze_schedule/v1'; |
8 changes: 8 additions & 0 deletions
8
.../alerting/common/routes/rule/apis/bulk_edit/validation/validate_snooze_schedule/latest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
18 changes: 18 additions & 0 deletions
18
...gins/alerting/common/routes/rule/apis/bulk_edit/validation/validate_snooze_schedule/v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { Frequency } from '@kbn/rrule'; | ||
import moment from 'moment'; | ||
import { RuleSnoozeScheduleV1 } from '../..'; | ||
|
||
export const validateSnoozeSchedule = (schedule: RuleSnoozeScheduleV1) => { | ||
const intervalIsDaily = schedule.rRule.freq === Frequency.DAILY; | ||
const durationInDays = moment.duration(schedule.duration, 'milliseconds').asDays(); | ||
if (intervalIsDaily && schedule.rRule.interval && durationInDays >= schedule.rRule.interval) { | ||
return 'Recurrence interval must be longer than the snooze duration'; | ||
} | ||
}; |
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/common/routes/rule/apis/create/schemas/latest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/common/routes/rule/apis/create/types/latest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for information, what's r_rule?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stands for recurrence rule, Its basically a protocol of sorts for communicating schedules with recurrences, we use it for snooze and maintenance windows https://icalendar.org/iCalendar-RFC-5545/3-8-5-3-recurrence-rule.html