From ad67fcbee25068f3392ec21b4e460b8c8ef76f78 Mon Sep 17 00:00:00 2001 From: Mike Cote Date: Wed, 23 Aug 2023 08:10:17 -0400 Subject: [PATCH 1/3] Initial commit --- .../task_manager/server/task_validator.test.ts | 8 ++------ .../plugins/task_manager/server/task_validator.ts | 14 -------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/task_manager/server/task_validator.test.ts b/x-pack/plugins/task_manager/server/task_validator.test.ts index 52822adf6f49f..08c18591e468e 100644 --- a/x-pack/plugins/task_manager/server/task_validator.test.ts +++ b/x-pack/plugins/task_manager/server/task_validator.test.ts @@ -64,9 +64,7 @@ describe('TaskValidator', () => { expect(result).toEqual(task); }); - // TODO: Remove skip once all task types have defined their state schema. - // https://github.com/elastic/kibana/issues/159347 - it.skip(`should fail to validate the state schema when the task type doesn't have stateSchemaByVersion defined`, () => { + it(`should fail to validate the state schema when the task type doesn't have stateSchemaByVersion defined`, () => { const definitions = new TaskTypeDictionary(mockLogger()); definitions.registerTaskDefinitions({ foo: fooTaskDefinition, @@ -322,9 +320,7 @@ describe('TaskValidator', () => { expect(result).toEqual(task); }); - // TODO: Remove skip once all task types have defined their state schema. - // https://github.com/elastic/kibana/issues/159347 - it.skip(`should fail to validate the state schema when the task type doesn't have stateSchemaByVersion defined`, () => { + it(`should fail to validate the state schema when the task type doesn't have stateSchemaByVersion defined`, () => { const definitions = new TaskTypeDictionary(mockLogger()); definitions.registerTaskDefinitions({ foo: fooTaskDefinition, diff --git a/x-pack/plugins/task_manager/server/task_validator.ts b/x-pack/plugins/task_manager/server/task_validator.ts index 61d9a903dd5b4..e485017d710de 100644 --- a/x-pack/plugins/task_manager/server/task_validator.ts +++ b/x-pack/plugins/task_manager/server/task_validator.ts @@ -64,13 +64,6 @@ export class TaskValidator { const taskTypeDef = this.definitions.get(task.taskType); const latestStateSchema = this.cachedGetLatestStateSchema(taskTypeDef); - // TODO: Remove once all task types have defined their state schema. - // https://github.com/elastic/kibana/issues/159347 - // Otherwise, failures on read / write would occur. (don't forget to unskip test) - if (!latestStateSchema) { - return task; - } - let state = task.state; try { state = this.getValidatedStateSchema( @@ -111,13 +104,6 @@ export class TaskValidator { const taskTypeDef = this.definitions.get(task.taskType); const latestStateSchema = this.cachedGetLatestStateSchema(taskTypeDef); - // TODO: Remove once all task types have defined their state schema. - // https://github.com/elastic/kibana/issues/159347 - // Otherwise, failures on read / write would occur. (don't forget to unskip test) - if (!latestStateSchema) { - return task; - } - // We are doing a write operation which must validate against the latest state schema return { ...task, From 8c7e6ce55d5918becc90b14d84e98a8f5e12e9cb Mon Sep 17 00:00:00 2001 From: Mike Cote Date: Mon, 11 Sep 2023 15:18:35 -0400 Subject: [PATCH 2/3] Fix failing tests --- .../plugins/task_manager/server/task_validator.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/task_manager/server/task_validator.ts b/x-pack/plugins/task_manager/server/task_validator.ts index e485017d710de..2b40f9be722f6 100644 --- a/x-pack/plugins/task_manager/server/task_validator.ts +++ b/x-pack/plugins/task_manager/server/task_validator.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { max, memoize } from 'lodash'; +import { max, memoize, isEmpty } from 'lodash'; import type { Logger } from '@kbn/core/server'; import type { ObjectType } from '@kbn/config-schema'; import { TaskTypeDictionary } from './task_type_dictionary'; @@ -65,6 +65,12 @@ export class TaskValidator { const latestStateSchema = this.cachedGetLatestStateSchema(taskTypeDef); let state = task.state; + + // Skip validating tasks who don't use state + if (!latestStateSchema && isEmpty(state)) { + return task; + } + try { state = this.getValidatedStateSchema( this.migrateTaskState(task.state, task.stateVersion, taskTypeDef, latestStateSchema), @@ -104,6 +110,11 @@ export class TaskValidator { const taskTypeDef = this.definitions.get(task.taskType); const latestStateSchema = this.cachedGetLatestStateSchema(taskTypeDef); + // Skip validating tasks who don't use state + if (!latestStateSchema && isEmpty(task.state)) { + return task; + } + // We are doing a write operation which must validate against the latest state schema return { ...task, From b0a65b3f5b38010c539930195255cc747db44b7f Mon Sep 17 00:00:00 2001 From: Mike Cote Date: Fri, 22 Sep 2023 11:36:46 -0400 Subject: [PATCH 3/3] Update comment --- x-pack/plugins/task_manager/server/task_validator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/task_manager/server/task_validator.ts b/x-pack/plugins/task_manager/server/task_validator.ts index 2b40f9be722f6..900af04cd1207 100644 --- a/x-pack/plugins/task_manager/server/task_validator.ts +++ b/x-pack/plugins/task_manager/server/task_validator.ts @@ -66,7 +66,7 @@ export class TaskValidator { let state = task.state; - // Skip validating tasks who don't use state + // Skip validating tasks that don't use state if (!latestStateSchema && isEmpty(state)) { return task; } @@ -110,7 +110,7 @@ export class TaskValidator { const taskTypeDef = this.definitions.get(task.taskType); const latestStateSchema = this.cachedGetLatestStateSchema(taskTypeDef); - // Skip validating tasks who don't use state + // Skip validating tasks that don't use state if (!latestStateSchema && isEmpty(task.state)) { return task; }