Skip to content

Commit

Permalink
Collect lssh logs in connection window
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanp413 committed Jul 4, 2024
1 parent 22e1e96 commit 84f1773
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Gitpod",
"description": "Gitpod Support",
"publisher": "gitpod",
"version": "0.0.167",
"version": "0.0.168",
"license": "MIT",
"icon": "resources/gitpod.png",
"repository": {
Expand Down
9 changes: 6 additions & 3 deletions src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface IFile {

export class ExportLogsCommand implements Command {
readonly id = 'gitpod.exportLogs';
static latestLSSHHost: string | undefined;

constructor(
private readonly context: vscode.ExtensionContext,
Expand Down Expand Up @@ -70,12 +71,14 @@ export class ExportLogsCommand implements Command {
}

private getLSSHLog(): string | undefined {
let lsshHostname: string | undefined;
const sshDestStr = getGitpodRemoteWindowConnectionInfo(this.context)?.sshDestStr;
if (sshDestStr) {
const sshDest = SSHDestination.fromRemoteSSHString(sshDestStr);
return path.join(os.tmpdir(), `lssh-${sshDest.hostname}.log`);
lsshHostname = SSHDestination.fromRemoteSSHString(sshDestStr).hostname;
} else if (ExportLogsCommand.latestLSSHHost) {
lsshHostname = ExportLogsCommand.latestLSSHHost;
}
return undefined;
return lsshHostname ? path.join(os.tmpdir(), `lssh-${lsshHostname}.log`) : undefined;
}

async exportLogs() {
Expand Down
5 changes: 5 additions & 0 deletions src/commands/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { IRemoteService } from '../services/remoteService';
import { WrapError } from '../common/utils';
import { getOpenSSHVersion, testSSHConnection as testLocalSSHConnection } from '../ssh/nativeSSH';
import { IExperimentsService } from '../experiments';
import { ExportLogsCommand } from './logs';

function getCommandName(command: string) {
return command.replace('gitpod.workspaces.', '').replace(/(?:_inline|_context)(?:@\d)?$/, '');
Expand Down Expand Up @@ -133,6 +134,8 @@ export class ConnectInNewWindowCommand implements Command {
await testLocalSSHConnection(localSSHDestination.user!, localSSHDestination.hostname);
localSSHTestSuccess = true;
} catch (e) {
ExportLogsCommand.latestLSSHHost = localSSHDestination?.hostname;

this.telemetryService.sendTelemetryException(
new WrapError('Local SSH: failed to connect to workspace', e),
{
Expand Down Expand Up @@ -305,6 +308,8 @@ export class ConnectInCurrentWindowCommand implements Command {
await testLocalSSHConnection(localSSHDestination.user!, localSSHDestination.hostname);
localSSHTestSuccess = true;
} catch (e) {
ExportLogsCommand.latestLSSHHost = localSSHDestination?.hostname;

this.telemetryService.sendTelemetryException(
new WrapError('Local SSH: failed to connect to workspace', e),
{
Expand Down
7 changes: 5 additions & 2 deletions src/remoteConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { ILogService } from './services/logService';
import { IHostService } from './services/hostService';
import { WrapError, getServiceURL } from './common/utils';
import { IRemoteService } from './services/remoteService';
import { ExportLogsCommand } from './commands/logs';

export class RemoteConnector extends Disposable {

Expand All @@ -44,8 +45,8 @@ export class RemoteConnector extends Disposable {
super();

this._register(this.hostService.onDidChangeHost(async () => {
await this.updateSSHRemotePlatform()
}))
await this.updateSSHRemotePlatform();
}));
}

private async getWorkspaceSSHDestination({ workspaceId, gitpodHost, debugWorkspace }: SSHConnectionParams): Promise<{ destination: SSHDestination; password?: string }> {
Expand Down Expand Up @@ -278,6 +279,8 @@ export class RemoteConnector extends Disposable {

this.telemetryService.sendUserFlowStatus('connected', localSSHFlow);
} catch (e) {
ExportLogsCommand.latestLSSHHost = localSSHDestination?.hostname;

const reason = e?.code ?? (e?.name && e.name !== 'Error' ? e.name : 'Unknown');
this.telemetryService.sendTelemetryException(new WrapError('Local SSH: failed to connect to workspace', e), { ...localSSHFlow });
this.telemetryService.sendUserFlowStatus('failed', { ...localSSHFlow, reason });
Expand Down

0 comments on commit 84f1773

Please sign in to comment.