xref: /aosp_15_r20/external/grpc-grpc-java/examples/example-debug/README.md (revision e07d83d3ffcef9ecfc9f7f475418ec639ff0e5fe)
1*e07d83d3SAndroid Build Coastguard Worker# gRPC Debug Example
2*e07d83d3SAndroid Build Coastguard Worker
3*e07d83d3SAndroid Build Coastguard WorkerThe debug example uses a Hello World style server whose response includes its
4*e07d83d3SAndroid Build Coastguard Workerhostname. It demonstrates usage of the AdminInterface and the grpcdebug
5*e07d83d3SAndroid Build Coastguard Workercommandline tool.
6*e07d83d3SAndroid Build Coastguard Worker
7*e07d83d3SAndroid Build Coastguard WorkerThe example requires grpc-java to already be built. You are strongly encouraged
8*e07d83d3SAndroid Build Coastguard Workerto check out a git release tag, since there will already be a build of grpc
9*e07d83d3SAndroid Build Coastguard Workeravailable. Otherwise, you must follow [COMPILING](../../COMPILING.md).
10*e07d83d3SAndroid Build Coastguard Worker
11*e07d83d3SAndroid Build Coastguard Worker### Build the example
12*e07d83d3SAndroid Build Coastguard Worker
13*e07d83d3SAndroid Build Coastguard Worker1. Optional:  Build the hello-world-debug example client.
14*e07d83d3SAndroid Build Coastguard Worker   See [the examples README](../README.md)
15*e07d83d3SAndroid Build Coastguard Worker
16*e07d83d3SAndroid Build Coastguard Worker2. Build the debuggable server and client. From the
17*e07d83d3SAndroid Build Coastguard Worker   `grpc-java/examples/examples-debug` directory run:
18*e07d83d3SAndroid Build Coastguard Worker
19*e07d83d3SAndroid Build Coastguard Worker```bash
20*e07d83d3SAndroid Build Coastguard Worker$ ../gradlew installDist
21*e07d83d3SAndroid Build Coastguard Worker```
22*e07d83d3SAndroid Build Coastguard Worker
23*e07d83d3SAndroid Build Coastguard WorkerThis creates the
24*e07d83d3SAndroid Build Coastguard Workerscripts `build/install/debug/bin/hostname-debuggable-server/bin/hostname-debuggable-server`
25*e07d83d3SAndroid Build Coastguard Workerthat
26*e07d83d3SAndroid Build Coastguard Workerruns the example.
27*e07d83d3SAndroid Build Coastguard Worker
28*e07d83d3SAndroid Build Coastguard WorkerTo run the debug example, run:
29*e07d83d3SAndroid Build Coastguard Worker
30*e07d83d3SAndroid Build Coastguard Worker```bash
31*e07d83d3SAndroid Build Coastguard Worker$ ./build/install/debug/bin/hostname-debuggable-server/bin/hostname-debuggable-server
32*e07d83d3SAndroid Build Coastguard Worker```
33*e07d83d3SAndroid Build Coastguard Worker
34*e07d83d3SAndroid Build Coastguard WorkerAnd in a different terminal window run the client.
35*e07d83d3SAndroid Build Coastguard Worker
36*e07d83d3SAndroid Build Coastguard WorkerNote:  You can use the standard hello-world client with no debugging enabled and
37*e07d83d3SAndroid Build Coastguard Workerstill see results on the server. However, if you want to get debug information
38*e07d83d3SAndroid Build Coastguard Workerabout the client you need to run the hello-world-debuggable client.
39*e07d83d3SAndroid Build Coastguard Worker
40*e07d83d3SAndroid Build Coastguard WorkerSimple client
41*e07d83d3SAndroid Build Coastguard Worker
42*e07d83d3SAndroid Build Coastguard Worker```bash
43*e07d83d3SAndroid Build Coastguard Worker$ ../build/install/examples/bin/hello-world-client
44*e07d83d3SAndroid Build Coastguard Worker```
45*e07d83d3SAndroid Build Coastguard Worker
46*e07d83d3SAndroid Build Coastguard Workerdebug enabled client
47*e07d83d3SAndroid Build Coastguard Worker
48*e07d83d3SAndroid Build Coastguard Worker```bash
49*e07d83d3SAndroid Build Coastguard Worker$ ./build/install/examples-debug/bin/hello-world-debuggable-client
50*e07d83d3SAndroid Build Coastguard Worker```
51*e07d83d3SAndroid Build Coastguard Worker
52*e07d83d3SAndroid Build Coastguard Worker### Maven
53*e07d83d3SAndroid Build Coastguard Worker
54*e07d83d3SAndroid Build Coastguard WorkerIf you prefer to use Maven:
55*e07d83d3SAndroid Build Coastguard Worker
56*e07d83d3SAndroid Build Coastguard Worker1. Build the hello-world example client. See [the examples README](../README.md)
57*e07d83d3SAndroid Build Coastguard Worker
58*e07d83d3SAndroid Build Coastguard Worker2. Run in this directory:
59*e07d83d3SAndroid Build Coastguard Worker
60*e07d83d3SAndroid Build Coastguard Worker```bash
61*e07d83d3SAndroid Build Coastguard Worker$ mvn verify
62*e07d83d3SAndroid Build Coastguard Worker$ # Run the server (from the examples-debug directory)
63*e07d83d3SAndroid Build Coastguard Worker$ mvn exec:java -Dexec.mainClass=io.grpc.examples.debug.HostnameServer
64*e07d83d3SAndroid Build Coastguard Worker$ # In another terminal run the client (from the examples directory)
65*e07d83d3SAndroid Build Coastguard Worker$ cd ..
66*e07d83d3SAndroid Build Coastguard Worker$ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworld.HelloWorldClient
67*e07d83d3SAndroid Build Coastguard Worker```
68*e07d83d3SAndroid Build Coastguard Worker
69*e07d83d3SAndroid Build Coastguard Worker## Using grpcdebug
70*e07d83d3SAndroid Build Coastguard Worker
71*e07d83d3SAndroid Build Coastguard Workergrpcdebug is a tool that has been created to access the metrics from the
72*e07d83d3SAndroid Build Coastguard Workerchannelz and health services.
73*e07d83d3SAndroid Build Coastguard Worker
74*e07d83d3SAndroid Build Coastguard Worker### Installing the grpcdebug tool
75*e07d83d3SAndroid Build Coastguard Worker
76*e07d83d3SAndroid Build Coastguard WorkerThe source code is located in a github project
77*e07d83d3SAndroid Build Coastguard Worker[grpc-ecosystem/grpcdebug](https://github.com/grpc-ecosystem/grpcdebug). You
78*e07d83d3SAndroid Build Coastguard Workercan either download [the latest built version]
79*e07d83d3SAndroid Build Coastguard Worker(https://github.com/grpc-ecosystem/grpcdebug/releases/latest) (recommended) or
80*e07d83d3SAndroid Build Coastguard Workerfollow the README.md to build it yourself.
81*e07d83d3SAndroid Build Coastguard Worker
82*e07d83d3SAndroid Build Coastguard Worker### Running the grpcdebug tool
83*e07d83d3SAndroid Build Coastguard Worker#### Usage
84*e07d83d3SAndroid Build Coastguard Worker`grpcdebug <target address> [flags] channelz <command> [argument]`
85*e07d83d3SAndroid Build Coastguard Worker
86*e07d83d3SAndroid Build Coastguard Worker
87*e07d83d3SAndroid Build Coastguard Worker| Command    |       Argument       | Description                                       |
88*e07d83d3SAndroid Build Coastguard Worker|:-----------|:--------------------:|:--------------------------------------------------|
89*e07d83d3SAndroid Build Coastguard Worker| channel    | \<channel id or URL> | Display channel states in a human readable way.   |
90*e07d83d3SAndroid Build Coastguard Worker| channels   |                      | Lists client channels for the target application. |
91*e07d83d3SAndroid Build Coastguard Worker| server     |     \<server ID>     | Displays server state in a human readable way.    |
92*e07d83d3SAndroid Build Coastguard Worker| servers    |                      | Lists servers in a human readable way.            |
93*e07d83d3SAndroid Build Coastguard Worker| socket     |     \<socket ID>     | Displays socket states in a human readable way.   |
94*e07d83d3SAndroid Build Coastguard Worker| subchannel |        \<id>         | Display subchannel states in human readable way.  |
95*e07d83d3SAndroid Build Coastguard Worker
96*e07d83d3SAndroid Build Coastguard WorkerGenerally, you will start with either `servers` or `channels` and then work down
97*e07d83d3SAndroid Build Coastguard Workerto the details
98*e07d83d3SAndroid Build Coastguard Worker<br><br>
99*e07d83d3SAndroid Build Coastguard Worker
100*e07d83d3SAndroid Build Coastguard Worker#### Getting overall server info
101*e07d83d3SAndroid Build Coastguard Worker```bash
102*e07d83d3SAndroid Build Coastguard Workerbin/grpcdebug/grpcdebug localhost:50051 channelz servers
103*e07d83d3SAndroid Build Coastguard Worker```
104*e07d83d3SAndroid Build Coastguard WorkerThis will show you the server ids with their activity
105*e07d83d3SAndroid Build Coastguard Worker```text
106*e07d83d3SAndroid Build Coastguard WorkerServer ID   Listen Addresses   Calls(Started/Succeeded/Failed)   Last Call Started
107*e07d83d3SAndroid Build Coastguard Worker2           [[::]:50051]       38/34/3                           now
108*e07d83d3SAndroid Build Coastguard Worker```
109*e07d83d3SAndroid Build Coastguard Worker<br>
110*e07d83d3SAndroid Build Coastguard Worker
111*e07d83d3SAndroid Build Coastguard Worker#### Getting details for a service
112*e07d83d3SAndroid Build Coastguard Worker```bash
113*e07d83d3SAndroid Build Coastguard Workerbin/grpcdebug/grpcdebug localhost:50051 channelz server 2
114*e07d83d3SAndroid Build Coastguard Worker```
115*e07d83d3SAndroid Build Coastguard Worker
116*e07d83d3SAndroid Build Coastguard WorkerThe output will include more communication details and will show socket ids for
117*e07d83d3SAndroid Build Coastguard Workercurrently connected clients
118*e07d83d3SAndroid Build Coastguard Worker
119*e07d83d3SAndroid Build Coastguard Worker```text
120*e07d83d3SAndroid Build Coastguard WorkerServer Id:           2
121*e07d83d3SAndroid Build Coastguard WorkerListen Addresses:    [[::]:50051]
122*e07d83d3SAndroid Build Coastguard WorkerCalls Started:       33
123*e07d83d3SAndroid Build Coastguard WorkerCalls Succeeded:     29
124*e07d83d3SAndroid Build Coastguard WorkerCalls Failed:        3
125*e07d83d3SAndroid Build Coastguard WorkerLast Call Started:   now
126*e07d83d3SAndroid Build Coastguard Worker---
127*e07d83d3SAndroid Build Coastguard WorkerSocket ID   Local->Remote              Streams(Started/Succeeded/Failed)   Messages(Sent/Received)
128*e07d83d3SAndroid Build Coastguard Worker19          [::1]:50051->[::1]:39834   4/3/0                               3/4
129*e07d83d3SAndroid Build Coastguard Worker```
130*e07d83d3SAndroid Build Coastguard Worker
131*e07d83d3SAndroid Build Coastguard Worker#### Displaying detailed info for a server side connection (socket)
132*e07d83d3SAndroid Build Coastguard Worker
133*e07d83d3SAndroid Build Coastguard Worker```bash
134*e07d83d3SAndroid Build Coastguard Workerbin/grpcdebug/grpcdebug localhost:50051 channelz socket 19
135*e07d83d3SAndroid Build Coastguard Worker```
136*e07d83d3SAndroid Build Coastguard Worker
137*e07d83d3SAndroid Build Coastguard WorkerThis will show a lot of gRPC internal information
138*e07d83d3SAndroid Build Coastguard Worker
139*e07d83d3SAndroid Build Coastguard Worker```text
140*e07d83d3SAndroid Build Coastguard WorkerSocket ID:                       19
141*e07d83d3SAndroid Build Coastguard WorkerAddress:                         [::1]:50051->[::1]:50094
142*e07d83d3SAndroid Build Coastguard WorkerStreams Started:                 1
143*e07d83d3SAndroid Build Coastguard WorkerStreams Succeeded:               0
144*e07d83d3SAndroid Build Coastguard WorkerStreams Failed:                  0
145*e07d83d3SAndroid Build Coastguard WorkerMessages Sent:                   0
146*e07d83d3SAndroid Build Coastguard WorkerMessages Received:               1
147*e07d83d3SAndroid Build Coastguard WorkerKeep Alives Sent:                0
148*e07d83d3SAndroid Build Coastguard WorkerLast Local Stream Created:
149*e07d83d3SAndroid Build Coastguard WorkerLast Remote Stream Created:      now
150*e07d83d3SAndroid Build Coastguard WorkerLast Message Sent Created:
151*e07d83d3SAndroid Build Coastguard WorkerLast Message Received Created:   now
152*e07d83d3SAndroid Build Coastguard WorkerLocal Flow Control Window:       65535
153*e07d83d3SAndroid Build Coastguard WorkerRemote Flow Control Window:      1048569
154*e07d83d3SAndroid Build Coastguard Worker---
155*e07d83d3SAndroid Build Coastguard WorkerSocket Options Name                                                                Value
156*e07d83d3SAndroid Build Coastguard WorkerSO_LINGER                                                                          [type.googleapis.com/grpc.channelz.v1.SocketOptionLinger]:{}
157*e07d83d3SAndroid Build Coastguard Workerio.grpc.netty.shaded.io.netty.channel.epoll.EpollChannelOption#TCP_CORK            false
158*e07d83d3SAndroid Build Coastguard WorkerWRITE_BUFFER_HIGH_WATER_MARK                                                       65536
159*e07d83d3SAndroid Build Coastguard WorkerWRITE_BUFFER_LOW_WATER_MARK                                                        32768
160*e07d83d3SAndroid Build Coastguard WorkerIP_TOS                                                                             0
161*e07d83d3SAndroid Build Coastguard Workerio.grpc.netty.shaded.io.netty.channel.epoll.EpollChannelOption#TCP_KEEPCNT         9
162*e07d83d3SAndroid Build Coastguard WorkerSINGLE_EVENTEXECUTOR_PER_GROUP                                                     true
163*e07d83d3SAndroid Build Coastguard WorkerSO_SNDBUF                                                                          2626560
164*e07d83d3SAndroid Build Coastguard Workerio.grpc.netty.shaded.io.netty.channel.epoll.EpollChannelOption#TCP_NOTSENT_LOWAT   0
165*e07d83d3SAndroid Build Coastguard WorkerWRITE_BUFFER_WATER_MARK                                                            WriteBufferWaterMark(low: 32768, high: 65536)
166*e07d83d3SAndroid Build Coastguard WorkerTCP_NODELAY                                                                        true
167*e07d83d3SAndroid Build Coastguard WorkerSO_RCVBUF                                                                          131072
168*e07d83d3SAndroid Build Coastguard Workerio.grpc.netty.shaded.io.netty.channel.epoll.EpollChannelOption#SO_BUSY_POLL        0
169*e07d83d3SAndroid Build Coastguard WorkerIP_TRANSPARENT                                                                     false
170*e07d83d3SAndroid Build Coastguard WorkerSO_KEEPALIVE                                                                       true
171*e07d83d3SAndroid Build Coastguard Workerio.grpc.netty.shaded.io.netty.channel.epoll.EpollChannelOption#TCP_QUICKACK        false
172*e07d83d3SAndroid Build Coastguard WorkerALLOCATOR                                                                          PooledByteBufAllocator(directByDefault: true)
173*e07d83d3SAndroid Build Coastguard WorkerTCP_FASTOPEN_CONNECT                                                               false
174*e07d83d3SAndroid Build Coastguard WorkerMESSAGE_SIZE_ESTIMATOR                                                             io.grpc.netty.shaded.io.netty.channel.DefaultMessageSizeEstimator@48d475b6
175*e07d83d3SAndroid Build Coastguard WorkerWRITE_SPIN_COUNT                                                                   16
176*e07d83d3SAndroid Build Coastguard WorkerSO_REUSEADDR                                                                       true
177*e07d83d3SAndroid Build Coastguard WorkerCONNECT_TIMEOUT_MILLIS                                                             30000
178*e07d83d3SAndroid Build Coastguard WorkerALLOW_HALF_CLOSURE                                                                 false
179*e07d83d3SAndroid Build Coastguard Workerio.grpc.netty.shaded.io.netty.channel.epoll.EpollChannelOption#EPOLL_MODE          EDGE_TRIGGERED
180*e07d83d3SAndroid Build Coastguard WorkerMAX_MESSAGES_PER_READ                                                              16
181*e07d83d3SAndroid Build Coastguard Workerio.grpc.netty.shaded.io.netty.channel.epoll.EpollChannelOption#TCP_KEEPIDLE        7200
182*e07d83d3SAndroid Build Coastguard WorkerAUTO_CLOSE                                                                         true
183*e07d83d3SAndroid Build Coastguard Workerio.grpc.netty.shaded.io.netty.channel.epoll.EpollChannelOption#TCP_KEEPINTVL       75
184*e07d83d3SAndroid Build Coastguard WorkerMAX_MESSAGES_PER_WRITE                                                             2147483647
185*e07d83d3SAndroid Build Coastguard WorkerAUTO_READ                                                                          true
186*e07d83d3SAndroid Build Coastguard WorkerTCP_MD5SIG                                                                         null
187*e07d83d3SAndroid Build Coastguard WorkerRCVBUF_ALLOCATOR                                                                   io.grpc.netty.shaded.io.netty.channel.AdaptiveRecvByteBufAllocator@360691a0
188*e07d83d3SAndroid Build Coastguard Worker```
189*e07d83d3SAndroid Build Coastguard Worker#### Displaying the list of gRPC client channels
190*e07d83d3SAndroid Build Coastguard WorkerCommand
191*e07d83d3SAndroid Build Coastguard Worker```bash
192*e07d83d3SAndroid Build Coastguard Workerbin/grpcdebug/grpcdebug localhost:50051 channelz channels
193*e07d83d3SAndroid Build Coastguard Worker```
194*e07d83d3SAndroid Build Coastguard WorkerOutput
195*e07d83d3SAndroid Build Coastguard Worker```text
196*e07d83d3SAndroid Build Coastguard WorkerChannel ID   Target            State     Calls(Started/Succeeded/Failed)   Created Time
197*e07d83d3SAndroid Build Coastguard Worker1            localhost:50051   READY     34/34/0
198*e07d83d3SAndroid Build Coastguard Worker3            localhost:50051   READY     16/16/0
199*e07d83d3SAndroid Build Coastguard Worker```
200*e07d83d3SAndroid Build Coastguard WorkerNote:  If you have a simple server that doesn't use gRPC clients to contact other
201*e07d83d3SAndroid Build Coastguard Workerservers, then this table will be empty.
202*e07d83d3SAndroid Build Coastguard Worker
203*e07d83d3SAndroid Build Coastguard Worker#### Displaying details of a gRPC client channel
204*e07d83d3SAndroid Build Coastguard WorkerCommand
205*e07d83d3SAndroid Build Coastguard Worker```bash
206*e07d83d3SAndroid Build Coastguard Workerbin/grpcdebug/grpcdebug localhost:50051 channelz channel 3
207*e07d83d3SAndroid Build Coastguard Worker```
208*e07d83d3SAndroid Build Coastguard WorkerOutput
209*e07d83d3SAndroid Build Coastguard Worker```text
210*e07d83d3SAndroid Build Coastguard WorkerChannel ID:        3
211*e07d83d3SAndroid Build Coastguard WorkerTarget:            localhost:50051
212*e07d83d3SAndroid Build Coastguard WorkerState:             READY
213*e07d83d3SAndroid Build Coastguard WorkerCalls Started:     16
214*e07d83d3SAndroid Build Coastguard WorkerCalls Succeeded:   16
215*e07d83d3SAndroid Build Coastguard WorkerCalls Failed:      0
216*e07d83d3SAndroid Build Coastguard WorkerCreated Time:
217*e07d83d3SAndroid Build Coastguard Worker---
218*e07d83d3SAndroid Build Coastguard WorkerSubchannel ID   Target                                               State     Calls(Started/Succeeded/Failed)   CreatedTime
219*e07d83d3SAndroid Build Coastguard Worker10              [[[localhost/127.0.0.1:50051]/{}], [[localhost/0:0   READY     16/16/0
220*e07d83d3SAndroid Build Coastguard Worker```
221*e07d83d3SAndroid Build Coastguard Worker
222*e07d83d3SAndroid Build Coastguard Worker#### Displaying details of a gRPC client subchannel
223*e07d83d3SAndroid Build Coastguard WorkerCommand
224*e07d83d3SAndroid Build Coastguard Worker```bash
225*e07d83d3SAndroid Build Coastguard Workerbin/grpcdebug/grpcdebug localhost:50051 channelz subchannel 10
226*e07d83d3SAndroid Build Coastguard Worker```
227*e07d83d3SAndroid Build Coastguard WorkerOutput
228*e07d83d3SAndroid Build Coastguard Worker```text
229*e07d83d3SAndroid Build Coastguard WorkerSubchannel ID:     10
230*e07d83d3SAndroid Build Coastguard WorkerTarget:            [[[localhost/127.0.0.1:50051]/{}], [[localhost/0:0:0:0:0:0:0:1:50051]/{}]]
231*e07d83d3SAndroid Build Coastguard WorkerState:             READY
232*e07d83d3SAndroid Build Coastguard WorkerCalls Started:     16
233*e07d83d3SAndroid Build Coastguard WorkerCalls Succeeded:   16
234*e07d83d3SAndroid Build Coastguard WorkerCalls Failed:      0
235*e07d83d3SAndroid Build Coastguard WorkerCreated Time:
236*e07d83d3SAndroid Build Coastguard Worker---
237*e07d83d3SAndroid Build Coastguard WorkerSocket ID   Local->Remote                      Streams(Started/Succeeded/Failed)   Messages(Sent/Received)
238*e07d83d3SAndroid Build Coastguard Worker11          127.0.0.1:48536->127.0.0.1:50051   16/16/0                             12/12
239*e07d83d3SAndroid Build Coastguard Worker```