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

Add Heartbeat #4

Merged
merged 17 commits into from
Jul 15, 2022
Merged

Add Heartbeat #4

merged 17 commits into from
Jul 15, 2022

Conversation

jeanp413
Copy link
Member

@jeanp413 jeanp413 commented Jun 29, 2022

Move heartbeat to gitpod-desktop from gitpod-remote

How to test:

cd dev/gpctl
go build
./gpctl workspaces last-heartbeat <instance_id>
  • Check only one close heartbeat is send

Not sure how to trigger ssh reconnection 🤔

Maybe use sudo killall sshd, but window closed after sshd terminate, not sure if it works

@jeanp413
Copy link
Member Author

cc @akosyakov

@akosyakov
Copy link
Member

Not sure how to trigger ssh reconnection 🤔

I think you don't need to care here. The test case will be:

  • observing that heartbeating is happening while window is opened and workspace is running
  • if workspace is not running heartbeating should be stopped
  • if window is closed close heartbeat should be send immediately, it should be preset in analytics as well

Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

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

It looks like a right direction, but we don't respect workspace lifecycle yet.

src/extension.ts Outdated Show resolved Hide resolved
src/heartbeat.ts Show resolved Hide resolved
src/remoteConnector.ts Outdated Show resolved Hide resolved
src/heartbeat.ts Outdated Show resolved Hide resolved
src/remoteConnector.ts Outdated Show resolved Hide resolved
src/heartbeat.ts Outdated Show resolved Hide resolved
src/remoteConnector.ts Outdated Show resolved Hide resolved
src/remoteConnector.ts Outdated Show resolved Hide resolved
@akosyakov
Copy link
Member

I opened gitpod-io/gitpod#11021 since I needed to rerun werft job.

src/remoteConnector.ts Outdated Show resolved Hide resolved
src/heartbeat.ts Outdated Show resolved Hide resolved
src/remoteConnector.ts Outdated Show resolved Hide resolved
@akosyakov
Copy link
Member

It looks great, only tracking of workspace running state is missing that we don't send events if workspace is not running.

src/heartbeat.ts Outdated Show resolved Hide resolved
src/heartbeat.ts Outdated Show resolved Hide resolved
src/heartbeat.ts Outdated Show resolved Hide resolved
src/remoteConnector.ts Outdated Show resolved Hide resolved
@akosyakov
Copy link
Member

It looks almost there, some tweak are needed for heatbeating code. @mustard-mh @andreafalzetti since I'm away till next Monday, could you help to finish with testing after another round of changes? 🙏

@jeanp413 jeanp413 marked this pull request as ready for review July 9, 2022 02:23
@jeanp413 jeanp413 requested a review from mustard-mh July 9, 2022 02:23
@jeanp413 jeanp413 changed the title WIP: heartbeat Add Heartbeat Jul 9, 2022
src/remoteConnector.ts Outdated Show resolved Hide resolved
@akosyakov
Copy link
Member

I think logic looks well. Could someone help with testing and giving another look at it? 🙏 cc @mustard-mh @andreafalzetti

@mustard-mh
Copy link
Contributor

Tested, and it works well.

But extension requests auth twice when I'm testing. I'll update How to Test section later

gitpod /workspace/gitpod/dev/gpctl (jp/heartbeat-test) $ ./gpctl workspaces last-heartbeat 7fe830ee-af57-49bb-8c6d-91ad81cfc705
2022-07-11T08:54:24.876441322Z
gitpod /workspace/gitpod/dev/gpctl (jp/heartbeat-test) $ ./gpctl workspaces last-heartbeat 7fe830ee-af57-49bb-8c6d-91ad81cfc705
2022-07-11T08:56:18.843874055Z
gitpod /workspace/gitpod/dev/gpctl (jp/heartbeat-test) $ ./gpctl workspaces last-heartbeat 7fe830ee-af57-49bb-8c6d-91ad81cfc705
2022-07-11T08:56:18.843874055Z
gitpod /workspace/gitpod/dev/gpctl (jp/heartbeat-test) $ ./gpctl workspaces last-heartbeat 7fe830ee-af57-49bb-8c6d-91ad81cfc705
2022-07-11T08:56:48.681459343Z

@mustard-mh
Copy link
Contributor

After exec

sudo killall sshd

The test VSCode Desktop window closed, don't know if reconnect works or not, since next time I open it, server maybe another one...

src/internalApi.ts Outdated Show resolved Hide resolved
// Check for gitpod remote extension version to avoid sending heartbeat in both extensions at the same time
const gitpodRemoteVersion = await getGitpodRemoteVersion();
if (gitpodRemoteVersion && semver.gte(gitpodRemoteVersion, '0.0.40')) {
const session = await this.getGitpodSession(connectionInfo.gitpodHost);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use same session above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, vscode takes care of returning the same session if the scopes are the same, also this code will execute in a new window/after reload when it's connecting to a remote workspace, and the previous code only gets executed when opening a callback uri

Copy link
Contributor

@mustard-mh mustard-mh left a comment

Choose a reason for hiding this comment

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

code LGTM

Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

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

🚀

@jeanp413
Copy link
Member Author

Could you do another test 🙏 I updated the test steps
Changed it so gitpod-remote exposes a command to cancel the heartbeat and if this command returns successful then we start heartbeat on gitpod-desktop, this is safer as it could be possible to end up with many version combinations of both extensions as users could not always update both extensions at the same time
Also added a new telemetry event vscode_desktop_heartbeat_state so we can track if all new connections always activate the heartbeat in gitpod-desktop, If we have 100% rate and all events come from latest extension versions then we can remove the heartbeat code in gitpod-remote and also this telemetry event

@mustard-mh
Copy link
Contributor

We can disable computer's network to test reconnect. 😄

@akosyakov
Copy link
Member

Also added a new telemetry event vscode_desktop_heartbeat_state so we can track if all new connections always activate the heartbeat in gitpod-desktop, If we have 100% rate and all events come from latest extension versions then we can remove the heartbeat code in gitpod-remote and also this telemetry event

sounds good, please update the tracking plan as usual 🙏

await this.context.globalState.update(`${RemoteConnector.SSH_DEST_KEY}${sshDestStr}`, { ...connectionInfo, isFirstConnection: false });

// Check for gitpod remote extension version to avoid sending heartbeat in both extensions at the same time
const isGitpodRemoteHeartbeatCancelled = await cancelGitpodRemoteHeartbeat();
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about it. We see that remote-ssh-extension fails to install right now very often. If we do it then heartbeat is missing.

@andreafalzetti
Copy link

andreafalzetti commented Jul 12, 2022

I am having issues to connect to the workspace. Any idea? 🤔

Screenshot 2022-07-12 at 13 38 07

[Info  - 18:41:40.325] gitpod.gitpod-desktop/0.0.40 (21.5.0 darwin arm64) vscode/1.69.0 (Visual Studio Code)
[Info  - 18:41:40.456] Reading sessions from keychain...
[Info  - 18:41:40.458] Getting sessions for function:accessCodeSyncStorage,function:getLoggedInUser,resource:default...
[Trace  - 18:41:40.471] Token acquired from secret storage.
[Info  - 18:41:40.471] Got stored sessions!
[Trace  - 18:41:40.471] Read the following session from the keychain with the following scopes: function:getLoggedInUser function:getOwnerToken function:getWorkspace resource:default
[Info  - 18:41:40.471] Got 1 verified sessions.
[Info  - 18:41:40.471] Got 0 sessions for function:accessCodeSyncStorage,function:getLoggedInUser,resource:default...
[Info  - 18:41:51.320] Opening Gitpod workspace
vscode://gitpod.gitpod-desktop/workspace/gitpod-experiments-a?%7B%22instanceId%22%3A%22ec8fc343-ae4d-4e44-b912-7ff4db88089b%22%2C%22workspaceId%22%3A%22andreafalze-gitpodexper-q2nellczhu0%22%2C%22gitpodHost%22%3A%22https%3A%2F%2Fjp-heartbeat-test.preview.gitpod-dev.com%22%7D
[Info  - 18:41:51.339] Getting sessions for function:getLoggedInUser,function:getOwnerToken,function:getWorkspace,resource:default...
[Info  - 18:41:51.339] Got 1 sessions for function:getLoggedInUser,function:getOwnerToken,function:getWorkspace,resource:default...
[Error  - 18:42:13.899] SSH test connection error:
Error: Timed out while waiting for handshake
    at Timeout._onTimeout (/Users/andrea/dev/gitpod/gitpod-vscode-desktop/node_modules/ssh2/lib/client.js:1014:23)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)

@jeanp413
Copy link
Member Author

You need to create a new prev env, the one I posted got merged

@jeanp413 jeanp413 merged commit 39353b7 into master Jul 15, 2022
@jeanp413 jeanp413 deleted the jp/heartbeat branch July 15, 2022 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants