Skip to content

Commit d5ce8f1

Browse files
kibanamachineqn895
andauthored
[ML] Add functional tests for runtime mappings in Transforms (#92738) (#94155)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Quynh Nguyen <43350163+qn895@users.noreply.github.com>
1 parent a25fdc3 commit d5ce8f1

File tree

8 files changed

+650
-24
lines changed

8 files changed

+650
-24
lines changed

x-pack/plugins/ml/public/application/components/data_grid/use_data_grid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const useDataGrid = (
112112
<ColumnChart
113113
chartData={chartData}
114114
columnType={c}
115-
dataTestSubj={`mlDataGridChart-${index}`}
115+
dataTestSubj={`mlDataGridChart-${c.id}`}
116116
/>
117117
) : undefined,
118118
};

x-pack/plugins/transform/public/app/sections/create_transform/components/advanced_runtime_mappings_editor/advanced_runtime_mappings_editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const AdvancedRuntimeMappingsEditor: FC<StepDefineFormHook['runtimeMappin
2626
}) => {
2727
return (
2828
<EuiCodeEditor
29-
data-test-subj="transformAdvancedPivotEditor"
29+
data-test-subj="transformAdvancedRuntimeMappingsEditor"
3030
style={{ border: '1px solid #e3e6ef' }}
3131
height="250px"
3232
width="100%"

x-pack/plugins/transform/public/app/sections/create_transform/components/advanced_runtime_mappings_settings/advanced_runtime_mappings_settings.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export const AdvancedRuntimeMappingsSettings: FC<StepDefineFormHook> = (props) =
155155
fill
156156
onClick={applyChanges}
157157
disabled={!isRuntimeMappingsEditorApplyButtonEnabled}
158+
data-test-subj="transformRuntimeMappingsApplyButton"
158159
>
159160
{i18n.translate(
160161
'xpack.transform.stepDefineForm.advancedSourceEditorApplyButtonText',

x-pack/test/functional/apps/transform/cloning.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,50 @@ function getTransformConfig(): TransformPivotConfig {
4141
};
4242
}
4343

44+
function getTransformConfigWithRuntimeMappings(): TransformPivotConfig {
45+
const date = Date.now();
46+
47+
return {
48+
id: `ec_cloning_runtime_${date}`,
49+
source: {
50+
index: ['ft_ecommerce'],
51+
runtime_mappings: {
52+
rt_gender_lower: {
53+
type: 'keyword',
54+
script: "emit(doc['customer_gender'].value.toLowerCase())",
55+
},
56+
rt_total_charge: {
57+
type: 'double',
58+
script: {
59+
source: "emit(doc['taxful_total_price'].value + 4.00)",
60+
},
61+
},
62+
},
63+
},
64+
pivot: {
65+
group_by: { rt_gender_lower: { terms: { field: 'rt_gender_lower' } } },
66+
aggregations: {
67+
'rt_total_charge.avg': { avg: { field: 'rt_total_charge' } },
68+
'rt_total_charge.min': { min: { field: 'rt_total_charge' } },
69+
'rt_total_charge.max': { max: { field: 'rt_total_charge' } },
70+
},
71+
},
72+
description: 'ecommerce batch transform grouped by terms(rt_gender_lower)',
73+
frequency: '3s',
74+
settings: {
75+
max_page_search_size: 250,
76+
},
77+
dest: { index: `user-ec_2_${date}` },
78+
};
79+
}
80+
4481
export default function ({ getService }: FtrProviderContext) {
4582
const esArchiver = getService('esArchiver');
4683
const transform = getService('transform');
4784

4885
describe('cloning', function () {
4986
const transformConfigWithPivot = getTransformConfig();
87+
const transformConfigWithRuntimeMapping = getTransformConfigWithRuntimeMappings();
5088
// const transformConfigWithLatest = getLatestTransformConfig();
5189

5290
before(async () => {
@@ -56,6 +94,11 @@ export default function ({ getService }: FtrProviderContext) {
5694
transformConfigWithPivot.id,
5795
transformConfigWithPivot
5896
);
97+
await transform.api.createAndRunTransform(
98+
transformConfigWithRuntimeMapping.id,
99+
transformConfigWithRuntimeMapping
100+
);
101+
59102
// await transform.api.createAndRunTransform(
60103
// transformConfigWithLatest.id,
61104
// transformConfigWithLatest
@@ -67,8 +110,13 @@ export default function ({ getService }: FtrProviderContext) {
67110

68111
after(async () => {
69112
await transform.testResources.deleteIndexPatternByTitle(transformConfigWithPivot.dest.index);
113+
await transform.testResources.deleteIndexPatternByTitle(
114+
transformConfigWithRuntimeMapping.dest.index
115+
);
116+
70117
// await transform.testResources.deleteIndexPatternByTitle(transformConfigWithLatest.dest.index);
71118
await transform.api.deleteIndices(transformConfigWithPivot.dest.index);
119+
await transform.api.deleteIndices(transformConfigWithRuntimeMapping.dest.index);
72120
// await transform.api.deleteIndices(transformConfigWithLatest.dest.index);
73121
await transform.api.cleanTransformIndices();
74122
});
@@ -84,6 +132,7 @@ export default function ({ getService }: FtrProviderContext) {
84132
return `user-${this.transformId}`;
85133
},
86134
expected: {
135+
runtimeMappingsEditorValueArr: [''],
87136
aggs: {
88137
index: 0,
89138
label: 'products.base_price.avg',
@@ -108,6 +157,35 @@ export default function ({ getService }: FtrProviderContext) {
108157
},
109158
},
110159
},
160+
{
161+
type: 'pivot' as const,
162+
suiteTitle: 'clone transform with runtime mappings',
163+
originalConfig: transformConfigWithRuntimeMapping,
164+
transformId: `clone_${transformConfigWithRuntimeMapping.id}`,
165+
transformDescription: `a cloned transform with runtime mappings`,
166+
get destinationIndex(): string {
167+
return `user-${this.transformId}`;
168+
},
169+
expected: {
170+
runtimeMappingsEditorValueArr: ['{', ' "rt_gender_lower": {', ' "type": "keyword",'],
171+
aggs: {
172+
index: 0,
173+
label: 'rt_total_charge.avg',
174+
},
175+
indexPreview: {
176+
columns: 10,
177+
rows: 5,
178+
},
179+
groupBy: {
180+
index: 0,
181+
label: 'rt_gender_lower',
182+
},
183+
transformPreview: {
184+
column: 0,
185+
values: [`female`, `male`],
186+
},
187+
},
188+
},
111189
// TODO enable tests when https://github.com/elastic/elasticsearch/issues/67148 is resolved
112190
// {
113191
// type: 'latest' as const,
@@ -168,6 +246,18 @@ export default function ({ getService }: FtrProviderContext) {
168246
});
169247

170248
it('navigates through the wizard, checks and sets all needed fields', async () => {
249+
await transform.testExecution.logTestStep('should have runtime mapping editor');
250+
await transform.wizard.assertRuntimeMappingsEditorSwitchExists();
251+
await transform.wizard.assertRuntimeMappingsEditorSwitchCheckState(false);
252+
253+
if (testData.expected.runtimeMappingsEditorValueArr) {
254+
await transform.wizard.toggleRuntimeMappingsEditorSwitch(true);
255+
await transform.wizard.assertRuntimeMappingsEditorExists();
256+
await transform.wizard.assertRuntimeMappingsEditorContent(
257+
testData.expected.runtimeMappingsEditorValueArr
258+
);
259+
}
260+
171261
await transform.testExecution.logTestStep('should load the index preview');
172262
await transform.wizard.assertIndexPreviewLoaded();
173263

0 commit comments

Comments
 (0)