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

Auto-forward all workspace open ports when using Latest JetBrains IDEs #11081

Merged
merged 1 commit into from
Aug 9, 2022

Conversation

felladrin
Copy link
Contributor

@felladrin felladrin commented Jul 1, 2022

Description

Auto-forward all workspace open ports when using Latest JetBrains IDEs.

Changes included:

  • Adds a GitpodPortsService, which is used by both Stable and Latest versions of the Backend Plugin.
  • Adds a GitpodPortForwardingService, which affects only Latest (Unstable) Version of JetBrains IDEs, and controls the auto-forwarding of all ports.
  • Adds a GitpodPortsServiceTest with a function unit test. It can be tested via IDE UI or command line [1].
  • Updates GitpodTerminalService, as we moved the implementation to forward all ports to GitpodPortForwardingService.
  • Updates GitpodClientProjectSessionTracker, which displays notifications about ports that have just been opened, to have the correct localhost URL if the port is being forwarded. (A few other small changes were made on that file, which were suggestions from IntelliJ to improve the code).
  • Updates GitpodCLIService to rewrite URLs coming from gp preview, when the URL is pointing to localhost, for pointing to the correct forwarded port on the client.
    • For example, a user starts a service on port 3000, which is automatically forwarded from the server to the user machine. But the user had port 3000 already occupied by some other process. What JetBrains IDE does, in this case, is looking for the next free port (3001, for example). So whenever the user runs gp preview http://127.0.0.1:3000, it should open http://127.0.0.1:3001 on the browser.
    • Note: It currently doesn't happen because of this issue, which will be solved later. So this shouldn't be tested in this PR. But the class is ready for when the issue is fixed.
  • Update of gradle-intellij-plugin to v1.8.0, which adds support for JetBrains Runtime 2022.2 directories layout.

Note: We confirmed with JetBrains that the host used for Forwarded Ports on the client is 127.0.0.1.

Related Issue(s)

Resolves #10783

How to test

  • Open Preferences on the Preview Environment of this PR, select any JetBrains IDE, and mark Latest Release to use the EAP version of the IDE.
  • Start any workspace, and once connected, execute any HTTP server from any terminal (can be a terminal used by a Gitpod Task or a new terminal created via the IDE UI). (You can run lama.sh for example: sh <(curl lama.sh) -p 8080)
  • Click on the "Open Browser" link from the notification and confirm it opens http://127.0.0.1:<forwarded_service_port>/ on your browser.
    image

Note:

  • If the port is already occupied by another process, JetBrains IDE will look for some random open port. (This random port unfortunately isn't displayed anywhere at this moment. It will be solved in a follow-up PR.)
  • The links from notifications about open ports should point to localhost only when using the Latest (Unstable) version of the IDE. When using the Stable version, links will point to the remote URL, as usual.
  • This PR should be affecting just the toast notification, not the dialog [1]. The dialog will be resolved in another PR.

Release Notes

All open ports from the workspace are automatically forwarded when using Latest JetBrains IDEs.

Documentation

None.

Werft options:

  • /werft with-preview

@felladrin felladrin self-assigned this Jul 1, 2022
@gitpod-io gitpod-io deleted a comment from werft-gitpod-dev-com bot Jul 1, 2022
@felladrin felladrin marked this pull request as ready for review July 4, 2022 12:04
@felladrin felladrin requested a review from a team July 4, 2022 12:04
@felladrin felladrin force-pushed the felladrin/jb-auto-forward-all-ports-10783 branch 4 times, most recently from c15b665 to 1535f54 Compare July 8, 2022 16:42
@akosyakov
Copy link
Member

akosyakov commented Jul 12, 2022

It is not enough to forward. We should make use of them, in UI elements like notifications. Could you review please the backend for such places and there we use port URL translate them to localhost host if available?

@felladrin
Copy link
Contributor Author

It is not enough to forward. We should make use of them, in UI elements like notifications. Could you review please the backend for such places and there we use port URL translate them to localhost host if available?

Understood. In this case, we'll see some files being duplicated (between "stable" and "latest" folders/packages), as port forwarding only works on "latest".

I'll leave this PR as a Draft while I update it.

@felladrin felladrin marked this pull request as draft July 12, 2022 17:29
@felladrin felladrin force-pushed the felladrin/jb-auto-forward-all-ports-10783 branch 3 times, most recently from 8d46cfa to 54943c3 Compare July 15, 2022 12:43
@felladrin felladrin marked this pull request as ready for review July 15, 2022 14:21
@felladrin
Copy link
Contributor Author

Updated! It's ready for review again!

@andreafalzetti andreafalzetti force-pushed the felladrin/jb-auto-forward-all-ports-10783 branch from 1ca27f2 to e88a000 Compare August 8, 2022 13:59
@felladrin felladrin force-pushed the felladrin/jb-auto-forward-all-ports-10783 branch from e88a000 to 5994e31 Compare August 8, 2022 15:23
@felladrin felladrin removed the request for review from a team August 8, 2022 15:24
@felladrin felladrin removed the request for review from akosyakov August 8, 2022 15:43
@felladrin felladrin removed team: webapp Issue belongs to the WebApp team team: workspace Issue belongs to the Workspace team team: devx labels Aug 9, 2022
@andreafalzetti
Copy link
Contributor

andreafalzetti commented Aug 9, 2022

/werft run with-clean-slate-deployment=true

👍 started the job as gitpod-build-felladrin-jb-auto-forward-all-ports-10783.36
(with .werft/ from main)

@andreafalzetti
Copy link
Contributor

andreafalzetti commented Aug 9, 2022

I've tested a couple of times but I always get the workspace URL instead of localhost. Am I doing something wrong?

  1. Started a workspace in https://felladrin-d4177edc98.preview.gitpod-dev.com/workspaces
  2. Selected IntelliJ Latest as preferred IDE

I have the latest JetBrains Gateway installed, with the latest gitpod plugin from the marketplace.
Screenshot 2022-08-09 at 11 57 44
Screenshot 2022-08-09 at 11 58 13
Screenshot 2022-08-09 at 11 58 27

Any idea, @felladrin?

@felladrin
Copy link
Contributor Author

I've tested a couple of times but I always get the workspace URL instead of localhost. Am I doing something wrong?

Ah, well observed! But that's ok :) It's coming from gp preview command, so we decided we'll check it in a separate PR [1][2].

@andreafalzetti
Copy link
Contributor

andreafalzetti commented Aug 9, 2022

I've tested a couple of times but I always get the workspace URL instead of localhost. Am I doing something wrong?

Ah, well observed! But that's ok :) It's coming from gp preview command, so we decided we'll check it in a separate PR [1][2].

when I click on the “Open Browser” link inside the toast notification, it opens the dialog to confirm, where the URL is visible, and the URL is the full workspace, even after confirm, it opens the full URL (Not localhost), so I am still confused.

@felladrin
Copy link
Contributor Author

felladrin commented Aug 9, 2022

True 🤔 Seems the auto-forwarding stopped working. Marking the PR as Draft while I fix it.

For the record, here's the error log:

2022-08-09 14:19:02,738 [   4730] SEVERE - #i.g.j.r.l.GitpodPortForwardingService - gitpod: Got an error while trying to get ports list from Supervisor. Going to try again in a second.
java.util.concurrent.ExecutionException: io.grpc.StatusRuntimeException: CANCELLED: Failed to read message.
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073)
	at io.gitpod.jetbrains.remote.latest.GitpodPortForwardingService.observePortsListWhileProjectIsOpen$lambda-0(GitpodPortForwardingService.kt:47)

@felladrin felladrin marked this pull request as draft August 9, 2022 14:23
@felladrin felladrin force-pushed the felladrin/jb-auto-forward-all-ports-10783 branch from 5994e31 to 3e940b8 Compare August 9, 2022 16:27
@felladrin felladrin force-pushed the felladrin/jb-auto-forward-all-ports-10783 branch from 3e940b8 to 0dfbc7d Compare August 9, 2022 17:01
@felladrin
Copy link
Contributor Author

Fixed by wrapping the handling of the status of the ports from GRPC in application.invokeLater to execute actions with PortForwardingManager in the UI thread. Without it, it was being executed on the same background thread as the GRPC listener. (More Info)

override fun onNext(response: Status.PortsStatusResponse) {
application.invokeLater { handlePortStatusResponse(response) }
}

@felladrin
Copy link
Contributor Author

Setting it as Ready for Review again :)

And just to rectify what I said before:
When clicking "Open browser" it will indeed show the dialog box with the localhost URL (which is a different dialog that is displayed when we run gp preview $(gp url 3000) on terminal):

image

@felladrin felladrin marked this pull request as ready for review August 9, 2022 17:34
Copy link
Contributor

@andreafalzetti andreafalzetti left a comment

Choose a reason for hiding this comment

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

LGTM, tested and works as expected 🍪

@roboquat roboquat merged commit d0627ab into main Aug 9, 2022
@roboquat roboquat deleted the felladrin/jb-auto-forward-all-ports-10783 branch August 9, 2022 18:08
@roboquat roboquat added deployed: IDE IDE change is running in production deployed Change is completely running in production labels Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: IDE IDE change is running in production deployed Change is completely running in production editor: jetbrains release-note size/XL team: IDE
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[jb] auto forward all ports
7 participants