debug backend plugin
This commit is contained in:
28
DEVELOPMENT_GUIDE.md
Normal file
28
DEVELOPMENT_GUIDE.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Plugin development
|
||||||
|
|
||||||
|
### Debugging backend plugin
|
||||||
|
|
||||||
|
For debugging backend part written on Go, you should go through a few steps. First, build a plugin with special flags for debugging:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make build-debug
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, configure your editor to connect to [delve](https://github.com/go-delve/delve) debugger running in headless mode. This is an example for VS Code:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Debug backend plugin",
|
||||||
|
"type": "go",
|
||||||
|
"request": "attach",
|
||||||
|
"mode": "remote",
|
||||||
|
"port": 3222,
|
||||||
|
"host": "127.0.0.1",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Finally, run grafana-server and then execute `./debug-backend.sh` from grafana-zabbix root folder. This script will attach delve to running plugin. Now you can go to the VS Code and run _Debug backend plugin_ debug config.
|
||||||
2
Makefile
2
Makefile
@@ -13,6 +13,8 @@ build-frontend:
|
|||||||
yarn dev-build
|
yarn dev-build
|
||||||
build-backend:
|
build-backend:
|
||||||
env GOOS=linux go build -mod=vendor -o ./dist/zabbix-plugin_linux_amd64 ./pkg
|
env GOOS=linux go build -mod=vendor -o ./dist/zabbix-plugin_linux_amd64 ./pkg
|
||||||
|
build-debug:
|
||||||
|
env GOOS=linux go build -mod=vendor -gcflags=all="-N -l" -o ./dist/zabbix-plugin_linux_amd64 ./pkg
|
||||||
|
|
||||||
dist: dist-frontend dist-backend
|
dist: dist-frontend dist-backend
|
||||||
dist-frontend:
|
dist-frontend:
|
||||||
|
|||||||
18
debug-backend.sh
Executable file
18
debug-backend.sh
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ "$1" == "-h" ]; then
|
||||||
|
echo "Usage: ${BASH_SOURCE[0]} [plugin process name] [port]"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
PORT="${2:-3222}"
|
||||||
|
PLUGIN_NAME="${1:-'zabbix-plugin_'}"
|
||||||
|
echo $PORT $PLUGIN_NAME
|
||||||
|
|
||||||
|
ptrace_scope=`cat /proc/sys/kernel/yama/ptrace_scope`
|
||||||
|
if [ "$ptrace_scope" != 0 ]; then
|
||||||
|
echo "WARNING: ptrace_scope set to value other than 0, this might prevent debugger from connecting, try writing \"0\" to /proc/sys/kernel/yama/ptrace_scope.
|
||||||
|
Read more at https://www.kernel.org/doc/Documentation/security/Yama.txt"
|
||||||
|
fi
|
||||||
|
|
||||||
|
dlv attach `pgrep ${PLUGIN_NAME}` --headless --listen 0.0.0.0:${PORT} --api-version 2
|
||||||
|
pkill dlv
|
||||||
Reference in New Issue
Block a user