Skip to content

Commit

Permalink
[8.x] [Response Ops][Task Manager] Changing task manager `schedu…
Browse files Browse the repository at this point in the history
…le.interval` schema to string from duration (#204413) (#204669)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Response Ops][Task Manager] Changing task manager
`schedule.interval` schema to string from duration
(#204413)](#204413)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Ying
Mao","email":"ying.mao@elastic.co"},"sourceCommit":{"committedDate":"2024-12-17T22:41:20Z","message":"[Response
Ops][Task Manager] Changing task manager `schedule.interval` schema to
string from duration (#204413)\n\n## Summary\r\n\r\nCurrently, when task
manager schema changes are migrated down (which can\r\noccur during a
release when there are multiple Kibana nodes running and\r\nthey get
updated one after another), we are running into this
bug:\r\nhttps://github.com//issues/204395 where the
task\r\n`schedule.interval` gets mutated from expected values (like
`60s`) to\r\nunallowed (but still valid for the schema) values (like
`PT1M`).\r\n\r\nThis changes the schema for `schedule.interval` to use a
string with\r\nvalidation function.\r\n\r\n## To verify\r\n1. Run Kibana
on `main` and create some rules that run frequently.\r\n2. \"Upgrade\"
to this PR branch and verify that rules continue to run.\r\n3.
\"Downgrade\" back to `main` and verify that rules continue to
run.","sha":"ccdd662a053f9d02fe1ea04afe2bdd80827459c0","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Feature:Task
Manager","Team:ResponseOps","v9.0.0","backport:prev-minor","v8.18.0"],"title":"[Response
Ops][Task Manager] Changing task manager `schedule.interval` schema to
string from
duration","number":204413,"url":"https://github.com/elastic/kibana/pull/204413","mergeCommit":{"message":"[Response
Ops][Task Manager] Changing task manager `schedule.interval` schema to
string from duration (#204413)\n\n## Summary\r\n\r\nCurrently, when task
manager schema changes are migrated down (which can\r\noccur during a
release when there are multiple Kibana nodes running and\r\nthey get
updated one after another), we are running into this
bug:\r\nhttps://github.com//issues/204395 where the
task\r\n`schedule.interval` gets mutated from expected values (like
`60s`) to\r\nunallowed (but still valid for the schema) values (like
`PT1M`).\r\n\r\nThis changes the schema for `schedule.interval` to use a
string with\r\nvalidation function.\r\n\r\n## To verify\r\n1. Run Kibana
on `main` and create some rules that run frequently.\r\n2. \"Upgrade\"
to this PR branch and verify that rules continue to run.\r\n3.
\"Downgrade\" back to `main` and verify that rules continue to
run.","sha":"ccdd662a053f9d02fe1ea04afe2bdd80827459c0"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204413","number":204413,"mergeCommit":{"message":"[Response
Ops][Task Manager] Changing task manager `schedule.interval` schema to
string from duration (#204413)\n\n## Summary\r\n\r\nCurrently, when task
manager schema changes are migrated down (which can\r\noccur during a
release when there are multiple Kibana nodes running and\r\nthey get
updated one after another), we are running into this
bug:\r\nhttps://github.com//issues/204395 where the
task\r\n`schedule.interval` gets mutated from expected values (like
`60s`) to\r\nunallowed (but still valid for the schema) values (like
`PT1M`).\r\n\r\nThis changes the schema for `schedule.interval` to use a
string with\r\nvalidation function.\r\n\r\n## To verify\r\n1. Run Kibana
on `main` and create some rules that run frequently.\r\n2. \"Upgrade\"
to this PR branch and verify that rules continue to run.\r\n3.
\"Downgrade\" back to `main` and verify that rules continue to
run.","sha":"ccdd662a053f9d02fe1ea04afe2bdd80827459c0"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Ying Mao <ying.mao@elastic.co>
  • Loading branch information
kibanamachine and ymao1 authored Dec 18, 2024
1 parent aed0010 commit af953f4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import { SavedObjectsModelVersionMap } from '@kbn/core-saved-objects-server';
import { taskSchemaV1, taskSchemaV2 } from '../schemas/task';

// IMPORTANT!!!
// When adding new model versions, make sure to manually test
// downgrading to the previous version. This is a gap in our
// automated test coverage so manual testing is needed.
export const taskModelVersions: SavedObjectsModelVersionMap = {
'1': {
changes: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { validateDuration } from './task';

test('allows valid duration', () => {
expect(validateDuration('1s')).toBeUndefined();
expect(validateDuration('45346s')).toBeUndefined();
expect(validateDuration('10m')).toBeUndefined();
expect(validateDuration('30000000h')).toBeUndefined();
expect(validateDuration('3245d')).toBeUndefined();
});

test('returns error message for invalid duration', () => {
expect(validateDuration('10x')).toBe('string is not a valid duration: 10x');
expect(validateDuration('PT1M')).toBe('string is not a valid duration: PT1M');
expect(validateDuration('foo')).toBe('string is not a valid duration: foo');
expect(validateDuration('1 minute')).toBe('string is not a valid duration: 1 minute');
expect(validateDuration('1hr')).toBe('string is not a valid duration: 1hr');
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
*/

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

export function validateDuration(duration: string) {
if (!isInterval(duration)) {
return 'string is not a valid duration: ' + duration;
}
}

export const taskSchemaV1 = schema.object({
taskType: schema.string(),
Expand All @@ -15,7 +22,7 @@ export const taskSchemaV1 = schema.object({
runAt: schema.string(),
schedule: schema.maybe(
schema.object({
interval: schema.duration(),
interval: schema.string({ validate: validateDuration }),
})
),
params: schema.string(),
Expand Down

0 comments on commit af953f4

Please sign in to comment.