From c67f56de2eba71feeb12c6fd7e42c7f414ed8754 Mon Sep 17 00:00:00 2001 From: Tim Etchells Date: Tue, 17 Dec 2019 14:09:33 -0500 Subject: [PATCH] Fix metrics enablement (#360) * Refresh isMetricsAvailable after toggle inject Signed-off-by: Tim Etchells * App Monitor and Perf Dashboard enablement changes - Separate app monitor and perf dashboard enablement - Always show App Monitor for java and node projects Signed-off-by: Tim Etchells --- dev/package.json | 4 ++-- dev/package.nls.json | 3 ++- dev/src/codewind/project/Project.ts | 23 +++++++++++++++----- dev/src/codewind/project/ProjectType.ts | 10 +++++++++ dev/src/codewind/project/Requester.ts | 4 ++-- dev/src/command/project/OpenAppMonitor.ts | 2 +- dev/src/command/project/OpenPerfDashboard.ts | 2 +- dev/src/view/TreeItemContext.ts | 12 +++++++--- 8 files changed, 44 insertions(+), 16 deletions(-) diff --git a/dev/package.json b/dev/package.json index e4a9e130..3ed0bd7c 100644 --- a/dev/package.json +++ b/dev/package.json @@ -488,12 +488,12 @@ }, { "command": "%cmdID_openAppMonitor%", - "when": "%isProjectWithMetrics%", + "when": "%isProjectWithAppMonitor%", "group": "ext.cw.b@3" }, { "command": "%cmdID_openPerfDashboard%", - "when": "%isProjectWithMetrics%", + "when": "%isProjectWithPerfDashboard%", "group": "ext.cw.b@4" }, { diff --git a/dev/package.nls.json b/dev/package.nls.json index 37407769..500fe84f 100644 --- a/dev/package.nls.json +++ b/dev/package.nls.json @@ -155,7 +155,8 @@ "isDisabledProject": "viewItem =~ /ext\\.cw\\.project\\.disabled.*/", "isStartedProject": "viewItem =~ /ext\\.cw\\.project\\.enabled\\.started.*/", "isDebuggableProject": "viewItem =~ /ext\\.cw\\.project\\.enabled.*\\.debuggable.*/", - "isProjectWithMetrics": "viewItem =~ /ext\\.cw\\.project\\.enabled.*\\.metricsAvailable.*/", + "isProjectWithAppMonitor": "viewItem =~ /ext\\.cw\\.project\\.enabled.*\\.appMonitor.*/", + "isProjectWithPerfDashboard": "viewItem =~ /ext\\.cw\\.project\\.enabled.*\\.perfDashboard.*/", "isRestartableProject": "viewItem =~ /ext\\.cw\\.project\\.enabled.*\\.restartable.*/", "isShellableProject": "viewItem =~ /ext\\.cw\\.project\\.enabled.*\\.shellable.*/", "isEnabledAutoBuildOn": "viewItem =~ /ext\\.cw\\.project\\.enabled.*\\.autoBuildOn/", diff --git a/dev/src/codewind/project/Project.ts b/dev/src/codewind/project/Project.ts index dc2969db..12236abb 100644 --- a/dev/src/codewind/project/Project.ts +++ b/dev/src/codewind/project/Project.ts @@ -32,8 +32,8 @@ import { deleteProjectDir } from "../../command/project/RemoveProjectCmd"; import { refreshProjectOverview } from "../../command/webview/pages/ProjectOverviewPage"; import Constants from "../../constants/Constants"; import Commands from "../../constants/Commands"; -import { getCodewindIngress } from "../../command/project/OpenPerfDashboard" -import EndpointUtil from "../../constants/Endpoints" +import { getCodewindIngress } from "../../command/project/OpenPerfDashboard"; +import EndpointUtil from "../../constants/Endpoints"; /** * Used to determine App Monitor URL @@ -552,6 +552,14 @@ export default class Project implements vscode.QuickPickItem { return this._capabilities; } + public get hasAppMonitor(): boolean { + return this.type.alwaysHasAppMonitor || this.capabilities.metricsAvailable; + } + + public get hasPerfDashboard(): boolean { + return this.capabilities.metricsAvailable || this.injectMetricsEnabled; + } + public get appUrl(): vscode.Uri | undefined { // If the backend has provided us with a baseUrl already, use that if (this.appBaseURL) { @@ -598,6 +606,7 @@ export default class Project implements vscode.QuickPickItem { const appMetricsPath = langToPathMap.get(this.type.language); const supported = appMetricsPath != null && this.capabilities.metricsAvailable; if ((!this._injectMetricsEnabled) && supported) { + // open app monitor in Application container Log.d(`${this.name} supports metrics ? ${supported}`); if (this.appUrl === undefined) { return undefined; @@ -608,17 +617,19 @@ export default class Project implements vscode.QuickPickItem { } return monitorPageUrlStr + appMetricsPath + "/?theme=dark"; } + try { + // open app monitor in Performance container const cwBaseUrl = global.isTheia ? getCodewindIngress() : this.connection.url; const dashboardUrl = EndpointUtil.getPerformanceMonitor(cwBaseUrl, this.language, this.id); - Log.d(`Monitor Dashboard url for ${this.name} is ${dashboardUrl}`); + Log.d(`Perf container Monitor Dashboard url for ${this.name} is ${dashboardUrl}`); return dashboardUrl.toString(); } catch (err) { + Log.e(`${this} error determining app monitor URL`, err); vscode.window.showErrorMessage(MCUtil.errToString(err)); return undefined; } - } public get canContainerShell(): boolean { @@ -730,7 +741,7 @@ export default class Project implements vscode.QuickPickItem { return changed; } - public setInjectMetrics(newInjectMetrics: boolean | undefined): boolean { + public async setInjectMetrics(newInjectMetrics: boolean | undefined): Promise { if (newInjectMetrics == null) { return false; } @@ -741,9 +752,9 @@ export default class Project implements vscode.QuickPickItem { if (changed) { // onChange has to be invoked explicitly because this function can be called outside of update() Log.d(`New autoInjectMetricsEnabled for ${this.name} is ${this._injectMetricsEnabled}`); + this.capabilities.metricsAvailable = await Requester.areMetricsAvailable(this); this.onChange(); } - return changed; } diff --git a/dev/src/codewind/project/ProjectType.ts b/dev/src/codewind/project/ProjectType.ts index 6094e27c..f7b6c434 100644 --- a/dev/src/codewind/project/ProjectType.ts +++ b/dev/src/codewind/project/ProjectType.ts @@ -144,6 +144,16 @@ export class ProjectType { ProjectType.InternalTypes.SPRING ].includes(this.internalType); } + + public get alwaysHasAppMonitor(): boolean { + // This should be the job of the capabilities API + return [ + ProjectType.Languages.JAVA, + ProjectType.Languages.NODE, + ] + .map((lang) => lang.toString().toLowerCase()) + .includes(this.language.toLowerCase()); + } } export namespace ProjectType { diff --git a/dev/src/codewind/project/Requester.ts b/dev/src/codewind/project/Requester.ts index 66776e36..0f370cbd 100644 --- a/dev/src/codewind/project/Requester.ts +++ b/dev/src/codewind/project/Requester.ts @@ -320,7 +320,7 @@ namespace Requester { return new ProjectCapabilities(result.startModes, result.controlCommands, metricsAvailable); } - async function areMetricsAvailable(project: Project): Promise { + export async function areMetricsAvailable(project: Project): Promise { const msg = Translator.t(STRING_NS, "checkingMetrics"); const res = await doProjectRequest(project, ProjectEndpoints.METRICS_STATUS, {}, "GET", msg, true); return res.metricsAvailable; @@ -338,7 +338,7 @@ namespace Requester { }; await doProjectRequest(project, ProjectEndpoints.METRICS_INJECTION, body, "POST", newAutoInjectMetricsUserStr); - project.setInjectMetrics(newInjectMetrics); + await project.setInjectMetrics(newInjectMetrics); } /** diff --git a/dev/src/command/project/OpenAppMonitor.ts b/dev/src/command/project/OpenAppMonitor.ts index e2c5bcd9..9d64cfe4 100644 --- a/dev/src/command/project/OpenAppMonitor.ts +++ b/dev/src/command/project/OpenAppMonitor.ts @@ -26,7 +26,7 @@ export default async function openAppMonitorCmd(project: Project): Promise return; } - if (project.appMonitorUrl == null || !(await testPingAppMonitor(project))) { + if (!project.hasAppMonitor || project.appMonitorUrl == null) { vscode.window.showWarningMessage(getAppMetricsNotSupportedMsg(project.name)); return; } diff --git a/dev/src/command/project/OpenPerfDashboard.ts b/dev/src/command/project/OpenPerfDashboard.ts index 13ce3aea..122884e4 100644 --- a/dev/src/command/project/OpenPerfDashboard.ts +++ b/dev/src/command/project/OpenPerfDashboard.ts @@ -21,7 +21,7 @@ import Constants from "../../constants/Constants"; import { testPingAppMonitor, getAppMetricsNotSupportedMsg } from "./OpenAppMonitor"; export default async function openPerformanceDashboard(project: Project): Promise { - const supportsMetrics = project.capabilities.metricsAvailable; + const supportsMetrics = project.hasPerfDashboard; Log.d(`${project.name} supports perfmonitor ? ${supportsMetrics}`); if (!supportsMetrics || !(await testPingAppMonitor(project))) { vscode.window.showWarningMessage(getAppMetricsNotSupportedMsg(project.name)); diff --git a/dev/src/view/TreeItemContext.ts b/dev/src/view/TreeItemContext.ts index 383fbd2e..b576ca2a 100644 --- a/dev/src/view/TreeItemContext.ts +++ b/dev/src/view/TreeItemContext.ts @@ -57,7 +57,9 @@ enum TreeItemContextValues { PROJ_AUTOBUILD_OFF = "autoBuildOff", PROJ_RESTARTABLE = "restartable", - PROJ_METRICS = "metricsAvailable", + + PROJ_APP_MONITOR = "appMonitor", + PROJ_PERF_DASHBOARD = "perfDashboard", PROJ_SHELLABLE = "shellable", @@ -138,8 +140,12 @@ namespace TreeItemContext { contextValues.push(TreeItemContextValues.PROJ_RESTARTABLE); } - if (project.capabilities.metricsAvailable) { - contextValues.push(TreeItemContextValues.PROJ_METRICS); + if (project.hasAppMonitor) { + contextValues.push(TreeItemContextValues.PROJ_APP_MONITOR); + } + + if (project.hasPerfDashboard) { + contextValues.push(TreeItemContextValues.PROJ_PERF_DASHBOARD); } if (project.canContainerShell) {