From b748fb8d146a7d849725e1ac053509ebcde5eb88 Mon Sep 17 00:00:00 2001 From: Eugene Lee Date: Mon, 24 Jan 2022 12:13:38 -0800 Subject: [PATCH] Add delete ability (#380) * Update tests, builds and doc (#318) * rebased with bwc tests Signed-off-by: Shenoy Pratik * updated bwc tests Signed-off-by: Shenoy Pratik * added release notes Signed-off-by: Shenoy Pratik * Rename trace-analytics to observability (#341) Signed-off-by: Joshua Li * Event analytics unit tests (#342) * tests Signed-off-by: Eric Wei * updated some snapshots Signed-off-by: Eric Wei * resolved few failing tests Signed-off-by: Eric Wei * few modifications Signed-off-by: Eric Wei * Update service map parsing results for testing (#345) Signed-off-by: Joshua Li * bumping version to 1.2.2 (#346) * bumping version to 1.2.2 Signed-off-by: Shenoy Pratik * update PR in release notes Signed-off-by: Shenoy Pratik * updating readme and badges (#352) Signed-off-by: Shenoy Pratik * Application Analytics (#299) * Add database schema for application Signed-off-by: Eugene Lee * Finished front end for Application overview Signed-off-by: Eugene Lee * Finished application detail page tabs Signed-off-by: Eugene Lee * WIP: Overview Page Signed-off-by: Eugene Lee * Rough sketch of App Analytics UI Signed-off-by: Eugene Lee * Create dummy page Signed-off-by: Eugene Lee * Create app complete. Stabilizing dashboard component. Signed-off-by: Eugene Lee * Update to 1.2 Observability Signed-off-by: Eugene Lee * notebooks internal error Signed-off-by: Eugene Lee * Address comments on PR: copyright headers, indentation, unnecessary render props Signed-off-by: Eugene Lee * Set max width of app and event Signed-off-by: Eugene Lee * Remove optional after description Signed-off-by: Eugene Lee * Change to singular Signed-off-by: Eugene Lee * Remove count badge for log source Signed-off-by: Eugene Lee * #290: Change form row label to ppl base query Signed-off-by: Eugene Lee * #291: Change description and help text for log source Signed-off-by: Eugene Lee * Pass down proper props Signed-off-by: Eugene Lee * Resolve gradle error and module not found error Signed-off-by: Eugene Lee * Resolve kotlin errors Signed-off-by: Eugene Lee * Fix parsers Signed-off-by: Eugene Lee * Add praseItemList Signed-off-by: Eugene Lee * Camelcase fields Signed-off-by: Eugene Lee * Remove whitespace, add copyright Signed-off-by: Eugene Lee * #292: Add autocomplete to Log Source accordion Signed-off-by: Eugene Lee * Lexicographic kotlin import Signed-off-by: Eugene Lee * Add newline at end of files Signed-off-by: Eugene Lee * #293: Add service map to create page Signed-off-by: Eugene Lee * #304: Activate Clear All button for services Signed-off-by: Eugene Lee * #305: Add button to clear base query Signed-off-by: Eugene Lee * opensearch-project#295: Add eui combo box for trace groups Signed-off-by: Eugene Lee * Separate out configuration renders Signed-off-by: Eugene Lee * debug adding filters traces Signed-off-by: Eugene Lee * #296: Add traces table to config Signed-off-by: Eugene Lee * Change from tsx to ts Signed-off-by: Eugene Lee * opensearch-project#309: Add page props and add app specific filters Signed-off-by: Eugene Lee * #308: Add button to clear trace groups Signed-off-by: Eugene Lee * #311: Allow services and traces to be selected Signed-off-by: Eugene Lee * Remove link to traces on table Signed-off-by: Eugene Lee * Disable clear all if nothing selected Signed-off-by: Eugene Lee * disable clear all when no log source Signed-off-by: Eugene Lee * Remove comment, add style to constant, temporarily remove availability Signed-off-by: Eugene Lee * Address PR comments Signed-off-by: Eugene Lee * Revert type assignment Signed-off-by: Eugene Lee * Update tests, builds and doc (#318) * rebased with bwc tests Signed-off-by: Shenoy Pratik * updated bwc tests Signed-off-by: Shenoy Pratik * added release notes Signed-off-by: Shenoy Pratik * Fix errors and address comments Signed-off-by: Eugene Lee * #319: Disable create until required fields are filled out Signed-off-by: Eugene Lee * #329: Add missing field tool tip Signed-off-by: Eugene Lee * Remove unnecessary imports Signed-off-by: Eugene Lee * #320: Add clear modal for friction Signed-off-by: Eugene Lee Co-authored-by: Shenoy Pratik * Fix merge conflict Signed-off-by: Eugene Lee * Update Workflow (#360) * updated snapshot in workflow to 1.2.3 Signed-off-by: Shenoy Pratik * replaced variable with 1.2.3-snapshot Signed-off-by: Shenoy Pratik * revert string to variable Signed-off-by: Shenoy Pratik * Application Analytics (#299) * Add database schema for application Signed-off-by: Eugene Lee * Finished front end for Application overview Signed-off-by: Eugene Lee * Finished application detail page tabs Signed-off-by: Eugene Lee * WIP: Overview Page Signed-off-by: Eugene Lee * Rough sketch of App Analytics UI Signed-off-by: Eugene Lee * Create dummy page Signed-off-by: Eugene Lee * Create app complete. Stabilizing dashboard component. Signed-off-by: Eugene Lee * Update to 1.2 Observability Signed-off-by: Eugene Lee * notebooks internal error Signed-off-by: Eugene Lee * Address comments on PR: copyright headers, indentation, unnecessary render props Signed-off-by: Eugene Lee * Set max width of app and event Signed-off-by: Eugene Lee * Remove optional after description Signed-off-by: Eugene Lee * Change to singular Signed-off-by: Eugene Lee * Remove count badge for log source Signed-off-by: Eugene Lee * #290: Change form row label to ppl base query Signed-off-by: Eugene Lee * #291: Change description and help text for log source Signed-off-by: Eugene Lee * Pass down proper props Signed-off-by: Eugene Lee * Resolve gradle error and module not found error Signed-off-by: Eugene Lee * Resolve kotlin errors Signed-off-by: Eugene Lee * Fix parsers Signed-off-by: Eugene Lee * Add praseItemList Signed-off-by: Eugene Lee * Camelcase fields Signed-off-by: Eugene Lee * Remove whitespace, add copyright Signed-off-by: Eugene Lee * #292: Add autocomplete to Log Source accordion Signed-off-by: Eugene Lee * Lexicographic kotlin import Signed-off-by: Eugene Lee * Add newline at end of files Signed-off-by: Eugene Lee * #293: Add service map to create page Signed-off-by: Eugene Lee * #304: Activate Clear All button for services Signed-off-by: Eugene Lee * #305: Add button to clear base query Signed-off-by: Eugene Lee * opensearch-project#295: Add eui combo box for trace groups Signed-off-by: Eugene Lee * Separate out configuration renders Signed-off-by: Eugene Lee * debug adding filters traces Signed-off-by: Eugene Lee * #296: Add traces table to config Signed-off-by: Eugene Lee * Change from tsx to ts Signed-off-by: Eugene Lee * opensearch-project#309: Add page props and add app specific filters Signed-off-by: Eugene Lee * #308: Add button to clear trace groups Signed-off-by: Eugene Lee * #311: Allow services and traces to be selected Signed-off-by: Eugene Lee * Remove link to traces on table Signed-off-by: Eugene Lee * Disable clear all if nothing selected Signed-off-by: Eugene Lee * disable clear all when no log source Signed-off-by: Eugene Lee * Remove comment, add style to constant, temporarily remove availability Signed-off-by: Eugene Lee * Address PR comments Signed-off-by: Eugene Lee * Revert type assignment Signed-off-by: Eugene Lee * Update tests, builds and doc (#318) * rebased with bwc tests Signed-off-by: Shenoy Pratik * updated bwc tests Signed-off-by: Shenoy Pratik * added release notes Signed-off-by: Shenoy Pratik * Fix errors and address comments Signed-off-by: Eugene Lee * #319: Disable create until required fields are filled out Signed-off-by: Eugene Lee * #329: Add missing field tool tip Signed-off-by: Eugene Lee * Remove unnecessary imports Signed-off-by: Eugene Lee * #320: Add clear modal for friction Signed-off-by: Eugene Lee Co-authored-by: Shenoy Pratik * Application Analytics (#299) * Add database schema for application Signed-off-by: Eugene Lee * Finished front end for Application overview Signed-off-by: Eugene Lee * Finished application detail page tabs Signed-off-by: Eugene Lee * WIP: Overview Page Signed-off-by: Eugene Lee * Rough sketch of App Analytics UI Signed-off-by: Eugene Lee * Create dummy page Signed-off-by: Eugene Lee * Create app complete. Stabilizing dashboard component. Signed-off-by: Eugene Lee * Update to 1.2 Observability Signed-off-by: Eugene Lee * notebooks internal error Signed-off-by: Eugene Lee * Address comments on PR: copyright headers, indentation, unnecessary render props Signed-off-by: Eugene Lee * Set max width of app and event Signed-off-by: Eugene Lee * Remove optional after description Signed-off-by: Eugene Lee * Change to singular Signed-off-by: Eugene Lee * Remove count badge for log source Signed-off-by: Eugene Lee * #290: Change form row label to ppl base query Signed-off-by: Eugene Lee * #291: Change description and help text for log source Signed-off-by: Eugene Lee * Pass down proper props Signed-off-by: Eugene Lee * Resolve gradle error and module not found error Signed-off-by: Eugene Lee * Resolve kotlin errors Signed-off-by: Eugene Lee * Fix parsers Signed-off-by: Eugene Lee * Add praseItemList Signed-off-by: Eugene Lee * Camelcase fields Signed-off-by: Eugene Lee * Remove whitespace, add copyright Signed-off-by: Eugene Lee * #292: Add autocomplete to Log Source accordion Signed-off-by: Eugene Lee * Lexicographic kotlin import Signed-off-by: Eugene Lee * Add newline at end of files Signed-off-by: Eugene Lee * #293: Add service map to create page Signed-off-by: Eugene Lee * #304: Activate Clear All button for services Signed-off-by: Eugene Lee * #305: Add button to clear base query Signed-off-by: Eugene Lee * opensearch-project#295: Add eui combo box for trace groups Signed-off-by: Eugene Lee * Separate out configuration renders Signed-off-by: Eugene Lee * debug adding filters traces Signed-off-by: Eugene Lee * #296: Add traces table to config Signed-off-by: Eugene Lee * Change from tsx to ts Signed-off-by: Eugene Lee * opensearch-project#309: Add page props and add app specific filters Signed-off-by: Eugene Lee * #308: Add button to clear trace groups Signed-off-by: Eugene Lee * #311: Allow services and traces to be selected Signed-off-by: Eugene Lee * Remove link to traces on table Signed-off-by: Eugene Lee * Disable clear all if nothing selected Signed-off-by: Eugene Lee * disable clear all when no log source Signed-off-by: Eugene Lee * Remove comment, add style to constant, temporarily remove availability Signed-off-by: Eugene Lee * Address PR comments Signed-off-by: Eugene Lee * Revert type assignment Signed-off-by: Eugene Lee * Update tests, builds and doc (#318) * rebased with bwc tests Signed-off-by: Shenoy Pratik * updated bwc tests Signed-off-by: Shenoy Pratik * added release notes Signed-off-by: Shenoy Pratik * Fix errors and address comments Signed-off-by: Eugene Lee * #319: Disable create until required fields are filled out Signed-off-by: Eugene Lee * #329: Add missing field tool tip Signed-off-by: Eugene Lee * Remove unnecessary imports Signed-off-by: Eugene Lee * #320: Add clear modal for friction Signed-off-by: Eugene Lee Co-authored-by: Shenoy Pratik * Fix merge conflict Signed-off-by: Eugene Lee * #321: Add clear modal for services (#355) Signed-off-by: Eugene Lee * #322: Add clear modal for traces (#356) Signed-off-by: Eugene Lee * Adds tests for application creation (#357) * Remove unnecessary memoization Signed-off-by: Eugene Lee * Add tests for create page Signed-off-by: Eugene Lee * Remove conflict Signed-off-by: Eugene Lee * Add create route for app analytics Signed-off-by: Eugene Lee * #325: Return to app table on cancel Signed-off-by: Eugene Lee * Remove unnecessary import Signed-off-by: Eugene Lee * #340: Apps selectable, actions correctly disabled Signed-off-by: Eugene Lee * Fix mapping update Signed-off-by: Eugene Lee * #327: Rename application Signed-off-by: Eugene Lee * #376: Fetch all applications for home page Signed-off-by: Eugene Lee * #343: Enable deletion of application Signed-off-by: Eugene Lee * Add exception catch Signed-off-by: Eugene Lee * More specific exception : Signed-off-by: Eugene Lee * Log error instead of warn Signed-off-by: Eugene Lee * Remove generic exception Signed-off-by: Eugene Lee * Debug assert Signed-off-by: Eugene Lee * Fix type Signed-off-by: Eugene Lee * Fix Lint Signed-off-by: Eugene Lee * Address comments Signed-off-by: Eugene Lee * 343: Enable deletion of application Signed-off-by: Eugene Lee * Remove duplicate import Signed-off-by: Eugene Lee * Bump version to 1.3 Signed-off-by: Eugene Lee * Bump workflow Signed-off-by: Eugene Lee Co-authored-by: Shenoy Pratik Co-authored-by: Joshua Li Co-authored-by: Eric Wei --- ...-observability-test-and-build-workflow.yml | 4 +-- .../components/app_table.tsx | 36 +++++++++++++++++-- .../components/application_analytics/home.tsx | 29 ++++++++++++--- .../app_analytics_adaptor.ts | 29 ++++++++++++--- .../app_analytics_router.ts | 36 ++++++++++++++++++- opensearch-observability/build.gradle | 2 +- 6 files changed, 121 insertions(+), 15 deletions(-) diff --git a/.github/workflows/opensearch-observability-test-and-build-workflow.yml b/.github/workflows/opensearch-observability-test-and-build-workflow.yml index ddfbc740b..6b69ff9b2 100644 --- a/.github/workflows/opensearch-observability-test-and-build-workflow.yml +++ b/.github/workflows/opensearch-observability-test-and-build-workflow.yml @@ -3,8 +3,8 @@ name: Test and Build OpenSearch Observability Backend Plugin on: [pull_request, push] env: - OPENSEARCH_VERSION: '1.2.3-SNAPSHOT' - OPENSEARCH_BRANCH: '1.2' + OPENSEARCH_VERSION: '1.3.0-SNAPSHOT' + OPENSEARCH_BRANCH: '1.3' COMMON_UTILS_BRANCH: 'main' jobs: diff --git a/dashboards-observability/public/components/application_analytics/components/app_table.tsx b/dashboards-observability/public/components/application_analytics/components/app_table.tsx index 3f0fec44f..0308634bf 100644 --- a/dashboards-observability/public/components/application_analytics/components/app_table.tsx +++ b/dashboards-observability/public/components/application_analytics/components/app_table.tsx @@ -30,14 +30,16 @@ import _ from 'lodash'; import React, { ReactElement, useEffect, useState } from 'react'; import { AppAnalyticsComponentDeps } from '../home'; import { getCustomModal } from '../../custom_panels/helpers/modal_containers'; +import { getClearModal } from '../helpers/modal_containers'; import { pageStyles } from '../../../../common/constants/shared'; -import { ApplicationListType } from '../../../../common/types/app_analytics'; +import { ApplicationListType } from '../../../../common/constants/application_analytics'; interface AppTableProps extends AppAnalyticsComponentDeps { loading: boolean; applications: Array; fetchApplications: () => void; renameApplication: (newAppName: string, appId: string) => void; + deleteApplication: (appList: string[], toastMessage?: string) => void; }; export function AppTable(props: AppTableProps) { @@ -45,7 +47,7 @@ export function AppTable(props: AppTableProps) { const [isActionsPopoverOpen, setIsActionsPopoverOpen] = useState(false); const [modalLayout, setModalLayout] = useState(); const [selectedApplications, setSelectedApplications] = useState([]); - const { chrome, applications, parentBreadcrumb, fetchApplications, renameApplication } = props; + const { chrome, applications, parentBreadcrumb, fetchApplications, renameApplication, deleteApplication } = props; useEffect(() => { chrome.setBreadcrumbs( @@ -72,13 +74,24 @@ export function AppTable(props: AppTableProps) { closeModal(); }; + const onDelete = async () => { + const toastMessage = `Application${ + selectedApplications.length > 1 ? 's' : ' "' + selectedApplications[0].name + '"' + } successfully deleted!`; + await deleteApplication( + selectedApplications.map((app) => app.id), + toastMessage + ); + closeModal(); + }; + const renameApp = () => { setModalLayout( getCustomModal( onRename, closeModal, 'Name', - 'Rename Application', + 'Rename application', 'Cancel', 'Rename', selectedApplications[0].name @@ -87,6 +100,19 @@ export function AppTable(props: AppTableProps) { showModal(); }; + const deleteApp = () => { + const applicationString = `application${selectedApplications.length > 1 ? 's' : ''}`; + setModalLayout( + getClearModal( + closeModal, + onDelete, + `Delete ${selectedApplications.length} ${applicationString}`, + `Are you sure you want to delete the selected ${selectedApplications.length} ${applicationString}?` + ) + ); + showModal(); + }; + const popoverButton = ( { + setIsActionsPopoverOpen(false); + deleteApp(); + }} > Delete , diff --git a/dashboards-observability/public/components/application_analytics/home.tsx b/dashboards-observability/public/components/application_analytics/home.tsx index 12b4eb2bd..96f4b4b74 100644 --- a/dashboards-observability/public/components/application_analytics/home.tsx +++ b/dashboards-observability/public/components/application_analytics/home.tsx @@ -18,7 +18,8 @@ import TimestampUtils from 'public/services/timestamp/timestamp'; import { handleIndicesExistRequest } from '../trace_analytics/requests/request_handler'; import { ObservabilitySideBar } from '../common/side_nav'; import { NotificationsStart } from '../../../../../src/core/public'; -import { optionType, APP_ANALYTICS_API_PREFIX, ApplicationListType } from '../../../common/types/app_analytics'; +import { APP_ANALYTICS_API_PREFIX } from '../../../common/constants/application_analytics'; +import { optionType, ApplicationListType } from '../../../common/types/app_analytics'; import { isNameValid } from './helpers/utils'; import { EuiGlobalToastList } from '@elastic/eui'; import { Toast } from '@elastic/eui/src/components/toast/global_toast_list'; @@ -93,7 +94,7 @@ export const Home = (props: HomeProps) => { const fetchApps = () => { return http .get(`${APP_ANALYTICS_API_PREFIX}/`) - .then(async (res) => { + .then((res) => { setApplicationData(res.data); }) .catch((err) => { @@ -122,7 +123,7 @@ export const Home = (props: HomeProps) => { .post(`${APP_ANALYTICS_API_PREFIX}/`, { body: JSON.stringify(requestBody) }) - .then(async (res) => { + .then((res) => { setToast(`Application "${name}" successfully created!`); window.location.assign(`${parentBreadcrumb.href}${res.newAppId}`) }) @@ -148,7 +149,7 @@ export const Home = (props: HomeProps) => { .patch(`${APP_ANALYTICS_API_PREFIX}/rename`, { body: JSON.stringify(requestBody) }) - .then(async (res) => { + .then((res) => { setApplicationData((prevApplicationData) => { const newApplicationData = [...prevApplicationData]; const renamedApplication = newApplicationData.find( @@ -165,6 +166,25 @@ export const Home = (props: HomeProps) => { }); }; + // Delete existing applications + const deleteApp = (appList: string[], toastMessage?: string) => { + return http + .delete(`${APP_ANALYTICS_API_PREFIX}/${appList.join(',')}`) + .then((res) => { + setApplicationData((prevApplicationData) => { + return prevApplicationData.filter((app) => !appList.includes(app.id)) + }); + const message = + toastMessage || `Application${appList.length > 1 ? 's' : ''} successfully deleted!`; + setToast(message); + return res; + }) + .catch((err: any) => { + setToast('Error occured while deleting application', 'danger'); + console.error(err); + }); + }; + return (
{ applications={applicationData} fetchApplications={fetchApps} renameApplication={renameApp} + deleteApplication={deleteApp} {...commonProps} /> } diff --git a/dashboards-observability/server/adaptors/application_analytics/app_analytics_adaptor.ts b/dashboards-observability/server/adaptors/application_analytics/app_analytics_adaptor.ts index 89f18ae16..8adaa6370 100644 --- a/dashboards-observability/server/adaptors/application_analytics/app_analytics_adaptor.ts +++ b/dashboards-observability/server/adaptors/application_analytics/app_analytics_adaptor.ts @@ -63,8 +63,13 @@ export class AppAnalyticsAdaptor { const updateApplicationBody = { name: name, }; - try { - const response = await this.updateApp(client, appId, updateApplicationBody); + try { + const response = await client.callAsCurrentUser('observability.updateObjectById', { + objectId: appId, + body: { + application: updateApplicationBody, + } + }) return response.objectId; } catch (err: any) { throw new Error('Rename Application Error: ' + err); @@ -86,7 +91,23 @@ export class AppAnalyticsAdaptor { }); return response; } catch (err: any) { - throw new Error('Update Panel Error: ' + err) + throw new Error('Update Panel Error: ' + err); + } + } + + // Delete existing applications + deleteApp = async ( + client: ILegacyScopedClusterClient, + appList: string, + ) => { + try { + const response = await client.callAsCurrentUser('observability.deleteObjectByIdList', { + objectIdList: appList, + }); + return { status: 'OK', message: response }; + } catch (err: any) { + throw new Error('Delete Application Error: ' + err); } } -} \ No newline at end of file + +} diff --git a/dashboards-observability/server/routes/application_analytics/app_analytics_router.ts b/dashboards-observability/server/routes/application_analytics/app_analytics_router.ts index 3aae27159..edcf8b3c0 100644 --- a/dashboards-observability/server/routes/application_analytics/app_analytics_router.ts +++ b/dashboards-observability/server/routes/application_analytics/app_analytics_router.ts @@ -138,4 +138,38 @@ export function registerAppAnalyticsRouter(router: IRouter) { } ); -} \ No newline at end of file + // Delete applications + router.delete( + { + path: `${API_PREFIX}/{appList}`, + validate: { + params: schema.object({ + appList: schema.string(), + }), + }, + }, + async ( + context, + request, + response + ): Promise> => { + const opensearchClient: ILegacyScopedClusterClient = context.observability_plugin.observabilityClient.asScoped( + request + ); + try { + const delResponse = await appAnalyticsBackend.deleteApp( + opensearchClient, + request.params.appList + ); + return response.ok({ + body: delResponse, + }); + } catch (err: any) { + return response.custom({ + statusCode: err.statusCode || 500, + body: err.message, + }); + } + } + ); +} diff --git a/opensearch-observability/build.gradle b/opensearch-observability/build.gradle index 7cd5c88a7..f2e5e1a49 100644 --- a/opensearch-observability/build.gradle +++ b/opensearch-observability/build.gradle @@ -9,7 +9,7 @@ import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask buildscript { ext { - opensearch_version = System.getProperty("opensearch.version", "1.2.3-SNAPSHOT") + opensearch_version = System.getProperty("opensearch.version", "1.3.0-SNAPSHOT") // 1.0.0 -> 1.0.0.0, and 1.0.0-SNAPSHOT -> 1.0.0.0-SNAPSHOT opensearch_build = opensearch_version.replaceAll(/(\.\d)([^\d]*)$/, '$1.0$2') common_utils_version = System.getProperty("common_utils.version", opensearch_build)