From e355acf8c758c2eb7796d149c130d18cbd11346c Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Mon, 25 Oct 2021 14:26:16 -0500 Subject: [PATCH 1/4] [ML] Retain _meta on clone --- .../transform/common/api_schemas/transforms.ts | 18 ++++++++++++++++++ .../transform/common/types/transform.ts | 1 + .../transform/public/app/common/request.ts | 1 + .../components/step_details/common.ts | 5 +++++ .../step_details/step_details_form.tsx | 1 + 5 files changed, 26 insertions(+) diff --git a/x-pack/plugins/transform/common/api_schemas/transforms.ts b/x-pack/plugins/transform/common/api_schemas/transforms.ts index 8867ecb5cc760..6cdf7ec58b514 100644 --- a/x-pack/plugins/transform/common/api_schemas/transforms.ts +++ b/x-pack/plugins/transform/common/api_schemas/transforms.ts @@ -94,6 +94,19 @@ function transformConfigPayloadValidator< } } +export const _metaSchema = schema.object( + {}, + { + unknowns: 'allow', + validate: (v: object) => { + // Values should all be objects + if (Object.values(v).some((arg) => !(typeof arg === 'object' && arg !== null))) { + return 'Invalid _meta request, expected only object'; + } + }, + } +); + // PUT transforms/{transformId} export const putTransformsRequestSchema = schema.object( { @@ -112,6 +125,11 @@ export const putTransformsRequestSchema = schema.object( settings: schema.maybe(settingsSchema), source: sourceSchema, sync: schema.maybe(syncSchema), + /** + * This _meta field stores an arbitrary key-value map + * where keys are strings and values are arbitrary objects (possibly also maps). + */ + _meta: schema.maybe(_metaSchema), }, { validate: transformConfigPayloadValidator, diff --git a/x-pack/plugins/transform/common/types/transform.ts b/x-pack/plugins/transform/common/types/transform.ts index a478946ff917c..c59b37fe57551 100644 --- a/x-pack/plugins/transform/common/types/transform.ts +++ b/x-pack/plugins/transform/common/types/transform.ts @@ -24,6 +24,7 @@ export type TransformBaseConfig = PutTransformsRequestSchema & { create_time?: number; version?: string; alerting_rules?: TransformHealthAlertRule[]; + _meta?: Record; }; export interface PivotConfigDefinition { diff --git a/x-pack/plugins/transform/public/app/common/request.ts b/x-pack/plugins/transform/public/app/common/request.ts index a7a3a91f9429b..f0e411f559aea 100644 --- a/x-pack/plugins/transform/public/app/common/request.ts +++ b/x-pack/plugins/transform/public/app/common/request.ts @@ -242,6 +242,7 @@ export const getCreateTransformRequestBody = ( }, } : {}), + ...(transformDetailsState._meta ? { _meta: transformDetailsState._meta } : {}), // conditionally add additional settings ...getCreateTransformSettingsRequestBody(transformDetailsState), }); diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/common.ts b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/common.ts index 39b1a2de26f8e..59aa0d0bf2525 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/common.ts +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/common.ts @@ -27,6 +27,7 @@ export interface StepDetailsExposedState { transformSettingsDocsPerSecond?: number; valid: boolean; indexPatternTimeField?: string | undefined; + _meta?: Record; } const defaultContinuousModeDelay = '60s'; @@ -94,6 +95,10 @@ export function applyTransformConfigToDetailsState( state.transformSettingsDocsPerSecond = transformConfig.settings.docs_per_second; } } + + if (transformConfig._meta) { + state._meta = transformConfig._meta; + } } return state; } diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/step_details_form.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/step_details_form.tsx index 416bad15d800a..eda95013f60bd 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/step_details_form.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/step_details_form.tsx @@ -289,6 +289,7 @@ export const StepDetailsForm: FC = React.memo( touched: true, valid, indexPatternTimeField, + _meta: defaults._meta, }); // custom comparison /* eslint-disable react-hooks/exhaustive-deps */ From ebfa1e67e67a8d042a82167416414ee4e5f63b6b Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 26 Oct 2021 09:39:19 -0500 Subject: [PATCH 2/4] [ML] Fix validation on schema to only check it it's defined/not null --- x-pack/plugins/transform/common/api_schemas/transforms.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/transform/common/api_schemas/transforms.ts b/x-pack/plugins/transform/common/api_schemas/transforms.ts index 6cdf7ec58b514..59165199fe7d3 100644 --- a/x-pack/plugins/transform/common/api_schemas/transforms.ts +++ b/x-pack/plugins/transform/common/api_schemas/transforms.ts @@ -100,8 +100,8 @@ export const _metaSchema = schema.object( unknowns: 'allow', validate: (v: object) => { // Values should all be objects - if (Object.values(v).some((arg) => !(typeof arg === 'object' && arg !== null))) { - return 'Invalid _meta request, expected only object'; + if (Object.values(v).some((arg) => arg === undefined || arg === null)) { + return 'Invalid _meta request'; } }, } From ed31df64711dfd58b06b2eb307a0b0c4597f3c24 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 26 Oct 2021 10:23:04 -0500 Subject: [PATCH 3/4] [ML] Remove validation because es should handle the validation already --- x-pack/plugins/transform/common/api_schemas/transforms.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/x-pack/plugins/transform/common/api_schemas/transforms.ts b/x-pack/plugins/transform/common/api_schemas/transforms.ts index 59165199fe7d3..55ea326069f0d 100644 --- a/x-pack/plugins/transform/common/api_schemas/transforms.ts +++ b/x-pack/plugins/transform/common/api_schemas/transforms.ts @@ -98,12 +98,6 @@ export const _metaSchema = schema.object( {}, { unknowns: 'allow', - validate: (v: object) => { - // Values should all be objects - if (Object.values(v).some((arg) => arg === undefined || arg === null)) { - return 'Invalid _meta request'; - } - }, } ); From 95c7f440fef444fe0943c3dfdf65ddd48fddc169 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Wed, 27 Oct 2021 11:05:01 -0500 Subject: [PATCH 4/4] Change type to unknown --- x-pack/plugins/transform/common/types/transform.ts | 2 +- .../sections/create_transform/components/step_details/common.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/transform/common/types/transform.ts b/x-pack/plugins/transform/common/types/transform.ts index c59b37fe57551..92ffc0b99bc3d 100644 --- a/x-pack/plugins/transform/common/types/transform.ts +++ b/x-pack/plugins/transform/common/types/transform.ts @@ -24,7 +24,7 @@ export type TransformBaseConfig = PutTransformsRequestSchema & { create_time?: number; version?: string; alerting_rules?: TransformHealthAlertRule[]; - _meta?: Record; + _meta?: Record; }; export interface PivotConfigDefinition { diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/common.ts b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/common.ts index 59aa0d0bf2525..21e6bce204ec8 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/common.ts +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/common.ts @@ -27,7 +27,7 @@ export interface StepDetailsExposedState { transformSettingsDocsPerSecond?: number; valid: boolean; indexPatternTimeField?: string | undefined; - _meta?: Record; + _meta?: Record; } const defaultContinuousModeDelay = '60s';