From c66896aef49b5f0b3624574a431580483b56ea63 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Thu, 27 Apr 2023 08:47:39 -0700 Subject: [PATCH] Save new prometheus metrics to OSD saved objects (#428) (#433) * 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) Co-authored-by: Joshua Li --- 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!');