Skip to content

Commit b68e736

Browse files
committed
[ML] Add better error handling/transparency
1 parent 97c5890 commit b68e736

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

x-pack/plugins/ml/common/util/runtime_field_utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
*/
77

88
import { isPopulatedObject } from './object_utils';
9-
import { RUNTIME_FIELD_TYPES } from '../../../../../src/plugins/data/common/index_patterns';
9+
import {
10+
RUNTIME_FIELD_TYPES,
11+
RuntimeType,
12+
} from '../../../../../src/plugins/data/common/index_patterns';
1013
import type { RuntimeField, RuntimeMappings } from '../types/fields';
11-
import type { RuntimeType } from '../../../runtime_fields/target/types/public';
1214

1315
export function isRuntimeField(arg: unknown): arg is RuntimeField {
1416
return (

x-pack/plugins/ml/public/application/datavisualizer/index_based/data_loader/data_loader.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import { DEFAULT_SAMPLER_SHARD_SIZE } from '../../../../../common/constants/fiel
1919
import { ml } from '../../../services/ml_api_service';
2020
import { FieldHistogramRequestConfig, FieldRequestConfig } from '../common';
2121
import { RuntimeMappings } from '../../../../../common/types/fields';
22+
import {
23+
ToastNotificationService,
24+
toastNotificationServiceProvider,
25+
} from '../../../services/toast_notification_service';
2226

2327
// Maximum number of examples to obtain for text type fields.
2428
const MAX_EXAMPLES_DEFAULT: number = 10;
@@ -28,16 +32,16 @@ export class DataLoader {
2832
private _runtimeMappings: RuntimeMappings;
2933
private _indexPatternTitle: IndexPatternTitle = '';
3034
private _maxExamples: number = MAX_EXAMPLES_DEFAULT;
31-
private _toastNotifications: CoreSetup['notifications']['toasts'];
35+
private _toastNotificationsService: ToastNotificationService;
3236

3337
constructor(
3438
indexPattern: IndexPattern,
3539
toastNotifications: CoreSetup['notifications']['toasts']
3640
) {
3741
this._indexPattern = indexPattern;
38-
this._runtimeMappings = this._indexPattern.getComputedFields().runtimeFields;
42+
this._runtimeMappings = this._indexPattern.getComputedFields().runtimeFields as RuntimeMappings;
3943
this._indexPatternTitle = indexPattern.title;
40-
this._toastNotifications = toastNotifications;
44+
this._toastNotificationsService = toastNotificationServiceProvider(toastNotifications);
4145
}
4246

4347
async loadOverallData(
@@ -121,7 +125,8 @@ export class DataLoader {
121125

122126
displayError(err: any) {
123127
if (err.statusCode === 500) {
124-
this._toastNotifications.addDanger(
128+
this._toastNotificationsService.displayErrorToast(
129+
err,
125130
i18n.translate('xpack.ml.datavisualizer.dataLoader.internalServerErrorMessage', {
126131
defaultMessage:
127132
'Error loading data in index {index}. {message}. ' +
@@ -133,7 +138,8 @@ export class DataLoader {
133138
})
134139
);
135140
} else {
136-
this._toastNotifications.addDanger(
141+
this._toastNotificationsService.displayErrorToast(
142+
err,
137143
i18n.translate('xpack.ml.datavisualizer.page.errorLoadingDataMessage', {
138144
defaultMessage: 'Error loading data in index {index}. {message}',
139145
values: {

x-pack/plugins/ml/public/application/datavisualizer/index_based/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ import { FullTimeRangeSelector } from '../../components/full_time_range_selector
3838
import { mlTimefilterRefresh$ } from '../../services/timefilter_refresh_service';
3939
import { useMlContext } from '../../contexts/ml';
4040
import { kbnTypeToMLJobType } from '../../util/field_types_utils';
41-
import { useTimefilter } from '../../contexts/kibana';
41+
import { useNotifications, useTimefilter } from '../../contexts/kibana';
4242
import { timeBasedIndexCheck, getQueryFromSavedSearch } from '../../util/index_utils';
4343
import { getTimeBucketsFromCache } from '../../util/time_buckets';
44-
import { getToastNotifications } from '../../util/dependency_cache';
4544
import { usePageUrlState, useUrlState } from '../../util/url_state';
4645
import { ActionsPanel } from './components/actions_panel';
4746
import { SearchPanel } from './components/search_panel';
@@ -132,7 +131,8 @@ export const Page: FC = () => {
132131
autoRefreshSelector: true,
133132
});
134133

135-
const dataLoader = useMemo(() => new DataLoader(currentIndexPattern, getToastNotifications()), [
134+
const { toasts } = useNotifications();
135+
const dataLoader = useMemo(() => new DataLoader(currentIndexPattern, toasts), [
136136
currentIndexPattern,
137137
]);
138138

x-pack/plugins/ml/server/models/data_visualizer/data_visualizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ export class DataVisualizer {
630630
// Combine runtime mappings from the index pattern as well as the datafeed
631631
const combinedRuntimeMappings: RuntimeMappings = {
632632
...(isPopulatedObject(runtimeMappings) ? runtimeMappings : {}),
633-
...(datafeedConfig !== undefined && isPopulatedObject(datafeedConfig.runtime_mappings)
633+
...(isPopulatedObject(datafeedConfig) && isPopulatedObject(datafeedConfig.runtime_mappings)
634634
? datafeedConfig.runtime_mappings
635635
: {}),
636636
};

x-pack/plugins/ml/server/routes/schemas/data_visualizer_schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const runtimeMappingsSchema = schema.maybe(
2020
unknowns: 'allow',
2121
validate: (v: object) => {
2222
if (Object.values(v).some((o) => !isRuntimeField(o))) {
23-
return 'Your error message about invalid runtime definition';
23+
return 'Invalid runtime field';
2424
}
2525
},
2626
}

0 commit comments

Comments
 (0)