GoogleCloudPlatform / cloud-code-intellij

Plugin to support the Google Cloud Platform in IntelliJ IDEA - Docs and Issues Repository
Apache License 2.0
319 stars 59 forks source link

Allow Controlling Port Forwarding #3110

Open anthonyalayo opened 1 year ago

anthonyalayo commented 1 year ago

I have a spring boot java service using cloud code. I want to debug the server start sequence, but there is no way to do it.

Scenario 1

  1. Enable deployment checks on the cloud code run configuration
  2. Set the JVM arguments for debugging to not wait for the debug connection
  3. The port forwarding will be established after the server start sequence

Scenario 2

  1. Disable deployment checks on the cloud code run configuration
  2. Set the JVM arguments for debugging to wait for the debug connection
  3. The kubectl port forwarding will be attempted before the service is ready, and it will fail
  4. The server will start without any debugging capability

At present, how can I debug startup code in a server that occurs before readiness/liveness probes in cloud code?

If there was a button, or a delay, that I could configure for port forwarding to kick in, this would be solved. I could add suspend=y for the java debug agent, and have my port forwarding happen after X seconds.

Expected Behavior

I can control when port forwarding URLs occurs when using "Develop on Kubernetes".

Actual Behavior

I can not control when port forwarding URLs occurs when using "Develop on Kubernetes".

Additional Information

etanshaul commented 1 year ago

@anthonyalayo thanks for the feature request. we will consider and triage this.

anthonyalayo commented 1 year ago

Thank you! I updated the description for clarity.

etanshaul commented 1 year ago

Hi @anthonyalayo to see if you can get unblocked in the interim:

In scenario 2, disabling deployment checks as well as setting suspend=y were not sufficient to debug start up code? It seemed to work in my tests (using the Cloud Code supplied Java hello-world sample in the New Project wizard - https://github.com/GoogleCloudPlatform/cloud-code-samples/blob/v1/java/java-hello-world/kubernetes-manifests/hello.deployment.yaml#L26).

Of course port forwarding failed. But, I was then able to run kubectl port-forward [my-pod] 8080:8080 and debug the service itself. Not ideal, but at the moment Cloud Code doesn't have configurable port-forwarding as you observed. Also ideally Skaffold itself would support suspending (https://github.com/GoogleContainerTools/skaffold/issues/4870).

anthonyalayo commented 1 year ago

Of course port forwarding failed. But, I was then able to run kubectl port-forward [my-pod] 8080:8080 and debug the service itself. Not ideal, but at the moment Cloud Code doesn't have configurable port-forwarding as you observed.

I see, you manually port forwarded in a terminal after it failed. Was the IDE able to pick that up and hit breakpoints?

Also ideally Skaffold itself would support suspending (https://github.com/GoogleContainerTools/skaffold/issues/4870).

Agreed, thanks for pointing out that ticket. Either or would solve the problem here. Considering that the linked issue was opened over 2 years ago, I have less confidence that Skaffold support would get implemented.

etanshaul commented 1 year ago

Was the IDE able to pick that up and hit breakpoints?

yes it was.

I don’t know that there is a great solution here without Skaffold involvement. Skaffold controls the port-forwarding as well as the debug instrumentation (so making “suspend” configurable will require a change there too). I will check with them if any progress has been made.

anthonyalayo commented 1 year ago

Thank you!