From f57879ac5641edb9e6879ef815a77fd1ffff5ce7 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Wed, 22 Jul 2020 21:22:05 -0700 Subject: [PATCH] Flag protect new logs --- test/cpp/util/grpc_cli.cc | 2 ++ test/cpp/util/grpc_tool.cc | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/test/cpp/util/grpc_cli.cc b/test/cpp/util/grpc_cli.cc index 5c840ff540d..614a578cc28 100644 --- a/test/cpp/util/grpc_cli.cc +++ b/test/cpp/util/grpc_cli.cc @@ -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 diff --git a/test/cpp/util/grpc_tool.cc b/test/cpp/util/grpc_tool.cc index 4d2a8dd853b..27a9bdc3665 100644 --- a/test/cpp/util/grpc_tool.cc +++ b/test/cpp/util/grpc_tool.cc @@ -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,8 +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); - fprintf(stderr, "New call for method_name:%s has peer address:|%s|\n", - formatted_method_name.c_str(), call.peer().c_str()); + 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))) { @@ -672,8 +678,11 @@ bool GrpcTool::CallMethod(int argc, const char** argv, std::multimap server_initial_metadata, server_trailing_metadata; CliCall call(channel, formatted_method_name, client_metadata); - fprintf(stderr, "New call for method_name:%s has peer address:|%s|\n", - formatted_method_name.c_str(), call.peer().c_str()); + 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, @@ -772,8 +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); - fprintf(stderr, "New call for method_name:%s has peer address:|%s|\n", - formatted_method_name.c_str(), call.peer().c_str()); + 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();