godebuggingkubernetes-helmdelve

How to show app's original logs while using delve debugger with kubernetes and golang?


I'm using Kubernetes and helm chart to deploy some microservice applications in a system. Other services will use Netcat to wait for the waiter-service until it is up, but this waiter-service service seems not to work properly when started by delve, so I want to check its logs.

The dockerfile's entry point is like below:

/dlv --listen=:40000 --log --log-output=rpc --allow-non-terminal-interactive=true 
--api-version=2 exec /server -- appname --config=configfile.yaml

The logs i received are like below:

2022-08-24T13:22:11Z debug layer=rpc serving JSON-RPC on new connection
2022-08-24T13:22:11Z debug layer=rpc <- RPCServer.SetApiVersion(api.SetAPIVersionIn{"APIVersion":2})
2022-08-24T13:22:11Z debug layer=rpc -> *api.SetAPIVersionOut{} error: ""
2022-08-24T13:22:11Z debug layer=rpc <- RPCServer.IsMulticlient(rpc2.IsMulticlientIn{})
2022-08-24T13:22:11Z debug layer=rpc -> *rpc2.IsMulticlientOut{"IsMulticlient":false} error: ""
2022-08-24T13:22:11Z debug layer=rpc (async 3) <- RPCServer.State(rpc2.StateIn{"NonBlocking":true})
2022-08-24T13:22:11Z debug layer=rpc (async 3) -> rpc2.StateOut{"State":{"Pid":14,"Running":false,"Recording":false,"CoreDumping":false,"currentThread":{"id":14,"pc":4652512,"file":"/usr/lib/go-1.18/src/runtime/rt0_linux_amd64.s","line":8,"function":{"name":"_rt0_amd64_linux","value":4652512,"type":0,"goType":0,"optimized":true},"goroutineID":0,"ReturnValues":null,"CallReturn":false},"Threads":[{"id":14,"pc":4652512,"file":"/usr/lib/go-1.18/src/runtime/rt0_linux_amd64.s","line":8,"function":{"name":"_rt0_amd64_linux","value":4652512,"type":0,"goType":0,"optimized":true},"goroutineID":0,"ReturnValues":null,"CallReturn":false}],"NextInProgress":false,"WatchOutOfScope":null,"exited":false,"exitStatus":0,"When":""}} error: ""
2022-08-24T13:22:11Z debug layer=rpc <- RPCServer.Recorded(rpc2.RecordedIn{})
2022-08-24T13:22:11Z debug layer=rpc -> *rpc2.RecordedOut{"Recorded":false,"TraceDirectory":""} error: ""

But when I run it with normal command

/server appname --config=configfile.yaml

My expected logs are like:

2022/08/24 07:43:43 maxprocs: Leaving GOMAXPROCS=16: CPU quota undefined
2022-08-24T07:43:44.976Z    INFO    database/pool.go:35 database configuration  {"MaxConns": 8, "RetryCount": 10, "RetryInterval (seconds)": 5}
2022-08-24T07:43:44.976Z    INFO    v4@v4.15.0/conn.go:355  Dialing PostgreSQL server   {"host": "postgres-infras.emulator.svc.cluster.local"}
2022-08-24T07:43:44.980Z    INFO    nats/jetstream.go:335   nats jetstream connected
2022-08-24T07:43:45.090Z    INFO    zap/grpclogger.go:92    [core][Channel #1 SubChannel #2] Subchannel Connectivity change to READY    {"system": "grpc", "grpc_log": true}

The question is how can I read the actual logs to know the reason why waiter-service is not working when others can?


Solution

  • You can add the below options:

     --continue --headless
    

    Related issue: Go delve --continue