From a81c28fc1e1b8b5e93afadb05d7272ae9ac5f5df Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Fri, 23 Aug 2019 14:02:58 +0100 Subject: [PATCH] [ML] Adding error reporting to new job wizard charts --- .../messagebar/messagebar_service.d.ts | 20 +++++++++++++ .../transform_service/delete_transform.ts | 2 +- .../transform_service/start_transform.ts | 2 +- .../transform_service/stop_transform.ts | 2 +- .../estimate_bucket_span.ts | 18 ++---------- .../multi_metric_view/metric_selection.tsx | 29 ++++++++++++------- .../bucket_span_estimator.js | 6 ++-- .../single_series_checker.js | 6 ++-- 8 files changed, 51 insertions(+), 34 deletions(-) create mode 100644 x-pack/legacy/plugins/ml/public/components/messagebar/messagebar_service.d.ts diff --git a/x-pack/legacy/plugins/ml/public/components/messagebar/messagebar_service.d.ts b/x-pack/legacy/plugins/ml/public/components/messagebar/messagebar_service.d.ts new file mode 100644 index 0000000000000..747ee928ac0c1 --- /dev/null +++ b/x-pack/legacy/plugins/ml/public/components/messagebar/messagebar_service.d.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ + +declare interface MlMessageBarService { + getMessages(): any[]; + addMessage(msg: any): void; + removeMessage(index: number): void; + clear(): void; + info(text: any): void; + warning(text: any): void; + error(text: any, resp?: any): void; + notify: { + error(text: any, resp?: any): void; + }; +} + +export const mlMessageBarService: MlMessageBarService; diff --git a/x-pack/legacy/plugins/ml/public/data_frame/pages/transform_management/services/transform_service/delete_transform.ts b/x-pack/legacy/plugins/ml/public/data_frame/pages/transform_management/services/transform_service/delete_transform.ts index 824bff8e5cb39..796af91d04d40 100644 --- a/x-pack/legacy/plugins/ml/public/data_frame/pages/transform_management/services/transform_service/delete_transform.ts +++ b/x-pack/legacy/plugins/ml/public/data_frame/pages/transform_management/services/transform_service/delete_transform.ts @@ -13,7 +13,7 @@ import { DataFrameTransformEndpointRequest, DataFrameTransformEndpointResult, } from '../../components/transform_list/common'; -// @ts-ignore no declaration file + import { mlMessageBarService } from '../../../../../../public/components/messagebar/messagebar_service'; export const deleteTransforms = async (dataFrames: DataFrameTransformListRow[]) => { diff --git a/x-pack/legacy/plugins/ml/public/data_frame/pages/transform_management/services/transform_service/start_transform.ts b/x-pack/legacy/plugins/ml/public/data_frame/pages/transform_management/services/transform_service/start_transform.ts index 27e558000c000..7887607ee573e 100644 --- a/x-pack/legacy/plugins/ml/public/data_frame/pages/transform_management/services/transform_service/start_transform.ts +++ b/x-pack/legacy/plugins/ml/public/data_frame/pages/transform_management/services/transform_service/start_transform.ts @@ -15,7 +15,7 @@ import { DataFrameTransformEndpointRequest, DataFrameTransformEndpointResult, } from '../../components/transform_list/common'; -// @ts-ignore no declaration file + import { mlMessageBarService } from '../../../../../../public/components/messagebar/messagebar_service'; export const startTransforms = async (dataFrames: DataFrameTransformListRow[]) => { diff --git a/x-pack/legacy/plugins/ml/public/data_frame/pages/transform_management/services/transform_service/stop_transform.ts b/x-pack/legacy/plugins/ml/public/data_frame/pages/transform_management/services/transform_service/stop_transform.ts index 3fa6e9c7aea39..d7e5485d22656 100644 --- a/x-pack/legacy/plugins/ml/public/data_frame/pages/transform_management/services/transform_service/stop_transform.ts +++ b/x-pack/legacy/plugins/ml/public/data_frame/pages/transform_management/services/transform_service/stop_transform.ts @@ -15,7 +15,7 @@ import { DataFrameTransformEndpointRequest, DataFrameTransformEndpointResult, } from '../../components/transform_list/common'; -// @ts-ignore no declaration file + import { mlMessageBarService } from '../../../../../../public/components/messagebar/messagebar_service'; export const stopTransforms = async (dataFrames: DataFrameTransformListRow[]) => { diff --git a/x-pack/legacy/plugins/ml/public/jobs/new_job_new/pages/components/pick_fields_step/components/bucket_span_estimator/estimate_bucket_span.ts b/x-pack/legacy/plugins/ml/public/jobs/new_job_new/pages/components/pick_fields_step/components/bucket_span_estimator/estimate_bucket_span.ts index bfe559e5edd21..f480e199e752a 100644 --- a/x-pack/legacy/plugins/ml/public/jobs/new_job_new/pages/components/pick_fields_step/components/bucket_span_estimator/estimate_bucket_span.ts +++ b/x-pack/legacy/plugins/ml/public/jobs/new_job_new/pages/components/pick_fields_step/components/bucket_span_estimator/estimate_bucket_span.ts @@ -6,13 +6,12 @@ import { useContext, useState } from 'react'; -import { i18n } from '@kbn/i18n'; -import { toastNotifications } from 'ui/notify'; import { JobCreatorContext } from '../../../job_creator_context'; import { EVENT_RATE_FIELD_ID } from '../../../../../../../../common/types/fields'; import { isMultiMetricJobCreator, isPopulationJobCreator } from '../../../../../common/job_creator'; import { ml } from '../../../../../../../services/ml_api_service'; import { useKibanaContext } from '../../../../../../../contexts/kibana'; +import { mlMessageBarService } from '../../../../../../../components/messagebar/messagebar_service'; export enum ESTIMATE_STATUS { NOT_RUNNING, @@ -47,20 +46,7 @@ export function useEstimateBucketSpan() { const { name, error, message } = await ml.estimateBucketSpan(data); setStatus(ESTIMATE_STATUS.NOT_RUNNING); if (error === true) { - let text = ''; - if (message !== undefined) { - if (typeof message === 'object') { - text = message.msg || JSON.stringify(message); - } else { - text = message; - } - } - toastNotifications.addDanger({ - title: i18n.translate('xpack.ml.newJob.wizard.pickFieldsStep.bucketSpanEstimatorError', { - defaultMessage: `Bucket span estimation error`, - }), - text, - }); + mlMessageBarService.notify.error(message); } else { jobCreator.bucketSpan = name; jobCreatorUpdate(); diff --git a/x-pack/legacy/plugins/ml/public/jobs/new_job_new/pages/components/pick_fields_step/components/multi_metric_view/metric_selection.tsx b/x-pack/legacy/plugins/ml/public/jobs/new_job_new/pages/components/pick_fields_step/components/multi_metric_view/metric_selection.tsx index c14e2e59a3387..d0c673f9c952d 100644 --- a/x-pack/legacy/plugins/ml/public/jobs/new_job_new/pages/components/pick_fields_step/components/multi_metric_view/metric_selection.tsx +++ b/x-pack/legacy/plugins/ml/public/jobs/new_job_new/pages/components/pick_fields_step/components/multi_metric_view/metric_selection.tsx @@ -16,6 +16,7 @@ import { AggFieldPair } from '../../../../../../../../common/types/fields'; import { defaultChartSettings, ChartSettings } from '../../../charts/common/settings'; import { MetricSelector } from './metric_selector'; import { ChartGrid } from './chart_grid'; +import { mlMessageBarService } from '../../../../../../../components/messagebar/messagebar_service'; interface Props { isActive: boolean; @@ -118,7 +119,9 @@ export const MultiMetricDetectors: FC = ({ isActive, setIsValid }) => { chartLoader .loadFieldExampleValues(splitField) .then(setFieldValues) - .catch(() => {}); + .catch(error => { + mlMessageBarService.notify.error(error); + }); } else { setFieldValues([]); } @@ -154,16 +157,20 @@ export const MultiMetricDetectors: FC = ({ isActive, setIsValid }) => { if (aggFieldPairList.length > 0) { setLoadingData(true); - const resp: LineChartData = await chartLoader.loadLineCharts( - jobCreator.start, - jobCreator.end, - aggFieldPairList, - jobCreator.splitField, - fieldValues.length > 0 ? fieldValues[0] : null, - cs.intervalMs - ); - - setLineChartsData(resp); + try { + const resp: LineChartData = await chartLoader.loadLineCharts( + jobCreator.start, + jobCreator.end, + aggFieldPairList, + jobCreator.splitField, + fieldValues.length > 0 ? fieldValues[0] : null, + cs.intervalMs + ); + setLineChartsData(resp); + } catch (error) { + mlMessageBarService.notify.error(error); + setLineChartsData([]); + } setLoadingData(false); } } diff --git a/x-pack/legacy/plugins/ml/server/models/bucket_span_estimator/bucket_span_estimator.js b/x-pack/legacy/plugins/ml/server/models/bucket_span_estimator/bucket_span_estimator.js index 6f4d5abddad62..0d67ad6b8a5a0 100644 --- a/x-pack/legacy/plugins/ml/server/models/bucket_span_estimator/bucket_span_estimator.js +++ b/x-pack/legacy/plugins/ml/server/models/bucket_span_estimator/bucket_span_estimator.js @@ -8,6 +8,8 @@ import _ from 'lodash'; +import { mlLog } from '../../client/log'; + import { INTERVALS } from './intervals'; import { singleSeriesCheckerFactory } from './single_series_checker'; import { polledDataCheckerFactory } from './polled_data_checker'; @@ -115,7 +117,7 @@ export function estimateBucketSpanFactory(callWithRequest, elasticsearchPlugin, run() { return new Promise((resolve, reject) => { if (this.checkers.length === 0) { - console.log('BucketSpanEstimator: run has stopped because no checks were created'); + mlLog.warn('BucketSpanEstimator: run has stopped because no checks were created'); reject('BucketSpanEstimator: run has stopped because no checks were created'); } @@ -136,7 +138,7 @@ export function estimateBucketSpanFactory(callWithRequest, elasticsearchPlugin, resolve(median); } else { // no results found - console.log('BucketSpanEstimator: run has stopped because no checks returned a valid interval'); + mlLog.warn('BucketSpanEstimator: run has stopped because no checks returned a valid interval'); reject('BucketSpanEstimator: run has stopped because no checks returned a valid interval'); } } diff --git a/x-pack/legacy/plugins/ml/server/models/bucket_span_estimator/single_series_checker.js b/x-pack/legacy/plugins/ml/server/models/bucket_span_estimator/single_series_checker.js index b3fa7bdb1496f..a0286b8e34b8c 100644 --- a/x-pack/legacy/plugins/ml/server/models/bucket_span_estimator/single_series_checker.js +++ b/x-pack/legacy/plugins/ml/server/models/bucket_span_estimator/single_series_checker.js @@ -13,6 +13,8 @@ * Bucket spans: 5m, 10m, 30m, 1h, 3h */ + +import { mlLog } from '../../client/log'; import { INTERVALS, LONG_INTERVALS } from './intervals'; export function singleSeriesCheckerFactory(callWithRequest) { @@ -59,7 +61,7 @@ export function singleSeriesCheckerFactory(callWithRequest) { start(); }) .catch((resp) => { - console.log('SingleSeriesChecker: Could not load metric reference data', this); + mlLog.warn('SingleSeriesChecker: Could not load metric reference data'); reject(resp); }); } @@ -145,7 +147,7 @@ export function singleSeriesCheckerFactory(callWithRequest) { } } } else { - console.log('SingleSeriesChecker: runTest stopped because fullBuckets is empty', this); + mlLog.warn('SingleSeriesChecker: runTest stopped because fullBuckets is empty'); reject('runTest stopped because fullBuckets is empty'); } })