aboutsummaryrefslogtreecommitdiffstats
path: root/docs/part-2/2_xds-agent/4_debug.md
blob: a84c0bc271efceec48bce6f8770b65f0e9edbff2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Debugging

## XDS agent architecture

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

```bash
|
+-- 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](https://code.visualstudio.com/) and
[Go plugin](https://marketplace.visualstudio.com/items?itemName=lukehoban.Go)
(`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:

```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 :

```json
{
    "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:

```bash
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 :

```bash
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 :

```bash
cd webapp
npm run watch
```

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