Merge pull request #23557 from apolcyn/display_peer_address

Log the peer address of grpc_cli CallMethod RPCs to stderr
pull/23599/head
apolcyn 5 years ago committed by GitHub
commit 7e7a48f863
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      test/cpp/util/cli_call.h
  2. 2
      test/cpp/util/grpc_cli.cc
  3. 17
      test/cpp/util/grpc_tool.cc

@ -84,6 +84,8 @@ class CliCall final {
// Finish the RPC.
Status Finish(IncomingMetadataContainer* server_trailing_metadata);
std::string peer() const { return ctx_.peer(); }
private:
std::unique_ptr<grpc::GenericStub> stub_;
grpc_impl::ClientContext ctx_;

@ -54,6 +54,8 @@
10. --default_service_config, optional default service config to use
on the channel. Note that this may be ignored if the name resolver
returns a service config.
11. --display_peer_address, on CallMethod commands, log the peer socket
address of the connection that each RPC is made on to stderr.
*/
#include <fstream>

@ -62,6 +62,10 @@ DEFINE_string(
"Default service config to use on the channel, if non-empty. Note "
"that this will be ignored if the name resolver returns a service "
"config.");
DEFINE_bool(
display_peer_address, false,
"Log the peer socket address of the connection that each RPC is made "
"on to stderr.");
DEFINE_bool(json_input, false, "Input in json format");
DEFINE_bool(json_output, false, "Output in json format");
DEFINE_string(infile, "", "Input file (default is stdin)");
@ -541,6 +545,10 @@ bool GrpcTool::CallMethod(int argc, const char** argv,
PrintMetadata(client_metadata, "Sending client initial metadata:");
CliCall call(channel, formatted_method_name, client_metadata);
if (FLAGS_display_peer_address) {
fprintf(stderr, "New call for method_name:%s has peer address:|%s|\n",
formatted_method_name.c_str(), call.peer().c_str());
}
if (FLAGS_infile.empty()) {
if (isatty(fileno(stdin))) {
@ -670,6 +678,11 @@ bool GrpcTool::CallMethod(int argc, const char** argv,
std::multimap<grpc::string_ref, grpc::string_ref>
server_initial_metadata, server_trailing_metadata;
CliCall call(channel, formatted_method_name, client_metadata);
if (FLAGS_display_peer_address) {
fprintf(stderr,
"New call for method_name:%s has peer address:|%s|\n",
formatted_method_name.c_str(), call.peer().c_str());
}
call.Write(serialized_request_proto);
call.WritesDone();
if (!call.Read(&serialized_response_proto,
@ -768,6 +781,10 @@ bool GrpcTool::CallMethod(int argc, const char** argv,
PrintMetadata(client_metadata, "Sending client initial metadata:");
CliCall call(channel, formatted_method_name, client_metadata);
if (FLAGS_display_peer_address) {
fprintf(stderr, "New call for method_name:%s has peer address:|%s|\n",
formatted_method_name.c_str(), call.peer().c_str());
}
call.Write(serialized_request_proto);
call.WritesDone();

Loading…
Cancel
Save