Skip to content

Commit

Permalink
[7.x] [ML] Update transform cloning to include description and new fi…
Browse files Browse the repository at this point in the history
…elds (#78364) (#79181)
  • Loading branch information
qn895 authored Oct 1, 2020
1 parent 32e3308 commit 8ad16b2
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 8 deletions.
33 changes: 33 additions & 0 deletions x-pack/plugins/transform/public/app/common/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
defaultQuery,
getPreviewTransformRequestBody,
getCreateTransformRequestBody,
getCreateTransformSettingsRequestBody,
getPivotQuery,
isDefaultQuery,
isMatchAllQuery,
Expand Down Expand Up @@ -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,
Expand All @@ -180,11 +182,42 @@ describe('Transform: Common', () => {
},
settings: {
max_page_search_size: 100,
docs_per_second: 400,
},
source: {
index: ['the-index-pattern-title'],
query: { query_string: { default_operator: 'AND', query: 'the-search-query' } },
},
});
});

test('getCreateTransformSettingsRequestBody() with multiple settings', () => {
const transformDetailsState: Partial<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 one setting', () => {
const transformDetailsState: Partial<StepDetailsExposedState> = {
transformSettingsDocsPerSecond: 400,
};

const request = getCreateTransformSettingsRequestBody(transformDetailsState);

expect(request).toEqual({
settings: {
docs_per_second: 400,
},
});
});
});
22 changes: 15 additions & 7 deletions x-pack/plugins/transform/public/app/common/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ export function getPreviewTransformRequestBody(
return request;
}

export const getCreateTransformSettingsRequestBody = (
transformDetailsState: Partial<StepDetailsExposedState>
): { 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,
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface StepDetailsExposedState {
transformDescription: string;
transformFrequency: string;
transformSettingsMaxPageSearchSize: number;
transformSettingsDocsPerSecond?: number;
valid: boolean;
indexPatternTimeField?: string | undefined;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -275,6 +290,8 @@ export const StepDetailsForm: FC<Props> = React.memo(
const [transformSettingsMaxPageSearchSize, setTransformSettingsMaxPageSearchSize] = useState(
defaults.transformSettingsMaxPageSearchSize
);
const [transformSettingsDocsPerSecond] = useState(defaults.transformSettingsDocsPerSecond);

const isTransformSettingsMaxPageSearchSizeValid = transformSettingsMaxPageSearchSizeValidator(
transformSettingsMaxPageSearchSize
);
Expand All @@ -301,6 +318,7 @@ export const StepDetailsForm: FC<Props> = React.memo(
transformDescription,
transformFrequency,
transformSettingsMaxPageSearchSize,
transformSettingsDocsPerSecond,
destinationIndex,
touched: true,
valid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ export const StepDetailsSummary: FC<StepDetailsExposedState> = React.memo((props
paddingSize="s"
>
<EuiFormRow
data-test-subj={'transformWizardAdvancedSettingsFrequencyLabel'}
label={i18n.translate('xpack.transform.stepDetailsSummary.frequencyLabel', {
defaultMessage: 'Frequency',
})}
>
<span>{transformFrequency}</span>
</EuiFormRow>
<EuiFormRow
data-test-subj={'transformWizardAdvancedSettingsMaxPageSearchSizeLabel'}
label={i18n.translate('xpack.transform.stepDetailsSummary.maxPageSearchSizeLabel', {
defaultMessage: 'Maximum page search size',
})}
Expand Down
15 changes: 14 additions & 1 deletion x-pack/test/functional/apps/transform/cloning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ function getTransformConfig(): TransformPivotConfig {
},
description:
'ecommerce batch transform with avg(products.base_price) grouped by terms(category.keyword)',
frequency: '3s',
settings: {
max_page_search_size: 250,
},
dest: { index: `user-ec_2_${date}` },
};
}
Expand Down Expand Up @@ -155,7 +159,7 @@ export default function ({ getService }: FtrProviderContext) {

await transform.testExecution.logTestStep('should input the transform description');
await transform.wizard.assertTransformDescriptionInputExists();
await transform.wizard.assertTransformDescriptionValue('');
await transform.wizard.assertTransformDescriptionValue(transformConfig.description!);
await transform.wizard.setTransformDescription(testData.transformDescription);

await transform.testExecution.logTestStep('should input the destination index');
Expand All @@ -173,6 +177,15 @@ export default function ({ getService }: FtrProviderContext) {
await transform.wizard.assertContinuousModeSwitchExists();
await transform.wizard.assertContinuousModeSwitchCheckState(false);

await transform.testExecution.logTestStep(
'should display the advanced settings and show pre-filled configuration'
);
await transform.wizard.openTransformAdvancedSettingsAccordion();
await transform.wizard.assertTransformFrequencyValue(transformConfig.frequency!);
await transform.wizard.assertTransformMaxPageSearchSizeValue(
transformConfig.settings!.max_page_search_size!
);

await transform.testExecution.logTestStep('should load the create step');
await transform.wizard.advanceToCreateStep();

Expand Down
47 changes: 47 additions & 0 deletions x-pack/test/functional/services/transform/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,53 @@ export function TransformWizardProvider({ getService }: FtrProviderContext) {
);
},

async assertTransformAdvancedSettingsAccordionExists() {
await testSubjects.existOrFail('transformWizardAccordionAdvancedSettings');
},

// for now we expect this to be used only for opening the accordion
async openTransformAdvancedSettingsAccordion() {
await this.assertTransformAdvancedSettingsAccordionExists();
await testSubjects.click('transformWizardAccordionAdvancedSettings');
await this.assertTransformFrequencyInputExists();
await this.assertTransformMaxPageSearchSizeInputExists();
},

async assertTransformFrequencyInputExists() {
await testSubjects.existOrFail('transformFrequencyInput');
expect(await testSubjects.isDisplayed('transformFrequencyInput')).to.eql(
true,
`Expected 'Frequency' input to be displayed`
);
},

async assertTransformFrequencyValue(expectedValue: string) {
const actualValue = await testSubjects.getAttribute('transformFrequencyInput', 'value');
expect(actualValue).to.eql(
expectedValue,
`Transform frequency input text should be '${expectedValue}' (got '${actualValue}')`
);
},

async assertTransformMaxPageSearchSizeInputExists() {
await testSubjects.existOrFail('transformMaxPageSearchSizeInput');
expect(await testSubjects.isDisplayed('transformMaxPageSearchSizeInput')).to.eql(
true,
`Expected 'Maximum page search size' input to be displayed`
);
},

async assertTransformMaxPageSearchSizeValue(expectedValue: number) {
const actualValue = await testSubjects.getAttribute(
'transformMaxPageSearchSizeInput',
'value'
);
expect(actualValue).to.eql(
expectedValue,
`Transform maximum page search size input text should be '${expectedValue}' (got '${actualValue}')`
);
},

async assertCreateAndStartButtonExists() {
await testSubjects.existOrFail('transformWizardCreateAndStartButton');
expect(await testSubjects.isDisplayed('transformWizardCreateAndStartButton')).to.eql(
Expand Down

0 comments on commit 8ad16b2

Please sign in to comment.