File tree 3 files changed +15
-26
lines changed
examples/features/debugging
3 files changed +15
-26
lines changed Original file line number Diff line number Diff line change 1
1
# Debugging
2
2
3
+ Currently, grpc provides two major tools to help user debug issues, which are logging and channelz.
4
+
5
+ ## Logs
3
6
gRPC has put substantial logging instruments on critical paths of gRPC to help users debug issues.
4
7
The [ Log Levels] ( https://github.com/grpc/grpc-go/blob/master/Documentation/log_levels.md ) doc describes
5
8
what each log level means in the gRPC context.
6
9
7
- We also provides a runtime debugging tool, Channelz, to help users with live debugging.
8
-
9
- ## Logs
10
10
To turn on the logs for debugging, run the code with the following environment variable:
11
11
` GRPC_GO_LOG_VERBOSITY_LEVEL=99 GRPC_GO_LOG_SEVERITY_LEVEL=info ` .
12
12
13
13
## Channelz
14
+ We also provides a runtime debugging tool, Channelz, to help users with live debugging.
15
+
14
16
See the channelz blog post here ([ link] ( https://grpc.io/blog/a_short_introduction_to_channelz ) ) for
15
17
details about how to use channelz service to debug live program.
16
18
Original file line number Diff line number Diff line change 16
16
*
17
17
*/
18
18
19
+ // Binary client is an example client.
19
20
package main
20
21
21
22
import (
22
23
"log"
23
24
"net"
24
25
"os"
25
- "os/signal"
26
26
"time"
27
27
28
28
"golang.org/x/net/context"
@@ -39,10 +39,11 @@ const (
39
39
40
40
func main () {
41
41
/***** Set up the server serving channelz service. *****/
42
- lis , err := net .Listen ("tcp" , ":50050 " )
42
+ lis , err := net .Listen ("tcp" , ":50052 " )
43
43
if err != nil {
44
44
log .Fatalf ("failed to listen: %v" , err )
45
45
}
46
+ defer lis .Close ()
46
47
s := grpc .NewServer ()
47
48
service .RegisterChannelzServiceToServer (s )
48
49
go s .Serve (lis )
@@ -81,11 +82,8 @@ func main() {
81
82
}
82
83
}
83
84
84
- /***** Wait for CTRL+C to exit *****/
85
- // Unless you exit the program with CTRL+C, channelz data will be available for querying.
85
+ /***** Wait for user exiting the program *****/
86
+ // Unless you exit the program (e.g. CTRL+C) , channelz data will be available for querying.
86
87
// Users can take time to examine and learn about the info provided by channelz.
87
- ch := make (chan os.Signal , 1 )
88
- signal .Notify (ch , os .Interrupt )
89
- // Block until a signal is received.
90
- <- ch
88
+ select {}
91
89
}
Original file line number Diff line number Diff line change 16
16
*
17
17
*/
18
18
19
+ // Binary server is an example server.
19
20
package main
20
21
21
22
import (
22
23
"log"
23
24
"net"
24
- "os"
25
- "os/signal"
26
25
"time"
27
26
28
27
"golang.org/x/net/context"
@@ -67,16 +66,13 @@ func main() {
67
66
defer s .Stop ()
68
67
69
68
/***** Start three GreeterServers(with one of them to be the slowServer). *****/
70
- var listeners []net.Listener
71
- var svrs []* grpc.Server
72
69
for i := 0 ; i < 3 ; i ++ {
73
70
lis , err := net .Listen ("tcp" , ports [i ])
74
71
if err != nil {
75
72
log .Fatalf ("failed to listen: %v" , err )
76
73
}
77
- listeners = append ( listeners , lis )
74
+ defer lis . Close ( )
78
75
s := grpc .NewServer ()
79
- svrs = append (svrs , s )
80
76
if i == 2 {
81
77
pb .RegisterGreeterServer (s , & slowServer {})
82
78
} else {
@@ -85,13 +81,6 @@ func main() {
85
81
go s .Serve (lis )
86
82
}
87
83
88
- /***** Wait for CTRL+C to exit *****/
89
- ch := make (chan os.Signal , 1 )
90
- signal .Notify (ch , os .Interrupt )
91
- // Block until a signal is received.
92
- <- ch
93
- for i := 0 ; i < 3 ; i ++ {
94
- svrs [i ].Stop ()
95
- listeners [i ].Close ()
96
- }
84
+ /***** Wait for user exiting the program *****/
85
+ select {}
97
86
}
You can’t perform that action at this time.
0 commit comments