From 3d99c0f3b80d38a2231bae9d341dbd639576bd41 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Wed, 23 Sep 2020 17:12:14 -0500 Subject: [PATCH 1/6] [ML] Update transform cloning to include description and new fields [ML] Clean up console --- .../transform/public/app/common/request.ts | 81 ++++++++++--------- .../step_details/step_details_form.tsx | 18 +++++ 2 files changed, 62 insertions(+), 37 deletions(-) diff --git a/x-pack/plugins/transform/public/app/common/request.ts b/x-pack/plugins/transform/public/app/common/request.ts index 45160d125309d..5c78e119f1979 100644 --- a/x-pack/plugins/transform/public/app/common/request.ts +++ b/x-pack/plugins/transform/public/app/common/request.ts @@ -134,44 +134,51 @@ export const getCreateTransformRequestBody = ( indexPatternTitle: IndexPattern['title'], pivotState: StepDefineExposedState, transformDetailsState: StepDetailsExposedState -): PutTransformsRequestSchema => ({ - ...getPreviewTransformRequestBody( - indexPatternTitle, - getPivotQuery(pivotState.searchQuery), - dictionaryToArray(pivotState.groupByList), - dictionaryToArray(pivotState.aggList) - ), - // conditionally add optional description - ...(transformDetailsState.transformDescription !== '' - ? { description: transformDetailsState.transformDescription } - : {}), - // conditionally add optional frequency - ...(transformDetailsState.transformFrequency !== '' - ? { frequency: transformDetailsState.transformFrequency } - : {}), - dest: { - index: transformDetailsState.destinationIndex, - }, - // conditionally add continuous mode config - ...(transformDetailsState.isContinuousModeEnabled - ? { - sync: { - time: { - field: transformDetailsState.continuousModeDateField, - delay: transformDetailsState.continuousModeDelay, +): PutTransformsRequestSchema => { + const tempSettings = { + settings: {} as Record, + }; + if (transformDetailsState.transformSettingsMaxPageSearchSize) { + tempSettings.settings.max_page_search_size = + transformDetailsState.transformSettingsMaxPageSearchSize; + } + if (transformDetailsState.transformSettingsDocsPerSecond) { + tempSettings.settings.docs_per_second = transformDetailsState.transformSettingsDocsPerSecond; + } + + return { + ...getPreviewTransformRequestBody( + indexPatternTitle, + getPivotQuery(pivotState.searchQuery), + dictionaryToArray(pivotState.groupByList), + dictionaryToArray(pivotState.aggList) + ), + // conditionally add optional description + ...(transformDetailsState.transformDescription !== '' + ? { description: transformDetailsState.transformDescription } + : {}), + // conditionally add optional frequency + ...(transformDetailsState.transformFrequency !== '' + ? { frequency: transformDetailsState.transformFrequency } + : {}), + dest: { + index: transformDetailsState.destinationIndex, + }, + // conditionally add continuous mode config + ...(transformDetailsState.isContinuousModeEnabled + ? { + sync: { + time: { + field: transformDetailsState.continuousModeDateField, + delay: transformDetailsState.continuousModeDelay, + }, }, - }, - } - : {}), - // conditionally add additional settings - ...(transformDetailsState.transformSettingsMaxPageSearchSize - ? { - settings: { - max_page_search_size: transformDetailsState.transformSettingsMaxPageSearchSize, - }, - } - : {}), -}); + } + : {}), + // conditionally add additional settings + ...tempSettings, + }; +}; export function isHttpFetchError(error: any): error is HttpFetchError { return ( 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, From 55574f922217db8f1543e74a28dc4039042a4666 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Thu, 24 Sep 2020 11:55:00 -0500 Subject: [PATCH 2/6] [ML] Update tests --- .../step_details/step_details_summary.tsx | 2 + .../test/functional/apps/ml/settings/index.ts | 2 +- .../test/functional/apps/transform/cloning.ts | 15 +++++- .../functional/services/transform/wizard.ts | 47 +++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) 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} Date: Mon, 28 Sep 2020 17:48:36 -0500 Subject: [PATCH 3/6] [ML] Refactor to getCreateTransformSettingsRequestBody --- .../transform/public/app/common/request.ts | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/transform/public/app/common/request.ts b/x-pack/plugins/transform/public/app/common/request.ts index 5c78e119f1979..8c70b5df260f7 100644 --- a/x-pack/plugins/transform/public/app/common/request.ts +++ b/x-pack/plugins/transform/public/app/common/request.ts @@ -130,22 +130,27 @@ export function getPreviewTransformRequestBody( return request; } -export const getCreateTransformRequestBody = ( - indexPatternTitle: IndexPattern['title'], - pivotState: StepDefineExposedState, +export const getCreateTransformSettingsRequestBody = ( transformDetailsState: StepDetailsExposedState -): PutTransformsRequestSchema => { - const tempSettings = { - settings: {} as Record, - }; +): { settings: PutTransformsRequestSchema['settings'] } => { + // have to use Record<> here because typeof schema is readonly + const tempSettings = {} as Record; + if (transformDetailsState.transformSettingsMaxPageSearchSize) { - tempSettings.settings.max_page_search_size = - transformDetailsState.transformSettingsMaxPageSearchSize; + tempSettings.max_page_search_size = transformDetailsState.transformSettingsMaxPageSearchSize; } if (transformDetailsState.transformSettingsDocsPerSecond) { - tempSettings.settings.docs_per_second = transformDetailsState.transformSettingsDocsPerSecond; + tempSettings.docs_per_second = transformDetailsState.transformSettingsDocsPerSecond; } + return { settings: tempSettings }; +}; + +export const getCreateTransformRequestBody = ( + indexPatternTitle: IndexPattern['title'], + pivotState: StepDefineExposedState, + transformDetailsState: StepDetailsExposedState +): PutTransformsRequestSchema => { return { ...getPreviewTransformRequestBody( indexPatternTitle, @@ -176,7 +181,7 @@ export const getCreateTransformRequestBody = ( } : {}), // conditionally add additional settings - ...tempSettings, + ...getCreateTransformSettingsRequestBody(transformDetailsState), }; }; From b82513ee3b2596c45de46ea97892322317edfd7e Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Wed, 30 Sep 2020 16:20:36 -0500 Subject: [PATCH 4/6] [ML] Update tests to have getCreateTransformSettingsRequestBody --- .../public/app/common/request.test.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) 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..487048eaffe7d 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 all settings', () => { + const transformDetailsState: StepDetailsExposedState = { + transformSettingsDocsPerSecond: 400, + transformSettingsMaxPageSearchSize: 100, + }; + + const request = getCreateTransformSettingsRequestBody(transformDetailsState); + + expect(request).toEqual({ + settings: { + docs_per_second: 400, + max_page_search_size: 100, + }, + }); + }); + + test('getCreateTransformSettingsRequestBody() with individual settings', () => { + const transformDetailsState: StepDetailsExposedState = { + transformSettingsDocsPerSecond: 400, + }; + + const request = getCreateTransformSettingsRequestBody(transformDetailsState); + + expect(request).toEqual({ + settings: { + docs_per_second: 400, + }, + }); + }); }); From 6222e739019a28453edbd5463bd6db2dd5e35a1a Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Wed, 30 Sep 2020 17:23:47 -0500 Subject: [PATCH 5/6] [ML] Update type --- .../plugins/transform/public/app/common/request.test.ts | 8 ++++---- x-pack/plugins/transform/public/app/common/request.ts | 2 +- 2 files changed, 5 insertions(+), 5 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 487048eaffe7d..46ace2c3315a5 100644 --- a/x-pack/plugins/transform/public/app/common/request.test.ts +++ b/x-pack/plugins/transform/public/app/common/request.test.ts @@ -191,8 +191,8 @@ describe('Transform: Common', () => { }); }); - test('getCreateTransformSettingsRequestBody() with all settings', () => { - const transformDetailsState: StepDetailsExposedState = { + test('getCreateTransformSettingsRequestBody() with multiple settings', () => { + const transformDetailsState: Partial = { transformSettingsDocsPerSecond: 400, transformSettingsMaxPageSearchSize: 100, }; @@ -207,8 +207,8 @@ describe('Transform: Common', () => { }); }); - test('getCreateTransformSettingsRequestBody() with individual settings', () => { - const transformDetailsState: StepDetailsExposedState = { + test('getCreateTransformSettingsRequestBody() with one setting', () => { + const transformDetailsState: Partial = { transformSettingsDocsPerSecond: 400, }; diff --git a/x-pack/plugins/transform/public/app/common/request.ts b/x-pack/plugins/transform/public/app/common/request.ts index 8c70b5df260f7..39412756266e2 100644 --- a/x-pack/plugins/transform/public/app/common/request.ts +++ b/x-pack/plugins/transform/public/app/common/request.ts @@ -131,7 +131,7 @@ export function getPreviewTransformRequestBody( } export const getCreateTransformSettingsRequestBody = ( - transformDetailsState: StepDetailsExposedState + transformDetailsState: Partial ): { settings: PutTransformsRequestSchema['settings'] } => { // have to use Record<> here because typeof schema is readonly const tempSettings = {} as Record; From 665232fd43a76aa120784f80400a2878f383a08b Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Thu, 1 Oct 2020 09:54:01 -0500 Subject: [PATCH 6/6] [ML] Update getCreateTransformSettingsRequestBody and getCreateTransformRequestBody --- .../transform/public/app/common/request.ts | 86 +++++++++---------- 1 file changed, 41 insertions(+), 45 deletions(-) diff --git a/x-pack/plugins/transform/public/app/common/request.ts b/x-pack/plugins/transform/public/app/common/request.ts index 39412756266e2..8ee235baf7c5a 100644 --- a/x-pack/plugins/transform/public/app/common/request.ts +++ b/x-pack/plugins/transform/public/app/common/request.ts @@ -132,58 +132,54 @@ export function getPreviewTransformRequestBody( export const getCreateTransformSettingsRequestBody = ( transformDetailsState: Partial -): { settings: PutTransformsRequestSchema['settings'] } => { - // have to use Record<> here because typeof schema is readonly - const tempSettings = {} as Record; - - if (transformDetailsState.transformSettingsMaxPageSearchSize) { - tempSettings.max_page_search_size = transformDetailsState.transformSettingsMaxPageSearchSize; - } - if (transformDetailsState.transformSettingsDocsPerSecond) { - tempSettings.docs_per_second = transformDetailsState.transformSettingsDocsPerSecond; - } - - return { settings: tempSettings }; +): { 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, transformDetailsState: StepDetailsExposedState -): PutTransformsRequestSchema => { - return { - ...getPreviewTransformRequestBody( - indexPatternTitle, - getPivotQuery(pivotState.searchQuery), - dictionaryToArray(pivotState.groupByList), - dictionaryToArray(pivotState.aggList) - ), - // conditionally add optional description - ...(transformDetailsState.transformDescription !== '' - ? { description: transformDetailsState.transformDescription } - : {}), - // conditionally add optional frequency - ...(transformDetailsState.transformFrequency !== '' - ? { frequency: transformDetailsState.transformFrequency } - : {}), - dest: { - index: transformDetailsState.destinationIndex, - }, - // conditionally add continuous mode config - ...(transformDetailsState.isContinuousModeEnabled - ? { - sync: { - time: { - field: transformDetailsState.continuousModeDateField, - delay: transformDetailsState.continuousModeDelay, - }, +): PutTransformsRequestSchema => ({ + ...getPreviewTransformRequestBody( + indexPatternTitle, + getPivotQuery(pivotState.searchQuery), + dictionaryToArray(pivotState.groupByList), + dictionaryToArray(pivotState.aggList) + ), + // conditionally add optional description + ...(transformDetailsState.transformDescription !== '' + ? { description: transformDetailsState.transformDescription } + : {}), + // conditionally add optional frequency + ...(transformDetailsState.transformFrequency !== '' + ? { frequency: transformDetailsState.transformFrequency } + : {}), + dest: { + index: transformDetailsState.destinationIndex, + }, + // conditionally add continuous mode config + ...(transformDetailsState.isContinuousModeEnabled + ? { + sync: { + time: { + field: transformDetailsState.continuousModeDateField, + delay: transformDetailsState.continuousModeDelay, }, - } - : {}), - // conditionally add additional settings - ...getCreateTransformSettingsRequestBody(transformDetailsState), - }; -}; + }, + } + : {}), + // conditionally add additional settings + ...getCreateTransformSettingsRequestBody(transformDetailsState), +}); export function isHttpFetchError(error: any): error is HttpFetchError { return (