This tells how to prepare code and GoLand IDE to debug Go code of the application running on the cluster.
It works with minikube and GKE/Infra clusters.
It should be possible to use other debugging UIs/front-ends but wasn’t tested.
Main instructions are available here: https://github.com/stackrox/stackrox#debugging
If you’re using GoLand, get familiar with its features available for debugging.
-
One-time setup
In GoLand openRun | Edit Configurations …
, click on the+
icon to add new configuration, chooseGo Remote
template.
Give configuration some name, choseHost:
localhost
andPort:
40000
.
SelectOn disconnect:
optionLeave it running
. -
Connect to remote debugger
Make sure remote debugger is launched/attached and port forwarding is enabled. See corresponding section in README.md.
Next, selectRun | Debug…
and select Go Remote configuration you’ve created.If all done right, you should see
Connected
message in theDebug | Debugger | Variables
windowDon’t forget to set up some code breakpoints.
-
Stopping debugger
When hitting the stop button in GoLand, you may be asked if you want to stop thedlv
debugger instance. It is recommended to chooseNo
because otherwise GoLand may start missing breakpoints.Next, you may be asked if you want to kill the process where debugger was attached. It is recommended to choose
No
because otherwise you’d have to restart the pod.
-
Update your GoLand. JetBrains Toolbox is a good tool for this. GoLand's support for debugging is relatively new, and stability fixes usually come with new IDE releases.
-
After you disconnect GoLand (or it gets disconnected because of a process crash, etc.) and then reconnect, sometimes it happens that GoLand does not stop on breakpoints even though you know it must. I wasn’t able to trace the origin, but here’s what may help:
- Restart GoLand via
File | Invalidate Caches… | Just Restart
.
- Restart GoLand via
-
Occasionally, when stepping through, the debugged process crashes (with abort signal in logs) and GoLand shows a dialog what to do when disconnecting from it. If that happens, you’ll need to delete the pod so that the process can be started again.
This happens when you run into a section protected bymutex_dev
and spend there more than 5 seconds, see https://github.com/stackrox/stackrox/blob/master/pkg/sync/mutex_dev.go. You may want to overrideMUTEX_WATCHDOG_TIMEOUT_SECS=0
environment variable on debugged deployment (or temporarily comment-outkill()
line) to prevent pods from getting killed. -
Breakpoints suspend execution of all goroutines and so pod lifecycle probes might fail if the execution is suspended for too long. Make sure you’re familiar with effects of failing probes - https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes and you know which probes are configured for the pod you’re debugging.
-
If the Central pod crashed and restarted, you’ll have to re-establish port forward to be able to reach StackRox UI and/or back-end. Use
kubectl -n stackrox port-forward svc/central 8000:443 &
for this.