Skip to content

Commit

Permalink
Save new prometheus metrics to OSD saved objects (opensearch-project#428
Browse files Browse the repository at this point in the history
)

* Save new prometheus metrics to OSD saved objects

Signed-off-by: Joshua Li <[email protected]>

* Return if failed at saving metrics

Signed-off-by: Joshua Li <[email protected]>

---------

Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 authored Apr 26, 2023
1 parent edf1663 commit cde1cef
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions public/components/metrics/top_menu/top_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'];
Expand Down Expand Up @@ -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,
});
Expand All @@ -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!');
Expand Down

0 comments on commit cde1cef

Please sign in to comment.