Skip to content

Commit

Permalink
Revert "[Task Manager] Force validation on all tasks using state (#16… (
Browse files Browse the repository at this point in the history
elastic#167877)

Revert of elastic#164574

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Xavier Mouligneau <xavier.mouligneau@elastic.co>
  • Loading branch information
3 people committed Oct 3, 2023
1 parent 2256a7a commit 395f75e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
8 changes: 6 additions & 2 deletions x-pack/plugins/task_manager/server/task_validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ describe('TaskValidator', () => {
expect(result).toEqual(task);
});

it(`should fail to validate the state schema when the task type doesn't have stateSchemaByVersion defined`, () => {
// 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`, () => {
const definitions = new TaskTypeDictionary(mockLogger());
definitions.registerTaskDefinitions({
foo: fooTaskDefinition,
Expand Down Expand Up @@ -320,7 +322,9 @@ describe('TaskValidator', () => {
expect(result).toEqual(task);
});

it(`should fail to validate the state schema when the task type doesn't have stateSchemaByVersion defined`, () => {
// 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`, () => {
const definitions = new TaskTypeDictionary(mockLogger());
definitions.registerTaskDefinitions({
foo: fooTaskDefinition,
Expand Down
17 changes: 10 additions & 7 deletions x-pack/plugins/task_manager/server/task_validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { max, memoize, isEmpty } from 'lodash';
import { max, memoize } from 'lodash';
import type { Logger } from '@kbn/core/server';
import type { ObjectType } from '@kbn/config-schema';
import { TaskTypeDictionary } from './task_type_dictionary';
Expand Down Expand Up @@ -64,13 +64,14 @@ export class TaskValidator {
const taskTypeDef = this.definitions.get(task.taskType);
const latestStateSchema = this.cachedGetLatestStateSchema(taskTypeDef);

let state = task.state;

// Skip validating tasks that don't use state
if (!latestStateSchema && isEmpty(state)) {
// 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(
this.migrateTaskState(task.state, task.stateVersion, taskTypeDef, latestStateSchema),
Expand Down Expand Up @@ -110,8 +111,10 @@ export class TaskValidator {
const taskTypeDef = this.definitions.get(task.taskType);
const latestStateSchema = this.cachedGetLatestStateSchema(taskTypeDef);

// Skip validating tasks that don't use state
if (!latestStateSchema && isEmpty(task.state)) {
// 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;
}

Expand Down

0 comments on commit 395f75e

Please sign in to comment.