grpcdebug 是一个命令行接口,专注于简化 gRPC 应用程序的调试过程。
grpcdebug is a command line interface focusing on simplifying the debugging process of gRPC applications. grpcdebug fetches the internal states of the gRPC library from the application via gRPC protocol and provide a human-friendly UX to browse them. Currently, it supports Channelz/Health Checking/CSDS (aka. admin services). In other words, it can fetch statistics about how many RPCs has being sent or failed on a given gRPC channel, it can inspect address resolution results, it can dump the in-effective xDS configuration that directs the routing of RPCs.
If you are looking for a tool to send gRPC requests and interact with a gRPC server, please checkout https://github.com/fullstorydev/grpcurl.
…The download links of the binaries can be found at
https://github.com/grpc-ecosystem/grpcdebug/releases. You can find the
precompiled artifacts for macOS/Linux/Windows.
Minimum Golang Version 1.22. Official Golang install guide: https://golang.org/doc/install.
You can install the grpcdebug tool using command:
go install -v github.com/grpc-ecosystem/grpcdebug@latestYou can check your Golang version with:
go versionDon't forget to add Golang binaries to your PATH:
export PATH=$PATH:$(go env GOPATH)/binIf certain commands are confusing, please try to use -h to get more context.
Suggestions and ideas are welcome, please post them to
https://github.com/grpc-ecosystem/grpcdebug/issues!
If you haven't got your gRPC application instrumented, feel free to try out the
mocking testserver which implemented admin services.
cd internal/testing/testserver
go run main.go
# Serving Business Logic on :10001
# Serving Insecure Admin Services on :50051
# Serving Secure Admin Services on :50052
# ...To connect to a gRPC endpoint without any credentials, we don't use any special
flags. If the local network can connect to the given gRPC endpoint, it should
just work. For example, if I have a gRPC application exposing admin services at
localhost:50051:
grpcdebug localhost:50051 channelz channelsOne way to establish a TLS connection with grpcdebug is by specifying the credentials via command line flags. For example:
grpcdebug localhost:50052 --security=tls --credential_file=./internal/testing/ca.pem --server_name_override="*.test.youtube.com" channelz channelsAlternatively, like OpenSSH clients, you can specify the security settings in a
grpcdebug_config.yaml file. grpcdebug CLI will find matching connection config and
then use it to connect.
servers:
"pattern string":
real_address: string
security: insecure/tls
credential_file: string
server_name_override: stringHere is an example config file grpcdebug_config.yaml.
Each server config can have the following settings:
Server which dictates if this rule should
apply;insecure or tls, expecting more in the future;grpcdebug searches the config file in the following order:
GRPCDEBUG_CONFIG is set, if so, load from the
given path;grpcdebug_config.yaml file in the current working directory;grpcdebug_config.yaml file in the user config directory (Linux:
$HOME/.config, macOS: $HOME/Library/Application Support, Windows:
%AppData%, see
os.UserConfigDir()).For example, we can connect to our mock test server's secure admin port via:
GRPCDEBUG_CONFIG=internal/testing/grpcdebug_config.yaml grpcdebug localhost:50052 channelz channels
# Or
GRPCDEBUG_CONFIG=internal/testing/grpcdebug_config.yaml grpcdebug prod channelz channelsgrpcdebug can be used to fetch the health checking status of a peer gRPC
application (see
health.proto).
gRPC's health checking works at the service-level, meaning services registered on
the same gRPC server may have different health statuses. The health status of
service "" is used to represent the overall health status of the gRPC
application.
To simply fetch the overall health status:
grpcdebug localhost:50051 health
# : SERVING
# or
# : NOT_SERVINGOr fetch individual service's health status:
grpcdebug localhost:50051 health helloworld.Greeter
# : SERVING
# helloworld.Greeter: SERVINGChannelz is a channel tracing library that allows applications to remotely query gRPC internal debug information. Also, Channelz has a web interface (see gdebug). grpcdebug is able to fetch information and present it in a more readable way.
Generally, you wil start with either the servers or channels command and
then work down to the details.
For all Channelz commands, you can add --json to get the raw Channelz output.
grpcdebug localhost:50051 channelz servers --json
#[
# {
# "ref": {
# "server_id": 2,
# "name": "ServerImpl{logId=2, transportServer=NettyServer{logId=1, addresses=[0.0.0.0/0.0.0.0:50051]}}"
# },
# "data": {
# "calls_started": 3,
# "calls_succeeded": 2,
# "last_call_started_timestamp": {
# "seconds": 1680220688,
# "nanos": 444000000
# }
# },
# "listen_socket": [
# {
# "socket_id": 3,
# "name": "ListenSocket{logId=3, channel=[id: 0x05f9f16c, L:/0:0:0:0:0:0:0:0%0:50051]}"
# }
# ]
# }
#]
grpcdebug localhost:50051 channelz channels
# Channel ID Target State Calls(Started/Succeeded/Failed) Created Time
# 7 localhost:10001 READY 5136/4631/505 8 minutes agogrpcdebug localhost:50051 channelz servers
# Server ID Listen Addresses Calls(Started/Succeeded/Failed) Last Call Started
# 1 [:::10001] 2852/2530/322 now
# 2 [:::50051] 29/28/0 now
# 3 [:::50052] 4/4/0 26 seconds agoYou can identify a channel via the Channel ID.
…grpcdebug localhost:50051 channelz subchannel 8
# Subchannel ID: 8
# Target: localhost:10001
# State: READY
# Calls Started: 4490
# Calls Succeeded: 3966
# Calls Failed: 524
# Created Time: 7 minutes ago
# ---
# Socket ID Local->Remote Streams(Started/Succeeded/Failed) Messages(Sent/Received)
# 9 ::1:47436->::1:10001 4490/4490/0 4490/3966…grpcdebug localhost:50051 channelz server 1
# Server Id: 1
# Listen Addresses: [:::10001]
# Calls Started: 5250
# Calls Succeeded: 4647
# Calls Failed: 603
# Last Call Started: now
# ---
# Socket ID Local->Remote Streams(Started/Succeeded/Failed) Messages(Sent/Received)
# 10 ::1:10001->::1:47436 5250/5250/0 4647/5250In production, there may be thousands of clients/servers/sockets. It would be very noisy to print all of them at once, so Channelz supports pagination through start_id and max_results
grpcdebug localhost:50051 channelz servers --start_id=0 --max_results=1
# Server ID Listen Addresses Calls(Started/Succeeded/Failed) Last Call Started
# 1 [:::10001] 2852/2530/322 now
grpcdebug localhost:50051 channelz servers --start_id=2 --max_results=2
# Server ID Listen Addresses Calls(Started/Succeeded/Failed) Last Call Started
# 2 [:::50051] 29/28/0 now
# 3 [:::50052] 4/4/0 26 seconds agoIt works similarly for printing channels via channelz channels and printing server sockets via channelz server.
xDS is a data plane configuration API commonly used in service mesh projects. It's created by Envoy, used by Istio, Traffic Director, and gRPC.
The xDS resources status might be REQUESTED/DOES_NOT_EXIST/ACKED/NACKED (see
config_dump.proto).
This view is intended for a quick scan if a configuration is propagated from the
service mesh control plane.
…grpcdebug localhost:50051 xds config
# {
# "config": [
# {
# "node": {
# "id": "projects/1040920224690/networks/default/nodes/5cc9170c-d5b4-4061-b431-c1d43e6ac0ab",
# "cluster": "cluster",
# "metadata": {
# "INSTANCE_IP": "192.168.120.31",
# "TRAFFICDIRECTOR_GCP_PROJECT_NUMBER": "1040920224690",
# "TRAFFICDIRECTOR_NETWORK_NAME": "default"
# },
# ...For an example config dump, see csds_config_dump.json.
The dumped xDS config can be quite verbose, if I only interested in certain xDS type, grpcdebug can only print the selected section.
…………暂无开放 Issues,或尚未同步最近议题。