Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use asExternalUri For Server Url #173

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"workbench.colorCustomizations": {
"activityBar.background": "#273111",
"titleBar.activeBackground": "#374518",
"titleBar.activeForeground": "#F8FBF2"
},
}
11 changes: 10 additions & 1 deletion vscode-trace-common/src/client/tsp-client-provider-impl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TspClient } from 'tsp-typescript-client/lib/protocol/tsp-client';
import { RestClient, ConnectionStatusListener } from 'tsp-typescript-client/lib/protocol/rest-client';
import { ServerStateManager } from 'tsp-typescript-client/lib/protocol/request-manager';
import { ExperimentManager } from 'traceviewer-base/lib/experiment-manager';
import { TraceManager } from 'traceviewer-base/lib/trace-manager';
import { ITspClientProvider } from 'traceviewer-base/lib/tsp-client-provider';
Expand Down Expand Up @@ -29,7 +30,6 @@ export class TspClientProvider implements ITspClientProvider {
this._signalHandler?.notifyConnection(status);
};
RestClient.addConnectionStatusListener(this._statusListener);
this._tspClient.checkHealth();

this._urlProvider = _urlProvider;
this._listeners = [];
Expand All @@ -53,6 +53,10 @@ export class TspClientProvider implements ITspClientProvider {
return this._experimentManager;
}

public getRequestManager(): typeof ServerStateManager {
return ServerStateManager;
}

/**
* Add a listener for trace server url changes
* @param listener The listener function to be called when the url is
Expand All @@ -62,3 +66,8 @@ export class TspClientProvider implements ITspClientProvider {
this._listeners.push(listener);
}
}

// Perhaps this should live somewhere else or in its own file.
export const cancelAllOngoingRequests = (): void => {
ServerStateManager.cancelAllRequests();
}
13 changes: 12 additions & 1 deletion vscode-trace-common/src/messages/vscode-message-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ export const VSCODE_MESSAGES = {
REQUEST_SELECTION_RANGE_CHANGE: 'requestSelectionRangeChange',
RESTORE_VIEW: 'restoreView',
RESTORE_COMPLETE: 'restoreComplete',
OUTPUT_DATA_CHANGED: 'outputDataChanged'
OUTPUT_DATA_CHANGED: 'outputDataChanged',
CANCEL_REQUESTS: 'cancelRequests',
TRACE_SERVER_STATUS: 'traceServerStatus',
START_SERVER: 'startServer',
};

export class VsCodeMessageManager extends Messages.MessageManager {
Expand Down Expand Up @@ -193,4 +196,12 @@ export class VsCodeMessageManager extends Messages.MessageManager {
const status: string = JSON.stringify(context);
vscode.postMessage({ command: VSCODE_MESSAGES.MARKER_CATEGORIES_CONTEXT, data: { status } });
}

cancelRequests(): void {
vscode.postMessage({ command: VSCODE_MESSAGES.CANCEL_REQUESTS });
}

startServer(): void {
vscode.postMessage({ command: VSCODE_MESSAGES.START_SERVER });
}
}
20 changes: 16 additions & 4 deletions vscode-trace-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,32 +111,44 @@
},
"views": {
"trace-explorer": [
{
"type": "webview",
"id": "traceExplorer.welcomeView",
"name": "Welcome",
"when": "trace-explorer.noExperiments || !traceViewer.serverOn"
},
{
"type": "webview",
"id": "traceExplorer.openedTracesView",
"name": "Opened Traces"
"name": "Opened Traces",
"when": "!trace-explorer.noExperiments && traceViewer.serverOn"
},
{
"type": "webview",
"id": "traceExplorer.availableViews",
"name": "Views",
"when": "!trace-explorer.noExperiments"
"when": "!trace-explorer.noExperiments && traceViewer.serverOn"
},
{
"type": "webview",
"id": "traceExplorer.timeRangeDataView",
"name": "Time Range Data",
"when": "!trace-explorer.noExperiments"
"when": "!trace-explorer.noExperiments && traceViewer.serverOn"
},
{
"type": "webview",
"id": "traceExplorer.itemPropertiesView",
"name": "Item Properties",
"when": "!trace-explorer.noExperiments"
"when": "!trace-explorer.noExperiments && traceViewer.serverOn"
}
]
},
"viewsWelcome": [
{
"view": "activitybar",
"contents": "The Trace Server is currently offline. You can start it by executing the command or pressing the button below. \n [Start Trace Server](command:traceViewer.startServer)",
"when": "traceViewer.serverOn == false"
},
{
"view": "traces",
"contents": "No traces found [learn more](https://www.eclipse.org/tracecompass/).\n[Add traces](command:nodeDependencies.addEntry)"
Expand Down
109 changes: 72 additions & 37 deletions vscode-trace-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { TraceExplorerItemPropertiesProvider } from './trace-explorer/properties
import { TraceExplorerTimeRangeDataProvider } from './trace-explorer/time-range/trace-explorer-time-range-data-webview-provider';
import { TraceExplorerAvailableViewsProvider } from './trace-explorer/available-views/trace-explorer-available-views-webview-provider';
import { TraceExplorerOpenedTracesViewProvider } from './trace-explorer/opened-traces/trace-explorer-opened-traces-webview-provider';
import { TraceExplorerWelcomeViewProvider } from './trace-explorer/welcome-view/trace-explorer-welcome-webview-provider';

import {
fileHandler,
openOverviewHandler,
Expand All @@ -29,14 +31,14 @@ const tspClientProvider = new TspClientProvider(getTspClientUrl(), undefined, ne

export function activate(context: vscode.ExtensionContext): ExternalAPI {
traceLogger = new TraceExtensionLogger('Trace Extension');

vscode.commands.executeCommand('setContext', 'traceViewer.serverOn', true);
const serverStatusBarItemPriority = 1;
const serverStatusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Right,
serverStatusBarItemPriority
);
context.subscriptions.push(serverStatusBarItem);
const serverStatusService = new TraceServerConnectionStatusService(serverStatusBarItem);
const serverStatusService = new TraceServerConnectionStatusService(serverStatusBarItem, isUp);

const tracesProvider = new TraceExplorerOpenedTracesViewProvider(context.extensionUri, serverStatusService);
context.subscriptions.push(
Expand All @@ -58,6 +60,11 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI {
vscode.window.registerWebviewViewProvider(TraceExplorerTimeRangeDataProvider.viewType, timeRangeDataProvider)
);

const welcomeViewProvider = new TraceExplorerWelcomeViewProvider(context.extensionUri, serverStatusService)
context.subscriptions.push(
vscode.window.registerWebviewViewProvider(TraceExplorerWelcomeViewProvider.viewType, welcomeViewProvider)
);

context.subscriptions.push(
vscode.commands.registerCommand('messages.post.propertiespanel', (command: string, data) => {
if (propertiesProvider) {
Expand All @@ -66,17 +73,39 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI {
})
);

const updateUris = async (): Promise<void> => {
const baseUri = vscode.Uri.parse(getTraceServerUrl());
const extUri = await vscode.env.asExternalUri(baseUri);
const extUriString = extUri.toString();

tracesProvider.updateTraceServerUrl(extUriString);
myAnalysisProvider.updateTraceServerUrl(extUriString);
TraceViewerPanel.updateTraceServerUrl(extUriString);
};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@williamsyang-work a question, what if a user executes the command Trace Server: Start (if stopped) manually using the command palette, shouildn't updateUris() be called as well? Maybe when command serverStatus.started is executed? Please let me know.

Copy link
Contributor Author

@williamsyang-work williamsyang-work Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bhufmann I tested starting and stopping the trace server via command palette and it worked as-is for me.
My understanding is: as long as server url remains the same we don't need to update it. The process on that port can stop, start, restart, etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@williamsyang-work When connecting to the remote host and executing the command Trace Server: Start (if stopped) then the server is started, but the port forwarding is not working because updateUris() and hencevscode.asExternalUrl is not executed. Start and stop is still working in this case. I tested that case with a remote running in a virtual machine and I saw it not working.

However, when using the open trace command that starts the server and updateUris() is executed will enable port forwarding for the manual start command.

I think we need to address the manual start case as well.

Copy link
Contributor Author

@williamsyang-work williamsyang-work Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per our discussion updateUris() is now called in the serverStatus.started command. This updates the Trace-Explorer webviews and starts port forwarding.

There seems to be another bug where it shows the server's data accurately, but then changes back to 'No Traces Open: Open Trace' state after some time.

const emitServerStatus = (status: boolean) => {
console.log('Emitting the server status as: ', status);
TraceViewerPanel.setServerStatus(status);
myAnalysisProvider.setServerStatus(status);
tracesProvider.setServerStatus(status);
}

const cancelAllOngoingRequests = () => {
TraceViewerPanel.cancelHttpRequests();
myAnalysisProvider.cancelHttpRequests();
tracesProvider.cancelHttpRequests();
}

const analysisProvider = new AnalysisProvider();
// TODO: For now, a different command opens traces from file explorer. Remove when we have a proper trace finder
const fileOpenHandler = fileHandler(analysisProvider);
context.subscriptions.push(
vscode.commands.registerCommand('traces.openTraceFile', async file => {
await startTraceServerIfAvailable();
if (await isUp()) {
fileOpenHandler(context, file);
}
})
);
context.subscriptions.push(vscode.commands.registerCommand('traces.openTraceFile', async file => {
await startTraceServerIfAvailable();
await updateUris();
if (await isUp()) {
fileOpenHandler(context, file);
}
}));

// Listening to configuration change for the trace server URL
context.subscriptions.push(
Expand All @@ -88,18 +117,10 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI {
updateTspClient();
}

if (e.affectsConfiguration('trace-compass.traceserver.url')) {
const newUrl = getTraceServerUrl();

// Signal the change to the `Opened traces` and `Available views` webview
tracesProvider.updateTraceServerUrl(newUrl);
myAnalysisProvider.updateTraceServerUrl(newUrl);

// Signal the change to all trace panels
TraceViewerPanel.updateTraceServerUrl(newUrl);
}
})
);
if (e.affectsConfiguration('trace-compass.traceserver.url')) {
updateUris();
}
}));

const overViewOpenHandler = openOverviewHandler();

Expand Down Expand Up @@ -152,36 +173,50 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI {
})
);

context.subscriptions.push(
vscode.commands.registerCommand('openedTraces.openTraceFolder', async () => {
await startTraceServerIfAvailable();
if (await isUp()) {
fileOpenHandler(context, undefined);
}
})
);
context.subscriptions.push(vscode.commands.registerCommand('openedTraces.openTraceFolder', async () => {
await startTraceServerIfAvailable();
await updateUris();
if (await isUp()) {
fileOpenHandler(context, undefined);
}
}));

context.subscriptions.push(
vscode.commands.registerCommand('traceViewer.shortcuts', () => {
keyboardShortcutsHandler(context.extensionUri);
})
);

context.subscriptions.push(vscode.commands.registerCommand('serverStatus.started', () => {
serverStatusService.render(true);
emitServerStatus(true);
cancelAllOngoingRequests();
vscode.commands.executeCommand('setContext', 'traceViewer.serverOn', true);
updateUris();
if (tracesProvider) {
tracesProvider.postMessagetoWebview(VSCODE_MESSAGES.TRACE_SERVER_STARTED, undefined);
}
}));

context.subscriptions.push(
vscode.commands.registerCommand('serverStatus.started', () => {
serverStatusService.render(true);
if (tracesProvider) {
tracesProvider.postMessagetoWebview(VSCODE_MESSAGES.TRACE_SERVER_STARTED, undefined);
}
vscode.commands.registerCommand('serverStatus.stopped', () => {
vscode.commands.executeCommand('setContext', 'traceViewer.serverOn', false);
serverStatusService.render(false);
cancelAllOngoingRequests();
emitServerStatus(false);
})
);

context.subscriptions.push(
vscode.commands.registerCommand('serverStatus.stopped', () => {
serverStatusService.render(false);
vscode.commands.registerCommand('traceViewer.startServer', () => {
startTraceServerIfAvailable();
})
);

isUp()
.then(status => vscode.commands.executeCommand('setContext', 'traceViewer.serverOn', status))
.catch(()=> vscode.commands.executeCommand('setContext', 'traceViewer.serverOn', false));

vscode.commands.executeCommand('setContext', 'traceViewer.markerSetsPresent', false);
vscode.commands.executeCommand('setContext', 'traceViewer.markerCategoriesPresent', false);
return traceExtensionAPI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ export class TraceExplorerAvailableViewsProvider implements vscode.WebviewViewPr
this._statusService.render(status);
}
return;
case VSCODE_MESSAGES.WEBVIEW_READY:
// Post the tspTypescriptClient
webviewView.webview.postMessage({
command: VSCODE_MESSAGES.SET_TSP_CLIENT,
data: getTspClientUrl()
});
if (this._selectedExperiment !== undefined) {
signalManager().fireExperimentSelectedSignal(this._selectedExperiment);
}
return;
case VSCODE_MESSAGES.WEBVIEW_READY:
// Post the tspTypescriptClient
webviewView.webview.postMessage({
command: VSCODE_MESSAGES.SET_TSP_CLIENT,
data: getTspClientUrl()
});
if (this._selectedExperiment !== undefined) {
signalManager().fireExperimentSelectedSignal(this._selectedExperiment);
}
return;
case VSCODE_MESSAGES.OUTPUT_ADDED:
if (message.data && message.data.descriptor) {
// FIXME: JSONBig.parse() created bigint if numbers are small.
Expand Down Expand Up @@ -126,6 +126,14 @@ export class TraceExplorerAvailableViewsProvider implements vscode.WebviewViewPr
}
}

public cancelHttpRequests(): void {
this._view?.webview.postMessage({ command: VSCODE_MESSAGES.CANCEL_REQUESTS });
}

public setServerStatus(status: boolean): void {
this._view?.webview.postMessage({ command: VSCODE_MESSAGES.TRACE_SERVER_STATUS, data: status.toString() });
}

/* eslint-disable max-len */
private _getHtmlForWebview(webview: vscode.Webview) {
// Get the local path to main script run in the webview, then convert it to a uri we can use in the webview.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class TraceExplorerOpenedTracesViewProvider implements vscode.WebviewView
// experimentSelectedSignal will update available views widget
signalManager().fireExperimentSelectedSignal(this._selectedExperiment);
}
this._statusService.serverStatus().then(stat => this.setServerStatus(stat));
return;
case VSCODE_MESSAGES.RE_OPEN_TRACE:
if (message.data && message.data.wrapper) {
Expand Down Expand Up @@ -132,15 +133,19 @@ export class TraceExplorerOpenedTracesViewProvider implements vscode.WebviewView
case VSCODE_MESSAGES.OPEN_TRACE:
vscode.commands.executeCommand('openedTraces.openTraceFolder');
return;
case VSCODE_MESSAGES.EXPERIMENT_SELECTED: {
let experiment: Experiment | undefined;
if (message.data && message.data.wrapper) {
experiment = convertSignalExperiment(JSONBig.parse(message.data.wrapper));
} else {
experiment = undefined;
case VSCODE_MESSAGES.EXPERIMENT_SELECTED:
if (true) {
let experiment: Experiment | undefined;
if (message.data && message.data.wrapper) {
experiment = convertSignalExperiment(JSONBig.parse(message.data.wrapper));
} else {
experiment = undefined;
}
signalManager().fireExperimentSelectedSignal(experiment);
return;
}
signalManager().fireExperimentSelectedSignal(experiment);
}
case VSCODE_MESSAGES.START_SERVER:
vscode.commands.executeCommand('traceViewer.startServer');
}
},
undefined,
Expand Down Expand Up @@ -170,6 +175,15 @@ export class TraceExplorerOpenedTracesViewProvider implements vscode.WebviewView
}
}

public cancelHttpRequests(): void {
this._view?.webview.postMessage({ command: VSCODE_MESSAGES.CANCEL_REQUESTS });
}

public setServerStatus(status: boolean): void {
console.log(`Opened Traces - The server is ${status}`);
this?._view?.webview.postMessage({ command: VSCODE_MESSAGES.TRACE_SERVER_STATUS, data: status.toString() });
}

/* eslint-disable max-len */
private _getHtmlForWebview(webview: vscode.Webview) {
// Get the local path to main script run in the webview, then convert it to a uri we can use in the webview.
Expand Down
Loading