From 767bb23f486b48f7b97eb20ed2040a7786021b25 Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Wed, 26 Apr 2023 16:50:08 -0700 Subject: [PATCH] Save new prometheus metrics to OSD saved objects (#428) * Save new prometheus metrics to OSD saved objects Signed-off-by: Joshua Li * Return if failed at saving metrics Signed-off-by: Joshua Li --------- Signed-off-by: Joshua Li (cherry picked from commit cde1cefe590cead25795bf4c73b606a2e0e8d252) --- public/components/metrics/top_menu/top_menu.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/public/components/metrics/top_menu/top_menu.tsx b/public/components/metrics/top_menu/top_menu.tsx index 70a10059f7..2a530926e5 100644 --- a/public/components/metrics/top_menu/top_menu.tsx +++ b/public/components/metrics/top_menu/top_menu.tsx @@ -27,6 +27,9 @@ import { resolutionOptions } from '../../../../common/constants/metrics'; import { MetricType } from '../../../../common/types/metrics'; import { uiSettingsService } from '../../../../common/utils'; import SavedObjects from '../../../services/saved_objects/event_analytics/saved_objects'; +import { getSavedObjectsClient } from '../../../services/saved_objects/saved_object_client/client_factory'; +import { OSDSavedVisualizationClient } from '../../../services/saved_objects/saved_object_client/osd_saved_objects/saved_visualization'; +import { addMultipleVizToPanels, uuidRx } from '../../custom_panels/redux/panel_slice'; import { sortMetricLayout, updateMetricsWithSelections } from '../helpers/utils'; import { allAvailableMetricsSelector, @@ -36,7 +39,6 @@ import { import { SearchBar } from '../sidebar/search_bar'; import { MetricsExportPanel } from './metrics_export_panel'; import './top_menu.scss'; -import { addMultipleVizToPanels, uuidRx } from '../../custom_panels/redux/panel_slice'; interface TopMenuProps { http: CoreStart['http']; @@ -170,9 +172,12 @@ export const TopMenu = ({ ); if (metricLayout.metricType === 'prometheusMetric') { - return await savedObjects.createSavedVisualization(updatedMetric); + return OSDSavedVisualizationClient.getInstance().create(updatedMetric); } else { - return await savedObjects.updateSavedVisualizationById({ + return getSavedObjectsClient({ + objectId: metricLayout.id, + objectType: 'savedVisualization', + }).update({ ...updatedMetric, objectId: metricLayout.id, }); @@ -182,7 +187,8 @@ export const TopMenu = ({ } catch (e) { const message = 'Issue in saving metrics'; console.error(message, e); - setToast('Issue in saving metrics', 'danger'); + setToast(message, 'danger'); + return; } setToast('Saved metrics successfully!');