From 559023c01d74008b6029c3c3debd748665f630cb Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Wed, 12 Jun 2019 15:05:01 -0700 Subject: [PATCH] Adopt reviewer's advice --- examples/python/debug/README.md | 37 ++++++++++++++++++++++----- examples/python/debug/debug_server.py | 5 ++-- examples/python/debug/get_stats.py | 3 --- examples/python/debug/send_message.py | 3 --- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/examples/python/debug/README.md b/examples/python/debug/README.md index db57c79de84..ceed31ef767 100644 --- a/examples/python/debug/README.md +++ b/examples/python/debug/README.md @@ -1,13 +1,21 @@ # gRPC Python Debug Example -This example demonstrate the usage of Channelz. For a better looking website, the [gdebug](https://github.com/grpc/grpc-experiments/tree/master/gdebug) uses gRPC-Web protocol and will serve all useful information in web pages. +This example demonstrate the usage of Channelz. For a better looking website, +the [gdebug](https://github.com/grpc/grpc-experiments/tree/master/gdebug) uses +gRPC-Web protocol and will serve all useful information in web pages. ## Channelz: Live Channel Tracing -Channelz is a channel tracing feature. It will track statistics like how many messages have been sent, how many of them failed, what are the connected sockets. Since it is implemented in C-Core and has low-overhead, it is recommended to turn on for production services. See [Channelz design doc](https://github.com/grpc/proposal/blob/master/A14-channelz.md). +Channelz is a channel tracing feature. It will track statistics like how many +messages have been sent, how many of them failed, what are the connected +sockets. Since it is implemented in C-Core and has low-overhead, it is +recommended to turn on for production services. See [Channelz design +doc](https://github.com/grpc/proposal/blob/master/A14-channelz.md). ## How to enable tracing log -The tracing log generation might have larger overhead, especially when you try to trace transport. It would result in replicating the traffic loads. However, it is still the most powerful tool when you need to dive in. +The tracing log generation might have larger overhead, especially when you try +to trace transport. It would result in replicating the traffic loads. However, +it is still the most powerful tool when you need to dive in. ### The Most Verbose Tracing Log @@ -18,7 +26,8 @@ GRPC_VERBOSITY=debug GRPC_TRACE=all ``` -For more granularity, please see [environment_variables](https://github.com/grpc/grpc/blob/master/doc/environment_variables.md). +For more granularity, please see +[environment_variables](https://github.com/grpc/grpc/blob/master/doc/environment_variables.md). ### Debug Transport Protocol @@ -36,8 +45,24 @@ GRPC_TRACE=call_error,connectivity_state,pick_first,round_robin,glb ## How to debug your application? -`pdb` is a debugging tool that is available for Python interpreters natively. You can set breakpoint, and execute commands while the application is stopped. +`pdb` is a debugging tool that is available for Python interpreters natively. +You can set breakpoint, and execute commands while the application is stopped. -The simplest usage is add a single line in the place you want to inspect: `import pdb; pdb.set_trace()`. When interpreter see this line, it would pop out a interactive command line interface for you to inspect the application state. +The simplest usage is add a single line in the place you want to inspect: +`import pdb; pdb.set_trace()`. When interpreter see this line, it would pop out +a interactive command line interface for you to inspect the application state. For more detailed usage, see https://docs.python.org/3/library/pdb.html. + +**Caveat**: gRPC Python uses C-Extension under-the-hood, so `pdb` may not be +able to trace through the whole stack. + +## gRPC Command Line Tool + +`grpc_cli` is a handy tool to interact with gRPC backend easily. Imageine you can +inspect what service does a server provide without writing any code, and make +gRPC calls just like `curl`. + +The installation guide: https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md#code-location +The usage guide: https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md#usage +The source code: https://github.com/grpc/grpc/blob/master/test/cpp/util/grpc_cli.cc diff --git a/examples/python/debug/debug_server.py b/examples/python/debug/debug_server.py index 2866d284267..64926b53457 100644 --- a/examples/python/debug/debug_server.py +++ b/examples/python/debug/debug_server.py @@ -45,12 +45,11 @@ class FaultInjectGreeter(helloworld_pb2_grpc.GreeterServicer): if random.random() < self._failure_rate: context.abort(grpc.StatusCode.UNAVAILABLE, 'Randomly injected failure.') - return helloworld_pb2.HelloReply( - message='Hello, %s!' % request.name) + return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name) def create_server(addr, failure_rate): - server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) + server = grpc.server(futures.ThreadPoolExecutor()) helloworld_pb2_grpc.add_GreeterServicer_to_server( FaultInjectGreeter(failure_rate), server) diff --git a/examples/python/debug/get_stats.py b/examples/python/debug/get_stats.py index 22924098d51..d0b7061c54f 100644 --- a/examples/python/debug/get_stats.py +++ b/examples/python/debug/get_stats.py @@ -25,9 +25,6 @@ from grpc_channelz.v1 import channelz_pb2_grpc def run(addr): - # NOTE(gRPC Python Team): .close() is possible on a channel and should be - # used in circumstances in which the with statement does not fit the needs - # of the code. with grpc.insecure_channel(addr) as channel: channelz_stub = channelz_pb2_grpc.ChannelzStub(channel) response = channelz_stub.GetServers( diff --git a/examples/python/debug/send_message.py b/examples/python/debug/send_message.py index 99425263b50..3bad52c8fac 100644 --- a/examples/python/debug/send_message.py +++ b/examples/python/debug/send_message.py @@ -34,9 +34,6 @@ def process(stub, request): def run(addr, n): - # NOTE(gRPC Python Team): .close() is possible on a channel and should be - # used in circumstances in which the with statement does not fit the needs - # of the code. with grpc.insecure_channel(addr) as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) request = helloworld_pb2.HelloRequest(name='you')