Merge pull request #215 from erthalion/feature/debugger-documentation-section

Add a section about debugger
This commit is contained in:
zerg-junior 2018-02-01 18:10:47 +01:00 committed by GitHub
commit 4cbb86ea13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 45 additions and 0 deletions

View File

@ -305,3 +305,48 @@ The operator also supports pprof endpoints listed at the [pprof package](https:/
* /debug/pprof/profile
* /debug/pprof/symbol
* /debug/pprof/trace
It's possible to attach a debugger to troubleshoot postgres-operator inside a
docker container. It's possible with gdb and
[delve](https://github.com/derekparker/delve). Since the latter one is a
specialized debugger for golang, we will use it as an example. To use it you
need:
* Install delve locally
```
go get -u github.com/derekparker/delve/cmd/dlv
```
* Add following dependencies to the `Dockerfile`
```
RUN apk --no-cache add go git musl-dev
RUN go get github.com/derekparker/delve/cmd/dlv
```
* Update the `Makefile` to build the project with debugging symbols. For that
you need to add `gcflags` to a build target for corresponding OS (e.g. linux)
```
-gcflags "-N -l"
```
* Run `postgres-operator` under the delve. For that you need to replace
`ENTRYPOINT` with the following `CMD`:
```
CMD ["/root/go/bin/dlv", "--listen=:DLV_PORT", "--headless=true", "--api-version=2", "exec", "/postgres-operator"]
```
* Forward the listening port
```
kubectl port-forward POD_NAME DLV_PORT:DLV_PORT
```
* Attach to it
```
$ dlv connect 127.0.0.1:DLV_PORT
```