Skip to content

Commit

Permalink
Revert "[ML] Transforms: Add ability to delete dest index & index pat…
Browse files Browse the repository at this point in the history
…tern when deleting transform job" (#68793)
  • Loading branch information
qn895 authored Jun 10, 2020
1 parent 332a138 commit 3197a00
Show file tree
Hide file tree
Showing 24 changed files with 107 additions and 1,165 deletions.
78 changes: 0 additions & 78 deletions x-pack/plugins/ml/common/util/errors.test.ts

This file was deleted.

75 changes: 0 additions & 75 deletions x-pack/plugins/ml/common/util/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ResponseError, ResponseHeaders } from 'kibana/server';
import { isErrorResponse } from '../types/errors';

export function getErrorMessage(error: any) {
Expand All @@ -18,77 +17,3 @@ export function getErrorMessage(error: any) {

return JSON.stringify(error);
}

// Adding temporary types until Kibana ResponseError is updated

export interface BoomResponse {
data: any;
isBoom: boolean;
isServer: boolean;
output: {
statusCode: number;
payload: {
statusCode: number;
error: string;
message: string;
};
headers: {};
};
}
export type MLResponseError =
| {
message: {
msg: string;
};
}
| { msg: string };

export interface MLCustomHttpResponseOptions<
T extends ResponseError | MLResponseError | BoomResponse
> {
/** HTTP message to send to the client */
body?: T;
/** HTTP Headers with additional information about response */
headers?: ResponseHeaders;
statusCode: number;
}

export const extractErrorMessage = (
error:
| MLCustomHttpResponseOptions<MLResponseError | ResponseError | BoomResponse>
| undefined
| string
): string => {
// extract only the error message within the response error coming from Kibana, Elasticsearch, and our own ML messages

if (typeof error === 'string') {
return error;
}
if (error?.body === undefined) return '';

if (typeof error.body === 'string') {
return error.body;
}
if (
typeof error.body === 'object' &&
'output' in error.body &&
error.body.output.payload.message
) {
return error.body.output.payload.message;
}

if (typeof error.body === 'object' && 'msg' in error.body && typeof error.body.msg === 'string') {
return error.body.msg;
}

if (typeof error.body === 'object' && 'message' in error.body) {
if (typeof error.body.message === 'string') {
return error.body.message;
}
if (!(error.body.message instanceof Error) && typeof (error.body.message.msg === 'string')) {
return error.body.message.msg;
}
}
// If all else fail return an empty message instead of JSON.stringify
return '';
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
} from '@elastic/eui';
import { IIndexPattern } from 'src/plugins/data/common';
import { FormattedMessage } from '@kbn/i18n/react';
import { extractErrorMessage } from '../../../../../../../common/util/errors';
import {
deleteAnalytics,
deleteAnalyticsAndDestIndex,
Expand All @@ -30,6 +29,7 @@ import {
} from '../../../../../capabilities/check_capabilities';
import { useMlKibana } from '../../../../../contexts/kibana';
import { isDataFrameAnalyticsRunning, DataFrameAnalyticsListRow } from './common';
import { extractErrorMessage } from '../../../../../util/error_utils';

interface DeleteActionProps {
item: DataFrameAnalyticsListRow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { i18n } from '@kbn/i18n';
import { extractErrorMessage } from '../../../../../../../common/util/errors';
import { getToastNotifications } from '../../../../../util/dependency_cache';
import { ml } from '../../../../../services/ml_api_service';
import { refreshAnalyticsList$, REFRESH_ANALYTICS_LIST_STATE } from '../../../../common';
import {
isDataFrameAnalyticsFailed,
DataFrameAnalyticsListRow,
} from '../../components/analytics_list/common';
import { extractErrorMessage } from '../../../../../util/error_utils';

export const deleteAnalytics = async (d: DataFrameAnalyticsListRow) => {
const toastNotifications = getToastNotifications();
Expand Down
32 changes: 32 additions & 0 deletions x-pack/plugins/ml/public/application/util/error_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { CustomHttpResponseOptions, ResponseError } from 'kibana/server';

export const extractErrorMessage = (
error: CustomHttpResponseOptions<ResponseError> | undefined | string
): string | undefined => {
if (typeof error === 'string') {
return error;
}

if (error?.body) {
if (typeof error.body === 'string') {
return error.body;
}
if (typeof error.body === 'object' && 'message' in error.body) {
if (typeof error.body.message === 'string') {
return error.body.message;
}
// @ts-ignore
if (typeof (error.body.message?.msg === 'string')) {
// @ts-ignore
return error.body.message?.msg;
}
}
}
return undefined;
};
1 change: 0 additions & 1 deletion x-pack/plugins/ml/public/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export * from '../common/types/audit_message';

export * from '../common/util/anomaly_utils';
export * from '../common/util/errors';

export * from '../common/util/validators';

export * from './application/formatters/metric_change_description';
Expand Down
17 changes: 0 additions & 17 deletions x-pack/plugins/transform/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,3 @@ export interface ResultData {
export interface TransformEndpointResult {
[key: string]: ResultData;
}

export interface DeleteTransformEndpointRequest {
transformsInfo: TransformEndpointRequest[];
deleteDestIndex?: boolean;
deleteDestIndexPattern?: boolean;
}

export interface DeleteTransformStatus {
transformDeleted: ResultData;
destIndexDeleted?: ResultData;
destIndexPatternDeleted?: ResultData;
destinationIndex?: string | undefined;
}

export interface DeleteTransformEndpointResult {
[key: string]: DeleteTransformStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ const MAX_SIMPLE_MESSAGE_LENGTH = 140;
interface ToastNotificationTextProps {
overlays: CoreStart['overlays'];
text: any;
previewTextLength?: number;
}

export const ToastNotificationText: FC<ToastNotificationTextProps> = ({
overlays,
text,
previewTextLength,
}) => {
export const ToastNotificationText: FC<ToastNotificationTextProps> = ({ overlays, text }) => {
if (typeof text === 'string' && text.length <= MAX_SIMPLE_MESSAGE_LENGTH) {
return text;
}
Expand All @@ -51,9 +46,8 @@ export const ToastNotificationText: FC<ToastNotificationTextProps> = ({

const unformattedText = text.message ? text.message : text;
const formattedText = typeof unformattedText === 'object' ? JSON.stringify(text, null, 2) : text;
const textLength = previewTextLength ?? 140;
const previewText = `${formattedText.substring(0, textLength)}${
formattedText.length > textLength ? ' ...' : ''
const previewText = `${formattedText.substring(0, 140)}${
formattedText.length > 140 ? ' ...' : ''
}`;

const openModal = () => {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/transform/public/app/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

export { useApi } from './use_api';
export { useGetTransforms } from './use_get_transforms';
export { useDeleteTransforms, useDeleteIndexAndTargetIndex } from './use_delete_transform';
export { useDeleteTransforms } from './use_delete_transform';
export { useStartTransforms } from './use_start_transform';
export { useStopTransforms } from './use_stop_transform';
export { useRequest } from './use_request';
15 changes: 4 additions & 11 deletions x-pack/plugins/transform/public/app/hooks/use_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
*/

import { useMemo } from 'react';
import {
TransformId,
TransformEndpointRequest,
TransformEndpointResult,
DeleteTransformEndpointResult,
} from '../../../common';
import { TransformEndpointRequest, TransformEndpointResult, TransformId } from '../../../common';
import { API_BASE_PATH } from '../../../common/constants';

import { useAppDependencies } from '../app_dependencies';
Expand Down Expand Up @@ -45,12 +40,10 @@ export const useApi = () => {
});
},
deleteTransforms(
transformsInfo: TransformEndpointRequest[],
deleteDestIndex: boolean | undefined,
deleteDestIndexPattern: boolean | undefined
): Promise<DeleteTransformEndpointResult> {
transformsInfo: TransformEndpointRequest[]
): Promise<TransformEndpointResult> {
return http.post(`${API_BASE_PATH}delete_transforms`, {
body: JSON.stringify({ transformsInfo, deleteDestIndex, deleteDestIndexPattern }),
body: JSON.stringify(transformsInfo),
});
},
getTransformsPreview(obj: PreviewRequestBody): Promise<GetTransformsResponse> {
Expand Down
Loading

0 comments on commit 3197a00

Please sign in to comment.