Skip to content

Comments

Add rrule schema to task schedule with intermediate release#219429

Merged
ersin-erdal merged 23 commits intoelastic:mainfrom
ersin-erdal:216308-add-rrule-to-task-model-versions
May 2, 2025
Merged

Add rrule schema to task schedule with intermediate release#219429
ersin-erdal merged 23 commits intoelastic:mainfrom
ersin-erdal:216308-add-rrule-to-task-model-versions

Conversation

@ersin-erdal
Copy link
Contributor

@ersin-erdal ersin-erdal commented Apr 28, 2025

Towards: #216308

This PR adds the rrule schema to the task SO with an intermediate release for the following PR:
#217728

@ersin-erdal ersin-erdal added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v9.0.0 backport:version Backport to applied version labels v8.19.0 v9.0.1 labels Apr 28, 2025
@ersin-erdal ersin-erdal marked this pull request as ready for review April 28, 2025 20:05
@ersin-erdal ersin-erdal requested review from a team as code owners April 28, 2025 20:05
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)


const rruleCommon = schema.object({
freq: schema.number(),
interval: schema.number(),
Copy link
Contributor

Choose a reason for hiding this comment

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

should we set a minimum here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

const byminute = schema.maybe(schema.arrayOf(schema.number({ min: 0, max: 59 })));
const byhour = schema.maybe(schema.arrayOf(schema.number({ min: 0, max: 23 })));
const byweekday = schema.maybe(schema.arrayOf(schema.number({ min: 1, max: 7 })));
const bymonthday = schema.maybe(schema.arrayOf(schema.number({ min: 1, max: 31 })));
Copy link
Contributor

Choose a reason for hiding this comment

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

The alerting schema has some validations for these fields (checking for non-empty arrays). Should we add similar validations here? Also, I know we're only supporting a subset of the rRule specification, but should we try to make it as close to the alerting one as possible? For example, here, byweekday is a number that maps to an enum but in the alerting spec, it's a string.

Alerting schema: x-pack/platform/plugins/shared/alerting/common/routes/r_rule/request/schemas/v1.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the min length check but byweekday is interesting as it can take both string and number.
here: x-pack/platform/plugins/shared/alerting/server/saved_objects/schemas/raw_rule/v3.ts

validation in the request schema you shared also accepts numbers between 1-4 in the regex but as string!
Should we stick with it??

Copy link
Contributor Author

@ersin-erdal ersin-erdal Apr 29, 2025

Choose a reason for hiding this comment

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

Btw idk why it is only between 1 and 4! maybe someone confused it with freq since it takes 4 numbers...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK i modified it to cover the both cases: numbers between 1-7 and enums MO, TH etc...
Looks like our rrule lib supports both.

Copy link
Contributor

Choose a reason for hiding this comment

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

cc @cnasikas Any feedback/comments on this schema?

Copy link
Member

@cnasikas cnasikas Apr 30, 2025

Choose a reason for hiding this comment

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

I would advise following the schema as defined in x-pack/platform/plugins/shared/alerting/common/routes/r_rule/request/schemas/v1.ts as closely as possible. The byweekday can be a specific date like MO or -1WE, which can mean the last Wednesday of the month. In the UI this is configured like:

Screenshot 2025-04-30 at 1 07 14 PM

The rrule library can automatically handle this kind of input.

Copy link
Member

Choose a reason for hiding this comment

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

It would be nice if we had a schema in a package where you could import it (future work).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I used the same schemas.

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

Overall looks good! However, I don't think we've quite concluded a related conversation. Would be good to do so before merging.

"interval": {
"type": "keyword"
},
"rrule": {
Copy link
Contributor

Choose a reason for hiding this comment

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

probably don't need it at all, unless we're doing an exists query in the code somewhere currently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed all

bymonthday: schema.never(),
});

export const rruleSchedule = schema.oneOf([rruleMonthly, rruleWeekly, rruleDaily]);
Copy link
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
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.

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

Mappings changes LGTM, did not know you could add dynamic: false after creation like this, TIL

@prodsecmachine
Copy link
Collaborator

prodsecmachine commented May 1, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

LGTM

@ymao1
Copy link
Contributor

ymao1 commented May 1, 2025

@ersin-erdal I have your branch pulled into my scheduled report branch and am reusing these schemas for the scheduled report SO, I'm getting this type error for the rrule definition when it looks like this:

schedule: { rrule: { freq: Frequency.DAILY, interval: 2, tzid: 'UTC' } },

Type '{ freq: Frequency.DAILY; interval: number; tzid: string; }' is not assignable to type 'Mutable<Readonly<{ byhour?: number[] | undefined; byminute?: number[] | undefined; byweekday?: number[] | undefined; bymonthday?: number[] | undefined; } & { freq: Frequency.MONTHLY; interval: number; tzid: string; }> | Readonly<...> | Readonly<...>>'.
  Property 'bymonthday' is missing in type '{ freq: Frequency.DAILY; interval: number; tzid: string; }' but required in type 'Mutable<Readonly<{ byhour?: number[] | undefined; byminute?: number[] | undefined; byweekday?: number[] | undefined; } & { freq: Frequency.DAILY; interval: number; tzid: string; bymonthday: never; }>>'.
rrule.ts[Ln 52, Col 3]: 'bymonthday' is declared here.
task.ts[Ln 64, Col3]: The expected type comes from property 'rrule' which is declared here on type 'Mutable<Readonly<{} & { rrule: Readonly<{ byhour?: number[] | undefined; byminute?: number[] | undefined; byweekday?: number[] | undefined; bymonthday?: number[] | undefined; } & { freq: Frequency.MONTHLY; interval: number; tzid: string; }> | Readonly<...> | Readonly<...>; }>>'

which is confusing because bymonthday is schema.never but is it complaining that it's not defined? any ideas?

@ymao1
Copy link
Contributor

ymao1 commented May 1, 2025

it works when i change it to schema.maybe(schema.never()) but I don't know if that makes sense

@ersin-erdal
Copy link
Contributor Author

it works when i change it to schema.maybe(schema.never()) but I don't know if that makes sense

The only difference between the schemas here and in my other PR is { minSize: 1 } maybe that forces bymonthday to be defined even as undefined

I am adding schema.maybe to it, here as well. just in case.

@ymao1
Copy link
Contributor

ymao1 commented May 2, 2025

I'm deriving the type from the schema using TypeOf...maybe there's a better way of doing that?

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #1 / integrations Endpoint Exceptions "before all" hook for "should add event.module=endpoint to entry if only wildcard operator is present"

Metrics [docs]

✅ unchanged

History

@ersin-erdal ersin-erdal merged commit 65cc416 into elastic:main May 2, 2025
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19, 9.0

https://github.com/elastic/kibana/actions/runs/14796596120

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.19 Backport failed because of merge conflicts
9.0 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 219429

Questions ?

Please refer to the Backport tool documentation

@ersin-erdal
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

ersin-erdal added a commit to ersin-erdal/kibana that referenced this pull request May 2, 2025
…219429)

Towards: elastic#216308

This PR adds the `rrule` schema to the task SO with an intermediate
release for the following PR:
elastic#217728

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 65cc416)

# Conflicts:
#	src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts
ersin-erdal added a commit that referenced this pull request May 5, 2025
…219429) (#219993)

# Backport

This will backport the following commits from `main` to `8.19`:
- [Add rrule schema to task schedule with intermediate release
(#219429)](#219429)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Ersin
Erdal","email":"92688503+ersin-erdal@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-05-02T13:54:00Z","message":"Add
rrule schema to task schedule with intermediate release
(#219429)\n\nTowards: #216308\n\nThis PR adds the `rrule` schema to the
task SO with an intermediate\nrelease for the following
PR:\n#217728\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"65cc4167b57008f5b3577be4476f0932c5c8d278","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","backport:version","v9.1.0","v8.19.0"],"title":"Add
rrule schema to task schedule with intermediate
release","number":219429,"url":"https://github.com/elastic/kibana/pull/219429","mergeCommit":{"message":"Add
rrule schema to task schedule with intermediate release
(#219429)\n\nTowards: #216308\n\nThis PR adds the `rrule` schema to the
task SO with an intermediate\nrelease for the following
PR:\n#217728\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"65cc4167b57008f5b3577be4476f0932c5c8d278"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/219429","number":219429,"mergeCommit":{"message":"Add
rrule schema to task schedule with intermediate release
(#219429)\n\nTowards: #216308\n\nThis PR adds the `rrule` schema to the
task SO with an intermediate\nrelease for the following
PR:\n#217728\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"65cc4167b57008f5b3577be4476f0932c5c8d278"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
…219429)

Towards: elastic#216308

This PR adds the `rrule` schema to the task SO with an intermediate
release for the following PR:
elastic#217728

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
qn895 pushed a commit to qn895/kibana that referenced this pull request Jun 3, 2025
…219429)

Towards: elastic#216308

This PR adds the `rrule` schema to the task SO with an intermediate
release for the following PR:
elastic#217728

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants