784274128b4547864bbb6d20742ecd275a0e3fe3
[AGL/documentation.git] / docs / ATTIC / 3_Developer_Guides / 4_X(cross)_Development_System:_User's_Guide / 4_X(cross)_Development_System:_ Internals / 3.4.4.3_xds-agent / 3.4.4.3.4_Debug.md
1 <!-- WARNING: This file is generated by fetch_docs.js using /home/boron/Documents/AGL/docs-webtemplate/site/_data/tocs/devguides/master/xds-docs-guides-devguides-book.yml -->
2
3 # Debugging
4
5 ## XDS agent architecture
6
7 The agent part is written in *Go* and the webapp / dashboard is in *typescript + Angular4*.
8
9 ```bash
10 |
11 +-- bin/                where xds-server binary file will be built
12 |
13 +-- conf.d              Linux configuration and startup files (systemd user service)
14 |
15 +-- glide.yaml          Go package dependency file
16 |
17 +-- lib/                sources of server part (Go)
18 |
19 +-- main.go             main entry point of of Web server (Go)
20 |
21 +-- Makefile            makefile including
22 |
23 +-- README.md           readme
24 |
25 +-- scripts/            hold various scripts used for installation or startup
26 |
27 +-- tools/              temporary directory to hold development tools (like glide)
28 |
29 +-- vendor/             temporary directory to hold Go dependencies packages
30 |
31 +-- webapp/             source client basic webapp / dashboard
32 ```
33
34 ## Debug xds-agent (Go code)
35
36 Install first [Visual Studio Code](https://code.visualstudio.com/) and
37 [Go plugin](https://marketplace.visualstudio.com/items?itemName=lukehoban.Go)
38 (`ext install lukehoban.Go`)
39
40 Visual Studio Code launcher settings can be found into `.vscode/launch.json`.
41 The important think is to correctly set `GOPATH` in launch.json in order to
42 build xds-agent and debug it within Visual Studio Code.
43
44 Here is an example of launch.json:
45
46 ```json
47 {
48     "version": "0.2.0",
49     "configurations": [{
50             "name": "XDS-Agent",
51             "type": "go",
52             "request": "launch",
53             "mode": "debug",
54             "remotePath": "",
55             "port": 2345,
56             "host": "127.0.0.1",
57             "program": "${workspaceRoot}",
58             "env": {
59                 "GOPATH": "${workspaceRoot}/../../../../../..:${env:GOPATH}",
60             },
61             "args": ["-log", "debug", "-c", "__agent-config_local_dev.json"],
62             "showLog": false
63         }
64     ]
65 }
66 ```
67
68 And `__agent-config_local_dev.json` file content is as follow :
69
70 ```json
71 {
72     "webAppDir": "./webapp/dist",
73     "logsDir": "${HOME}/tmp/xds-agent/logs",
74     "xdsServers": [
75         {
76           "url": "http://localhost:8000"
77         }
78     ],
79     "syncthing": {
80         "binDir": "./bin",
81         "home": "${HOME}/tmp/xds_local_dev/syncthing-config",
82         "gui-address": "http://localhost:8386",
83     }
84 }
85 ```
86
87 ### Tricks to debug both xds-agent and xds-server
88
89 To debug both `xds-agent` and `xds-server` or common code `xds-common`, it may
90 be useful use the same local sources.
91
92 A trick to do that is to replace `xds-server` + `xds-common` in `vendor`
93 directory by a symlink that points to local sources.
94
95 So clone first `xds-server` + `xds-common` sources next to `xds-agent` directory.
96
97 You should have the following tree:
98
99 ```bash
100 tree -L 5 src/
101 src/
102 `-- gerrit.automotivelinux.org
103     `-- gerrit
104         `-- src
105             `-- xds
106                 |-- xds-agent
107                 |-- xds-common
108                 `-- xds-server
109 ```
110
111 Then invoke `vendor/debug` Makefile rule to create symbolic links inside vendor
112 directory :
113
114 ```bash
115 cd src/gerrit.automotivelinux.org/gerrit/src/xds/xds-agent
116 make vendor/debug
117 ```
118
119 ## Debug dashboard part (Typescript / angular code)
120
121 Start `xds-agent` either from command line or in debug mode (see previous
122 chapter) and in another terminal start a watcher daemon so that type typescript
123 sources of webapp / dashboard are automatically "transpiled" using following
124 command :
125
126 ```bash
127 cd webapp
128 npm run watch
129 ```
130
131 Then open the XDS Dashboard page ([http://localhost:8800](http://localhost:8800))
132 and open the developer tool of web browser (for example `Ctrl+Shift+I` in Chrome).