Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Update transform cloning to include description and new fields #78364

Merged
merged 11 commits into from
Oct 1, 2020
Merged
81 changes: 44 additions & 37 deletions x-pack/plugins/transform/public/app/common/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number | null | undefined>,
};
if (transformDetailsState.transformSettingsMaxPageSearchSize) {
tempSettings.settings.max_page_search_size =
transformDetailsState.transformSettingsMaxPageSearchSize;
}
if (transformDetailsState.transformSettingsDocsPerSecond) {
tempSettings.settings.docs_per_second = transformDetailsState.transformSettingsDocsPerSecond;
}
walterra marked this conversation as resolved.
Show resolved Hide resolved

return {
walterra marked this conversation as resolved.
Show resolved Hide resolved
...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 (
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
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/ml/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
describe('settings', function () {
this.tags(['quynh', 'skipFirefox']);
this.tags(['skipFirefox']);

loadTestFile(require.resolve('./calendar_creation'));
loadTestFile(require.resolve('./calendar_edit'));
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