Skip to content

Commit

Permalink
[ML] Adding error reporting to new job wizard charts
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Aug 27, 2019
1 parent b7bba21 commit a81c28f
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,7 +119,9 @@ export const MultiMetricDetectors: FC<Props> = ({ isActive, setIsValid }) => {
chartLoader
.loadFieldExampleValues(splitField)
.then(setFieldValues)
.catch(() => {});
.catch(error => {
mlMessageBarService.notify.error(error);
});
} else {
setFieldValues([]);
}
Expand Down Expand Up @@ -154,16 +157,20 @@ export const MultiMetricDetectors: FC<Props> = ({ 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');
}

Expand All @@ -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');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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');
}
})
Expand Down

0 comments on commit a81c28f

Please sign in to comment.