Skip to content

Commit

Permalink
[ML] Add functional tests for runtime mappings in Transforms (#92738)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
qn895 and kibanamachine authored Mar 9, 2021
1 parent ee2ec0a commit fcf397f
Show file tree
Hide file tree
Showing 8 changed files with 650 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const useDataGrid = (
<ColumnChart
chartData={chartData}
columnType={c}
dataTestSubj={`mlDataGridChart-${index}`}
dataTestSubj={`mlDataGridChart-${c.id}`}
/>
) : undefined,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const AdvancedRuntimeMappingsEditor: FC<StepDefineFormHook['runtimeMappin
}) => {
return (
<EuiCodeEditor
data-test-subj="transformAdvancedPivotEditor"
data-test-subj="transformAdvancedRuntimeMappingsEditor"
style={{ border: '1px solid #e3e6ef' }}
height="250px"
width="100%"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export const AdvancedRuntimeMappingsSettings: FC<StepDefineFormHook> = (props) =
fill
onClick={applyChanges}
disabled={!isRuntimeMappingsEditorApplyButtonEnabled}
data-test-subj="transformRuntimeMappingsApplyButton"
>
{i18n.translate(
'xpack.transform.stepDefineForm.advancedSourceEditorApplyButtonText',
Expand Down
90 changes: 90 additions & 0 deletions x-pack/test/functional/apps/transform/cloning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,50 @@ function getTransformConfig(): TransformPivotConfig {
};
}

function getTransformConfigWithRuntimeMappings(): TransformPivotConfig {
const date = Date.now();

return {
id: `ec_cloning_runtime_${date}`,
source: {
index: ['ft_ecommerce'],
runtime_mappings: {
rt_gender_lower: {
type: 'keyword',
script: "emit(doc['customer_gender'].value.toLowerCase())",
},
rt_total_charge: {
type: 'double',
script: {
source: "emit(doc['taxful_total_price'].value + 4.00)",
},
},
},
},
pivot: {
group_by: { rt_gender_lower: { terms: { field: 'rt_gender_lower' } } },
aggregations: {
'rt_total_charge.avg': { avg: { field: 'rt_total_charge' } },
'rt_total_charge.min': { min: { field: 'rt_total_charge' } },
'rt_total_charge.max': { max: { field: 'rt_total_charge' } },
},
},
description: 'ecommerce batch transform grouped by terms(rt_gender_lower)',
frequency: '3s',
settings: {
max_page_search_size: 250,
},
dest: { index: `user-ec_2_${date}` },
};
}

export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const transform = getService('transform');

describe('cloning', function () {
const transformConfigWithPivot = getTransformConfig();
const transformConfigWithRuntimeMapping = getTransformConfigWithRuntimeMappings();
// const transformConfigWithLatest = getLatestTransformConfig();

before(async () => {
Expand All @@ -56,6 +94,11 @@ export default function ({ getService }: FtrProviderContext) {
transformConfigWithPivot.id,
transformConfigWithPivot
);
await transform.api.createAndRunTransform(
transformConfigWithRuntimeMapping.id,
transformConfigWithRuntimeMapping
);

// await transform.api.createAndRunTransform(
// transformConfigWithLatest.id,
// transformConfigWithLatest
Expand All @@ -67,8 +110,13 @@ export default function ({ getService }: FtrProviderContext) {

after(async () => {
await transform.testResources.deleteIndexPatternByTitle(transformConfigWithPivot.dest.index);
await transform.testResources.deleteIndexPatternByTitle(
transformConfigWithRuntimeMapping.dest.index
);

// await transform.testResources.deleteIndexPatternByTitle(transformConfigWithLatest.dest.index);
await transform.api.deleteIndices(transformConfigWithPivot.dest.index);
await transform.api.deleteIndices(transformConfigWithRuntimeMapping.dest.index);
// await transform.api.deleteIndices(transformConfigWithLatest.dest.index);
await transform.api.cleanTransformIndices();
});
Expand All @@ -84,6 +132,7 @@ export default function ({ getService }: FtrProviderContext) {
return `user-${this.transformId}`;
},
expected: {
runtimeMappingsEditorValueArr: [''],
aggs: {
index: 0,
label: 'products.base_price.avg',
Expand All @@ -108,6 +157,35 @@ export default function ({ getService }: FtrProviderContext) {
},
},
},
{
type: 'pivot' as const,
suiteTitle: 'clone transform with runtime mappings',
originalConfig: transformConfigWithRuntimeMapping,
transformId: `clone_${transformConfigWithRuntimeMapping.id}`,
transformDescription: `a cloned transform with runtime mappings`,
get destinationIndex(): string {
return `user-${this.transformId}`;
},
expected: {
runtimeMappingsEditorValueArr: ['{', ' "rt_gender_lower": {', ' "type": "keyword",'],
aggs: {
index: 0,
label: 'rt_total_charge.avg',
},
indexPreview: {
columns: 10,
rows: 5,
},
groupBy: {
index: 0,
label: 'rt_gender_lower',
},
transformPreview: {
column: 0,
values: [`female`, `male`],
},
},
},
// TODO enable tests when https://github.com/elastic/elasticsearch/issues/67148 is resolved
// {
// type: 'latest' as const,
Expand Down Expand Up @@ -168,6 +246,18 @@ export default function ({ getService }: FtrProviderContext) {
});

it('navigates through the wizard, checks and sets all needed fields', async () => {
await transform.testExecution.logTestStep('should have runtime mapping editor');
await transform.wizard.assertRuntimeMappingsEditorSwitchExists();
await transform.wizard.assertRuntimeMappingsEditorSwitchCheckState(false);

if (testData.expected.runtimeMappingsEditorValueArr) {
await transform.wizard.toggleRuntimeMappingsEditorSwitch(true);
await transform.wizard.assertRuntimeMappingsEditorExists();
await transform.wizard.assertRuntimeMappingsEditorContent(
testData.expected.runtimeMappingsEditorValueArr
);
}

await transform.testExecution.logTestStep('should load the index preview');
await transform.wizard.assertIndexPreviewLoaded();

Expand Down
Loading

0 comments on commit fcf397f

Please sign in to comment.