Skip to content

Commit c7abd93

Browse files
authored
[ML] Fix analytics starting state. (#48373)
- Fixes the missing starting state for analytics jobs. - Fixes checks if a analytics job is running, for example fixes an issue where the Delete-button was available for a running job in the analytics job list.
1 parent 3162194 commit c7abd93

File tree

9 files changed

+50
-42
lines changed

9 files changed

+50
-42
lines changed

x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/components/analytics_list/action_delete.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@ import {
2121
createPermissionFailureMessage,
2222
} from '../../../../../privilege/check_privilege';
2323

24-
import { DataFrameAnalyticsListRow, DATA_FRAME_TASK_STATE } from './common';
24+
import { isDataFrameAnalyticsRunning, DataFrameAnalyticsListRow } from './common';
2525

2626
interface DeleteActionProps {
2727
item: DataFrameAnalyticsListRow;
2828
}
2929

3030
export const DeleteAction: FC<DeleteActionProps> = ({ item }) => {
31-
const disabled =
32-
item.stats.state === DATA_FRAME_TASK_STATE.STARTED ||
33-
item.stats.state === DATA_FRAME_TASK_STATE.ANALYZING ||
34-
item.stats.state === DATA_FRAME_TASK_STATE.REINDEXING;
31+
const disabled = isDataFrameAnalyticsRunning(item.stats.state);
3532

3633
const canDeleteDataFrameAnalytics: boolean = checkPermission('canDeleteDataFrameAnalytics');
3734

x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/components/analytics_list/actions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const getActions = () => {
5656
AnalyticsViewAction,
5757
{
5858
render: (item: DataFrameAnalyticsListRow) => {
59-
if (!isDataFrameAnalyticsRunning(item.stats)) {
59+
if (!isDataFrameAnalyticsRunning(item.stats.state)) {
6060
return <StartAction item={item} />;
6161
}
6262

x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/components/analytics_list/analytics_list.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ import React, { Fragment, FC, useState } from 'react';
88

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

11-
import {
12-
// EuiBadge,
13-
EuiButtonEmpty,
14-
EuiCallOut,
15-
EuiEmptyPrompt,
16-
} from '@elastic/eui';
11+
import { EuiButtonEmpty, EuiCallOut, EuiEmptyPrompt } from '@elastic/eui';
1712

1813
import { DataFrameAnalyticsId, useRefreshAnalyticsList } from '../../../../common';
1914
import { checkPermission } from '../../../../../privilege/check_privilege';
@@ -24,7 +19,6 @@ import {
2419
DataFrameAnalyticsListRow,
2520
ItemIdToExpandedRowMap,
2621
DATA_FRAME_TASK_STATE,
27-
// DATA_FRAME_MODE,
2822
Query,
2923
Clause,
3024
} from './common';

x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/components/analytics_list/columns.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ import {
2020
import { getAnalysisType, DataFrameAnalyticsId } from '../../../../common';
2121
import {
2222
getDataFrameAnalyticsProgress,
23+
isDataFrameAnalyticsFailed,
24+
isDataFrameAnalyticsRunning,
25+
isDataFrameAnalyticsStopped,
2326
DataFrameAnalyticsListColumn,
2427
DataFrameAnalyticsListRow,
2528
DataFrameAnalyticsStats,
26-
DATA_FRAME_TASK_STATE,
2729
} from './common';
2830
import { getActions } from './actions';
2931

@@ -32,6 +34,7 @@ enum TASK_STATE_COLOR {
3234
failed = 'danger',
3335
reindexing = 'primary',
3436
started = 'primary',
37+
starting = 'primary',
3538
stopped = 'hollow',
3639
}
3740

@@ -41,7 +44,7 @@ export const getTaskStateBadge = (
4144
) => {
4245
const color = TASK_STATE_COLOR[state];
4346

44-
if (state === DATA_FRAME_TASK_STATE.FAILED && reason !== undefined) {
47+
if (isDataFrameAnalyticsFailed(state) && reason !== undefined) {
4548
return (
4649
<EuiToolTip content={reason}>
4750
<EuiBadge className="mlTaskStateBadge" color={color}>
@@ -91,10 +94,10 @@ export const progressColumn = {
9194
{!isBatchTransform && (
9295
<Fragment>
9396
<EuiFlexItem style={{ width: '40px' }} grow={false}>
94-
{item.stats.state === DATA_FRAME_TASK_STATE.STARTED && (
97+
{isDataFrameAnalyticsRunning(item.stats.state) && (
9598
<EuiProgress color="primary" size="m" />
9699
)}
97-
{item.stats.state === DATA_FRAME_TASK_STATE.STOPPED && (
100+
{isDataFrameAnalyticsStopped(item.stats.state) && (
98101
<EuiProgress value={0} max={100} color="primary" size="m" />
99102
)}
100103
</EuiFlexItem>

x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/components/analytics_list/common.test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import {
1111
isCompletedAnalyticsJob,
1212
isDataFrameAnalyticsRunning,
1313
isDataFrameAnalyticsStats,
14+
DataFrameAnalyticsStats,
15+
DATA_FRAME_TASK_STATE,
1416
} from './common';
1517

16-
const completedJob = StatsMock.data_frame_analytics[0];
17-
const runningJob = StatsMock.data_frame_analytics[1];
18+
const completedJob = StatsMock.data_frame_analytics[0] as DataFrameAnalyticsStats;
19+
const runningJob = StatsMock.data_frame_analytics[1] as DataFrameAnalyticsStats;
1820

1921
describe('Data Frame Analytics: common utils', () => {
2022
test('isCompletedAnalyticsJob()', () => {
@@ -23,8 +25,16 @@ describe('Data Frame Analytics: common utils', () => {
2325
});
2426

2527
test('isDataFrameAnalyticsRunning()', () => {
26-
expect(isDataFrameAnalyticsRunning(completedJob)).toBe(false);
27-
expect(isDataFrameAnalyticsRunning(runningJob)).toBe(true);
28+
expect(isDataFrameAnalyticsRunning(completedJob.state)).toBe(false);
29+
expect(isDataFrameAnalyticsRunning(runningJob.state)).toBe(true);
30+
runningJob.state = DATA_FRAME_TASK_STATE.STARTED;
31+
expect(isDataFrameAnalyticsRunning(runningJob.state)).toBe(true);
32+
runningJob.state = DATA_FRAME_TASK_STATE.STARTING;
33+
expect(isDataFrameAnalyticsRunning(runningJob.state)).toBe(true);
34+
runningJob.state = DATA_FRAME_TASK_STATE.REINDEXING;
35+
expect(isDataFrameAnalyticsRunning(runningJob.state)).toBe(true);
36+
runningJob.state = DATA_FRAME_TASK_STATE.FAILED;
37+
expect(isDataFrameAnalyticsRunning(runningJob.state)).toBe(false);
2838
});
2939

3040
test('isDataFrameAnalyticsStats()', () => {

x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/components/analytics_list/common.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export enum DATA_FRAME_TASK_STATE {
1212
FAILED = 'failed',
1313
REINDEXING = 'reindexing',
1414
STARTED = 'started',
15+
STARTING = 'starting',
1516
STOPPED = 'stopped',
1617
}
1718

@@ -54,14 +55,23 @@ export interface DataFrameAnalyticsStats {
5455
state: DATA_FRAME_TASK_STATE;
5556
}
5657

57-
export function isDataFrameAnalyticsRunning(stats: DataFrameAnalyticsStats) {
58+
export function isDataFrameAnalyticsFailed(state: DATA_FRAME_TASK_STATE) {
59+
return state === DATA_FRAME_TASK_STATE.FAILED;
60+
}
61+
62+
export function isDataFrameAnalyticsRunning(state: DATA_FRAME_TASK_STATE) {
5863
return (
59-
stats.state === DATA_FRAME_TASK_STATE.ANALYZING ||
60-
stats.state === DATA_FRAME_TASK_STATE.STARTED ||
61-
stats.state === DATA_FRAME_TASK_STATE.REINDEXING
64+
state === DATA_FRAME_TASK_STATE.ANALYZING ||
65+
state === DATA_FRAME_TASK_STATE.REINDEXING ||
66+
state === DATA_FRAME_TASK_STATE.STARTED ||
67+
state === DATA_FRAME_TASK_STATE.STARTING
6268
);
6369
}
6470

71+
export function isDataFrameAnalyticsStopped(state: DATA_FRAME_TASK_STATE) {
72+
return state === DATA_FRAME_TASK_STATE.STOPPED;
73+
}
74+
6575
export function isDataFrameAnalyticsStats(arg: any): arg is DataFrameAnalyticsStats {
6676
return (
6777
typeof arg === 'object' &&

x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/services/analytics_service/delete_analytics.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@ import { ml } from '../../../../../services/ml_api_service';
1111
import { refreshAnalyticsList$, REFRESH_ANALYTICS_LIST_STATE } from '../../../../common';
1212

1313
import {
14-
DATA_FRAME_TASK_STATE,
14+
isDataFrameAnalyticsFailed,
1515
DataFrameAnalyticsListRow,
1616
} from '../../components/analytics_list/common';
1717

1818
export const deleteAnalytics = async (d: DataFrameAnalyticsListRow) => {
1919
try {
20-
if (d.stats.state === DATA_FRAME_TASK_STATE.FAILED) {
21-
await ml.dataFrameAnalytics.stopDataFrameAnalytics(
22-
d.config.id,
23-
d.stats.state === DATA_FRAME_TASK_STATE.FAILED,
24-
true
25-
);
20+
if (isDataFrameAnalyticsFailed(d.stats.state)) {
21+
await ml.dataFrameAnalytics.stopDataFrameAnalytics(d.config.id, true, true);
2622
}
2723
await ml.dataFrameAnalytics.deleteDataFrameAnalytics(d.config.id);
2824
toastNotifications.addSuccess(

x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/services/analytics_service/stop_analytics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import { ml } from '../../../../../services/ml_api_service';
1111
import { refreshAnalyticsList$, REFRESH_ANALYTICS_LIST_STATE } from '../../../../common';
1212

1313
import {
14-
DATA_FRAME_TASK_STATE,
14+
isDataFrameAnalyticsFailed,
1515
DataFrameAnalyticsListRow,
1616
} from '../../components/analytics_list/common';
1717

1818
export const stopAnalytics = async (d: DataFrameAnalyticsListRow) => {
1919
try {
2020
await ml.dataFrameAnalytics.stopDataFrameAnalytics(
2121
d.config.id,
22-
d.stats.state === DATA_FRAME_TASK_STATE.FAILED,
22+
isDataFrameAnalyticsFailed(d.stats.state),
2323
true
2424
);
2525
toastNotifications.addSuccess(

x-pack/legacy/plugins/ml/public/overview/components/analytics_panel/analytics_stats_bar.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import React, { FC } from 'react';
88
import { i18n } from '@kbn/i18n';
99
import { StatsBar, AnalyticStatsBarStats } from '../../../components/stats_bar';
1010
import {
11+
isDataFrameAnalyticsFailed,
12+
isDataFrameAnalyticsRunning,
13+
isDataFrameAnalyticsStopped,
1114
DataFrameAnalyticsListRow,
12-
DATA_FRAME_TASK_STATE,
1315
} from '../../../data_frame_analytics/pages/analytics_management/components/analytics_list/common';
1416

1517
function getAnalyticsStats(analyticsList: any[]) {
@@ -53,15 +55,11 @@ function getAnalyticsStats(analyticsList: any[]) {
5355
let stoppedJobs = 0;
5456

5557
analyticsList.forEach(job => {
56-
if (job.stats.state === DATA_FRAME_TASK_STATE.FAILED) {
58+
if (isDataFrameAnalyticsFailed(job.stats.state)) {
5759
failedJobs++;
58-
} else if (
59-
job.stats.state === DATA_FRAME_TASK_STATE.STARTED ||
60-
job.stats.state === DATA_FRAME_TASK_STATE.ANALYZING ||
61-
job.stats.state === DATA_FRAME_TASK_STATE.REINDEXING
62-
) {
60+
} else if (isDataFrameAnalyticsRunning(job.stats.state)) {
6361
startedJobs++;
64-
} else if (job.stats.state === DATA_FRAME_TASK_STATE.STOPPED) {
62+
} else if (isDataFrameAnalyticsStopped(job.stats.state)) {
6563
stoppedJobs++;
6664
}
6765
});

0 commit comments

Comments
 (0)