Skip to content

Visual Studio Code

igorpick edited this page Jun 8, 2021 · 4 revisions

Debugging noobaa node.js process

This page explains how to debug the noobaa node.js processes from VSCode using the example of the webserver process running in noobaa-core-0 pod.

Prerequisites

  • Installed noobaa system on kubernetes cluster
  • Installed VSCode with plugin "Cloud code 1.12.1"

1. Add required env variable to noobaa-core pod template

webserver is managed by supervisor process control system which has config per process.

For example:

[program:webserver]
stopsignal=KILL
killasgroup=true
stopasgroup=true
autostart=true
directory=/root/node_modules/noobaa-core
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/1
stderr_logfile_maxbytes=0
command=/usr/local/bin/node %(ENV_WEB_NODE_OPTIONS)s src/server/web_server.js

The webserver process can be started with flags provided by the WEB_NODE_OPTIONS env variable.

By default the variable is empty, but in our case we have to configure it with value "--inspect".

Supervisor available variables:

  • webserver - WEB_NODE_OPTIONS
  • bg_workers - BG_NODE_OPTIONS
  • hosted_agents - HOSTED_AGENTS_NODE_OPTIONS

$ kubectl edit statefulsets.apps noobaa-core

spec:
  containers:
    - env:
      - name: WEB_NODE_OPTIONS
        value: --inspect

The action will trigger recreating the noobaa-core-0 pod and weserver will start listening on port 9229 for debugging.

2. Create new running config in VSCode:

Add configuration "Cloud Code: Attach (Node.js)"

{
            "name": "Attach to Kubernetes Pod (NodeJS)",
            "type": "cloudcode.kubernetes",
            "request": "attach",
            "language": "Node",
            "debugPort": 9229,
            "podSelector": {
                "noobaa-core": "noobaa"
            },
            "localRoot": "**<User local code path>**/noobaa/noobaa-core/src/",
            "remoteRoot": "/root/node_modules/noobaa-core/src/"
}
Clone this wiki locally