Skip to content
This repository was archived by the owner on Feb 20, 2021. It is now read-only.

Enable OpenShift Debugging #33

Closed
ghost opened this issue Jan 31, 2018 · 7 comments
Closed

Enable OpenShift Debugging #33

ghost opened this issue Jan 31, 2018 · 7 comments
Assignees

Comments

@ghost
Copy link

ghost commented Jan 31, 2018

Enable a debugger to attach to a node.js application running in OpenShift.

ATM, you can set the following environment variables:

  • DEV_MODE=true
  • NODE_ENV=development

which will provide some access over 5858, but you should consider a different solution.

@lance lance self-assigned this Feb 1, 2018
@lance lance added the backlog label Feb 21, 2018
@lholmquist
Copy link
Contributor

Ok, so at some point i was able to remote debug my application running on openshift in the chrome debugger, so i set out to remember how to do it.

I had originally used the openshift-test repo, https://github.com/lance/openshift-test.

deployed that openshift in debug mode

The end of the log of the pod looked sort of like this:


+ echo 'Launching via nodemon...'
--
  | + exec npx nodemon --inspect=5858
  | Launching via nodemon...
  | [nodemon] 1.17.3
  | [nodemon] to restart at any time, enter `rs`
  | [nodemon] watching: *.*
  | [nodemon] starting `node --inspect=5858 index.js`
  | Debugger listening on ws://127.0.0.1:5858/545f2720-8d15-4e0a-87d0-c4eec871905b
  | For help see https://nodejs.org/en/docs/inspector
  | Server listening on port 8080


Then from console, i did this:
oc port-forward $(oc get po | grep openshift-test | grep Running | awk '{print $1}') 8888:5858

Then went to chrome://inspect in the browser, clicked "configure" and added 127.0.0.1:8888 and was able to remote debug.

I wanted to recreate that with a booster, so i took the configmap booster, https://github.com/bucharest-gold/nodejs-configmap, and did the normal deploy stuff, but made sure it was in debug mode using "--build.env NODE_ENV=debug"

The end of the pod log for that is similar to this:


npm info ok
--
  | + echo 'Launching via nodemon...'
  | + exec npx nodemon --inspect=5858
  | Launching via nodemon...
  | [nodemon] 1.17.3
  | [nodemon] to restart at any time, enter `rs`
  | [nodemon] watching: *.*
  | [nodemon] starting `PORT=8080 node ./bin/www --inspect=5858`

Now, when i try to port forward, i keep getting an error about a connection refused, sort of like this:

Handling connection for 8888
Handling connection for 8888
E0418 20:37:32.844331   72361 portforward.go:331] an error occurred forwarding 8888 -> 5858: error forwarding port 5858 to pod 12f4b2e7dbc0830d237f8e2418c561047951bcc73f7f4ce120db174fd2420b89, uid : exit status 1: 2018/04/18 20:37:32 socat[5398] E connect(5, AF=2 127.0.0.1:5858, 16): Connection refused
E0418 20:37:32.848624   72361 portforward.go:331] an error occurred forwarding 8888 -> 5858: error forwarding port 5858 to pod 12f4b2e7dbc0830d237f8e2418c561047951bcc73f7f4ce120db174fd2420b89, uid : exit status 1: 2018/04/18 20:37:32 socat[5399] E connect(5, AF=2 127.0.0.1:5858, 16): Connection refused

I think i know why, in the second example, the debugger is never listening since the "--inspect=5858" is in the wrong spot when starting the node process.

Not sure how to fix that. I'll check in the nodemon issues

@lholmquist
Copy link
Contributor

might be a possible solution remy/nodemon#1226

@lance
Copy link
Contributor

lance commented Apr 18, 2018

@lholmquist are you sure you don't need to expose that port as a route?

@lance
Copy link
Contributor

lance commented Apr 18, 2018

Ahh - I think you are right @lholmquist - specifically this comment in that issue

I believe that if you change your package so that the main prop reads ./bin/www, and change scripts.start to node . you should be able to pass --inspect to nodemon the way you're expecting to.

@lholmquist
Copy link
Contributor

lholmquist commented Apr 18, 2018

that almost worked, I added the main section with "./bin/www" and my scripts.start is now "PORT=8080 node ."

but it looks like nodemon is stripping that PORT part for some reason.


Launching via nodemon...
--
  | + echo 'Launching via nodemon...'
  | + exec npx nodemon --inspect=5858
  | [nodemon] 1.17.3
  | [nodemon] to restart at any time, enter `rs`
  | [nodemon] watching: *.*
  | [nodemon] starting `node --inspect=5858 ./bin/www`
  | Debugger listening on ws://127.0.0.1:5858/349faca7-9d6e-4f66-ae7c-29afe9eeefcb
  | For help see https://nodejs.org/en/docs/inspector


almost there.

with this new setup, if i do a "npm run start" locally, things are working,

@lholmquist
Copy link
Contributor

lholmquist commented Apr 19, 2018

It looks like this is expected behavior for nodemon. from what i've seen, if you want to add an environment variable during the nodemon execution, you do something like PORT=8080 nodemon

@lance i have it in my head that the s2i images are expecting port 8080 for some reason, is that actually true or am i making that up? I think the issue is that our liveness and readiness probes for the boosters are looking for port 8080 if no PORT env is provided, express starts out on port 3000

So there are a couple things we can do for the boosters to add the PORT env variable.

  1. change the default port in the "./bin/www" file to 8080 instead of 3000 - https://github.com/bucharest-gold/nodejs-configmap/blob/master/bin/www#L35

    • This is the quickest option
  2. in the deployment config, create an environment variable

    • This could also be added to the deploymentConfig "enricher" so a user wouldn't have to specify it if they were just letting nodeshift create a default deploymentConfig for them
    • This might be a better option in the long run?

I do need to update all the boosters to include a "main" property and change the start script to what i showed in the previous post. So i will need to update the boosters no matter what

lholmquist referenced this issue in lholmquist/nodejs-rest-http Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to https://github.com/bucharest-gold/centos7-s2i-nodejs/issues/33\#issuecomment-382587104.

fixes nodeshift-starters#98
lholmquist added a commit to lholmquist/nodejs-rest-http-crud that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-starters#93
lholmquist added a commit to lholmquist/nodejs-configmap that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-starters#45
lholmquist added a commit to lholmquist/nodejs-rest-http-secured that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-archived#69
lholmquist added a commit to lholmquist/nodejs-circuit-breaker that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-starters#44
lholmquist added a commit to lholmquist/nodejs-cache that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-starters#11
lholmquist added a commit to lholmquist/nodejs-rest-http-secured that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-archived#69
lholmquist added a commit to lholmquist/nodejs-configmap that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-starters#45
lholmquist added a commit to lholmquist/nodejs-rest-http-crud that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-starters#93
lholmquist referenced this issue in lholmquist/nodejs-rest-http-redhat Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to https://github.com/bucharest-gold/centos7-s2i-nodejs/issues/33\#issuecomment-382587104.

fixes nodeshift-archived#26
lholmquist referenced this issue in lholmquist/nodejs-rest-http-redhat Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to https://github.com/bucharest-gold/centos7-s2i-nodejs/issues/33\#issuecomment-382587104.

fixes nodeshift-archived#26
lholmquist added a commit to lholmquist/nodejs-rest-http-crud-redhat that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-archived#93
lholmquist added a commit to lholmquist/nodejs-rest-http-crud-redhat that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-archived#30
lholmquist added a commit to lholmquist/nodejs-configmap-redhat that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-archived#33
lholmquist added a commit to lholmquist/nodejs-rest-http-secured-redhat that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-archived#69
lholmquist added a commit to lholmquist/nodejs-health-check-redhat that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-archived#101
lholmquist added a commit to lholmquist/nodejs-health-check-redhat that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-archived#28
lholmquist added a commit to lholmquist/nodejs-rest-http-secured-redhat that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-archived#31
lholmquist added a commit to lholmquist/nodejs-circuit-breaker-redhat that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-archived#11
lholmquist added a commit to lholmquist/nodejs-cache-redhat that referenced this issue Apr 23, 2018
npm start will now look at the main property for the entry point.  Port 8080 is now set as the default port instead of 3000.   This is a fix related to nodeshift-archived/centos7-s2i-nodejs#33\#issuecomment-382587104.

fixes nodeshift-archived#4
@lholmquist
Copy link
Contributor

lholmquist commented May 1, 2018

So i think to close this issue, we really just need to update the docs?

perhaps i can write a blog post also, sort of piggybacking off of https://medium.com/@auscunningham/debug-your-openshift-node-js-apps-locally-with-visual-studio-code-vs-code-1b7da847fd9c and not using vscode but just the chrome debugger

The fixes i needed to do to the boosters aren't live yet in the launcher, but they are in master of each of the repos, and probably won't be until summit, but that should be ok.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants