From 86bd765c0da46f4f929ac68a458acbf5abcc22ca Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Mon, 31 Aug 2020 18:20:54 -0500 Subject: [PATCH 01/14] [ML] Add time range settings to ml advanced settings --- .../plugins/ml/common/constants/settings.ts | 1 + .../ml/server/lib/register_settings.ts | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/ml/common/constants/settings.ts b/x-pack/plugins/ml/common/constants/settings.ts index 2df2ecd22e078..6664653fdead5 100644 --- a/x-pack/plugins/ml/common/constants/settings.ts +++ b/x-pack/plugins/ml/common/constants/settings.ts @@ -5,3 +5,4 @@ */ export const FILE_DATA_VISUALIZER_MAX_FILE_SIZE = 'ml:fileDataVisualizerMaxFileSize'; +export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:anomalyDetectionDefaultTimeRange'; diff --git a/x-pack/plugins/ml/server/lib/register_settings.ts b/x-pack/plugins/ml/server/lib/register_settings.ts index 38b1f5e3fc083..9242c02d3bbea 100644 --- a/x-pack/plugins/ml/server/lib/register_settings.ts +++ b/x-pack/plugins/ml/server/lib/register_settings.ts @@ -7,11 +7,36 @@ import { CoreSetup } from 'kibana/server'; import { i18n } from '@kbn/i18n'; import { schema } from '@kbn/config-schema'; -import { FILE_DATA_VISUALIZER_MAX_FILE_SIZE } from '../../common/constants/settings'; +import { + FILE_DATA_VISUALIZER_MAX_FILE_SIZE, + ANOMALY_DETECTION_DEFAULT_TIME_RANGE, +} from '../../common/constants/settings'; import { MAX_FILE_SIZE } from '../../common/constants/file_datavisualizer'; export function registerKibanaSettings(coreSetup: CoreSetup) { coreSetup.uiSettings.register({ + [ANOMALY_DETECTION_DEFAULT_TIME_RANGE]: { + name: i18n.translate('xpack.ml.advancedSettings.anomalyDetectionDefaultTimeRangeName', { + defaultMessage: 'Time filter defaults', + }), + type: 'json', + value: `{ + "from": "now-15m", + "to": "now" +}`, + description: i18n.translate( + 'xpack.ml.advancedSettings.anomalyDetectionDefaultTimeRangeDesc', + { + defaultMessage: 'The default time range use view anomaly detection jobs.', + } + ), + category: ['Machine Learning'], + schema: schema.object({ + from: schema.string(), + to: schema.string(), + }), + }, + [FILE_DATA_VISUALIZER_MAX_FILE_SIZE]: { name: i18n.translate('xpack.ml.maxFileSizeSettingsName', { defaultMessage: 'File Data Visualizer maximum file upload size', From d92932d2e388d9ee60dfb83978b90c93cb2fbd55 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 1 Sep 2020 00:39:14 -0500 Subject: [PATCH 02/14] [ML] Add change so list of jobs reflect default settings --- .../plugins/ml/common/constants/settings.ts | 1 + .../components/job_actions/results.js | 14 ++++- .../application/services/job_service.d.ts | 3 +- .../application/services/job_service.js | 56 ++++++++++++++----- .../ml/public/application/util/date_utils.ts | 10 +++- .../ml/server/lib/register_settings.ts | 55 +++++++++++------- 6 files changed, 100 insertions(+), 39 deletions(-) diff --git a/x-pack/plugins/ml/common/constants/settings.ts b/x-pack/plugins/ml/common/constants/settings.ts index 6664653fdead5..9ed1915e7949a 100644 --- a/x-pack/plugins/ml/common/constants/settings.ts +++ b/x-pack/plugins/ml/common/constants/settings.ts @@ -5,4 +5,5 @@ */ export const FILE_DATA_VISUALIZER_MAX_FILE_SIZE = 'ml:fileDataVisualizerMaxFileSize'; +export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:enableAnomalyDetectionDefaultTimeRange'; export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:anomalyDetectionDefaultTimeRange'; diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_actions/results.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_actions/results.js index 74072aa7e9638..f2f2e26a8789a 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_actions/results.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_actions/results.js @@ -11,11 +11,21 @@ import { EuiButtonIcon, EuiToolTip } from '@elastic/eui'; import { mlJobService } from '../../../../services/job_service'; import { i18n } from '@kbn/i18n'; -import { getBasePath } from '../../../../util/dependency_cache'; +import { getBasePath, getUiSettings } from '../../../../util/dependency_cache'; +import { + ANOMALY_DETECTION_ENABLE_TIME_RANGE, + ANOMALY_DETECTION_DEFAULT_TIME_RANGE, +} from '../../../../../../common/constants/settings'; export function getLink(location, jobs) { const basePath = getBasePath(); - const resultsPageUrl = mlJobService.createResultsUrlForJobs(jobs, location); + const useUserTimeSettings = getUiSettings().get(ANOMALY_DETECTION_ENABLE_TIME_RANGE); + const userTimeSettings = getUiSettings().get(ANOMALY_DETECTION_DEFAULT_TIME_RANGE); + const resultsPageUrl = mlJobService.createResultsUrlForJobs( + jobs, + location, + useUserTimeSettings === true && userTimeSettings !== undefined ? userTimeSettings : undefined + ); return `${basePath.get()}/app/ml${resultsPageUrl}`; } diff --git a/x-pack/plugins/ml/public/application/services/job_service.d.ts b/x-pack/plugins/ml/public/application/services/job_service.d.ts index 2134d157e1baa..30b2ec044285a 100644 --- a/x-pack/plugins/ml/public/application/services/job_service.d.ts +++ b/x-pack/plugins/ml/public/application/services/job_service.d.ts @@ -5,6 +5,7 @@ */ import { SearchResponse } from 'elasticsearch'; +import { TimeRange } from 'src/plugins/data/common/query/timefilter/types'; import { CombinedJob } from '../../../common/types/anomaly_detection_jobs'; import { Calendar } from '../../../common/types/calendars'; @@ -15,7 +16,7 @@ export interface ExistingJobsAndGroups { declare interface JobService { jobs: CombinedJob[]; - createResultsUrlForJobs: (jobs: any[], target: string) => string; + createResultsUrlForJobs: (jobs: any[], target: string, timeRange?: TimeRange) => string; tempJobCloningObjects: { job: any; skipTimeRangeStep: boolean; diff --git a/x-pack/plugins/ml/public/application/services/job_service.js b/x-pack/plugins/ml/public/application/services/job_service.js index 704d76059f75c..4441080b9b1f0 100644 --- a/x-pack/plugins/ml/public/application/services/job_service.js +++ b/x-pack/plugins/ml/public/application/services/job_service.js @@ -21,6 +21,7 @@ import { ML_DATA_PREVIEW_COUNT } from '../../../common/util/job_utils'; import { TIME_FORMAT } from '../../../common/constants/time_format'; import { parseInterval } from '../../../common/util/parse_interval'; import { toastNotificationServiceProvider } from '../services/toast_notification_service'; +import { validateTimeRange } from '../util/date_utils'; const msgs = mlMessageBarService; let jobs = []; @@ -790,8 +791,9 @@ class JobService { return groups; } - createResultsUrlForJobs(jobsList, resultsPage) { - return createResultsUrlForJobs(jobsList, resultsPage); + createResultsUrlForJobs(jobsList, resultsPage, timeRange) { + console.log('timeRange', timeRange); + return createResultsUrlForJobs(jobsList, resultsPage, timeRange); } createResultsUrl(jobIds, from, to, resultsPage) { @@ -932,31 +934,47 @@ function createJobStats(jobsList, jobStats) { jobStats.activeNodes.value = Object.keys(mlNodes).length; } -function createResultsUrlForJobs(jobsList, resultsPage) { +function createResultsUrlForJobs(jobsList, resultsPage, userTimeRange) { let from = undefined; let to = undefined; - if (jobsList.length === 1) { - from = jobsList[0].earliestTimestampMs; - to = jobsList[0].latestResultsTimestampMs; // Will be max(latest source data, latest bucket results) + const jobIds = jobsList.map((j) => j.id); + + // if user input is a valid time range object + if (validateTimeRange(userTimeRange)) { + from = userTimeRange.from; + to = userTimeRange.to; + const fromFieldAValidDate = moment(userTimeRange.from).isValid(); + const toFieldAValidDate = moment(userTimeRange.to).isValid(); + // if both are not a valid date, use 'quick' + // e.g. "now-15m" "now+1d" + if (!fromFieldAValidDate && !toFieldAValidDate) { + return createResultsUrl(jobIds, from, to, resultsPage, 'quick'); + } + // if both fields are absolute date + // continue to createResultsUrl with from and to converted as normal } else { - const jobsWithData = jobsList.filter((j) => j.earliestTimestampMs !== undefined); - if (jobsWithData.length > 0) { - from = Math.min(...jobsWithData.map((j) => j.earliestTimestampMs)); - to = Math.max(...jobsWithData.map((j) => j.latestResultsTimestampMs)); + if (jobsList.length === 1) { + from = jobsList[0].earliestTimestampMs; + to = jobsList[0].latestResultsTimestampMs; // Will be max(latest source data, latest bucket results) + } else { + const jobsWithData = jobsList.filter((j) => j.earliestTimestampMs !== undefined); + if (jobsWithData.length > 0) { + from = Math.min(...jobsWithData.map((j) => j.earliestTimestampMs)); + to = Math.max(...jobsWithData.map((j) => j.latestResultsTimestampMs)); + } } } const fromString = moment(from).format(TIME_FORMAT); // Defaults to 'now' if 'from' is undefined const toString = moment(to).format(TIME_FORMAT); // Defaults to 'now' if 'to' is undefined - const jobIds = jobsList.map((j) => j.id); return createResultsUrl(jobIds, fromString, toString, resultsPage); } -function createResultsUrl(jobIds, start, end, resultsPage) { +function createResultsUrl(jobIds, start, end, resultsPage, mode = 'absolute') { const idString = jobIds.map((j) => `'${j}'`).join(','); - const from = moment(start).toISOString(); - const to = moment(end).toISOString(); + let from; + let to; let path = ''; if (resultsPage !== undefined) { @@ -964,9 +982,17 @@ function createResultsUrl(jobIds, start, end, resultsPage) { path += resultsPage; } + if (mode === 'quick') { + from = start; + to = end; + } else { + from = moment(start).toISOString(); + to = moment(end).toISOString(); + } + path += `?_g=(ml:(jobIds:!(${idString}))`; path += `,refreshInterval:(display:Off,pause:!f,value:0),time:(from:'${from}'`; - path += `,mode:absolute,to:'${to}'`; + path += `,to:'${to}'`; path += "))&_a=(query:(query_string:(analyze_wildcard:!t,query:'*')))"; return path; diff --git a/x-pack/plugins/ml/public/application/util/date_utils.ts b/x-pack/plugins/ml/public/application/util/date_utils.ts index 8f3215b6cd211..21adc0b4b9c66 100644 --- a/x-pack/plugins/ml/public/application/util/date_utils.ts +++ b/x-pack/plugins/ml/public/application/util/date_utils.ts @@ -8,7 +8,8 @@ // @ts-ignore import { formatDate } from '@elastic/eui/lib/services/format'; - +import dateMath from '@elastic/datemath'; +import { TimeRange } from '../../../../../../src/plugins/data/common'; export function formatHumanReadableDate(ts: number) { return formatDate(ts, 'MMMM Do YYYY'); } @@ -20,3 +21,10 @@ export function formatHumanReadableDateTime(ts: number): string { export function formatHumanReadableDateTimeSeconds(ts: number) { return formatDate(ts, 'MMMM Do YYYY, HH:mm:ss'); } + +export function validateTimeRange(time?: TimeRange): boolean { + if (!time) return false; + const momentDateFrom = dateMath.parse(time.from); + const momentDateTo = dateMath.parse(time.to); + return !!(momentDateFrom && momentDateFrom.isValid() && momentDateTo && momentDateTo.isValid()); +} diff --git a/x-pack/plugins/ml/server/lib/register_settings.ts b/x-pack/plugins/ml/server/lib/register_settings.ts index 9242c02d3bbea..2b18f17820ede 100644 --- a/x-pack/plugins/ml/server/lib/register_settings.ts +++ b/x-pack/plugins/ml/server/lib/register_settings.ts @@ -10,11 +10,44 @@ import { schema } from '@kbn/config-schema'; import { FILE_DATA_VISUALIZER_MAX_FILE_SIZE, ANOMALY_DETECTION_DEFAULT_TIME_RANGE, + ANOMALY_DETECTION_ENABLE_TIME_RANGE, } from '../../common/constants/settings'; import { MAX_FILE_SIZE } from '../../common/constants/file_datavisualizer'; export function registerKibanaSettings(coreSetup: CoreSetup) { coreSetup.uiSettings.register({ + [FILE_DATA_VISUALIZER_MAX_FILE_SIZE]: { + name: i18n.translate('xpack.ml.maxFileSizeSettingsName', { + defaultMessage: 'File Data Visualizer maximum file upload size', + }), + value: MAX_FILE_SIZE, + description: i18n.translate('xpack.ml.maxFileSizeSettingsDescription', { + defaultMessage: + 'Sets the file size limit when importing data in the File Data Visualizer. The highest supported value for this setting is 1GB.', + }), + category: ['Machine Learning'], + schema: schema.string(), + validation: { + regexString: '\\d+[mMgG][bB]', + message: i18n.translate('xpack.ml.maxFileSizeSettingsError', { + defaultMessage: 'Should be a valid data size. e.g. 200MB, 1GB', + }), + }, + }, + [ANOMALY_DETECTION_ENABLE_TIME_RANGE]: { + name: i18n.translate('xpack.ml.advancedSettings.enableAnomalyDetectionDefaultTimeRangeName', { + defaultMessage: 'Enable default time range for anomaly detection jobs.', + }), + value: false, + schema: schema.boolean(), + description: i18n.translate( + 'xpack.ml.advancedSettings.anomalyDetectionDefaultTimeRangeDesc', + { + defaultMessage: 'Use a default time range to view anomaly detection jobs.', + } + ), + category: ['Machine Learning'], + }, [ANOMALY_DETECTION_DEFAULT_TIME_RANGE]: { name: i18n.translate('xpack.ml.advancedSettings.anomalyDetectionDefaultTimeRangeName', { defaultMessage: 'Time filter defaults', @@ -27,33 +60,15 @@ export function registerKibanaSettings(coreSetup: CoreSetup) { description: i18n.translate( 'xpack.ml.advancedSettings.anomalyDetectionDefaultTimeRangeDesc', { - defaultMessage: 'The default time range use view anomaly detection jobs.', + defaultMessage: 'The default time range to view anomaly detection jobs.', } ), - category: ['Machine Learning'], schema: schema.object({ from: schema.string(), to: schema.string(), }), - }, - - [FILE_DATA_VISUALIZER_MAX_FILE_SIZE]: { - name: i18n.translate('xpack.ml.maxFileSizeSettingsName', { - defaultMessage: 'File Data Visualizer maximum file upload size', - }), - value: MAX_FILE_SIZE, - description: i18n.translate('xpack.ml.maxFileSizeSettingsDescription', { - defaultMessage: - 'Sets the file size limit when importing data in the File Data Visualizer. The highest supported value for this setting is 1GB.', - }), + requiresPageReload: true, category: ['Machine Learning'], - schema: schema.string(), - validation: { - regexString: '\\d+[mMgG][bB]', - message: i18n.translate('xpack.ml.maxFileSizeSettingsError', { - defaultMessage: 'Should be a valid data size. e.g. 200MB, 1GB', - }), - }, }, }); } From ee5e375317322d5842e9b400396b2317199f459a Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 1 Sep 2020 00:54:16 -0500 Subject: [PATCH 03/14] [ML] Reorder settings order & remove console.log --- x-pack/plugins/ml/common/constants/settings.ts | 2 +- x-pack/plugins/ml/public/application/services/job_service.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugins/ml/common/constants/settings.ts b/x-pack/plugins/ml/common/constants/settings.ts index 9ed1915e7949a..062cb01162ef8 100644 --- a/x-pack/plugins/ml/common/constants/settings.ts +++ b/x-pack/plugins/ml/common/constants/settings.ts @@ -6,4 +6,4 @@ export const FILE_DATA_VISUALIZER_MAX_FILE_SIZE = 'ml:fileDataVisualizerMaxFileSize'; export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:enableAnomalyDetectionDefaultTimeRange'; -export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:anomalyDetectionDefaultTimeRange'; +export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:setAnomalyDetectionDefaultTimeRange'; diff --git a/x-pack/plugins/ml/public/application/services/job_service.js b/x-pack/plugins/ml/public/application/services/job_service.js index 4441080b9b1f0..e82393731a95a 100644 --- a/x-pack/plugins/ml/public/application/services/job_service.js +++ b/x-pack/plugins/ml/public/application/services/job_service.js @@ -792,7 +792,6 @@ class JobService { } createResultsUrlForJobs(jobsList, resultsPage, timeRange) { - console.log('timeRange', timeRange); return createResultsUrlForJobs(jobsList, resultsPage, timeRange); } From 911ad3f65f8837104e18123d9a9e360a3896d2dd Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 1 Sep 2020 00:57:09 -0500 Subject: [PATCH 04/14] [ML] Reorder settings order to have verb after setting name --- x-pack/plugins/ml/common/constants/settings.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/ml/common/constants/settings.ts b/x-pack/plugins/ml/common/constants/settings.ts index 062cb01162ef8..55deb48652b0c 100644 --- a/x-pack/plugins/ml/common/constants/settings.ts +++ b/x-pack/plugins/ml/common/constants/settings.ts @@ -5,5 +5,5 @@ */ export const FILE_DATA_VISUALIZER_MAX_FILE_SIZE = 'ml:fileDataVisualizerMaxFileSize'; -export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:enableAnomalyDetectionDefaultTimeRange'; -export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:setAnomalyDetectionDefaultTimeRange'; +export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetectionDefaultTimeRangeEnable'; +export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:anomalyDetectionDefaultTimeRangeSet'; From 6b35e207fea8fa0ce73c5893b54c5dfa23841b5f Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 1 Sep 2020 13:41:34 -0500 Subject: [PATCH 05/14] [ML] Create new hook to create AD links --- .../custom_hooks/use_create_ad_links.ts | 37 +++++++++++++++++++ .../components/job_actions/results.js | 26 ++----------- .../anomaly_detection_panel/actions.tsx | 8 ++-- 3 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 x-pack/plugins/ml/public/application/components/custom_hooks/use_create_ad_links.ts diff --git a/x-pack/plugins/ml/public/application/components/custom_hooks/use_create_ad_links.ts b/x-pack/plugins/ml/public/application/components/custom_hooks/use_create_ad_links.ts new file mode 100644 index 0000000000000..368e758a027c4 --- /dev/null +++ b/x-pack/plugins/ml/public/application/components/custom_hooks/use_create_ad_links.ts @@ -0,0 +1,37 @@ +/* + * 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 { useCallback } from 'react'; +import { useMlKibana, useUiSettings } from '../../contexts/kibana'; +import { + ANOMALY_DETECTION_DEFAULT_TIME_RANGE, + ANOMALY_DETECTION_ENABLE_TIME_RANGE, +} from '../../../../common/constants/settings'; +import { mlJobService } from '../../services/job_service'; + +export const useCreateADLinks = () => { + const { + services: { + http: { basePath }, + }, + } = useMlKibana(); + + const useUserTimeSettings = useUiSettings().get(ANOMALY_DETECTION_ENABLE_TIME_RANGE); + const userTimeSettings = useUiSettings().get(ANOMALY_DETECTION_DEFAULT_TIME_RANGE); + const createLinkWithUserDefaults = useCallback( + (location, jobList) => { + const resultsPageUrl = mlJobService.createResultsUrlForJobs( + jobList, + location, + useUserTimeSettings === true && userTimeSettings !== undefined + ? userTimeSettings + : undefined + ); + return `${basePath.get()}/app/ml${resultsPageUrl}`; + }, + [basePath] + ); + return { createLinkWithUserDefaults }; +}; diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_actions/results.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_actions/results.js index f2f2e26a8789a..e222fbb4f262b 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_actions/results.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_actions/results.js @@ -8,26 +8,8 @@ import PropTypes from 'prop-types'; import React from 'react'; import { EuiButtonIcon, EuiToolTip } from '@elastic/eui'; - -import { mlJobService } from '../../../../services/job_service'; import { i18n } from '@kbn/i18n'; -import { getBasePath, getUiSettings } from '../../../../util/dependency_cache'; -import { - ANOMALY_DETECTION_ENABLE_TIME_RANGE, - ANOMALY_DETECTION_DEFAULT_TIME_RANGE, -} from '../../../../../../common/constants/settings'; - -export function getLink(location, jobs) { - const basePath = getBasePath(); - const useUserTimeSettings = getUiSettings().get(ANOMALY_DETECTION_ENABLE_TIME_RANGE); - const userTimeSettings = getUiSettings().get(ANOMALY_DETECTION_DEFAULT_TIME_RANGE); - const resultsPageUrl = mlJobService.createResultsUrlForJobs( - jobs, - location, - useUserTimeSettings === true && userTimeSettings !== undefined ? userTimeSettings : undefined - ); - return `${basePath.get()}/app/ml${resultsPageUrl}`; -} +import { useCreateADLinks } from '../../../../components/custom_hooks/use_create_ad_links'; export function ResultLinks({ jobs }) { const openJobsInSingleMetricViewerText = i18n.translate( @@ -54,13 +36,13 @@ export function ResultLinks({ jobs }) { const singleMetricVisible = jobs.length < 2; const singleMetricEnabled = jobs.length === 1 && jobs[0].isSingleMetricViewerJob; const jobActionsDisabled = jobs.length === 1 && jobs[0].deleting === true; - + const { createLinkWithUserDefaults } = useCreateADLinks(); return ( {singleMetricVisible && ( = ({ jobsList }) => { values: { jobsCount: jobsList.length, jobId: jobsList[0] && jobsList[0].id }, } ); + const { createLinkWithUserDefaults } = useCreateADLinks(); return ( Date: Tue, 1 Sep 2020 14:50:18 -0500 Subject: [PATCH 06/14] [ML] Add toast notification for Anomaly Explorer --- .../public/application/explorer/explorer.js | 9 ++++++- .../application/routing/routes/explorer.tsx | 26 ++++++++++++++----- .../application/services/job_service.js | 3 +-- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/ml/public/application/explorer/explorer.js b/x-pack/plugins/ml/public/application/explorer/explorer.js index d78df80fad94e..4329f898e9f1e 100644 --- a/x-pack/plugins/ml/public/application/explorer/explorer.js +++ b/x-pack/plugins/ml/public/application/explorer/explorer.js @@ -145,6 +145,14 @@ export class Explorer extends React.Component { state = { filterIconTriggeredQuery: undefined, language: DEFAULT_QUERY_LANG }; htmlIdGen = htmlIdGenerator(); + componentDidMount() { + const { invalidTimeRangeError } = this.props; + if (invalidTimeRangeError) { + const toastNotifications = getToastNotifications(); + toastNotifications.addWarning(invalidTimeRangeError); + } + } + // Escape regular parens from fieldName as that portion of the query is not wrapped in double quotes // and will cause a syntax error when called with getKqlQueryValues applyFilter = (fieldName, fieldValue, action) => { @@ -298,7 +306,6 @@ export class Explorer extends React.Component {
- {stoppedPartitions && ( ({ path: '/explorer', render: (props, deps) => , @@ -72,7 +72,7 @@ const ExplorerUrlStateManager: FC = ({ jobsWithTim const [globalState, setGlobalState] = useUrlState('_g'); const [lastRefresh, setLastRefresh] = useState(0); const [stoppedPartitions, setStoppedPartitions] = useState(); - + const [invalidTimeRangeError, setInValidTimeRangeError] = useState(); const timefilter = useTimefilter({ timeRangeSelector: true, autoRefreshSelector: true }); const { jobIds } = useJobSelection(jobsWithTimeRange); @@ -98,10 +98,23 @@ const ExplorerUrlStateManager: FC = ({ jobsWithTim // `timefilter.getBounds()` to update `bounds` in this component's state. useEffect(() => { if (globalState?.time !== undefined) { - timefilter.setTime({ - from: globalState.time.from, - to: globalState.time.to, - }); + if (!validateTimeRange(globalState.time)) { + setInValidTimeRangeError( + i18n.translate('invalidTimeRangeInUrlCallout', { + defaultMessage: + "The time filter changed to the full range for this job due to invalid default time filter '{from}' - '{to}'. Please check the advanced settings.", + values: { + from: globalState.time.from, + to: globalState.time.to, + }, + }) + ); + } else { + timefilter.setTime({ + from: globalState.time.from, + to: globalState.time.to, + }); + } const timefilterBounds = timefilter.getBounds(); // Only if both min/max bounds are valid moment times set the bounds. @@ -235,6 +248,7 @@ const ExplorerUrlStateManager: FC = ({ jobsWithTim showCharts, severity: tableSeverity.val, stoppedPartitions, + invalidTimeRangeError, }} />
diff --git a/x-pack/plugins/ml/public/application/services/job_service.js b/x-pack/plugins/ml/public/application/services/job_service.js index e82393731a95a..52b85edb06b7a 100644 --- a/x-pack/plugins/ml/public/application/services/job_service.js +++ b/x-pack/plugins/ml/public/application/services/job_service.js @@ -21,7 +21,6 @@ import { ML_DATA_PREVIEW_COUNT } from '../../../common/util/job_utils'; import { TIME_FORMAT } from '../../../common/constants/time_format'; import { parseInterval } from '../../../common/util/parse_interval'; import { toastNotificationServiceProvider } from '../services/toast_notification_service'; -import { validateTimeRange } from '../util/date_utils'; const msgs = mlMessageBarService; let jobs = []; @@ -939,7 +938,7 @@ function createResultsUrlForJobs(jobsList, resultsPage, userTimeRange) { const jobIds = jobsList.map((j) => j.id); // if user input is a valid time range object - if (validateTimeRange(userTimeRange)) { + if (userTimeRange) { from = userTimeRange.from; to = userTimeRange.to; const fromFieldAValidDate = moment(userTimeRange.from).isValid(); From 0176c5980550694e9004aa83306975cb8e3e5211 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 1 Sep 2020 15:16:36 -0500 Subject: [PATCH 07/14] [ML] Add toast notification for SMV --- .../application/routing/routes/explorer.tsx | 4 ++-- .../routing/routes/timeseriesexplorer.tsx | 24 +++++++++++++++---- .../timeseriesexplorer/timeseriesexplorer.js | 8 +++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/ml/public/application/routing/routes/explorer.tsx b/x-pack/plugins/ml/public/application/routing/routes/explorer.tsx index 2df2e41df95c8..1c281cb941384 100644 --- a/x-pack/plugins/ml/public/application/routing/routes/explorer.tsx +++ b/x-pack/plugins/ml/public/application/routing/routes/explorer.tsx @@ -100,9 +100,9 @@ const ExplorerUrlStateManager: FC = ({ jobsWithTim if (globalState?.time !== undefined) { if (!validateTimeRange(globalState.time)) { setInValidTimeRangeError( - i18n.translate('invalidTimeRangeInUrlCallout', { + i18n.translate('xpack.ml.explorer.invalidTimeRangeInUrlCallout', { defaultMessage: - "The time filter changed to the full range for this job due to invalid default time filter '{from}' - '{to}'. Please check the advanced settings.", + "The time filter changed to the full range for this job due to invalid default time filter from '{from}' to '{to}'. Please check the advanced settings.", values: { from: globalState.time.from, to: globalState.time.to, diff --git a/x-pack/plugins/ml/public/application/routing/routes/timeseriesexplorer.tsx b/x-pack/plugins/ml/public/application/routing/routes/timeseriesexplorer.tsx index 1f122ed18a851..9fd6cf2450f12 100644 --- a/x-pack/plugins/ml/public/application/routing/routes/timeseriesexplorer.tsx +++ b/x-pack/plugins/ml/public/application/routing/routes/timeseriesexplorer.tsx @@ -38,6 +38,7 @@ import { useResolver } from '../use_resolver'; import { basicResolvers } from '../resolvers'; import { getBreadcrumbWithUrlForApp } from '../breadcrumbs'; import { useTimefilter } from '../../contexts/kibana'; +import { validateTimeRange } from '../../..'; export const timeSeriesExplorerRouteFactory = (navigateToPath: NavigateToPath): MlRoute => ({ path: '/timeseriesexplorer', @@ -91,6 +92,7 @@ export const TimeSeriesExplorerUrlStateManager: FC(); const timefilter = useTimefilter({ timeRangeSelector: true, autoRefreshSelector: true }); + const [invalidTimeRangeError, setInValidTimeRangeError] = useState(); const refresh = useRefresh(); useEffect(() => { @@ -114,10 +116,23 @@ export const TimeSeriesExplorerUrlStateManager: FC(undefined); useEffect(() => { if (globalState?.time !== undefined) { - timefilter.setTime({ - from: globalState.time.from, - to: globalState.time.to, - }); + if (!validateTimeRange(globalState.time)) { + setInValidTimeRangeError( + i18n.translate('xpack.ml.timeSeriesExplorer.invalidTimeRangeInUrlCallout', { + defaultMessage: + "The time filter changed to the full range for this job due to invalid default time filter from '{from}' to '{to}'. Please check the advanced settings.", + values: { + from: globalState.time.from, + to: globalState.time.to, + }, + }) + ); + } else { + timefilter.setTime({ + from: globalState.time.from, + to: globalState.time.to, + }); + } const timefilterBounds = timefilter.getBounds(); // Only if both min/max bounds are valid moment times set the bounds. @@ -300,6 +315,7 @@ export const TimeSeriesExplorerUrlStateManager: FC ); diff --git a/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js b/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js index 83a789074d353..d290ea0f58ed7 100644 --- a/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js +++ b/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js @@ -833,6 +833,14 @@ export class TimeSeriesExplorer extends React.Component { } componentDidMount() { + // if timeRange used in the url is incorrect + // perhaps due to user's advanced setting using incorrect date-maths + const { invalidTimeRangeError } = this.props; + if (invalidTimeRangeError) { + const toastNotifications = getToastNotifications(); + toastNotifications.addWarning(invalidTimeRangeError); + } + // Required to redraw the time series chart when the container is resized. this.resizeChecker = new ResizeChecker(this.resizeRef.current); this.resizeChecker.on('resize', () => { From 41552018659642508ce52909429c1cc2e63df5c1 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 1 Sep 2020 16:10:59 -0500 Subject: [PATCH 08/14] [ML] Change to pass 'invalid' to url to retain the original full range + update field values --- .../plugins/ml/common/constants/settings.ts | 4 +-- .../public/application/explorer/explorer.js | 11 +++++++- .../application/routing/routes/explorer.tsx | 26 ++++++------------- .../routing/routes/timeseriesexplorer.tsx | 25 +++++------------- .../application/services/job_service.js | 26 +++++++++++++------ .../timeseriesexplorer/timeseriesexplorer.js | 11 +++++++- .../ml/server/lib/register_settings.ts | 8 +++--- 7 files changed, 59 insertions(+), 52 deletions(-) diff --git a/x-pack/plugins/ml/common/constants/settings.ts b/x-pack/plugins/ml/common/constants/settings.ts index 55deb48652b0c..358089a97f0f5 100644 --- a/x-pack/plugins/ml/common/constants/settings.ts +++ b/x-pack/plugins/ml/common/constants/settings.ts @@ -5,5 +5,5 @@ */ export const FILE_DATA_VISUALIZER_MAX_FILE_SIZE = 'ml:fileDataVisualizerMaxFileSize'; -export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetectionDefaultTimeRangeEnable'; -export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:anomalyDetectionDefaultTimeRangeSet'; +export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetectionTimeDefaultsEnable'; +export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:anomalyDetectionTimeDefaults'; diff --git a/x-pack/plugins/ml/public/application/explorer/explorer.js b/x-pack/plugins/ml/public/application/explorer/explorer.js index 4329f898e9f1e..0fd181342fcf6 100644 --- a/x-pack/plugins/ml/public/application/explorer/explorer.js +++ b/x-pack/plugins/ml/public/application/explorer/explorer.js @@ -68,6 +68,7 @@ import { ExplorerChartsContainer } from './explorer_charts/explorer_charts_conta import { AnomaliesTable } from '../components/anomalies_table/anomalies_table'; import { getTimefilter, getToastNotifications } from '../util/dependency_cache'; +import { ANOMALY_DETECTION_DEFAULT_TIME_RANGE } from '../../../common/constants/settings'; const ExplorerPage = ({ children, @@ -149,7 +150,15 @@ export class Explorer extends React.Component { const { invalidTimeRangeError } = this.props; if (invalidTimeRangeError) { const toastNotifications = getToastNotifications(); - toastNotifications.addWarning(invalidTimeRangeError); + toastNotifications.addWarning( + i18n.translate('xpack.ml.explorer.invalidTimeRangeInUrlCallout', { + defaultMessage: + 'The time filter changed to the full range for this job due to invalid default time filter. Please check the advanced settings for {field}.', + values: { + field: ANOMALY_DETECTION_DEFAULT_TIME_RANGE, + }, + }) + ); } } diff --git a/x-pack/plugins/ml/public/application/routing/routes/explorer.tsx b/x-pack/plugins/ml/public/application/routing/routes/explorer.tsx index 1c281cb941384..191933812ffe3 100644 --- a/x-pack/plugins/ml/public/application/routing/routes/explorer.tsx +++ b/x-pack/plugins/ml/public/application/routing/routes/explorer.tsx @@ -33,7 +33,7 @@ import { getBreadcrumbWithUrlForApp } from '../breadcrumbs'; import { useTimefilter } from '../../contexts/kibana'; import { isViewBySwimLaneData } from '../../explorer/swimlane_container'; import { JOB_ID } from '../../../../common/constants/anomalies'; -import { validateTimeRange } from '../../util/date_utils'; + export const explorerRouteFactory = (navigateToPath: NavigateToPath): MlRoute => ({ path: '/explorer', render: (props, deps) => , @@ -72,7 +72,7 @@ const ExplorerUrlStateManager: FC = ({ jobsWithTim const [globalState, setGlobalState] = useUrlState('_g'); const [lastRefresh, setLastRefresh] = useState(0); const [stoppedPartitions, setStoppedPartitions] = useState(); - const [invalidTimeRangeError, setInValidTimeRangeError] = useState(); + const [invalidTimeRangeError, setInValidTimeRangeError] = useState(false); const timefilter = useTimefilter({ timeRangeSelector: true, autoRefreshSelector: true }); const { jobIds } = useJobSelection(jobsWithTimeRange); @@ -98,23 +98,13 @@ const ExplorerUrlStateManager: FC = ({ jobsWithTim // `timefilter.getBounds()` to update `bounds` in this component's state. useEffect(() => { if (globalState?.time !== undefined) { - if (!validateTimeRange(globalState.time)) { - setInValidTimeRangeError( - i18n.translate('xpack.ml.explorer.invalidTimeRangeInUrlCallout', { - defaultMessage: - "The time filter changed to the full range for this job due to invalid default time filter from '{from}' to '{to}'. Please check the advanced settings.", - values: { - from: globalState.time.from, - to: globalState.time.to, - }, - }) - ); - } else { - timefilter.setTime({ - from: globalState.time.from, - to: globalState.time.to, - }); + if (globalState.time.mode === 'invalid') { + setInValidTimeRangeError(true); } + timefilter.setTime({ + from: globalState.time.from, + to: globalState.time.to, + }); const timefilterBounds = timefilter.getBounds(); // Only if both min/max bounds are valid moment times set the bounds. diff --git a/x-pack/plugins/ml/public/application/routing/routes/timeseriesexplorer.tsx b/x-pack/plugins/ml/public/application/routing/routes/timeseriesexplorer.tsx index 9fd6cf2450f12..817c975415997 100644 --- a/x-pack/plugins/ml/public/application/routing/routes/timeseriesexplorer.tsx +++ b/x-pack/plugins/ml/public/application/routing/routes/timeseriesexplorer.tsx @@ -38,7 +38,6 @@ import { useResolver } from '../use_resolver'; import { basicResolvers } from '../resolvers'; import { getBreadcrumbWithUrlForApp } from '../breadcrumbs'; import { useTimefilter } from '../../contexts/kibana'; -import { validateTimeRange } from '../../..'; export const timeSeriesExplorerRouteFactory = (navigateToPath: NavigateToPath): MlRoute => ({ path: '/timeseriesexplorer', @@ -92,7 +91,7 @@ export const TimeSeriesExplorerUrlStateManager: FC(); const timefilter = useTimefilter({ timeRangeSelector: true, autoRefreshSelector: true }); - const [invalidTimeRangeError, setInValidTimeRangeError] = useState(); + const [invalidTimeRangeError, setInValidTimeRangeError] = useState(false); const refresh = useRefresh(); useEffect(() => { @@ -116,23 +115,13 @@ export const TimeSeriesExplorerUrlStateManager: FC(undefined); useEffect(() => { if (globalState?.time !== undefined) { - if (!validateTimeRange(globalState.time)) { - setInValidTimeRangeError( - i18n.translate('xpack.ml.timeSeriesExplorer.invalidTimeRangeInUrlCallout', { - defaultMessage: - "The time filter changed to the full range for this job due to invalid default time filter from '{from}' to '{to}'. Please check the advanced settings.", - values: { - from: globalState.time.from, - to: globalState.time.to, - }, - }) - ); - } else { - timefilter.setTime({ - from: globalState.time.from, - to: globalState.time.to, - }); + if (globalState.time.mode === 'invalid') { + setInValidTimeRangeError(true); } + timefilter.setTime({ + from: globalState.time.from, + to: globalState.time.to, + }); const timefilterBounds = timefilter.getBounds(); // Only if both min/max bounds are valid moment times set the bounds. diff --git a/x-pack/plugins/ml/public/application/services/job_service.js b/x-pack/plugins/ml/public/application/services/job_service.js index 52b85edb06b7a..640f63617b7d4 100644 --- a/x-pack/plugins/ml/public/application/services/job_service.js +++ b/x-pack/plugins/ml/public/application/services/job_service.js @@ -21,7 +21,7 @@ import { ML_DATA_PREVIEW_COUNT } from '../../../common/util/job_utils'; import { TIME_FORMAT } from '../../../common/constants/time_format'; import { parseInterval } from '../../../common/util/parse_interval'; import { toastNotificationServiceProvider } from '../services/toast_notification_service'; - +import { validateTimeRange } from '../util/date_utils'; const msgs = mlMessageBarService; let jobs = []; let datafeedIds = {}; @@ -935,22 +935,29 @@ function createJobStats(jobsList, jobStats) { function createResultsUrlForJobs(jobsList, resultsPage, userTimeRange) { let from = undefined; let to = undefined; + let mode = 'absolute'; const jobIds = jobsList.map((j) => j.id); - // if user input is a valid time range object - if (userTimeRange) { + // if the custom default time filter is set and enabled in advanced settings + // if time is either absolute date or proper datemath format + if (validateTimeRange(userTimeRange)) { from = userTimeRange.from; to = userTimeRange.to; + // if both pass datemath's checks but are not technically absolute dates, use 'quick' + // e.g. "now-15m" "now+1d" const fromFieldAValidDate = moment(userTimeRange.from).isValid(); const toFieldAValidDate = moment(userTimeRange.to).isValid(); - // if both are not a valid date, use 'quick' - // e.g. "now-15m" "now+1d" if (!fromFieldAValidDate && !toFieldAValidDate) { return createResultsUrl(jobIds, from, to, resultsPage, 'quick'); } - // if both fields are absolute date - // continue to createResultsUrl with from and to converted as normal } else { + // if time range is specified but with incorrect format + // change back to the default time range but alert the user + // that the advanced setting config is invalid + if (userTimeRange) { + mode = 'invalid'; + } + if (jobsList.length === 1) { from = jobsList[0].earliestTimestampMs; to = jobsList[0].latestResultsTimestampMs; // Will be max(latest source data, latest bucket results) @@ -966,7 +973,7 @@ function createResultsUrlForJobs(jobsList, resultsPage, userTimeRange) { const fromString = moment(from).format(TIME_FORMAT); // Defaults to 'now' if 'from' is undefined const toString = moment(to).format(TIME_FORMAT); // Defaults to 'now' if 'to' is undefined - return createResultsUrl(jobIds, fromString, toString, resultsPage); + return createResultsUrl(jobIds, fromString, toString, resultsPage, mode); } function createResultsUrl(jobIds, start, end, resultsPage, mode = 'absolute') { @@ -991,6 +998,9 @@ function createResultsUrl(jobIds, start, end, resultsPage, mode = 'absolute') { path += `?_g=(ml:(jobIds:!(${idString}))`; path += `,refreshInterval:(display:Off,pause:!f,value:0),time:(from:'${from}'`; path += `,to:'${to}'`; + if (mode === 'invalid') { + path += `,mode:invalid`; + } path += "))&_a=(query:(query_string:(analyze_wildcard:!t,query:'*')))"; return path; diff --git a/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js b/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js index d290ea0f58ed7..228af93a2c17f 100644 --- a/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js +++ b/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js @@ -83,6 +83,7 @@ import { getFocusData, } from './timeseriesexplorer_utils'; import { EMPTY_FIELD_VALUE_LABEL } from './components/entity_control/entity_control'; +import { ANOMALY_DETECTION_DEFAULT_TIME_RANGE } from '../../../common/constants/settings'; // Used to indicate the chart is being plotted across // all partition field values, where the cardinality of the field cannot be @@ -838,7 +839,15 @@ export class TimeSeriesExplorer extends React.Component { const { invalidTimeRangeError } = this.props; if (invalidTimeRangeError) { const toastNotifications = getToastNotifications(); - toastNotifications.addWarning(invalidTimeRangeError); + toastNotifications.addWarning( + i18n.translate('xpack.ml.timeSeriesExplorer.invalidTimeRangeInUrlCallout', { + defaultMessage: + 'The time filter changed to the full range for this job due to invalid default time filter. Please check the advanced settings for {field}.', + values: { + field: ANOMALY_DETECTION_DEFAULT_TIME_RANGE, + }, + }) + ); } // Required to redraw the time series chart when the container is resized. diff --git a/x-pack/plugins/ml/server/lib/register_settings.ts b/x-pack/plugins/ml/server/lib/register_settings.ts index 2b18f17820ede..4843e55533a5a 100644 --- a/x-pack/plugins/ml/server/lib/register_settings.ts +++ b/x-pack/plugins/ml/server/lib/register_settings.ts @@ -36,14 +36,14 @@ export function registerKibanaSettings(coreSetup: CoreSetup) { }, [ANOMALY_DETECTION_ENABLE_TIME_RANGE]: { name: i18n.translate('xpack.ml.advancedSettings.enableAnomalyDetectionDefaultTimeRangeName', { - defaultMessage: 'Enable default time range for anomaly detection jobs.', + defaultMessage: 'Enable default time range for anomaly detection jobs', }), value: false, schema: schema.boolean(), description: i18n.translate( - 'xpack.ml.advancedSettings.anomalyDetectionDefaultTimeRangeDesc', + 'xpack.ml.advancedSettings.enableAnomalyDetectionDefaultTimeRangeDesc', { - defaultMessage: 'Use a default time range to view anomaly detection jobs.', + defaultMessage: 'Use a default time filter to view anomaly detection jobs.', } ), category: ['Machine Learning'], @@ -60,7 +60,7 @@ export function registerKibanaSettings(coreSetup: CoreSetup) { description: i18n.translate( 'xpack.ml.advancedSettings.anomalyDetectionDefaultTimeRangeDesc', { - defaultMessage: 'The default time range to view anomaly detection jobs.', + defaultMessage: 'The default time filter to view anomaly detection jobs.', } ), schema: schema.object({ From 41af491d1fa355395c34966f6c17b1275917b153 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 1 Sep 2020 16:14:40 -0500 Subject: [PATCH 09/14] [ML] Update texts --- x-pack/plugins/ml/server/lib/register_settings.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/ml/server/lib/register_settings.ts b/x-pack/plugins/ml/server/lib/register_settings.ts index 4843e55533a5a..68c880288a95d 100644 --- a/x-pack/plugins/ml/server/lib/register_settings.ts +++ b/x-pack/plugins/ml/server/lib/register_settings.ts @@ -36,14 +36,15 @@ export function registerKibanaSettings(coreSetup: CoreSetup) { }, [ANOMALY_DETECTION_ENABLE_TIME_RANGE]: { name: i18n.translate('xpack.ml.advancedSettings.enableAnomalyDetectionDefaultTimeRangeName', { - defaultMessage: 'Enable default time range for anomaly detection jobs', + defaultMessage: 'Enable time filter defaults for anomaly detection jobs', }), value: false, schema: schema.boolean(), description: i18n.translate( 'xpack.ml.advancedSettings.enableAnomalyDetectionDefaultTimeRangeDesc', { - defaultMessage: 'Use a default time filter to view anomaly detection jobs.', + defaultMessage: + 'Use the default time filter in the Single Metric Viewer and Anomaly Explorer.', } ), category: ['Machine Learning'], @@ -60,7 +61,8 @@ export function registerKibanaSettings(coreSetup: CoreSetup) { description: i18n.translate( 'xpack.ml.advancedSettings.anomalyDetectionDefaultTimeRangeDesc', { - defaultMessage: 'The default time filter to view anomaly detection jobs.', + defaultMessage: + 'The time filter selection to use when viewing anomaly detection job results.', } ), schema: schema.object({ From 56bef023446bac00d8cc45d4310425e36cee860f Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Wed, 2 Sep 2020 09:50:55 -0500 Subject: [PATCH 10/14] [ML] Change namings --- x-pack/plugins/ml/common/constants/settings.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/ml/common/constants/settings.ts b/x-pack/plugins/ml/common/constants/settings.ts index 358089a97f0f5..bb0e042102615 100644 --- a/x-pack/plugins/ml/common/constants/settings.ts +++ b/x-pack/plugins/ml/common/constants/settings.ts @@ -5,5 +5,5 @@ */ export const FILE_DATA_VISUALIZER_MAX_FILE_SIZE = 'ml:fileDataVisualizerMaxFileSize'; -export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetectionTimeDefaultsEnable'; -export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:anomalyDetectionTimeDefaults'; +export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetection:results:enableTmeDefaults'; +export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:anomalyDetection:results:timeDefaults'; From 1118b3e08345110bec102f86bfbd3bf46cce969c Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Wed, 2 Sep 2020 11:18:58 -0500 Subject: [PATCH 11/14] [ML] Add constants, update descriptions --- x-pack/plugins/ml/common/constants/settings.ts | 6 ++++++ .../ml/public/application/explorer/explorer.js | 2 +- .../anomaly_detection_panel/actions.tsx | 2 -- .../timeseriesexplorer/timeseriesexplorer.js | 2 +- x-pack/plugins/ml/server/lib/register_settings.ts | 15 +++++++-------- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/ml/common/constants/settings.ts b/x-pack/plugins/ml/common/constants/settings.ts index bb0e042102615..f024f07c2fbc6 100644 --- a/x-pack/plugins/ml/common/constants/settings.ts +++ b/x-pack/plugins/ml/common/constants/settings.ts @@ -7,3 +7,9 @@ export const FILE_DATA_VISUALIZER_MAX_FILE_SIZE = 'ml:fileDataVisualizerMaxFileSize'; export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetection:results:enableTmeDefaults'; export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:anomalyDetection:results:timeDefaults'; + +export const DEFAULT_AD_RESULTS_TIME_FILTER = { + from: 'now-15m', + to: 'now', +}; +export const DEFAULT_ENABLE_AD_RESULTS_TIME_FILTER = false; diff --git a/x-pack/plugins/ml/public/application/explorer/explorer.js b/x-pack/plugins/ml/public/application/explorer/explorer.js index 0fd181342fcf6..cea1159ebc14a 100644 --- a/x-pack/plugins/ml/public/application/explorer/explorer.js +++ b/x-pack/plugins/ml/public/application/explorer/explorer.js @@ -153,7 +153,7 @@ export class Explorer extends React.Component { toastNotifications.addWarning( i18n.translate('xpack.ml.explorer.invalidTimeRangeInUrlCallout', { defaultMessage: - 'The time filter changed to the full range for this job due to invalid default time filter. Please check the advanced settings for {field}.', + 'The time filter was changed to the full range due to an invalid default time filter. Check the advanced settings for {field}.', values: { field: ANOMALY_DETECTION_DEFAULT_TIME_RANGE, }, diff --git a/x-pack/plugins/ml/public/application/overview/components/anomaly_detection_panel/actions.tsx b/x-pack/plugins/ml/public/application/overview/components/anomaly_detection_panel/actions.tsx index 365536f24e99b..a71141d0356d0 100644 --- a/x-pack/plugins/ml/public/application/overview/components/anomaly_detection_panel/actions.tsx +++ b/x-pack/plugins/ml/public/application/overview/components/anomaly_detection_panel/actions.tsx @@ -10,8 +10,6 @@ import { i18n } from '@kbn/i18n'; import { MlSummaryJobs } from '../../../../../common/types/anomaly_detection_jobs'; import { useCreateADLinks } from '../../../components/custom_hooks/use_create_ad_links'; -// @ts-ignore no module file - interface Props { jobsList: MlSummaryJobs; } diff --git a/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js b/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js index 228af93a2c17f..0e99d64cf202f 100644 --- a/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js +++ b/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js @@ -842,7 +842,7 @@ export class TimeSeriesExplorer extends React.Component { toastNotifications.addWarning( i18n.translate('xpack.ml.timeSeriesExplorer.invalidTimeRangeInUrlCallout', { defaultMessage: - 'The time filter changed to the full range for this job due to invalid default time filter. Please check the advanced settings for {field}.', + 'The time filter was changed to the full range for this job due to an invalid default time filter. Check the advanced settings for {field}.', values: { field: ANOMALY_DETECTION_DEFAULT_TIME_RANGE, }, diff --git a/x-pack/plugins/ml/server/lib/register_settings.ts b/x-pack/plugins/ml/server/lib/register_settings.ts index 68c880288a95d..a9ee24fbb5cea 100644 --- a/x-pack/plugins/ml/server/lib/register_settings.ts +++ b/x-pack/plugins/ml/server/lib/register_settings.ts @@ -11,6 +11,8 @@ import { FILE_DATA_VISUALIZER_MAX_FILE_SIZE, ANOMALY_DETECTION_DEFAULT_TIME_RANGE, ANOMALY_DETECTION_ENABLE_TIME_RANGE, + DEFAULT_AD_RESULTS_TIME_FILTER, + DEFAULT_ENABLE_AD_RESULTS_TIME_FILTER, } from '../../common/constants/settings'; import { MAX_FILE_SIZE } from '../../common/constants/file_datavisualizer'; @@ -36,28 +38,25 @@ export function registerKibanaSettings(coreSetup: CoreSetup) { }, [ANOMALY_DETECTION_ENABLE_TIME_RANGE]: { name: i18n.translate('xpack.ml.advancedSettings.enableAnomalyDetectionDefaultTimeRangeName', { - defaultMessage: 'Enable time filter defaults for anomaly detection jobs', + defaultMessage: 'Enable time filter defaults for anomaly detection results', }), - value: false, + value: DEFAULT_ENABLE_AD_RESULTS_TIME_FILTER, schema: schema.boolean(), description: i18n.translate( 'xpack.ml.advancedSettings.enableAnomalyDetectionDefaultTimeRangeDesc', { defaultMessage: - 'Use the default time filter in the Single Metric Viewer and Anomaly Explorer.', + 'Use the default time filter in the Single Metric Viewer and Anomaly Explorer. If not enabled, the results for the full time range of the job are displayed.', } ), category: ['Machine Learning'], }, [ANOMALY_DETECTION_DEFAULT_TIME_RANGE]: { name: i18n.translate('xpack.ml.advancedSettings.anomalyDetectionDefaultTimeRangeName', { - defaultMessage: 'Time filter defaults', + defaultMessage: 'Time filter defaults for anomaly detection results', }), type: 'json', - value: `{ - "from": "now-15m", - "to": "now" -}`, + value: JSON.stringify(DEFAULT_AD_RESULTS_TIME_FILTER, null, 2), description: i18n.translate( 'xpack.ml.advancedSettings.anomalyDetectionDefaultTimeRangeDesc', { From 4272114ecbab6eb9c481fa55e409eef6c857ba02 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Wed, 2 Sep 2020 12:03:30 -0500 Subject: [PATCH 12/14] [ML] Rename timerange to time range --- .../application/components/job_selector/job_selector_flyout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/ml/public/application/components/job_selector/job_selector_flyout.tsx b/x-pack/plugins/ml/public/application/components/job_selector/job_selector_flyout.tsx index 62a74ed142ccf..6c57b3d08180d 100644 --- a/x-pack/plugins/ml/public/application/components/job_selector/job_selector_flyout.tsx +++ b/x-pack/plugins/ml/public/application/components/job_selector/job_selector_flyout.tsx @@ -237,7 +237,7 @@ export const JobSelectorFlyout: FC = ({ Date: Thu, 3 Sep 2020 09:36:31 -0500 Subject: [PATCH 13/14] [ML] Update typo ml:anomalyDetection:results:enableTimeDefaults --- x-pack/plugins/ml/common/constants/settings.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/ml/common/constants/settings.ts b/x-pack/plugins/ml/common/constants/settings.ts index f024f07c2fbc6..bab2aa2f2a0ae 100644 --- a/x-pack/plugins/ml/common/constants/settings.ts +++ b/x-pack/plugins/ml/common/constants/settings.ts @@ -5,7 +5,7 @@ */ export const FILE_DATA_VISUALIZER_MAX_FILE_SIZE = 'ml:fileDataVisualizerMaxFileSize'; -export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetection:results:enableTmeDefaults'; +export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetection:results:enableTimeDefaults'; export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:anomalyDetection:results:timeDefaults'; export const DEFAULT_AD_RESULTS_TIME_FILTER = { From 903f660b794d66602517a87507c66b9498683b07 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Fri, 4 Sep 2020 09:32:04 -0500 Subject: [PATCH 14/14] [ML] Update width for group control checkbox column --- .../job_selector/job_selector_table/job_selector_table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/ml/public/application/components/job_selector/job_selector_table/job_selector_table.js b/x-pack/plugins/ml/public/application/components/job_selector/job_selector_table/job_selector_table.js index 7b104ea372ae5..1136487485f17 100644 --- a/x-pack/plugins/ml/public/application/components/job_selector/job_selector_table/job_selector_table.js +++ b/x-pack/plugins/ml/public/application/components/job_selector/job_selector_table/job_selector_table.js @@ -174,7 +174,7 @@ export function JobSelectorTable({ id: 'checkbox', isCheckbox: true, textOnly: false, - width: '24px', + width: '32px', }, { label: 'group ID',