From 413a8120d0b065205028ff71cabacfea38ba668a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Wed, 19 Oct 2022 13:38:52 +0200 Subject: [PATCH 1/2] [APM] Suppress error toast when data view cannot be created --- .../apm/public/hooks/use_apm_data_view.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/apm/public/hooks/use_apm_data_view.ts b/x-pack/plugins/apm/public/hooks/use_apm_data_view.ts index 63d7232128d868..269f4ada4e14cd 100644 --- a/x-pack/plugins/apm/public/hooks/use_apm_data_view.ts +++ b/x-pack/plugins/apm/public/hooks/use_apm_data_view.ts @@ -25,7 +25,21 @@ export function useApmDataView() { useEffect(() => { async function fetchDataView() { const title = await getApmDataViewTitle(); - return services.dataViews.create({ title }); + try { + const displayError = false; + return await services.dataViews.create( + { title }, + undefined, + displayError + ); + } catch (e) { + const noDataScreen = e.message.includes('No matching indices found'); + if (noDataScreen) { + return; + } + + throw e; + } } fetchDataView().then(setDataView); From c8fe44f820e86df538e152e1a08284dd98c6c850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Wed, 19 Oct 2022 13:46:36 +0200 Subject: [PATCH 2/2] Display error as toast --- x-pack/plugins/apm/public/hooks/use_apm_data_view.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/apm/public/hooks/use_apm_data_view.ts b/x-pack/plugins/apm/public/hooks/use_apm_data_view.ts index 269f4ada4e14cd..2f2d14714e513e 100644 --- a/x-pack/plugins/apm/public/hooks/use_apm_data_view.ts +++ b/x-pack/plugins/apm/public/hooks/use_apm_data_view.ts @@ -6,6 +6,7 @@ */ import { DataView } from '@kbn/data-views-plugin/common'; +import { i18n } from '@kbn/i18n'; import { useKibana } from '@kbn/kibana-react-plugin/public'; import { useEffect, useState } from 'react'; import { ApmPluginStartDeps } from '../plugin'; @@ -19,7 +20,7 @@ async function getApmDataViewTitle() { } export function useApmDataView() { - const { services } = useKibana(); + const { services, notifications } = useKibana(); const [dataView, setDataView] = useState(); useEffect(() => { @@ -38,12 +39,19 @@ export function useApmDataView() { return; } + notifications.toasts.danger({ + title: i18n.translate('xpack.apm.data_view.creation_failed', { + defaultMessage: 'An error occurred while creating the data view', + }), + body: e.message, + }); + throw e; } } fetchDataView().then(setDataView); - }, [services.dataViews]); + }, [notifications.toasts, services.dataViews]); return { dataView }; }