[8.12] [ML] Data Frame Analytics: ensure job can be deleted from analytics map (#174212) (#174483)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[ML] Data Frame Analytics: ensure job can be deleted from analytics
map (#174212)](https://github.com/elastic/kibana/pull/174212)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Melissa
Alvarez","email":"melissa.alvarez@elastic.co"},"sourceCommit":{"committedDate":"2024-01-08T18:48:19Z","message":"[ML]
Data Frame Analytics: ensure job can be deleted from analytics map
(#174212)\n\n## Summary\r\n\r\nFixes
https://github.com/elastic/kibana/issues/174131\r\n\r\nThis PR removes
the failed job check - `stats` being undefined sometimes\r\nwas causing
the issue.\r\nThe need for stats is removed when we default to using the
`force=true`\r\noption in the delete endpoint.\r\nUsing that option
removes the need to first try and stop the job, as\r\nthat is handled by
the endpoint when using that option. This works\r\nregardless of the
job's
state.\r\n\r\n\r\n823580f2-3a09-4ed5-8641-9b2055a7051c\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] This
was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"96a9c8abe24bdd3258047ea0aecc2be108c37e72","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Feature:Data
Frame Analytics","v8.12.0","v8.13.0"],"title":"[ML] Data Frame
Analytics: ensure job can be deleted from analytics
map","number":174212,"url":"https://github.com/elastic/kibana/pull/174212","mergeCommit":{"message":"[ML]
Data Frame Analytics: ensure job can be deleted from analytics map
(#174212)\n\n## Summary\r\n\r\nFixes
https://github.com/elastic/kibana/issues/174131\r\n\r\nThis PR removes
the failed job check - `stats` being undefined sometimes\r\nwas causing
the issue.\r\nThe need for stats is removed when we default to using the
`force=true`\r\noption in the delete endpoint.\r\nUsing that option
removes the need to first try and stop the job, as\r\nthat is handled by
the endpoint when using that option. This works\r\nregardless of the
job's
state.\r\n\r\n\r\n823580f2-3a09-4ed5-8641-9b2055a7051c\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] This
was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"96a9c8abe24bdd3258047ea0aecc2be108c37e72"}},"sourceBranch":"main","suggestedTargetBranches":["8.12"],"targetPullRequestStates":[{"branch":"8.12","label":"v8.12.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.13.0","branchLabelMappingKey":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/174212","number":174212,"mergeCommit":{"message":"[ML]
Data Frame Analytics: ensure job can be deleted from analytics map
(#174212)\n\n## Summary\r\n\r\nFixes
https://github.com/elastic/kibana/issues/174131\r\n\r\nThis PR removes
the failed job check - `stats` being undefined sometimes\r\nwas causing
the issue.\r\nThe need for stats is removed when we default to using the
`force=true`\r\noption in the delete endpoint.\r\nUsing that option
removes the need to first try and stop the job, as\r\nthat is handled by
the endpoint when using that option. This works\r\nregardless of the
job's
state.\r\n\r\n\r\n823580f2-3a09-4ed5-8641-9b2055a7051c\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] This
was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"96a9c8abe24bdd3258047ea0aecc2be108c37e72"}}]}]
BACKPORT-->

Co-authored-by: Melissa Alvarez <melissa.alvarez@elastic.co>
This commit is contained in:
Kibana Machine 2024-01-08 14:59:20 -05:00 committed by GitHub
parent 9019ff6e15
commit 72c06f5caa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 19 deletions

View file

@ -132,13 +132,12 @@ export const useDeleteAction = (canDeleteDataFrameAnalytics: boolean) => {
if ((userCanDeleteIndex && deleteTargetIndex) || (userCanDeleteIndex && deleteDataView)) {
deleteAnalyticsAndDestIndex(
item.config,
item.stats,
deleteTargetIndex,
dataViewExists && deleteDataView,
toastNotificationService
);
} else {
deleteAnalytics(item.config, item.stats, toastNotificationService);
deleteAnalytics(item.config, toastNotificationService);
}
}
};

View file

@ -11,20 +11,13 @@ import { extractErrorMessage } from '@kbn/ml-error-utils';
import { ml } from '../../../../../services/ml_api_service';
import { ToastNotificationService } from '../../../../../services/toast_notification_service';
import { refreshAnalyticsList$, REFRESH_ANALYTICS_LIST_STATE } from '../../../../common';
import {
isDataFrameAnalyticsFailed,
DataFrameAnalyticsListRow,
} from '../../components/analytics_list/common';
import { DataFrameAnalyticsListRow } from '../../components/analytics_list/common';
export const deleteAnalytics = async (
analyticsConfig: DataFrameAnalyticsListRow['config'],
analyticsStats: DataFrameAnalyticsListRow['stats'],
toastNotificationService: ToastNotificationService
) => {
try {
if (isDataFrameAnalyticsFailed(analyticsStats.state)) {
await ml.dataFrameAnalytics.stopDataFrameAnalytics(analyticsConfig.id, true);
}
await ml.dataFrameAnalytics.deleteDataFrameAnalytics(analyticsConfig.id);
toastNotificationService.displaySuccessToast(
i18n.translate('xpack.ml.dataframe.analyticsList.deleteAnalyticsSuccessMessage', {
@ -46,16 +39,12 @@ export const deleteAnalytics = async (
export const deleteAnalyticsAndDestIndex = async (
analyticsConfig: DataFrameAnalyticsListRow['config'],
analyticsStats: DataFrameAnalyticsListRow['stats'],
deleteDestIndex: boolean,
deleteDestDataView: boolean,
toastNotificationService: ToastNotificationService
) => {
const destinationIndex = analyticsConfig.dest.index;
try {
if (isDataFrameAnalyticsFailed(analyticsStats.state)) {
await ml.dataFrameAnalytics.stopDataFrameAnalytics(analyticsConfig.id, true);
}
const status = await ml.dataFrameAnalytics.deleteDataFrameAnalyticsAndDestIndex(
analyticsConfig.id,
deleteDestIndex,

View file

@ -145,9 +145,10 @@ export const dataFrameAnalyticsApiProvider = (httpService: HttpService) => ({
version: '1',
});
},
deleteDataFrameAnalytics(analyticsId: string) {
deleteDataFrameAnalytics(analyticsId: string, force: boolean = true) {
return httpService.http<any>({
path: `${ML_INTERNAL_BASE_PATH}/data_frame/analytics/${analyticsId}`,
query: { force },
method: 'DELETE',
version: '1',
});
@ -155,11 +156,12 @@ export const dataFrameAnalyticsApiProvider = (httpService: HttpService) => ({
deleteDataFrameAnalyticsAndDestIndex(
analyticsId: string,
deleteDestIndex: boolean,
deleteDestDataView: boolean
deleteDestDataView: boolean,
force: boolean = true
) {
return httpService.http<DeleteDataFrameAnalyticsWithIndexResponse>({
path: `${ML_INTERNAL_BASE_PATH}/data_frame/analytics/${analyticsId}`,
query: { deleteDestIndex, deleteDestDataView },
query: { deleteDestIndex, deleteDestDataView, force },
method: 'DELETE',
version: '1',
});

View file

@ -479,7 +479,7 @@ export function dataFrameAnalyticsRoutes(
async ({ mlClient, client, request, response, getDataViewsService }) => {
try {
const { analyticsId } = request.params;
const { deleteDestIndex, deleteDestDataView } = request.query;
const { deleteDestIndex, deleteDestDataView, force } = request.query;
let destinationIndex: string | undefined;
const analyticsJobDeleted: DeleteDataFrameAnalyticsWithIndexStatus = { success: false };
const destIndexDeleted: DeleteDataFrameAnalyticsWithIndexStatus = { success: false };
@ -499,7 +499,7 @@ export function dataFrameAnalyticsRoutes(
destinationIndex = body.data_frame_analytics[0].dest.index;
}
} catch (e) {
// exist early if the job doesn't exist
// exit early if the job doesn't exist
return response.customError(wrapError(e));
}
@ -537,6 +537,7 @@ export function dataFrameAnalyticsRoutes(
try {
await mlClient.deleteDataFrameAnalytics({
id: analyticsId,
force,
});
analyticsJobDeleted.success = true;
} catch ({ body }) {

View file

@ -86,6 +86,7 @@ export const deleteDataFrameAnalyticsJobSchema = schema.object({
*/
deleteDestIndex: schema.maybe(schema.boolean()),
deleteDestDataView: schema.maybe(schema.boolean()),
force: schema.maybe(schema.boolean()),
});
export const dataFrameAnalyticsJobUpdateSchema = schema.object({