Skip to content

Commit

Permalink
improving mml warning
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Sep 10, 2020
1 parent e9848af commit 8875cfa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/ml/common/util/errors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface EsErrorRootCause {
export interface EsErrorBody {
error: {
root_cause?: EsErrorRootCause[];
caused_by?: EsErrorRootCause;
type: string;
reason: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useEffect, useMemo } from 'react';
import { DEFAULT_MODEL_MEMORY_LIMIT } from '../../../../../../../common/constants/new_job';
import { ml } from '../../../../../services/ml_api_service';
import { JobValidator, VALIDATION_DELAY_MS } from '../../job_validator/job_validator';
import { ErrorResponse } from '../../../../../../../common/types/errors';
import { MLHttpFetchError, MLResponseError } from '../../../../../../../common/util/errors';
import { useMlKibana } from '../../../../../contexts/kibana';
import { JobCreator } from '../job_creator';

Expand All @@ -36,10 +36,10 @@ export const modelMemoryEstimatorProvider = (
jobValidator: JobValidator
) => {
const modelMemoryCheck$ = new Subject<CalculatePayload>();
const error$ = new Subject<ErrorResponse['body']>();
const error$ = new Subject<MLHttpFetchError<MLResponseError>>();

return {
get error$(): Observable<ErrorResponse['body']> {
get error$(): Observable<MLHttpFetchError<MLResponseError>> {
return error$.asObservable();
},
get updates$(): Observable<string> {
Expand All @@ -64,7 +64,7 @@ export const modelMemoryEstimatorProvider = (
catchError((error) => {
// eslint-disable-next-line no-console
console.error('Model memory limit could not be calculated', error.body);
error$.next(error.body);
error$.next(error);
// fallback to the default in case estimation failed
return of(DEFAULT_MODEL_MEMORY_LIMIT);
})
Expand Down Expand Up @@ -120,7 +120,8 @@ export const useModelMemoryEstimator = (
title: i18n.translate('xpack.ml.newJob.wizard.estimateModelMemoryError', {
defaultMessage: 'Model memory limit could not be calculated',
}),
text: error.message,
text:
error.body.attributes?.body.error.caused_by?.reason || error.body.message || undefined,
});
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export function toastNotificationServiceProvider(toastNotifications: ToastsStart
toastNotifications.addDanger(toastOrTitle, options);
}

function displayWarningToast(toastOrTitle: ToastInput, options?: ToastOptions) {
toastNotifications.addWarning(toastOrTitle, options);
}

function displaySuccessToast(toastOrTitle: ToastInput, options?: ToastOptions) {
toastNotifications.addSuccess(toastOrTitle, options);
}
Expand All @@ -37,7 +41,7 @@ export function toastNotificationServiceProvider(toastNotifications: ToastsStart
});
}

return { displayDangerToast, displaySuccessToast, displayErrorToast };
return { displayDangerToast, displayWarningToast, displaySuccessToast, displayErrorToast };
}

export function getToastNotificationService() {
Expand Down

0 comments on commit 8875cfa

Please sign in to comment.