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

Allow configuring Project Manager server host and port #6774

Merged
merged 26 commits into from
Aug 25, 2023

Conversation

somebody1234
Copy link
Contributor

@somebody1234 somebody1234 commented May 19, 2023

Pull Request Description

  • Closes [/127.0.0.1:30535] Address in use #6730
    • Changes config to allow environment variables to override server host and port
    • Adds port scanning to Electron app to ensure the PM is started at a free port

Important Notes

  • SERVER_PORT=abcd enso.AppImage does NOT work. It would not be difficult to implement, but it probably needs discussion on how exactly it should be implemented - for example, SERVER_PORT is quite a generic name, should the Electron app pass though something like ENSO_PM_SERVER_PORT to the PM as SERVER_PORT instead?

⚠️ Port scanning is only implemented in the JS frontend. It is not implemented:

  • In Scala, because the JS/Rust code calling it needs to know the port as well. There shouldn't be any problems with adding port scanning though, if that's desired

  • In Rust, because I'm not sure parsing the host and port from a string is a good idea.

    • (This also applies to JS, but it must work in JS, and port scanning is already a dependency there so it's quite a bit easier)
  • QA will need a new PM (sbt buildProjectManagerDistribution or ./run backend sbt -> buildProjectManagerDistribution), and the path must be supplied as: -engine.project-manager-path=path/to/new/pm/here

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

@somebody1234
Copy link
Contributor Author

somebody1234 commented May 21, 2023

i don't know whether this needs tests on the scala side

@somebody1234 somebody1234 force-pushed the wip/sb/project-manager-host-port branch from 8ee8af1 to 92c736a Compare May 21, 2023 22:28
@somebody1234
Copy link
Contributor Author

So it seems like running two instances side-by-side by the same user should be unsupported - the Project Managers seem to want to acquire locks on the same files for compilation. So, when testing, instead a dummy HTTP server should be run on port 30535

@PabloBuchu PabloBuchu self-assigned this Jun 20, 2023
@xvcgreg
Copy link

xvcgreg commented Jun 26, 2023

@PabloBuchu what's the status of this task?

@somebody1234
Copy link
Contributor Author

closing until this becomes an issue again

@somebody1234 somebody1234 marked this pull request as ready for review August 9, 2023 06:44
@somebody1234
Copy link
Contributor Author

somebody1234 commented Aug 9, 2023

i've done some basic testing only - by using ide watch with a http server already running at port 30535 (which makes it start the PM at port 30536):

  • ✔️ PM is started at port 30536
  • ✔️ opening new empty project works on local backend
  • ✔️ opening new project from template works on local backend
  • ✔️ opening project works on remote (cloud) backend
  • ✔️ manually running PM at 30535 fails when there is another application running on that port
  • ✔️ manually running PM at 30535 succeeds when there is no application running on that port
  • ✔️ manually running PM without explicit port, defaults to 30535
  • ✔️ http://localhost:8080/?engine.projectManagerUrl=ws://127.0.0.1:30535 errors when there is no WebSocket server at port 30535
  • ✔️ http://localhost:8080/?engine.projectManagerUrl=ws://127.0.0.1:30536 doesn't error, and properly lists projects

config.server.host,
config.server.port
processConfig.serverHost.getOrElse(config.server.host),
processConfig.serverPort.getOrElse(config.server.port)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add overrides in the config (instead or in addition to the cli flags)

host = ${project-manager.network.interface}
port = 30535

The same way it is done for the network

network {
interface = "127.0.0.1"
interface = ${?NETWORK_INTERFACE}
min-port = 49152
min-port = ${?NETWORK_MIN_PORT}
max-port = 65535
max-port = ${?NETWORK_MAX_PORT}
}

i.e the line

   interface = ${?NETWORK_INTERFACE}

defines override of the interface value by the NETWORK_INTERFACE environment variable.

This way you can override config by providing the necessary environment variables without the need of adding extra CLI parameters.

@somebody1234
Copy link
Contributor Author

somebody1234 commented Aug 9, 2023

oh oops

(edit: the changes aren't finished, and the electron app will need to switch to provide envrironment variables instead, so the latest commit does NOT work)

@somebody1234 somebody1234 force-pushed the wip/sb/project-manager-host-port branch from 14f4542 to e350ced Compare August 9, 2023 07:21
@somebody1234 somebody1234 changed the title Add server host and port command-line arguments to Project Manager Allow configuring Project Manager server host and port Aug 9, 2023
@somebody1234 somebody1234 requested a review from 4e6 August 9, 2023 07:36
@somebody1234
Copy link
Contributor Author

so it seems like all the CLI changes were unnecessary - not a bad thing though, since it means fewer things could go wrong

@somebody1234
Copy link
Contributor Author

i've done basic re-testing so there shouldn't be any major problems

Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

As far as I can say this is the right approach and I am looking forward to use it.

@@ -51,7 +54,7 @@ project-manager {

storage {
projects-root = ${user.home}/enso
projects-root=${?PROJECTS_ROOT}
projects-root = ${?PROJECTS_ROOT}
Copy link
Member

Choose a reason for hiding this comment

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

I cannot claim to be an expert on Scala and its .conf file. However I believe that the ${?SERVER_HOST} definition reads value from environment property, if it is set.

I am surprised we need so little changes in the project-manager code!

// eslint-disable-next-line @typescript-eslint/naming-convention
SERVER_HOST: this.projectManagerHost,
// eslint-disable-next-line @typescript-eslint/naming-convention
SERVER_PORT: `${this.projectManagerPort}`,
Copy link
Member

Choose a reason for hiding this comment

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

This code prepares the SERVER_HOST and SERVER_PORT environment variables for the project-manager.

const binPath = pathOrPanic(args)
return await execFile(binPath, processArgs)
return await execFile(binPath, processArgs, { env })
Copy link
Member

Choose a reason for hiding this comment

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

Here the environment variables are passed to the project-manager process.

@somebody1234
Copy link
Contributor Author

somebody1234 commented Aug 18, 2023

@PabloBuchu this should be QAd (and code reviewed) at some point too btw

@PabloBuchu
Copy link
Contributor

just tried build and run normally and it is trowing errors

Screenshot 2023-08-22 at 10 03 52 Screenshot 2023-08-22 at 10 04 02

@JaroslavTulach @4e6 could you do a QA of the part with the PM port?

@somebody1234
Copy link
Contributor Author

weird, i thought MutuallyExclusiveOptions wouldn't be an issue after being fixed elsewhere... maybe something related to the project manager is staying in the URL?

i did change the logic that decides whether to try loading index.js.gz in the fix for showLogs, i guess it still always needs to history.replaceState(null, '', new URL('.', originalUrl)) when opening cloud projects though

if (supportsLocalBackend) {
await runNewProject()
} else {
if (!initialized) {
await Promise.all([
load.loadStyle(`${assetsRoot}style.css`),
load.loadScript(`${assetsRoot}index.js.gz`),
])
setInitialized(true)
}
const originalUrl = window.location.href
// The URL query contains commandline options when running in the desktop,
// which will break the entrypoint for opening a fresh IDE instance.
history.replaceState(null, '', new URL('.', originalUrl))
await runNewProject()
// Restore original URL so that initialization works correctly on refresh.
history.replaceState(null, '', originalUrl)
}

@somebody1234
Copy link
Contributor Author

pushed a commit that may fix it, unable to test due to issues with linux PM bundle

@4e6
Copy link
Contributor

4e6 commented Aug 22, 2023

I did the QA. It seems to work on my Linux machine

  • Started the project manager on a custom port env SERVER_PORT=30536 java -jar $JAVA_OPTS project-manager.jar -vv and then connected to it from the browser http://localhost:8080/?authentication=false&engine.projectManagerUrl=ws://127.0.0.1:30536
  • Built the IDE distribution with ./run --skip-version-check ide build --skip-wasm-opt and started it with ./dist/ide/enso-linux-2023.2.1-dev.AppImage -authentication=false --debug.dev-tools without errors in the console.

@PabloBuchu PabloBuchu added the CI: Ready to merge This PR is eligible for automatic merge label Aug 25, 2023
@mergify mergify bot merged commit aa2f72c into develop Aug 25, 2023
27 checks passed
@mergify mergify bot deleted the wip/sb/project-manager-host-port branch August 25, 2023 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[/127.0.0.1:30535] Address in use
6 participants