Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Uptime] Set ML anomaly look-back to 2w (from 24h) / Add spinner #65055

Merged
merged 3 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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