mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[ML] Transforms: Use delete_dest_index
flag instead of ES call to delete destination index. (#166797)
Part of #166796. Depends on https://github.com/elastic/elasticsearch/pull/99738. Uses the `delete_dest_index` flag instead of ES call to delete destination index in the transforms UI when deleting transforms. The PR also fixes some code related to destination indices for transforms and data frame analytics. A destination index can be just a single string. Before the properly typed transform APIs were available via `estypes`, we accidentally treated destination indices similar to source indices which might also be arrays of indices.
This commit is contained in:
parent
8e7b2338ba
commit
43a04a4205
8 changed files with 15 additions and 34 deletions
|
@ -8,4 +8,4 @@
|
|||
import type { DataFrameAnalyticsConfig } from '@kbn/ml-data-frame-analytics-utils';
|
||||
|
||||
export const getDestinationIndex = (jobConfig: DataFrameAnalyticsConfig | undefined) =>
|
||||
(Array.isArray(jobConfig?.dest.index) ? jobConfig?.dest.index[0] : jobConfig?.dest.index) ?? '';
|
||||
jobConfig?.dest.index ?? '';
|
||||
|
|
|
@ -29,6 +29,8 @@ import { deleteActionNameText, DeleteActionName } from './delete_action_name';
|
|||
|
||||
import { JobType } from '../../../../../../../common/types/saved_objects';
|
||||
|
||||
import { getDestinationIndex } from '../../../../common/get_destination_index';
|
||||
|
||||
const DF_ANALYTICS_JOB_TYPE: JobType = 'data-frame-analytics';
|
||||
|
||||
type DataFrameAnalyticsListRowEssentials = Pick<DataFrameAnalyticsListRow, 'config' | 'stats'>;
|
||||
|
@ -51,7 +53,7 @@ export const useDeleteAction = (canDeleteDataFrameAnalytics: boolean) => {
|
|||
application: { capabilities },
|
||||
} = useMlKibana().services;
|
||||
|
||||
const indexName = item?.config.dest.index ?? '';
|
||||
const indexName = getDestinationIndex(item?.config);
|
||||
|
||||
const toastNotificationService = useToastNotificationService();
|
||||
|
||||
|
|
|
@ -51,9 +51,7 @@ export const deleteAnalyticsAndDestIndex = async (
|
|||
deleteDestIndexPattern: boolean,
|
||||
toastNotificationService: ToastNotificationService
|
||||
) => {
|
||||
const destinationIndex = Array.isArray(analyticsConfig.dest.index)
|
||||
? analyticsConfig.dest.index[0]
|
||||
: analyticsConfig.dest.index;
|
||||
const destinationIndex = analyticsConfig.dest.index;
|
||||
try {
|
||||
if (isDataFrameAnalyticsFailed(analyticsStats.state)) {
|
||||
await ml.dataFrameAnalytics.stopDataFrameAnalytics(analyticsConfig.id, true);
|
||||
|
|
|
@ -26,7 +26,7 @@ export const useDataViewExists = (items: TransformListRow[]) => {
|
|||
return false;
|
||||
}
|
||||
const config = items[0].config;
|
||||
const indexName = Array.isArray(config.dest.index) ? config.dest.index[0] : config.dest.index;
|
||||
const indexName = config.dest.index;
|
||||
|
||||
if (indexName === undefined) {
|
||||
return false;
|
||||
|
|
|
@ -56,7 +56,7 @@ export const useDeleteIndexAndTargetIndex = (items: TransformListRow[]) => {
|
|||
useEffect(() => {
|
||||
if (dataViewExistsError !== null && items.length === 1) {
|
||||
const config = items[0].config;
|
||||
const indexName = Array.isArray(config.dest.index) ? config.dest.index[0] : config.dest.index;
|
||||
const indexName = config.dest.index;
|
||||
|
||||
toastNotifications.addDanger(
|
||||
i18n.translate(
|
||||
|
|
|
@ -19,9 +19,6 @@ import {
|
|||
DiscoverActionName,
|
||||
} from './discover_action_name';
|
||||
|
||||
const getDataViewTitleFromTargetIndex = (item: TransformListRow) =>
|
||||
Array.isArray(item.config.dest.index) ? item.config.dest.index.join(',') : item.config.dest.index;
|
||||
|
||||
export type DiscoverAction = ReturnType<typeof useDiscoverAction>;
|
||||
export const useDiscoverAction = (forceDisable: boolean) => {
|
||||
const {
|
||||
|
@ -48,8 +45,7 @@ export const useDiscoverAction = (forceDisable: boolean) => {
|
|||
(item: TransformListRow) => {
|
||||
const locator = share.url.locators.get(DISCOVER_APP_LOCATOR);
|
||||
if (!locator) return;
|
||||
const dataViewTitle = getDataViewTitleFromTargetIndex(item);
|
||||
const dataViewId = getDataViewIdByTitle(dataViewTitle);
|
||||
const dataViewId = getDataViewIdByTitle(item.config.dest.index);
|
||||
locator.navigateSync({
|
||||
indexPatternId: dataViewId,
|
||||
});
|
||||
|
@ -59,8 +55,7 @@ export const useDiscoverAction = (forceDisable: boolean) => {
|
|||
|
||||
const dataViewExists = useCallback(
|
||||
(item: TransformListRow) => {
|
||||
const dataViewTitle = getDataViewTitleFromTargetIndex(item);
|
||||
const dataViewId = getDataViewIdByTitle(dataViewTitle);
|
||||
const dataViewId = getDataViewIdByTitle(item.config.dest.index);
|
||||
return dataViewId !== undefined;
|
||||
},
|
||||
[getDataViewIdByTitle]
|
||||
|
|
|
@ -101,7 +101,7 @@ export const ExpandedRow: FC<Props> = ({ item, onAlertEdit, transformsStatsLoadi
|
|||
},
|
||||
{
|
||||
title: 'transform_version',
|
||||
description: item.config.version,
|
||||
description: item.config.version ?? '',
|
||||
},
|
||||
{
|
||||
title: 'description',
|
||||
|
@ -120,9 +120,7 @@ export const ExpandedRow: FC<Props> = ({ item, onAlertEdit, transformsStatsLoadi
|
|||
},
|
||||
{
|
||||
title: 'destination_index',
|
||||
description: Array.isArray(item.config.dest.index)
|
||||
? item.config.dest.index[0]
|
||||
: item.config.dest.index,
|
||||
description: item.config.dest.index,
|
||||
},
|
||||
{
|
||||
title: 'authorization',
|
||||
|
|
|
@ -677,9 +677,7 @@ async function deleteTransforms(
|
|||
transform_id: transformId,
|
||||
});
|
||||
const transformConfig = body.transforms[0];
|
||||
destinationIndex = Array.isArray(transformConfig.dest.index)
|
||||
? transformConfig.dest.index[0]
|
||||
: transformConfig.dest.index;
|
||||
destinationIndex = transformConfig.dest.index;
|
||||
} catch (getTransformConfigError) {
|
||||
transformDeleted.error = getTransformConfigError.meta.body.error;
|
||||
results[transformId] = {
|
||||
|
@ -692,19 +690,6 @@ async function deleteTransforms(
|
|||
continue;
|
||||
}
|
||||
}
|
||||
// If user checks box to delete the destinationIndex associated with the job
|
||||
if (destinationIndex && deleteDestIndex) {
|
||||
try {
|
||||
// If user does have privilege to delete the index, then delete the index
|
||||
// if no permission then return 403 forbidden
|
||||
await esClient.asCurrentUser.indices.delete({
|
||||
index: destinationIndex,
|
||||
});
|
||||
destIndexDeleted.success = true;
|
||||
} catch (deleteIndexError) {
|
||||
destIndexDeleted.error = deleteIndexError.meta.body.error;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the data view if there's a data view that matches the name of dest index
|
||||
if (destinationIndex && deleteDestDataView) {
|
||||
|
@ -723,8 +708,11 @@ async function deleteTransforms(
|
|||
await esClient.asCurrentUser.transform.deleteTransform({
|
||||
transform_id: transformId,
|
||||
force: shouldForceDelete && needToForceDelete,
|
||||
// @ts-expect-error ES type needs to be updated
|
||||
delete_dest_index: deleteDestIndex,
|
||||
});
|
||||
transformDeleted.success = true;
|
||||
destIndexDeleted.success = deleteDestIndex;
|
||||
} catch (deleteTransformJobError) {
|
||||
transformDeleted.error = deleteTransformJobError.meta.body.error;
|
||||
if (deleteTransformJobError.statusCode === 403) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue