如何在使用 Kubernetes 和 Golang 的 Delve 调试器时显示应用程序的原始日志?

huangapple go评论87阅读模式
英文:

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

问题

你可以通过查看容器的日志来了解为什么 waiter-service 在其他服务可以正常工作时无法正常工作。在Kubernetes中,你可以使用以下命令来获取容器的日志:

kubectl logs <pod_name> -c <container_name>

其中 <pod_name> 是你的Pod的名称,<container_name> 是你的容器的名称(在你的情况下可能是 waiter-service)。这将返回该容器的日志输出。

另外,你还可以使用以下命令来获取Pod的名称和容器的名称:

kubectl get pods

这将列出所有正在运行的Pod及其相关信息,包括名称和容器名称。

通过查看容器的日志,你可以找到导致 waiter-service 无法正常工作的原因。可能会有错误消息或异常堆栈跟踪,可以帮助你诊断问题并采取相应的措施。

英文:

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

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	{&quot;MaxConns&quot;: 8, &quot;RetryCount&quot;: 10, &quot;RetryInterval (seconds)&quot;: 5}
2022-08-24T07:43:44.976Z	INFO	v4@v4.15.0/conn.go:355	Dialing PostgreSQL server	{&quot;host&quot;: &quot;postgres-infras.emulator.svc.cluster.local&quot;}
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	{&quot;system&quot;: &quot;grpc&quot;, &quot;grpc_log&quot;: true}

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

答案1

得分: 1

你可以添加以下选项:

--continue --headless

相关问题:Go delve --continue

英文:

You can add the below options:

 --continue --headless

Related issue: Go delve --continue

huangapple
  • 本文由 发表于 2022年8月24日 22:08:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/73474644.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定