diff options
author | Tanvi Jagtap <139093547+tanvi-jagtap@users.noreply.github.com> | 2024-05-09 22:16:01 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-05-09 22:18:42 -0700 |
commit | b943668f95268827966fa546c2611277360b9578 (patch) | |
tree | 55c20d071b457ebae2cdd2748c65fd28833b25dd | |
parent | bc4766381ae2331c24b0eaa8fb24894d8c5c7289 (diff) | |
download | grpc-grpc-b943668f95268827966fa546c2611277360b9578.tar.gz |
[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging - gpr_log (#36570)
[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging - gpr_log
In this CL we are migrating from gRPCs own gpr logging mechanism to absl logging mechanism. The intention is to deprecate gpr_log in the future.
We have the following mapping
1. gpr_log(GPR_INFO,...) -> LOG(INFO)
2. gpr_log(GPR_ERROR,...) -> LOG(ERROR)
3. gpr_log(GPR_DEBUG,...) -> VLOG(2)
Reviewers need to check :
1. If the above mapping is correct.
2. The content of the log is as before.
gpr_log format strings did not use string_view or std::string . absl LOG accepts these. So there will be some elimination of string_view and std::string related conversions. This is expected.
Closes #36570
COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36570 from tanvi-jagtap:test_cpp_interop_tjagtap c50744629540020e2bb0e27158a6437d82c5bc64
PiperOrigin-RevId: 632375773
-rw-r--r-- | test/cpp/interop/BUILD | 2 | ||||
-rw-r--r-- | test/cpp/interop/grpclb_fallback_test.cc | 40 | ||||
-rw-r--r-- | test/cpp/interop/http2_client.cc | 33 |
3 files changed, 38 insertions, 37 deletions
diff --git a/test/cpp/interop/BUILD b/test/cpp/interop/BUILD index 76b49f88be..21d86d0497 100644 --- a/test/cpp/interop/BUILD +++ b/test/cpp/interop/BUILD @@ -46,6 +46,7 @@ grpc_cc_binary( external_deps = [ "absl/flags:flag", "absl/log:check", + "absl/log:log", "absl/time:time", ], language = "C++", @@ -429,6 +430,7 @@ grpc_cc_binary( external_deps = [ "absl/flags:flag", "absl/log:check", + "absl/log:log", ], deps = [ "//:grpc++", diff --git a/test/cpp/interop/grpclb_fallback_test.cc b/test/cpp/interop/grpclb_fallback_test.cc index c8e20fdc54..331885e8c0 100644 --- a/test/cpp/interop/grpclb_fallback_test.cc +++ b/test/cpp/interop/grpclb_fallback_test.cc @@ -32,11 +32,11 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include "absl/time/time.h" #include <grpc/support/alloc.h> -#include <grpc/support/log.h> #include <grpc/support/port_platform.h> #include <grpcpp/channel.h> #include <grpcpp/client_context.h> @@ -87,8 +87,8 @@ enum RpcMode { GrpclbRouteType DoRPCAndGetPath(TestService::Stub* stub, int deadline_seconds, RpcMode rpc_mode) { - gpr_log(GPR_INFO, "DoRPCAndGetPath deadline_seconds:%d rpc_mode:%d", - deadline_seconds, rpc_mode); + LOG(INFO) << "DoRPCAndGetPath deadline_seconds:" << deadline_seconds + << " rpc_mode:" << rpc_mode; SimpleRequest request; SimpleResponse response; grpc::ClientContext context; @@ -101,16 +101,16 @@ GrpclbRouteType DoRPCAndGetPath(TestService::Stub* stub, int deadline_seconds, context.set_deadline(deadline); grpc::Status s = stub->UnaryCall(&context, request, &response); if (!s.ok()) { - gpr_log(GPR_INFO, "DoRPCAndGetPath failed. status-message: %s", - s.error_message().c_str()); + LOG(INFO) << "DoRPCAndGetPath failed. status-message: " + << s.error_message(); return GrpclbRouteType::GRPCLB_ROUTE_TYPE_UNKNOWN; } CHECK(response.grpclb_route_type() == GrpclbRouteType::GRPCLB_ROUTE_TYPE_BACKEND || response.grpclb_route_type() == GrpclbRouteType::GRPCLB_ROUTE_TYPE_FALLBACK); - gpr_log(GPR_INFO, "DoRPCAndGetPath done. grpclb_route_type:%d", - response.grpclb_route_type()); + LOG(INFO) << "DoRPCAndGetPath done. grpclb_route_type:" + << response.grpclb_route_type(); return response.grpclb_route_type(); } @@ -120,7 +120,7 @@ GrpclbRouteType DoRPCAndGetPath(TestService::Stub* stub, int deadline_seconds) { bool TcpUserTimeoutMutateFd(int fd, grpc_socket_mutator* /*mutator*/) { int timeout = 20000; // 20 seconds - gpr_log(GPR_INFO, "Setting socket option TCP_USER_TIMEOUT on fd: %d", fd); + LOG(INFO) << "Setting socket option TCP_USER_TIMEOUT on fd: " << fd; if (0 != setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout, sizeof(timeout))) { grpc_core::Crash("Failed to set socket option TCP_USER_TIMEOUT"); @@ -161,7 +161,7 @@ std::unique_ptr<TestService::Stub> CreateFallbackTestStub() { } void RunCommand(const std::string& command) { - gpr_log(GPR_INFO, "RunCommand: |%s|", command.c_str()); + LOG(INFO) << "RunCommand: |" << command << "|"; int out = std::system(command.c_str()); if (WIFEXITED(out)) { int code = WEXITSTATUS(out); @@ -185,25 +185,23 @@ void WaitForFallbackAndDoRPCs(TestService::Stub* stub) { while (absl::Now() < fallback_deadline) { GrpclbRouteType grpclb_route_type = DoRPCAndGetPath(stub, 1); if (grpclb_route_type == GrpclbRouteType::GRPCLB_ROUTE_TYPE_BACKEND) { - gpr_log(GPR_ERROR, - "Got grpclb route type backend. Backends are " - "supposed to be unreachable, so this test is broken"); + LOG(ERROR) << "Got grpclb route type backend. Backends are " + "supposed to be unreachable, so this test is broken"; CHECK(0); } if (grpclb_route_type == GrpclbRouteType::GRPCLB_ROUTE_TYPE_FALLBACK) { - gpr_log(GPR_INFO, - "Made one successful RPC to a fallback. Now expect the same for " - "the rest."); + LOG(INFO) << "Made one successful RPC to a fallback. Now expect the same " + "for the rest."; fallback = true; break; } else { - gpr_log(GPR_ERROR, "Retryable RPC failure on iteration: %d", - fallback_retry_count); + LOG(ERROR) << "Retryable RPC failure on iteration: " + << fallback_retry_count; } fallback_retry_count++; } if (!fallback) { - gpr_log(GPR_ERROR, "Didn't fall back within deadline"); + LOG(ERROR) << "Didn't fall back within deadline"; CHECK(0); } for (int i = 0; i < 30; i++) { @@ -231,13 +229,13 @@ void DoFallbackAfterStartupTest() { int main(int argc, char** argv) { grpc::testing::InitTest(&argc, &argv, true); - gpr_log(GPR_INFO, "Testing: %s", absl::GetFlag(FLAGS_test_case).c_str()); + LOG(INFO) << "Testing: " << absl::GetFlag(FLAGS_test_case); if (absl::GetFlag(FLAGS_test_case) == "fallback_before_startup") { DoFallbackBeforeStartupTest(); - gpr_log(GPR_INFO, "DoFallbackBeforeStartup done!"); + LOG(INFO) << "DoFallbackBeforeStartup done!"; } else if (absl::GetFlag(FLAGS_test_case) == "fallback_after_startup") { DoFallbackAfterStartupTest(); - gpr_log(GPR_INFO, "DoFallbackBeforeStartup done!"); + LOG(INFO) << "DoFallbackBeforeStartup done!"; } else { grpc_core::Crash(absl::StrFormat("Invalid test case: %s", absl::GetFlag(FLAGS_test_case).c_str())); diff --git a/test/cpp/interop/http2_client.cc b/test/cpp/interop/http2_client.cc index eb96a08b71..89477f3cd5 100644 --- a/test/cpp/interop/http2_client.cc +++ b/test/cpp/interop/http2_client.cc @@ -22,10 +22,10 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include <grpc/support/alloc.h> -#include <grpc/support/log.h> #include <grpcpp/channel.h> #include <grpcpp/client_context.h> @@ -81,40 +81,40 @@ SimpleRequest Http2Client::BuildDefaultRequest() { } bool Http2Client::DoRstAfterHeader() { - gpr_log(GPR_DEBUG, "Sending RPC and expecting reset stream after header"); + VLOG(2) << "Sending RPC and expecting reset stream after header"; SimpleResponse response; AssertStatusCode(SendUnaryCall(&response), grpc::StatusCode::INTERNAL); CHECK(!response.has_payload()); // no data should be received - gpr_log(GPR_DEBUG, "Done testing reset stream after header"); + VLOG(2) << "Done testing reset stream after header"; return true; } bool Http2Client::DoRstAfterData() { - gpr_log(GPR_DEBUG, "Sending RPC and expecting reset stream after data"); + VLOG(2) << "Sending RPC and expecting reset stream after data"; SimpleResponse response; AssertStatusCode(SendUnaryCall(&response), grpc::StatusCode::INTERNAL); // There is no guarantee that data would be received. - gpr_log(GPR_DEBUG, "Done testing reset stream after data"); + VLOG(2) << "Done testing reset stream after data"; return true; } bool Http2Client::DoRstDuringData() { - gpr_log(GPR_DEBUG, "Sending RPC and expecting reset stream during data"); + VLOG(2) << "Sending RPC and expecting reset stream during data"; SimpleResponse response; AssertStatusCode(SendUnaryCall(&response), grpc::StatusCode::INTERNAL); CHECK(!response.has_payload()); // no data should be received - gpr_log(GPR_DEBUG, "Done testing reset stream during data"); + VLOG(2) << "Done testing reset stream during data"; return true; } bool Http2Client::DoGoaway() { - gpr_log(GPR_DEBUG, "Sending two RPCs and expecting goaway"); + VLOG(2) << "Sending two RPCs and expecting goaway"; SimpleResponse response; AssertStatusCode(SendUnaryCall(&response), grpc::StatusCode::OK); CHECK(response.payload().body() == std::string(kLargeResponseSize, '\0')); @@ -127,16 +127,16 @@ bool Http2Client::DoGoaway() { response.Clear(); AssertStatusCode(SendUnaryCall(&response), grpc::StatusCode::OK); CHECK(response.payload().body() == std::string(kLargeResponseSize, '\0')); - gpr_log(GPR_DEBUG, "Done testing goaway"); + VLOG(2) << "Done testing goaway"; return true; } bool Http2Client::DoPing() { - gpr_log(GPR_DEBUG, "Sending RPC and expecting ping"); + VLOG(2) << "Sending RPC and expecting ping"; SimpleResponse response; AssertStatusCode(SendUnaryCall(&response), grpc::StatusCode::OK); CHECK(response.payload().body() == std::string(kLargeResponseSize, '\0')); - gpr_log(GPR_DEBUG, "Done testing ping"); + VLOG(2) << "Done testing ping"; return true; } @@ -148,7 +148,7 @@ void Http2Client::MaxStreamsWorker( } bool Http2Client::DoMaxStreams() { - gpr_log(GPR_DEBUG, "Testing max streams"); + VLOG(2) << "Testing max streams"; // Make an initial call on the channel to ensure the server's max streams // setting is received @@ -167,7 +167,7 @@ bool Http2Client::DoMaxStreams() { it->join(); } - gpr_log(GPR_DEBUG, "Done testing max streams"); + VLOG(2) << "Done testing max streams"; return true; } @@ -198,7 +198,7 @@ int main(int argc, char** argv) { CHECK(channel->WaitForConnected(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(300, GPR_TIMESPAN)))); grpc::testing::Http2Client client(channel); - gpr_log(GPR_INFO, "Testing case: %s", absl::GetFlag(FLAGS_test_case).c_str()); + LOG(INFO) << "Testing case: " << absl::GetFlag(FLAGS_test_case); int ret = 0; if (absl::GetFlag(FLAGS_test_case) == "rst_after_header") { client.DoRstAfterHeader(); @@ -219,8 +219,9 @@ int main(int argc, char** argv) { char* joined_testcases = gpr_strjoin_sep(testcases, GPR_ARRAY_SIZE(testcases), "\n", nullptr); - gpr_log(GPR_ERROR, "Unsupported test case %s. Valid options are\n%s", - absl::GetFlag(FLAGS_test_case).c_str(), joined_testcases); + LOG(ERROR) << "Unsupported test case " << absl::GetFlag(FLAGS_test_case) + << ". Valid options are\n" + << joined_testcases; gpr_free(joined_testcases); ret = 1; } |