mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
[Security Solution] Failed getFieldsForIndexPattern calls can result in Exception Flyout getting stuck in loading state (#158371)
## Summary Original ticket https://github.com/elastic/kibana/issues/158110 These changes fixes the issue with the exception flyout which can be stuck in loading state in case `getFieldsForIndexPattern` throws an exception. Fixed by putting the `getFieldsForIndexPattern` call in try/catch. We use this call to fetch extended information about the fields [to show warning to the user in case there are some index issues](https://github.com/elastic/kibana/pull/149149). If `getFieldsForIndexPattern` fails and throws an exception we will continue using fields without conflicts/unmapped information. I also, noticed that we do not fetch extended information for the case where user uses index patterns instead of data views. Fixed this issue in `useFetchIndex`. cc @dhurley14 We will need to adjust either of our PRs depending whose changes will go in first :-) --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
03d4fe7515
commit
1a3cad1b27
2 changed files with 22 additions and 6 deletions
|
@ -13,3 +13,10 @@ export const ERROR_INDEX_FIELDS_SEARCH = i18n.translate(
|
||||||
defaultMessage: `An error has occurred creating the ad-hoc data view`,
|
defaultMessage: `An error has occurred creating the ad-hoc data view`,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const FETCH_FIELDS_WITH_UNMAPPED_DATA_ERROR = i18n.translate(
|
||||||
|
'xpack.securitySolution.dataView.fetchFields.warning',
|
||||||
|
{
|
||||||
|
defaultMessage: 'Failed to fetch detailed fields information',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
|
@ -8,11 +8,14 @@
|
||||||
import { useEffect, useState, useMemo } from 'react';
|
import { useEffect, useState, useMemo } from 'react';
|
||||||
import type { DataViewBase } from '@kbn/es-query';
|
import type { DataViewBase } from '@kbn/es-query';
|
||||||
|
|
||||||
|
import { useAppToasts } from '../../../common/hooks/use_app_toasts';
|
||||||
import type { Rule } from '../../rule_management/logic/types';
|
import type { Rule } from '../../rule_management/logic/types';
|
||||||
import { useGetInstalledJob } from '../../../common/components/ml/hooks/use_get_jobs';
|
import { useGetInstalledJob } from '../../../common/components/ml/hooks/use_get_jobs';
|
||||||
import { useKibana } from '../../../common/lib/kibana';
|
import { useKibana } from '../../../common/lib/kibana';
|
||||||
import { useFetchIndex } from '../../../common/containers/source';
|
import { useFetchIndex } from '../../../common/containers/source';
|
||||||
|
|
||||||
|
import * as i18n from '../../../common/containers/source/translations';
|
||||||
|
|
||||||
export interface ReturnUseFetchExceptionFlyoutData {
|
export interface ReturnUseFetchExceptionFlyoutData {
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
indexPatterns: DataViewBase;
|
indexPatterns: DataViewBase;
|
||||||
|
@ -25,6 +28,7 @@ export interface ReturnUseFetchExceptionFlyoutData {
|
||||||
*/
|
*/
|
||||||
export const useFetchIndexPatterns = (rules: Rule[] | null): ReturnUseFetchExceptionFlyoutData => {
|
export const useFetchIndexPatterns = (rules: Rule[] | null): ReturnUseFetchExceptionFlyoutData => {
|
||||||
const { data, spaces } = useKibana().services;
|
const { data, spaces } = useKibana().services;
|
||||||
|
const { addWarning } = useAppToasts();
|
||||||
const [dataViewLoading, setDataViewLoading] = useState(false);
|
const [dataViewLoading, setDataViewLoading] = useState(false);
|
||||||
const [activeSpaceId, setActiveSpaceId] = useState('');
|
const [activeSpaceId, setActiveSpaceId] = useState('');
|
||||||
const isSingleRule = useMemo(() => rules != null && rules.length === 1, [rules]);
|
const isSingleRule = useMemo(() => rules != null && rules.length === 1, [rules]);
|
||||||
|
@ -97,20 +101,25 @@ export const useFetchIndexPatterns = (rules: Rule[] | null): ReturnUseFetchExcep
|
||||||
if (activeSpaceId !== '' && memoDataViewId) {
|
if (activeSpaceId !== '' && memoDataViewId) {
|
||||||
setDataViewLoading(true);
|
setDataViewLoading(true);
|
||||||
const dv = await data.dataViews.get(memoDataViewId);
|
const dv = await data.dataViews.get(memoDataViewId);
|
||||||
const fieldsWithUnmappedInfo = await data.dataViews.getFieldsForIndexPattern(dv, {
|
let fieldsWithUnmappedInfo = null;
|
||||||
pattern: '',
|
try {
|
||||||
includeUnmapped: true,
|
fieldsWithUnmappedInfo = await data.dataViews.getFieldsForIndexPattern(dv, {
|
||||||
});
|
pattern: '',
|
||||||
|
includeUnmapped: true,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
addWarning(error, { title: i18n.FETCH_FIELDS_WITH_UNMAPPED_DATA_ERROR });
|
||||||
|
}
|
||||||
setDataViewLoading(false);
|
setDataViewLoading(false);
|
||||||
setDataViewIndexPatterns({
|
setDataViewIndexPatterns({
|
||||||
...dv,
|
...dv,
|
||||||
fields: fieldsWithUnmappedInfo,
|
...(fieldsWithUnmappedInfo ? { fields: fieldsWithUnmappedInfo } : {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchSingleDataView();
|
fetchSingleDataView();
|
||||||
}, [memoDataViewId, data.dataViews, setDataViewIndexPatterns, activeSpaceId]);
|
}, [memoDataViewId, data.dataViews, setDataViewIndexPatterns, activeSpaceId, addWarning]);
|
||||||
|
|
||||||
// Determine whether to use index patterns or data views
|
// Determine whether to use index patterns or data views
|
||||||
const indexPatternsToUse = useMemo(
|
const indexPatternsToUse = useMemo(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue