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] Transforms/Data frame analytics: Aligns data view / destination index creation workflow in wizards #171202

Merged
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
be70122
creates data_view_utils package
walterra Nov 14, 2023
11b84f5
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Nov 14, 2023
ff5ea62
improve types for API integration tests
walterra Nov 20, 2023
d96fa74
use API query options to create data view on job creation
walterra Nov 20, 2023
a5f68b6
update API integration tests
walterra Nov 20, 2023
6ba3f7f
linting
walterra Nov 21, 2023
b3090c1
rename index pattern to data view
walterra Nov 21, 2023
daa07ab
revert comments
walterra Nov 21, 2023
1c33a9b
move data view creation code to package
walterra Nov 22, 2023
5df8d4e
move data view delete code to package
walterra Nov 22, 2023
04e21bf
move schema to package
walterra Nov 22, 2023
473e46a
use package to delete data view in transform API
walterra Nov 22, 2023
a52cb00
linting
walterra Nov 22, 2023
f328d31
fix error message handling
walterra Nov 22, 2023
c81bb0e
rename index pattern to data view
walterra Nov 22, 2023
87ed625
rename index pattern to data view
walterra Nov 22, 2023
5f32d07
move transform ui components for data view creation to package
walterra Nov 22, 2023
78f2e47
use data view utils package for data frame analytics wizard components
walterra Nov 22, 2023
a689cbe
linting
walterra Nov 22, 2023
8b77db9
fix i18n
walterra Nov 22, 2023
880d286
fix functional tests
walterra Nov 23, 2023
6ff108e
cleanup
walterra Nov 23, 2023
621a1cf
revert es prefix
walterra Nov 23, 2023
eacd9b3
@kbn/ml-creation-wizard DestinationIndexForm component
walterra Nov 23, 2023
4eeb847
Use DestinationIndexForm in transform wizard
walterra Nov 23, 2023
edf26ea
fix i18n
walterra Nov 23, 2023
ee56458
linting
walterra Nov 23, 2023
7b17044
fix functional tests
walterra Nov 24, 2023
49d6b79
fix form width for transform wizard
walterra Nov 24, 2023
c5cc326
fix i18n
walterra Nov 24, 2023
ce5ad98
delete comment
walterra Nov 24, 2023
4b4a0c3
Merge branch 'main' into 160593-ml-consolidate-data-view-creation-wor…
walterra Nov 27, 2023
307d22f
add data view ui section to DFA JSON editor
walterra Nov 27, 2023
6cd6dc6
fix functional tests
walterra Nov 27, 2023
59cf486
change start dfa job from checkbox to switch
walterra Nov 27, 2023
371a510
Merge branch 'main' into 160593-ml-consolidate-data-view-creation-wor…
walterra Nov 29, 2023
0b8692e
remove disabled attribute
walterra Nov 29, 2023
019889b
Merge branch 'main' into 160593-ml-consolidate-data-view-creation-wor…
walterra Nov 29, 2023
4241809
fix functional tests
walterra Nov 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -517,8 +517,10 @@ x-pack/packages/ml/agg_utils @elastic/ml-ui
x-pack/packages/ml/anomaly_utils @elastic/ml-ui
x-pack/packages/ml/category_validator @elastic/ml-ui
x-pack/packages/ml/chi2test @elastic/ml-ui
x-pack/packages/ml/creation_wizard_utils @elastic/ml-ui
x-pack/packages/ml/data_frame_analytics_utils @elastic/ml-ui
x-pack/packages/ml/data_grid @elastic/ml-ui
x-pack/packages/ml/data_view_utils @elastic/ml-ui
x-pack/packages/ml/date_picker @elastic/ml-ui
x-pack/packages/ml/date_utils @elastic/ml-ui
x-pack/packages/ml/error_utils @elastic/ml-ui
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -536,8 +536,10 @@
"@kbn/ml-anomaly-utils": "link:x-pack/packages/ml/anomaly_utils",
"@kbn/ml-category-validator": "link:x-pack/packages/ml/category_validator",
"@kbn/ml-chi2test": "link:x-pack/packages/ml/chi2test",
"@kbn/ml-creation-wizard-utils": "link:x-pack/packages/ml/creation_wizard_utils",
"@kbn/ml-data-frame-analytics-utils": "link:x-pack/packages/ml/data_frame_analytics_utils",
"@kbn/ml-data-grid": "link:x-pack/packages/ml/data_grid",
"@kbn/ml-data-view-utils": "link:x-pack/packages/ml/data_view_utils",
"@kbn/ml-date-picker": "link:x-pack/packages/ml/date_picker",
"@kbn/ml-date-utils": "link:x-pack/packages/ml/date_utils",
"@kbn/ml-error-utils": "link:x-pack/packages/ml/error_utils",
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.base.json
Expand Up @@ -1028,10 +1028,14 @@
"@kbn/ml-category-validator/*": ["x-pack/packages/ml/category_validator/*"],
"@kbn/ml-chi2test": ["x-pack/packages/ml/chi2test"],
"@kbn/ml-chi2test/*": ["x-pack/packages/ml/chi2test/*"],
"@kbn/ml-creation-wizard-utils": ["x-pack/packages/ml/creation_wizard_utils"],
"@kbn/ml-creation-wizard-utils/*": ["x-pack/packages/ml/creation_wizard_utils/*"],
"@kbn/ml-data-frame-analytics-utils": ["x-pack/packages/ml/data_frame_analytics_utils"],
"@kbn/ml-data-frame-analytics-utils/*": ["x-pack/packages/ml/data_frame_analytics_utils/*"],
"@kbn/ml-data-grid": ["x-pack/packages/ml/data_grid"],
"@kbn/ml-data-grid/*": ["x-pack/packages/ml/data_grid/*"],
"@kbn/ml-data-view-utils": ["x-pack/packages/ml/data_view_utils"],
"@kbn/ml-data-view-utils/*": ["x-pack/packages/ml/data_view_utils/*"],
"@kbn/ml-date-picker": ["x-pack/packages/ml/date_picker"],
"@kbn/ml-date-picker/*": ["x-pack/packages/ml/date_picker/*"],
"@kbn/ml-date-utils": ["x-pack/packages/ml/date_utils"],
Expand Down
2 changes: 2 additions & 0 deletions x-pack/.i18nrc.json
Expand Up @@ -55,7 +55,9 @@
"xpack.metricsData": "plugins/metrics_data_access",
"xpack.ml": [
"packages/ml/anomaly_utils",
"packages/ml/creation_wizard_utils",
"packages/ml/data_grid",
"packages/ml/data_view_utils",
"packages/ml/date_picker",
"packages/ml/trained_models_utils",
"packages/ml/category_validator",
Expand Down
3 changes: 3 additions & 0 deletions x-pack/packages/ml/creation_wizard_utils/README.md
@@ -0,0 +1,3 @@
# @kbn/ml-creation-wizard-utils

Utilities and components shared across creation wizards in plugins owned by the @elastic/ml-ui team.
@@ -0,0 +1,102 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React, { type FC } from 'react';

import { EuiFieldText, EuiFormRow, EuiLink } from '@elastic/eui';

import { i18n } from '@kbn/i18n';

import { UseIdAsIndexNameSwitch } from './use_id_as_index_name_switch';

interface DestinationIndexFormProps {
createIndexLink: string;
destinationIndex: string;
destinationIndexNameEmpty: boolean;
destinationIndexNameExists: boolean;
destinationIndexNameValid: boolean;
destIndexSameAsId: boolean;
fullWidth?: boolean;
indexNameExistsMessage: string;
isJobCreated: boolean;
onDestinationIndexChange: (d: string) => void;
setDestIndexSameAsId: (d: boolean) => void;
switchLabel: string;
}

export const DestinationIndexForm: FC<DestinationIndexFormProps> = ({
createIndexLink,
destinationIndex,
destinationIndexNameEmpty,
destinationIndexNameExists,
destinationIndexNameValid,
destIndexSameAsId,
fullWidth = true,
indexNameExistsMessage,
isJobCreated,
onDestinationIndexChange,
setDestIndexSameAsId,
switchLabel,
}) => (
<>
<EuiFormRow
fullWidth={fullWidth}
helpText={destIndexSameAsId === true && destinationIndexNameExists && indexNameExistsMessage}
>
<UseIdAsIndexNameSwitch
destIndexSameAsId={destIndexSameAsId}
isJobCreated={isJobCreated}
setDestIndexSameAsId={setDestIndexSameAsId}
label={switchLabel}
/>
</EuiFormRow>
{destIndexSameAsId === false && (
<EuiFormRow
fullWidth={fullWidth}
label={i18n.translate('xpack.ml.creationWizardUtils.destinationIndexLabel', {
defaultMessage: 'Destination index',
})}
isInvalid={
destinationIndexNameEmpty || (!destinationIndexNameEmpty && !destinationIndexNameValid)
}
helpText={destinationIndexNameExists && indexNameExistsMessage}
error={
!destinationIndexNameEmpty &&
!destinationIndexNameValid && [
<>
{i18n.translate('xpack.ml.creationWizardUtils.destinationIndexInvalidError', {
defaultMessage: 'Invalid destination index name.',
})}
<br />
<EuiLink href={createIndexLink} target="_blank">
{i18n.translate('xpack.ml.creationWizardUtils.destinationIndexInvalidErrorLink', {
defaultMessage: 'Learn more about index name limitations.',
})}
</EuiLink>
</>,
]
}
>
<EuiFieldText
fullWidth={fullWidth}
disabled={isJobCreated}
placeholder="destination index"
value={destinationIndex}
onChange={(e) => onDestinationIndexChange(e.target.value)}
aria-label={i18n.translate(
'xpack.ml.creationWizardUtils.destinationIndexInputAriaLabel',
{
defaultMessage: 'Choose a unique destination index name.',
}
)}
isInvalid={!destinationIndexNameEmpty && !destinationIndexNameValid}
data-test-subj="mlCreationWizardUtilsDestinationIndexInput"
/>
</EuiFormRow>
)}
</>
);
@@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React, { type FC } from 'react';

import { EuiSwitch } from '@elastic/eui';

interface UseIdAsIndexNameSwitchProps {
destIndexSameAsId: boolean;
isJobCreated: boolean;
setDestIndexSameAsId: (d: boolean) => void;
label: string;
}

export const UseIdAsIndexNameSwitch: FC<UseIdAsIndexNameSwitchProps> = ({
destIndexSameAsId,
isJobCreated,
setDestIndexSameAsId,
label,
}) => (
<EuiSwitch
disabled={isJobCreated}
name="mlCreationWizardUtilsJobIdAsDestIndexName"
label={label}
checked={destIndexSameAsId === true}
onChange={() => setDestIndexSameAsId(!destIndexSameAsId)}
data-test-subj="mlCreationWizardUtilsJobIdAsDestIndexNameSwitch"
/>
);
12 changes: 12 additions & 0 deletions x-pack/packages/ml/creation_wizard_utils/jest.config.js
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../../..',
roots: ['<rootDir>/x-pack/packages/ml/creation_wizard_utils'],
};
5 changes: 5 additions & 0 deletions x-pack/packages/ml/creation_wizard_utils/kibana.jsonc
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/ml-creation-wizard-utils",
"owner": "@elastic/ml-ui"
}
6 changes: 6 additions & 0 deletions x-pack/packages/ml/creation_wizard_utils/package.json
@@ -0,0 +1,6 @@
{
"name": "@kbn/ml-creation-wizard-utils",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0"
}
21 changes: 21 additions & 0 deletions x-pack/packages/ml/creation_wizard_utils/tsconfig.json
@@ -0,0 +1,21 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/i18n",
]
}
3 changes: 3 additions & 0 deletions x-pack/packages/ml/data_view_utils/README.md
@@ -0,0 +1,3 @@
# @kbn/ml-data-view-utils

Utilities for handling data views in plugins owned by the @elastic/ml-ui team.
54 changes: 54 additions & 0 deletions x-pack/packages/ml/data_view_utils/actions/create.ts
@@ -0,0 +1,54 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { DataViewsService, RuntimeField } from '@kbn/data-views-plugin/common';

import type { CreateDataViewApiResponseSchema } from '../types/api_create_response_schema';

interface CreateDataViewFnOptions {
dataViewsService: DataViewsService;
dataViewName: string;
runtimeMappings: Record<string, RuntimeField>;
timeFieldName?: string;
errorFallbackId: string;
}

export const createDataViewFn = async ({
dataViewsService,
dataViewName,
runtimeMappings,
timeFieldName,
// A fall back id to be able to track the response
// because in case of an error we don't get a data view id.
errorFallbackId,
}: CreateDataViewFnOptions): Promise<CreateDataViewApiResponseSchema> => {
const response: CreateDataViewApiResponseSchema = {
dataViewsCreated: [],
dataViewsErrors: [],
};

try {
const dataViewsResp = await dataViewsService.createAndSave(
{
title: dataViewName,
timeFieldName,
runtimeFieldMap: runtimeMappings,
allowNoIndex: true,
},
false,
true
);

if (dataViewsResp.id) {
response.dataViewsCreated = [{ id: dataViewsResp.id }];
}
} catch (error) {
response.dataViewsErrors = [{ id: errorFallbackId, error }];
}

return response;
};
48 changes: 48 additions & 0 deletions x-pack/packages/ml/data_view_utils/actions/delete.ts
@@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { DataViewsService } from '@kbn/data-views-plugin/common';

import type { DeleteDataViewApiResponseSchema } from '../types/api_delete_response_schema';

import { DataViewHandler } from './data_view_handler';

async function getDataViewId(dataViewsService: DataViewsService, patternName: string) {
const iph = new DataViewHandler(dataViewsService);
return await iph.getDataViewId(patternName);
}

async function deleteDestDataViewById(dataViewsService: DataViewsService, dataViewId: string) {
const iph = new DataViewHandler(dataViewsService);
return await iph.deleteDataViewById(dataViewId);
}

interface DeleteDataViewFnOptions {
dataViewsService: DataViewsService;
dataViewName: string;
}

export const deleteDataViewFn = async ({
dataViewsService,
dataViewName,
}: DeleteDataViewFnOptions): Promise<DeleteDataViewApiResponseSchema> => {
const response: DeleteDataViewApiResponseSchema = {
success: false,
};

try {
const dataViewId = await getDataViewId(dataViewsService, dataViewName);
if (dataViewId) {
await deleteDestDataViewById(dataViewsService, dataViewId);
}
response.success = true;
} catch (deleteDestDataViewError) {
response.error = deleteDestDataViewError;
}

return response;
};