Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2cf3878
Add rrule schema to task schedule with intermediate release
ersin-erdal Apr 28, 2025
dacbfc6
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine Apr 28, 2025
c5069c7
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Apr 28, 2025
38bffd6
modify schema and remove mappings
ersin-erdal Apr 29, 2025
f846dbc
Merge branch '216308-add-rrule-to-task-model-versions' of github.com:…
ersin-erdal Apr 29, 2025
d24788c
fix mappings_addition
ersin-erdal Apr 29, 2025
4d30c93
remove mappings from the packages
ersin-erdal Apr 29, 2025
6ca6280
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine Apr 29, 2025
6b2e3ef
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Apr 29, 2025
a1b4481
remove rrule mapping
ersin-erdal Apr 30, 2025
be48567
fix interval mapping
ersin-erdal Apr 30, 2025
40c26ab
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine Apr 30, 2025
4478f57
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Apr 30, 2025
c57f65e
align rrule validation with the ones in alerting
ersin-erdal Apr 30, 2025
768160a
Merge branch '216308-add-rrule-to-task-model-versions' of github.com:…
ersin-erdal Apr 30, 2025
622cbc0
Merge branch 'main' into 216308-add-rrule-to-task-model-versions
ersin-erdal Apr 30, 2025
66b6bfc
remove dynamic:false
ersin-erdal May 1, 2025
39b9d76
Merge branch '216308-add-rrule-to-task-model-versions' of github.com:…
ersin-erdal May 1, 2025
73f1df1
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine May 1, 2025
8aea7eb
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine May 1, 2025
9563728
add schema.maybe(
ersin-erdal May 2, 2025
ae0e29d
Merge branch '216308-add-rrule-to-task-model-versions' of github.com:…
ersin-erdal May 2, 2025
b970cc2
revert schema.maybe
ersin-erdal May 2, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"synthetics-private-location": "27aaa44f792f70b734905e44e3e9b56bbeac7b86",
"synthetics-privates-locations": "36036b881524108c7327fe14bd224c6e4d972cb5",
"tag": "87f21f07df9cc37001b15a26e413c18f50d1fbfe",
"task": "f07a047b32e52f6c2bf569764536f4378af47e3f",
"task": "4bd8e19960b83c88f3cdf766ace268c081a1c619",
"telemetry": "3b3b89cf411a2a2e60487cef6ccdbc5df691aeb9",
"threshold-explorer-view": "5e2388a6835cec3c68c98b450cd267d66cce925f",
"ui-metric": "410a8ad28e0f44b161c960ff0ce950c712b17c52",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
*/

import type { SavedObjectsModelVersionMap } from '@kbn/core-saved-objects-server';
import { taskSchemaV1, taskSchemaV2, taskSchemaV3, taskSchemaV4 } from '../schemas/task';
import {
taskSchemaV1,
taskSchemaV2,
taskSchemaV3,
taskSchemaV4,
taskSchemaV5,
} from '../schemas/task';

// IMPORTANT!!!
// When adding new model versions, make sure to manually test
Expand Down Expand Up @@ -71,4 +77,11 @@ export const taskModelVersions: SavedObjectsModelVersionMap = {
create: taskSchemaV4,
},
},
'5': {
changes: [],
schemas: {
forwardCompatibility: taskSchemaV5.extends({}, { unknowns: 'ignore' }),
create: taskSchemaV5,
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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 { Frequency } from '@kbn/rrule';
import moment from 'moment-timezone';

function validateTimezone(timezone: string) {
if (moment.tz.zone(timezone) != null) {
return;
}

return 'string is not a valid timezone: ' + timezone;
}

const validateRecurrenceByWeekday = (array: string[]) => {
if (array.length === 0) {
return 'rRule byweekday cannot be empty';
}

const byWeekDayRegex = new RegExp('^(((\\+|-)[1-4])?(MO|TU|WE|TH|FR|SA|SU))$');
const invalidDays: string[] = [];

array.forEach((day) => {
if (!byWeekDayRegex.test(day)) {
invalidDays.push(day);
}
});

if (invalidDays.length > 0) {
return `invalid byweekday values in rRule byweekday: ${invalidDays.join(',')}`;
}
};

const rruleCommon = schema.object({
freq: schema.maybe(
schema.oneOf([
schema.literal(0),
schema.literal(1),
schema.literal(2),
schema.literal(3),
schema.literal(4),
schema.literal(5),
schema.literal(6),
])
),
interval: schema.maybe(
schema.number({
validate: (interval: number) => {
if (!Number.isInteger(interval)) {
return 'rRule interval must be an integer greater than 0';
}
},
min: 1,
})
),
tzid: schema.string({ validate: validateTimezone, defaultValue: 'UTC' }),
});

const byminute = schema.maybe(schema.arrayOf(schema.number({ min: 0, max: 59 }), { minSize: 1 }));
const byhour = schema.maybe(schema.arrayOf(schema.number({ min: 0, max: 23 }), { minSize: 1 }));
const byweekday = schema.maybe(
schema.arrayOf(schema.string(), {
minSize: 1,
validate: validateRecurrenceByWeekday,
})
);
const bymonthday = schema.maybe(schema.arrayOf(schema.number({ min: 1, max: 31 }), { minSize: 1 }));

const rruleMonthly = rruleCommon.extends({
freq: schema.literal(Frequency.MONTHLY),
byhour,
byminute,
byweekday,
bymonthday,
});

const rruleWeekly = rruleCommon.extends({
freq: schema.literal(Frequency.WEEKLY),
byhour,
byminute,
byweekday,
bymonthday: schema.never(),
});

const rruleDaily = rruleCommon.extends({
freq: schema.literal(Frequency.DAILY),
byhour,
byminute,
byweekday,
bymonthday: schema.never(),
});

export const rruleSchedule = schema.oneOf([rruleMonthly, rruleWeekly, rruleDaily]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about having one schema and do feq: schema.oneOf[schema.literal(Frequency.DAILY), schema.literal(Frequency.WEEKLY), schema.literal(Frequency.MONTHLY].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I grouped them because some configurations should not be used with some frequency types, it looks the same for now but when we add hourly and minutely we will not allow byweekday and byhour together as they break the library.

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

import { schema } from '@kbn/config-schema';
import { isInterval } from '../../lib/intervals';
import { rruleSchedule } from './rrule';

export function validateDuration(duration: string) {
if (!isInterval(duration)) {
Expand Down Expand Up @@ -64,3 +65,16 @@ export const taskSchemaV4 = taskSchemaV3.extends({
})
),
});

export const taskSchemaV5 = taskSchemaV4.extends({
schedule: schema.maybe(
schema.oneOf([
schema.object({
interval: schema.string({ validate: validateDuration }),
}),
schema.object({
rrule: rruleSchedule,
}),
])
),
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@kbn/encrypted-saved-objects-shared",
"@kbn/core-saved-objects-api-server-mocks",
"@kbn/core-http-server-utils",
"@kbn/rrule"
],
"exclude": ["target/**/*"]
}