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

odo dev --debug #5690

Conversation

feloy
Copy link
Contributor

@feloy feloy commented Apr 25, 2022

What type of PR is this:

/kind feature

What does this PR do / why we need it:

Which issue(s) this PR fixes:

Fixes #5583

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:

@netlify
Copy link

netlify bot commented Apr 25, 2022

Deploy Preview for odo-docusaurus-preview canceled.

Name Link
🔨 Latest commit e755f6b
🔍 Latest deploy log https://app.netlify.com/sites/odo-docusaurus-preview/deploys/6267d4eed9a58d0008829422

@openshift-ci openshift-ci bot added the kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation label Apr 25, 2022
@openshift-ci openshift-ci bot requested review from dharmit and rm3l April 25, 2022 11:23
@feloy feloy mentioned this pull request Apr 25, 2022
3 tasks
@odo-robot
Copy link

odo-robot bot commented Apr 25, 2022

Unit Tests on commit a372b9e finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Apr 25, 2022

Windows Tests (OCP) on commit a372b9e finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Apr 25, 2022

Kubernetes Tests on commit a372b9e finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Apr 25, 2022

OpenShift Tests on commit a372b9e finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Apr 25, 2022

Validate Tests on commit a372b9e finished successfully.
View logs: TXT HTML

pkg/odo/cli/dev/dev.go Outdated Show resolved Hide resolved
@feloy feloy force-pushed the feature-5583/odo-debug-only-bis branch from dfc7e66 to db39bec Compare April 26, 2022 07:03
@feloy feloy requested a review from rm3l April 26, 2022 07:03
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Apr 26, 2022
pkg/odo/cli/dev/dev.go Outdated Show resolved Hide resolved
pkg/odo/cli/dev/dev.go Outdated Show resolved Hide resolved
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Apr 26, 2022
@feloy feloy requested a review from dharmit April 26, 2022 11:06
@feloy feloy force-pushed the feature-5583/odo-debug-only-bis branch from da09c92 to d08dfba Compare April 26, 2022 11:07
@feloy feloy force-pushed the feature-5583/odo-debug-only-bis branch from d08dfba to e755f6b Compare April 26, 2022 11:18
@sonarcloud
Copy link

sonarcloud bot commented Apr 26, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@dharmit
Copy link
Member

dharmit commented Apr 26, 2022

@feloy in the past when we were working on debug mode, we used to consider testing things using VS Code launch.json and connecting to the port on which the app's debug mode port is listening.

For this PR, I downloaded the devfile in the tests of this PR, but can't really connect to it. Or, maybe, VS Code is connecting to it, but I don't know what to do. Also, I have never worked with websockets myself, so maybe I'm doing it completely wrong.

Do you think you can share the steps you followed to test the debug mode yourself?

I spent some time on it, but still feel dumb about this thing (how to test debug mode functionality.)

@feloy
Copy link
Contributor Author

feloy commented Apr 26, 2022

@feloy in the past when we were working on debug mode, we used to consider testing things using VS Code launch.json and connecting to the port on which the app's debug mode port is listening.

For this PR, I downloaded the devfile in the tests of this PR, but can't really connect to it. Or, maybe, VS Code is connecting to it, but I don't know what to do. Also, I have never worked with websockets myself, so maybe I'm doing it completely wrong.

Do you think you can share the steps you followed to test the debug mode yourself?

I spent some time on it, but still feel dumb about this thing (how to test debug mode functionality.)

@dharmit It should be the exact same way as with odo v2. If you follow the steps described in this blog post (Debugging the micro-service), it should work: https://dev.to/feloy/odo-a-tool-to-simplify-development-on-kubernetes-5c9a

To test with the files used in the integration test, you can get the launch.json from the blog post, then run a Debug session and set a Breakpoint where a request is replied (on the res.send('Hello from Node.js Starter Application!'); for example). Then you execute a request on your app endpoint (curl 127.0.0.1:40001) and vscode should pop up and show your program interrupted on your breakpoint

@rm3l
Copy link
Member

rm3l commented Apr 26, 2022

@feloy in the past when we were working on debug mode, we used to consider testing things using VS Code launch.json and connecting to the port on which the app's debug mode port is listening.

For this PR, I downloaded the devfile in the tests of this PR, but can't really connect to it. Or, maybe, VS Code is connecting to it, but I don't know what to do. Also, I have never worked with websockets myself, so maybe I'm doing it completely wrong.

Do you think you can share the steps you followed to test the debug mode yourself?

I spent some time on it, but still feel dumb about this thing (how to test debug mode functionality.)

FWIW, I tested this PR earlier today using this sample Spring-Boot Maven project (forked from the SpringBoot Getting Started Guides to add a devfile.yaml). Then used jdb (but we can use IDEs like IntelliJ IDEA) to connect to the local port:

❯ git clone https://github.com/rm3l/gs-spring-boot
❯ cd gs-spring-boot/complete
❯ odo dev --debug

# In a separate terminal
❯ jdb -attach localhost:40002
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...

> threads
Group system:
  (java.lang.ref.Reference$ReferenceHandler)6377                       Reference Handler      running
  (java.lang.ref.Finalizer$FinalizerThread)6378                        Finalizer              cond. waiting
  (java.lang.Thread)6379                                               Signal Dispatcher      running
Group main:
  (org.apache.tomcat.util.threads.TaskThread)6382                      Catalina-utility-1     cond. waiting
  (org.apache.tomcat.util.threads.TaskThread)6383                      Catalina-utility-2     cond. waiting
  (org.springframework.boot.web.embedded.tomcat.TomcatWebServer$1)6384 container-0            sleeping
  (java.lang.Thread)6385                                               http-nio-8080-Poller   running
  (java.lang.Thread)6386                                               http-nio-8080-Acceptor running
  (java.lang.Thread)6387                                               DestroyJavaVM          running
Group InnocuousThreadGroup:
  (jdk.internal.misc.InnocuousThread)6388                              Common-Cleaner         cond. waiting

> stop at com.example.springboot.HelloController:11
Set breakpoint com.example.springboot.HelloController:11

### Then running 'curl http://localhost:40001/' in a separate terminal should hit the breakpoint set:
Breakpoint hit: "thread=http-nio-8080-exec-3", com.example.springboot.HelloController.index(), line=11 bci=0

http-nio-8080-exec-3[1] list
Source file not found: HelloController.java

http-nio-8080-exec-3[1] where
  [1] com.example.springboot.HelloController.index (HelloController.java:11)                                                                                                                                                                   
  [2] jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (native method)                                                                                                                                                                    
  [3] jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)                                                                                                                                                  
  [4] jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)                                                                                                                                          
  [5] java.lang.reflect.Method.invoke (Method.java:566)                                                                                                                                                                                        
  [6] org.springframework.web.method.support.InvocableHandlerMethod.doInvoke (InvocableHandlerMethod.java:205)                                                                                                                                 
--- TRUNCATED ---

http-nio-8080-exec-3[1] cont
> 

@dharmit
Copy link
Member

dharmit commented Apr 27, 2022

To test with the files used in the integration test, you can get the launch.json from the blog post, then run a Debug session and set a Breakpoint where a request is replied (on the res.send('Hello from Node.js Starter Application!'); for example). Then you execute a request on your app endpoint (curl 127.0.0.1:40001) and vscode should pop up and show your program interrupted on your breakpoint

@feloy I am doing something wrong, it seems.

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "attach",
            "name": "odo dev debug",
            "program": "${workspaceFolder}/server.js",
            "address": "localhost",
            "port": 40002,
            "localRoot": "${workspaceFolder}",
        }
    ]
}

I have added breakpoints at both the lines in the server.js that have Hello from Node.js in them. I run odo dev --debug, then I start debugging session from VS Code, and finally do curl localhost:40001/curl localhost:40002. Neither of them takes me to the breakpoint.

The feeling of dumbness is getting real bad at this point, so I'll approve since I don't want my limitation to block your PR.

/approve
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Apr 27, 2022
@openshift-ci
Copy link

openshift-ci bot commented Apr 27, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dharmit

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. label Apr 27, 2022
@feloy
Copy link
Contributor Author

feloy commented Apr 27, 2022

To test with the files used in the integration test, you can get the launch.json from the blog post, then run a Debug session and set a Breakpoint where a request is replied (on the res.send('Hello from Node.js Starter Application!'); for example). Then you execute a request on your app endpoint (curl 127.0.0.1:40001) and vscode should pop up and show your program interrupted on your breakpoint

@feloy I am doing something wrong, it seems.

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "attach",
            "name": "odo dev debug",
            "program": "${workspaceFolder}/server.js",
            "address": "localhost",
            "port": 40002,
            "localRoot": "${workspaceFolder}",
        }
    ]
}

I have added breakpoints at both the lines in the server.js that have Hello from Node.js in them. I run odo dev --debug, then I start debugging session from VS Code, and finally do curl localhost:40001/curl localhost:40002. Neither of them takes me to the breakpoint.

The feeling of dumbness is getting real bad at this point, so I'll approve since I don't want my limitation to block your PR.

/approve /lgtm

Can you try with this launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to remote 5858",
            "type": "node",
            "request": "attach",
            "address": "localhost",
            "port": 40002,
            "localRoot": "${workspaceFolder}",
            "remoteRoot": "/projects"
        }
    ]
}

@feloy
Copy link
Contributor Author

feloy commented Apr 27, 2022

/override ci/prow/v4.10-integration-e2e

IBM Could tests pass

@openshift-ci
Copy link

openshift-ci bot commented Apr 27, 2022

@feloy: Overrode contexts on behalf of feloy: ci/prow/v4.10-integration-e2e

In response to this:

/override ci/prow/v4.10-integration-e2e

IBM Could tests pass

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-merge-robot openshift-merge-robot merged commit 3354b21 into redhat-developer:main Apr 27, 2022
@dharmit
Copy link
Member

dharmit commented Apr 27, 2022

Can you try with this launch.json:

That works. Thanks!

It works when I curl the port 40001, not 40002. However, the debug port 5858 is forwarded to 40002:

Your application is now running on the cluster
 - Forwarding from 127.0.0.1:40001 -> 3000
 - Forwarding from 127.0.0.1:40002 -> 5858

I think I need to use websockets instead of http when trying to work with 40002, right?

@feloy
Copy link
Contributor Author

feloy commented Apr 27, 2022

Port 5858 (and 40002) are for the debugger only, for it to be able to communicate with the process inside the container. You, as a developer, don't need to use it directly.

@dharmit
Copy link
Member

dharmit commented Apr 27, 2022

OK, thanks for guiding me patiently. I surely need some debugging 101 class/course. 😞

cdrage pushed a commit to cdrage/odo that referenced this pull request Aug 31, 2022
* odo dev --debug

* Integration tests

* validate commands

* Fix rebase

* Review: Add integration test

* Modify error message when run/debug commands are not found in devfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation lgtm Indicates that a PR is ready to be merged. Required by Prow.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

odo dev --debug - debugging components
4 participants