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

[ML] Model snapshot management #68182

Merged
merged 18 commits into from
Jun 16, 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
7 changes: 7 additions & 0 deletions x-pack/plugins/ml/common/constants/time_format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './datafeed';
export * from './datafeed_stats';
export * from './combined_job';
export * from './summary_job';
export * from './model_snapshot';
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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 { JobId } from './job';
import { ModelSizeStats } from './job_stats';

export interface ModelSnapshot {
job_id: JobId;
min_version: string;
timestamp: number;
description: string;
darnautov marked this conversation as resolved.
Show resolved Hide resolved
snapshot_id: string;
snapshot_doc_count: number;
model_size_stats: ModelSizeStats;
latest_record_time_stamp: number;
latest_result_time_stamp: number;
retain: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ import {
getLatestDataOrBucketTimestamp,
isTimeSeriesViewJob,
} from '../../../../../common/util/job_utils';
import { TIME_FORMAT } from '../../../../../common/constants/time_format';

import {
annotation$,
annotationsRefresh$,
annotationsRefreshed,
} from '../../../services/annotations_service';

const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';

/**
* Table component for rendering the lists of annotations for an ML job.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export {
useColorRange,
COLOR_RANGE,
COLOR_RANGE_SCALE,
useCurrentEuiTheme,
} from './use_color_range';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import d3 from 'd3';

import { useMemo } from 'react';
import euiThemeLight from '@elastic/eui/dist/eui_theme_light.json';
import euiThemeDark from '@elastic/eui/dist/eui_theme_dark.json';

Expand Down Expand Up @@ -150,7 +150,7 @@ export const useColorRange = (
colorRangeScale = COLOR_RANGE_SCALE.LINEAR,
featureCount = 1
) => {
const euiTheme = useUiSettings().get('theme:darkMode') ? euiThemeDark : euiThemeLight;
const { euiTheme } = useCurrentEuiTheme();

const colorRanges: Record<COLOR_RANGE, string[]> = {
[COLOR_RANGE.BLUE]: [
Expand Down Expand Up @@ -186,3 +186,11 @@ export const useColorRange = (

return scaleTypes[colorRangeScale];
};

export function useCurrentEuiTheme() {
const uiSettings = useUiSettings();
return useMemo(
() => ({ euiTheme: uiSettings.get('theme:darkMode') ? euiThemeDark : euiThemeLight }),
[uiSettings]
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import { i18n } from '@kbn/i18n';
import theme from '@elastic/eui/dist/eui_theme_light.json';

import { JobMessage } from '../../../../common/types/audit_message';
import { TIME_FORMAT } from '../../../../common/constants/time_format';
import { JobIcon } from '../job_message_icon';

const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';

interface JobMessagesProps {
messages: JobMessage[];
loading: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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 React, { FC } from 'react';
import { i18n } from '@kbn/i18n';

import { FormattedMessage } from '@kbn/i18n/react';

import { EuiOverlayMask, EuiConfirmModal } from '@elastic/eui';

import { COMBINED_JOB_STATE } from '../model_snapshots_table';

interface Props {
combinedJobState: COMBINED_JOB_STATE;
hideCloseJobModalVisible(): void;
forceCloseJob(): void;
}
export const CloseJobConfirm: FC<Props> = ({
combinedJobState,
hideCloseJobModalVisible,
forceCloseJob,
}) => {
return (
<EuiOverlayMask>
<EuiConfirmModal
title={
combinedJobState === COMBINED_JOB_STATE.OPEN_AND_RUNNING
? i18n.translate('xpack.ml.modelSnapshotTable.closeJobConfirm.stopAndClose.title', {
defaultMessage: 'Stop datafeed and close job?',
})
: i18n.translate('xpack.ml.modelSnapshotTable.closeJobConfirm.close.title', {
defaultMessage: 'Close job?',
})
}
onCancel={hideCloseJobModalVisible}
onConfirm={forceCloseJob}
cancelButtonText={i18n.translate(
'xpack.ml.modelSnapshotTable.closeJobConfirm.cancelButton',
{
defaultMessage: 'Cancel',
}
)}
confirmButtonText={
combinedJobState === COMBINED_JOB_STATE.OPEN_AND_RUNNING
? i18n.translate('xpack.ml.modelSnapshotTable.closeJobConfirm.stopAndClose.button', {
defaultMessage: 'Force stop and close',
})
: i18n.translate('xpack.ml.modelSnapshotTable.closeJobConfirm.close.button', {
defaultMessage: 'Force close',
})
}
defaultFocusedButton="confirm"
>
<p>
{combinedJobState === COMBINED_JOB_STATE.OPEN_AND_RUNNING && (
<FormattedMessage
id="xpack.ml.modelSnapshotTable.closeJobConfirm.contentOpenAndRunning"
defaultMessage="Job is currently open and running."
/>
)}
{combinedJobState === COMBINED_JOB_STATE.OPEN_AND_STOPPED && (
<FormattedMessage
id="xpack.ml.modelSnapshotTable.closeJobConfirm.contentOpen"
defaultMessage="Job is currently open."
/>
)}
<br />
<FormattedMessage
id="xpack.ml.modelSnapshotTable.closeJobConfirm.content"
defaultMessage="Snapshot revert can only happen on jobs which are closed."
/>
</p>
</EuiConfirmModal>
</EuiOverlayMask>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export { CloseJobConfirm } from './close_job_confirm';
Loading