From 96143e16432d580e9998cb0811d34342054244ae Mon Sep 17 00:00:00 2001 From: Eugene Lee Date: Tue, 25 Jan 2022 12:32:36 -0800 Subject: [PATCH] Application Details (#383) * 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 * 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 * bumping main to 1.3 (#361) Signed-off-by: Shenoy Pratik * Add observability visualization to notebooks (#351) * added observability viz support to notes Signed-off-by: Shenoy Pratik * updated tests, clone para, zeppelin parser Signed-off-by: Shenoy Pratik * updated observability viz links & cypress Signed-off-by: Shenoy Pratik * updated tests Signed-off-by: Shenoy Pratik * removed inputType, merged both viz options Signed-off-by: Shenoy Pratik * resolved merge conflict Signed-off-by: Shenoy Pratik * updated links, adaptors, tests Signed-off-by: Shenoy Pratik * removed unused files, updated workflow Signed-off-by: Shenoy Pratik * updated UI dateformat for observability viz Signed-off-by: Shenoy Pratik * updated jest timeout Signed-off-by: Shenoy Pratik * updated notebook tests Signed-off-by: Shenoy Pratik * Add .whitesource configuration file (#365) Co-authored-by: whitesource-for-github-com[bot] <50673670+whitesource-for-github-com[bot]@users.noreply.github.com> * CVE fix:json-schema, gson & glob-parent (#368) * CVE fix:json-schema, gson & glob-parent Signed-off-by: Shenoy Pratik * updated yarn.lock Signed-off-by: Shenoy Pratik * Update Release Notes 1.2.4 (#370) * CVE fix:json-schema, gson & glob-parent Signed-off-by: Shenoy Pratik * updated yarn.lock Signed-off-by: Shenoy Pratik * Update Release Notes 1.2.4 Signed-off-by: Shenoy Pratik * jcenter removed from gradle.build (#374) 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 * #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 * 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 * 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 * Fetch application by Id 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 * Remove branch Signed-off-by: Eugene Lee * Remove trace if selected Signed-off-by: Eugene Lee * Rename trace-analytics to observability (#341) Signed-off-by: Joshua Li * updating readme and badges (#352) Signed-off-by: Shenoy Pratik * Name is blank if loading Signed-off-by: Eugene Lee Co-authored-by: Shenoy Pratik Co-authored-by: Joshua Li Co-authored-by: Eric Wei Co-authored-by: whitesource-for-github-com[bot] <50673670+whitesource-for-github-com[bot]@users.noreply.github.com> --- .../components/application.tsx | 47 ++++++++++++++++--- .../components/create.tsx | 2 +- .../components/application_analytics/home.tsx | 20 ++++---- .../app_analytics_adaptor.ts | 14 +++++- .../app_analytics_router.ts | 36 ++++++++++++++ 5 files changed, 101 insertions(+), 18 deletions(-) diff --git a/dashboards-observability/public/components/application_analytics/components/application.tsx b/dashboards-observability/public/components/application_analytics/components/application.tsx index 3c0af6d13..0b32d7499 100644 --- a/dashboards-observability/public/components/application_analytics/components/application.tsx +++ b/dashboards-observability/public/components/application_analytics/components/application.tsx @@ -24,9 +24,11 @@ import DSLService from 'public/services/requests/dsl'; import PPLService from 'public/services/requests/ppl'; import SavedObjects from 'public/services/saved_objects/event_analytics/saved_objects'; import TimestampUtils from 'public/services/timestamp/timestamp'; -import React, { ReactChild, useState } from 'react'; +import React, { ReactChild, useEffect, useState } from 'react'; import { isEmpty, uniqueId } from 'lodash'; import { + ApplicationType, + APP_ANALYTICS_API_PREFIX, TAB_CONFIG_ID_TXT_PFX, TAB_CONFIG_TITLE, TAB_LOG_ID_TXT_PFX, @@ -70,14 +72,45 @@ interface AppDetailProps extends AppAnalyticsComponentDeps { notifications: NotificationsStart; } - export function Application(props: AppDetailProps) { - const { pplService, dslService, timestampUtils, savedObjects, http, notifications } = props; + const { pplService, dslService, timestampUtils, savedObjects, http, notifications, appId, chrome, parentBreadcrumb } = props; + const [application, setApplication] = useState(); const [selectedTabId, setSelectedTab] = useState(TAB_OVERVIEW_ID); const handleContentTabClick = (selectedTab: IQueryTab) => setSelectedTab(selectedTab.id); const history = useHistory(); const [toasts, setToasts] = useState>([]); + // Fetch application by id + const fetchAppById = async (appId: string) => { + return http + .get(`${APP_ANALYTICS_API_PREFIX}/${appId}`) + .then((res) => { + setApplication(res.application); + }) + .catch((err) => { + setToast('Error occurred while fetching application', 'danger'); + console.error(err); + }) + } + + useEffect(() => { + fetchAppById(appId); + }, [appId]); + + useEffect(() => { + chrome.setBreadcrumbs([ + parentBreadcrumb, + { + text: 'Application analytics', + href: '#/application_analytics', + }, + { + text: application?.name || '', + href: `${parentBreadcrumb.href}${appId}`, + }, + ]); + }, [appId, application?.name]); + const setToast = (title: string, color = 'success', text?: ReactChild, side?: string) => { if (!text) text = ''; setToasts([...toasts, { id: new Date().toISOString(), title, text, color } as Toast]); @@ -98,20 +131,20 @@ export function Application(props: AppDetailProps) { const getOverview = () => { return ( - + ); }; const getService = () => { return ( - + ); }; const getTrace = () => { return ( <> - + -

my-app1

+

{application?.name || ''}

diff --git a/dashboards-observability/public/components/application_analytics/components/create.tsx b/dashboards-observability/public/components/application_analytics/components/create.tsx index 17f21e7cd..8749846b1 100644 --- a/dashboards-observability/public/components/application_analytics/components/create.tsx +++ b/dashboards-observability/public/components/application_analytics/components/create.tsx @@ -97,7 +97,7 @@ export const CreateApp = (props: CreateAppProps) => { }; const onCreate = () => { - createApp(state.name, state.description, query, selectedServices, selectedTraces) + createApp(state.name, state.description, query, selectedServices, selectedTraces); } const onCancel = () => { diff --git a/dashboards-observability/public/components/application_analytics/home.tsx b/dashboards-observability/public/components/application_analytics/home.tsx index 5f847406f..35be5732a 100644 --- a/dashboards-observability/public/components/application_analytics/home.tsx +++ b/dashboards-observability/public/components/application_analytics/home.tsx @@ -38,7 +38,7 @@ export interface AppAnalyticsComponentDeps extends TraceAnalyticsComponentDeps { export const Home = (props: HomeProps) => { const { pplService, dslService, timestampUtils, savedObjects, parentBreadcrumb, http, chrome, notifications } = props; - const [applicationData, setApplicationData] = useState>([]); + const [applicationList, setApplicationList] = useState>([]); const [toasts, setToasts] = useState>([]); const [indicesExist, setIndicesExist] = useState(true); const storedFilters = sessionStorage.getItem('AppAnalyticsFilters'); @@ -94,10 +94,10 @@ export const Home = (props: HomeProps) => { return http .get(`${APP_ANALYTICS_API_PREFIX}/`) .then((res) => { - setApplicationData(res.data); + setApplicationList(res.data); }) .catch((err) => { - setToast('Error occured while fetching applications', 'danger'); + setToast('Error occurred while fetching applications', 'danger'); console.error(err); }) } @@ -124,7 +124,9 @@ export const Home = (props: HomeProps) => { }) .then((res) => { setToast(`Application "${name}" successfully created!`); - window.location.assign(`${parentBreadcrumb.href}${res.newAppId}`) + setFiltersWithStorage([]); + setQueryWithStorage(''); + window.location.assign(`${parentBreadcrumb.href}application_analytics/${res.newAppId}`) }) .catch((err) => { setToast(`Error occurred while creating new application "${name}"`, 'danger'); @@ -149,8 +151,8 @@ export const Home = (props: HomeProps) => { body: JSON.stringify(requestBody) }) .then((res) => { - setApplicationData((prevApplicationData) => { - const newApplicationData = [...prevApplicationData]; + setApplicationList((prevApplicationList) => { + const newApplicationData = [...prevApplicationList]; const renamedApplication = newApplicationData.find( (application) => application.id === appId ); @@ -170,8 +172,8 @@ export const Home = (props: HomeProps) => { return http .delete(`${APP_ANALYTICS_API_PREFIX}/${appList.join(',')}`) .then((res) => { - setApplicationData((prevApplicationData) => { - return prevApplicationData.filter((app) => !appList.includes(app.id)) + setApplicationList((prevApplicationList) => { + return prevApplicationList.filter((app) => !appList.includes(app.id)) }); const message = toastMessage || `Application${appList.length > 1 ? 's' : ''} successfully deleted!`; @@ -201,7 +203,7 @@ export const Home = (props: HomeProps) => { { + fetchApps = async (client: ILegacyScopedClusterClient) => { try { const response = await client.callAsCurrentUser('observability.getObject', { objectType: 'application', @@ -25,6 +25,18 @@ export class AppAnalyticsAdaptor { } } + // Fetch application by id + fetchAppById = async (client: ILegacyScopedClusterClient, appId: string) => { + try { + const response = await client.callAsCurrentUser('observability.getObjectById', { + objectId: appId, + }); + return response.observabilityObjectList[0]; + } catch (err: any) { + throw new Error('Fetch Application By Id Error: ' + err); + } + } + // Create a new application createNewApp = async ( client: ILegacyScopedClusterClient, 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 edcf8b3c0..e22f7eb92 100644 --- a/dashboards-observability/server/routes/application_analytics/app_analytics_router.ts +++ b/dashboards-observability/server/routes/application_analytics/app_analytics_router.ts @@ -48,6 +48,42 @@ export function registerAppAnalyticsRouter(router: IRouter) { } } ) + + // Fetch application by id + router.get( + { + path: `${API_PREFIX}/{appId}`, + validate: { + params: schema.object({ + appId: schema.string(), + }), + }, + }, + async( + context, + request, + response + ): Promise> => { + const opensearchClient: ILegacyScopedClusterClient = context.observability_plugin.observabilityClient.asScoped( + request + ); + try { + const appObject = await appAnalyticsBackend.fetchAppById( + opensearchClient, + request.params.appId + ); + return response.ok({ + body: appObject + }); + } catch (err: any) { + console.error('Error occurred while fetching application', err); + return response.custom({ + statusCode: err.statusCode || 500, + body: err.message, + }); + } + } + ) // Create a new application router.post(