From 8ad16b28ecfe8f68ca90606e10b3ea1c18c17a8e Mon Sep 17 00:00:00 2001 From: Quynh Nguyen <43350163+qn895@users.noreply.github.com> Date: Thu, 1 Oct 2020 14:25:32 -0500 Subject: [PATCH] [7.x] [ML] Update transform cloning to include description and new fields (#78364) (#79181) --- .../public/app/common/request.test.ts | 33 +++++++++++++ .../transform/public/app/common/request.ts | 22 ++++++--- .../step_details/step_details_form.tsx | 18 +++++++ .../step_details/step_details_summary.tsx | 2 + .../test/functional/apps/transform/cloning.ts | 15 +++++- .../functional/services/transform/wizard.ts | 47 +++++++++++++++++++ 6 files changed, 129 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/transform/public/app/common/request.test.ts b/x-pack/plugins/transform/public/app/common/request.test.ts index 913ea8964eaf0..46ace2c3315a5 100644 --- a/x-pack/plugins/transform/public/app/common/request.test.ts +++ b/x-pack/plugins/transform/public/app/common/request.test.ts @@ -17,6 +17,7 @@ import { defaultQuery, getPreviewTransformRequestBody, getCreateTransformRequestBody, + getCreateTransformSettingsRequestBody, getPivotQuery, isDefaultQuery, isMatchAllQuery, @@ -159,6 +160,7 @@ describe('Transform: Common', () => { transformDescription: 'the-transform-description', transformFrequency: '1m', transformSettingsMaxPageSearchSize: 100, + transformSettingsDocsPerSecond: 400, destinationIndex: 'the-destination-index', touched: true, valid: true, @@ -180,6 +182,7 @@ describe('Transform: Common', () => { }, settings: { max_page_search_size: 100, + docs_per_second: 400, }, source: { index: ['the-index-pattern-title'], @@ -187,4 +190,34 @@ describe('Transform: Common', () => { }, }); }); + + test('getCreateTransformSettingsRequestBody() with multiple settings', () => { + const transformDetailsState: Partial = { + transformSettingsDocsPerSecond: 400, + transformSettingsMaxPageSearchSize: 100, + }; + + const request = getCreateTransformSettingsRequestBody(transformDetailsState); + + expect(request).toEqual({ + settings: { + docs_per_second: 400, + max_page_search_size: 100, + }, + }); + }); + + test('getCreateTransformSettingsRequestBody() with one setting', () => { + const transformDetailsState: Partial = { + transformSettingsDocsPerSecond: 400, + }; + + const request = getCreateTransformSettingsRequestBody(transformDetailsState); + + expect(request).toEqual({ + settings: { + docs_per_second: 400, + }, + }); + }); }); diff --git a/x-pack/plugins/transform/public/app/common/request.ts b/x-pack/plugins/transform/public/app/common/request.ts index 45160d125309d..8ee235baf7c5a 100644 --- a/x-pack/plugins/transform/public/app/common/request.ts +++ b/x-pack/plugins/transform/public/app/common/request.ts @@ -130,6 +130,20 @@ export function getPreviewTransformRequestBody( return request; } +export const getCreateTransformSettingsRequestBody = ( + transformDetailsState: Partial +): { settings?: PutTransformsRequestSchema['settings'] } => { + const settings: PutTransformsRequestSchema['settings'] = { + ...(transformDetailsState.transformSettingsMaxPageSearchSize + ? { max_page_search_size: transformDetailsState.transformSettingsMaxPageSearchSize } + : {}), + ...(transformDetailsState.transformSettingsDocsPerSecond + ? { docs_per_second: transformDetailsState.transformSettingsDocsPerSecond } + : {}), + }; + return Object.keys(settings).length > 0 ? { settings } : {}; +}; + export const getCreateTransformRequestBody = ( indexPatternTitle: IndexPattern['title'], pivotState: StepDefineExposedState, @@ -164,13 +178,7 @@ export const getCreateTransformRequestBody = ( } : {}), // conditionally add additional settings - ...(transformDetailsState.transformSettingsMaxPageSearchSize - ? { - settings: { - max_page_search_size: transformDetailsState.transformSettingsMaxPageSearchSize, - }, - } - : {}), + ...getCreateTransformSettingsRequestBody(transformDetailsState), }); export function isHttpFetchError(error: any): error is HttpFetchError { 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 00ab516f625fe..9b43879512e4d 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 @@ -63,6 +63,7 @@ export interface StepDetailsExposedState { transformDescription: string; transformFrequency: string; transformSettingsMaxPageSearchSize: number; + transformSettingsDocsPerSecond?: number; valid: boolean; indexPatternTimeField?: string | undefined; } @@ -100,6 +101,20 @@ export function applyTransformConfigToDetailsState( state.continuousModeDelay = time?.delay ?? defaultContinuousModeDelay; state.isContinuousModeEnabled = true; } + if (transformConfig.description !== undefined) { + state.transformDescription = transformConfig.description; + } + if (transformConfig.frequency !== undefined) { + state.transformFrequency = transformConfig.frequency; + } + if (transformConfig.settings) { + if (typeof transformConfig.settings?.max_page_search_size === 'number') { + state.transformSettingsMaxPageSearchSize = transformConfig.settings.max_page_search_size; + } + if (typeof transformConfig.settings?.docs_per_second === 'number') { + state.transformSettingsDocsPerSecond = transformConfig.settings.docs_per_second; + } + } } return state; } @@ -275,6 +290,8 @@ export const StepDetailsForm: FC = React.memo( const [transformSettingsMaxPageSearchSize, setTransformSettingsMaxPageSearchSize] = useState( defaults.transformSettingsMaxPageSearchSize ); + const [transformSettingsDocsPerSecond] = useState(defaults.transformSettingsDocsPerSecond); + const isTransformSettingsMaxPageSearchSizeValid = transformSettingsMaxPageSearchSizeValidator( transformSettingsMaxPageSearchSize ); @@ -301,6 +318,7 @@ export const StepDetailsForm: FC = React.memo( transformDescription, transformFrequency, transformSettingsMaxPageSearchSize, + transformSettingsDocsPerSecond, destinationIndex, touched: true, valid, diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/step_details_summary.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/step_details_summary.tsx index 45cd8aa465522..f5444eaf6640a 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/step_details_summary.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_details/step_details_summary.tsx @@ -98,6 +98,7 @@ export const StepDetailsSummary: FC = React.memo((props paddingSize="s" > = React.memo((props {transformFrequency}