Debugging

XDS agent architecture

The agent part is written in Go and the webapp / dashboard is in typescript + Angular4.

|
+-- bin/                where xds-server binary file will be built
|
+-- conf.d              Linux configuration and startup files (systemd user service)
|
+-- glide.yaml          Go package dependency file
|
+-- lib/                sources of server part (Go)
|
+-- main.go             main entry point of of Web server (Go)
|
+-- Makefile            makefile including
|
+-- README.md           readme
|
+-- scripts/            hold various scripts used for installation or startup
|
+-- tools/              temporary directory to hold development tools (like glide)
|
+-- vendor/             temporary directory to hold Go dependencies packages
|
+-- webapp/             source client basic webapp / dashboard

Debug xds-agent (Go code)

Install first Visual Studio Code and Go plugin (ext install lukehoban.Go)

Visual Studio Code launcher settings can be found into .vscode/launch.json. The important think is to correctly set GOPATH in launch.json in order to build xds-agent and debug it within Visual Studio Code.

Here is an example of launch.json:

{
    "version": "0.2.0",
    "configurations": [{
            "name": "XDS-Agent",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "remotePath": "",
            "port": 2345,
            "host": "127.0.0.1",
            "program": "${workspaceRoot}",
            "env": {
                "GOPATH": "${workspaceRoot}/../../../../../..:${env:GOPATH}",
            },
            "args": ["-log", "debug", "-c", "__agent-config_local_dev.json"],
            "showLog": false
        }
    ]
}

And __agent-config_local_dev.json file content is as follow :

{
    "webAppDir": "./webapp/dist",
    "logsDir": "${HOME}/tmp/xds-agent/logs",
    "xdsServers": [
        {
          "url": "http://localhost:8000"
        }
    ],
    "syncthing": {
        "binDir": "./bin",
        "home": "${HOME}/tmp/xds_local_dev/syncthing-config",
        "gui-address": "http://localhost:8386",
    }
}

Tricks to debug both xds-agent and xds-server

To debug both xds-agent and xds-server or common code xds-common, it may be useful use the same local sources.

A trick to do that is to replace xds-server + xds-common in vendor directory by a symlink that points to local sources.

So clone first xds-server + xds-common sources next to xds-agent directory.

You should have the following tree:

tree -L 5 src/
src/
`-- gerrit.automotivelinux.org
    `-- gerrit
        `-- src
            `-- xds
                |-- xds-agent
                |-- xds-common
                `-- xds-server

Then invoke vendor/debug Makefile rule to create symbolic links inside vendor directory :

cd src/gerrit.automotivelinux.org/gerrit/src/xds/xds-agent
make vendor/debug

Debug dashboard part (Typescript / angular code)

Start xds-agent either from command line or in debug mode (see previous chapter) and in another terminal start a watcher daemon so that type typescript sources of webapp / dashboard are automatically “transpiled” using following command :

cd webapp
npm run watch

Then open the XDS Dashboard page (http://localhost:8800) and open the developer tool of web browser (for example Ctrl+Shift+I in Chrome).