chore: Add back debug backend (#2244)

This commit is contained in:
Zoltán Bedi
2026-01-26 17:04:45 +01:00
committed by GitHub
parent 88ec24c94c
commit 3edec69265
13 changed files with 130 additions and 36 deletions

View File

@@ -3,7 +3,7 @@
# see https://github.com/unknwon/bra/blob/master/templates/default.bra.toml for more configuration options.
[run]
init_cmds = [
["mage", "-v", "build:backend"],
["mage", "-v", "build:debug"],
["mage", "-v" , "reloadPlugin"]
]
watch_all = true
@@ -17,6 +17,6 @@ watch_dirs = [
watch_exts = [".go", ".json"]
build_delay = 2000
cmds = [
["mage", "-v", "build:backend"],
["mage", "-v", "build:debug"],
["mage", "-v" , "reloadPlugin"]
]

View File

@@ -7,7 +7,8 @@ ARG anonymous_auth_enabled=true
ARG development=false
ARG TARGETARCH
ARG GO_VERSION=1.25.6
ARG GO_ARCH=${TARGETARCH:-amd64}
ENV DEV "${development}"
# Make it as simple as possible to access the grafana instance for development purposes
@@ -43,7 +44,27 @@ RUN if [ "${development}" = "true" ]; then \
COPY supervisord/supervisord.conf /etc/supervisor.d/supervisord.ini
COPY supervisord/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Installing Go
RUN if [ "${development}" = "true" ]; then \
curl -O -L https://golang.org/dl/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \
rm -rf /usr/local/go && \
tar -C /usr/local -xzf go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \
echo "export PATH=$PATH:/usr/local/go/bin:~/go/bin" >> ~/.bashrc && \
rm -f go${GO_VERSION}.linux-${GO_ARCH}.tar.gz; \
fi
# Installing delve for debugging
RUN if [ "${development}" = "true" ]; then \
/usr/local/go/bin/go install github.com/go-delve/delve/cmd/dlv@latest; \
fi
# Installing mage for plugin (re)building
RUN if [ "${development}" = "true" ]; then \
git clone https://github.com/magefile/mage; \
cd mage; \
export PATH=$PATH:/usr/local/go/bin; \
go run bootstrap.go; \
fi
# Inject livereload script into grafana index.html
RUN sed -i 's|</body>|<script src="http://localhost:35729/livereload.js"></script></body>|g' /usr/share/grafana/public/views/index.html

View File

@@ -7,11 +7,17 @@ services:
context: .
args:
grafana_image: ${GRAFANA_IMAGE:-grafana-enterprise}
grafana_version: ${GRAFANA_VERSION:-12.2.0}
grafana_version: ${GRAFANA_VERSION:-12.3.1}
development: ${DEVELOPMENT:-false}
anonymous_auth_enabled: ${ANONYMOUS_AUTH_ENABLED:-true}
ports:
- 3000:3000/tcp
- 2345:2345/tcp # delve
security_opt:
- 'apparmor:unconfined'
- 'seccomp:unconfined'
cap_add:
- SYS_PTRACE
volumes:
- ../dist:/var/lib/grafana/plugins/alexanderzobnin-zabbix-app
- ../provisioning:/etc/grafana/provisioning

View File

@@ -5,7 +5,7 @@ user=root
[program:grafana]
user=root
directory=/var/lib/grafana
command=/run.sh
command=bash -c 'while [ ! -f /root/alexanderzobnin-zabbix-app/dist/datasource/gpx_zabbix-datasource* ]; do sleep 1; done; /run.sh'
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
@@ -13,3 +13,35 @@ killasgroup=true
stopasgroup=true
autostart=true
[program:delve]
user=root
command=/bin/bash -c 'pid=""; while [ -z "$pid" ]; do pid=$(pgrep -f gpx_zabbix-datasource); done; /root/go/bin/dlv attach --api-version=2 --headless --continue --accept-multiclient --listen=:2345 $pid'
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
killasgroup=false
stopasgroup=false
autostart=true
autorestart=true
[program:build-watcher]
user=root
command=/bin/bash -c 'while inotifywait -e modify,create,delete -r /var/lib/grafana/plugins/alexanderzobnin-zabbix-app; do echo "Change detected, restarting delve...";supervisorctl restart delve; done'
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
killasgroup=true
stopasgroup=true
autostart=true
[program:mage-watcher]
user=root
environment=PATH="/usr/local/go/bin:/root/go/bin:%(ENV_PATH)s"
directory=/root/alexanderzobnin-zabbix-app
command=/bin/bash -c 'git config --global --add safe.directory /root/alexanderzobnin-zabbix-app && mage -v watch'
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
killasgroup=true
stopasgroup=true
autostart=true

1
.gitignore vendored
View File

@@ -2,7 +2,6 @@
*.sublime-project
.idea/
.vscode
*.bat
.DS_Store

36
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,36 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Standalone debug mode",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/pkg",
"env": {},
"args": [
"-standalone"
]
},
{
"name": "Attach to plugin backend in docker",
"type": "go",
"request": "attach",
"mode": "remote",
"port": 2345,
"host": "127.0.0.1",
"showLog": true,
"trace": "log",
"logOutput": "rpc",
"substitutePath": [
{
"from": "${workspaceFolder}",
"to": "/root/alexanderzobnin-zabbix-app"
}
]
}
]
}

View File

@@ -4,11 +4,11 @@
```sh
# install frontend deps
yarn install --pure-lockfile
yarn install
# build frontend
yarn build
#build backend for current platform
mage -v build:backend
#build backend
mage -v
```
## Rebuild backend on changes
@@ -19,31 +19,31 @@ mage watch
## 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:
The plugin supports two debugging modes for the Go backend:
### Standalone Debug Mode
This mode allows you to run and debug the plugin locally:
1. Use the **"Standalone debug mode"** configuration in VS Code (already configured in `.vscode/launch.json`)
2. Set breakpoints in your Go code
3. The plugin will start in standalone mode with the `-standalone` flag
4. Run your local grafana instance
### Debugging with Docker (Recommended for Grafana Integration)
For debugging the backend plugin while it's running inside Grafana in Docker:
1. Run the docker compose file with the following command in any of the devenv folders:
```sh
make build-debug
DEVELOPMENT=true docker compose up --build -d
```
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.
1. Attach VS Code debugger:
- Use the **"Attach to plugin backend in docker"** configuration in VS Code (already configured in `.vscode/launch.json`)
- Set breakpoints in your Go code
- The debugger will connect to delve running in the Docker container
## Submitting PR

View File

@@ -29,7 +29,11 @@
"src/**",
"pkg/**"
],
"ignoreRegExpList": ["import\\s*\\((.|[\r\n])*?\\)", "import\\s*.*\".*?\"", "\\[@.+\\]"],
"ignoreRegExpList": [
"import\\s*\\((.|[\r\n])*?\\)",
"import\\s*.*\".*?\"",
"\\[@.+\\]"
],
"words": [
"alexanderzobnin",
"applicationids",
@@ -37,6 +41,7 @@
"datapoints",
"datasource",
"datasources",
"devenv",
"dompurify",
"eventid",
"eventids",

View File

@@ -19,7 +19,6 @@ services:
file: ../../.config/docker-compose-base.yaml
service: grafana
volumes:
- ../..:/grafana-zabbix
- ../dashboards:/devenv/dashboards
- '../datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml'
- '../dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml'

View File

@@ -19,7 +19,6 @@ services:
file: ../../.config/docker-compose-base.yaml
service: grafana
volumes:
- ../..:/grafana-zabbix
- ../dashboards:/devenv/dashboards
- '../datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml'
- '../dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml'

View File

@@ -19,7 +19,6 @@ services:
file: ../../.config/docker-compose-base.yaml
service: grafana
volumes:
- ../..:/grafana-zabbix
- ../dashboards:/devenv/dashboards
- '../datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml'
- '../dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml'

View File

@@ -5,7 +5,6 @@ services:
file: ../../.config/docker-compose-base.yaml
service: grafana
volumes:
- ../..:/grafana-zabbix
- ../dashboards:/devenv/dashboards
- '../datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml'
- '../dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml'

View File

@@ -5,7 +5,6 @@ services:
file: ../../.config/docker-compose-base.yaml
service: grafana
volumes:
- ../..:/grafana-zabbix
- ../dashboards:/devenv/dashboards
- '../datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml'
- '../dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml'