Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Fix metrics enablement (#360)
Browse files Browse the repository at this point in the history
* Refresh isMetricsAvailable after toggle inject

Signed-off-by: Tim Etchells <[email protected]>

* 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 <[email protected]>
  • Loading branch information
Tim Etchells authored and jopit committed Dec 17, 2019
1 parent f1d771e commit c67f56d
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 16 deletions.
4 changes: 2 additions & 2 deletions dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
{
Expand Down
3 changes: 2 additions & 1 deletion dev/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
23 changes: 17 additions & 6 deletions dev/src/codewind/project/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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<boolean> {
if (newInjectMetrics == null) {
return false;
}
Expand All @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions dev/src/codewind/project/ProjectType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions dev/src/codewind/project/Requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ namespace Requester {
return new ProjectCapabilities(result.startModes, result.controlCommands, metricsAvailable);
}

async function areMetricsAvailable(project: Project): Promise<boolean> {
export async function areMetricsAvailable(project: Project): Promise<boolean> {
const msg = Translator.t(STRING_NS, "checkingMetrics");
const res = await doProjectRequest(project, ProjectEndpoints.METRICS_STATUS, {}, "GET", msg, true);
return res.metricsAvailable;
Expand All @@ -338,7 +338,7 @@ namespace Requester {
};

await doProjectRequest(project, ProjectEndpoints.METRICS_INJECTION, body, "POST", newAutoInjectMetricsUserStr);
project.setInjectMetrics(newInjectMetrics);
await project.setInjectMetrics(newInjectMetrics);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion dev/src/command/project/OpenAppMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default async function openAppMonitorCmd(project: Project): Promise<void>
return;
}

if (project.appMonitorUrl == null || !(await testPingAppMonitor(project))) {
if (!project.hasAppMonitor || project.appMonitorUrl == null) {
vscode.window.showWarningMessage(getAppMetricsNotSupportedMsg(project.name));
return;
}
Expand Down
2 changes: 1 addition & 1 deletion dev/src/command/project/OpenPerfDashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Constants from "../../constants/Constants";
import { testPingAppMonitor, getAppMetricsNotSupportedMsg } from "./OpenAppMonitor";

export default async function openPerformanceDashboard(project: Project): Promise<void> {
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));
Expand Down
12 changes: 9 additions & 3 deletions dev/src/view/TreeItemContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c67f56d

Please sign in to comment.