Skip to content

Commit

Permalink
[7.x] [Uptime] Set ML anomaly look-back to 2w (from 24h) / Add spinner (
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed May 5, 2020
1 parent c44a93b commit aeb2a06
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import React, { useContext, useState } from 'react';

import { EuiButtonEmpty, EuiContextMenu, EuiIcon, EuiPopover } from '@elastic/eui';
import { useSelector } from 'react-redux';
import { canDeleteMLJobSelector } from '../../../state/selectors';
import {
canDeleteMLJobSelector,
hasMLJobSelector,
isMLJobCreatingSelector,
} from '../../../state/selectors';
import { UptimeSettingsContext } from '../../../contexts';
import * as labels from './translations';
import { getMLJobLinkHref } from './ml_job_link';
Expand All @@ -28,6 +32,10 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro

const canDeleteMLJob = useSelector(canDeleteMLJobSelector);

const isMLJobCreating = useSelector(isMLJobCreatingSelector);

const { loading: isMLJobLoading } = useSelector(hasMLJobSelector);

const { dateRangeStart, dateRangeEnd } = useGetUrlParams();

const monitorId = useMonitorId();
Expand All @@ -39,6 +47,7 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro
iconSide={hasMLJob ? 'right' : 'left'}
onClick={hasMLJob ? () => setIsPopOverOpen(true) : onEnableJob}
disabled={hasMLJob && !canDeleteMLJob}
isLoading={isMLJobCreating || isMLJobLoading}
>
{hasMLJob ? labels.ANOMALY_DETECTION : labels.ENABLE_ANOMALY_DETECTION}
</EuiButtonEmpty>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,14 @@ export const MachineLearningFlyout: React.FC<Props> = ({ onClose }) => {
]);

useEffect(() => {
if (hasExistingMLJob) {
if (hasExistingMLJob && !isMLJobCreating && !hasMLJob && heartbeatIndices) {
setIsCreatingJob(true);
dispatch(createMLJobAction.get({ monitorId: monitorId as string, heartbeatIndices }));
}
}, [dispatch, hasExistingMLJob, heartbeatIndices, monitorId]);

// Don't add isMLJobCreating, because it will result int end less loop
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dispatch, hasExistingMLJob, heartbeatIndices, monitorId, hasMLJob]);

if (hasExistingMLJob) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export const MLIntegrationComponent = () => {

refreshApp();
}
return () => {
dispatch(resetMLState());
};
}, [
isMLJobDeleting,
isConfirmDeleteJobOpen,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/uptime/public/state/api/ml_anomaly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const createMLJob = async ({
useDedicatedIndex: false,
startDatafeed: true,
start: moment()
.subtract(24, 'h')
.subtract(2, 'w')
.valueOf(),
indexPatternName: heartbeatIndices,
query: {
Expand Down

0 comments on commit aeb2a06

Please sign in to comment.