From ed5893120e16e018e4e4efc029dd000c30443c42 Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap <139093547+tanvi-jagtap@users.noreply.github.com> Date: Thu, 16 May 2024 00:34:38 -0700 Subject: [PATCH 01/23] [grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging - gpr_log (#36608) [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 #36608 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36608 from tanvi-jagtap:regex_test_core_misc e6b9481dac3db7ca4cda900eef6c44031680cb8b PiperOrigin-RevId: 634246311 --- .../posix/oracle_event_engine_posix.cc | 21 ++-- test/core/event_engine/windows/iocp_test.cc | 9 +- test/core/gprpp/mpscq_test.cc | 12 +-- test/core/gprpp/single_set_ptr_test.cc | 3 +- test/core/handshake/client_ssl.cc | 20 ++-- test/core/handshake/server_ssl_common.cc | 12 +-- test/core/handshake/verify_peer_options.cc | 4 +- test/core/http/httpcli_test_util.cc | 8 +- test/core/load_balancing/lb_policy_test_lib.h | 98 +++++++++---------- .../load_balancing/outlier_detection_test.cc | 38 +++---- .../weighted_round_robin_test.cc | 26 ++--- .../load_balancing/xds_override_host_test.cc | 29 +++--- .../network_benchmarks/low_level_ping_pong.cc | 76 +++++++------- test/core/promise/party_test.cc | 7 +- test/core/slice/slice_test.cc | 5 +- test/core/surface/completion_queue_test.cc | 6 +- .../completion_queue_threading_test.cc | 42 ++++---- .../surface/concurrent_connectivity_test.cc | 8 +- test/core/test_util/cmdline.h | 4 +- test/core/test_util/reconnect_server.cc | 17 ++-- test/core/test_util/test_config.cc | 17 ++-- .../fake_handshaker/fake_handshaker_server.cc | 10 +- .../alts_concurrent_connectivity_test.cc | 34 +++---- .../alts_handshaker_service_api_test_lib.cc | 9 +- test/core/tsi/ssl_transport_security_test.cc | 69 ++++++------- test/core/xds/xds_client_fuzzer.cc | 70 ++++++------- 26 files changed, 315 insertions(+), 339 deletions(-) diff --git a/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc b/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc index 86e0a6ac033..52eff1798ec 100644 --- a/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc +++ b/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -32,7 +33,6 @@ #include #include -#include #include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/gprpp/crash.h" @@ -255,7 +255,7 @@ bool PosixOracleEndpoint::Write( } void PosixOracleEndpoint::ProcessReadOperations() { - gpr_log(GPR_INFO, "Starting thread to process read ops ..."); + LOG(INFO) << "Starting thread to process read ops ..."; while (true) { read_op_signal_->WaitForNotification(); read_op_signal_ = std::make_unique(); @@ -273,11 +273,11 @@ void PosixOracleEndpoint::ProcessReadOperations() { grpc_core::StrError(saved_errno))) : absl::OkStatus()); } - gpr_log(GPR_INFO, "Shutting down read ops thread ..."); + LOG(INFO) << "Shutting down read ops thread ..."; } void PosixOracleEndpoint::ProcessWriteOperations() { - gpr_log(GPR_INFO, "Starting thread to process write ops ..."); + LOG(INFO) << "Starting thread to process write ops ..."; while (true) { write_op_signal_->WaitForNotification(); write_op_signal_ = std::make_unique(); @@ -293,7 +293,7 @@ void PosixOracleEndpoint::ProcessWriteOperations() { grpc_core::StrError(saved_errno))) : absl::OkStatus()); } - gpr_log(GPR_INFO, "Shutting down write ops thread ..."); + LOG(INFO) << "Shutting down write ops thread ..."; } PosixOracleListener::PosixOracleListener( @@ -341,7 +341,7 @@ PosixOracleListener::~PosixOracleListener() { } void PosixOracleListener::HandleIncomingConnections() { - gpr_log(GPR_INFO, "Starting accept thread ..."); + LOG(INFO) << "Starting accept thread ..."; CHECK(!listener_fds_.empty()); int nfds = listener_fds_.size(); // Add one extra file descriptor to poll the pipe fd. @@ -371,17 +371,16 @@ void PosixOracleListener::HandleIncomingConnections() { // pfds[i].fd has a readable event. int client_sock_fd = accept(pfds[i].fd, nullptr, nullptr); if (client_sock_fd < 0) { - gpr_log(GPR_ERROR, - "Error accepting new connection: %s. Ignoring connection " - "attempt ...", - grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Error accepting new connection: " + << grpc_core::StrError(errno) + << ". Ignoring connection attempt ..."; continue; } on_accept_(PosixOracleEndpoint::Create(client_sock_fd), memory_allocator_factory_->CreateMemoryAllocator("test")); } } - gpr_log(GPR_INFO, "Shutting down accept thread ..."); + LOG(INFO) << "Shutting down accept thread ..."; gpr_free(pfds); } diff --git a/test/core/event_engine/windows/iocp_test.cc b/test/core/event_engine/windows/iocp_test.cc index 787ca180cb0..e96b8d3816d 100644 --- a/test/core/event_engine/windows/iocp_test.cc +++ b/test/core/event_engine/windows/iocp_test.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/time/time.h" #include "absl/types/variant.h" @@ -49,7 +50,7 @@ using ::grpc_event_engine::experimental::WinSocket; // `ASSERT_OK(...) << GetErrorMessage(error, context);` void LogErrorMessage(int messageid, absl::string_view context) { char* utf8_message = gpr_format_message(messageid); - gpr_log(GPR_ERROR, "Error in %s: %s", context, utf8_message); + LOG(ERROR) << "Error in " << context << ": " << utf8_message; gpr_free(utf8_message); } } // namespace @@ -77,7 +78,7 @@ TEST_F(IOCPTest, ClientReceivesNotificationOfServerSend) { DWORD bytes_rcvd; on_read = new AnyInvocableClosure([win_socket = wrapped_client_socket.get(), &read_called, &read_wsabuf]() { - gpr_log(GPR_DEBUG, "Notified on read"); + VLOG(2) << "Notified on read"; EXPECT_GE(win_socket->read_info()->result().bytes_transferred, 10u); EXPECT_STREQ(read_wsabuf.buf, "hello!"); read_called.Notify(); @@ -96,7 +97,7 @@ TEST_F(IOCPTest, ClientReceivesNotificationOfServerSend) { } { on_write = new AnyInvocableClosure([&write_called] { - gpr_log(GPR_DEBUG, "Notified on write"); + VLOG(2) << "Notified on write"; write_called.Notify(); }); wrapped_server_socket->NotifyOnWrite(on_write); @@ -153,7 +154,7 @@ TEST_F(IOCPTest, IocpWorkTimeoutDueToNoNotificationRegistered) { wrapped_client_socket->NotifyOnRead( SelfDeletingClosure::Create([win_socket = wrapped_client_socket.get(), &read_called, &read_wsabuf]() { - gpr_log(GPR_DEBUG, "Notified on read"); + VLOG(2) << "Notified on read"; EXPECT_GE(win_socket->read_info()->result().bytes_transferred, 10u); EXPECT_STREQ(read_wsabuf.buf, "hello!"); read_called.Notify(); diff --git a/test/core/gprpp/mpscq_test.cc b/test/core/gprpp/mpscq_test.cc index 9e2cb410234..1bf92acd189 100644 --- a/test/core/gprpp/mpscq_test.cc +++ b/test/core/gprpp/mpscq_test.cc @@ -23,9 +23,9 @@ #include +#include "absl/log/log.h" #include "gtest/gtest.h" -#include #include #include @@ -49,7 +49,7 @@ static test_node* new_node(size_t i, size_t* ctr) { } TEST(MpscqTest, Serial) { - gpr_log(GPR_DEBUG, "test_serial"); + VLOG(2) << "test_serial"; MultiProducerSingleConsumerQueue q; for (size_t i = 0; i < 10000000; i++) { q.Push(&new_node(i, nullptr)->node); @@ -79,7 +79,7 @@ static void test_thread(void* args) { } TEST(MpscqTest, Mt) { - gpr_log(GPR_DEBUG, "test_mt"); + VLOG(2) << "test_mt"; gpr_event start; gpr_event_init(&start); grpc_core::Thread thds[100]; @@ -106,7 +106,7 @@ TEST(MpscqTest, Mt) { if (tn->i == THREAD_ITERATIONS) num_done++; delete tn; } - gpr_log(GPR_DEBUG, "spins: %" PRIdPTR, spins); + VLOG(2) << "spins: " << spins; for (auto& th : thds) { th.Join(); } @@ -146,7 +146,7 @@ static void pull_thread(void* arg) { } TEST(MpscqTest, MtMultipop) { - gpr_log(GPR_DEBUG, "test_mt_multipop"); + VLOG(2) << "test_mt_multipop"; gpr_event start; gpr_event_init(&start); grpc_core::Thread thds[50]; @@ -176,7 +176,7 @@ TEST(MpscqTest, MtMultipop) { for (auto& pth : pull_thds) { pth.Join(); } - gpr_log(GPR_DEBUG, "spins: %" PRIdPTR, pa.spins); + VLOG(2) << "spins: " << pa.spins; for (auto& th : thds) { th.Join(); } diff --git a/test/core/gprpp/single_set_ptr_test.cc b/test/core/gprpp/single_set_ptr_test.cc index 62108e3df59..b93aa14c3e8 100644 --- a/test/core/gprpp/single_set_ptr_test.cc +++ b/test/core/gprpp/single_set_ptr_test.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/log/log.h" #include "gtest/gtest.h" namespace grpc_core { @@ -28,7 +29,7 @@ TEST(SingleSetPtrTest, NoOp) { SingleSetPtr(); } TEST(SingleSetPtrTest, CanSet) { SingleSetPtr p; EXPECT_FALSE(p.is_set()); - EXPECT_DEATH_IF_SUPPORTED(gpr_log(GPR_ERROR, "%d", *p), ""); + EXPECT_DEATH_IF_SUPPORTED({ LOG(ERROR) << *p; }, ""); p.Set(new int(42)); EXPECT_EQ(*p, 42); } diff --git a/test/core/handshake/client_ssl.cc b/test/core/handshake/client_ssl.cc index 5445b7b402e..d59018f3a65 100644 --- a/test/core/handshake/client_ssl.cc +++ b/test/core/handshake/client_ssl.cc @@ -24,6 +24,7 @@ #include #include "absl/base/thread_annotations.h" +#include "absl/strings/str_format.h" #include "gtest/gtest.h" #include @@ -49,12 +50,12 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include #include #include -#include #include "src/core/lib/debug/trace.h" #include "src/core/lib/gprpp/crash.h" @@ -119,7 +120,7 @@ static int create_socket(int* out_port) { if (bind(s, reinterpret_cast(&addr), sizeof(addr)) < 0) { perror("Unable to bind"); - gpr_log(GPR_ERROR, "%s", "Unable to bind to any port"); + LOG(ERROR) << "Unable to bind to any port"; close(s); return -1; } @@ -135,7 +136,7 @@ static int create_socket(int* out_port) { 0 || addr_len > sizeof(addr)) { perror("getsockname"); - gpr_log(GPR_ERROR, "%s", "Unable to get socket local address"); + LOG(ERROR) << "Unable to get socket local address"; close(s); return -1; } @@ -176,14 +177,15 @@ static void ssl_log_where_info(const SSL* ssl, int where, int flag, const char* msg) { if ((where & flag) && GRPC_TRACE_FLAG_ENABLED(client_ssl_tsi_tracing_enabled)) { - gpr_log(GPR_INFO, "%20.20s - %30.30s - %5.10s", msg, - SSL_state_string_long(ssl), SSL_state_string(ssl)); + LOG(INFO) << absl::StrFormat("%20.20s - %30.30s - %5.10s", msg, + SSL_state_string_long(ssl), + SSL_state_string(ssl)); } } static void ssl_server_info_callback(const SSL* ssl, int where, int ret) { if (ret == 0) { - gpr_log(GPR_ERROR, "ssl_server_info_callback: error occurred.\n"); + LOG(ERROR) << "ssl_server_info_callback: error occurred.\n"; return; } @@ -251,7 +253,7 @@ static void server_thread(void* arg) { // bind/listen/accept at TCP layer. const int sock = args->socket; - gpr_log(GPR_INFO, "Server listening"); + LOG(INFO) << "Server listening"; struct sockaddr_in addr; socklen_t len = sizeof(addr); const int client = @@ -268,9 +270,9 @@ static void server_thread(void* arg) { SSL_set_fd(ssl, client); if (SSL_accept(ssl) <= 0) { ERR_print_errors_fp(stderr); - gpr_log(GPR_ERROR, "Handshake failed."); + LOG(ERROR) << "Handshake failed."; } else { - gpr_log(GPR_INFO, "Handshake successful."); + LOG(INFO) << "Handshake successful."; } // Send out the settings frame. diff --git a/test/core/handshake/server_ssl_common.cc b/test/core/handshake/server_ssl_common.cc index aefa17d5223..0bebf83ed2e 100644 --- a/test/core/handshake/server_ssl_common.cc +++ b/test/core/handshake/server_ssl_common.cc @@ -35,6 +35,7 @@ #include "absl/base/thread_annotations.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -42,7 +43,6 @@ #include #include #include -#include #include #include @@ -152,7 +152,7 @@ void server_thread(void* arg) { CHECK(ev.type == GRPC_QUEUE_TIMEOUT); } - gpr_log(GPR_INFO, "Shutting down server"); + LOG(INFO) << "Shutting down server"; grpc_server_shutdown_and_notify(server, cq, nullptr); grpc_completion_queue_shutdown(cq); @@ -246,7 +246,7 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len, } } CHECK_GT(sock, 0); - gpr_log(GPR_INFO, "Connected to server on port %d", s.port()); + LOG(INFO) << "Connected to server on port " << s.port(); // Establish a SSL* and connect at SSL layer. SSL* ssl = SSL_new(ctx); @@ -254,10 +254,10 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len, SSL_set_fd(ssl, sock); if (SSL_connect(ssl) <= 0) { ERR_print_errors_fp(stderr); - gpr_log(GPR_ERROR, "Handshake failed."); + LOG(ERROR) << "Handshake failed."; success = false; } else { - gpr_log(GPR_INFO, "Handshake successful."); + LOG(INFO) << "Handshake successful."; // Validate ALPN preferred by server matches alpn_expected. const unsigned char* alpn_selected; unsigned int alpn_selected_len; @@ -265,7 +265,7 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len, if (strlen(alpn_expected) != alpn_selected_len || strncmp(reinterpret_cast(alpn_selected), alpn_expected, alpn_selected_len) != 0) { - gpr_log(GPR_ERROR, "Unexpected ALPN protocol preference"); + LOG(ERROR) << "Unexpected ALPN protocol preference"; success = false; } } diff --git a/test/core/handshake/verify_peer_options.cc b/test/core/handshake/verify_peer_options.cc index b7680cc7897..3e5e2b1590d 100644 --- a/test/core/handshake/verify_peer_options.cc +++ b/test/core/handshake/verify_peer_options.cc @@ -33,13 +33,13 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include #include #include #include -#include #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/thd.h" @@ -89,7 +89,7 @@ static void server_thread(void* arg) { CHECK(ev.type == GRPC_QUEUE_TIMEOUT); } - gpr_log(GPR_INFO, "Shutting down server"); + LOG(INFO) << "Shutting down server"; grpc_server_shutdown_and_notify(server, cq, nullptr); grpc_server_cancel_all_calls(server); grpc_completion_queue_shutdown(cq); diff --git a/test/core/http/httpcli_test_util.cc b/test/core/http/httpcli_test_util.cc index e70c42858d6..f47bb1d61a8 100644 --- a/test/core/http/httpcli_test_util.cc +++ b/test/core/http/httpcli_test_util.cc @@ -23,11 +23,11 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/types/optional.h" #include -#include #include #include #include @@ -86,10 +86,10 @@ HttpRequestTestServer StartHttpRequestTestServer(int argc, char** argv, absl::StrCat(root, "/src/core/tsi/test_creds/ca.pem"); ConfigVars::SetOverrides(overrides); } - gpr_log(GPR_INFO, "starting HttpRequest test server subprocess:"); + LOG(INFO) << "starting HttpRequest test server subprocess:"; for (size_t i = 0; i < args.size(); i++) { - gpr_log(GPR_INFO, " HttpRequest test server subprocess argv[%ld]: %s", i, - args[i]); + LOG(INFO) << " HttpRequest test server subprocess argv[" << i + << "]: " << args[i]; } gpr_subprocess* server = gpr_subprocess_create(args.size(), const_cast(args.data())); diff --git a/test/core/load_balancing/lb_policy_test_lib.h b/test/core/load_balancing/lb_policy_test_lib.h index 3c57342e5d4..46e0e7d4fec 100644 --- a/test/core/load_balancing/lb_policy_test_lib.h +++ b/test/core/load_balancing/lb_policy_test_lib.h @@ -36,6 +36,7 @@ #include "absl/base/thread_annotations.h" #include "absl/functional/any_invocable.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" @@ -51,7 +52,6 @@ #include #include #include -#include #include #include "src/core/client_channel/client_channel_internal.h" @@ -152,8 +152,8 @@ class LoadBalancingPolicyTest : public ::testing::Test { void OnConnectivityStateChange(grpc_connectivity_state new_state, const absl::Status& status) override { - gpr_log(GPR_INFO, "notifying watcher: state=%s status=%s", - ConnectivityStateName(new_state), status.ToString().c_str()); + LOG(INFO) << "notifying watcher: state=" + << ConnectivityStateName(new_state) << " status=" << status; watcher_->OnConnectivityStateChange(new_state, status); } @@ -212,11 +212,10 @@ class LoadBalancingPolicyTest : public ::testing::Test { health_watcher_wrapper_ = watcher_wrapper.get(); state_->state_tracker_.AddWatcher(GRPC_CHANNEL_SHUTDOWN, std::move(watcher_wrapper)); - gpr_log(GPR_INFO, - "AddDataWatcher(): added HealthWatch=%p " - "connectivity_watcher=%p watcher_wrapper=%p", - health_watcher_.get(), connectivity_watcher_ptr, - health_watcher_wrapper_); + LOG(INFO) << "AddDataWatcher(): added HealthWatch=" + << health_watcher_.get() + << " connectivity_watcher=" << connectivity_watcher_ptr + << " watcher_wrapper=" << health_watcher_wrapper_; } } @@ -232,10 +231,9 @@ class LoadBalancingPolicyTest : public ::testing::Test { if (health_watcher_.get() != static_cast(watcher)) { return; } - gpr_log(GPR_INFO, - "CancelDataWatcher(): cancelling HealthWatch=%p " - "watcher_wrapper=%p", - health_watcher_.get(), health_watcher_wrapper_); + LOG(INFO) << "CancelDataWatcher(): cancelling HealthWatch=" + << health_watcher_.get() + << " watcher_wrapper=" << health_watcher_wrapper_; state_->state_tracker_.RemoveWatcher(health_watcher_wrapper_); health_watcher_wrapper_ = nullptr; health_watcher_.reset(); @@ -327,18 +325,16 @@ class LoadBalancingPolicyTest : public ::testing::Test { AssertValidConnectivityStateTransition(state_tracker_.state(), state, location); } - gpr_log(GPR_INFO, "Setting state on tracker"); + LOG(INFO) << "Setting state on tracker"; state_tracker_.SetState(state, status, "set from test"); // SetState() enqueued the connectivity state notifications for // the subchannel, so we add another callback to the queue to be // executed after that state notifications has been delivered. - gpr_log(GPR_INFO, - "Waiting for state notifications to be delivered"); + LOG(INFO) << "Waiting for state notifications to be delivered"; test_->work_serializer_->Run( [&]() { - gpr_log(GPR_INFO, - "State notifications delivered, waiting for health " - "notifications"); + LOG(INFO) << "State notifications delivered, waiting for " + "health notifications"; // Now the connectivity state notifications has been // delivered. If the state reported was READY, then the // pick_first leaf policy will have started a health watch, so @@ -351,7 +347,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { }, DEBUG_LOCATION); notification.WaitForNotification(); - gpr_log(GPR_INFO, "Health notifications delivered"); + LOG(INFO) << "Health notifications delivered"; } // Indicates if any of the associated SubchannelInterface objects @@ -472,8 +468,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { << location.file() << ":" << location.line(); if (update == nullptr) return absl::nullopt; StateUpdate result = std::move(*update); - gpr_log(GPR_INFO, "dequeued next state update: %s", - result.ToString().c_str()); + LOG(INFO) << "dequeued next state update: " << result.ToString(); queue_.pop_front(); return std::move(result); } @@ -506,8 +501,8 @@ class LoadBalancingPolicyTest : public ::testing::Test { PickerWrapper(LoadBalancingPolicyTest* test, RefCountedPtr picker) : test_(test), picker_(std::move(picker)) { - gpr_log(GPR_INFO, "creating wrapper %p for picker %p", this, - picker_.get()); + LOG(INFO) << "creating wrapper " << this << " for picker " + << picker_.get(); } void Orphaned() override { @@ -579,8 +574,8 @@ class LoadBalancingPolicyTest : public ::testing::Test { StateUpdate update{ state, status, MakeRefCounted(test_, std::move(picker))}; - gpr_log(GPR_INFO, "enqueuing state update from LB policy: %s", - update.ToString().c_str()); + LOG(INFO) << "enqueuing state update from LB policy: " + << update.ToString(); queue_.push_back(std::move(update)); } @@ -847,14 +842,12 @@ class LoadBalancingPolicyTest : public ::testing::Test { // notifications for the subchannels, so we add another // callback to the queue to be executed after those initial // state notifications have been delivered. - gpr_log(GPR_INFO, - "Applied update, waiting for initial connectivity state " - "notifications"); + LOG(INFO) << "Applied update, waiting for initial connectivity state " + "notifications"; work_serializer_->Run( [&]() { - gpr_log(GPR_INFO, - "Initial connectivity state notifications delivered; " - "waiting for health notifications"); + LOG(INFO) << "Initial connectivity state notifications " + "delivered; waiting for health notifications"; // Now that the initial state notifications have been // delivered, the queue will contain the health watch // notifications for any subchannels in state READY, @@ -868,7 +861,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { }, DEBUG_LOCATION); notification.WaitForNotification(); - gpr_log(GPR_INFO, "health notifications delivered"); + LOG(INFO) << "health notifications delivered"; return status; } @@ -900,15 +893,15 @@ class LoadBalancingPolicyTest : public ::testing::Test { bool WaitForStateUpdate( std::function continue_predicate, SourceLocation location = SourceLocation()) { - gpr_log(GPR_INFO, "==> WaitForStateUpdate()"); + LOG(INFO) << "==> WaitForStateUpdate()"; while (true) { auto update = helper_->GetNextStateUpdate(location); if (!update.has_value()) { - gpr_log(GPR_INFO, "WaitForStateUpdate() returning false"); + LOG(INFO) << "WaitForStateUpdate() returning false"; return false; } if (!continue_predicate(std::move(*update))) { - gpr_log(GPR_INFO, "WaitForStateUpdate() returning true"); + LOG(INFO) << "WaitForStateUpdate() returning true"; return true; } } @@ -945,7 +938,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { // update for state READY, whose picker is returned. RefCountedPtr WaitForConnected( SourceLocation location = SourceLocation()) { - gpr_log(GPR_INFO, "==> WaitForConnected()"); + LOG(INFO) << "==> WaitForConnected()"; RefCountedPtr final_picker; WaitForStateUpdate( [&](FakeHelper::StateUpdate update) { @@ -1022,7 +1015,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { const CallAttributes& call_attributes = {}, size_t num_iterations = 3, SourceLocation location = SourceLocation()) { - gpr_log(GPR_INFO, "Waiting for expected RR addresses..."); + LOG(INFO) << "Waiting for expected RR addresses..."; RefCountedPtr retval; size_t num_picks = std::max(new_addresses.size(), old_addresses.size()) * num_iterations; @@ -1038,7 +1031,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { EXPECT_TRUE(picks.has_value()) << location.file() << ":" << location.line(); if (!picks.has_value()) return false; - gpr_log(GPR_INFO, "PICKS: %s", absl::StrJoin(*picks, " ").c_str()); + LOG(INFO) << "PICKS: " << absl::StrJoin(*picks, " "); // If the picks still match the old list, then keep going. if (PicksAreRoundRobin(old_addresses, *picks)) return true; // Otherwise, the picks should match the new list. @@ -1053,7 +1046,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { return false; // Stop. }, location); - gpr_log(GPR_INFO, "done waiting for expected RR addresses"); + LOG(INFO) << "done waiting for expected RR addresses"; return retval; } @@ -1307,7 +1300,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { RefCountedPtr DrainRoundRobinPickerUpdates(absl::Span addresses, SourceLocation location = SourceLocation()) { - gpr_log(GPR_INFO, "Draining RR picker updates..."); + LOG(INFO) << "Draining RR picker updates..."; RefCountedPtr picker; while (!helper_->QueueEmpty()) { auto update = helper_->GetNextStateUpdate(location); @@ -1322,17 +1315,17 @@ class LoadBalancingPolicyTest : public ::testing::Test { location); picker = std::move(update->picker); } - gpr_log(GPR_INFO, "Done draining RR picker updates"); + LOG(INFO) << "Done draining RR picker updates"; return picker; } // Expects zero or more CONNECTING updates. void DrainConnectingUpdates(SourceLocation location = SourceLocation()) { - gpr_log(GPR_INFO, "Draining CONNECTING updates..."); + LOG(INFO) << "Draining CONNECTING updates..."; while (!helper_->QueueEmpty()) { ASSERT_TRUE(ExpectConnectingUpdate(location)); } - gpr_log(GPR_INFO, "Done draining CONNECTING updates"); + LOG(INFO) << "Done draining CONNECTING updates"; } // Triggers a connection failure for the current address for an @@ -1341,10 +1334,10 @@ class LoadBalancingPolicyTest : public ::testing::Test { absl::Span addresses, size_t current_index, size_t new_index, absl::AnyInvocable expect_after_disconnect, SourceLocation location = SourceLocation()) { - gpr_log(GPR_INFO, - "Expecting endpoint address change: addresses={%s}, " - "current_index=%" PRIuPTR ", new_index=%" PRIuPTR, - absl::StrJoin(addresses, ", ").c_str(), current_index, new_index); + LOG(INFO) << "Expecting endpoint address change: addresses={" + << absl::StrJoin(addresses, ", ") + << "}, current_index=" << current_index + << ", new_index=" << new_index; ASSERT_LT(current_index, addresses.size()); ASSERT_LT(new_index, addresses.size()); // Find all subchannels. @@ -1385,7 +1378,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { // interacts with it again. subchannel->SetConnectivityState(GRPC_CHANNEL_IDLE); } - gpr_log(GPR_INFO, "Done with endpoint address change"); + LOG(INFO) << "Done with endpoint address change"; } // Requests a picker on picker and expects a Fail result. @@ -1451,19 +1444,18 @@ class LoadBalancingPolicyTest : public ::testing::Test { void WaitForWorkSerializerToFlush() { ExecCtx exec_ctx; - gpr_log(GPR_INFO, "waiting for WorkSerializer to flush..."); + LOG(INFO) << "waiting for WorkSerializer to flush..."; absl::Notification notification; work_serializer_->Run([&]() { notification.Notify(); }, DEBUG_LOCATION); notification.WaitForNotification(); - gpr_log(GPR_INFO, "WorkSerializer flush complete"); + LOG(INFO) << "WorkSerializer flush complete"; } void IncrementTimeBy(Duration duration) { ExecCtx exec_ctx; - gpr_log(GPR_INFO, "Incrementing time by %s...", - duration.ToString().c_str()); + LOG(INFO) << "Incrementing time by " << duration; fuzzing_ee_->TickForDuration(duration); - gpr_log(GPR_INFO, "Done incrementing time"); + LOG(INFO) << "Done incrementing time"; // Flush WorkSerializer, in case the timer callback enqueued anything. WaitForWorkSerializerToFlush(); } diff --git a/test/core/load_balancing/outlier_detection_test.cc b/test/core/load_balancing/outlier_detection_test.cc index ba60dce52eb..db425e666fa 100644 --- a/test/core/load_balancing/outlier_detection_test.cc +++ b/test/core/load_balancing/outlier_detection_test.cc @@ -25,6 +25,7 @@ #include #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" @@ -33,7 +34,6 @@ #include #include -#include #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -215,14 +215,14 @@ TEST_F(OutlierDetectionTest, FailurePercentage) { // Expect normal startup. auto picker = ExpectRoundRobinStartup(kAddresses); ASSERT_NE(picker, nullptr); - gpr_log(GPR_INFO, "### RR startup complete"); + LOG(INFO) << "### RR startup complete"; // Do a pick and report a failed call. auto address = DoPickWithFailedCall(picker.get()); ASSERT_TRUE(address.has_value()); - gpr_log(GPR_INFO, "### failed RPC on %s", address->c_str()); + LOG(INFO) << "### failed RPC on " << *address; // Advance time and run the timer callback to trigger ejection. IncrementTimeBy(Duration::Seconds(10)); - gpr_log(GPR_INFO, "### ejection complete"); + LOG(INFO) << "### ejection complete"; // Expect a picker update. std::vector remaining_addresses; for (const auto& addr : kAddresses) { @@ -231,7 +231,7 @@ TEST_F(OutlierDetectionTest, FailurePercentage) { WaitForRoundRobinListChange(kAddresses, remaining_addresses); // Advance time and run the timer callback to trigger un-ejection. IncrementTimeBy(Duration::Seconds(10)); - gpr_log(GPR_INFO, "### un-ejection complete"); + LOG(INFO) << "### un-ejection complete"; // Expect a picker update. WaitForRoundRobinListChange(remaining_addresses, kAddresses); } @@ -265,11 +265,11 @@ TEST_F(OutlierDetectionTest, MultipleAddressesPerEndpoint) { // Expect normal startup. auto picker = ExpectRoundRobinStartup(kEndpoints); ASSERT_NE(picker, nullptr); - gpr_log(GPR_INFO, "### RR startup complete"); + LOG(INFO) << "### RR startup complete"; // Do a pick and report a failed call. auto address = DoPickWithFailedCall(picker.get()); ASSERT_TRUE(address.has_value()); - gpr_log(GPR_INFO, "### failed RPC on %s", address->c_str()); + LOG(INFO) << "### failed RPC on " << *address; // Based on the address that the failed call went to, we determine // which addresses to use in the subsequent steps. absl::Span ejected_endpoint_addresses; @@ -297,12 +297,12 @@ TEST_F(OutlierDetectionTest, MultipleAddressesPerEndpoint) { } // Advance time and run the timer callback to trigger ejection. IncrementTimeBy(Duration::Seconds(10)); - gpr_log(GPR_INFO, "### ejection complete"); + LOG(INFO) << "### ejection complete"; // Expect a picker that removes the ejected address. WaitForRoundRobinListChange( {kEndpoint1Addresses[0], kEndpoint2Addresses[0], kEndpoint3Addresses[0]}, {sentinel_endpoint_addresses[0], unmodified_endpoint_address}); - gpr_log(GPR_INFO, "### ejected endpoint removed"); + LOG(INFO) << "### ejected endpoint removed"; // Cause the connection to the ejected endpoint to fail, and then // have it reconnect to a different address. The endpoint is still // ejected, so the new address should not be used. @@ -312,7 +312,7 @@ TEST_F(OutlierDetectionTest, MultipleAddressesPerEndpoint) { // re-resolution request in the queue. DrainRoundRobinPickerUpdates( {sentinel_endpoint_addresses[0], unmodified_endpoint_address}); - gpr_log(GPR_INFO, "### done changing address of ejected endpoint"); + LOG(INFO) << "### done changing address of ejected endpoint"; // Do the same thing for the sentinel endpoint, so that we // know that the LB policy has seen the address change for the ejected // endpoint. @@ -324,10 +324,10 @@ TEST_F(OutlierDetectionTest, MultipleAddressesPerEndpoint) { WaitForRoundRobinListChange( {unmodified_endpoint_address}, {sentinel_endpoint_addresses[1], unmodified_endpoint_address}); - gpr_log(GPR_INFO, "### done changing address of ejected endpoint"); + LOG(INFO) << "### done changing address of ejected endpoint"; // Advance time and run the timer callback to trigger un-ejection. IncrementTimeBy(Duration::Seconds(10)); - gpr_log(GPR_INFO, "### un-ejection complete"); + LOG(INFO) << "### un-ejection complete"; // The ejected endpoint should come back using the new address. WaitForRoundRobinListChange( {sentinel_endpoint_addresses[1], unmodified_endpoint_address}, @@ -363,11 +363,11 @@ TEST_F(OutlierDetectionTest, EjectionStateResetsWhenEndpointAddressesChange) { // Expect normal startup. auto picker = ExpectRoundRobinStartup(kEndpoints); ASSERT_NE(picker, nullptr); - gpr_log(GPR_INFO, "### RR startup complete"); + LOG(INFO) << "### RR startup complete"; // Do a pick and report a failed call. auto ejected_address = DoPickWithFailedCall(picker.get()); ASSERT_TRUE(ejected_address.has_value()); - gpr_log(GPR_INFO, "### failed RPC on %s", ejected_address->c_str()); + LOG(INFO) << "### failed RPC on " << *ejected_address; // Based on the address that the failed call went to, we determine // which addresses to use in the subsequent steps. std::vector expected_round_robin_while_ejected; @@ -393,12 +393,12 @@ TEST_F(OutlierDetectionTest, EjectionStateResetsWhenEndpointAddressesChange) { } // Advance time and run the timer callback to trigger ejection. IncrementTimeBy(Duration::Seconds(10)); - gpr_log(GPR_INFO, "### ejection complete"); + LOG(INFO) << "### ejection complete"; // Expect a picker that removes the ejected address. WaitForRoundRobinListChange( {kEndpoint1Addresses[0], kEndpoint2Addresses[0], kEndpoint3Addresses[0]}, expected_round_robin_while_ejected); - gpr_log(GPR_INFO, "### ejected endpoint removed"); + LOG(INFO) << "### ejected endpoint removed"; // Send an update that removes the other address from the ejected endpoint. status = ApplyUpdate(BuildUpdate(new_endpoints, kConfig), lb_policy_.get()); EXPECT_TRUE(status.ok()) << status; @@ -447,14 +447,14 @@ TEST_F(OutlierDetectionTest, DoesNotWorkWithPickFirst) { for (size_t i = 0; i < 3; ++i) { EXPECT_EQ(ExpectPickComplete(picker.get()), kAddresses[0]); } - gpr_log(GPR_INFO, "### PF startup complete"); + LOG(INFO) << "### PF startup complete"; // Now have an RPC to that subchannel fail. auto address = DoPickWithFailedCall(picker.get()); ASSERT_TRUE(address.has_value()); - gpr_log(GPR_INFO, "### failed RPC on %s", address->c_str()); + LOG(INFO) << "### failed RPC on " << *address; // Advance time and run the timer callback to trigger ejection. IncrementTimeBy(Duration::Seconds(10)); - gpr_log(GPR_INFO, "### ejection timer pass complete"); + LOG(INFO) << "### ejection timer pass complete"; // Subchannel should not be ejected. ExpectQueueEmpty(); // Subchannel should not see a reconnection request. diff --git a/test/core/load_balancing/weighted_round_robin_test.cc b/test/core/load_balancing/weighted_round_robin_test.cc index 9a5eebba751..58a3be1fa14 100644 --- a/test/core/load_balancing/weighted_round_robin_test.cc +++ b/test/core/load_balancing/weighted_round_robin_test.cc @@ -27,6 +27,7 @@ #include #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" @@ -38,7 +39,6 @@ #include #include -#include #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/orphanable.h" @@ -98,7 +98,7 @@ class WeightedRoundRobinTest : public LoadBalancingPolicyTest { RefCountedPtr Build() { Json config = Json::FromArray({Json::FromObject( {{"weighted_round_robin", Json::FromObject(json_)}})}); - gpr_log(GPR_INFO, "CONFIG: %s", JsonDump(config).c_str()); + LOG(INFO) << "CONFIG: " << JsonDump(config); return MakeConfig(config); } @@ -247,10 +247,10 @@ class WeightedRoundRobinTest : public LoadBalancingPolicyTest { auto picks = GetCompletePicks(picker, NumPicksNeeded(expected), {}, &subchannel_call_trackers, location); ASSERT_TRUE(picks.has_value()) << location.file() << ":" << location.line(); - gpr_log(GPR_INFO, "PICKS: %s", absl::StrJoin(*picks, " ").c_str()); + LOG(INFO) << "PICKS: " << absl::StrJoin(*picks, " "); ReportBackendMetrics(*picks, subchannel_call_trackers, backend_metrics); auto actual = MakePickMap(*picks); - gpr_log(GPR_INFO, "Pick map: %s", PickMapString(actual).c_str()); + LOG(INFO) << "Pick map: " << PickMapString(actual); EXPECT_EQ(expected, actual) << "Expected: " << PickMapString(expected) << "\nActual: " << PickMapString(actual) << "\nat " << location.file() @@ -265,17 +265,17 @@ class WeightedRoundRobinTest : public LoadBalancingPolicyTest { absl::Duration timeout = absl::Seconds(5), bool run_timer_callbacks = true, SourceLocation location = SourceLocation()) { - gpr_log(GPR_INFO, "==> WaitForWeightedRoundRobinPicks(): Expecting %s", - PickMapString(expected).c_str()); + LOG(INFO) << "==> WaitForWeightedRoundRobinPicks(): Expecting " + << PickMapString(expected); size_t num_picks = NumPicksNeeded(expected); absl::Time deadline = absl::Now() + timeout; while (true) { - gpr_log(GPR_INFO, "TOP OF LOOP"); + LOG(INFO) << "TOP OF LOOP"; // We need to see the expected weights for 3 consecutive passes, just // to make sure we're consistently returning the right weights. size_t num_passes = 0; for (; num_passes < 3; ++num_passes) { - gpr_log(GPR_INFO, "PASS %" PRIuPTR ": DOING PICKS", num_passes); + LOG(INFO) << "PASS " << num_passes << ": DOING PICKS"; std::vector> subchannel_call_trackers; @@ -284,13 +284,13 @@ class WeightedRoundRobinTest : public LoadBalancingPolicyTest { EXPECT_TRUE(picks.has_value()) << location.file() << ":" << location.line(); if (!picks.has_value()) return false; - gpr_log(GPR_INFO, "PICKS: %s", absl::StrJoin(*picks, " ").c_str()); + LOG(INFO) << "PICKS: " << absl::StrJoin(*picks, " "); // Report backend metrics to the LB policy. ReportBackendMetrics(*picks, subchannel_call_trackers, backend_metrics); // Check the observed weights. auto actual = MakePickMap(*picks); - gpr_log(GPR_INFO, "Pick map:\nExpected: %s\n Actual: %s", - PickMapString(expected).c_str(), PickMapString(actual).c_str()); + LOG(INFO) << "Pick map:\nExpected: " << PickMapString(expected) + << "\n Actual: " << PickMapString(actual); if (expected != actual) { // Make sure each address is one of the expected addresses, // even if the weights aren't as expected. @@ -321,7 +321,7 @@ class WeightedRoundRobinTest : public LoadBalancingPolicyTest { << location.file() << ":" << location.line(); if (*picker == nullptr) return false; } else if (run_timer_callbacks) { - gpr_log(GPR_INFO, "running timer callback..."); + LOG(INFO) << "running timer callback..."; // Increment time and run any timer callbacks. IncrementTimeBy(Duration::Seconds(1)); } @@ -1150,7 +1150,7 @@ TEST_F(WeightedRoundRobinTest, MetricValues) { ::testing::Optional(0)); // Advance time to make weights stale and trigger the timer callback // to recompute weights. - gpr_log(GPR_INFO, "advancing time to trigger staleness..."); + LOG(INFO) << "advancing time to trigger staleness..."; IncrementTimeBy(Duration::Seconds(2)); // Picker should now be falling back to round-robin. ExpectWeightedRoundRobinPicks( diff --git a/test/core/load_balancing/xds_override_host_test.cc b/test/core/load_balancing/xds_override_host_test.cc index 0e8f11cc46e..e75581f720e 100644 --- a/test/core/load_balancing/xds_override_host_test.cc +++ b/test/core/load_balancing/xds_override_host_test.cc @@ -23,6 +23,7 @@ #include #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_join.h" @@ -35,7 +36,6 @@ #include #include -#include #include "src/core/ext/filters/stateful_session/stateful_session_filter.h" #include "src/core/lib/channel/channel_args.h" @@ -295,21 +295,20 @@ TEST_F(XdsOverrideHostTest, auto* address1_attribute = MakeOverrideHostAttribute(kAddresses[1]); ExpectOverridePicks(picker.get(), address1_attribute, kAddresses[1]); // Subchannel for address 1 becomes disconnected. - gpr_log(GPR_INFO, "### subchannel 1 reporting IDLE"); + LOG(INFO) << "### subchannel 1 reporting IDLE"; auto subchannel = FindSubchannel(kAddresses[1]); ASSERT_NE(subchannel, nullptr); subchannel->SetConnectivityState(GRPC_CHANNEL_IDLE); EXPECT_TRUE(subchannel->ConnectionRequested()); - gpr_log(GPR_INFO, "### expecting re-resolution request"); + LOG(INFO) << "### expecting re-resolution request"; ExpectReresolutionRequest(); - gpr_log(GPR_INFO, - "### expecting RR picks to exclude the disconnected subchannel"); + LOG(INFO) << "### expecting RR picks to exclude the disconnected subchannel"; picker = WaitForRoundRobinListChange(kAddresses, {kAddresses[0], kAddresses[2]}); // Picks with the override will be queued. ExpectPickQueued(picker.get(), {address1_attribute}); // The subchannel starts trying to reconnect. - gpr_log(GPR_INFO, "### subchannel 1 reporting CONNECTING"); + LOG(INFO) << "### subchannel 1 reporting CONNECTING"; subchannel->SetConnectivityState(GRPC_CHANNEL_CONNECTING); picker = ExpectState(GRPC_CHANNEL_READY); ASSERT_NE(picker, nullptr); @@ -317,15 +316,15 @@ TEST_F(XdsOverrideHostTest, // Picks with the override will still be queued. ExpectPickQueued(picker.get(), {address1_attribute}); // The connection attempt fails. - gpr_log(GPR_INFO, "### subchannel 1 reporting TRANSIENT_FAILURE"); + LOG(INFO) << "### subchannel 1 reporting TRANSIENT_FAILURE"; subchannel->SetConnectivityState(GRPC_CHANNEL_TRANSIENT_FAILURE, absl::ResourceExhaustedError("Hmmmm")); - gpr_log(GPR_INFO, "### expecting re-resolution request"); + LOG(INFO) << "### expecting re-resolution request"; ExpectReresolutionRequest(); picker = ExpectState(GRPC_CHANNEL_READY); ExpectRoundRobinPicks(picker.get(), {kAddresses[0], kAddresses[2]}); // The host override is not used. - gpr_log(GPR_INFO, "### checking that host override is not used"); + LOG(INFO) << "### checking that host override is not used"; ExpectRoundRobinPicksWithAttribute(picker.get(), address1_attribute, {kAddresses[0], kAddresses[2]}); } @@ -376,7 +375,7 @@ TEST_F(XdsOverrideHostTest, DrainingSubchannelIsConnecting) { // The picker should use the DRAINING host when a call's override // points to that hose, but the host should not be used if there is no // override pointing to it. - gpr_log(GPR_INFO, "### sending update with DRAINING host"); + LOG(INFO) << "### sending update with DRAINING host"; ApplyUpdateWithHealthStatuses({{kAddresses[0], XdsHealthStatus::kUnknown}, {kAddresses[1], XdsHealthStatus::kDraining}, {kAddresses[2], XdsHealthStatus::kHealthy}}, @@ -391,7 +390,7 @@ TEST_F(XdsOverrideHostTest, DrainingSubchannelIsConnecting) { // Now the connection to the draining host gets dropped. // The picker should queue picks where the override host is IDLE. // All picks without an override host should not use this host. - gpr_log(GPR_INFO, "### closing connection to DRAINING host"); + LOG(INFO) << "### closing connection to DRAINING host"; subchannel->SetConnectivityState(GRPC_CHANNEL_IDLE); picker = ExpectState(GRPC_CHANNEL_READY); ExpectPickQueued(picker.get(), {address1_attribute}); @@ -401,7 +400,7 @@ TEST_F(XdsOverrideHostTest, DrainingSubchannelIsConnecting) { // The pick behavior is the same as above: The picker should queue // picks where the override host is CONNECTING. All picks without an // override host should not use this host. - gpr_log(GPR_INFO, "### subchannel starts reconnecting"); + LOG(INFO) << "### subchannel starts reconnecting"; WaitForWorkSerializerToFlush(); EXPECT_TRUE(subchannel->ConnectionRequested()); ExpectQueueEmpty(); @@ -412,7 +411,7 @@ TEST_F(XdsOverrideHostTest, DrainingSubchannelIsConnecting) { // The subchannel now becomes connected again. // Now picks with this override host can be completed again. // Picks without an override host still don't use the draining host. - gpr_log(GPR_INFO, "### subchannel becomes reconnected"); + LOG(INFO) << "### subchannel becomes reconnected"; subchannel->SetConnectivityState(GRPC_CHANNEL_READY); picker = ExpectState(GRPC_CHANNEL_READY); ExpectOverridePicks(picker.get(), address1_attribute, kAddresses[1]); @@ -644,7 +643,7 @@ TEST_F(XdsOverrideHostTest, IdleTimer) { }); const std::array kAddresses = { "ipv4:127.0.0.1:441", "ipv4:127.0.0.1:442", "ipv4:127.0.0.1:443"}; - gpr_log(GPR_INFO, "### sending initial update"); + LOG(INFO) << "### sending initial update"; EXPECT_EQ(UpdateXdsOverrideHostPolicy(kAddresses, {"UNKNOWN", "HEALTHY"}, Duration::Minutes(1)), absl::OkStatus()); @@ -663,7 +662,7 @@ TEST_F(XdsOverrideHostTest, IdleTimer) { ExpectOverridePicks(picker.get(), address2_attribute, kAddresses[2]); // Increment time by 5 seconds and send an update that moves endpoints 1 // and 2 to state DRAINING. - gpr_log(GPR_INFO, "### moving endpoints 1 and 2 to state DRAINING"); + LOG(INFO) << "### moving endpoints 1 and 2 to state DRAINING"; IncrementTimeBy(Duration::Seconds(5)); ApplyUpdateWithHealthStatuses({{kAddresses[0], XdsHealthStatus::kUnknown}, {kAddresses[1], XdsHealthStatus::kDraining}, diff --git a/test/core/network_benchmarks/low_level_ping_pong.cc b/test/core/network_benchmarks/low_level_ping_pong.cc index 69b5228b362..49bd712bb7a 100644 --- a/test/core/network_benchmarks/low_level_ping_pong.cc +++ b/test/core/network_benchmarks/low_level_ping_pong.cc @@ -36,9 +36,9 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include -#include #include #include "src/core/lib/gprpp/strerror.h" @@ -84,8 +84,7 @@ static int read_bytes(int fd, char* buf, size_t read_size, int spin) { if (errno == EAGAIN && spin == 1) { continue; } - gpr_log(GPR_ERROR, "Read failed: %s", - grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Read failed: " << grpc_core::StrError(errno); return -1; } } else { @@ -118,8 +117,7 @@ static int poll_read_bytes(int fd, char* buf, size_t read_size, int spin) { if (errno == EINTR) { continue; } else { - gpr_log(GPR_ERROR, "Poll failed: %s", - grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Poll failed: " << grpc_core::StrError(errno); return -1; } } @@ -130,7 +128,7 @@ static int poll_read_bytes(int fd, char* buf, size_t read_size, int spin) { err2 = read(fd, buf + bytes_read, read_size - bytes_read); } while (err2 < 0 && errno == EINTR); if (err2 < 0 && errno != EAGAIN) { - gpr_log(GPR_ERROR, "Read failed: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Read failed: " << grpc_core::StrError(errno); return -1; } bytes_read += static_cast(err2); @@ -159,8 +157,7 @@ static int epoll_read_bytes(struct thread_args* args, char* buf, int spin) { err = epoll_wait(args->epoll_fd, &ev, 1, spin ? 0 : -1); if (err < 0) { if (errno == EINTR) continue; - gpr_log(GPR_ERROR, "epoll_wait failed: %s", - grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "epoll_wait failed: " << grpc_core::StrError(errno); return -1; } if (err == 0 && spin) continue; @@ -206,8 +203,7 @@ static int blocking_write_bytes(struct thread_args* args, char* buf) { if (errno == EINTR) { continue; } else { - gpr_log(GPR_ERROR, "Read failed: %s", - grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Read failed: " << grpc_core::StrError(errno); return -1; } } else { @@ -245,7 +241,7 @@ static int epoll_setup(thread_args* args) { set_socket_nonblocking(args); epoll_fd = epoll_create(1); if (epoll_fd < 0) { - gpr_log(GPR_ERROR, "epoll_create: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "epoll_create: " << grpc_core::StrError(errno); return -1; } @@ -254,7 +250,7 @@ static int epoll_setup(thread_args* args) { ev.events = EPOLLIN | EPOLLET; ev.data.fd = args->fds.read_fd; if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, args->fds.read_fd, &ev) < 0) { - gpr_log(GPR_ERROR, "epoll_ctl: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "epoll_ctl: " << grpc_core::StrError(errno); } return 0; } @@ -263,16 +259,16 @@ static int epoll_setup(thread_args* args) { static void server_thread(thread_args* args) { char* buf = static_cast(gpr_malloc(args->msg_size)); if (args->setup(args) < 0) { - gpr_log(GPR_ERROR, "Setup failed"); + LOG(ERROR) << "Setup failed"; } for (;;) { if (args->read_bytes(args, buf) < 0) { - gpr_log(GPR_ERROR, "Server read failed"); + LOG(ERROR) << "Server read failed"; gpr_free(buf); return; } if (args->write_bytes(args, buf) < 0) { - gpr_log(GPR_ERROR, "Server write failed"); + LOG(ERROR) << "Server write failed"; gpr_free(buf); return; } @@ -287,11 +283,11 @@ static void server_thread_wrap(void* arg) { static void print_histogram(grpc_histogram* histogram) { // TODO(klempner): Print more detailed information, such as detailed histogram // buckets - gpr_log(GPR_INFO, "latency (50/95/99/99.9): %f/%f/%f/%f", - grpc_histogram_percentile(histogram, 50), - grpc_histogram_percentile(histogram, 95), - grpc_histogram_percentile(histogram, 99), - grpc_histogram_percentile(histogram, 99.9)); + LOG(INFO) << "latency (50/95/99/99.9): " + << grpc_histogram_percentile(histogram, 50) << "/" + << grpc_histogram_percentile(histogram, 95) << "/" + << grpc_histogram_percentile(histogram, 99) << "/" + << grpc_histogram_percentile(histogram, 99.9); } static double now(void) { @@ -310,16 +306,16 @@ static void client_thread(thread_args* args) { int i; if (args->setup(args) < 0) { - gpr_log(GPR_ERROR, "Setup failed"); + LOG(ERROR) << "Setup failed"; } for (i = 0; i < kNumIters; ++i) { start_time = now(); if (args->write_bytes(args, buf) < 0) { - gpr_log(GPR_ERROR, "Client write failed"); + LOG(ERROR) << "Client write failed"; goto error; } if (args->read_bytes(args, buf) < 0) { - gpr_log(GPR_ERROR, "Client read failed"); + LOG(ERROR) << "Client read failed"; goto error; } end_time = now(); @@ -338,8 +334,7 @@ error: static int create_listening_socket(struct sockaddr* port, socklen_t len) { int fd = socket(port->sa_family, SOCK_STREAM, 0); if (fd < 0) { - gpr_log(GPR_ERROR, "Unable to create socket: %s", - grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Unable to create socket: " << grpc_core::StrError(errno); goto error; } @@ -357,17 +352,17 @@ static int create_listening_socket(struct sockaddr* port, socklen_t len) { } if (bind(fd, port, len) < 0) { - gpr_log(GPR_ERROR, "bind: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "bind: " << grpc_core::StrError(errno); goto error; } if (listen(fd, 1) < 0) { - gpr_log(GPR_ERROR, "listen: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "listen: " << grpc_core::StrError(errno); goto error; } if (getsockname(fd, port, &len) < 0) { - gpr_log(GPR_ERROR, "getsockname: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "getsockname: " << grpc_core::StrError(errno); goto error; } @@ -384,8 +379,7 @@ static int connect_client(struct sockaddr* addr, socklen_t len) { int fd = socket(addr->sa_family, SOCK_STREAM, 0); int err; if (fd < 0) { - gpr_log(GPR_ERROR, "Unable to create socket: %s", - grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Unable to create socket: " << grpc_core::StrError(errno); goto error; } @@ -403,7 +397,7 @@ static int connect_client(struct sockaddr* addr, socklen_t len) { } while (err < 0 && errno == EINTR); if (err < 0) { - gpr_log(GPR_ERROR, "connect error: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "connect error: " << grpc_core::StrError(errno); goto error; } return fd; @@ -418,7 +412,7 @@ error: static int accept_server(int listen_fd) { int fd = accept(listen_fd, nullptr, nullptr); if (fd < 0) { - gpr_log(GPR_ERROR, "Accept failed: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Accept failed: " << grpc_core::StrError(errno); return -1; } return fd; @@ -438,19 +432,19 @@ static int create_sockets_tcp(fd_pair* client_fds, fd_pair* server_fds) { listen_fd = create_listening_socket(sa_port, sizeof(port)); if (listen_fd == -1) { - gpr_log(GPR_ERROR, "Listen failed"); + LOG(ERROR) << "Listen failed"; goto error; } client_fd = connect_client(sa_port, sizeof(port)); if (client_fd == -1) { - gpr_log(GPR_ERROR, "Connect failed"); + LOG(ERROR) << "Connect failed"; goto error; } server_fd = accept_server(listen_fd); if (server_fd == -1) { - gpr_log(GPR_ERROR, "Accept failed"); + LOG(ERROR) << "Accept failed"; goto error; } @@ -477,7 +471,7 @@ error: static int create_sockets_socketpair(fd_pair* client_fds, fd_pair* server_fds) { int fds[2]; if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) { - gpr_log(GPR_ERROR, "socketpair: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "socketpair: " << grpc_core::StrError(errno); return -1; } @@ -492,12 +486,12 @@ static int create_sockets_pipe(fd_pair* client_fds, fd_pair* server_fds) { int cfds[2]; int sfds[2]; if (pipe(cfds) < 0) { - gpr_log(GPR_ERROR, "pipe: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "pipe: " << grpc_core::StrError(errno); return -1; } if (pipe(sfds) < 0) { - gpr_log(GPR_ERROR, "pipe: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "pipe: " << grpc_core::StrError(errno); return -1; } @@ -592,8 +586,8 @@ static int run_benchmark(const char* socket_type, thread_args* client_args, return rv; } - gpr_log(GPR_INFO, "Starting test %s %s %zu", client_args->strategy_name, - socket_type, client_args->msg_size); + LOG(INFO) << "Starting test " << client_args->strategy_name << " " + << socket_type << " " << client_args->msg_size; grpc_core::Thread server("server_thread", server_thread_wrap, server_args); server.Start(); @@ -663,7 +657,7 @@ int main(int argc, char** argv) { } if (read_strategy == nullptr) { - gpr_log(GPR_INFO, "No strategy specified, running all benchmarks"); + LOG(INFO) << "No strategy specified, running all benchmarks"; return run_all_benchmarks(static_cast(msg_size)); } diff --git a/test/core/promise/party_test.cc b/test/core/promise/party_test.cc index 077fdfa39d1..3afe59b755d 100644 --- a/test/core/promise/party_test.cc +++ b/test/core/promise/party_test.cc @@ -23,6 +23,7 @@ #include #include "absl/base/thread_annotations.h" +#include "absl/log/log.h" #include "gtest/gtest.h" #include @@ -114,8 +115,7 @@ TYPED_TEST(PartySyncTest, AddAndRemoveParticipant) { participants[slot].exchange(nullptr, std::memory_order_acquire); if (participant == done.get()) run_me = true; if (participant == nullptr) { - gpr_log(GPR_ERROR, - "Participant was null (spurious wakeup observed)"); + LOG(ERROR) << "Participant was null (spurious wakeup observed)"; return false; } participant->store(true, std::memory_order_release); @@ -165,8 +165,7 @@ TYPED_TEST(PartySyncTest, AddAndRemoveTwoParticipants) { participants[slot].exchange(nullptr, std::memory_order_acquire); if (participant == done.get()) run_me++; if (participant == nullptr) { - gpr_log(GPR_ERROR, - "Participant was null (spurious wakeup observed)"); + LOG(ERROR) << "Participant was null (spurious wakeup observed)"; return false; } participant->fetch_sub(1, std::memory_order_release); diff --git a/test/core/slice/slice_test.cc b/test/core/slice/slice_test.cc index f21781ee48d..44c139d8c07 100644 --- a/test/core/slice/slice_test.cc +++ b/test/core/slice/slice_test.cc @@ -28,6 +28,7 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/string_view.h" #include "gtest/gtest.h" @@ -182,7 +183,7 @@ TEST_P(GrpcSliceSizedTest, SliceSplitHeadWorks) { grpc_slice head, tail; size_t i; - gpr_log(GPR_INFO, "length=%" PRIuPTR, length); + LOG(INFO) << "length=" << length; // Create a slice in which each byte is equal to the distance from it to the // beginning of the slice. @@ -211,7 +212,7 @@ TEST_P(GrpcSliceSizedTest, SliceSplitTailWorks) { grpc_slice head, tail; size_t i; - gpr_log(GPR_INFO, "length=%" PRIuPTR, length); + LOG(INFO) << "length=" << length; // Create a slice in which each byte is equal to the distance from it to the // beginning of the slice. diff --git a/test/core/surface/completion_queue_test.cc b/test/core/surface/completion_queue_test.cc index 0cb90259fa0..82dbaed6dd6 100644 --- a/test/core/surface/completion_queue_test.cc +++ b/test/core/surface/completion_queue_test.cc @@ -22,11 +22,11 @@ #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "gtest/gtest.h" #include -#include #include #include @@ -34,7 +34,7 @@ #include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" -#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x) +#define LOG_TEST(x) LOG(INFO) << x static void* create_test_tag(void) { static intptr_t i = 0; @@ -65,7 +65,7 @@ static void shutdown_and_destroy(grpc_completion_queue* cc) { break; } default: { - gpr_log(GPR_ERROR, "Unknown completion type"); + LOG(ERROR) << "Unknown completion type"; break; } } diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index 3aebf747c13..ad81f5194f9 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -21,12 +21,12 @@ #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "gtest/gtest.h" #include #include -#include #include #include @@ -37,7 +37,7 @@ #include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" -#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x) +#define LOG_TEST(x) LOG(INFO) << x static void* create_test_tag(void) { static intptr_t i = 0; @@ -61,7 +61,7 @@ static void shutdown_and_destroy(grpc_completion_queue* cc) { break; } default: { - gpr_log(GPR_ERROR, "Unknown completion type"); + LOG(ERROR) << "Unknown completion type"; break; } } @@ -155,20 +155,20 @@ static void producer_thread(void* arg) { test_thread_options* opt = static_cast(arg); int i; - gpr_log(GPR_INFO, "producer %d started", opt->id); + LOG(INFO) << "producer " << opt->id << " started"; gpr_event_set(&opt->on_started, reinterpret_cast(1)); ASSERT_TRUE(gpr_event_wait(opt->phase1, ten_seconds_time())); - gpr_log(GPR_INFO, "producer %d phase 1", opt->id); + LOG(INFO) << "producer " << opt->id << " phase 1"; for (i = 0; i < TEST_THREAD_EVENTS; i++) { ASSERT_TRUE(grpc_cq_begin_op(opt->cc, (void*)(intptr_t)1)); } - gpr_log(GPR_INFO, "producer %d phase 1 done", opt->id); + LOG(INFO) << "producer " << opt->id << " phase 1 done"; gpr_event_set(&opt->on_phase1_done, reinterpret_cast(1)); ASSERT_TRUE(gpr_event_wait(opt->phase2, ten_seconds_time())); - gpr_log(GPR_INFO, "producer %d phase 2", opt->id); + LOG(INFO) << "producer " << opt->id << " phase 2"; for (i = 0; i < TEST_THREAD_EVENTS; i++) { grpc_core::ExecCtx exec_ctx; grpc_cq_end_op(opt->cc, reinterpret_cast(1), absl::OkStatus(), @@ -178,7 +178,7 @@ static void producer_thread(void* arg) { opt->events_triggered++; } - gpr_log(GPR_INFO, "producer %d phase 2 done", opt->id); + LOG(INFO) << "producer " << opt->id << " phase 2 done"; gpr_event_set(&opt->on_finished, reinterpret_cast(1)); } @@ -186,17 +186,17 @@ static void consumer_thread(void* arg) { test_thread_options* opt = static_cast(arg); grpc_event ev; - gpr_log(GPR_INFO, "consumer %d started", opt->id); + LOG(INFO) << "consumer " << opt->id << " started"; gpr_event_set(&opt->on_started, reinterpret_cast(1)); ASSERT_TRUE(gpr_event_wait(opt->phase1, ten_seconds_time())); - gpr_log(GPR_INFO, "consumer %d phase 1", opt->id); + LOG(INFO) << "consumer " << opt->id << " phase 1"; - gpr_log(GPR_INFO, "consumer %d phase 1 done", opt->id); + LOG(INFO) << "consumer " << opt->id << " phase 1 done"; gpr_event_set(&opt->on_phase1_done, reinterpret_cast(1)); ASSERT_TRUE(gpr_event_wait(opt->phase2, ten_seconds_time())); - gpr_log(GPR_INFO, "consumer %d phase 2", opt->id); + LOG(INFO) << "consumer " << opt->id << " phase 2"; for (;;) { ev = grpc_completion_queue_next( opt->cc, gpr_inf_future(GPR_CLOCK_MONOTONIC), nullptr); @@ -206,7 +206,7 @@ static void consumer_thread(void* arg) { opt->events_triggered++; break; case GRPC_QUEUE_SHUTDOWN: - gpr_log(GPR_INFO, "consumer %d phase 2 done", opt->id); + LOG(INFO) << "consumer " << opt->id << " phase 2 done"; gpr_event_set(&opt->on_finished, reinterpret_cast(1)); return; case GRPC_QUEUE_TIMEOUT: @@ -225,8 +225,8 @@ static void test_threading(size_t producers, size_t consumers) { size_t total_consumed = 0; static int optid = 101; - gpr_log(GPR_INFO, "%s: %" PRIuPTR " producers, %" PRIuPTR " consumers", - "test_threading", producers, consumers); + LOG(INFO) << "test_threading: " << producers << " producers, " << consumers + << " consumers"; // start all threads: they will wait for phase1 grpc_core::Thread* threads = static_cast( @@ -252,17 +252,17 @@ static void test_threading(size_t producers, size_t consumers) { // start phase1: producers will pre-declare all operations they will // complete - gpr_log(GPR_INFO, "start phase 1"); + LOG(INFO) << "start phase 1"; gpr_event_set(&phase1, reinterpret_cast(1)); - gpr_log(GPR_INFO, "wait phase 1"); + LOG(INFO) << "wait phase 1"; for (i = 0; i < producers + consumers; i++) { ASSERT_TRUE(gpr_event_wait(&options[i].on_phase1_done, ten_seconds_time())); } - gpr_log(GPR_INFO, "done phase 1"); + LOG(INFO) << "done phase 1"; // start phase2: operations will complete, and consumers will consume them - gpr_log(GPR_INFO, "start phase 2"); + LOG(INFO) << "start phase 2"; gpr_event_set(&phase2, reinterpret_cast(1)); // in parallel, we shutdown the completion channel - all events should still @@ -270,11 +270,11 @@ static void test_threading(size_t producers, size_t consumers) { grpc_completion_queue_shutdown(cc); // join all threads - gpr_log(GPR_INFO, "wait phase 2"); + LOG(INFO) << "wait phase 2"; for (i = 0; i < producers + consumers; i++) { ASSERT_TRUE(gpr_event_wait(&options[i].on_finished, ten_seconds_time())); } - gpr_log(GPR_INFO, "done phase 2"); + LOG(INFO) << "done phase 2"; // destroy the completion channel grpc_completion_queue_destroy(cc); diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index 090d0ba1f5a..33bc43d2752 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -23,6 +23,7 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "gtest/gtest.h" @@ -30,7 +31,6 @@ #include #include #include -#include #include #include @@ -192,7 +192,7 @@ TEST(ConcurrentConnectivityTest, RunConcurrentConnectivityTest) { // First round, no server { - gpr_log(GPR_DEBUG, "Wave 1"); + VLOG(2) << "Wave 1"; grpc_core::Thread threads[NUM_THREADS]; args.addr = "localhost:54321"; for (auto& th : threads) { @@ -207,7 +207,7 @@ TEST(ConcurrentConnectivityTest, RunConcurrentConnectivityTest) { // Second round, actual grpc server { - gpr_log(GPR_DEBUG, "Wave 2"); + VLOG(2) << "Wave 2"; int port = grpc_pick_unused_port_or_die(); args.addr = absl::StrCat("localhost:", port); args.server = grpc_server_create(nullptr, nullptr); @@ -239,7 +239,7 @@ TEST(ConcurrentConnectivityTest, RunConcurrentConnectivityTest) { // Third round, bogus tcp server { - gpr_log(GPR_DEBUG, "Wave 3"); + VLOG(2) << "Wave 3"; auto* pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(pollset, &args.mu); args.pollset.push_back(pollset); diff --git a/test/core/test_util/cmdline.h b/test/core/test_util/cmdline.h index 4be2fa6dbad..d118d6a9412 100644 --- a/test/core/test_util/cmdline.h +++ b/test/core/test_util/cmdline.h @@ -21,6 +21,8 @@ #include +#include "absl/log/log.h" + #include /// Simple command line parser. @@ -43,7 +45,7 @@ /// gpr_cmdline_destroy(cl); /// if (verbose) { -/// gpr_log(GPR_INFO, "Goodbye cruel world!"); +/// LOG(INFO) << "Goodbye cruel world!"; /// } /// return 0; diff --git a/test/core/test_util/reconnect_server.cc b/test/core/test_util/reconnect_server.cc index 036ee3d1e52..68031263f52 100644 --- a/test/core/test_util/reconnect_server.cc +++ b/test/core/test_util/reconnect_server.cc @@ -20,10 +20,10 @@ #include +#include "absl/log/log.h" #include "absl/strings/string_view.h" #include -#include #include #include "src/core/lib/iomgr/endpoint.h" @@ -37,14 +37,14 @@ static void pretty_print_backoffs(reconnect_server* server) { int i = 1; double expected_backoff = 1000.0, backoff; timestamp_list* head = server->head; - gpr_log(GPR_INFO, "reconnect server: new connection"); + LOG(INFO) << "reconnect server: new connection"; for (head = server->head; head && head->next; head = head->next, i++) { diff = gpr_time_sub(head->next->timestamp, head->timestamp); backoff = gpr_time_to_millis(diff); - gpr_log(GPR_INFO, - "retry %2d:backoff %6.2fs,expected backoff %6.2fs, jitter %4.2f%%", - i, backoff / 1000.0, expected_backoff / 1000.0, - (backoff - expected_backoff) * 100.0 / expected_backoff); + LOG(INFO) << absl::StrFormat( + "retry %2d:backoff %6.2fs,expected backoff %6.2fs, jitter %4.2f%%", i, + backoff / 1000.0, expected_backoff / 1000.0, + (backoff - expected_backoff) * 100.0 / expected_backoff); expected_backoff *= 1.6; int max_reconnect_backoff_ms = 120 * 1000; if (server->max_reconnect_backoff_ms > 0) { @@ -73,11 +73,10 @@ static void on_connect(void* arg, grpc_endpoint* tcp, server->peer = new std::string(peer); } else { if (last_colon == std::string::npos) { - gpr_log(GPR_ERROR, "peer does not contain a ':'"); + LOG(ERROR) << "peer does not contain a ':'"; } else if (peer.compare(0, static_cast(last_colon), *server->peer) != 0) { - gpr_log(GPR_ERROR, "mismatched peer! %s vs %s", server->peer->c_str(), - std::string(peer).c_str()); + LOG(ERROR) << "mismatched peer! " << *server->peer << " vs " << peer; } } new_tail = static_cast(gpr_malloc(sizeof(timestamp_list))); diff --git a/test/core/test_util/test_config.cc b/test/core/test_util/test_config.cc index 11c74d2a36c..b816f5f1b10 100644 --- a/test/core/test_util/test_config.cc +++ b/test/core/test_util/test_config.cc @@ -22,6 +22,7 @@ #include #include "absl/debugging/failure_signal_handler.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/str_format.h" @@ -126,11 +127,11 @@ void grpc_test_init(int* argc, char** argv) { grpc_core::testing::InitializeStackTracer(argv[0]); absl::FailureSignalHandlerOptions options; absl::InstallFailureSignalHandler(options); - gpr_log(GPR_DEBUG, - "test slowdown factor: sanitizer=%" PRId64 ", fixture=%" PRId64 - ", poller=%" PRId64 ", total=%" PRId64, - grpc_test_sanitizer_slowdown_factor(), g_fixture_slowdown_factor, - g_poller_slowdown_factor, grpc_test_slowdown_factor()); + VLOG(2) << "test slowdown factor: sanitizer=" + << grpc_test_sanitizer_slowdown_factor() + << ", fixture=" << g_fixture_slowdown_factor + << ", poller=" << g_poller_slowdown_factor + << ", total=" << grpc_test_slowdown_factor(); // seed rng with pid, so we don't end up with the same random numbers as a // concurrently running test binary srand(seed()); @@ -160,7 +161,7 @@ TestEnvironment::~TestEnvironment() { // This will wait until gRPC shutdown has actually happened to make sure // no gRPC resources (such as thread) are active. (timeout = 10s) if (!grpc_wait_until_shutdown(10)) { - gpr_log(GPR_ERROR, "Timeout in waiting for gRPC shutdown"); + LOG(ERROR) << "Timeout in waiting for gRPC shutdown"; } if (BuiltUnderMsan()) { // This is a workaround for MSAN. MSAN doesn't like having shutdown thread @@ -171,7 +172,7 @@ TestEnvironment::~TestEnvironment() { gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(500, GPR_TIMESPAN))); } - gpr_log(GPR_INFO, "TestEnvironment ends"); + LOG(INFO) << "TestEnvironment ends"; } TestGrpcScope::TestGrpcScope() { grpc_init(); } @@ -179,7 +180,7 @@ TestGrpcScope::TestGrpcScope() { grpc_init(); } TestGrpcScope::~TestGrpcScope() { grpc_shutdown(); if (!grpc_wait_until_shutdown(10)) { - gpr_log(GPR_ERROR, "Timeout in waiting for gRPC shutdown"); + LOG(ERROR) << "Timeout in waiting for gRPC shutdown"; } } diff --git a/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc b/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc index a333fd85417..e7f58d93c94 100644 --- a/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc +++ b/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc @@ -22,10 +22,10 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include -#include #include #include #include @@ -69,7 +69,7 @@ class FakeHandshakerService : public HandshakerService::Service { HandshakerContext context; HandshakerReq request; HandshakerResp response; - gpr_log(GPR_DEBUG, "Start a new handshake."); + VLOG(2) << "Start a new handshake."; while (stream->Read(&request)) { status = ProcessRequest(&context, request, &response); if (!status.ok()) return WriteErrorResponse(stream, status); @@ -101,13 +101,13 @@ class FakeHandshakerService : public HandshakerService::Service { CHECK_NE(response, nullptr); response->Clear(); if (request.has_client_start()) { - gpr_log(GPR_DEBUG, "Process client start request."); + VLOG(2) << "Process client start request."; return ProcessClientStart(context, request.client_start(), response); } else if (request.has_server_start()) { - gpr_log(GPR_DEBUG, "Process server start request."); + VLOG(2) << "Process server start request."; return ProcessServerStart(context, request.server_start(), response); } else if (request.has_next()) { - gpr_log(GPR_DEBUG, "Process next request."); + VLOG(2) << "Process next request."; return ProcessNext(context, request.next(), response); } return Status(StatusCode::INVALID_ARGUMENT, "Request is empty."); diff --git a/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc b/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc index 1b9bbe894dd..65a32533d42 100644 --- a/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc +++ b/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc @@ -32,6 +32,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" @@ -40,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -113,8 +113,7 @@ class FakeHandshakeServer { // TODO(apolcyn): when removing the global concurrent handshake limiting // queue, set MAX_CONCURRENT_STREAMS on this server. server_ = builder.BuildAndStart(); - gpr_log(GPR_INFO, "Fake handshaker server listening on %s", - address_.c_str()); + LOG(INFO) << "Fake handshaker server listening on " << address_; } ~FakeHandshakeServer() { @@ -148,13 +147,12 @@ class TestServer { server_creds)); grpc_server_credentials_release(server_creds); grpc_server_start(server_); - gpr_log(GPR_DEBUG, "Start TestServer %p. listen on %s", this, - server_addr_.c_str()); + VLOG(2) << "Start TestServer " << this << ". listen on " << server_addr_; server_thd_ = std::make_unique(PollUntilShutdown, this); } ~TestServer() { - gpr_log(GPR_DEBUG, "Begin dtor of TestServer %p", this); + VLOG(2) << "Begin dtor of TestServer " << this; grpc_server_shutdown_and_notify(server_, server_cq_, this); server_thd_->join(); grpc_server_destroy(server_); @@ -170,7 +168,7 @@ class TestServer { self->server_cq_, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); CHECK(ev.type == GRPC_OP_COMPLETE); CHECK(ev.tag == self); - gpr_log(GPR_DEBUG, "TestServer %p stop polling", self); + VLOG(2) << "TestServer " << self << " stop polling"; } private: @@ -210,7 +208,7 @@ class ConnectLoopRunner { static void ConnectLoop(const ConnectLoopRunner* self) { for (size_t i = 0; i < self->loops_; i++) { - gpr_log(GPR_DEBUG, "runner:%p connect_loop begin loop %ld", self, i); + VLOG(2) << "runner:" << self << " connect_loop begin loop " << i; grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); grpc_channel* channel = create_secure_channel_for_test( @@ -259,7 +257,7 @@ class ConnectLoopRunner { grpc_completion_queue_shutdown(cq); drain_cq(cq); grpc_completion_queue_destroy(cq); - gpr_log(GPR_DEBUG, "runner:%p connect_loop finished loop %ld", self, i); + VLOG(2) << "runner:" << self << " connect_loop finished loop " << i; } } @@ -296,8 +294,7 @@ TEST(AltsConcurrentConnectivityTest, TestConcurrentClientServerHandshakes) { TestServer test_server; size_t num_concurrent_connects = 50; std::vector> connect_loop_runners; - gpr_log(GPR_DEBUG, - "start performing concurrent expected-to-succeed connects"); + VLOG(2) << "start performing concurrent expected-to-succeed connects"; for (size_t i = 0; i < num_concurrent_connects; i++) { connect_loop_runners.push_back(std::make_unique( test_server.address(), fake_handshake_server.address(), @@ -306,8 +303,7 @@ TEST(AltsConcurrentConnectivityTest, TestConcurrentClientServerHandshakes) { 0 /* reconnect_backoff_ms unset */)); } connect_loop_runners.clear(); - gpr_log(GPR_DEBUG, - "done performing concurrent expected-to-succeed connects"); + VLOG(2) << "done performing concurrent expected-to-succeed connects"; } } @@ -336,7 +332,7 @@ TEST(AltsConcurrentConnectivityTest, { std::vector> connect_loop_runners; size_t num_concurrent_connects = 100; - gpr_log(GPR_DEBUG, "start performing concurrent expected-to-fail connects"); + VLOG(2) << "start performing concurrent expected-to-fail connects"; for (size_t i = 0; i < num_concurrent_connects; i++) { connect_loop_runners.push_back(std::make_unique( fake_backend_server.address(), fake_handshake_server.address(), @@ -345,7 +341,7 @@ TEST(AltsConcurrentConnectivityTest, 0 /* reconnect_backoff_ms unset */)); } connect_loop_runners.clear(); - gpr_log(GPR_DEBUG, "done performing concurrent expected-to-fail connects"); + VLOG(2) << "done performing concurrent expected-to-fail connects"; } } @@ -368,7 +364,7 @@ TEST(AltsConcurrentConnectivityTest, { std::vector> connect_loop_runners; size_t num_concurrent_connects = 100; - gpr_log(GPR_DEBUG, "start performing concurrent expected-to-fail connects"); + VLOG(2) << "start performing concurrent expected-to-fail connects"; for (size_t i = 0; i < num_concurrent_connects; i++) { connect_loop_runners.push_back(std::make_unique( fake_backend_server.address(), fake_handshake_server.address(), @@ -377,7 +373,7 @@ TEST(AltsConcurrentConnectivityTest, 0 /* reconnect_backoff_ms unset */)); } connect_loop_runners.clear(); - gpr_log(GPR_DEBUG, "done performing concurrent expected-to-fail connects"); + VLOG(2) << "done performing concurrent expected-to-fail connects"; } } @@ -400,7 +396,7 @@ TEST(AltsConcurrentConnectivityTest, { std::vector> connect_loop_runners; size_t num_concurrent_connects = 100; - gpr_log(GPR_DEBUG, "start performing concurrent expected-to-fail connects"); + VLOG(2) << "start performing concurrent expected-to-fail connects"; for (size_t i = 0; i < num_concurrent_connects; i++) { connect_loop_runners.push_back(std::make_unique( fake_backend_server.address(), fake_handshake_server.address(), @@ -409,7 +405,7 @@ TEST(AltsConcurrentConnectivityTest, 100 /* reconnect_backoff_ms */)); } connect_loop_runners.clear(); - gpr_log(GPR_DEBUG, "done performing concurrent expected-to-fail connects"); + VLOG(2) << "done performing concurrent expected-to-fail connects"; } } diff --git a/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc b/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc index dbf65518e56..1afa79ca951 100644 --- a/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc +++ b/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc @@ -18,13 +18,14 @@ #include "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" +#include "absl/log/log.h" + bool grpc_gcp_handshaker_resp_set_peer_rpc_versions( grpc_gcp_HandshakerResp* resp, upb_Arena* arena, uint32_t max_major, uint32_t max_minor, uint32_t min_major, uint32_t min_minor) { if (resp == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr argument to " - "grpc_gcp_handshaker_resp_set_peer_rpc_versions()."); + LOG(ERROR) << "Invalid nullptr argument to " + "grpc_gcp_handshaker_resp_set_peer_rpc_versions()."; return false; } grpc_gcp_rpc_protocol_versions versions; @@ -50,7 +51,7 @@ grpc_gcp_HandshakerReq* grpc_gcp_handshaker_req_decode(grpc_slice slice, grpc_gcp_HandshakerReq* resp = grpc_gcp_HandshakerReq_parse( reinterpret_cast(buf), buf_size, arena); if (!resp) { - gpr_log(GPR_ERROR, "grpc_gcp_HandshakerReq decode error"); + LOG(ERROR) << "grpc_gcp_HandshakerReq decode error"; return nullptr; } return resp; diff --git a/test/core/tsi/ssl_transport_security_test.cc b/test/core/tsi/ssl_transport_security_test.cc index ff1e0dcfa58..a66720e0ca0 100644 --- a/test/core/tsi/ssl_transport_security_test.cc +++ b/test/core/tsi/ssl_transport_security_test.cc @@ -27,11 +27,11 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include #include -#include #include #include "src/core/lib/gprpp/memory.h" @@ -710,7 +710,7 @@ INSTANTIATE_TEST_SUITE_P( }); TEST_P(SslTransportSecurityTest, DoHandshakeTinyHandshakeBuffer) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_tiny_handshake_buffer"); + LOG(INFO) << "ssl_tsi_test_do_handshake_tiny_handshake_buffer"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); ssl_tsi_test_fixture_->handshake_buffer_size = @@ -722,7 +722,7 @@ TEST_P(SslTransportSecurityTest, DoHandshakeTinyHandshakeBuffer) { } TEST_P(SslTransportSecurityTest, DoHandshakeSmallHandshakeBuffer) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_small_handshake_buffer"); + LOG(INFO) << "ssl_tsi_test_do_handshake_small_handshake_buffer"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); ssl_tsi_test_fixture_->handshake_buffer_size = @@ -731,14 +731,14 @@ TEST_P(SslTransportSecurityTest, DoHandshakeSmallHandshakeBuffer) { } TEST_P(SslTransportSecurityTest, DoHandshake) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake"); + LOG(INFO) << "ssl_tsi_test_do_handshake"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); DoHandshake(); } TEST_P(SslTransportSecurityTest, DoHandshakeWithRootStore) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_with_root_store"); + LOG(INFO) << "ssl_tsi_test_do_handshake_with_root_store"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); ssl_fixture_->MutableKeyCertLib()->use_root_store = true; @@ -749,8 +749,8 @@ TEST_P(SslTransportSecurityTest, DoHandshakeWithRootStore) { #if OPENSSL_VERSION_NUMBER >= 0x10100000 TEST_P(SslTransportSecurityTest, DoHandshakeSkippingServerCertificateVerification) { - gpr_log(GPR_INFO, - "ssl_tsi_test_do_handshake_skipping_server_certificate_verification"); + LOG(INFO) + << "ssl_tsi_test_do_handshake_skipping_server_certificate_verification"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); ssl_fixture_->SetVerifyRootCertSubject(false); @@ -763,8 +763,7 @@ TEST_P(SslTransportSecurityTest, #endif TEST_P(SslTransportSecurityTest, DoHandshakeWithLargeServerHandshakeMessages) { - gpr_log(GPR_INFO, - "ssl_tsi_test_do_handshake_with_large_server_handshake_messages"); + LOG(INFO) << "ssl_tsi_test_do_handshake_with_large_server_handshake_messages"; std::string trust_bundle = GenerateTrustBundle(); SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); @@ -792,7 +791,7 @@ TEST_P(SslTransportSecurityTest, DoHandshakeWithLargeServerHandshakeMessages) { } TEST_P(SslTransportSecurityTest, DoHandshakeWithClientAuthentication) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_with_client_authentication"); + LOG(INFO) << "ssl_tsi_test_do_handshake_with_client_authentication"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); ssl_fixture_->SetForceClientAuth(true); @@ -801,9 +800,8 @@ TEST_P(SslTransportSecurityTest, DoHandshakeWithClientAuthentication) { TEST_P(SslTransportSecurityTest, DoHandshakeWithClientAuthenticationAndRootStore) { - gpr_log( - GPR_INFO, - "ssl_tsi_test_do_handshake_with_client_authentication_and_root_store"); + LOG(INFO) + << "ssl_tsi_test_do_handshake_with_client_authentication_and_root_store"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); ssl_fixture_->SetForceClientAuth(true); @@ -813,8 +811,8 @@ TEST_P(SslTransportSecurityTest, TEST_P(SslTransportSecurityTest, DoHandshakeWithServerNameIndicationExactDomain) { - gpr_log(GPR_INFO, - "ssl_tsi_test_do_handshake_with_server_name_indication_exact_domain"); + LOG(INFO) + << "ssl_tsi_test_do_handshake_with_server_name_indication_exact_domain"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); // server1 cert contains "waterzooi.test.google.be" in SAN. @@ -825,9 +823,8 @@ TEST_P(SslTransportSecurityTest, TEST_P(SslTransportSecurityTest, DoHandshakeWithServerNameIndicationWildStarDomain) { - gpr_log( - GPR_INFO, - "ssl_tsi_test_do_handshake_with_server_name_indication_wild_star_domain"); + LOG(INFO) << "ssl_tsi_test_do_handshake_with_server_name_indication_wild_" + "star_domain"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); // server1 cert contains "*.test.google.fr" in SAN. @@ -837,8 +834,7 @@ TEST_P(SslTransportSecurityTest, } TEST_P(SslTransportSecurityTest, DoHandshakeWithWrongServerNameIndication) { - gpr_log(GPR_INFO, - "ssl_tsi_test_do_handshake_with_wrong_server_name_indication"); + LOG(INFO) << "ssl_tsi_test_do_handshake_with_wrong_server_name_indication"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); // server certs do not contain "test.google.cn". @@ -849,9 +845,8 @@ TEST_P(SslTransportSecurityTest, DoHandshakeWithWrongServerNameIndication) { TEST_P(SslTransportSecurityTest, DoHandshakeWithInvalidAndIgnoredServerNameIndication) { - gpr_log(GPR_INFO, - "ssl_tsi_test_do_handshake_with_invalid_and_ignored_server_name_" - "indication"); + LOG(INFO) << "ssl_tsi_test_do_handshake_with_invalid_and_ignored_server_name_" + "indication"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); // SNI that's an IP address will be ignored. @@ -861,7 +856,7 @@ TEST_P(SslTransportSecurityTest, } TEST_P(SslTransportSecurityTest, DoHandshakeWithBadServerCert) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_with_bad_server_cert"); + LOG(INFO) << "ssl_tsi_test_do_handshake_with_bad_server_cert"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); ssl_fixture_->MutableKeyCertLib()->use_bad_server_cert = true; @@ -869,7 +864,7 @@ TEST_P(SslTransportSecurityTest, DoHandshakeWithBadServerCert) { } TEST_P(SslTransportSecurityTest, DoHandshakeWithBadClientCert) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_with_bad_client_cert"); + LOG(INFO) << "ssl_tsi_test_do_handshake_with_bad_client_cert"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); ssl_fixture_->MutableKeyCertLib()->use_bad_client_cert = true; @@ -880,7 +875,7 @@ TEST_P(SslTransportSecurityTest, DoHandshakeWithBadClientCert) { #ifdef OPENSSL_IS_BORINGSSL // BoringSSL and OpenSSL have different behaviors on mismatched ALPN. TEST_P(SslTransportSecurityTest, DoHandshakeAlpnClientNoServer) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_alpn_client_no_server"); + LOG(INFO) << "ssl_tsi_test_do_handshake_alpn_client_no_server"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); ssl_fixture_->SetAlpnMode(ALPN_CLIENT_NO_SERVER); @@ -888,7 +883,7 @@ TEST_P(SslTransportSecurityTest, DoHandshakeAlpnClientNoServer) { } TEST_P(SslTransportSecurityTest, DoHandshakeAlpnClientServerMismatch) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_alpn_client_server_mismatch"); + LOG(INFO) << "ssl_tsi_test_do_handshake_alpn_client_server_mismatch"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); ssl_fixture_->SetAlpnMode(ALPN_CLIENT_SERVER_MISMATCH); @@ -896,7 +891,7 @@ TEST_P(SslTransportSecurityTest, DoHandshakeAlpnClientServerMismatch) { } TEST_P(SslTransportSecurityTest, DoRoundTripForAllConfigs) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_round_trip_for_all_configs"); + LOG(INFO) << "ssl_tsi_test_do_round_trip_for_all_configs"; unsigned int* bit_array = static_cast( gpr_zalloc(sizeof(unsigned int) * TSI_TEST_NUM_OF_ARGUMENTS)); const unsigned int mask = 1U << (TSI_TEST_NUM_OF_ARGUMENTS - 1); @@ -919,7 +914,7 @@ TEST_P(SslTransportSecurityTest, DoRoundTripForAllConfigs) { } TEST_P(SslTransportSecurityTest, DoRoundTripWithErrorOnStack) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_round_trip_with_error_on_stack"); + LOG(INFO) << "ssl_tsi_test_do_round_trip_with_error_on_stack"; // Invoke an SSL function that causes an error, and ensure the error // makes it to the stack. ASSERT_FALSE(EC_KEY_new_by_curve_name(NID_rsa)); @@ -930,7 +925,7 @@ TEST_P(SslTransportSecurityTest, DoRoundTripWithErrorOnStack) { } TEST_P(SslTransportSecurityTest, DoRoundTripOddBufferSize) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_round_trip_odd_buffer_size"); + LOG(INFO) << "ssl_tsi_test_do_round_trip_odd_buffer_size"; const size_t odd_sizes[] = {1025, 2051, 4103, 8207, 16409}; size_t size = sizeof(odd_sizes) / sizeof(size_t); // 1. This test is extremely slow under MSAN and TSAN. @@ -962,7 +957,7 @@ TEST_P(SslTransportSecurityTest, DoRoundTripOddBufferSize) { } TEST_P(SslTransportSecurityTest, DoHandshakeSessionCache) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_session_cache"); + LOG(INFO) << "ssl_tsi_test_do_handshake_session_cache"; tsi_ssl_session_cache* session_cache = tsi_ssl_session_cache_create_lru(16); char session_ticket_key[kSessionTicketEncryptionKeySize]; auto do_handshake = [this, &session_ticket_key, @@ -995,7 +990,7 @@ TEST_P(SslTransportSecurityTest, DoHandshakeSessionCache) { #endif // OPENSSL_IS_BORINGSSL TEST_P(SslTransportSecurityTest, DoHandshakeAlpnServerNoClient) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_alpn_server_no_client"); + LOG(INFO) << "ssl_tsi_test_do_handshake_alpn_server_no_client"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); ssl_fixture_->SetAlpnMode(ALPN_SERVER_NO_CLIENT); @@ -1003,7 +998,7 @@ TEST_P(SslTransportSecurityTest, DoHandshakeAlpnServerNoClient) { } TEST_P(SslTransportSecurityTest, DoHandshakeAlpnClientServerOk) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_alpn_client_server_ok"); + LOG(INFO) << "ssl_tsi_test_do_handshake_alpn_client_server_ok"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); ssl_fixture_->SetAlpnMode(ALPN_CLIENT_SERVER_OK); @@ -1011,7 +1006,7 @@ TEST_P(SslTransportSecurityTest, DoHandshakeAlpnClientServerOk) { } TEST_P(SslTransportSecurityTest, DoHandshakeWithCustomBioPair) { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_with_custom_bio_pair"); + LOG(INFO) << "ssl_tsi_test_do_handshake_with_custom_bio_pair"; SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), /*send_client_ca_list=*/std::get<1>(GetParam())); #if OPENSSL_VERSION_NUMBER >= 0x10100000 @@ -1143,7 +1138,7 @@ TEST(SslTransportSecurityTest, TestClientHandshakerFactoryBadParams) { } TEST(SslTransportSecurityTest, DuplicateRootCertificates) { - gpr_log(GPR_INFO, "ssl_tsi_test_duplicate_root_certificates"); + LOG(INFO) << "ssl_tsi_test_duplicate_root_certificates"; char* root_cert = load_file(SSL_TSI_TEST_CREDENTIALS_DIR "ca.pem"); char* dup_root_cert = static_cast( gpr_zalloc(sizeof(char) * (strlen(root_cert) * 2 + 1))); @@ -1159,7 +1154,7 @@ TEST(SslTransportSecurityTest, DuplicateRootCertificates) { } TEST(SslTransportSecurityTest, ExtractX509SubjectNames) { - gpr_log(GPR_INFO, "ssl_tsi_test_extract_x509_subject_names"); + LOG(INFO) << "ssl_tsi_test_extract_x509_subject_names"; char* cert = load_file(SSL_TSI_TEST_CREDENTIALS_DIR "multi-domain.pem"); tsi_peer peer; ASSERT_EQ(tsi_ssl_extract_x509_subject_names_from_pem_cert(cert, &peer), @@ -1263,7 +1258,7 @@ TEST(SslTransportSecurityTest, ExtractX509SubjectNames) { } TEST(SslTransportSecurityTest, ExtractCertChain) { - gpr_log(GPR_INFO, "ssl_tsi_test_extract_cert_chain"); + LOG(INFO) << "ssl_tsi_test_extract_cert_chain"; char* cert = load_file(SSL_TSI_TEST_CREDENTIALS_DIR "server1.pem"); char* ca = load_file(SSL_TSI_TEST_CREDENTIALS_DIR "ca.pem"); char* chain = static_cast( diff --git a/test/core/xds/xds_client_fuzzer.cc b/test/core/xds/xds_client_fuzzer.cc index 4653d545713..f7b3e2fc48e 100644 --- a/test/core/xds/xds_client_fuzzer.cc +++ b/test/core/xds/xds_client_fuzzer.cc @@ -20,6 +20,7 @@ #include #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" @@ -28,7 +29,6 @@ #include "absl/types/optional.h" #include -#include #include "src/core/lib/event_engine/default_event_engine.h" #include "src/core/lib/gprpp/orphanable.h" @@ -53,8 +53,7 @@ class Fuzzer { explicit Fuzzer(absl::string_view bootstrap_json) { auto bootstrap = GrpcXdsBootstrap::Create(bootstrap_json); if (!bootstrap.ok()) { - gpr_log(GPR_ERROR, "error creating bootstrap: %s", - bootstrap.status().ToString().c_str()); + LOG(ERROR) << "error creating bootstrap: " << bootstrap.status(); // Leave xds_client_ unset, so Act() will be a no-op. return; } @@ -122,20 +121,18 @@ class Fuzzer { [](const testing::XdsClientTestPeer::ResourceCountLabels& labels, uint64_t count) { - gpr_log(GPR_INFO, - "xds_authority=\"%s\", resource_type=\"%s\", " - "cache_state=\"%s\" count=%" PRIu64, - std::string(labels.xds_authority).c_str(), - std::string(labels.resource_type).c_str(), - std::string(labels.cache_state).c_str(), count); + LOG(INFO) << "xds_authority=\"" << labels.xds_authority + << "\", resource_type=\"" << labels.resource_type + << "\", cache_state=\"" << labels.cache_state + << "\" count=" << count; }); break; case xds_client_fuzzer::Action::kReportServerConnections: testing::XdsClientTestPeer(xds_client_.get()) .TestReportServerConnections( [](absl::string_view xds_server, bool connected) { - gpr_log(GPR_INFO, "xds_server=\"%s\" connected=%d", - std::string(xds_server).c_str(), connected); + LOG(INFO) << "xds_server=\"" << xds_server + << "\" connected=" << connected; }); break; case xds_client_fuzzer::Action::kTriggerConnectionFailure: @@ -174,26 +171,24 @@ class Fuzzer { std::shared_ptr resource, RefCountedPtr /* read_delay_handle */) override { - gpr_log(GPR_INFO, "==> OnResourceChanged(%s %s): %s", - std::string(ResourceType::Get()->type_url()).c_str(), - resource_name_.c_str(), resource->ToString().c_str()); + LOG(INFO) << "==> OnResourceChanged(" << ResourceType::Get()->type_url() + << " " << resource_name_ << "): " << resource->ToString(); } void OnError( absl::Status status, RefCountedPtr /* read_delay_handle */) override { - gpr_log(GPR_INFO, "==> OnError(%s %s): %s", - std::string(ResourceType::Get()->type_url()).c_str(), - resource_name_.c_str(), status.ToString().c_str()); + LOG(INFO) << "==> OnError(" << ResourceType::Get()->type_url() << " " + << resource_name_ << "): " << status; } void OnResourceDoesNotExist( RefCountedPtr /* read_delay_handle */) override { - gpr_log(GPR_INFO, "==> OnResourceDoesNotExist(%s %s)", - std::string(ResourceType::Get()->type_url()).c_str(), - resource_name_.c_str()); + LOG(INFO) << "==> OnResourceDoesNotExist(" + << ResourceType::Get()->type_url() << " " << resource_name_ + << ")"; } private: @@ -208,9 +203,9 @@ class Fuzzer { template void StartWatch(std::map>* watchers, std::string resource_name) { - gpr_log(GPR_INFO, "### StartWatch(%s %s)", - std::string(WatcherType::ResourceType::Get()->type_url()).c_str(), - resource_name.c_str()); + LOG(INFO) << "### StartWatch(" + << WatcherType::ResourceType::Get()->type_url() << " " + << resource_name << ")"; auto watcher = MakeRefCounted(resource_name); (*watchers)[resource_name].insert(watcher.get()); WatcherType::ResourceType::Get()->StartWatch( @@ -220,9 +215,9 @@ class Fuzzer { template void StopWatch(std::map>* watchers, std::string resource_name) { - gpr_log(GPR_INFO, "### StopWatch(%s %s)", - std::string(WatcherType::ResourceType::Get()->type_url()).c_str(), - resource_name.c_str()); + LOG(INFO) << "### StopWatch(" + << WatcherType::ResourceType::Get()->type_url() << " " + << resource_name << ")"; auto& watchers_set = (*watchers)[resource_name]; auto it = watchers_set.begin(); if (it == watchers_set.end()) return; @@ -252,8 +247,8 @@ class Fuzzer { void TriggerConnectionFailure(const std::string& authority, absl::Status status) { - gpr_log(GPR_INFO, "### TriggerConnectionFailure(%s): %s", authority.c_str(), - status.ToString().c_str()); + LOG(INFO) << "### TriggerConnectionFailure(" << authority + << "): " << status; const auto* xds_server = GetServer(authority); if (xds_server == nullptr) return; transport_factory_->TriggerConnectionFailure(*xds_server, @@ -290,14 +285,14 @@ class Fuzzer { void ReadMessageFromClient(const xds_client_fuzzer::StreamId& stream_id, bool ok) { - gpr_log(GPR_INFO, "### ReadMessageFromClient(%s): %s", - StreamIdString(stream_id).c_str(), ok ? "true" : "false"); + LOG(INFO) << "### ReadMessageFromClient(" << StreamIdString(stream_id) + << "): " << (ok ? "true" : "false"); auto stream = GetStream(stream_id); if (stream == nullptr) return; - gpr_log(GPR_INFO, " stream=%p", stream.get()); + LOG(INFO) << " stream=" << stream.get(); auto message = stream->WaitForMessageFromClient(absl::ZeroDuration()); if (message.has_value()) { - gpr_log(GPR_INFO, " completing send_message"); + LOG(INFO) << " completing send_message"; stream->CompleteSendMessageFromClient(ok); } } @@ -305,21 +300,20 @@ class Fuzzer { void SendMessageToClient( const xds_client_fuzzer::StreamId& stream_id, const envoy::service::discovery::v3::DiscoveryResponse& response) { - gpr_log(GPR_INFO, "### SendMessageToClient(%s)", - StreamIdString(stream_id).c_str()); + LOG(INFO) << "### SendMessageToClient(" << StreamIdString(stream_id) << ")"; auto stream = GetStream(stream_id); if (stream == nullptr) return; - gpr_log(GPR_INFO, " stream=%p", stream.get()); + LOG(INFO) << " stream=" << stream.get(); stream->SendMessageToClient(response.SerializeAsString()); } void SendStatusToClient(const xds_client_fuzzer::StreamId& stream_id, absl::Status status) { - gpr_log(GPR_INFO, "### SendStatusToClient(%s): %s", - StreamIdString(stream_id).c_str(), status.ToString().c_str()); + LOG(INFO) << "### SendStatusToClient(" << StreamIdString(stream_id) + << "): " << status; auto stream = GetStream(stream_id); if (stream == nullptr) return; - gpr_log(GPR_INFO, " stream=%p", stream.get()); + LOG(INFO) << " stream=" << stream.get(); stream->MaybeSendStatusToClient(std::move(status)); } From f088d2aa0be4c5b827dfdf8e63931909702bb342 Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap Date: Thu, 16 May 2024 01:47:57 -0700 Subject: [PATCH 02/23] [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. PiperOrigin-RevId: 634264627 --- .../frame_protector/alts_frame_protector.cc | 25 +++++---- .../alts/handshaker/alts_handshaker_client.cc | 52 +++++++++---------- .../tsi/alts/handshaker/alts_tsi_utils.cc | 3 +- .../transport_security_common_api.cc | 3 +- ...lts_grpc_integrity_only_record_protocol.cc | 9 ++-- ..._grpc_privacy_integrity_record_protocol.cc | 8 +-- .../alts_zero_copy_grpc_protector.cc | 7 +-- src/core/tsi/fake_transport_security.cc | 21 ++++---- src/core/tsi/local_transport_security.cc | 11 ++-- .../ssl/session_cache/ssl_session_cache.cc | 8 +-- src/core/tsi/ssl_transport_security.cc | 37 ++++++------- src/core/tsi/ssl_transport_security_utils.cc | 35 ++++++------- src/core/xds/grpc/xds_client_grpc.cc | 3 +- 13 files changed, 112 insertions(+), 110 deletions(-) diff --git a/src/core/tsi/alts/frame_protector/alts_frame_protector.cc b/src/core/tsi/alts/frame_protector/alts_frame_protector.cc index 9b48b181d1f..09415c413d6 100644 --- a/src/core/tsi/alts/frame_protector/alts_frame_protector.cc +++ b/src/core/tsi/alts/frame_protector/alts_frame_protector.cc @@ -24,10 +24,10 @@ #include #include +#include "absl/log/log.h" #include "absl/types/span.h" #include -#include #include #include "src/core/lib/gprpp/memory.h" @@ -70,7 +70,7 @@ static tsi_result seal(alts_frame_protector* impl) { &output_size, &error_details); impl->in_place_protect_bytes_buffered = output_size; if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "%s", error_details); + LOG(ERROR) << error_details; gpr_free(error_details); return TSI_INTERNAL_ERROR; } @@ -88,7 +88,7 @@ static tsi_result alts_protect_flush(tsi_frame_protector* self, if (self == nullptr || protected_output_frames == nullptr || protected_output_frames_size == nullptr || still_pending_size == nullptr) { - gpr_log(GPR_ERROR, "Invalid nullptr arguments to alts_protect_flush()."); + LOG(ERROR) << "Invalid nullptr arguments to alts_protect_flush()."; return TSI_INVALID_ARGUMENT; } alts_frame_protector* impl = reinterpret_cast(self); @@ -113,7 +113,7 @@ static tsi_result alts_protect_flush(tsi_frame_protector* self, } if (!alts_reset_frame_writer(impl->writer, impl->in_place_protect_buffer, impl->in_place_protect_bytes_buffered)) { - gpr_log(GPR_ERROR, "Couldn't reset frame writer."); + LOG(ERROR) << "Couldn't reset frame writer."; return TSI_INTERNAL_ERROR; } } @@ -126,7 +126,7 @@ static tsi_result alts_protect_flush(tsi_frame_protector* self, size_t written_frame_bytes = *protected_output_frames_size; if (!alts_write_frame_bytes(impl->writer, protected_output_frames, &written_frame_bytes)) { - gpr_log(GPR_ERROR, "Couldn't write frame bytes."); + LOG(ERROR) << "Couldn't write frame bytes."; return TSI_INTERNAL_ERROR; } *protected_output_frames_size = written_frame_bytes; @@ -149,7 +149,7 @@ static tsi_result alts_protect(tsi_frame_protector* self, if (self == nullptr || unprotected_bytes == nullptr || unprotected_bytes_size == nullptr || protected_output_frames == nullptr || protected_output_frames_size == nullptr) { - gpr_log(GPR_ERROR, "Invalid nullptr arguments to alts_protect()."); + LOG(ERROR) << "Invalid nullptr arguments to alts_protect()."; return TSI_INVALID_ARGUMENT; } alts_frame_protector* impl = reinterpret_cast(self); @@ -202,7 +202,7 @@ static tsi_result unseal(alts_frame_protector* impl) { impl->max_unprotected_frame_size, alts_get_output_bytes_read(impl->reader), &output_size, &error_details); if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "%s", error_details); + LOG(ERROR) << error_details; gpr_free(error_details); return TSI_DATA_CORRUPTED; } @@ -241,7 +241,7 @@ static tsi_result alts_unprotect(tsi_frame_protector* self, if (self == nullptr || protected_frames_bytes == nullptr || protected_frames_bytes_size == nullptr || unprotected_bytes == nullptr || unprotected_bytes_size == nullptr) { - gpr_log(GPR_ERROR, "Invalid nullptr arguments to alts_unprotect()."); + LOG(ERROR) << "Invalid nullptr arguments to alts_unprotect()."; return TSI_INVALID_ARGUMENT; } alts_frame_protector* impl = reinterpret_cast(self); @@ -256,7 +256,7 @@ static tsi_result alts_unprotect(tsi_frame_protector* self, impl->in_place_unprotect_bytes_processed + impl->overhead_length))) { if (!alts_reset_frame_reader(impl->reader, impl->in_place_unprotect_buffer)) { - gpr_log(GPR_ERROR, "Couldn't reset frame reader."); + LOG(ERROR) << "Couldn't reset frame reader."; return TSI_INTERNAL_ERROR; } impl->in_place_unprotect_bytes_processed = 0; @@ -276,7 +276,7 @@ static tsi_result alts_unprotect(tsi_frame_protector* self, size_t read_frames_bytes_size = *protected_frames_bytes_size; if (!alts_read_frame_bytes(impl->reader, protected_frames_bytes, &read_frames_bytes_size)) { - gpr_log(GPR_ERROR, "Failed to process frame."); + LOG(ERROR) << "Failed to process frame."; return TSI_INTERNAL_ERROR; } *protected_frames_bytes_size = read_frames_bytes_size; @@ -370,8 +370,7 @@ tsi_result alts_create_frame_protector(const uint8_t* key, size_t key_size, size_t* max_protected_frame_size, tsi_frame_protector** self) { if (key == nullptr || self == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to alts_create_frame_protector()."); + LOG(ERROR) << "Invalid nullptr arguments to alts_create_frame_protector()."; return TSI_INTERNAL_ERROR; } char* error_details = nullptr; @@ -379,7 +378,7 @@ tsi_result alts_create_frame_protector(const uint8_t* key, size_t key_size, grpc_status_code status = create_alts_crypters( key, key_size, is_client, is_rekey, impl, &error_details); if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to create ALTS crypters, %s.", error_details); + LOG(ERROR) << "Failed to create ALTS crypters, " << error_details; gpr_free(error_details); return TSI_INTERNAL_ERROR; } diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc index 88cf0c06223..91afee2e5f5 100644 --- a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +++ b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/numbers.h" #include "upb/mem/arena.hpp" @@ -205,13 +206,13 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c, alts_tsi_handshaker* handshaker = client->handshaker; // Invalid input check. if (client->cb == nullptr) { - gpr_log(GPR_ERROR, - "client->cb is nullptr in alts_tsi_handshaker_handle_response()"); + LOG(ERROR) + << "client->cb is nullptr in alts_tsi_handshaker_handle_response()"; return; } if (handshaker == nullptr) { - gpr_log(GPR_ERROR, - "handshaker is nullptr in alts_tsi_handshaker_handle_response()"); + LOG(ERROR) + << "handshaker is nullptr in alts_tsi_handshaker_handle_response()"; handle_response_done( client, TSI_INTERNAL_ERROR, "handshaker is nullptr in alts_tsi_handshaker_handle_response()", @@ -220,14 +221,14 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c, } // TSI handshake has been shutdown. if (alts_tsi_handshaker_has_shutdown(handshaker)) { - gpr_log(GPR_INFO, "TSI handshake shutdown"); + LOG(INFO) << "TSI handshake shutdown"; handle_response_done(client, TSI_HANDSHAKE_SHUTDOWN, "TSI handshake shutdown", nullptr, 0, nullptr); return; } // Check for failed grpc read. if (!is_ok || client->inject_read_failure) { - gpr_log(GPR_INFO, "read failed on grpc call to handshaker service"); + LOG(INFO) << "read failed on grpc call to handshaker service"; handle_response_done(client, TSI_INTERNAL_ERROR, "read failed on grpc call to handshaker service", nullptr, 0, nullptr); @@ -249,7 +250,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c, client->recv_buffer = nullptr; // Invalid handshaker response check. if (resp == nullptr) { - gpr_log(GPR_ERROR, "alts_tsi_utils_deserialize_response() failed"); + LOG(ERROR) << "alts_tsi_utils_deserialize_response() failed"; handle_response_done(client, TSI_DATA_CORRUPTED, "alts_tsi_utils_deserialize_response() failed", nullptr, 0, nullptr); @@ -258,7 +259,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c, const grpc_gcp_HandshakerStatus* resp_status = grpc_gcp_HandshakerResp_status(resp); if (resp_status == nullptr) { - gpr_log(GPR_ERROR, "No status in HandshakerResp"); + LOG(ERROR) << "No status in HandshakerResp"; handle_response_done(client, TSI_DATA_CORRUPTED, "No status in HandshakerResp", nullptr, 0, nullptr); return; @@ -281,7 +282,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c, tsi_result status = alts_tsi_handshaker_result_create(resp, client->is_client, &result); if (status != TSI_OK) { - gpr_log(GPR_ERROR, "alts_tsi_handshaker_result_create() failed"); + LOG(ERROR) << "alts_tsi_handshaker_result_create() failed"; handle_response_done(client, status, "alts_tsi_handshaker_result_create() failed", nullptr, 0, nullptr); @@ -299,7 +300,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c, if (details.size > 0) { error = absl::StrCat("Status ", code, " from handshaker service: ", absl::string_view(details.data, details.size)); - gpr_log(GPR_ERROR, "%s", error.c_str()); + LOG(ERROR) << error; } } // TODO(apolcyn): consider short ciruiting handle_response_done and @@ -357,7 +358,7 @@ static tsi_result continue_make_grpc_call(alts_grpc_handshaker_client* client, if (client->grpc_caller(client->call, ops, static_cast(op - ops), &client->on_handshaker_service_resp_recv) != GRPC_CALL_OK) { - gpr_log(GPR_ERROR, "Start batch operation failed"); + LOG(ERROR) << "Start batch operation failed"; return TSI_INTERNAL_ERROR; } return TSI_OK; @@ -544,21 +545,21 @@ static grpc_byte_buffer* get_serialized_start_client( static tsi_result handshaker_client_start_client(alts_handshaker_client* c) { if (c == nullptr) { - gpr_log(GPR_ERROR, "client is nullptr in handshaker_client_start_client()"); + LOG(ERROR) << "client is nullptr in handshaker_client_start_client()"; return TSI_INVALID_ARGUMENT; } grpc_byte_buffer* buffer = get_serialized_start_client(c); alts_grpc_handshaker_client* client = reinterpret_cast(c); if (buffer == nullptr) { - gpr_log(GPR_ERROR, "get_serialized_start_client() failed"); + LOG(ERROR) << "get_serialized_start_client() failed"; return TSI_INTERNAL_ERROR; } handshaker_client_send_buffer_destroy(client); client->send_buffer = buffer; tsi_result result = make_grpc_call(&client->base, true /* is_start */); if (result != TSI_OK) { - gpr_log(GPR_ERROR, "make_grpc_call() failed"); + LOG(ERROR) << "make_grpc_call() failed"; } return result; } @@ -603,21 +604,21 @@ static grpc_byte_buffer* get_serialized_start_server( static tsi_result handshaker_client_start_server(alts_handshaker_client* c, grpc_slice* bytes_received) { if (c == nullptr || bytes_received == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to handshaker_client_start_server()"); + LOG(ERROR) << "Invalid arguments to handshaker_client_start_server()"; return TSI_INVALID_ARGUMENT; } alts_grpc_handshaker_client* client = reinterpret_cast(c); grpc_byte_buffer* buffer = get_serialized_start_server(c, bytes_received); if (buffer == nullptr) { - gpr_log(GPR_ERROR, "get_serialized_start_server() failed"); + LOG(ERROR) << "get_serialized_start_server() failed"; return TSI_INTERNAL_ERROR; } handshaker_client_send_buffer_destroy(client); client->send_buffer = buffer; tsi_result result = make_grpc_call(&client->base, true /* is_start */); if (result != TSI_OK) { - gpr_log(GPR_ERROR, "make_grpc_call() failed"); + LOG(ERROR) << "make_grpc_call() failed"; } return result; } @@ -640,7 +641,7 @@ static grpc_byte_buffer* get_serialized_next(grpc_slice* bytes_received) { static tsi_result handshaker_client_next(alts_handshaker_client* c, grpc_slice* bytes_received) { if (c == nullptr || bytes_received == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to handshaker_client_next()"); + LOG(ERROR) << "Invalid arguments to handshaker_client_next()"; return TSI_INVALID_ARGUMENT; } alts_grpc_handshaker_client* client = @@ -649,14 +650,14 @@ static tsi_result handshaker_client_next(alts_handshaker_client* c, client->recv_bytes = grpc_core::CSliceRef(*bytes_received); grpc_byte_buffer* buffer = get_serialized_next(bytes_received); if (buffer == nullptr) { - gpr_log(GPR_ERROR, "get_serialized_next() failed"); + LOG(ERROR) << "get_serialized_next() failed"; return TSI_INTERNAL_ERROR; } handshaker_client_send_buffer_destroy(client); client->send_buffer = buffer; tsi_result result = make_grpc_call(&client->base, false /* is_start */); if (result != TSI_OK) { - gpr_log(GPR_ERROR, "make_grpc_call() failed"); + LOG(ERROR) << "make_grpc_call() failed"; } return result; } @@ -716,7 +717,7 @@ alts_handshaker_client* alts_grpc_handshaker_client_create( void* user_data, alts_handshaker_client_vtable* vtable_for_testing, bool is_client, size_t max_frame_size, std::string* error) { if (channel == nullptr || handshaker_service_url == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to alts_handshaker_client_create()"); + LOG(ERROR) << "Invalid arguments to alts_handshaker_client_create()"; return nullptr; } alts_grpc_handshaker_client* client = new alts_grpc_handshaker_client(); @@ -891,8 +892,7 @@ tsi_result alts_handshaker_client_start_client(alts_handshaker_client* client) { client->vtable->client_start != nullptr) { return client->vtable->client_start(client); } - gpr_log(GPR_ERROR, - "client or client->vtable has not been initialized properly"); + LOG(ERROR) << "client or client->vtable has not been initialized properly"; return TSI_INVALID_ARGUMENT; } @@ -902,8 +902,7 @@ tsi_result alts_handshaker_client_start_server(alts_handshaker_client* client, client->vtable->server_start != nullptr) { return client->vtable->server_start(client, bytes_received); } - gpr_log(GPR_ERROR, - "client or client->vtable has not been initialized properly"); + LOG(ERROR) << "client or client->vtable has not been initialized properly"; return TSI_INVALID_ARGUMENT; } @@ -913,8 +912,7 @@ tsi_result alts_handshaker_client_next(alts_handshaker_client* client, client->vtable->next != nullptr) { return client->vtable->next(client, bytes_received); } - gpr_log(GPR_ERROR, - "client or client->vtable has not been initialized properly"); + LOG(ERROR) << "client or client->vtable has not been initialized properly"; return TSI_INVALID_ARGUMENT; } diff --git a/src/core/tsi/alts/handshaker/alts_tsi_utils.cc b/src/core/tsi/alts/handshaker/alts_tsi_utils.cc index 05e5400a7d8..0c4325844bd 100644 --- a/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +++ b/src/core/tsi/alts/handshaker/alts_tsi_utils.cc @@ -19,6 +19,7 @@ #include "src/core/tsi/alts/handshaker/alts_tsi_utils.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -59,7 +60,7 @@ grpc_gcp_HandshakerResp* alts_tsi_utils_deserialize_response( grpc_core::CSliceUnref(slice); grpc_byte_buffer_reader_destroy(&bbr); if (resp == nullptr) { - gpr_log(GPR_ERROR, "grpc_gcp_handshaker_resp_decode() failed"); + LOG(ERROR) << "grpc_gcp_handshaker_resp_decode() failed"; return nullptr; } return resp; diff --git a/src/core/tsi/alts/handshaker/transport_security_common_api.cc b/src/core/tsi/alts/handshaker/transport_security_common_api.cc index bb3c209a711..79fafc8f0af 100644 --- a/src/core/tsi/alts/handshaker/transport_security_common_api.cc +++ b/src/core/tsi/alts/handshaker/transport_security_common_api.cc @@ -18,6 +18,7 @@ #include "src/core/tsi/alts/handshaker/transport_security_common_api.h" +#include "absl/log/log.h" #include "upb/mem/arena.hpp" #include @@ -100,7 +101,7 @@ bool grpc_gcp_rpc_protocol_versions_decode( reinterpret_cast(GRPC_SLICE_START_PTR(slice)), GRPC_SLICE_LENGTH(slice), arena.ptr()); if (versions_msg == nullptr) { - gpr_log(GPR_ERROR, "cannot deserialize RpcProtocolVersions message"); + LOG(ERROR) << "cannot deserialize RpcProtocolVersions message"; return false; } grpc_gcp_rpc_protocol_versions_assign_from_upb(versions, versions_msg); diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc index 81df2cbb131..8d9a98dbc45 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -69,7 +70,7 @@ static tsi_result alts_grpc_integrity_only_extra_copy_protect( grpc_status_code status = alts_iovec_record_protocol_integrity_only_protect( rp->iovec_rp, rp->iovec_buf, 1, header_iovec, tag_iovec, &error_details); if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to protect, %s", error_details); + LOG(ERROR) << "Failed to protect, " << error_details; gpr_free(error_details); return TSI_INTERNAL_ERROR; } @@ -109,7 +110,7 @@ static tsi_result alts_grpc_integrity_only_protect( rp->iovec_rp, rp->iovec_buf, unprotected_slices->count, header_iovec, tag_iovec, &error_details); if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to protect, %s", error_details); + LOG(ERROR) << "Failed to protect, " << error_details; gpr_free(error_details); return TSI_INTERNAL_ERROR; } @@ -132,7 +133,7 @@ static tsi_result alts_grpc_integrity_only_unprotect( return TSI_INVALID_ARGUMENT; } if (protected_slices->length < rp->header_length + rp->tag_length) { - gpr_log(GPR_ERROR, "Protected slices do not have sufficient data."); + LOG(ERROR) << "Protected slices do not have sufficient data."; return TSI_INVALID_ARGUMENT; } // In this method, rp points to alts_grpc_record_protocol struct @@ -171,7 +172,7 @@ static tsi_result alts_grpc_integrity_only_unprotect( integrity_only_record_protocol->data_sb.count, header_iovec, tag_iovec, &error_details); if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to unprotect, %s", error_details); + LOG(ERROR) << "Failed to unprotect, " << error_details; gpr_free(error_details); return TSI_INTERNAL_ERROR; } diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc index 768c8b775b7..a9aac4948a9 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc @@ -18,6 +18,8 @@ #include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h" +#include "absl/log/log.h" + #include #include #include @@ -60,7 +62,7 @@ static tsi_result alts_grpc_privacy_integrity_protect( rp->iovec_rp, rp->iovec_buf, unprotected_slices->count, protected_iovec, &error_details); if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to protect, %s", error_details); + LOG(ERROR) << "Failed to protect, " << error_details; gpr_free(error_details); grpc_core::CSliceUnref(protected_slice); return TSI_INTERNAL_ERROR; @@ -84,7 +86,7 @@ static tsi_result alts_grpc_privacy_integrity_unprotect( // Allocates memory for output frame. In privacy-integrity unprotect, the // unprotected data are stored in a newly allocated buffer. if (protected_slices->length < rp->header_length + rp->tag_length) { - gpr_log(GPR_ERROR, "Protected slices do not have sufficient data."); + LOG(ERROR) << "Protected slices do not have sufficient data."; return TSI_INVALID_ARGUMENT; } size_t unprotected_frame_size = @@ -105,7 +107,7 @@ static tsi_result alts_grpc_privacy_integrity_unprotect( rp->iovec_rp, header_iovec, rp->iovec_buf, protected_slices->count, unprotected_iovec, &error_details); if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to unprotect, %s", error_details); + LOG(ERROR) << "Failed to unprotect, " << error_details; gpr_free(error_details); grpc_core::CSliceUnref(unprotected_slice); return TSI_INTERNAL_ERROR; diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc index 6847dfdaa96..3d29dc6de9e 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -93,7 +94,7 @@ static bool read_frame_size(const grpc_slice_buffer* sb, (static_cast(frame_size_buffer[1]) << 8) | static_cast(frame_size_buffer[0]); if (frame_size > kMaxFrameLength) { - gpr_log(GPR_ERROR, "Frame size is larger than maximum frame size"); + LOG(ERROR) << "Frame size is larger than maximum frame size"; return false; } // Returns frame size including frame length field. @@ -124,7 +125,7 @@ static tsi_result create_alts_grpc_record_protocol( kAesGcmTagLength, &crypter, &error_details); if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to create AEAD crypter, %s", error_details); + LOG(ERROR) << "Failed to create AEAD crypter, " << error_details; gpr_free(error_details); return TSI_INTERNAL_ERROR; } @@ -153,7 +154,7 @@ static tsi_result alts_zero_copy_grpc_protector_protect( grpc_slice_buffer* protected_slices) { if (self == nullptr || unprotected_slices == nullptr || protected_slices == nullptr) { - gpr_log(GPR_ERROR, "Invalid nullptr arguments to zero-copy grpc protect."); + LOG(ERROR) << "Invalid nullptr arguments to zero-copy grpc protect."; return TSI_INVALID_ARGUMENT; } alts_zero_copy_grpc_protector* protector = diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index 9c39f59fec3..2fffb042bb8 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -22,6 +22,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -31,7 +32,7 @@ #include "src/core/lib/gprpp/memory.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/tsi/transport_security_grpc.h" -#include "src/core/util/useful.h" +#include "src/core/tsi/transport_security_interface.h" // --- Constants. --- #define TSI_FAKE_FRAME_HEADER_SIZE 4 @@ -91,7 +92,7 @@ static const char* tsi_fake_handshake_message_strings[] = { static const char* tsi_fake_handshake_message_to_string(int msg) { if (msg < 0 || msg >= TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { - gpr_log(GPR_ERROR, "Invalid message %d", msg); + LOG(ERROR) << "Invalid message " << msg; return "UNKNOWN"; } return tsi_fake_handshake_message_strings[msg]; @@ -107,7 +108,7 @@ static tsi_result tsi_fake_handshake_message_from_string( return TSI_OK; } } - gpr_log(GPR_ERROR, "Invalid handshake message."); + LOG(ERROR) << "Invalid handshake message."; if (error != nullptr) *error = "invalid handshake message"; return TSI_DATA_CORRUPTED; } @@ -312,8 +313,8 @@ static tsi_result fake_protector_protect(tsi_frame_protector* self, result = tsi_fake_frame_decode(frame_header, &written_in_frame_size, frame, /*error=*/nullptr); if (result != TSI_INCOMPLETE_DATA) { - gpr_log(GPR_ERROR, "tsi_fake_frame_decode returned %s", - tsi_result_to_string(result)); + LOG(ERROR) << "tsi_fake_frame_decode returned " + << tsi_result_to_string(result); return result; } } @@ -469,7 +470,7 @@ static tsi_result fake_zero_copy_grpc_protector_unprotect( if (impl->parsed_frame_size == 0) { impl->parsed_frame_size = read_frame_size(&impl->protected_sb); if (impl->parsed_frame_size <= 4) { - gpr_log(GPR_ERROR, "Invalid frame size."); + LOG(ERROR) << "Invalid frame size."; return TSI_DATA_CORRUPTED; } } @@ -653,7 +654,7 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer( impl->next_message_to_send == TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { // We're done. if (GRPC_TRACE_FLAG_ENABLED(tsi_tracing_enabled)) { - gpr_log(GPR_INFO, "Server is done."); + LOG(INFO) << "Server is done."; } impl->result = TSI_OK; } else { @@ -694,15 +695,15 @@ static tsi_result fake_handshaker_process_bytes_from_peer( tsi_fake_handshake_message_to_string(expected_msg)); } if (GRPC_TRACE_FLAG_ENABLED(tsi_tracing_enabled)) { - gpr_log(GPR_INFO, "%s received %s.", impl->is_client ? "Client" : "Server", - tsi_fake_handshake_message_to_string(received_msg)); + LOG(INFO) << (impl->is_client ? "Client" : "Server") << " received " + << tsi_fake_handshake_message_to_string(received_msg); } tsi_fake_frame_reset(&impl->incoming_frame, 0 /* needs_draining */); impl->needs_incoming_message = 0; if (impl->next_message_to_send == TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { // We're done. if (GRPC_TRACE_FLAG_ENABLED(tsi_tracing_enabled)) { - gpr_log(GPR_INFO, "%s is done.", impl->is_client ? "Client" : "Server"); + LOG(INFO) << (impl->is_client ? "Client" : "Server") << " is done."; } impl->result = TSI_OK; } diff --git a/src/core/tsi/local_transport_security.cc b/src/core/tsi/local_transport_security.cc index 944aee67145..30a2ef7f670 100644 --- a/src/core/tsi/local_transport_security.cc +++ b/src/core/tsi/local_transport_security.cc @@ -22,8 +22,9 @@ #include #include +#include "absl/log/log.h" + #include -#include #include #include @@ -68,7 +69,7 @@ tsi_result handshaker_result_get_unused_bytes(const tsi_handshaker_result* self, const unsigned char** bytes, size_t* bytes_size) { if (self == nullptr || bytes == nullptr || bytes_size == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to get_unused_bytes()"); + LOG(ERROR) << "Invalid arguments to get_unused_bytes()"; return TSI_INVALID_ARGUMENT; } auto* result = reinterpret_cast( @@ -101,7 +102,7 @@ tsi_result create_handshaker_result(const unsigned char* received_bytes, size_t received_bytes_size, tsi_handshaker_result** self) { if (self == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to create_handshaker_result()"); + LOG(ERROR) << "Invalid arguments to create_handshaker_result()"; return TSI_INVALID_ARGUMENT; } local_tsi_handshaker_result* result = @@ -128,7 +129,7 @@ tsi_result handshaker_next(tsi_handshaker* self, tsi_handshaker_on_next_done_cb /*cb*/, void* /*user_data*/, std::string* error) { if (self == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to handshaker_next()"); + LOG(ERROR) << "Invalid arguments to handshaker_next()"; if (error != nullptr) *error = "invalid argument"; return TSI_INVALID_ARGUMENT; } @@ -164,7 +165,7 @@ const tsi_handshaker_vtable handshaker_vtable = { tsi_result tsi_local_handshaker_create(tsi_handshaker** self) { if (self == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to local_tsi_handshaker_create()"); + LOG(ERROR) << "Invalid arguments to local_tsi_handshaker_create()"; return TSI_INVALID_ARGUMENT; } local_tsi_handshaker* handshaker = grpc_core::Zalloc(); diff --git a/src/core/tsi/ssl/session_cache/ssl_session_cache.cc b/src/core/tsi/ssl/session_cache/ssl_session_cache.cc index 4f33c4722ac..de89e3e85fe 100644 --- a/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +++ b/src/core/tsi/ssl/session_cache/ssl_session_cache.cc @@ -19,6 +19,7 @@ #include "src/core/tsi/ssl/session_cache/ssl_session_cache.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -64,9 +65,8 @@ class SslSessionLRUCache::Node { SslSessionLRUCache::SslSessionLRUCache(size_t capacity) : capacity_(capacity) { if (capacity == 0) { - gpr_log( - GPR_ERROR, - "SslSessionLRUCache capacity is zero. SSL sessions cannot be resumed."); + LOG(ERROR) << "SslSessionLRUCache capacity is zero. SSL sessions cannot be " + "resumed."; } } @@ -100,7 +100,7 @@ SslSessionLRUCache::Node* SslSessionLRUCache::FindLocked( void SslSessionLRUCache::Put(const char* key, SslSessionPtr session) { if (session == nullptr) { - gpr_log(GPR_ERROR, "Attempted to put null SSL session in session cache."); + LOG(ERROR) << "Attempted to put null SSL session in session cache."; return; } grpc_core::MutexLock lock(&lock_); diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc index 61ecc279534..6ec4e0a2546 100644 --- a/src/core/tsi/ssl_transport_security.cc +++ b/src/core/tsi/ssl_transport_security.cc @@ -23,6 +23,8 @@ #include +#include "src/core/tsi/transport_security_interface.h" + // TODO(jboeuf): refactor inet_ntop into a portability header. // Note: for whomever reads this and tries to refactor this, this // can't be in grpc, it has to be in gpr. @@ -293,8 +295,7 @@ static tsi_result ssl_get_x509_common_name(X509* cert, unsigned char** utf8, } common_name_asn1 = X509_NAME_ENTRY_get_data(common_name_entry); if (common_name_asn1 == nullptr) { - gpr_log(GPR_ERROR, - "Could not get common name entry asn1 from certificate."); + LOG(ERROR) << "Could not get common name entry asn1 from certificate."; return TSI_INTERNAL_ERROR; } utf8_returned_size = ASN1_STRING_to_UTF8(utf8, common_name_asn1); @@ -804,7 +805,7 @@ static tsi_result populate_ssl_context( } if ((cipher_list != nullptr) && !SSL_CTX_set_cipher_list(context, cipher_list)) { - gpr_log(GPR_ERROR, "Invalid cipher list: %s.", cipher_list); + LOG(ERROR) << "Invalid cipher list: " << cipher_list; return TSI_INVALID_ARGUMENT; } { @@ -862,8 +863,7 @@ static tsi_result build_alpn_protocol_name_list( size_t length = alpn_protocols[i] == nullptr ? 0 : strlen(alpn_protocols[i]); if (length == 0 || length > 255) { - gpr_log(GPR_ERROR, "Invalid protocol name length: %d.", - static_cast(length)); + LOG(ERROR) << "Invalid protocol name length: " << length; return TSI_INVALID_ARGUMENT; } *protocol_name_list_length += length + 1; @@ -892,13 +892,12 @@ static tsi_result build_alpn_protocol_name_list( static int verify_cb(int ok, X509_STORE_CTX* ctx) { int cert_error = X509_STORE_CTX_get_error(ctx); if (cert_error == X509_V_ERR_UNABLE_TO_GET_CRL) { - gpr_log(GPR_INFO, - "Certificate verification failed to find relevant CRL file. " - "Ignoring error."); + LOG(INFO) << "Certificate verification failed to find relevant CRL file. " + "Ignoring error."; return 1; } if (cert_error != 0) { - gpr_log(GPR_ERROR, "Certificate verify failed with code %d", cert_error); + LOG(ERROR) << "Certificate verify failed with code " << cert_error; } return ok; } @@ -942,8 +941,8 @@ static int RootCertExtractCallback(X509_STORE_CTX* ctx, void* /*arg*/) { if (ssl_index < 0) { char err_str[256]; ERR_error_string_n(ERR_get_error(), err_str, sizeof(err_str)); - gpr_log(GPR_ERROR, - "error getting the SSL index from the X509_STORE_CTX: %s", err_str); + LOG(ERROR) << "error getting the SSL index from the X509_STORE_CTX: " + << err_str; return ret; } SSL* ssl = static_cast(X509_STORE_CTX_get_ex_data(ctx, ssl_index)); @@ -987,8 +986,7 @@ static grpc_core::experimental::CrlProvider* GetCrlProvider( } SSL* ssl = static_cast(X509_STORE_CTX_get_ex_data(ctx, ssl_index)); if (ssl == nullptr) { - gpr_log(GPR_INFO, - "error while fetching from CrlProvider. SSL object is null"); + LOG(INFO) << "error while fetching from CrlProvider. SSL object is null"; return nullptr; } SSL_CTX* ssl_ctx = SSL_get_SSL_CTX(ssl); @@ -1175,8 +1173,8 @@ static tsi_result tsi_set_min_and_max_tls_versions( SSL_CTX* ssl_context, tsi_tls_version min_tls_version, tsi_tls_version max_tls_version) { if (ssl_context == nullptr) { - gpr_log(GPR_INFO, - "Invalid nullptr argument to |tsi_set_min_and_max_tls_versions|."); + LOG(INFO) << "Invalid nullptr argument to " + "|tsi_set_min_and_max_tls_versions|."; return TSI_INVALID_ARGUMENT; } #if OPENSSL_VERSION_NUMBER >= 0x10100000 @@ -2085,8 +2083,7 @@ static int does_entry_match_name(absl::string_view entry, entry.remove_prefix(2); // Remove *. size_t dot = name_subdomain.find('.'); if (dot == absl::string_view::npos || dot == name_subdomain.size() - 1) { - gpr_log(GPR_ERROR, "Invalid toplevel subdomain: %s", - std::string(name_subdomain).c_str()); + LOG(ERROR) << "Invalid toplevel subdomain: " << name_subdomain; return 0; } if (name_subdomain.back() == '.') { @@ -2113,7 +2110,7 @@ static int ssl_server_handshaker_factory_servername_callback(SSL* ssl, return SSL_TLSEXT_ERR_OK; } } - gpr_log(GPR_ERROR, "No match found for server name: %s.", servername); + LOG(ERROR) << "No match found for server name: " << servername; return SSL_TLSEXT_ERR_NOACK; } @@ -2297,8 +2294,8 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options( options->alpn_protocols, options->num_alpn_protocols, &impl->alpn_protocol_list, &impl->alpn_protocol_list_length); if (result != TSI_OK) { - gpr_log(GPR_ERROR, "Building alpn list failed with error %s.", - tsi_result_to_string(result)); + LOG(ERROR) << "Building alpn list failed with error " + << tsi_result_to_string(result); break; } #if TSI_OPENSSL_ALPN_SUPPORT diff --git a/src/core/tsi/ssl_transport_security_utils.cc b/src/core/tsi/ssl_transport_security_utils.cc index 2660e51e0de..1a6747a60a2 100644 --- a/src/core/tsi/ssl_transport_security_utils.cc +++ b/src/core/tsi/ssl_transport_security_utils.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -63,7 +64,7 @@ void LogSslErrorStack(void) { while ((err = ERR_get_error()) != 0) { char details[256]; ERR_error_string_n(static_cast(err), details, sizeof(details)); - gpr_log(GPR_ERROR, "%s", details); + LOG(ERROR) << details; } } @@ -76,12 +77,12 @@ tsi_result DoSslWrite(SSL* ssl, unsigned char* unprotected_bytes, if (ssl_write_result < 0) { ssl_write_result = SSL_get_error(ssl, ssl_write_result); if (ssl_write_result == SSL_ERROR_WANT_READ) { - gpr_log(GPR_ERROR, - "Peer tried to renegotiate SSL connection. This is unsupported."); + LOG(ERROR) + << "Peer tried to renegotiate SSL connection. This is unsupported."; return TSI_UNIMPLEMENTED; } else { - gpr_log(GPR_ERROR, "SSL_write failed with error %s.", - SslErrorString(ssl_write_result)); + LOG(ERROR) << "SSL_write failed with error " + << SslErrorString(ssl_write_result); return TSI_INTERNAL_ERROR; } } @@ -107,12 +108,12 @@ tsi_result DoSslRead(SSL* ssl, unsigned char* unprotected_bytes, "Peer tried to renegotiate SSL connection. This is unsupported."); return TSI_UNIMPLEMENTED; case SSL_ERROR_SSL: - gpr_log(GPR_ERROR, "Corruption detected."); + LOG(ERROR) << "Corruption detected."; LogSslErrorStack(); return TSI_DATA_CORRUPTED; default: - gpr_log(GPR_ERROR, "SSL_read failed with error %s.", - SslErrorString(read_from_ssl)); + LOG(ERROR) << "SSL_read failed with error " + << SslErrorString(read_from_ssl); return TSI_PROTOCOL_FAILURE; } } @@ -139,8 +140,7 @@ tsi_result SslProtectorProtect(const unsigned char* unprotected_bytes, read_from_ssl = BIO_read(network_io, protected_output_frames, static_cast(*protected_output_frames_size)); if (read_from_ssl < 0) { - gpr_log(GPR_ERROR, - "Could not read from BIO even though some data is pending"); + LOG(ERROR) << "Could not read from BIO even though some data is pending"; return TSI_INTERNAL_ERROR; } *protected_output_frames_size = static_cast(read_from_ssl); @@ -166,7 +166,7 @@ tsi_result SslProtectorProtect(const unsigned char* unprotected_bytes, read_from_ssl = BIO_read(network_io, protected_output_frames, static_cast(*protected_output_frames_size)); if (read_from_ssl < 0) { - gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); + LOG(ERROR) << "Could not read from BIO after SSL_write."; return TSI_INTERNAL_ERROR; } *protected_output_frames_size = static_cast(read_from_ssl); @@ -200,7 +200,7 @@ tsi_result SslProtectorProtectFlush(size_t& buffer_offset, read_from_ssl = BIO_read(network_io, protected_output_frames, static_cast(*protected_output_frames_size)); if (read_from_ssl <= 0) { - gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); + LOG(ERROR) << "Could not read from BIO after SSL_write."; return TSI_INTERNAL_ERROR; } *protected_output_frames_size = static_cast(read_from_ssl); @@ -237,8 +237,8 @@ tsi_result SslProtectorUnprotect(const unsigned char* protected_frames_bytes, written_into_ssl = BIO_write(network_io, protected_frames_bytes, static_cast(*protected_frames_bytes_size)); if (written_into_ssl < 0) { - gpr_log(GPR_ERROR, "Sending protected frame to ssl failed with %d", - written_into_ssl); + LOG(ERROR) << "Sending protected frame to ssl failed with " + << written_into_ssl; return TSI_INTERNAL_ERROR; } *protected_frames_bytes_size = static_cast(written_into_ssl); @@ -260,16 +260,15 @@ bool VerifyCrlSignature(X509_CRL* crl, X509* issuer) { if (ikey == nullptr) { // Can't verify signature because we couldn't get the pubkey, fail the // check. - gpr_log(GPR_DEBUG, "Could not public key from certificate."); + VLOG(2) << "Could not public key from certificate."; EVP_PKEY_free(ikey); return false; } int ret = X509_CRL_verify(crl, ikey); if (ret < 0) { - gpr_log(GPR_DEBUG, - "There was an unexpected problem checking the CRL signature."); + VLOG(2) << "There was an unexpected problem checking the CRL signature."; } else if (ret == 0) { - gpr_log(GPR_DEBUG, "CRL failed verification."); + VLOG(2) << "CRL failed verification."; } EVP_PKEY_free(ikey); return ret == 1; diff --git a/src/core/xds/grpc/xds_client_grpc.cc b/src/core/xds/grpc/xds_client_grpc.cc index 7b7fee2ca76..3b00fed06e4 100644 --- a/src/core/xds/grpc/xds_client_grpc.cc +++ b/src/core/xds/grpc/xds_client_grpc.cc @@ -24,6 +24,7 @@ #include #include "absl/base/thread_annotations.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -220,7 +221,7 @@ absl::StatusOr GetBootstrapContents(const char* fallback_config) { // Finally, try fallback config. if (fallback_config != nullptr) { if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) { - gpr_log(GPR_INFO, "Got bootstrap contents from fallback config"); + LOG(INFO) << "Got bootstrap contents from fallback config"; } return fallback_config; } From c95886f65aca16b89dcafe11cd102928e8ef025c Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap Date: Thu, 16 May 2024 02:15:01 -0700 Subject: [PATCH 03/23] [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. PiperOrigin-RevId: 634272059 --- src/core/lib/surface/call.cc | 2 +- src/core/lib/surface/channel_init.cc | 7 ++++--- src/core/lib/surface/completion_queue.cc | 9 +++++---- src/core/lib/surface/init.cc | 9 +++++---- src/core/resolver/binder/binder_resolver.cc | 5 +++-- src/core/resolver/dns/c_ares/dns_resolver_ares.cc | 3 ++- src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc | 3 ++- src/core/resolver/dns/dns_resolver_plugin.cc | 9 +++++---- .../event_engine/event_engine_client_channel_resolver.cc | 3 ++- src/core/resolver/dns/native/dns_resolver.cc | 5 +++-- src/core/resolver/google_c2p/google_c2p_resolver.cc | 3 ++- src/core/server/server.cc | 5 +++-- .../service_config/service_config_channel_arg_filter.cc | 3 ++- 13 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index cd0a1ed7dd0..cd9a15d0bd6 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -325,7 +325,7 @@ void Call::HandleCompressionAlgorithmDisabled( grpc_compression_algorithm_name(compression_algorithm, &algo_name); std::string error_msg = absl::StrFormat("Compression algorithm '%s' is disabled.", algo_name); - gpr_log(GPR_ERROR, "%s", error_msg.c_str()); + LOG(ERROR) << error_msg; CancelWithError(grpc_error_set_int(absl::UnimplementedError(error_msg), StatusIntProperty::kRpcStatus, GRPC_STATUS_UNIMPLEMENTED)); diff --git a/src/core/lib/surface/channel_init.cc b/src/core/lib/surface/channel_init.cc index 698a57b195d..da694aa59be 100644 --- a/src/core/lib/surface/channel_init.cc +++ b/src/core/lib/surface/channel_init.cc @@ -27,6 +27,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" @@ -313,7 +314,7 @@ ChannelInit::StackConfig ChannelInit::BuildStackConfig( const auto filter_str = absl::StrCat(" ", loc_strs[filter.filter], NameFromChannelFilter(filter.filter), after_str); - gpr_log(GPR_INFO, "%s", filter_str.c_str()); + LOG(INFO) << filter_str; } // Finally list out the terminal filters and where they were registered // from. @@ -325,7 +326,7 @@ ChannelInit::StackConfig ChannelInit::BuildStackConfig( strlen(NameFromChannelFilter(terminal.filter)), ' '), "[terminal]"); - gpr_log(GPR_INFO, "%s", filter_str.c_str()); + LOG(INFO) << filter_str; } } // Check if there are no terminal filters: this would be an error. @@ -398,7 +399,7 @@ bool ChannelInit::CreateStack(ChannelStackBuilder* builder) const { "\n"); } } - gpr_log(GPR_ERROR, "%s", error.c_str()); + LOG(ERROR) << error; return false; } for (const auto& post_processor : stack_config.post_processors) { diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 92b52c4216e..b439191f1bb 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -28,6 +28,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" @@ -260,7 +261,7 @@ struct cq_next_data { CHECK_EQ(queue.num_items(), 0); #ifndef NDEBUG if (pending_events.load(std::memory_order_acquire) != 0) { - gpr_log(GPR_ERROR, "Destroying CQ without draining it fully."); + LOG(ERROR) << "Destroying CQ without draining it fully."; } #endif } @@ -290,7 +291,7 @@ struct cq_pluck_data { CHECK(completed_head.next == reinterpret_cast(&completed_head)); #ifndef NDEBUG if (pending_events.load(std::memory_order_acquire) != 0) { - gpr_log(GPR_ERROR, "Destroying CQ without draining it fully."); + LOG(ERROR) << "Destroying CQ without draining it fully."; } #endif } @@ -327,7 +328,7 @@ struct cq_callback_data { ~cq_callback_data() { #ifndef NDEBUG if (pending_events.load(std::memory_order_acquire) != 0) { - gpr_log(GPR_ERROR, "Destroying CQ without draining it fully."); + LOG(ERROR) << "Destroying CQ without draining it fully."; } #endif } @@ -942,7 +943,7 @@ static void dump_pending_tags(grpc_completion_queue* cq) { parts.push_back(absl::StrFormat(" %p", cq->outstanding_tags[i])); } gpr_mu_unlock(cq->mu); - gpr_log(GPR_DEBUG, "%s", absl::StrJoin(parts, "").c_str()); + VLOG(2) << absl::StrJoin(parts, ""); } #else static void dump_pending_tags(grpc_completion_queue* /*cq*/) {} diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index b2a766ac8a0..fc8e75484d2 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -19,6 +19,7 @@ #include "src/core/lib/surface/init.h" #include "absl/base/thread_annotations.h" +#include "absl/log/log.h" #include #include @@ -137,7 +138,7 @@ void grpc_shutdown_from_cleanup_thread(void* /*ignored*/) { return; } grpc_shutdown_internal_locked(); - gpr_log(GPR_DEBUG, "grpc_shutdown from cleanup thread done"); + VLOG(2) << "grpc_shutdown from cleanup thread done"; } void grpc_shutdown(void) { @@ -155,14 +156,14 @@ void grpc_shutdown(void) { 0) && grpc_core::ExecCtx::Get() == nullptr) { // just run clean-up when this is called on non-executor thread. - gpr_log(GPR_DEBUG, "grpc_shutdown starts clean-up now"); + VLOG(2) << "grpc_shutdown starts clean-up now"; g_shutting_down = true; grpc_shutdown_internal_locked(); - gpr_log(GPR_DEBUG, "grpc_shutdown done"); + VLOG(2) << "grpc_shutdown done"; } else { // spawn a detached thread to do the actual clean up in case we are // currently in an executor thread. - gpr_log(GPR_DEBUG, "grpc_shutdown spawns clean-up thread"); + VLOG(2) << "grpc_shutdown spawns clean-up thread"; g_initializations++; g_shutting_down = true; grpc_core::Thread cleanup_thread( diff --git a/src/core/resolver/binder/binder_resolver.cc b/src/core/resolver/binder/binder_resolver.cc index 903a5528470..7cd03f29193 100644 --- a/src/core/resolver/binder/binder_resolver.cc +++ b/src/core/resolver/binder/binder_resolver.cc @@ -37,6 +37,7 @@ #include #include +#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -126,12 +127,12 @@ class BinderResolverFactory final : public ResolverFactory { grpc_resolved_address addr; { if (!uri.authority().empty()) { - gpr_log(GPR_ERROR, "authority is not supported in binder scheme"); + LOG(ERROR) << "authority is not supported in binder scheme"; return false; } grpc_error_handle error = BinderAddrPopulate(uri.path(), &addr); if (!error.ok()) { - gpr_log(GPR_ERROR, "%s", StatusToString(error).c_str()); + LOG(ERROR) << StatusToString(error); return false; } } diff --git a/src/core/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/resolver/dns/c_ares/dns_resolver_ares.cc index 4fa22539ba1..06b9985c948 100644 --- a/src/core/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/resolver/dns/c_ares/dns_resolver_ares.cc @@ -24,6 +24,7 @@ #include #include "absl/base/thread_annotations.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/match.h" @@ -348,7 +349,7 @@ class AresClientChannelDNSResolverFactory final : public ResolverFactory { bool IsValidUri(const URI& uri) const override { if (absl::StripPrefix(uri.path(), "/").empty()) { - gpr_log(GPR_ERROR, "no server name supplied in dns URI"); + LOG(ERROR) << "no server name supplied in dns URI"; return false; } return true; diff --git a/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc b/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc index e1f717cb9d4..7994a1900a5 100644 --- a/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc +++ b/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/string_view.h" #include @@ -952,7 +953,7 @@ static bool resolve_as_ip_literal_locked( static bool target_matches_localhost_inner(const char* name, std::string* host, std::string* port) { if (!grpc_core::SplitHostPort(name, host, port)) { - gpr_log(GPR_ERROR, "Unable to split host and port for name: %s", name); + LOG(ERROR) << "Unable to split host and port for name: " << name; return false; } return gpr_stricmp(host->c_str(), "localhost") == 0; diff --git a/src/core/resolver/dns/dns_resolver_plugin.cc b/src/core/resolver/dns/dns_resolver_plugin.cc index a0f92a6c600..122c3fd740e 100644 --- a/src/core/resolver/dns/dns_resolver_plugin.cc +++ b/src/core/resolver/dns/dns_resolver_plugin.cc @@ -15,6 +15,7 @@ #include +#include "absl/log/log.h" #include "absl/strings/match.h" #include @@ -32,14 +33,14 @@ namespace grpc_core { void RegisterDnsResolver(CoreConfiguration::Builder* builder) { #ifdef GRPC_IOS_EVENT_ENGINE_CLIENT - gpr_log(GPR_DEBUG, "Using EventEngine dns resolver"); + VLOG(2) << "Using EventEngine dns resolver"; builder->resolver_registry()->RegisterResolverFactory( std::make_unique()); return; #endif #ifndef GRPC_DO_NOT_INSTANTIATE_POSIX_POLLER if (IsEventEngineDnsEnabled()) { - gpr_log(GPR_DEBUG, "Using EventEngine dns resolver"); + VLOG(2) << "Using EventEngine dns resolver"; builder->resolver_registry()->RegisterResolverFactory( std::make_unique()); return; @@ -48,14 +49,14 @@ void RegisterDnsResolver(CoreConfiguration::Builder* builder) { auto resolver = ConfigVars::Get().DnsResolver(); // ---- Ares resolver ---- if (ShouldUseAresDnsResolver(resolver)) { - gpr_log(GPR_DEBUG, "Using ares dns resolver"); + VLOG(2) << "Using ares dns resolver"; RegisterAresDnsResolver(builder); return; } // ---- Native resolver ---- if (absl::EqualsIgnoreCase(resolver, "native") || !builder->resolver_registry()->HasResolverFactory("dns")) { - gpr_log(GPR_DEBUG, "Using native dns resolver"); + VLOG(2) << "Using native dns resolver"; RegisterNativeDnsResolver(builder); return; } diff --git a/src/core/resolver/dns/event_engine/event_engine_client_channel_resolver.cc b/src/core/resolver/dns/event_engine/event_engine_client_channel_resolver.cc index 8a9d1a49db9..743422ab603 100644 --- a/src/core/resolver/dns/event_engine/event_engine_client_channel_resolver.cc +++ b/src/core/resolver/dns/event_engine/event_engine_client_channel_resolver.cc @@ -26,6 +26,7 @@ #include "absl/base/thread_annotations.h" #include "absl/cleanup/cleanup.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/match.h" @@ -567,7 +568,7 @@ absl::optional EventEngineClientChannelDNSResolver:: bool EventEngineClientChannelDNSResolverFactory::IsValidUri( const URI& uri) const { if (absl::StripPrefix(uri.path(), "/").empty()) { - gpr_log(GPR_ERROR, "no server name supplied in dns URI"); + LOG(ERROR) << "no server name supplied in dns URI"; return false; } return true; diff --git a/src/core/resolver/dns/native/dns_resolver.cc b/src/core/resolver/dns/native/dns_resolver.cc index 43dddc719a4..8ecb92d4857 100644 --- a/src/core/resolver/dns/native/dns_resolver.cc +++ b/src/core/resolver/dns/native/dns_resolver.cc @@ -20,6 +20,7 @@ #include #include "absl/functional/bind_front.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" @@ -150,11 +151,11 @@ class NativeClientChannelDNSResolverFactory final : public ResolverFactory { bool IsValidUri(const URI& uri) const override { if (GPR_UNLIKELY(!uri.authority().empty())) { - gpr_log(GPR_ERROR, "authority based dns uri's not supported"); + LOG(ERROR) << "authority based dns uri's not supported"; return false; } if (absl::StripPrefix(uri.path(), "/").empty()) { - gpr_log(GPR_ERROR, "no server name supplied in dns URI"); + LOG(ERROR) << "no server name supplied in dns URI"; return false; } return true; diff --git a/src/core/resolver/google_c2p/google_c2p_resolver.cc b/src/core/resolver/google_c2p/google_c2p_resolver.cc index 0fb3744a3e8..d58e9a81b3e 100644 --- a/src/core/resolver/google_c2p/google_c2p_resolver.cc +++ b/src/core/resolver/google_c2p/google_c2p_resolver.cc @@ -22,6 +22,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -282,7 +283,7 @@ class GoogleCloud2ProdResolverFactory final : public ResolverFactory { bool IsValidUri(const URI& uri) const override { if (GPR_UNLIKELY(!uri.authority().empty())) { - gpr_log(GPR_ERROR, "google-c2p URI scheme does not support authorities"); + LOG(ERROR) << "google-c2p URI scheme does not support authorities"; return false; } return true; diff --git a/src/core/server/server.cc b/src/core/server/server.cc index e66c3c5d232..b891001f3d4 100644 --- a/src/core/server/server.cc +++ b/src/core/server/server.cc @@ -33,6 +33,7 @@ #include "absl/cleanup/cleanup.h" #include "absl/container/flat_hash_map.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/types/optional.h" @@ -980,7 +981,7 @@ grpc_error_handle Server::SetupTransport( } t->StartConnectivityWatch(MakeOrphanable( t->RefAsSubclass(), Ref())); - gpr_log(GPR_INFO, "Adding connection"); + LOG(INFO) << "Adding connection"; connections_.emplace(std::move(t)); ++connections_open_; } else { @@ -1494,7 +1495,7 @@ void Server::ChannelData::Destroy() { GRPC_CLOSURE_INIT(&finish_destroy_channel_closure_, FinishDestroy, this, grpc_schedule_on_exec_ctx); if (GRPC_TRACE_FLAG_ENABLED(grpc_server_channel_trace)) { - gpr_log(GPR_INFO, "Disconnected client"); + LOG(INFO) << "Disconnected client"; } grpc_transport_op* op = grpc_make_transport_op(&finish_destroy_channel_closure_); diff --git a/src/core/service_config/service_config_channel_arg_filter.cc b/src/core/service_config/service_config_channel_arg_filter.cc index c73e9dd450e..9afa99018fc 100644 --- a/src/core/service_config/service_config_channel_arg_filter.cc +++ b/src/core/service_config/service_config_channel_arg_filter.cc @@ -22,6 +22,7 @@ #include #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/types/optional.h" @@ -69,7 +70,7 @@ class ServiceConfigChannelArgFilter final auto service_config = ServiceConfigImpl::Create(args, *service_config_str); if (!service_config.ok()) { - gpr_log(GPR_ERROR, "%s", service_config.status().ToString().c_str()); + LOG(ERROR) << service_config.status().ToString(); } else { service_config_ = std::move(*service_config); } From 44e4bdc6168ce88abefdace2f17468d9b3116296 Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap Date: Thu, 16 May 2024 02:38:38 -0700 Subject: [PATCH 04/23] [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. PiperOrigin-RevId: 634277899 --- src/core/channelz/channelz_registry.cc | 3 ++- src/core/client_channel/dynamic_filters.cc | 3 ++- src/core/client_channel/subchannel.cc | 3 ++- .../ext/filters/logging/logging_filter.cc | 3 ++- src/core/ext/gcp/metadata_query.cc | 3 ++- .../transport/binder/client/channel_create.cc | 1 + .../http_connect/http_proxy_mapper.cc | 3 ++- src/core/lib/address_utils/parse_address.cc | 11 +++++---- src/core/lib/channel/channel_stack.cc | 3 ++- src/core/lib/compression/message_compress.cc | 9 ++++---- src/core/lib/debug/trace.cc | 5 ++-- src/core/lib/gprpp/posix/thd.cc | 3 ++- src/core/lib/gprpp/windows/thd.cc | 5 ++-- src/core/lib/gprpp/work_serializer.cc | 11 +++++---- .../lib/http/httpcli_security_connector.cc | 3 ++- src/core/lib/promise/map_pipe.h | 5 ++-- src/core/lib/promise/pipe.h | 23 ++++++++++--------- 17 files changed, 57 insertions(+), 40 deletions(-) diff --git a/src/core/channelz/channelz_registry.cc b/src/core/channelz/channelz_registry.cc index 5efbc60e8db..0ba7a2ac438 100644 --- a/src/core/channelz/channelz_registry.cc +++ b/src/core/channelz/channelz_registry.cc @@ -25,6 +25,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -171,7 +172,7 @@ void ChannelzRegistry::InternalLogAllEntities() { } for (size_t i = 0; i < nodes.size(); ++i) { std::string json = nodes[i]->RenderJsonString(); - gpr_log(GPR_INFO, "%s", json.c_str()); + LOG(INFO) << json; } } diff --git a/src/core/client_channel/dynamic_filters.cc b/src/core/client_channel/dynamic_filters.cc index a9c0f2cd4ff..c589f860807 100644 --- a/src/core/client_channel/dynamic_filters.cc +++ b/src/core/client_channel/dynamic_filters.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include @@ -68,7 +69,7 @@ DynamicFilters::Call::Call(Args args, grpc_error_handle* error) *error = grpc_call_stack_init(channel_stack_->channel_stack_.get(), 1, Destroy, this, &call_args); if (GPR_UNLIKELY(!error->ok())) { - gpr_log(GPR_ERROR, "error: %s", StatusToString(*error).c_str()); + LOG(ERROR) << "error: " << StatusToString(*error); return; } grpc_call_stack_set_pollset_or_pollset_set(call_stack, args.pollent); diff --git a/src/core/client_channel/subchannel.cc b/src/core/client_channel/subchannel.cc index f61ad752a9e..d0f9edefeab 100644 --- a/src/core/client_channel/subchannel.cc +++ b/src/core/client_channel/subchannel.cc @@ -27,6 +27,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/strings/cord.h" #include "absl/strings/str_cat.h" @@ -196,7 +197,7 @@ SubchannelCall::SubchannelCall(Args args, grpc_error_handle* error) *error = grpc_call_stack_init(connected_subchannel_->channel_stack(), 1, SubchannelCall::Destroy, this, &call_args); if (GPR_UNLIKELY(!error->ok())) { - gpr_log(GPR_ERROR, "error: %s", StatusToString(*error).c_str()); + LOG(ERROR) << "error: " << StatusToString(*error); return; } grpc_call_stack_set_pollset_or_pollset_set(callstk, args.pollent); diff --git a/src/core/ext/filters/logging/logging_filter.cc b/src/core/ext/filters/logging/logging_filter.cc index 0aca4fe7568..a89cca9c657 100644 --- a/src/core/ext/filters/logging/logging_filter.cc +++ b/src/core/ext/filters/logging/logging_filter.cc @@ -31,6 +31,7 @@ #include #include +#include "absl/log/log.h" #include "absl/numeric/int128.h" #include "absl/random/random.h" #include "absl/random/uniform_int_distribution.h" @@ -160,7 +161,7 @@ LoggingSink::Entry::Address PeerStringToAddress(const Slice& peer_string) { LoggingSink::Entry::Address address; absl::StatusOr uri = URI::Parse(peer_string.as_string_view()); if (!uri.ok()) { - gpr_log(GPR_DEBUG, "peer_string is in invalid format and cannot be logged"); + VLOG(2) << "peer_string is in invalid format and cannot be logged"; return address; } diff --git a/src/core/ext/gcp/metadata_query.cc b/src/core/ext/gcp/metadata_query.cc index 24422cb780f..dd2e0603641 100644 --- a/src/core/ext/gcp/metadata_query.cc +++ b/src/core/ext/gcp/metadata_query.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" @@ -120,7 +121,7 @@ void MetadataQuery::OnDone(void* arg, grpc_error_handle error) { absl::StrFormat("MetadataServer Could not parse zone: %s", std::string(body).c_str())); if (GRPC_TRACE_FLAG_ENABLED(grpc_metadata_query_trace)) { - gpr_log(GPR_INFO, "%s", result.status().ToString().c_str()); + LOG(INFO) << result.status().ToString(); } } else { result = std::string(body.substr(pos + 1)); diff --git a/src/core/ext/transport/binder/client/channel_create.cc b/src/core/ext/transport/binder/client/channel_create.cc index e590b9db51c..4c3f69eaf0f 100644 --- a/src/core/ext/transport/binder/client/channel_create.cc +++ b/src/core/ext/transport/binder/client/channel_create.cc @@ -35,6 +35,7 @@ #ifdef GPR_SUPPORT_BINDER_TRANSPORT #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/strings/substitute.h" #include "absl/time/clock.h" diff --git a/src/core/handshaker/http_connect/http_proxy_mapper.cc b/src/core/handshaker/http_connect/http_proxy_mapper.cc index 677c9ffa9a4..c989d281360 100644 --- a/src/core/handshaker/http_connect/http_proxy_mapper.cc +++ b/src/core/handshaker/http_connect/http_proxy_mapper.cc @@ -26,6 +26,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/ascii.h" @@ -150,7 +151,7 @@ absl::optional GetHttpProxyServer( // User cred found *user_cred = authority_strs[0]; proxy_name = authority_strs[1]; - gpr_log(GPR_DEBUG, "userinfo found in proxy URI"); + VLOG(2) << "userinfo found in proxy URI"; } else { // Bad authority proxy_name = absl::nullopt; diff --git a/src/core/lib/address_utils/parse_address.cc b/src/core/lib/address_utils/parse_address.cc index 0bdd541adfa..1b677f5f6cb 100644 --- a/src/core/lib/address_utils/parse_address.cc +++ b/src/core/lib/address_utils/parse_address.cc @@ -19,6 +19,7 @@ #include "src/core/lib/address_utils/parse_address.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include @@ -70,7 +71,7 @@ bool grpc_parse_unix(const grpc_core::URI& uri, grpc_error_handle error = grpc_core::UnixSockaddrPopulate(uri.path(), resolved_addr); if (!error.ok()) { - gpr_log(GPR_ERROR, "%s", grpc_core::StatusToString(error).c_str()); + LOG(ERROR) << "" << grpc_core::StatusToString(error); return false; } return true; @@ -86,7 +87,7 @@ bool grpc_parse_unix_abstract(const grpc_core::URI& uri, grpc_error_handle error = grpc_core::UnixAbstractSockaddrPopulate(uri.path(), resolved_addr); if (!error.ok()) { - gpr_log(GPR_ERROR, "%s", grpc_core::StatusToString(error).c_str()); + LOG(ERROR) << "" << grpc_core::StatusToString(error); return false; } return true; @@ -170,7 +171,7 @@ bool grpc_parse_vsock(const grpc_core::URI& uri, grpc_error_handle error = grpc_core::VSockaddrPopulate(uri.path(), resolved_addr); if (!error.ok()) { - gpr_log(GPR_ERROR, "%s", grpc_core::StatusToString(error).c_str()); + LOG(ERROR) << "" << grpc_core::StatusToString(error); return false; } return true; @@ -238,7 +239,7 @@ bool grpc_parse_ipv4_hostport(absl::string_view hostport, } // Parse port. if (port.empty()) { - if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv4 scheme"); + if (log_errors) LOG(ERROR) << "no port given for ipv4 scheme"; goto done; } int port_num; @@ -333,7 +334,7 @@ bool grpc_parse_ipv6_hostport(absl::string_view hostport, } // Parse port. if (port.empty()) { - if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv6 scheme"); + if (log_errors) LOG(ERROR) << "no port given for ipv6 scheme"; goto done; } int port_num; diff --git a/src/core/lib/channel/channel_stack.cc b/src/core/lib/channel/channel_stack.cc index 0a4dd15607a..59c80a2d42d 100644 --- a/src/core/lib/channel/channel_stack.cc +++ b/src/core/lib/channel/channel_stack.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -121,7 +122,7 @@ grpc_error_handle grpc_channel_stack_init( const grpc_core::ChannelArgs& channel_args, const char* name, grpc_channel_stack* stack) { if (grpc_trace_channel_stack.enabled()) { - gpr_log(GPR_INFO, "CHANNEL_STACK: init %s", name); + LOG(INFO) << "CHANNEL_STACK: init " << name; for (size_t i = 0; i < filter_count; i++) { gpr_log(GPR_INFO, "CHANNEL_STACK: filter %s%s", filters[i]->name, filters[i]->make_call_promise ? " [promise-capable]" : ""); diff --git a/src/core/lib/compression/message_compress.cc b/src/core/lib/compression/message_compress.cc index 131f89eb64f..bb806509286 100644 --- a/src/core/lib/compression/message_compress.cc +++ b/src/core/lib/compression/message_compress.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -67,12 +68,12 @@ static int zlib_body(z_stream* zs, grpc_slice_buffer* input, } } while (zs->avail_out == 0); if (zs->avail_in) { - gpr_log(GPR_INFO, "zlib: not all input consumed"); + LOG(INFO) << "zlib: not all input consumed"; goto error; } } if (r != Z_STREAM_END) { - gpr_log(GPR_INFO, "zlib: Data error"); + LOG(INFO) << "zlib: Data error"; goto error; } @@ -165,7 +166,7 @@ static int compress_inner(grpc_compression_algorithm algorithm, case GRPC_COMPRESS_ALGORITHMS_COUNT: break; } - gpr_log(GPR_ERROR, "invalid compression algorithm %d", algorithm); + LOG(ERROR) << "invalid compression algorithm " << algorithm; return 0; } @@ -190,6 +191,6 @@ int grpc_msg_decompress(grpc_compression_algorithm algorithm, case GRPC_COMPRESS_ALGORITHMS_COUNT: break; } - gpr_log(GPR_ERROR, "invalid compression algorithm %d", algorithm); + LOG(ERROR) << "invalid compression algorithm " << algorithm; return 0; } diff --git a/src/core/lib/debug/trace.cc b/src/core/lib/debug/trace.cc index 5b7e189bf9c..8500def37f7 100644 --- a/src/core/lib/debug/trace.cc +++ b/src/core/lib/debug/trace.cc @@ -22,6 +22,7 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/match.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" @@ -75,9 +76,9 @@ void TraceFlagList::Add(TraceFlag* flag) { } void TraceFlagList::LogAllTracers() { - gpr_log(GPR_DEBUG, "available tracers:"); + VLOG(2) << "available tracers:"; for (TraceFlag* t = root_tracer_; t != nullptr; t = t->next_tracer_) { - gpr_log(GPR_DEBUG, "\t%s", t->name_); + VLOG(2) << "\t" << t->name_; } } diff --git a/src/core/lib/gprpp/posix/thd.cc b/src/core/lib/gprpp/posix/thd.cc index 149101103f9..dd3124fad25 100644 --- a/src/core/lib/gprpp/posix/thd.cc +++ b/src/core/lib/gprpp/posix/thd.cc @@ -33,6 +33,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" // IWYU pragma: keep #include #include @@ -213,7 +214,7 @@ void Thread::Kill(gpr_thd_id tid) { } #else // GPR_ANDROID void Thread::Kill(gpr_thd_id /* tid */) { - gpr_log(GPR_DEBUG, "Thread::Kill is not supported on Android."); + VLOG(2) << "Thread::Kill is not supported on Android."; } #endif diff --git a/src/core/lib/gprpp/windows/thd.cc b/src/core/lib/gprpp/windows/thd.cc index 20a060f2b33..b5c6368cf40 100644 --- a/src/core/lib/gprpp/windows/thd.cc +++ b/src/core/lib/gprpp/windows/thd.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -149,12 +150,12 @@ namespace grpc_core { void Thread::Signal(gpr_thd_id /* tid */, int /* sig */) { // TODO(hork): Implement - gpr_log(GPR_DEBUG, "Thread signals are not supported on Windows."); + VLOG(2) << "Thread signals are not supported on Windows."; } void Thread::Kill(gpr_thd_id /* tid */) { // TODO(hork): Implement - gpr_log(GPR_DEBUG, "Thread::Kill is not supported on Windows."); + VLOG(2) << "Thread::Kill is not supported on Windows."; } Thread::Thread(const char* /* thd_name */, void (*thd_body)(void* arg), diff --git a/src/core/lib/gprpp/work_serializer.cc b/src/core/lib/gprpp/work_serializer.cc index 605877fddcd..88c10c00a8a 100644 --- a/src/core/lib/gprpp/work_serializer.cc +++ b/src/core/lib/gprpp/work_serializer.cc @@ -28,6 +28,7 @@ #include "absl/container/inlined_vector.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -151,7 +152,7 @@ void WorkSerializer::LegacyWorkSerializer::Run(std::function callback, // We took ownership of the WorkSerializer. Invoke callback and drain queue. SetCurrentThread(); if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) { - gpr_log(GPR_INFO, " Executing immediately"); + LOG(INFO) << " Executing immediately"; } callback(); // Delete the callback while still holding the WorkSerializer, so @@ -193,7 +194,7 @@ void WorkSerializer::LegacyWorkSerializer::Orphan() { refs_.fetch_sub(MakeRefPair(0, 1), std::memory_order_acq_rel); if (GetOwners(prev_ref_pair) == 0 && GetSize(prev_ref_pair) == 1) { if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) { - gpr_log(GPR_INFO, " Destroying"); + LOG(INFO) << " Destroying"; } delete this; } @@ -232,7 +233,7 @@ void WorkSerializer::LegacyWorkSerializer::DrainQueueOwned() { // up orphaning the work serializer. In that case, delete the object. if (GetSize(prev_ref_pair) == 1) { if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) { - gpr_log(GPR_INFO, " Queue Drained. Destroying"); + LOG(INFO) << " Queue Drained. Destroying"; } delete this; return; @@ -252,7 +253,7 @@ void WorkSerializer::LegacyWorkSerializer::DrainQueueOwned() { if (GetSize(expected) == 0) { // WorkSerializer got orphaned while this was running if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) { - gpr_log(GPR_INFO, " Queue Drained. Destroying"); + LOG(INFO) << " Queue Drained. Destroying"; } delete this; return; @@ -272,7 +273,7 @@ void WorkSerializer::LegacyWorkSerializer::DrainQueueOwned() { // This can happen due to a race condition within the mpscq // implementation or because of a race with Run()/Schedule(). if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) { - gpr_log(GPR_INFO, " Queue returned nullptr, trying again"); + LOG(INFO) << " Queue returned nullptr, trying again"; } } if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) { diff --git a/src/core/lib/http/httpcli_security_connector.cc b/src/core/lib/http/httpcli_security_connector.cc index 36b8cd84857..7db2021b71c 100644 --- a/src/core/lib/http/httpcli_security_connector.cc +++ b/src/core/lib/http/httpcli_security_connector.cc @@ -20,6 +20,7 @@ #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -173,7 +174,7 @@ class HttpRequestSSLCredentials : public grpc_channel_credentials { const tsi_ssl_root_certs_store* root_store = DefaultSslRootStore::GetRootStore(); if (root_store == nullptr) { - gpr_log(GPR_ERROR, "Could not get default pem root certs."); + LOG(ERROR) << "Could not get default pem root certs."; return nullptr; } absl::optional target_string = diff --git a/src/core/lib/promise/map_pipe.h b/src/core/lib/promise/map_pipe.h index 8dd4223dce3..fef1f18994f 100644 --- a/src/core/lib/promise/map_pipe.h +++ b/src/core/lib/promise/map_pipe.h @@ -15,6 +15,7 @@ #ifndef GRPC_SRC_CORE_LIB_PROMISE_MAP_PIPE_H #define GRPC_SRC_CORE_LIB_PROMISE_MAP_PIPE_H +#include "absl/log/log.h" #include "absl/status/status.h" #include @@ -46,14 +47,14 @@ auto MapPipe(PipeReceiver src, PipeSender dst, Filter filter_factory) { return TrySeq( [] { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_DEBUG, "MapPipe: start map"); + VLOG(2) << "MapPipe: start map"; } return Empty{}; }, filter_factory.Make(std::move(t)), [&dst](T t) { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_DEBUG, "MapPipe: start push"); + VLOG(2) << "MapPipe: start push"; } return Map(dst.Push(std::move(t)), [](bool successful_push) { if (successful_push) { diff --git a/src/core/lib/promise/pipe.h b/src/core/lib/promise/pipe.h index c77919f697c..570f59e77a1 100644 --- a/src/core/lib/promise/pipe.h +++ b/src/core/lib/promise/pipe.h @@ -23,6 +23,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/types/optional.h" #include "absl/types/variant.h" @@ -119,7 +120,7 @@ class Center : public InterceptorList { // Add one ref to this object, and return this. void IncrementRefCount() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_DEBUG, "%s", DebugOpString("IncrementRefCount").c_str()); + VLOG(2) << DebugOpString("IncrementRefCount"); } refs_++; DCHECK_NE(refs_, 0); @@ -134,7 +135,7 @@ class Center : public InterceptorList { // If no refs remain, destroy this object void Unref() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_DEBUG, "%s", DebugOpString("Unref").c_str()); + VLOG(2) << DebugOpString("Unref"); } DCHECK_GT(refs_, 0); refs_--; @@ -149,7 +150,7 @@ class Center : public InterceptorList { // Return false if the recv end is closed. Poll Push(T* value) { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("Push").c_str()); + LOG(INFO) << DebugOpString("Push"); } DCHECK_NE(refs_, 0); switch (value_state_) { @@ -173,7 +174,7 @@ class Center : public InterceptorList { Poll PollAck() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("PollAck").c_str()); + LOG(INFO) << DebugOpString("PollAck"); } DCHECK_NE(refs_, 0); switch (value_state_) { @@ -201,7 +202,7 @@ class Center : public InterceptorList { // Return nullopt if the send end is closed and no value had been pushed. Poll> Next() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("Next").c_str()); + LOG(INFO) << DebugOpString("Next"); } DCHECK_NE(refs_, 0); switch (value_state_) { @@ -227,7 +228,7 @@ class Center : public InterceptorList { // but the pipe is closed, reports closed). Poll PollClosedForSender() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("PollClosedForSender").c_str()); + LOG(INFO) << DebugOpString("PollClosedForSender"); } DCHECK_NE(refs_, 0); switch (value_state_) { @@ -250,7 +251,7 @@ class Center : public InterceptorList { // but the pipe is closed, reports open). Poll PollClosedForReceiver() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("PollClosedForReceiver").c_str()); + LOG(INFO) << DebugOpString("PollClosedForReceiver"); } DCHECK_NE(refs_, 0); switch (value_state_) { @@ -271,7 +272,7 @@ class Center : public InterceptorList { Poll PollEmpty() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("PollEmpty").c_str()); + LOG(INFO) << DebugOpString("PollEmpty"); } DCHECK_NE(refs_, 0); switch (value_state_) { @@ -291,7 +292,7 @@ class Center : public InterceptorList { void AckNext() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("AckNext").c_str()); + LOG(INFO) << DebugOpString("AckNext"); } switch (value_state_) { case ValueState::kReady: @@ -318,7 +319,7 @@ class Center : public InterceptorList { void MarkClosed() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("MarkClosed").c_str()); + LOG(INFO) << DebugOpString("MarkClosed"); } switch (value_state_) { case ValueState::kEmpty: @@ -347,7 +348,7 @@ class Center : public InterceptorList { void MarkCancelled() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("MarkCancelled").c_str()); + LOG(INFO) << DebugOpString("MarkCancelled"); } switch (value_state_) { case ValueState::kEmpty: From bb201db996dc01209013ee18dd561894983adedd Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap Date: Thu, 16 May 2024 02:41:55 -0700 Subject: [PATCH 05/23] [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. PiperOrigin-RevId: 634278682 --- src/core/lib/event_engine/ares_resolver.cc | 5 +++-- .../lib/event_engine/posix_engine/ev_epoll1_linux.cc | 9 +++++---- src/core/lib/event_engine/posix_engine/posix_endpoint.cc | 7 ++++--- src/core/lib/event_engine/posix_engine/posix_endpoint.h | 3 ++- src/core/lib/event_engine/posix_engine/posix_engine.cc | 3 ++- .../posix_engine/posix_engine_listener_utils.cc | 5 +++-- .../lib/event_engine/posix_engine/tcp_socket_utils.cc | 5 +++-- .../lib/event_engine/posix_engine/traced_buffer_list.cc | 3 ++- .../thread_pool/work_stealing_thread_pool.cc | 5 +++-- 9 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/core/lib/event_engine/ares_resolver.cc b/src/core/lib/event_engine/ares_resolver.cc index 4273616642c..58df73794b9 100644 --- a/src/core/lib/event_engine/ares_resolver.cc +++ b/src/core/lib/event_engine/ares_resolver.cc @@ -53,6 +53,7 @@ #include "absl/functional/any_invocable.h" #include "absl/hash/hash.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/match.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" @@ -200,7 +201,7 @@ AresResolver::CreateAresResolver( ares_channel channel; int status = ares_init_options(&channel, &opts, ARES_OPT_FLAGS); if (status != ARES_SUCCESS) { - gpr_log(GPR_ERROR, "ares_init_options failed, status: %d", status); + LOG(ERROR) << "ares_init_options failed, status: " << status; return AresStatusToAbslStatus( status, absl::StrCat("Failed to init c-ares channel: ", ares_strerror(status))); @@ -769,7 +770,7 @@ void AresResolver::OnTXTDoneLocked(void* arg, int status, int /*timeouts*/, result.size()); if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_ares_resolver)) { for (const auto& record : result) { - gpr_log(GPR_INFO, "%s", record.c_str()); + LOG(INFO) << record; } } // Clean up. diff --git a/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc b/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc index a1fffc0a7f9..bf9c82367fb 100644 --- a/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +++ b/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc @@ -19,6 +19,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" @@ -164,14 +165,14 @@ int EpollCreateAndCloexec() { #ifdef GRPC_LINUX_EPOLL_CREATE1 int fd = epoll_create1(EPOLL_CLOEXEC); if (fd < 0) { - gpr_log(GPR_ERROR, "epoll_create1 unavailable"); + LOG(ERROR) << "epoll_create1 unavailable"; } #else int fd = epoll_create(MAX_EPOLL_EVENTS); if (fd < 0) { - gpr_log(GPR_ERROR, "epoll_create unavailable"); + LOG(ERROR) << "epoll_create unavailable"; } else if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { - gpr_log(GPR_ERROR, "fcntl following epoll_create failed"); + LOG(ERROR) << "fcntl following epoll_create failed"; return -1; } #endif @@ -356,7 +357,7 @@ Epoll1Poller::Epoll1Poller(Scheduler* scheduler) wakeup_fd_ = *CreateWakeupFd(); CHECK(wakeup_fd_ != nullptr); CHECK_GE(g_epoll_set_.epfd, 0); - gpr_log(GPR_INFO, "grpc epoll fd: %d", g_epoll_set_.epfd); + LOG(INFO) << "grpc epoll fd: " << g_epoll_set_.epfd; struct epoll_event ev; ev.events = static_cast(EPOLLIN | EPOLLET); ev.data.ptr = wakeup_fd_.get(); diff --git a/src/core/lib/event_engine/posix_engine/posix_endpoint.cc b/src/core/lib/event_engine/posix_engine/posix_endpoint.cc index 7c8dd72052a..18d7dfb4623 100644 --- a/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +++ b/src/core/lib/event_engine/posix_engine/posix_endpoint.cc @@ -27,6 +27,7 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" @@ -718,7 +719,7 @@ bool PosixEndpointImpl::ProcessErrors() { return processed_err; } if (GPR_UNLIKELY((msg.msg_flags & MSG_CTRUNC) != 0)) { - gpr_log(GPR_ERROR, "Error message was truncated."); + LOG(ERROR) << "Error message was truncated."; } if (msg.msg_controllen == 0) { @@ -813,7 +814,7 @@ struct cmsghdr* PosixEndpointImpl::ProcessTimestamp(msghdr* msg, auto serr = reinterpret_cast(CMSG_DATA(next_cmsg)); if (serr->ee_errno != ENOMSG || serr->ee_origin != SO_EE_ORIGIN_TIMESTAMPING) { - gpr_log(GPR_ERROR, "Unexpected control message"); + LOG(ERROR) << "Unexpected control message"; return cmsg; } traced_buffers_.ProcessTimestamp(serr, opt_stats, tss); @@ -1303,7 +1304,7 @@ PosixEndpointImpl::PosixEndpointImpl(EventHandle* handle, if (setsockopt(fd_, SOL_SOCKET, SO_ZEROCOPY, &enable, sizeof(enable)) != 0) { zerocopy_enabled = false; - gpr_log(GPR_ERROR, "Failed to set zerocopy options on the socket."); + LOG(ERROR) << "Failed to set zerocopy options on the socket."; } } diff --git a/src/core/lib/event_engine/posix_engine/posix_endpoint.h b/src/core/lib/event_engine/posix_engine/posix_endpoint.h index c85c81e1eb1..9a0ca6b8db4 100644 --- a/src/core/lib/event_engine/posix_engine/posix_endpoint.h +++ b/src/core/lib/event_engine/posix_engine/posix_endpoint.h @@ -30,6 +30,7 @@ #include "absl/functional/any_invocable.h" #include "absl/hash/hash.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -183,7 +184,7 @@ class TcpZerocopySendCtx { if (send_records_ == nullptr || free_send_records_ == nullptr) { gpr_free(send_records_); gpr_free(free_send_records_); - gpr_log(GPR_INFO, "Disabling TCP TX zerocopy due to memory pressure.\n"); + LOG(INFO) << "Disabling TCP TX zerocopy due to memory pressure.\n"; memory_limited_ = true; enabled_ = false; } else { diff --git a/src/core/lib/event_engine/posix_engine/posix_engine.cc b/src/core/lib/event_engine/posix_engine/posix_engine.cc index 189866faa73..f5c1bf6c3d2 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine.cc +++ b/src/core/lib/event_engine/posix_engine/posix_engine.cc @@ -26,6 +26,7 @@ #include "absl/cleanup/cleanup.h" #include "absl/functional/any_invocable.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -231,7 +232,7 @@ void AsyncConnect::OnWritable(absl::Status status) // your program or another program on the same computer // opened too many network connections. The "easy" fix: // don't do that! - gpr_log(GPR_ERROR, "kernel out of buffers"); + LOG(ERROR) << "kernel out of buffers"; mu_.Unlock(); fd->NotifyOnWrite(on_writable_); // Don't run the cleanup function for this case. diff --git a/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc b/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc index cbd8902d325..ebcbec1771b 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc +++ b/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc @@ -23,6 +23,7 @@ #include "absl/cleanup/cleanup.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_replace.h" @@ -156,7 +157,7 @@ absl::Status PrepareSocket(const PosixTcpOptions& options, #ifdef GRPC_LINUX_ERRQUEUE if (!socket.sock.SetSocketZeroCopy().ok()) { // it's not fatal, so just log it. - gpr_log(GPR_DEBUG, "Node does not support SO_ZEROCOPY, continuing."); + VLOG(2) << "Node does not support SO_ZEROCOPY, continuing."; } else { socket.zero_copy_enabled = true; } @@ -244,7 +245,7 @@ absl::StatusOr ListenerContainerAddAllLocalAddresses( auto result = GetUnusedPort(); GRPC_RETURN_IF_ERROR(result.status()); requested_port = *result; - gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port); + VLOG(2) << "Picked unused port " << requested_port; } if (getifaddrs(&ifa) != 0 || ifa == nullptr) { return absl::FailedPreconditionError( diff --git a/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc b/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc index d2cf5f6f426..987a010084c 100644 --- a/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +++ b/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc @@ -18,6 +18,7 @@ #include #include "absl/cleanup/cleanup.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/types/optional.h" @@ -653,7 +654,7 @@ void PosixSocketWrapper::TrySetSocketTcpUserTimeout( } if (newval != timeout) { // Do not fail on failing to set TCP_USER_TIMEOUT - gpr_log(GPR_ERROR, "Failed to set TCP_USER_TIMEOUT"); + LOG(ERROR) << "Failed to set TCP_USER_TIMEOUT"; return; } } @@ -684,7 +685,7 @@ bool PosixSocketWrapper::IsIpv6LoopbackAvailable() { int fd = socket(AF_INET6, SOCK_STREAM, 0); bool loopback_available = false; if (fd < 0) { - gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed."); + LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed."; } else { sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); diff --git a/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc b/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc index 314e451c664..1171cb76624 100644 --- a/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc +++ b/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc @@ -22,6 +22,7 @@ #include #include "absl/functional/any_invocable.h" +#include "absl/log/log.h" #include #include @@ -48,7 +49,7 @@ void FillGprFromTimestamp(gpr_timespec* gts, const struct timespec* ts) { void DefaultTimestampsCallback(void* /*arg*/, Timestamps* /*ts*/, absl::Status /*shudown_err*/) { - gpr_log(GPR_DEBUG, "Timestamps callback has not been registered"); + VLOG(2) << "Timestamps callback has not been registered"; } // The saved callback function that will be invoked when we get all the diff --git a/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc b/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc index eeaed8abb3c..f22f9484d32 100644 --- a/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc +++ b/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc @@ -27,6 +27,7 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/time/clock.h" #include "absl/time/time.h" #include "absl/types/optional.h" @@ -267,7 +268,7 @@ void WorkStealingThreadPool::WorkStealingThreadPoolImpl::StartThread() { } void WorkStealingThreadPool::WorkStealingThreadPoolImpl::Quiesce() { - gpr_log(GPR_INFO, "WorkStealingThreadPoolImpl::Quiesce"); + LOG(INFO) << "WorkStealingThreadPoolImpl::Quiesce"; SetShutdown(true); // Wait until all threads have exited. // Note that if this is a threadpool thread then we won't exit this thread @@ -319,7 +320,7 @@ bool WorkStealingThreadPool::WorkStealingThreadPoolImpl::IsQuiesced() { } void WorkStealingThreadPool::WorkStealingThreadPoolImpl::PrepareFork() { - gpr_log(GPR_INFO, "WorkStealingThreadPoolImpl::PrepareFork"); + LOG(INFO) << "WorkStealingThreadPoolImpl::PrepareFork"; SetForking(true); work_signal_.SignalAll(); auto threads_were_shut_down = living_thread_count_.BlockUntilThreadCount( From 68134ba53d4b2813820cd66d3f6a9bdc272779a7 Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap Date: Thu, 16 May 2024 03:10:00 -0700 Subject: [PATCH 06/23] [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. PiperOrigin-RevId: 634286257 --- src/cpp/ext/csm/csm_observability.cc | 4 ++-- src/cpp/server/server_context.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cpp/ext/csm/csm_observability.cc b/src/cpp/ext/csm/csm_observability.cc index 751a3f52418..c924db3fbdc 100644 --- a/src/cpp/ext/csm/csm_observability.cc +++ b/src/cpp/ext/csm/csm_observability.cc @@ -23,6 +23,7 @@ #include #include "absl/functional/any_invocable.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/types/optional.h" #include "google/cloud/opentelemetry/resource_detector.h" @@ -30,7 +31,6 @@ #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/resource/resource_detector.h" -#include #include #include @@ -56,7 +56,7 @@ bool CsmChannelTargetSelector(absl::string_view target) { if (!g_csm_plugin_enabled) return false; auto uri = grpc_core::URI::Parse(target); if (!uri.ok()) { - gpr_log(GPR_ERROR, "Failed to parse URI: %s", std::string(target).c_str()); + LOG(ERROR) << "Failed to parse URI: " << target; return false; } // CSM channels should have an "xds" scheme diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index a5eae9ac62f..69d2f55237f 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -29,6 +29,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" @@ -38,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -347,7 +347,7 @@ void ServerContextBase::TryCancel() const { grpc_call_cancel_with_status(call_.call, GRPC_STATUS_CANCELLED, "Cancelled on the server side", nullptr); if (err != GRPC_CALL_OK) { - gpr_log(GPR_ERROR, "TryCancel failed with: %d", err); + LOG(ERROR) << "TryCancel failed with: " << err; } } From c890a35f0c5639f16ce9cc0920715e1f77dc0a4a Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap Date: Thu, 16 May 2024 04:35:50 -0700 Subject: [PATCH 07/23] [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. PiperOrigin-RevId: 634311108 --- .../transport/binder/client/channel_create.cc | 2 +- .../binder/client/endpoint_binder_pool.cc | 17 ++++++------ .../ext/transport/binder/client/jni_utils.cc | 7 ++--- .../binder/transport/binder_transport.cc | 6 ++--- .../ext/transport/binder/utils/ndk_binder.cc | 11 ++++---- .../utils/transport_stream_receiver_impl.cc | 19 +++++++------ .../binder/wire_format/binder_android.cc | 5 ++-- .../binder/wire_format/wire_writer.cc | 25 +++++++---------- .../server/chaotic_good_server.cc | 27 +++++++++---------- .../chttp2/client/chttp2_connector.cc | 3 ++- .../transport/chttp2/server/chttp2_server.cc | 19 +++++++------ .../chttp2/transport/chttp2_transport.cc | 14 +++++----- .../chttp2/transport/hpack_parser_table.cc | 6 ++--- .../ext/transport/chttp2/transport/parsing.cc | 10 +++---- .../inproc/legacy_inproc_transport.cc | 11 ++++---- 15 files changed, 89 insertions(+), 93 deletions(-) diff --git a/src/core/ext/transport/binder/client/channel_create.cc b/src/core/ext/transport/binder/client/channel_create.cc index 4c3f69eaf0f..9f757f69bc7 100644 --- a/src/core/ext/transport/binder/client/channel_create.cc +++ b/src/core/ext/transport/binder/client/channel_create.cc @@ -112,7 +112,7 @@ std::shared_ptr CreateCustomBinderChannel( std::string connection_id = grpc_binder::GetConnectionIdGenerator()->Generate(uri); - gpr_log(GPR_ERROR, "connection id is %s", connection_id.c_str()); + LOG(ERROR) << "connection id is " << connection_id; // After invoking this Java method, Java code will put endpoint binder into // `EndpointBinderPool` after the connection succeeds diff --git a/src/core/ext/transport/binder/client/endpoint_binder_pool.cc b/src/core/ext/transport/binder/client/endpoint_binder_pool.cc index 5932ce7a9bf..012d7f03063 100644 --- a/src/core/ext/transport/binder/client/endpoint_binder_pool.cc +++ b/src/core/ext/transport/binder/client/endpoint_binder_pool.cc @@ -15,6 +15,7 @@ #include "src/core/ext/transport/binder/client/endpoint_binder_pool.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include @@ -36,11 +37,11 @@ Java_io_grpc_binder_cpp_GrpcBinderConnection_notifyConnected__Ljava_lang_String_ JNIEnv* jni_env, jobject, jstring conn_id_jstring, jobject ibinder) { jboolean isCopy; const char* conn_id = jni_env->GetStringUTFChars(conn_id_jstring, &isCopy); - gpr_log(GPR_INFO, "%s invoked with conn_id = %s", __func__, conn_id); + LOG(INFO) << __func__ << " invoked with conn_id = " << conn_id; CHECK_NE(ibinder, nullptr); grpc_binder::ndk_util::SpAIBinder aibinder = grpc_binder::FromJavaBinder(jni_env, ibinder); - gpr_log(GPR_INFO, "%s got aibinder = %p", __func__, aibinder.get()); + LOG(INFO) << __func__ << " got aibinder = " << aibinder.get(); auto b = std::make_unique(aibinder); CHECK(b != nullptr); grpc_binder::GetEndpointBinderPool()->AddEndpointBinder(conn_id, @@ -58,7 +59,7 @@ namespace grpc_binder { void EndpointBinderPool::GetEndpointBinder( std::string conn_id, std::function)> cb) { - gpr_log(GPR_INFO, "EndpointBinder requested. conn_id = %s", conn_id.c_str()); + LOG(INFO) << "EndpointBinder requested. conn_id = " << conn_id; std::unique_ptr b; { grpc_core::MutexLock l(&m_); @@ -68,9 +69,8 @@ void EndpointBinderPool::GetEndpointBinder( CHECK(b != nullptr); } else { if (pending_requests_.count(conn_id) != 0) { - gpr_log(GPR_ERROR, - "Duplicate GetEndpointBinder requested. conn_id = %s", - conn_id.c_str()); + LOG(ERROR) << "Duplicate GetEndpointBinder requested. conn_id = " + << conn_id; return; } pending_requests_[conn_id] = std::move(cb); @@ -83,15 +83,14 @@ void EndpointBinderPool::GetEndpointBinder( void EndpointBinderPool::AddEndpointBinder( std::string conn_id, std::unique_ptr b) { - gpr_log(GPR_INFO, "EndpointBinder added. conn_id = %s", conn_id.c_str()); + LOG(INFO) << "EndpointBinder added. conn_id = " << conn_id; CHECK(b != nullptr); // cb will be set in the following block if there is a pending callback std::function)> cb = nullptr; { grpc_core::MutexLock l(&m_); if (binder_map_.count(conn_id) != 0) { - gpr_log(GPR_ERROR, "EndpointBinder already in the pool. conn_id = %s", - conn_id.c_str()); + LOG(ERROR) << "EndpointBinder already in the pool. conn_id = " << conn_id; return; } if (pending_requests_.count(conn_id)) { diff --git a/src/core/ext/transport/binder/client/jni_utils.cc b/src/core/ext/transport/binder/client/jni_utils.cc index 9255b7f1d17..1133604a175 100644 --- a/src/core/ext/transport/binder/client/jni_utils.cc +++ b/src/core/ext/transport/binder/client/jni_utils.cc @@ -15,6 +15,7 @@ #include "src/core/ext/transport/binder/client/jni_utils.h" #include "absl/log/check.h" +#include "absl/log/log.h" // IWYU pragma: keep #include @@ -83,7 +84,7 @@ void TryEstablishConnection(JNIEnv* env, jobject application, jmethodID mid = env->GetStaticMethodID(cl, method.c_str(), type.c_str()); if (mid == nullptr) { - gpr_log(GPR_ERROR, "No method id %s", method.c_str()); + LOG(ERROR) << "No method id " << method; } env->CallStaticVoidMethod(cl, mid, application, @@ -107,7 +108,7 @@ void TryEstablishConnectionWithUri(JNIEnv* env, jobject application, jmethodID mid = env->GetStaticMethodID(cl, method.c_str(), type.c_str()); if (mid == nullptr) { - gpr_log(GPR_ERROR, "No method id %s", method.c_str()); + LOG(ERROR) << "No method id " << method; } env->CallStaticVoidMethod(cl, mid, application, @@ -126,7 +127,7 @@ bool IsSignatureMatch(JNIEnv* env, jobject context, int uid1, int uid2) { jmethodID mid = env->GetStaticMethodID(cl, method.c_str(), type.c_str()); if (mid == nullptr) { - gpr_log(GPR_ERROR, "No method id %s", method.c_str()); + LOG(ERROR) << "No method id " << method; } jboolean result = env->CallStaticBooleanMethod(cl, mid, context, uid1, uid2); diff --git a/src/core/ext/transport/binder/transport/binder_transport.cc b/src/core/ext/transport/binder/transport/binder_transport.cc index 65512675d96..7c832505d9d 100644 --- a/src/core/ext/transport/binder/transport/binder_transport.cc +++ b/src/core/ext/transport/binder/transport/binder_transport.cc @@ -297,7 +297,7 @@ static void recv_trailing_metadata_locked(void* arg, // Append status to metadata // TODO(b/192208695): See if we can avoid to manually put status // code into the header - gpr_log(GPR_INFO, "status = %d", args->status); + LOG(INFO) << "status = " << args->status; stream->recv_trailing_metadata->Set( grpc_core::GrpcStatusMetadata(), static_cast(args->status)); @@ -350,7 +350,7 @@ class MetadataEncoder { } void Encode(grpc_core::GrpcStatusMetadata, grpc_status_code status) { - gpr_log(GPR_INFO, "send trailing metadata status = %d", status); + LOG(INFO) << "send trailing metadata status = " << status; tx_->SetStatus(status); } @@ -395,7 +395,7 @@ static void perform_stream_op_locked(void* stream_op, CHECK(!op->send_initial_metadata && !op->send_message && !op->send_trailing_metadata && !op->recv_initial_metadata && !op->recv_message && !op->recv_trailing_metadata); - gpr_log(GPR_INFO, "cancel_stream is_client = %d", stream->is_client); + LOG(INFO) << "cancel_stream is_client = " << stream->is_client; if (!stream->is_client) { // Send trailing metadata to inform the other end about the cancellation, // regardless if we'd already done that or not. diff --git a/src/core/ext/transport/binder/utils/ndk_binder.cc b/src/core/ext/transport/binder/utils/ndk_binder.cc index 1c0ae278ac4..08b0c824cb8 100644 --- a/src/core/ext/transport/binder/utils/ndk_binder.cc +++ b/src/core/ext/transport/binder/utils/ndk_binder.cc @@ -23,6 +23,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include @@ -60,10 +61,10 @@ void SetJvm(JNIEnv* env) { JavaVM* jvm = nullptr; jint error = env->GetJavaVM(&jvm); if (error != JNI_OK) { - gpr_log(GPR_ERROR, "Failed to get JVM"); + LOG(ERROR) << "Failed to get JVM"; } g_jvm = jvm; - gpr_log(GPR_INFO, "JVM cached"); + LOG(INFO) << "JVM cached"; } // `SetJvm` need to be called in the process before `AttachJvm`. This is always @@ -77,14 +78,14 @@ bool AttachJvm() { // Note: The following code would be run at most once per thread. grpc_core::MutexLock lock(&g_jvm_mu); if (g_jvm == nullptr) { - gpr_log(GPR_ERROR, "JVM not cached yet"); + LOG(ERROR) << "JVM not cached yet"; return false; } JNIEnv* env_unused; // Note that attach a thread that is already attached is a no-op, so it is // fine to call this again if the thread has already been attached by other. g_jvm->AttachCurrentThread(&env_unused, /* thr_args= */ nullptr); - gpr_log(GPR_INFO, "JVM attached successfully"); + LOG(INFO) << "JVM attached successfully"; g_is_jvm_attached = true; return true; } @@ -151,7 +152,7 @@ binder_status_t AIBinder_transact(AIBinder* binder, transaction_code_t code, AParcel** in, AParcel** out, binder_flags_t flags) { if (!AttachJvm()) { - gpr_log(GPR_ERROR, "failed to attach JVM. AIBinder_transact might fail."); + LOG(ERROR) << "failed to attach JVM. AIBinder_transact might fail."; } FORWARD(AIBinder_transact)(binder, code, in, out, flags); } diff --git a/src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc b/src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc index 7005a59aa6e..9546109aa61 100644 --- a/src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc +++ b/src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc @@ -23,8 +23,7 @@ #include #include "absl/log/check.h" - -#include +#include "absl/log/log.h" #include "src/core/lib/gprpp/crash.h" @@ -36,7 +35,7 @@ const absl::string_view void TransportStreamReceiverImpl::RegisterRecvInitialMetadata( StreamIdentifier id, InitialMetadataCallbackType cb) { - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; absl::StatusOr initial_metadata{}; { grpc_core::MutexLock l(&m_); @@ -64,7 +63,7 @@ void TransportStreamReceiverImpl::RegisterRecvInitialMetadata( void TransportStreamReceiverImpl::RegisterRecvMessage( StreamIdentifier id, MessageDataCallbackType cb) { - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; absl::StatusOr message{}; { grpc_core::MutexLock l(&m_); @@ -98,7 +97,7 @@ void TransportStreamReceiverImpl::RegisterRecvMessage( void TransportStreamReceiverImpl::RegisterRecvTrailingMetadata( StreamIdentifier id, TrailingMetadataCallbackType cb) { - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; std::pair, int> trailing_metadata{}; { grpc_core::MutexLock l(&m_); @@ -122,7 +121,7 @@ void TransportStreamReceiverImpl::RegisterRecvTrailingMetadata( void TransportStreamReceiverImpl::NotifyRecvInitialMetadata( StreamIdentifier id, absl::StatusOr initial_metadata) { - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; if (!is_client_ && accept_stream_callback_ && initial_metadata.ok()) { accept_stream_callback_(); } @@ -143,7 +142,7 @@ void TransportStreamReceiverImpl::NotifyRecvInitialMetadata( void TransportStreamReceiverImpl::NotifyRecvMessage( StreamIdentifier id, absl::StatusOr message) { - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; MessageDataCallbackType cb; { grpc_core::MutexLock l(&m_); @@ -166,7 +165,7 @@ void TransportStreamReceiverImpl::NotifyRecvTrailingMetadata( // assumes in-order commitments of transactions and that trailing metadata is // parsed after message data, we can safely cancel all upcoming callbacks of // recv_message. - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; OnRecvTrailingMetadata(id); TrailingMetadataCallbackType cb; { @@ -233,7 +232,7 @@ void TransportStreamReceiverImpl::CancelTrailingMetadataCallback( } void TransportStreamReceiverImpl::OnRecvTrailingMetadata(StreamIdentifier id) { - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; m_.Lock(); trailing_metadata_recvd_.insert(id); m_.Unlock(); @@ -245,7 +244,7 @@ void TransportStreamReceiverImpl::OnRecvTrailingMetadata(StreamIdentifier id) { } void TransportStreamReceiverImpl::CancelStream(StreamIdentifier id) { - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; CancelInitialMetadataCallback(id, absl::CancelledError("Stream cancelled")); CancelMessageCallback(id, absl::CancelledError("Stream cancelled")); CancelTrailingMetadataCallback(id, absl::CancelledError("Stream cancelled")); diff --git a/src/core/ext/transport/binder/wire_format/binder_android.cc b/src/core/ext/transport/binder/wire_format/binder_android.cc index fc816447c59..6ca9b6dcecd 100644 --- a/src/core/ext/transport/binder/wire_format/binder_android.cc +++ b/src/core/ext/transport/binder/wire_format/binder_android.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" @@ -65,7 +66,7 @@ ndk_util::binder_status_t f_onTransact(ndk_util::AIBinder* binder, const ndk_util::AParcel* in, ndk_util::AParcel* /*out*/) { gpr_log(GPR_INFO, __func__); - gpr_log(GPR_INFO, "tx code = %u", code); + LOG(INFO) << "tx code = " << code; auto* user_data = static_cast(ndk_util::AIBinder_getUserData(binder)); @@ -79,7 +80,7 @@ ndk_util::binder_status_t f_onTransact(ndk_util::AIBinder* binder, if (status.ok()) { return ndk_util::STATUS_OK; } else { - gpr_log(GPR_ERROR, "Callback failed: %s", status.ToString().c_str()); + LOG(ERROR) << "Callback failed: " << status.ToString(); return ndk_util::STATUS_UNKNOWN_ERROR; } } diff --git a/src/core/ext/transport/binder/wire_format/wire_writer.cc b/src/core/ext/transport/binder/wire_format/wire_writer.cc index f81d1d6172f..6379bd17ff4 100644 --- a/src/core/ext/transport/binder/wire_format/wire_writer.cc +++ b/src/core/ext/transport/binder/wire_format/wire_writer.cc @@ -22,6 +22,7 @@ #include "absl/cleanup/cleanup.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/types/variant.h" #include @@ -78,7 +79,7 @@ absl::Status WriteTrailingMetadata(const Transaction& tx, } else { // client suffix currently is always empty according to the wireformat if (!tx.GetSuffixMetadata().empty()) { - gpr_log(GPR_ERROR, "Got non-empty suffix metadata from client."); + LOG(ERROR) << "Got non-empty suffix metadata from client."; } } return absl::OkStatus(); @@ -218,8 +219,7 @@ void WireWriterImpl::RunScheduledTxInternal(RunScheduledTxArgs* args) { return absl::OkStatus(); }); if (!result.ok()) { - gpr_log(GPR_ERROR, "Failed to make binder transaction %s", - result.ToString().c_str()); + LOG(ERROR) << "Failed to make binder transaction " << result; } delete args; return; @@ -242,8 +242,7 @@ void WireWriterImpl::RunScheduledTxInternal(RunScheduledTxArgs* args) { if (CanBeSentInOneTransaction(*stream_tx->tx.get())) { // NOLINT absl::Status result = RpcCallFastPath(std::move(stream_tx->tx)); if (!result.ok()) { - gpr_log(GPR_ERROR, "Failed to handle non-chunked RPC call %s", - result.ToString().c_str()); + LOG(ERROR) << "Failed to handle non-chunked RPC call " << result; } delete args; return; @@ -256,8 +255,7 @@ void WireWriterImpl::RunScheduledTxInternal(RunScheduledTxArgs* args) { return RunStreamTx(stream_tx, parcel, &is_last_chunk); }); if (!result.ok()) { - gpr_log(GPR_ERROR, "Failed to make binder transaction %s", - result.ToString().c_str()); + LOG(ERROR) << "Failed to make binder transaction " << result; } if (!is_last_chunk) { { @@ -290,7 +288,7 @@ absl::Status WireWriterImpl::SendAck(int64_t num_bytes) { // Ensure combiner will be run if this is not called from top-level gRPC API // entrypoint. grpc_core::ExecCtx exec_ctx; - gpr_log(GPR_INFO, "Ack %" PRId64 " bytes received", num_bytes); + LOG(INFO) << "Ack " << num_bytes << " bytes received"; if (is_transacting_) { // This can happen because NDK might call our registered callback function // in the same thread while we are telling it to send a transaction @@ -298,10 +296,8 @@ absl::Status WireWriterImpl::SendAck(int64_t num_bytes) { // the same thread or the other thread. We are currently in the call stack // of other transaction, Liveness of ACK is still guaranteed even if this is // a race with another thread. - gpr_log( - GPR_INFO, - "Scheduling ACK transaction instead of directly execute it to avoid " - "deadlock."); + LOG(INFO) << "Scheduling ACK transaction instead of directly execute it to " + "avoid deadlock."; auto args = new RunScheduledTxArgs(); args->writer = this; args->tx = RunScheduledTxArgs::AckTx(); @@ -318,8 +314,7 @@ absl::Status WireWriterImpl::SendAck(int64_t num_bytes) { return absl::OkStatus(); }); if (!result.ok()) { - gpr_log(GPR_ERROR, "Failed to make binder transaction %s", - result.ToString().c_str()); + LOG(ERROR) << "Failed to make binder transaction " << result; } return result; } @@ -328,7 +323,7 @@ void WireWriterImpl::OnAckReceived(int64_t num_bytes) { // Ensure combiner will be run if this is not called from top-level gRPC API // entrypoint. grpc_core::ExecCtx exec_ctx; - gpr_log(GPR_INFO, "OnAckReceived %" PRId64, num_bytes); + LOG(INFO) << "OnAckReceived " << num_bytes; // Do not try to obtain `write_mu_` in this function. NDKBinder might invoke // the callback to notify us about new incoming binder transaction when we are // sending transaction. i.e. `write_mu_` might have already been acquired by diff --git a/src/core/ext/transport/chaotic_good/server/chaotic_good_server.cc b/src/core/ext/transport/chaotic_good/server/chaotic_good_server.cc index 7dd94de3090..8af652a292c 100644 --- a/src/core/ext/transport/chaotic_good/server/chaotic_good_server.cc +++ b/src/core/ext/transport/chaotic_good/server/chaotic_good_server.cc @@ -22,6 +22,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/random/bit_gen_ref.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -99,8 +100,8 @@ absl::StatusOr ChaoticGoodServerListener::Bind( grpc_event_engine::experimental::EventEngine::ResolvedAddress addr) { if (grpc_chaotic_good_trace.enabled()) { auto str = grpc_event_engine::experimental::ResolvedAddressToString(addr); - gpr_log(GPR_INFO, "CHAOTIC_GOOD: Listen on %s", - str.ok() ? str->c_str() : str.status().ToString().c_str()); + LOG(INFO) << "CHAOTIC_GOOD: Listen on " + << (str.ok() ? str->c_str() : str.status().ToString()); } EventEngine::Listener::AcceptCallback accept_cb = [self = RefAsSubclass()]( @@ -123,8 +124,7 @@ absl::StatusOr ChaoticGoodServerListener::Bind( grpc_event_engine::experimental::ChannelArgsEndpointConfig(args_), std::make_unique("chaotic_good_server_listener")); if (!ee_listener.ok()) { - gpr_log(GPR_ERROR, "Bind failed: %s", - ee_listener.status().ToString().c_str()); + LOG(ERROR) << "Bind failed: " << ee_listener.status().ToString(); return ee_listener.status(); } ee_listener_ = std::move(ee_listener.value()); @@ -139,9 +139,9 @@ absl::Status ChaoticGoodServerListener::StartListening() { CHECK(ee_listener_ != nullptr); auto status = ee_listener_->Start(); if (!status.ok()) { - gpr_log(GPR_ERROR, "Start listening failed: %s", status.ToString().c_str()); + LOG(ERROR) << "Start listening failed: " << status.ToString(); } else if (grpc_chaotic_good_trace.enabled()) { - gpr_log(GPR_INFO, "CHAOTIC_GOOD: Started listening"); + LOG(INFO) << "CHAOTIC_GOOD: Started listening"; } return status; } @@ -161,7 +161,7 @@ ChaoticGoodServerListener::ActiveConnection::~ActiveConnection() { void ChaoticGoodServerListener::ActiveConnection::Orphan() { if (grpc_chaotic_good_trace.enabled()) { - gpr_log(GPR_INFO, "ActiveConnection::Orphan() %p", this); + LOG(INFO) << "ActiveConnection::Orphan() " << this; } if (handshaking_state_ != nullptr) { handshaking_state_->Shutdown(); @@ -193,8 +193,7 @@ void ChaoticGoodServerListener::ActiveConnection::NewConnectionID() { void ChaoticGoodServerListener::ActiveConnection::Done( absl::optional error) { if (error.has_value()) { - gpr_log(GPR_ERROR, "ActiveConnection::Done:%p %s", this, - std::string(*error).c_str()); + LOG(ERROR) << "ActiveConnection::Done:" << this << " " << *error; } // Can easily be holding various locks here: bounce through EE to ensure no // deadlocks. @@ -459,7 +458,7 @@ Timestamp ChaoticGoodServerListener::ActiveConnection::HandshakingState:: void ChaoticGoodServerListener::Orphan() { if (grpc_chaotic_good_trace.enabled()) { - gpr_log(GPR_INFO, "ChaoticGoodServerListener::Orphan()"); + LOG(INFO) << "ChaoticGoodServerListener::Orphan()"; } { absl::flat_hash_set> connection_list; @@ -481,8 +480,8 @@ int grpc_server_add_chaotic_good_port(grpc_server* server, const char* addr) { const auto resolved_or = grpc_core::GetDNSResolver()->LookupHostnameBlocking( parsed_addr, absl::StrCat(0xd20)); if (!resolved_or.ok()) { - gpr_log(GPR_ERROR, "Failed to resolve %s: %s", addr, - resolved_or.status().ToString().c_str()); + LOG(ERROR) << "Failed to resolve " << addr << ": " + << resolved_or.status().ToString(); return 0; } int port_num = 0; @@ -497,8 +496,8 @@ int grpc_server_add_chaotic_good_port(grpc_server* server, const char* addr) { ->c_str()); auto bind_result = listener->Bind(ee_addr); if (!bind_result.ok()) { - gpr_log(GPR_ERROR, "Failed to bind to %s: %s", addr, - bind_result.status().ToString().c_str()); + LOG(ERROR) << "Failed to bind to " << addr << ": " + << bind_result.status().ToString(); return 0; } if (port_num == 0) { diff --git a/src/core/ext/transport/chttp2/client/chttp2_connector.cc b/src/core/ext/transport/chttp2/client/chttp2_connector.cc index 2d64d03e4ff..37f1a565736 100644 --- a/src/core/ext/transport/chttp2/client/chttp2_connector.cc +++ b/src/core/ext/transport/chttp2/client/chttp2_connector.cc @@ -25,6 +25,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" @@ -311,7 +312,7 @@ class Chttp2SecureClientChannelFactory : public ClientChannelFactory { absl::StatusOr> CreateChannel(const char* target, const ChannelArgs& args) { if (target == nullptr) { - gpr_log(GPR_ERROR, "cannot create channel with NULL target name"); + LOG(ERROR) << "cannot create channel with NULL target name"; return absl::InvalidArgumentError("channel target is NULL"); } return ChannelCreate(target, args, GRPC_CLIENT_CHANNEL, nullptr); diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index 1c2ab26dc24..3388e234fd9 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -30,6 +30,7 @@ #include "absl/base/thread_annotations.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" @@ -45,7 +46,6 @@ #include #include #include -#include #include #include "src/core/channelz/channelz.h" @@ -326,8 +326,7 @@ void Chttp2ServerListener::ConfigFetcherWatcher::UpdateConnectionManager( grpc_error_handle error = grpc_tcp_server_add_port( listener_->tcp_server_, &listener_->resolved_address_, &port_temp); if (!error.ok()) { - gpr_log(GPR_ERROR, "Error adding port to server: %s", - StatusToString(error).c_str()); + LOG(ERROR) << "Error adding port to server: " << StatusToString(error); // TODO(yashykt): We wouldn't need to assert here if we bound to the // port earlier during AddPort. CHECK(0); @@ -535,8 +534,8 @@ void Chttp2ServerListener::ActiveConnection::HandshakingState::OnHandshakeDone( }); } else { // Failed to create channel from transport. Clean up. - gpr_log(GPR_ERROR, "Failed to create channel: %s", - StatusToString(channel_init_err).c_str()); + LOG(ERROR) << "Failed to create channel: " + << StatusToString(channel_init_err); transport->Orphan(); grpc_slice_buffer_destroy(args->read_buffer); gpr_free(args->read_buffer); @@ -1038,7 +1037,7 @@ grpc_error_handle Chttp2ServerAddPort(Server* server, const char* addr, resolved_or->size() - error_list.size(), resolved_or->size()); error = GRPC_ERROR_CREATE_REFERENCING(msg.c_str(), error_list.data(), error_list.size()); - gpr_log(GPR_INFO, "WARNING: %s", StatusToString(error).c_str()); + LOG(INFO) << "WARNING: " << StatusToString(error); // we managed to bind some addresses: continue without error } return absl::OkStatus(); @@ -1158,7 +1157,7 @@ int grpc_server_add_http2_port(grpc_server* server, const char* addr, done: sc.reset(DEBUG_LOCATION, "server"); if (!err.ok()) { - gpr_log(GPR_ERROR, "%s", grpc_core::StatusToString(err).c_str()); + LOG(ERROR) << grpc_core::StatusToString(err); } return port_num; } @@ -1169,7 +1168,7 @@ void grpc_server_add_channel_from_fd(grpc_server* server, int fd, // For now, we only support insecure server credentials if (creds == nullptr || creds->type() != grpc_core::InsecureServerCredentials::Type()) { - gpr_log(GPR_ERROR, "Failed to create channel due to invalid creds"); + LOG(ERROR) << "Failed to create channel due to invalid creds"; return; } grpc_core::ExecCtx exec_ctx; @@ -1194,8 +1193,8 @@ void grpc_server_add_channel_from_fd(grpc_server* server, int fd, } grpc_chttp2_transport_start_reading(transport, nullptr, nullptr, nullptr); } else { - gpr_log(GPR_ERROR, "Failed to create channel: %s", - grpc_core::StatusToString(error).c_str()); + LOG(ERROR) << "Failed to create channel: " + << grpc_core::StatusToString(error); transport->Orphan(); } } diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 10f1a35a946..dd677809492 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -803,8 +803,8 @@ grpc_chttp2_stream::grpc_chttp2_stream(grpc_chttp2_transport* t, if (server_data) { id = static_cast(reinterpret_cast(server_data)); if (grpc_http_trace.enabled()) { - gpr_log(GPR_DEBUG, "HTTP:%p/%p creating accept stream %d [from %p]", t, - this, id, server_data); + VLOG(2) << "HTTP:" << t << "/" << this << " creating accept stream " << id + << " [from " << server_data << "]"; } *t->accepting_stream = this; t->stream_map.emplace(id, this); @@ -1037,8 +1037,8 @@ static void write_action(grpc_chttp2_transport* t) { max_frame_size = INT_MAX; } if (GRPC_TRACE_FLAG_ENABLED(grpc_ping_trace)) { - gpr_log(GPR_INFO, "%s[%p]: Write %" PRIdPTR " bytes", - t->is_client ? "CLIENT" : "SERVER", t, t->outbuf.Length()); + LOG(INFO) << (t->is_client ? "CLIENT" : "SERVER") << "[" << t << "]: Write " + << t->outbuf.Length() << " bytes"; } t->write_size_policy.BeginWrite(t->outbuf.Length()); grpc_endpoint_write(t->ep, t->outbuf.c_slice_buffer(), @@ -1051,8 +1051,8 @@ static void write_action_end(grpc_core::RefCountedPtr t, grpc_error_handle error) { auto* tp = t.get(); if (GRPC_TRACE_FLAG_ENABLED(grpc_ping_trace)) { - gpr_log(GPR_INFO, "%s[%p]: Finish write", - t->is_client ? "CLIENT" : "SERVER", t.get()); + LOG(INFO) << (t->is_client ? "CLIENT" : "SERVER") << "[" << t.get() + << "]: Finish write"; } tp->combiner->Run(grpc_core::InitTransportClosure( std::move(t), &tp->write_action_end_locked), @@ -1329,7 +1329,7 @@ static void log_metadata(const grpc_metadata_batch* md_batch, uint32_t id, const std::string prefix = absl::StrCat( "HTTP:", id, is_initial ? ":HDR" : ":TRL", is_client ? ":CLI:" : ":SVR:"); md_batch->Log([&prefix](absl::string_view key, absl::string_view value) { - gpr_log(GPR_INFO, "%s", absl::StrCat(prefix, key, ": ", value).c_str()); + LOG(INFO) << absl::StrCat(prefix, key, ": ", value); }); } diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc b/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc index d878c3c1b61..41d7d27c343 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc @@ -26,11 +26,11 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include #include #include "src/core/ext/transport/chttp2/transport/hpack_constants.h" @@ -100,7 +100,7 @@ void HPackTable::SetMaxBytes(uint32_t max_bytes) { return; } if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) { - gpr_log(GPR_INFO, "Update hpack parser max size to %d", max_bytes); + LOG(INFO) << "Update hpack parser max size to " << max_bytes; } while (mem_used_ > max_bytes) { EvictOne(); @@ -112,7 +112,7 @@ bool HPackTable::SetCurrentTableSize(uint32_t bytes) { if (current_table_bytes_ == bytes) return true; if (bytes > max_bytes_) return false; if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) { - gpr_log(GPR_INFO, "Update hpack parser table size to %d", bytes); + LOG(INFO) << "Update hpack parser table size to " << bytes; } while (mem_used_ > bytes) { EvictOne(); diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index e74596eee01..a49d91263e5 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -29,6 +29,7 @@ #include "absl/base/attributes.h" #include "absl/container/flat_hash_map.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/random/bit_gen_ref.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" @@ -769,7 +770,7 @@ static grpc_error_handle init_header_frame_parser(grpc_chttp2_transport* t, frame_type = HPackParser::LogInfo::kTrailers; break; case 2: - gpr_log(GPR_ERROR, "too many header frames received"); + LOG(ERROR) << "too many header frames received"; return init_header_skip_frame_parser(t, priority_type, is_eoh); } if (frame_type == HPackParser::LogInfo::kTrailers && !t->header_eof) { @@ -889,10 +890,9 @@ static grpc_error_handle parse_frame_slice(grpc_chttp2_transport* t, int is_last) { grpc_chttp2_stream* s = t->incoming_stream; if (grpc_http_trace.enabled()) { - gpr_log(GPR_DEBUG, - "INCOMING[%p;%p]: Parse %" PRIdPTR "b %sframe fragment with %s", t, - s, GRPC_SLICE_LENGTH(slice), is_last ? "last " : "", - t->parser.name); + VLOG(2) << "INCOMING[" << t << ";" << s << "]: Parse " + << GRPC_SLICE_LENGTH(slice) << "b " << (is_last ? "last " : "") + << "frame fragment with " << t->parser.name; } grpc_error_handle err = t->parser.parser(t->parser.user_data, t, s, slice, is_last); diff --git a/src/core/ext/transport/inproc/legacy_inproc_transport.cc b/src/core/ext/transport/inproc/legacy_inproc_transport.cc index dd5c4663abc..9412fe41e4e 100644 --- a/src/core/ext/transport/inproc/legacy_inproc_transport.cc +++ b/src/core/ext/transport/inproc/legacy_inproc_transport.cc @@ -28,6 +28,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" @@ -319,7 +320,7 @@ void log_metadata(const grpc_metadata_batch* md_batch, bool is_client, std::string prefix = absl::StrCat( "INPROC:", is_initial ? "HDR:" : "TRL:", is_client ? "CLI:" : "SVR:"); md_batch->Log([&prefix](absl::string_view key, absl::string_view value) { - gpr_log(GPR_INFO, "%s", absl::StrCat(prefix, key, ": ", value).c_str()); + LOG(INFO) << absl::StrCat(prefix, key, ": ", value); }); } @@ -1268,8 +1269,8 @@ grpc_channel* grpc_legacy_inproc_channel_create(grpc_server* server, "inproc", client_args, GRPC_CLIENT_DIRECT_CHANNEL, client_transport); if (!new_channel.ok()) { CHECK(!channel); - gpr_log(GPR_ERROR, "Failed to create client channel: %s", - grpc_core::StatusToString(error).c_str()); + LOG(ERROR) << "Failed to create client channel: " + << grpc_core::StatusToString(error); intptr_t integer; grpc_status_code status = GRPC_STATUS_INTERNAL; if (grpc_error_get_int(error, grpc_core::StatusIntProperty::kRpcStatus, @@ -1286,8 +1287,8 @@ grpc_channel* grpc_legacy_inproc_channel_create(grpc_server* server, } } else { CHECK(!channel); - gpr_log(GPR_ERROR, "Failed to create server channel: %s", - grpc_core::StatusToString(error).c_str()); + LOG(ERROR) << "Failed to create server channel: " + << grpc_core::StatusToString(error); intptr_t integer; grpc_status_code status = GRPC_STATUS_INTERNAL; if (grpc_error_get_int(error, grpc_core::StatusIntProperty::kRpcStatus, From 2d2d5a3c411a2bade319a08085e55821cf2d5ed9 Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap Date: Thu, 16 May 2024 05:56:57 -0700 Subject: [PATCH 08/23] [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. PiperOrigin-RevId: 634349131 --- src/core/lib/iomgr/buffer_list.cc | 6 ++++-- src/core/lib/iomgr/call_combiner.cc | 11 ++++++----- src/core/lib/iomgr/ev_epoll1_linux.cc | 4 ++-- src/core/lib/iomgr/ev_poll_posix.cc | 7 ++++--- src/core/lib/iomgr/ev_posix.cc | 3 ++- .../lib/iomgr/event_engine_shims/endpoint.cc | 5 +++-- src/core/lib/iomgr/fork_windows.cc | 4 +++- src/core/lib/iomgr/internal_errqueue.cc | 6 ++++-- src/core/lib/iomgr/iocp_windows.cc | 3 ++- .../lib/iomgr/socket_utils_common_posix.cc | 5 +++-- src/core/lib/iomgr/socket_windows.cc | 3 ++- src/core/lib/iomgr/tcp_client_posix.cc | 3 ++- src/core/lib/iomgr/tcp_posix.cc | 8 ++++---- .../iomgr/tcp_server_utils_posix_common.cc | 3 ++- .../iomgr/tcp_server_utils_posix_ifaddrs.cc | 3 ++- src/core/lib/iomgr/tcp_server_windows.cc | 7 ++++--- src/core/lib/iomgr/timer_manager.cc | 19 ++++++++++--------- 17 files changed, 59 insertions(+), 41 deletions(-) diff --git a/src/core/lib/iomgr/buffer_list.cc b/src/core/lib/iomgr/buffer_list.cc index 6de9d89c05b..aedb4227073 100644 --- a/src/core/lib/iomgr/buffer_list.cc +++ b/src/core/lib/iomgr/buffer_list.cc @@ -18,6 +18,8 @@ #include "src/core/lib/iomgr/buffer_list.h" +#include "absl/log/log.h" + #include #include #include @@ -42,7 +44,7 @@ void FillGprFromTimestamp(gpr_timespec* gts, const struct timespec* ts) { void DefaultTimestampsCallback(void* /*arg*/, Timestamps* /*ts*/, absl::Status /*shudown_err*/) { - gpr_log(GPR_DEBUG, "Timestamps callback has not been registered"); + VLOG(2) << "Timestamps callback has not been registered"; } // The saved callback function that will be invoked when we get all the @@ -321,7 +323,7 @@ void grpc_tcp_set_write_timestamps_callback( // Can't comment out the name because some compilers and formatters don't // like the sequence */* , which would arise from */*fn*/. (void)fn; - gpr_log(GPR_DEBUG, "Timestamps callback is not enabled for this platform"); + VLOG(2) << "Timestamps callback is not enabled for this platform"; } } // namespace grpc_core diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc index 6c44bdb0650..c6fb49cea1a 100644 --- a/src/core/lib/iomgr/call_combiner.cc +++ b/src/core/lib/iomgr/call_combiner.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -130,13 +131,13 @@ void CallCombiner::Start(grpc_closure* closure, grpc_error_handle error, } if (prev_size == 0) { if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " EXECUTING IMMEDIATELY"); + LOG(INFO) << " EXECUTING IMMEDIATELY"; } // Queue was empty, so execute this closure immediately. ScheduleClosure(closure, error); } else { if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " QUEUING"); + LOG(INFO) << " QUEUING"; } // Queue was not empty, so add closure to queue. closure->error_data.error = internal::StatusAllocHeapPtr(error); @@ -160,7 +161,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) { if (prev_size > 1) { while (true) { if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " checking queue"); + LOG(INFO) << " checking queue"; } bool empty; grpc_closure* closure = @@ -169,7 +170,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) { // This can happen either due to a race condition within the mpscq // code or because of a race with Start(). if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " queue returned no result; checking again"); + LOG(INFO) << " queue returned no result; checking again"; } continue; } @@ -184,7 +185,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) { break; } } else if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " queue empty"); + LOG(INFO) << " queue empty"; } } diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index d40b20a93b7..3dc33746701 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -122,7 +122,7 @@ static bool epoll_set_init() { return false; } - gpr_log(GPR_INFO, "grpc epoll fd: %d", g_epoll_set.epfd); + LOG(INFO) << "grpc epoll fd: " << g_epoll_set.epfd; gpr_atm_no_barrier_store(&g_epoll_set.num_events, 0); gpr_atm_no_barrier_store(&g_epoll_set.cursor, 0); return true; @@ -1073,7 +1073,7 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset, log.push_back(absl::StrFormat(" worker_kick_state=%s", kick_state_string(specific_worker->state))); } - gpr_log(GPR_DEBUG, "%s", absl::StrJoin(log, "").c_str()); + VLOG(2) << absl::StrJoin(log, ""); } if (specific_worker == nullptr) { diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index 0752fd61657..7d290d7d83e 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -34,6 +34,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -583,7 +584,7 @@ static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { static void fd_notify_on_error(grpc_fd* /*fd*/, grpc_closure* closure) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_ERROR, "Polling engine does not support tracking errors."); + LOG(ERROR) << "Polling engine does not support tracking errors."; } grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, absl::CancelledError()); } @@ -602,7 +603,7 @@ static void fd_set_writable(grpc_fd* fd) { static void fd_set_error(grpc_fd* /*fd*/) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_ERROR, "Polling engine does not support tracking errors."); + LOG(ERROR) << "Polling engine does not support tracking errors."; } } @@ -1397,7 +1398,7 @@ const grpc_event_engine_vtable grpc_ev_poll_posix = { // check_engine_available = [](bool) { if (!grpc_has_wakeup_fd()) { - gpr_log(GPR_ERROR, "Skipping poll because of no wakeup fd."); + LOG(ERROR) << "Skipping poll because of no wakeup fd."; return false; } if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) { diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index 3456a87c482..e204b4a697b 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -25,6 +25,7 @@ #include +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include "absl/strings/str_split.h" @@ -109,7 +110,7 @@ static void try_engine(absl::string_view engine) { if (g_vtables[i] != nullptr && is(engine, g_vtables[i]->name) && g_vtables[i]->check_engine_available(engine == g_vtables[i]->name)) { g_event_engine = g_vtables[i]; - gpr_log(GPR_DEBUG, "Using polling engine: %s", g_event_engine->name); + VLOG(2) << "Using polling engine: " << g_event_engine->name; return; } } diff --git a/src/core/lib/iomgr/event_engine_shims/endpoint.cc b/src/core/lib/iomgr/event_engine_shims/endpoint.cc index dc0019efc12..42238e47062 100644 --- a/src/core/lib/iomgr/event_engine_shims/endpoint.cc +++ b/src/core/lib/iomgr/event_engine_shims/endpoint.cc @@ -19,6 +19,7 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" @@ -128,7 +129,7 @@ class EventEngineEndpointWrapper { for (i = 0; i < pending_read_buffer_->count; i++) { char* dump = grpc_dump_slice(pending_read_buffer_->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "READ DATA: %s", dump); + VLOG(2) << "READ DATA: " << dump; gpr_free(dump); } } @@ -159,7 +160,7 @@ class EventEngineEndpointWrapper { for (i = 0; i < slices->count; i++) { char* dump = grpc_dump_slice(slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "WRITE DATA: %s", dump); + VLOG(2) << "WRITE DATA: " << dump; gpr_free(dump); } } diff --git a/src/core/lib/iomgr/fork_windows.cc b/src/core/lib/iomgr/fork_windows.cc index d8e73ed87c4..0e1583173d3 100644 --- a/src/core/lib/iomgr/fork_windows.cc +++ b/src/core/lib/iomgr/fork_windows.cc @@ -22,6 +22,8 @@ #ifndef GRPC_POSIX_FORK +#include "absl/log/log.h" + #include #include @@ -30,7 +32,7 @@ // AROUND VERY SPECIFIC USE CASES. // -void grpc_prefork() { gpr_log(GPR_ERROR, "Forking not supported on Windows"); } +void grpc_prefork() { LOG(ERROR) << "Forking not supported on Windows"; } void grpc_postfork_parent() {} diff --git a/src/core/lib/iomgr/internal_errqueue.cc b/src/core/lib/iomgr/internal_errqueue.cc index 3167cb035de..5223687a439 100644 --- a/src/core/lib/iomgr/internal_errqueue.cc +++ b/src/core/lib/iomgr/internal_errqueue.cc @@ -14,6 +14,8 @@ #include "src/core/lib/iomgr/internal_errqueue.h" +#include "absl/log/log.h" + #include #include @@ -37,7 +39,7 @@ bool KernelSupportsErrqueue() { // least 4.0.0 struct utsname buffer; if (uname(&buffer) != 0) { - gpr_log(GPR_ERROR, "uname: %s", StrError(errno).c_str()); + LOG(ERROR) << "uname: " << StrError(errno); return false; } char* release = buffer.release; @@ -48,7 +50,7 @@ bool KernelSupportsErrqueue() { if (strtol(release, nullptr, 10) >= 4) { return true; } else { - gpr_log(GPR_DEBUG, "ERRQUEUE support not enabled"); + VLOG(2) << "ERRQUEUE support not enabled"; } #endif // GRPC_LINUX_ERRQUEUE return false; diff --git a/src/core/lib/iomgr/iocp_windows.cc b/src/core/lib/iomgr/iocp_windows.cc index 0353aa7614a..a19c13ab7b6 100644 --- a/src/core/lib/iomgr/iocp_windows.cc +++ b/src/core/lib/iomgr/iocp_windows.cc @@ -27,6 +27,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -157,7 +158,7 @@ void grpc_iocp_add_socket(grpc_winsocket* socket) { (uintptr_t)socket, 0); if (!ret) { char* utf8_message = gpr_format_message(WSAGetLastError()); - gpr_log(GPR_ERROR, "Unable to add socket to iocp: %s", utf8_message); + LOG(ERROR) << "Unable to add socket to iocp: " << utf8_message; gpr_free(utf8_message); __debugbreak(); abort(); diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc index ce4d7a3566c..7ebafa6897b 100644 --- a/src/core/lib/iomgr/socket_utils_common_posix.cc +++ b/src/core/lib/iomgr/socket_utils_common_posix.cc @@ -44,6 +44,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -411,7 +412,7 @@ grpc_error_handle grpc_set_socket_tcp_user_timeout( } } else { if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_INFO, "TCP_USER_TIMEOUT not supported for this platform"); + LOG(INFO) << "TCP_USER_TIMEOUT not supported for this platform"; } } return absl::OkStatus(); @@ -442,7 +443,7 @@ static void probe_ipv6_once(void) { int fd = socket(AF_INET6, SOCK_STREAM, 0); g_ipv6_loopback_available = 0; if (fd < 0) { - gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed."); + LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed."; } else { grpc_sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index fc2cdc97407..44e524c6829 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -28,6 +28,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include @@ -217,7 +218,7 @@ static void probe_ipv6_once(void) { SOCKET s = socket(AF_INET6, SOCK_STREAM, 0); g_ipv6_loopback_available = 0; if (s == INVALID_SOCKET) { - gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed."); + LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed."; } else { grpc_sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index 2e5e8fd6b8e..8fb50f6754e 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -30,6 +30,7 @@ #include "absl/container/flat_hash_map.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -240,7 +241,7 @@ static void on_writable(void* acp, grpc_error_handle error) { // your program or another program on the same computer // opened too many network connections. The "easy" fix: // don't do that! - gpr_log(GPR_ERROR, "kernel out of buffers"); + LOG(ERROR) << "kernel out of buffers"; gpr_mu_unlock(&ac->mu); grpc_fd_notify_on_write(fd, &ac->write_closure); return; diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index 07906b6889c..1f9f9817e04 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -875,7 +875,7 @@ static void tcp_trace_read(grpc_tcp* tcp, grpc_error_handle error) for (i = 0; i < tcp->incoming_buffer->count; i++) { char* dump = grpc_dump_slice(tcp->incoming_buffer->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "READ DATA: %s", dump); + VLOG(2) << "READ DATA: " << dump; gpr_free(dump); } } @@ -1853,7 +1853,7 @@ static void tcp_handle_write(void* arg /* grpc_tcp */, tcp->write_cb = nullptr; tcp->current_zerocopy_send = nullptr; if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_INFO, "write: %s", grpc_core::StatusToString(error).c_str()); + LOG(INFO) << "write: " << grpc_core::StatusToString(error); } // No need to take a ref on error since tcp_flush provides a ref. grpc_core::Closure::Run(DEBUG_LOCATION, cb, error); @@ -1877,7 +1877,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, if (gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) { char* data = grpc_dump_slice(buf->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "WRITE DATA: %s", data); + VLOG(2) << "WRITE DATA: " << data; gpr_free(data); } } @@ -1921,7 +1921,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, notify_on_write(tcp); } else { if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_INFO, "write: %s", grpc_core::StatusToString(error).c_str()); + LOG(INFO) << "write: " << grpc_core::StatusToString(error); } grpc_core::Closure::Run(DEBUG_LOCATION, cb, error); } diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc index 181ab5b8e25..ee8f7350eb6 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc @@ -32,6 +32,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -221,7 +222,7 @@ grpc_error_handle grpc_tcp_server_prepare_socket( err = grpc_set_socket_zerocopy(fd); if (!err.ok()) { // it's not fatal, so just log it. - gpr_log(GPR_DEBUG, "Node does not support SO_ZEROCOPY, continuing."); + VLOG(2) << "Node does not support SO_ZEROCOPY, continuing."; } #endif err = grpc_set_socket_nonblocking(fd, 1); diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc index d04dddf8e46..495e800ea08 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc @@ -31,6 +31,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -115,7 +116,7 @@ grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, } else if (requested_port <= 0) { return GRPC_ERROR_CREATE("Bad get_unused_port()"); } - gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port); + VLOG(2) << "Picked unused port " << requested_port; } static bool v4_available = grpc_is_ipv4_availabile(); diff --git a/src/core/lib/iomgr/tcp_server_windows.cc b/src/core/lib/iomgr/tcp_server_windows.cc index 70b4a6a5920..b2a0ab25be8 100644 --- a/src/core/lib/iomgr/tcp_server_windows.cc +++ b/src/core/lib/iomgr/tcp_server_windows.cc @@ -28,6 +28,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -405,7 +406,7 @@ static void on_accept(void* arg, grpc_error_handle error) { if (!wsa_success) { if (!sp->shutting_down) { char* utf8_message = gpr_format_message(WSAGetLastError()); - gpr_log(GPR_ERROR, "on_accept error: %s", utf8_message); + LOG(ERROR) << "on_accept error: " << utf8_message; gpr_free(utf8_message); } closesocket(sock); @@ -415,7 +416,7 @@ static void on_accept(void* arg, grpc_error_handle error) { (char*)&sp->socket->socket, sizeof(sp->socket->socket)); if (err) { char* utf8_message = gpr_format_message(WSAGetLastError()); - gpr_log(GPR_ERROR, "setsockopt error: %s", utf8_message); + LOG(ERROR) << "setsockopt error: " << utf8_message; gpr_free(utf8_message); } int peer_name_len = (int)peer_name.len; @@ -432,7 +433,7 @@ static void on_accept(void* arg, grpc_error_handle error) { } } else { char* utf8_message = gpr_format_message(WSAGetLastError()); - gpr_log(GPR_ERROR, "getpeername error: %s", utf8_message); + LOG(ERROR) << "getpeername error: " << utf8_message; gpr_free(utf8_message); } std::string fd_name = absl::StrCat("tcp_server:", peer_name_string); diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 6e4197a8f83..9cab02d2877 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -89,7 +90,7 @@ static void start_timer_thread_and_unlock(void) { ++g_thread_count; gpr_mu_unlock(&g_mu); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "Spawn timer thread"); + LOG(INFO) << "Spawn timer thread"; } completed_thread* ct = static_cast(gpr_malloc(sizeof(*ct))); @@ -125,7 +126,7 @@ static void run_some_timers() { // waiter so that the next deadline is not missed if (!g_has_timed_waiter) { if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "kick untimed waiter"); + LOG(INFO) << "kick untimed waiter"; } gpr_cv_signal(&g_cv_wait); } @@ -133,7 +134,7 @@ static void run_some_timers() { } // without our lock, flush the exec_ctx if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "flush exec_ctx"); + LOG(INFO) << "flush exec_ctx"; } grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&g_mu); @@ -199,7 +200,7 @@ static bool wait_until(grpc_core::Timestamp next) { if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace) && next == grpc_core::Timestamp::InfFuture()) { - gpr_log(GPR_INFO, "sleep until kicked"); + LOG(INFO) << "sleep until kicked"; } gpr_cv_wait(&g_cv_wait, &g_mu, next.as_timespec(GPR_CLOCK_MONOTONIC)); @@ -251,7 +252,7 @@ static void timer_main_loop() { // Consequently, we can just sleep forever here and be happy at some // saved wakeup cycles. if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "timers not checked: expect another thread to"); + LOG(INFO) << "timers not checked: expect another thread to"; } next = grpc_core::Timestamp::InfFuture(); ABSL_FALLTHROUGH_INTENDED; @@ -277,7 +278,7 @@ static void timer_thread_cleanup(completed_thread* ct) { g_completed_threads = ct; gpr_mu_unlock(&g_mu); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "End timer thread"); + LOG(INFO) << "End timer thread"; } } @@ -318,18 +319,18 @@ void grpc_timer_manager_init(void) { static void stop_threads(void) { gpr_mu_lock(&g_mu); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "stop timer threads: threaded=%d", g_threaded); + LOG(INFO) << "stop timer threads: threaded=" << g_threaded; } if (g_threaded) { g_threaded = false; gpr_cv_broadcast(&g_cv_wait); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "num timer threads: %d", g_thread_count); + LOG(INFO) << "num timer threads: " << g_thread_count; } while (g_thread_count > 0) { gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "num timer threads: %d", g_thread_count); + LOG(INFO) << "num timer threads: " << g_thread_count; } gc_completed_threads(); } From 841af82bbadcff28ff912dc66e30d89a6f7ec4d9 Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap Date: Thu, 16 May 2024 08:29:22 -0700 Subject: [PATCH 09/23] [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. PiperOrigin-RevId: 634405948 --- .../security/authorization/evaluate_args.cc | 3 ++- .../lib/security/context/security_context.cc | 3 ++- .../credentials/alts/check_gcp_environment.cc | 4 +++- .../security/credentials/call_creds_util.cc | 3 ++- .../google_default_credentials.cc | 3 ++- .../security/credentials/jwt/json_token.cc | 19 ++++++++++--------- .../credentials/jwt/jwt_credentials.cc | 3 ++- .../credentials/oauth2/oauth2_credentials.cc | 15 ++++++++------- .../credentials/plugin/plugin_credentials.cc | 3 ++- .../credentials/ssl/ssl_credentials.cc | 9 +++++---- .../tls/grpc_tls_credentials_options.cc | 3 ++- .../credentials/tls/tls_credentials.cc | 9 +++++---- .../load_system_roots_supported.cc | 6 ++++-- .../ssl/ssl_security_connector.cc | 3 ++- .../security/security_connector/ssl_utils.cc | 15 ++++++++------- .../tls/tls_security_connector.cc | 5 +++-- 16 files changed, 62 insertions(+), 44 deletions(-) diff --git a/src/core/lib/security/authorization/evaluate_args.cc b/src/core/lib/security/authorization/evaluate_args.cc index ce4e8c2947a..8da1bd7eeb3 100644 --- a/src/core/lib/security/authorization/evaluate_args.cc +++ b/src/core/lib/security/authorization/evaluate_args.cc @@ -16,6 +16,7 @@ #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/match.h" @@ -41,7 +42,7 @@ EvaluateArgs::PerChannelArgs::Address ParseEndpointUri( EvaluateArgs::PerChannelArgs::Address address; absl::StatusOr uri = URI::Parse(uri_text); if (!uri.ok()) { - gpr_log(GPR_DEBUG, "Failed to parse uri."); + VLOG(2) << "Failed to parse uri."; return address; } absl::string_view host_view; diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index cac14517afc..0fc65da3f42 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -23,6 +23,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -52,7 +53,7 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call, GRPC_API_TRACE("grpc_call_set_credentials(call=%p, creds=%p)", 2, (call, creds)); if (!grpc_call_is_client(call)) { - gpr_log(GPR_ERROR, "Method is client-side only."); + LOG(ERROR) << "Method is client-side only."; return GRPC_CALL_ERROR_NOT_ON_SERVER; } ctx = static_cast( diff --git a/src/core/lib/security/credentials/alts/check_gcp_environment.cc b/src/core/lib/security/credentials/alts/check_gcp_environment.cc index 3c98988a48e..ff7ce1e33bf 100644 --- a/src/core/lib/security/credentials/alts/check_gcp_environment.cc +++ b/src/core/lib/security/credentials/alts/check_gcp_environment.cc @@ -22,6 +22,8 @@ #include #include +#include "absl/log/log.h" + #include #include #include @@ -56,7 +58,7 @@ namespace internal { char* read_bios_file(const char* bios_file) { FILE* fp = fopen(bios_file, "r"); if (!fp) { - gpr_log(GPR_INFO, "BIOS data file does not exist or cannot be opened."); + LOG(INFO) << "BIOS data file does not exist or cannot be opened."; return nullptr; } char buf[kBiosDataBufferSize + 1]; diff --git a/src/core/lib/security/credentials/call_creds_util.cc b/src/core/lib/security/credentials/call_creds_util.cc index e946bd64716..c49dd918ab5 100644 --- a/src/core/lib/security/credentials/call_creds_util.cc +++ b/src/core/lib/security/credentials/call_creds_util.cc @@ -18,6 +18,7 @@ #include +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -47,7 +48,7 @@ ServiceUrlAndMethod MakeServiceUrlAndMethod( auto last_slash = service.find_last_of('/'); absl::string_view method_name; if (last_slash == absl::string_view::npos) { - gpr_log(GPR_ERROR, "No '/' found in fully qualified method name"); + LOG(ERROR) << "No '/' found in fully qualified method name"; service = ""; method_name = ""; } else if (last_slash == 0) { diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc index b3515b33f11..17455936444 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/strings/match.h" #include "absl/strings/string_view.h" @@ -137,7 +138,7 @@ grpc_google_default_channel_credentials::create_security_connector( is_xds_non_cfe_cluster; // Return failure if ALTS is selected but not running on GCE. if (use_alts && alts_creds_ == nullptr) { - gpr_log(GPR_ERROR, "ALTS is selected, but not running on GCE."); + LOG(ERROR) << "ALTS is selected, but not running on GCE."; return nullptr; } grpc_core::RefCountedPtr sc = diff --git a/src/core/lib/security/credentials/jwt/json_token.cc b/src/core/lib/security/credentials/jwt/json_token.cc index 21bd06fd61b..2f1c5c35fc4 100644 --- a/src/core/lib/security/credentials/jwt/json_token.cc +++ b/src/core/lib/security/credentials/jwt/json_token.cc @@ -30,6 +30,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/escaping.h" @@ -86,7 +87,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const Json& json) { memset(&result, 0, sizeof(grpc_auth_json_key)); result.type = GRPC_AUTH_JSON_TYPE_INVALID; if (json.type() == Json::Type::kNull) { - gpr_log(GPR_ERROR, "Invalid json."); + LOG(ERROR) << "Invalid json."; goto end; } @@ -114,7 +115,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const Json& json) { bio = BIO_new(BIO_s_mem()); success = BIO_puts(bio, prop_value); if ((success < 0) || (static_cast(success) != strlen(prop_value))) { - gpr_log(GPR_ERROR, "Could not write into openssl BIO."); + LOG(ERROR) << "Could not write into openssl BIO."; goto end; } #if OPENSSL_VERSION_NUMBER < 0x30000000L @@ -124,7 +125,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const Json& json) { result.private_key = PEM_read_bio_PrivateKey(bio, nullptr, nullptr, nullptr); #endif if (result.private_key == nullptr) { - gpr_log(GPR_ERROR, "Could not deserialize private key."); + LOG(ERROR) << "Could not deserialize private key."; goto end; } success = 1; @@ -191,7 +192,7 @@ static char* encoded_jwt_claim(const grpc_auth_json_key* json_key, gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec expiration = gpr_time_add(now, token_lifetime); if (gpr_time_cmp(token_lifetime, grpc_max_auth_token_lifetime()) > 0) { - gpr_log(GPR_INFO, "Cropping token lifetime to maximum allowed value."); + LOG(INFO) << "Cropping token lifetime to maximum allowed value."; expiration = gpr_time_add(now, grpc_max_auth_token_lifetime()); } @@ -256,7 +257,7 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key, if (md == nullptr) return nullptr; md_ctx = EVP_MD_CTX_create(); if (md_ctx == nullptr) { - gpr_log(GPR_ERROR, "Could not create MD_CTX"); + LOG(ERROR) << "Could not create MD_CTX"; goto end; } #if OPENSSL_VERSION_NUMBER < 0x30000000L @@ -266,20 +267,20 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key, if (EVP_DigestSignInit(md_ctx, nullptr, md, nullptr, json_key->private_key) != 1) { #endif - gpr_log(GPR_ERROR, "DigestInit failed."); + LOG(ERROR) << "DigestInit failed."; goto end; } if (EVP_DigestSignUpdate(md_ctx, to_sign, strlen(to_sign)) != 1) { - gpr_log(GPR_ERROR, "DigestUpdate failed."); + LOG(ERROR) << "DigestUpdate failed."; goto end; } if (EVP_DigestSignFinal(md_ctx, nullptr, &sig_len) != 1) { - gpr_log(GPR_ERROR, "DigestFinal (get signature length) failed."); + LOG(ERROR) << "DigestFinal (get signature length) failed."; goto end; } sig = static_cast(gpr_malloc(sig_len)); if (EVP_DigestSignFinal(md_ctx, sig, &sig_len) != 1) { - gpr_log(GPR_ERROR, "DigestFinal (signature compute) failed."); + LOG(ERROR) << "DigestFinal (signature compute) failed."; goto end; } result = diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.cc b/src/core/lib/security/credentials/jwt/jwt_credentials.cc index bb69678b8f0..b1ae58f2dea 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.cc +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.cc @@ -25,6 +25,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" @@ -134,7 +135,7 @@ grpc_core::RefCountedPtr grpc_service_account_jwt_access_credentials_create_from_auth_json_key( grpc_auth_json_key key, gpr_timespec token_lifetime) { if (!grpc_auth_json_key_is_valid(&key)) { - gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation"); + LOG(ERROR) << "Invalid input for jwt credentials creation"; return nullptr; } return grpc_core::MakeRefCounted( diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index 0c2862940db..63ecb7300e1 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -28,6 +28,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -86,7 +87,7 @@ grpc_auth_refresh_token grpc_auth_refresh_token_create_from_json( memset(&result, 0, sizeof(grpc_auth_refresh_token)); result.type = GRPC_AUTH_JSON_TYPE_INVALID; if (json.type() != Json::Type::kObject) { - gpr_log(GPR_ERROR, "Invalid json."); + LOG(ERROR) << "Invalid json."; goto end; } @@ -161,7 +162,7 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( grpc_credentials_status status = GRPC_CREDENTIALS_OK; if (response == nullptr) { - gpr_log(GPR_ERROR, "Received NULL response."); + LOG(ERROR) << "Received NULL response."; status = GRPC_CREDENTIALS_ERROR; goto end; } @@ -193,14 +194,14 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( goto end; } if (json->type() != Json::Type::kObject) { - gpr_log(GPR_ERROR, "Response should be a JSON object"); + LOG(ERROR) << "Response should be a JSON object"; status = GRPC_CREDENTIALS_ERROR; goto end; } it = json->object().find("access_token"); if (it == json->object().end() || it->second.type() != Json::Type::kString) { - gpr_log(GPR_ERROR, "Missing or invalid access_token in JSON."); + LOG(ERROR) << "Missing or invalid access_token in JSON."; status = GRPC_CREDENTIALS_ERROR; goto end; } @@ -208,7 +209,7 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( it = json->object().find("token_type"); if (it == json->object().end() || it->second.type() != Json::Type::kString) { - gpr_log(GPR_ERROR, "Missing or invalid token_type in JSON."); + LOG(ERROR) << "Missing or invalid token_type in JSON."; status = GRPC_CREDENTIALS_ERROR; goto end; } @@ -216,7 +217,7 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( it = json->object().find("expires_in"); if (it == json->object().end() || it->second.type() != Json::Type::kNumber) { - gpr_log(GPR_ERROR, "Missing or invalid expires_in in JSON."); + LOG(ERROR) << "Missing or invalid expires_in in JSON."; status = GRPC_CREDENTIALS_ERROR; goto end; } @@ -479,7 +480,7 @@ grpc_core::RefCountedPtr grpc_refresh_token_credentials_create_from_auth_refresh_token( grpc_auth_refresh_token refresh_token) { if (!grpc_auth_refresh_token_is_valid(&refresh_token)) { - gpr_log(GPR_ERROR, "Invalid input for refresh token credentials creation"); + LOG(ERROR) << "Invalid input for refresh token credentials creation"; return nullptr; } return grpc_core::MakeRefCounted( diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index be6ea721dee..f31b422a93f 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -22,6 +22,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -83,7 +84,7 @@ grpc_plugin_credentials::PendingRequest::ProcessPluginResult( !GRPC_LOG_IF_ERROR( "validate_metadata_from_plugin", grpc_validate_header_nonbin_value_is_legal(md[i].value))) { - gpr_log(GPR_ERROR, "Plugin added invalid metadata value."); + LOG(ERROR) << "Plugin added invalid metadata value."; seen_illegal_header = true; break; } diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.cc b/src/core/lib/security/credentials/ssl/ssl_credentials.cc index 1d178a35a22..9537ce1bb88 100644 --- a/src/core/lib/security/credentials/ssl/ssl_credentials.cc +++ b/src/core/lib/security/credentials/ssl/ssl_credentials.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/types/optional.h" #include @@ -54,7 +55,7 @@ grpc_ssl_credentials::grpc_ssl_credentials( const char* pem_root_certs = grpc_core::DefaultSslRootStore::GetPemRootCerts(); if (pem_root_certs == nullptr) { - gpr_log(GPR_ERROR, "Could not get default pem root certs."); + LOG(ERROR) << "Could not get default pem root certs."; } else { char* default_roots = gpr_strdup(pem_root_certs); config_.pem_root_certs = default_roots; @@ -378,7 +379,7 @@ grpc_ssl_server_credentials_create_options_using_config( grpc_ssl_server_certificate_config* config) { grpc_ssl_server_credentials_options* options = nullptr; if (config == nullptr) { - gpr_log(GPR_ERROR, "Certificate config must not be NULL."); + LOG(ERROR) << "Certificate config must not be NULL."; goto done; } options = static_cast( @@ -394,7 +395,7 @@ grpc_ssl_server_credentials_create_options_using_config_fetcher( grpc_ssl_client_certificate_request_type client_certificate_request, grpc_ssl_server_certificate_config_callback cb, void* user_data) { if (cb == nullptr) { - gpr_log(GPR_ERROR, "Invalid certificate config callback parameter."); + LOG(ERROR) << "Invalid certificate config callback parameter."; return nullptr; } @@ -466,7 +467,7 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_with_options( goto done; } else if (options->certificate_config_fetcher != nullptr && options->certificate_config_fetcher->cb == nullptr) { - gpr_log(GPR_ERROR, "Certificate config fetcher callback must not be NULL."); + LOG(ERROR) << "Certificate config fetcher callback must not be NULL."; goto done; } diff --git a/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc b/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc index 0b95cc01264..288b2debc00 100644 --- a/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +++ b/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -131,7 +132,7 @@ void grpc_tls_credentials_options_set_tls_session_key_log_file_path( gpr_log(GPR_INFO, "Enabling TLS session key logging with keys stored at: %s", path); } else { - gpr_log(GPR_INFO, "Disabling TLS session key logging"); + LOG(INFO) << "Disabling TLS session key logging"; } options->set_tls_session_key_log_file_path(path != nullptr ? path : ""); } diff --git a/src/core/lib/security/credentials/tls/tls_credentials.cc b/src/core/lib/security/credentials/tls/tls_credentials.cc index b62b3b352e5..de88b4dd342 100644 --- a/src/core/lib/security/credentials/tls/tls_credentials.cc +++ b/src/core/lib/security/credentials/tls/tls_credentials.cc @@ -22,6 +22,7 @@ #include #include +#include "absl/log/log.h" #include "absl/types/optional.h" #include @@ -42,22 +43,22 @@ namespace { bool CredentialOptionSanityCheck(grpc_tls_credentials_options* options, bool is_client) { if (options == nullptr) { - gpr_log(GPR_ERROR, "TLS credentials options is nullptr."); + LOG(ERROR) << "TLS credentials options is nullptr."; return false; } // In this case, there will be non-retriable handshake errors. if (options->min_tls_version() > options->max_tls_version()) { - gpr_log(GPR_ERROR, "TLS min version must not be higher than max version."); + LOG(ERROR) << "TLS min version must not be higher than max version."; grpc_tls_credentials_options_destroy(options); return false; } if (options->max_tls_version() > grpc_tls_version::TLS1_3) { - gpr_log(GPR_ERROR, "TLS max version must not be higher than v1.3."); + LOG(ERROR) << "TLS max version must not be higher than v1.3."; grpc_tls_credentials_options_destroy(options); return false; } if (options->min_tls_version() < grpc_tls_version::TLS1_2) { - gpr_log(GPR_ERROR, "TLS min version must not be lower than v1.2."); + LOG(ERROR) << "TLS min version must not be lower than v1.2."; grpc_tls_credentials_options_destroy(options); return false; } diff --git a/src/core/lib/security/security_connector/load_system_roots_supported.cc b/src/core/lib/security/security_connector/load_system_roots_supported.cc index 5df3eac642f..a7dd8610de5 100644 --- a/src/core/lib/security/security_connector/load_system_roots_supported.cc +++ b/src/core/lib/security/security_connector/load_system_roots_supported.cc @@ -32,6 +32,8 @@ #include #include +#include "absl/log/log.h" + #include #include @@ -110,7 +112,7 @@ grpc_slice CreateRootCertsBundle(const char* certs_directory) { if (stat_return == -1 || !S_ISREG(dir_entry_stat.st_mode)) { // no subdirectories. if (stat_return == -1) { - gpr_log(GPR_ERROR, "failed to get status for file: %s", file_data.path); + LOG(ERROR) << "failed to get status for file: " << file_data.path; } continue; } @@ -131,7 +133,7 @@ grpc_slice CreateRootCertsBundle(const char* certs_directory) { if (read_ret != -1) { bytes_read += read_ret; } else { - gpr_log(GPR_ERROR, "failed to read file: %s", roots_filenames[i].path); + LOG(ERROR) << "failed to read file: " << roots_filenames[i].path; } } } diff --git a/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc b/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc index c41c5521676..52ec0f39534 100644 --- a/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +++ b/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc @@ -25,6 +25,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -380,7 +381,7 @@ grpc_ssl_channel_security_connector_create( const char* overridden_target_name, tsi_ssl_client_handshaker_factory* client_factory) { if (config == nullptr || target_name == nullptr) { - gpr_log(GPR_ERROR, "An ssl channel needs a config and a target name."); + LOG(ERROR) << "An ssl channel needs a config and a target name."; return nullptr; } diff --git a/src/core/lib/security/security_connector/ssl_utils.cc b/src/core/lib/security/security_connector/ssl_utils.cc index 3c92255719f..1e69711bf33 100644 --- a/src/core/lib/security/security_connector/ssl_utils.cc +++ b/src/core/lib/security/security_connector/ssl_utils.cc @@ -26,6 +26,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" @@ -123,7 +124,7 @@ tsi_tls_version grpc_get_tsi_tls_version(grpc_tls_version tls_version) { case grpc_tls_version::TLS1_3: return tsi_tls_version::TSI_TLS1_3; default: - gpr_log(GPR_INFO, "Falling back to TLS 1.2."); + LOG(INFO) << "Falling back to TLS 1.2."; return tsi_tls_version::TSI_TLS1_2; } } @@ -180,7 +181,7 @@ absl::Status SslCheckCallHost(absl::string_view host, status = GRPC_SECURITY_OK; } if (status != GRPC_SECURITY_OK) { - gpr_log(GPR_ERROR, "call host does not match SSL server name"); + LOG(ERROR) << "call host does not match SSL server name"; grpc_shallow_peer_destruct(&peer); return absl::UnauthenticatedError( "call host does not match SSL server name"); @@ -232,16 +233,16 @@ static bool IsSpiffeId(absl::string_view uri) { return false; }; if (uri.size() > 2048) { - gpr_log(GPR_INFO, "Invalid SPIFFE ID: ID longer than 2048 bytes."); + LOG(INFO) << "Invalid SPIFFE ID: ID longer than 2048 bytes."; return false; } std::vector splits = absl::StrSplit(uri, '/'); if (splits.size() < 4 || splits[3].empty()) { - gpr_log(GPR_INFO, "Invalid SPIFFE ID: workload id is empty."); + LOG(INFO) << "Invalid SPIFFE ID: workload id is empty."; return false; } if (splits[2].size() > 255) { - gpr_log(GPR_INFO, "Invalid SPIFFE ID: domain longer than 255 characters."); + LOG(INFO) << "Invalid SPIFFE ID: domain longer than 255 characters."; return false; } return true; @@ -332,7 +333,7 @@ grpc_core::RefCountedPtr grpc_ssl_peer_to_auth_context( GRPC_PEER_SPIFFE_ID_PROPERTY_NAME, spiffe_data, spiffe_length); } else { - gpr_log(GPR_INFO, "Invalid SPIFFE ID: multiple URI SANs."); + LOG(INFO) << "Invalid SPIFFE ID: multiple URI SANs."; } } return ctx; @@ -425,7 +426,7 @@ grpc_security_status grpc_ssl_tsi_client_handshaker_factory_init( // Use default root certificates. root_certs = grpc_core::DefaultSslRootStore::GetPemRootCerts(); if (root_certs == nullptr) { - gpr_log(GPR_ERROR, "Could not get default pem root certs."); + LOG(ERROR) << "Could not get default pem root certs."; return GRPC_SECURITY_ERROR; } root_store = grpc_core::DefaultSslRootStore::GetRootStore(); diff --git a/src/core/lib/security/security_connector/tls/tls_security_connector.cc b/src/core/lib/security/security_connector/tls/tls_security_connector.cc index cf0668d80b9..e74d9ca2bc4 100644 --- a/src/core/lib/security/security_connector/tls/tls_security_connector.cc +++ b/src/core/lib/security/security_connector/tls/tls_security_connector.cc @@ -26,6 +26,7 @@ #include "absl/functional/bind_front.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -452,7 +453,7 @@ void TlsChannelSecurityConnector::TlsChannelCertificateWatcher:: if (root_ready && identity_ready) { if (security_connector_->UpdateHandshakerFactoryLocked() != GRPC_SECURITY_OK) { - gpr_log(GPR_ERROR, "Update handshaker factory failed."); + LOG(ERROR) << "Update handshaker factory failed."; } } } @@ -721,7 +722,7 @@ void TlsServerSecurityConnector::TlsServerCertificateWatcher:: (!root_being_watched && identity_being_watched && identity_has_value)) { if (security_connector_->UpdateHandshakerFactoryLocked() != GRPC_SECURITY_OK) { - gpr_log(GPR_ERROR, "Update handshaker factory failed."); + LOG(ERROR) << "Update handshaker factory failed."; } } } From 271b2f17e2e1d425566fd437a99fc2dc3ef0e6eb Mon Sep 17 00:00:00 2001 From: Terry Wilson Date: Thu, 16 May 2024 09:25:02 -0700 Subject: [PATCH 10/23] [interop] Add grpc-java 1.64.0 to client_matrix.py (#36627) Closes #36627 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36627 from temawi:client-matrix-java-1.64.0 3ac1c0b9c6714089a16e2d4c5b7d59c27ef7228a PiperOrigin-RevId: 634427373 --- tools/interop_matrix/client_matrix.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/interop_matrix/client_matrix.py b/tools/interop_matrix/client_matrix.py index ccaf83cc1e6..e5aad848f6c 100644 --- a/tools/interop_matrix/client_matrix.py +++ b/tools/interop_matrix/client_matrix.py @@ -442,6 +442,7 @@ LANG_RELEASE_MATRIX = { ("v1.60.1", ReleaseInfo()), ("v1.61.0", ReleaseInfo()), ("v1.63.0", ReleaseInfo()), + ("v1.64.0", ReleaseInfo()), ] ), "python": OrderedDict( From cac1f2727e6975d6bb7426898c97916faa91bdaa Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 16 May 2024 13:10:49 -0700 Subject: [PATCH 11/23] [channel trace test] fix Windows portability tests (#36643) This fixes breakage triggered by #36434. Changing the order of the data members in `TraceEvent` caused the total size of the structure to be different, which meant that the long string we were adding was enough to cause 3 events to be evicted instead of 2. b/339066599 Closes #36643 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36643 from markdroth:channel_trace_test_fix 94586faced27ac4e0af8fda685cd154afeae1ba7 PiperOrigin-RevId: 634505085 --- test/core/channelz/channel_trace_test.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/test/core/channelz/channel_trace_test.cc b/test/core/channelz/channel_trace_test.cc index 59adb4fefda..6f99e22b38c 100644 --- a/test/core/channelz/channel_trace_test.cc +++ b/test/core/channelz/channel_trace_test.cc @@ -321,7 +321,7 @@ TEST(ChannelTracerTest, TestEviction) { TEST(ChannelTracerTest, TestMultipleEviction) { ExecCtx exec_ctx; - const int kTraceEventSize = GetSizeofTraceEvent(); + const size_t kTraceEventSize = GetSizeofTraceEvent(); const int kNumEvents = 5; ChannelTrace tracer(kTraceEventSize * kNumEvents); std::list<::testing::Matcher> matchers; @@ -337,14 +337,12 @@ TEST(ChannelTracerTest, TestMultipleEviction) { // At this point the list is full, and each subsequent enntry will cause an // eviction. We will now add in a trace event that has a copied string. This // uses more memory, so it will cause a double eviciction. - tracer.AddTraceEvent( - ChannelTrace::Severity::Info, - grpc_slice_from_copied_string( - "long enough string to trigger a multiple eviction")); + std::string msg(GRPC_SLICE_INLINED_SIZE + 1, 'x'); + tracer.AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_cpp_string(msg)); matchers.pop_front(); matchers.pop_front(); - matchers.push_back(IsTraceEvent( - "long enough string to trigger a multiple eviction", "CT_INFO")); + matchers.push_back(IsTraceEvent(msg, "CT_INFO")); Json json = tracer.RenderJson(); ValidateJsonProtoTranslation(json); EXPECT_THAT(json, IsChannelTrace(kNumEvents + 1, From f00dfb0f786a1483051a185e41321b9e21bb1f26 Mon Sep 17 00:00:00 2001 From: gRPC Team Bot Date: Thu, 16 May 2024 14:28:46 -0700 Subject: [PATCH 12/23] Automated rollback of commit bb201db996dc01209013ee18dd561894983adedd. PiperOrigin-RevId: 634530149 --- src/core/lib/event_engine/ares_resolver.cc | 5 ++--- .../lib/event_engine/posix_engine/ev_epoll1_linux.cc | 9 ++++----- src/core/lib/event_engine/posix_engine/posix_endpoint.cc | 7 +++---- src/core/lib/event_engine/posix_engine/posix_endpoint.h | 3 +-- src/core/lib/event_engine/posix_engine/posix_engine.cc | 3 +-- .../posix_engine/posix_engine_listener_utils.cc | 5 ++--- .../lib/event_engine/posix_engine/tcp_socket_utils.cc | 5 ++--- .../lib/event_engine/posix_engine/traced_buffer_list.cc | 3 +-- .../thread_pool/work_stealing_thread_pool.cc | 5 ++--- 9 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/core/lib/event_engine/ares_resolver.cc b/src/core/lib/event_engine/ares_resolver.cc index 58df73794b9..4273616642c 100644 --- a/src/core/lib/event_engine/ares_resolver.cc +++ b/src/core/lib/event_engine/ares_resolver.cc @@ -53,7 +53,6 @@ #include "absl/functional/any_invocable.h" #include "absl/hash/hash.h" #include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/strings/match.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" @@ -201,7 +200,7 @@ AresResolver::CreateAresResolver( ares_channel channel; int status = ares_init_options(&channel, &opts, ARES_OPT_FLAGS); if (status != ARES_SUCCESS) { - LOG(ERROR) << "ares_init_options failed, status: " << status; + gpr_log(GPR_ERROR, "ares_init_options failed, status: %d", status); return AresStatusToAbslStatus( status, absl::StrCat("Failed to init c-ares channel: ", ares_strerror(status))); @@ -770,7 +769,7 @@ void AresResolver::OnTXTDoneLocked(void* arg, int status, int /*timeouts*/, result.size()); if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_ares_resolver)) { for (const auto& record : result) { - LOG(INFO) << record; + gpr_log(GPR_INFO, "%s", record.c_str()); } } // Clean up. diff --git a/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc b/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc index bf9c82367fb..a1fffc0a7f9 100644 --- a/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +++ b/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc @@ -19,7 +19,6 @@ #include #include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" @@ -165,14 +164,14 @@ int EpollCreateAndCloexec() { #ifdef GRPC_LINUX_EPOLL_CREATE1 int fd = epoll_create1(EPOLL_CLOEXEC); if (fd < 0) { - LOG(ERROR) << "epoll_create1 unavailable"; + gpr_log(GPR_ERROR, "epoll_create1 unavailable"); } #else int fd = epoll_create(MAX_EPOLL_EVENTS); if (fd < 0) { - LOG(ERROR) << "epoll_create unavailable"; + gpr_log(GPR_ERROR, "epoll_create unavailable"); } else if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { - LOG(ERROR) << "fcntl following epoll_create failed"; + gpr_log(GPR_ERROR, "fcntl following epoll_create failed"); return -1; } #endif @@ -357,7 +356,7 @@ Epoll1Poller::Epoll1Poller(Scheduler* scheduler) wakeup_fd_ = *CreateWakeupFd(); CHECK(wakeup_fd_ != nullptr); CHECK_GE(g_epoll_set_.epfd, 0); - LOG(INFO) << "grpc epoll fd: " << g_epoll_set_.epfd; + gpr_log(GPR_INFO, "grpc epoll fd: %d", g_epoll_set_.epfd); struct epoll_event ev; ev.events = static_cast(EPOLLIN | EPOLLET); ev.data.ptr = wakeup_fd_.get(); diff --git a/src/core/lib/event_engine/posix_engine/posix_endpoint.cc b/src/core/lib/event_engine/posix_engine/posix_endpoint.cc index 18d7dfb4623..7c8dd72052a 100644 --- a/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +++ b/src/core/lib/event_engine/posix_engine/posix_endpoint.cc @@ -27,7 +27,6 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" @@ -719,7 +718,7 @@ bool PosixEndpointImpl::ProcessErrors() { return processed_err; } if (GPR_UNLIKELY((msg.msg_flags & MSG_CTRUNC) != 0)) { - LOG(ERROR) << "Error message was truncated."; + gpr_log(GPR_ERROR, "Error message was truncated."); } if (msg.msg_controllen == 0) { @@ -814,7 +813,7 @@ struct cmsghdr* PosixEndpointImpl::ProcessTimestamp(msghdr* msg, auto serr = reinterpret_cast(CMSG_DATA(next_cmsg)); if (serr->ee_errno != ENOMSG || serr->ee_origin != SO_EE_ORIGIN_TIMESTAMPING) { - LOG(ERROR) << "Unexpected control message"; + gpr_log(GPR_ERROR, "Unexpected control message"); return cmsg; } traced_buffers_.ProcessTimestamp(serr, opt_stats, tss); @@ -1304,7 +1303,7 @@ PosixEndpointImpl::PosixEndpointImpl(EventHandle* handle, if (setsockopt(fd_, SOL_SOCKET, SO_ZEROCOPY, &enable, sizeof(enable)) != 0) { zerocopy_enabled = false; - LOG(ERROR) << "Failed to set zerocopy options on the socket."; + gpr_log(GPR_ERROR, "Failed to set zerocopy options on the socket."); } } diff --git a/src/core/lib/event_engine/posix_engine/posix_endpoint.h b/src/core/lib/event_engine/posix_engine/posix_endpoint.h index 9a0ca6b8db4..c85c81e1eb1 100644 --- a/src/core/lib/event_engine/posix_engine/posix_endpoint.h +++ b/src/core/lib/event_engine/posix_engine/posix_endpoint.h @@ -30,7 +30,6 @@ #include "absl/functional/any_invocable.h" #include "absl/hash/hash.h" #include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -184,7 +183,7 @@ class TcpZerocopySendCtx { if (send_records_ == nullptr || free_send_records_ == nullptr) { gpr_free(send_records_); gpr_free(free_send_records_); - LOG(INFO) << "Disabling TCP TX zerocopy due to memory pressure.\n"; + gpr_log(GPR_INFO, "Disabling TCP TX zerocopy due to memory pressure.\n"); memory_limited_ = true; enabled_ = false; } else { diff --git a/src/core/lib/event_engine/posix_engine/posix_engine.cc b/src/core/lib/event_engine/posix_engine/posix_engine.cc index f5c1bf6c3d2..189866faa73 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine.cc +++ b/src/core/lib/event_engine/posix_engine/posix_engine.cc @@ -26,7 +26,6 @@ #include "absl/cleanup/cleanup.h" #include "absl/functional/any_invocable.h" #include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -232,7 +231,7 @@ void AsyncConnect::OnWritable(absl::Status status) // your program or another program on the same computer // opened too many network connections. The "easy" fix: // don't do that! - LOG(ERROR) << "kernel out of buffers"; + gpr_log(GPR_ERROR, "kernel out of buffers"); mu_.Unlock(); fd->NotifyOnWrite(on_writable_); // Don't run the cleanup function for this case. diff --git a/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc b/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc index ebcbec1771b..cbd8902d325 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc +++ b/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc @@ -23,7 +23,6 @@ #include "absl/cleanup/cleanup.h" #include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_replace.h" @@ -157,7 +156,7 @@ absl::Status PrepareSocket(const PosixTcpOptions& options, #ifdef GRPC_LINUX_ERRQUEUE if (!socket.sock.SetSocketZeroCopy().ok()) { // it's not fatal, so just log it. - VLOG(2) << "Node does not support SO_ZEROCOPY, continuing."; + gpr_log(GPR_DEBUG, "Node does not support SO_ZEROCOPY, continuing."); } else { socket.zero_copy_enabled = true; } @@ -245,7 +244,7 @@ absl::StatusOr ListenerContainerAddAllLocalAddresses( auto result = GetUnusedPort(); GRPC_RETURN_IF_ERROR(result.status()); requested_port = *result; - VLOG(2) << "Picked unused port " << requested_port; + gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port); } if (getifaddrs(&ifa) != 0 || ifa == nullptr) { return absl::FailedPreconditionError( diff --git a/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc b/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc index 987a010084c..d2cf5f6f426 100644 --- a/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +++ b/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc @@ -18,7 +18,6 @@ #include #include "absl/cleanup/cleanup.h" -#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/types/optional.h" @@ -654,7 +653,7 @@ void PosixSocketWrapper::TrySetSocketTcpUserTimeout( } if (newval != timeout) { // Do not fail on failing to set TCP_USER_TIMEOUT - LOG(ERROR) << "Failed to set TCP_USER_TIMEOUT"; + gpr_log(GPR_ERROR, "Failed to set TCP_USER_TIMEOUT"); return; } } @@ -685,7 +684,7 @@ bool PosixSocketWrapper::IsIpv6LoopbackAvailable() { int fd = socket(AF_INET6, SOCK_STREAM, 0); bool loopback_available = false; if (fd < 0) { - LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed."; + gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed."); } else { sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); diff --git a/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc b/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc index 1171cb76624..314e451c664 100644 --- a/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc +++ b/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc @@ -22,7 +22,6 @@ #include #include "absl/functional/any_invocable.h" -#include "absl/log/log.h" #include #include @@ -49,7 +48,7 @@ void FillGprFromTimestamp(gpr_timespec* gts, const struct timespec* ts) { void DefaultTimestampsCallback(void* /*arg*/, Timestamps* /*ts*/, absl::Status /*shudown_err*/) { - VLOG(2) << "Timestamps callback has not been registered"; + gpr_log(GPR_DEBUG, "Timestamps callback has not been registered"); } // The saved callback function that will be invoked when we get all the diff --git a/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc b/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc index f22f9484d32..eeaed8abb3c 100644 --- a/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc +++ b/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc @@ -27,7 +27,6 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/time/clock.h" #include "absl/time/time.h" #include "absl/types/optional.h" @@ -268,7 +267,7 @@ void WorkStealingThreadPool::WorkStealingThreadPoolImpl::StartThread() { } void WorkStealingThreadPool::WorkStealingThreadPoolImpl::Quiesce() { - LOG(INFO) << "WorkStealingThreadPoolImpl::Quiesce"; + gpr_log(GPR_INFO, "WorkStealingThreadPoolImpl::Quiesce"); SetShutdown(true); // Wait until all threads have exited. // Note that if this is a threadpool thread then we won't exit this thread @@ -320,7 +319,7 @@ bool WorkStealingThreadPool::WorkStealingThreadPoolImpl::IsQuiesced() { } void WorkStealingThreadPool::WorkStealingThreadPoolImpl::PrepareFork() { - LOG(INFO) << "WorkStealingThreadPoolImpl::PrepareFork"; + gpr_log(GPR_INFO, "WorkStealingThreadPoolImpl::PrepareFork"); SetForking(true); work_signal_.SignalAll(); auto threads_were_shut_down = living_thread_count_.BlockUntilThreadCount( From 841dfc097d6c6fdf9bb114923d68a888ccaec030 Mon Sep 17 00:00:00 2001 From: Vignesh Babu Date: Thu, 16 May 2024 15:59:33 -0700 Subject: [PATCH 13/23] Automated rollback of commit 2d2d5a3c411a2bade319a08085e55821cf2d5ed9. PiperOrigin-RevId: 634556450 --- src/core/lib/iomgr/buffer_list.cc | 6 ++---- src/core/lib/iomgr/call_combiner.cc | 11 +++++------ src/core/lib/iomgr/ev_epoll1_linux.cc | 4 ++-- src/core/lib/iomgr/ev_poll_posix.cc | 7 +++---- src/core/lib/iomgr/ev_posix.cc | 3 +-- .../lib/iomgr/event_engine_shims/endpoint.cc | 5 ++--- src/core/lib/iomgr/fork_windows.cc | 4 +--- src/core/lib/iomgr/internal_errqueue.cc | 6 ++---- src/core/lib/iomgr/iocp_windows.cc | 3 +-- .../lib/iomgr/socket_utils_common_posix.cc | 5 ++--- src/core/lib/iomgr/socket_windows.cc | 3 +-- src/core/lib/iomgr/tcp_client_posix.cc | 3 +-- src/core/lib/iomgr/tcp_posix.cc | 8 ++++---- .../iomgr/tcp_server_utils_posix_common.cc | 3 +-- .../iomgr/tcp_server_utils_posix_ifaddrs.cc | 3 +-- src/core/lib/iomgr/tcp_server_windows.cc | 7 +++---- src/core/lib/iomgr/timer_manager.cc | 19 +++++++++---------- 17 files changed, 41 insertions(+), 59 deletions(-) diff --git a/src/core/lib/iomgr/buffer_list.cc b/src/core/lib/iomgr/buffer_list.cc index aedb4227073..6de9d89c05b 100644 --- a/src/core/lib/iomgr/buffer_list.cc +++ b/src/core/lib/iomgr/buffer_list.cc @@ -18,8 +18,6 @@ #include "src/core/lib/iomgr/buffer_list.h" -#include "absl/log/log.h" - #include #include #include @@ -44,7 +42,7 @@ void FillGprFromTimestamp(gpr_timespec* gts, const struct timespec* ts) { void DefaultTimestampsCallback(void* /*arg*/, Timestamps* /*ts*/, absl::Status /*shudown_err*/) { - VLOG(2) << "Timestamps callback has not been registered"; + gpr_log(GPR_DEBUG, "Timestamps callback has not been registered"); } // The saved callback function that will be invoked when we get all the @@ -323,7 +321,7 @@ void grpc_tcp_set_write_timestamps_callback( // Can't comment out the name because some compilers and formatters don't // like the sequence */* , which would arise from */*fn*/. (void)fn; - VLOG(2) << "Timestamps callback is not enabled for this platform"; + gpr_log(GPR_DEBUG, "Timestamps callback is not enabled for this platform"); } } // namespace grpc_core diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc index c6fb49cea1a..6c44bdb0650 100644 --- a/src/core/lib/iomgr/call_combiner.cc +++ b/src/core/lib/iomgr/call_combiner.cc @@ -21,7 +21,6 @@ #include #include "absl/log/check.h" -#include "absl/log/log.h" #include #include @@ -131,13 +130,13 @@ void CallCombiner::Start(grpc_closure* closure, grpc_error_handle error, } if (prev_size == 0) { if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - LOG(INFO) << " EXECUTING IMMEDIATELY"; + gpr_log(GPR_INFO, " EXECUTING IMMEDIATELY"); } // Queue was empty, so execute this closure immediately. ScheduleClosure(closure, error); } else { if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - LOG(INFO) << " QUEUING"; + gpr_log(GPR_INFO, " QUEUING"); } // Queue was not empty, so add closure to queue. closure->error_data.error = internal::StatusAllocHeapPtr(error); @@ -161,7 +160,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) { if (prev_size > 1) { while (true) { if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - LOG(INFO) << " checking queue"; + gpr_log(GPR_INFO, " checking queue"); } bool empty; grpc_closure* closure = @@ -170,7 +169,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) { // This can happen either due to a race condition within the mpscq // code or because of a race with Start(). if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - LOG(INFO) << " queue returned no result; checking again"; + gpr_log(GPR_INFO, " queue returned no result; checking again"); } continue; } @@ -185,7 +184,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) { break; } } else if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - LOG(INFO) << " queue empty"; + gpr_log(GPR_INFO, " queue empty"); } } diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index 3dc33746701..d40b20a93b7 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -122,7 +122,7 @@ static bool epoll_set_init() { return false; } - LOG(INFO) << "grpc epoll fd: " << g_epoll_set.epfd; + gpr_log(GPR_INFO, "grpc epoll fd: %d", g_epoll_set.epfd); gpr_atm_no_barrier_store(&g_epoll_set.num_events, 0); gpr_atm_no_barrier_store(&g_epoll_set.cursor, 0); return true; @@ -1073,7 +1073,7 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset, log.push_back(absl::StrFormat(" worker_kick_state=%s", kick_state_string(specific_worker->state))); } - VLOG(2) << absl::StrJoin(log, ""); + gpr_log(GPR_DEBUG, "%s", absl::StrJoin(log, "").c_str()); } if (specific_worker == nullptr) { diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index 7d290d7d83e..0752fd61657 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -34,7 +34,6 @@ #include #include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -584,7 +583,7 @@ static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { static void fd_notify_on_error(grpc_fd* /*fd*/, grpc_closure* closure) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - LOG(ERROR) << "Polling engine does not support tracking errors."; + gpr_log(GPR_ERROR, "Polling engine does not support tracking errors."); } grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, absl::CancelledError()); } @@ -603,7 +602,7 @@ static void fd_set_writable(grpc_fd* fd) { static void fd_set_error(grpc_fd* /*fd*/) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - LOG(ERROR) << "Polling engine does not support tracking errors."; + gpr_log(GPR_ERROR, "Polling engine does not support tracking errors."); } } @@ -1398,7 +1397,7 @@ const grpc_event_engine_vtable grpc_ev_poll_posix = { // check_engine_available = [](bool) { if (!grpc_has_wakeup_fd()) { - LOG(ERROR) << "Skipping poll because of no wakeup fd."; + gpr_log(GPR_ERROR, "Skipping poll because of no wakeup fd."); return false; } if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) { diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index e204b4a697b..3456a87c482 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -25,7 +25,6 @@ #include -#include "absl/log/log.h" #include "absl/strings/str_format.h" #include "absl/strings/str_split.h" @@ -110,7 +109,7 @@ static void try_engine(absl::string_view engine) { if (g_vtables[i] != nullptr && is(engine, g_vtables[i]->name) && g_vtables[i]->check_engine_available(engine == g_vtables[i]->name)) { g_event_engine = g_vtables[i]; - VLOG(2) << "Using polling engine: " << g_event_engine->name; + gpr_log(GPR_DEBUG, "Using polling engine: %s", g_event_engine->name); return; } } diff --git a/src/core/lib/iomgr/event_engine_shims/endpoint.cc b/src/core/lib/iomgr/event_engine_shims/endpoint.cc index 42238e47062..dc0019efc12 100644 --- a/src/core/lib/iomgr/event_engine_shims/endpoint.cc +++ b/src/core/lib/iomgr/event_engine_shims/endpoint.cc @@ -19,7 +19,6 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" @@ -129,7 +128,7 @@ class EventEngineEndpointWrapper { for (i = 0; i < pending_read_buffer_->count; i++) { char* dump = grpc_dump_slice(pending_read_buffer_->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - VLOG(2) << "READ DATA: " << dump; + gpr_log(GPR_DEBUG, "READ DATA: %s", dump); gpr_free(dump); } } @@ -160,7 +159,7 @@ class EventEngineEndpointWrapper { for (i = 0; i < slices->count; i++) { char* dump = grpc_dump_slice(slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - VLOG(2) << "WRITE DATA: " << dump; + gpr_log(GPR_DEBUG, "WRITE DATA: %s", dump); gpr_free(dump); } } diff --git a/src/core/lib/iomgr/fork_windows.cc b/src/core/lib/iomgr/fork_windows.cc index 0e1583173d3..d8e73ed87c4 100644 --- a/src/core/lib/iomgr/fork_windows.cc +++ b/src/core/lib/iomgr/fork_windows.cc @@ -22,8 +22,6 @@ #ifndef GRPC_POSIX_FORK -#include "absl/log/log.h" - #include #include @@ -32,7 +30,7 @@ // AROUND VERY SPECIFIC USE CASES. // -void grpc_prefork() { LOG(ERROR) << "Forking not supported on Windows"; } +void grpc_prefork() { gpr_log(GPR_ERROR, "Forking not supported on Windows"); } void grpc_postfork_parent() {} diff --git a/src/core/lib/iomgr/internal_errqueue.cc b/src/core/lib/iomgr/internal_errqueue.cc index 5223687a439..3167cb035de 100644 --- a/src/core/lib/iomgr/internal_errqueue.cc +++ b/src/core/lib/iomgr/internal_errqueue.cc @@ -14,8 +14,6 @@ #include "src/core/lib/iomgr/internal_errqueue.h" -#include "absl/log/log.h" - #include #include @@ -39,7 +37,7 @@ bool KernelSupportsErrqueue() { // least 4.0.0 struct utsname buffer; if (uname(&buffer) != 0) { - LOG(ERROR) << "uname: " << StrError(errno); + gpr_log(GPR_ERROR, "uname: %s", StrError(errno).c_str()); return false; } char* release = buffer.release; @@ -50,7 +48,7 @@ bool KernelSupportsErrqueue() { if (strtol(release, nullptr, 10) >= 4) { return true; } else { - VLOG(2) << "ERRQUEUE support not enabled"; + gpr_log(GPR_DEBUG, "ERRQUEUE support not enabled"); } #endif // GRPC_LINUX_ERRQUEUE return false; diff --git a/src/core/lib/iomgr/iocp_windows.cc b/src/core/lib/iomgr/iocp_windows.cc index a19c13ab7b6..0353aa7614a 100644 --- a/src/core/lib/iomgr/iocp_windows.cc +++ b/src/core/lib/iomgr/iocp_windows.cc @@ -27,7 +27,6 @@ #include #include "absl/log/check.h" -#include "absl/log/log.h" #include #include @@ -158,7 +157,7 @@ void grpc_iocp_add_socket(grpc_winsocket* socket) { (uintptr_t)socket, 0); if (!ret) { char* utf8_message = gpr_format_message(WSAGetLastError()); - LOG(ERROR) << "Unable to add socket to iocp: " << utf8_message; + gpr_log(GPR_ERROR, "Unable to add socket to iocp: %s", utf8_message); gpr_free(utf8_message); __debugbreak(); abort(); diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc index 7ebafa6897b..ce4d7a3566c 100644 --- a/src/core/lib/iomgr/socket_utils_common_posix.cc +++ b/src/core/lib/iomgr/socket_utils_common_posix.cc @@ -44,7 +44,6 @@ #include #include "absl/log/check.h" -#include "absl/log/log.h" #include #include @@ -412,7 +411,7 @@ grpc_error_handle grpc_set_socket_tcp_user_timeout( } } else { if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - LOG(INFO) << "TCP_USER_TIMEOUT not supported for this platform"; + gpr_log(GPR_INFO, "TCP_USER_TIMEOUT not supported for this platform"); } } return absl::OkStatus(); @@ -443,7 +442,7 @@ static void probe_ipv6_once(void) { int fd = socket(AF_INET6, SOCK_STREAM, 0); g_ipv6_loopback_available = 0; if (fd < 0) { - LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed."; + gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed."); } else { grpc_sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index 44e524c6829..fc2cdc97407 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -28,7 +28,6 @@ #include #include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/strings/str_format.h" #include @@ -218,7 +217,7 @@ static void probe_ipv6_once(void) { SOCKET s = socket(AF_INET6, SOCK_STREAM, 0); g_ipv6_loopback_available = 0; if (s == INVALID_SOCKET) { - LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed."; + gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed."); } else { grpc_sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index 8fb50f6754e..2e5e8fd6b8e 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -30,7 +30,6 @@ #include "absl/container/flat_hash_map.h" #include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -241,7 +240,7 @@ static void on_writable(void* acp, grpc_error_handle error) { // your program or another program on the same computer // opened too many network connections. The "easy" fix: // don't do that! - LOG(ERROR) << "kernel out of buffers"; + gpr_log(GPR_ERROR, "kernel out of buffers"); gpr_mu_unlock(&ac->mu); grpc_fd_notify_on_write(fd, &ac->write_closure); return; diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index 1f9f9817e04..07906b6889c 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -875,7 +875,7 @@ static void tcp_trace_read(grpc_tcp* tcp, grpc_error_handle error) for (i = 0; i < tcp->incoming_buffer->count; i++) { char* dump = grpc_dump_slice(tcp->incoming_buffer->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - VLOG(2) << "READ DATA: " << dump; + gpr_log(GPR_DEBUG, "READ DATA: %s", dump); gpr_free(dump); } } @@ -1853,7 +1853,7 @@ static void tcp_handle_write(void* arg /* grpc_tcp */, tcp->write_cb = nullptr; tcp->current_zerocopy_send = nullptr; if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - LOG(INFO) << "write: " << grpc_core::StatusToString(error); + gpr_log(GPR_INFO, "write: %s", grpc_core::StatusToString(error).c_str()); } // No need to take a ref on error since tcp_flush provides a ref. grpc_core::Closure::Run(DEBUG_LOCATION, cb, error); @@ -1877,7 +1877,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, if (gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) { char* data = grpc_dump_slice(buf->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - VLOG(2) << "WRITE DATA: " << data; + gpr_log(GPR_DEBUG, "WRITE DATA: %s", data); gpr_free(data); } } @@ -1921,7 +1921,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, notify_on_write(tcp); } else { if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - LOG(INFO) << "write: " << grpc_core::StatusToString(error); + gpr_log(GPR_INFO, "write: %s", grpc_core::StatusToString(error).c_str()); } grpc_core::Closure::Run(DEBUG_LOCATION, cb, error); } diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc index ee8f7350eb6..181ab5b8e25 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc @@ -32,7 +32,6 @@ #include #include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -222,7 +221,7 @@ grpc_error_handle grpc_tcp_server_prepare_socket( err = grpc_set_socket_zerocopy(fd); if (!err.ok()) { // it's not fatal, so just log it. - VLOG(2) << "Node does not support SO_ZEROCOPY, continuing."; + gpr_log(GPR_DEBUG, "Node does not support SO_ZEROCOPY, continuing."); } #endif err = grpc_set_socket_nonblocking(fd, 1); diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc index 495e800ea08..d04dddf8e46 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc @@ -31,7 +31,6 @@ #include #include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -116,7 +115,7 @@ grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, } else if (requested_port <= 0) { return GRPC_ERROR_CREATE("Bad get_unused_port()"); } - VLOG(2) << "Picked unused port " << requested_port; + gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port); } static bool v4_available = grpc_is_ipv4_availabile(); diff --git a/src/core/lib/iomgr/tcp_server_windows.cc b/src/core/lib/iomgr/tcp_server_windows.cc index b2a0ab25be8..70b4a6a5920 100644 --- a/src/core/lib/iomgr/tcp_server_windows.cc +++ b/src/core/lib/iomgr/tcp_server_windows.cc @@ -28,7 +28,6 @@ #include #include "absl/log/check.h" -#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -406,7 +405,7 @@ static void on_accept(void* arg, grpc_error_handle error) { if (!wsa_success) { if (!sp->shutting_down) { char* utf8_message = gpr_format_message(WSAGetLastError()); - LOG(ERROR) << "on_accept error: " << utf8_message; + gpr_log(GPR_ERROR, "on_accept error: %s", utf8_message); gpr_free(utf8_message); } closesocket(sock); @@ -416,7 +415,7 @@ static void on_accept(void* arg, grpc_error_handle error) { (char*)&sp->socket->socket, sizeof(sp->socket->socket)); if (err) { char* utf8_message = gpr_format_message(WSAGetLastError()); - LOG(ERROR) << "setsockopt error: " << utf8_message; + gpr_log(GPR_ERROR, "setsockopt error: %s", utf8_message); gpr_free(utf8_message); } int peer_name_len = (int)peer_name.len; @@ -433,7 +432,7 @@ static void on_accept(void* arg, grpc_error_handle error) { } } else { char* utf8_message = gpr_format_message(WSAGetLastError()); - LOG(ERROR) << "getpeername error: " << utf8_message; + gpr_log(GPR_ERROR, "getpeername error: %s", utf8_message); gpr_free(utf8_message); } std::string fd_name = absl::StrCat("tcp_server:", peer_name_string); diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 9cab02d2877..6e4197a8f83 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -21,7 +21,6 @@ #include #include "absl/log/check.h" -#include "absl/log/log.h" #include #include @@ -90,7 +89,7 @@ static void start_timer_thread_and_unlock(void) { ++g_thread_count; gpr_mu_unlock(&g_mu); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - LOG(INFO) << "Spawn timer thread"; + gpr_log(GPR_INFO, "Spawn timer thread"); } completed_thread* ct = static_cast(gpr_malloc(sizeof(*ct))); @@ -126,7 +125,7 @@ static void run_some_timers() { // waiter so that the next deadline is not missed if (!g_has_timed_waiter) { if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - LOG(INFO) << "kick untimed waiter"; + gpr_log(GPR_INFO, "kick untimed waiter"); } gpr_cv_signal(&g_cv_wait); } @@ -134,7 +133,7 @@ static void run_some_timers() { } // without our lock, flush the exec_ctx if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - LOG(INFO) << "flush exec_ctx"; + gpr_log(GPR_INFO, "flush exec_ctx"); } grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&g_mu); @@ -200,7 +199,7 @@ static bool wait_until(grpc_core::Timestamp next) { if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace) && next == grpc_core::Timestamp::InfFuture()) { - LOG(INFO) << "sleep until kicked"; + gpr_log(GPR_INFO, "sleep until kicked"); } gpr_cv_wait(&g_cv_wait, &g_mu, next.as_timespec(GPR_CLOCK_MONOTONIC)); @@ -252,7 +251,7 @@ static void timer_main_loop() { // Consequently, we can just sleep forever here and be happy at some // saved wakeup cycles. if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - LOG(INFO) << "timers not checked: expect another thread to"; + gpr_log(GPR_INFO, "timers not checked: expect another thread to"); } next = grpc_core::Timestamp::InfFuture(); ABSL_FALLTHROUGH_INTENDED; @@ -278,7 +277,7 @@ static void timer_thread_cleanup(completed_thread* ct) { g_completed_threads = ct; gpr_mu_unlock(&g_mu); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - LOG(INFO) << "End timer thread"; + gpr_log(GPR_INFO, "End timer thread"); } } @@ -319,18 +318,18 @@ void grpc_timer_manager_init(void) { static void stop_threads(void) { gpr_mu_lock(&g_mu); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - LOG(INFO) << "stop timer threads: threaded=" << g_threaded; + gpr_log(GPR_INFO, "stop timer threads: threaded=%d", g_threaded); } if (g_threaded) { g_threaded = false; gpr_cv_broadcast(&g_cv_wait); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - LOG(INFO) << "num timer threads: " << g_thread_count; + gpr_log(GPR_INFO, "num timer threads: %d", g_thread_count); } while (g_thread_count > 0) { gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - LOG(INFO) << "num timer threads: " << g_thread_count; + gpr_log(GPR_INFO, "num timer threads: %d", g_thread_count); } gc_completed_threads(); } From 3b20b1977883cf91046edb0173c731689e3052b4 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 16 May 2024 18:24:34 -0700 Subject: [PATCH 14/23] [reorg] move test/core/gpr -> test/core/util (#36641) Forgot to move these in #36543. Closes #36641 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36641 from markdroth:reorg_util_gpr_tests 6972b7ab1d3ea7c127d8389dfa3286a9bc25f377 PiperOrigin-RevId: 634592295 --- CMakeLists.txt | 102 +++++++++++------------ build_autogenerated.yaml | 38 ++++----- test/core/{gpr => util}/BUILD | 2 +- test/core/{gpr => util}/alloc_test.cc | 0 test/core/{gpr => util}/cpu_test.cc | 0 test/core/{gpr => util}/env_test.cc | 0 test/core/{gpr => util}/log_test.cc | 0 test/core/{gpr => util}/spinlock_test.cc | 0 test/core/{gpr => util}/string_test.cc | 0 test/core/{gpr => util}/sync_test.cc | 0 test/core/{gpr => util}/time_test.cc | 0 test/core/{gpr => util}/useful_test.cc | 0 tools/run_tests/generated/tests.json | 36 ++++---- 13 files changed, 89 insertions(+), 89 deletions(-) rename test/core/{gpr => util}/BUILD (98%) rename test/core/{gpr => util}/alloc_test.cc (100%) rename test/core/{gpr => util}/cpu_test.cc (100%) rename test/core/{gpr => util}/env_test.cc (100%) rename test/core/{gpr => util}/log_test.cc (100%) rename test/core/{gpr => util}/spinlock_test.cc (100%) rename test/core/{gpr => util}/string_test.cc (100%) rename test/core/{gpr => util}/sync_test.cc (100%) rename test/core/{gpr => util}/time_test.cc (100%) rename test/core/{gpr => util}/useful_test.cc (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7128fd2f552..d0172728836 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1458,7 +1458,6 @@ if(gRPC_BUILD_TESTS) add_dependencies(buildtests_cxx test_core_event_engine_posix_timer_heap_test) add_dependencies(buildtests_cxx test_core_event_engine_posix_timer_list_test) add_dependencies(buildtests_cxx test_core_event_engine_slice_buffer_test) - add_dependencies(buildtests_cxx test_core_gpr_time_test) add_dependencies(buildtests_cxx test_core_gprpp_time_test) add_dependencies(buildtests_cxx test_core_iomgr_timer_heap_test) add_dependencies(buildtests_cxx test_core_security_credentials_test) @@ -1468,6 +1467,7 @@ if(gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_cxx test_core_transport_test_suite_chaotic_good_test) endif() + add_dependencies(buildtests_cxx test_core_util_time_test) add_dependencies(buildtests_cxx test_cpp_client_credentials_test) add_dependencies(buildtests_cxx test_cpp_end2end_ssl_credentials_test) add_dependencies(buildtests_cxx test_cpp_ext_chaotic_good_test) @@ -6313,7 +6313,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(alloc_test - test/core/gpr/alloc_test.cc + test/core/util/alloc_test.cc ) if(WIN32 AND MSVC) if(BUILD_SHARED_LIBS) @@ -11722,7 +11722,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(cpu_test - test/core/gpr/cpu_test.cc + test/core/util/cpu_test.cc ) if(WIN32 AND MSVC) if(BUILD_SHARED_LIBS) @@ -12918,7 +12918,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(env_test - test/core/gpr/env_test.cc + test/core/util/env_test.cc ) if(WIN32 AND MSVC) if(BUILD_SHARED_LIBS) @@ -19118,7 +19118,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(log_test - test/core/gpr/log_test.cc + test/core/util/log_test.cc ) if(WIN32 AND MSVC) if(BUILD_SHARED_LIBS) @@ -28540,7 +28540,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(spinlock_test - test/core/gpr/spinlock_test.cc + test/core/util/spinlock_test.cc ) if(WIN32 AND MSVC) if(BUILD_SHARED_LIBS) @@ -29286,7 +29286,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(string_test - test/core/gpr/string_test.cc + test/core/util/string_test.cc ) if(WIN32 AND MSVC) if(BUILD_SHARED_LIBS) @@ -29371,7 +29371,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(sync_test - test/core/gpr/sync_test.cc + test/core/util/sync_test.cc ) if(WIN32 AND MSVC) if(BUILD_SHARED_LIBS) @@ -29998,48 +29998,6 @@ target_link_libraries(test_core_event_engine_slice_buffer_test ) -endif() -if(gRPC_BUILD_TESTS) - -add_executable(test_core_gpr_time_test - test/core/gpr/time_test.cc -) -if(WIN32 AND MSVC) - if(BUILD_SHARED_LIBS) - target_compile_definitions(test_core_gpr_time_test - PRIVATE - "GPR_DLL_IMPORTS" - "GRPC_DLL_IMPORTS" - ) - endif() -endif() -target_compile_features(test_core_gpr_time_test PUBLIC cxx_std_14) -target_include_directories(test_core_gpr_time_test - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} - ${_gRPC_RE2_INCLUDE_DIR} - ${_gRPC_SSL_INCLUDE_DIR} - ${_gRPC_UPB_GENERATED_DIR} - ${_gRPC_UPB_GRPC_GENERATED_DIR} - ${_gRPC_UPB_INCLUDE_DIR} - ${_gRPC_XXHASH_INCLUDE_DIR} - ${_gRPC_ZLIB_INCLUDE_DIR} - third_party/googletest/googletest/include - third_party/googletest/googletest - third_party/googletest/googlemock/include - third_party/googletest/googlemock - ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(test_core_gpr_time_test - ${_gRPC_ALLTARGETS_LIBRARIES} - gtest - grpc_test_util -) - - endif() if(gRPC_BUILD_TESTS) @@ -30387,6 +30345,48 @@ endif() endif() if(gRPC_BUILD_TESTS) +add_executable(test_core_util_time_test + test/core/util/time_test.cc +) +if(WIN32 AND MSVC) + if(BUILD_SHARED_LIBS) + target_compile_definitions(test_core_util_time_test + PRIVATE + "GPR_DLL_IMPORTS" + "GRPC_DLL_IMPORTS" + ) + endif() +endif() +target_compile_features(test_core_util_time_test PUBLIC cxx_std_14) +target_include_directories(test_core_util_time_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(test_core_util_time_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + grpc_test_util +) + + +endif() +if(gRPC_BUILD_TESTS) + add_executable(test_cpp_client_credentials_test test/cpp/client/credentials_test.cc test/cpp/util/tls_test_utils.cc @@ -32064,7 +32064,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(useful_test - test/core/gpr/useful_test.cc + test/core/util/useful_test.cc ) target_compile_features(useful_test PUBLIC cxx_std_14) target_include_directories(useful_test diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 70180718c9d..f72466229e9 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -5407,7 +5407,7 @@ targets: language: c++ headers: [] src: - - test/core/gpr/alloc_test.cc + - test/core/util/alloc_test.cc deps: - gtest - grpc_test_util @@ -8402,7 +8402,7 @@ targets: language: c++ headers: [] src: - - test/core/gpr/cpu_test.cc + - test/core/util/cpu_test.cc deps: - gtest - grpc_test_util @@ -8995,7 +8995,7 @@ targets: language: c++ headers: [] src: - - test/core/gpr/env_test.cc + - test/core/util/env_test.cc deps: - gtest - grpc_test_util @@ -12778,7 +12778,7 @@ targets: language: c++ headers: [] src: - - test/core/gpr/log_test.cc + - test/core/util/log_test.cc deps: - gtest - grpc_test_util @@ -18693,7 +18693,7 @@ targets: language: c++ headers: [] src: - - test/core/gpr/spinlock_test.cc + - test/core/util/spinlock_test.cc deps: - gtest - grpc_test_util @@ -18988,7 +18988,7 @@ targets: language: c++ headers: [] src: - - test/core/gpr/string_test.cc + - test/core/util/string_test.cc deps: - gtest - grpc_test_util @@ -19017,7 +19017,7 @@ targets: language: c++ headers: [] src: - - test/core/gpr/sync_test.cc + - test/core/util/sync_test.cc deps: - gtest - grpc_test_util @@ -19345,17 +19345,6 @@ targets: - absl/status:statusor - absl/utility:utility - gpr -- name: test_core_gpr_time_test - gtest: true - build: test - language: c++ - headers: [] - src: - - test/core/gpr/time_test.cc - deps: - - gtest - - grpc_test_util - uses_polling: false - name: test_core_gprpp_time_test gtest: true build: test @@ -19527,6 +19516,17 @@ targets: - linux - posix uses_polling: false +- name: test_core_util_time_test + gtest: true + build: test + language: c++ + headers: [] + src: + - test/core/util/time_test.cc + deps: + - gtest + - grpc_test_util + uses_polling: false - name: test_cpp_client_credentials_test gtest: true build: test @@ -20266,7 +20266,7 @@ targets: headers: - src/core/util/useful.h src: - - test/core/gpr/useful_test.cc + - test/core/util/useful_test.cc deps: - gtest uses_polling: false diff --git a/test/core/gpr/BUILD b/test/core/util/BUILD similarity index 98% rename from test/core/gpr/BUILD rename to test/core/util/BUILD index 381d592e30d..728ef6bd167 100644 --- a/test/core/gpr/BUILD +++ b/test/core/util/BUILD @@ -16,7 +16,7 @@ load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package") licenses(["notice"]) -grpc_package(name = "test/core/gpr") +grpc_package(name = "test/core/util") grpc_cc_test( name = "alloc_test", diff --git a/test/core/gpr/alloc_test.cc b/test/core/util/alloc_test.cc similarity index 100% rename from test/core/gpr/alloc_test.cc rename to test/core/util/alloc_test.cc diff --git a/test/core/gpr/cpu_test.cc b/test/core/util/cpu_test.cc similarity index 100% rename from test/core/gpr/cpu_test.cc rename to test/core/util/cpu_test.cc diff --git a/test/core/gpr/env_test.cc b/test/core/util/env_test.cc similarity index 100% rename from test/core/gpr/env_test.cc rename to test/core/util/env_test.cc diff --git a/test/core/gpr/log_test.cc b/test/core/util/log_test.cc similarity index 100% rename from test/core/gpr/log_test.cc rename to test/core/util/log_test.cc diff --git a/test/core/gpr/spinlock_test.cc b/test/core/util/spinlock_test.cc similarity index 100% rename from test/core/gpr/spinlock_test.cc rename to test/core/util/spinlock_test.cc diff --git a/test/core/gpr/string_test.cc b/test/core/util/string_test.cc similarity index 100% rename from test/core/gpr/string_test.cc rename to test/core/util/string_test.cc diff --git a/test/core/gpr/sync_test.cc b/test/core/util/sync_test.cc similarity index 100% rename from test/core/gpr/sync_test.cc rename to test/core/util/sync_test.cc diff --git a/test/core/gpr/time_test.cc b/test/core/util/time_test.cc similarity index 100% rename from test/core/gpr/time_test.cc rename to test/core/util/time_test.cc diff --git a/test/core/gpr/useful_test.cc b/test/core/util/useful_test.cc similarity index 100% rename from test/core/gpr/useful_test.cc rename to test/core/util/useful_test.cc diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index a733817a370..8dc1a7348a1 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -10406,7 +10406,7 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_gpr_time_test", + "name": "test_core_gprpp_time_test", "platforms": [ "linux", "mac", @@ -10430,7 +10430,7 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_gprpp_time_test", + "name": "test_core_iomgr_timer_heap_test", "platforms": [ "linux", "mac", @@ -10454,14 +10454,14 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_iomgr_timer_heap_test", + "name": "test_core_security_credentials_test", "platforms": [ "linux", "mac", "posix", "windows" ], - "uses_polling": false + "uses_polling": true }, { "args": [], @@ -10478,7 +10478,7 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_security_credentials_test", + "name": "test_core_security_ssl_credentials_test", "platforms": [ "linux", "mac", @@ -10502,14 +10502,14 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_security_ssl_credentials_test", + "name": "test_core_slice_slice_buffer_test", "platforms": [ "linux", "mac", "posix", "windows" ], - "uses_polling": true + "uses_polling": false }, { "args": [], @@ -10526,7 +10526,7 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_slice_slice_buffer_test", + "name": "test_core_slice_slice_test", "platforms": [ "linux", "mac", @@ -10540,9 +10540,7 @@ "benchmark": false, "ci_platforms": [ "linux", - "mac", - "posix", - "windows" + "posix" ], "cpu_cost": 1.0, "exclude_configs": [], @@ -10550,12 +10548,10 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_slice_slice_test", + "name": "test_core_transport_test_suite_chaotic_good_test", "platforms": [ "linux", - "mac", - "posix", - "windows" + "posix" ], "uses_polling": false }, @@ -10564,7 +10560,9 @@ "benchmark": false, "ci_platforms": [ "linux", - "posix" + "mac", + "posix", + "windows" ], "cpu_cost": 1.0, "exclude_configs": [], @@ -10572,10 +10570,12 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_transport_test_suite_chaotic_good_test", + "name": "test_core_util_time_test", "platforms": [ "linux", - "posix" + "mac", + "posix", + "windows" ], "uses_polling": false }, From 2b45675f2e2bd727ed7d21340226a4caf699882e Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap Date: Fri, 17 May 2024 01:40:28 -0700 Subject: [PATCH 15/23] Automated rollback of commit 841dfc097d6c6fdf9bb114923d68a888ccaec030. PiperOrigin-RevId: 634674389 --- src/core/lib/iomgr/buffer_list.cc | 6 ++++-- src/core/lib/iomgr/call_combiner.cc | 11 ++++++----- src/core/lib/iomgr/ev_poll_posix.cc | 7 ++++--- src/core/lib/iomgr/ev_posix.cc | 3 ++- .../lib/iomgr/event_engine_shims/endpoint.cc | 5 +++-- src/core/lib/iomgr/fork_windows.cc | 4 +++- src/core/lib/iomgr/internal_errqueue.cc | 6 ++++-- src/core/lib/iomgr/iocp_windows.cc | 3 ++- .../lib/iomgr/socket_utils_common_posix.cc | 5 +++-- src/core/lib/iomgr/socket_windows.cc | 3 ++- src/core/lib/iomgr/tcp_client_posix.cc | 3 ++- src/core/lib/iomgr/tcp_posix.cc | 8 ++++---- .../iomgr/tcp_server_utils_posix_common.cc | 3 ++- .../iomgr/tcp_server_utils_posix_ifaddrs.cc | 3 ++- src/core/lib/iomgr/tcp_server_windows.cc | 7 ++++--- src/core/lib/iomgr/timer_manager.cc | 19 ++++++++++--------- 16 files changed, 57 insertions(+), 39 deletions(-) diff --git a/src/core/lib/iomgr/buffer_list.cc b/src/core/lib/iomgr/buffer_list.cc index 6de9d89c05b..aedb4227073 100644 --- a/src/core/lib/iomgr/buffer_list.cc +++ b/src/core/lib/iomgr/buffer_list.cc @@ -18,6 +18,8 @@ #include "src/core/lib/iomgr/buffer_list.h" +#include "absl/log/log.h" + #include #include #include @@ -42,7 +44,7 @@ void FillGprFromTimestamp(gpr_timespec* gts, const struct timespec* ts) { void DefaultTimestampsCallback(void* /*arg*/, Timestamps* /*ts*/, absl::Status /*shudown_err*/) { - gpr_log(GPR_DEBUG, "Timestamps callback has not been registered"); + VLOG(2) << "Timestamps callback has not been registered"; } // The saved callback function that will be invoked when we get all the @@ -321,7 +323,7 @@ void grpc_tcp_set_write_timestamps_callback( // Can't comment out the name because some compilers and formatters don't // like the sequence */* , which would arise from */*fn*/. (void)fn; - gpr_log(GPR_DEBUG, "Timestamps callback is not enabled for this platform"); + VLOG(2) << "Timestamps callback is not enabled for this platform"; } } // namespace grpc_core diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc index 6c44bdb0650..c6fb49cea1a 100644 --- a/src/core/lib/iomgr/call_combiner.cc +++ b/src/core/lib/iomgr/call_combiner.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -130,13 +131,13 @@ void CallCombiner::Start(grpc_closure* closure, grpc_error_handle error, } if (prev_size == 0) { if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " EXECUTING IMMEDIATELY"); + LOG(INFO) << " EXECUTING IMMEDIATELY"; } // Queue was empty, so execute this closure immediately. ScheduleClosure(closure, error); } else { if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " QUEUING"); + LOG(INFO) << " QUEUING"; } // Queue was not empty, so add closure to queue. closure->error_data.error = internal::StatusAllocHeapPtr(error); @@ -160,7 +161,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) { if (prev_size > 1) { while (true) { if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " checking queue"); + LOG(INFO) << " checking queue"; } bool empty; grpc_closure* closure = @@ -169,7 +170,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) { // This can happen either due to a race condition within the mpscq // code or because of a race with Start(). if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " queue returned no result; checking again"); + LOG(INFO) << " queue returned no result; checking again"; } continue; } @@ -184,7 +185,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) { break; } } else if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " queue empty"); + LOG(INFO) << " queue empty"; } } diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index 0752fd61657..7d290d7d83e 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -34,6 +34,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -583,7 +584,7 @@ static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { static void fd_notify_on_error(grpc_fd* /*fd*/, grpc_closure* closure) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_ERROR, "Polling engine does not support tracking errors."); + LOG(ERROR) << "Polling engine does not support tracking errors."; } grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, absl::CancelledError()); } @@ -602,7 +603,7 @@ static void fd_set_writable(grpc_fd* fd) { static void fd_set_error(grpc_fd* /*fd*/) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_ERROR, "Polling engine does not support tracking errors."); + LOG(ERROR) << "Polling engine does not support tracking errors."; } } @@ -1397,7 +1398,7 @@ const grpc_event_engine_vtable grpc_ev_poll_posix = { // check_engine_available = [](bool) { if (!grpc_has_wakeup_fd()) { - gpr_log(GPR_ERROR, "Skipping poll because of no wakeup fd."); + LOG(ERROR) << "Skipping poll because of no wakeup fd."; return false; } if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) { diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index 3456a87c482..e204b4a697b 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -25,6 +25,7 @@ #include +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include "absl/strings/str_split.h" @@ -109,7 +110,7 @@ static void try_engine(absl::string_view engine) { if (g_vtables[i] != nullptr && is(engine, g_vtables[i]->name) && g_vtables[i]->check_engine_available(engine == g_vtables[i]->name)) { g_event_engine = g_vtables[i]; - gpr_log(GPR_DEBUG, "Using polling engine: %s", g_event_engine->name); + VLOG(2) << "Using polling engine: " << g_event_engine->name; return; } } diff --git a/src/core/lib/iomgr/event_engine_shims/endpoint.cc b/src/core/lib/iomgr/event_engine_shims/endpoint.cc index dc0019efc12..42238e47062 100644 --- a/src/core/lib/iomgr/event_engine_shims/endpoint.cc +++ b/src/core/lib/iomgr/event_engine_shims/endpoint.cc @@ -19,6 +19,7 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" @@ -128,7 +129,7 @@ class EventEngineEndpointWrapper { for (i = 0; i < pending_read_buffer_->count; i++) { char* dump = grpc_dump_slice(pending_read_buffer_->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "READ DATA: %s", dump); + VLOG(2) << "READ DATA: " << dump; gpr_free(dump); } } @@ -159,7 +160,7 @@ class EventEngineEndpointWrapper { for (i = 0; i < slices->count; i++) { char* dump = grpc_dump_slice(slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "WRITE DATA: %s", dump); + VLOG(2) << "WRITE DATA: " << dump; gpr_free(dump); } } diff --git a/src/core/lib/iomgr/fork_windows.cc b/src/core/lib/iomgr/fork_windows.cc index d8e73ed87c4..0e1583173d3 100644 --- a/src/core/lib/iomgr/fork_windows.cc +++ b/src/core/lib/iomgr/fork_windows.cc @@ -22,6 +22,8 @@ #ifndef GRPC_POSIX_FORK +#include "absl/log/log.h" + #include #include @@ -30,7 +32,7 @@ // AROUND VERY SPECIFIC USE CASES. // -void grpc_prefork() { gpr_log(GPR_ERROR, "Forking not supported on Windows"); } +void grpc_prefork() { LOG(ERROR) << "Forking not supported on Windows"; } void grpc_postfork_parent() {} diff --git a/src/core/lib/iomgr/internal_errqueue.cc b/src/core/lib/iomgr/internal_errqueue.cc index 3167cb035de..5223687a439 100644 --- a/src/core/lib/iomgr/internal_errqueue.cc +++ b/src/core/lib/iomgr/internal_errqueue.cc @@ -14,6 +14,8 @@ #include "src/core/lib/iomgr/internal_errqueue.h" +#include "absl/log/log.h" + #include #include @@ -37,7 +39,7 @@ bool KernelSupportsErrqueue() { // least 4.0.0 struct utsname buffer; if (uname(&buffer) != 0) { - gpr_log(GPR_ERROR, "uname: %s", StrError(errno).c_str()); + LOG(ERROR) << "uname: " << StrError(errno); return false; } char* release = buffer.release; @@ -48,7 +50,7 @@ bool KernelSupportsErrqueue() { if (strtol(release, nullptr, 10) >= 4) { return true; } else { - gpr_log(GPR_DEBUG, "ERRQUEUE support not enabled"); + VLOG(2) << "ERRQUEUE support not enabled"; } #endif // GRPC_LINUX_ERRQUEUE return false; diff --git a/src/core/lib/iomgr/iocp_windows.cc b/src/core/lib/iomgr/iocp_windows.cc index 0353aa7614a..a19c13ab7b6 100644 --- a/src/core/lib/iomgr/iocp_windows.cc +++ b/src/core/lib/iomgr/iocp_windows.cc @@ -27,6 +27,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -157,7 +158,7 @@ void grpc_iocp_add_socket(grpc_winsocket* socket) { (uintptr_t)socket, 0); if (!ret) { char* utf8_message = gpr_format_message(WSAGetLastError()); - gpr_log(GPR_ERROR, "Unable to add socket to iocp: %s", utf8_message); + LOG(ERROR) << "Unable to add socket to iocp: " << utf8_message; gpr_free(utf8_message); __debugbreak(); abort(); diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc index ce4d7a3566c..7ebafa6897b 100644 --- a/src/core/lib/iomgr/socket_utils_common_posix.cc +++ b/src/core/lib/iomgr/socket_utils_common_posix.cc @@ -44,6 +44,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -411,7 +412,7 @@ grpc_error_handle grpc_set_socket_tcp_user_timeout( } } else { if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_INFO, "TCP_USER_TIMEOUT not supported for this platform"); + LOG(INFO) << "TCP_USER_TIMEOUT not supported for this platform"; } } return absl::OkStatus(); @@ -442,7 +443,7 @@ static void probe_ipv6_once(void) { int fd = socket(AF_INET6, SOCK_STREAM, 0); g_ipv6_loopback_available = 0; if (fd < 0) { - gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed."); + LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed."; } else { grpc_sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index fc2cdc97407..44e524c6829 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -28,6 +28,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include @@ -217,7 +218,7 @@ static void probe_ipv6_once(void) { SOCKET s = socket(AF_INET6, SOCK_STREAM, 0); g_ipv6_loopback_available = 0; if (s == INVALID_SOCKET) { - gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed."); + LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed."; } else { grpc_sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index 2e5e8fd6b8e..8fb50f6754e 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -30,6 +30,7 @@ #include "absl/container/flat_hash_map.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -240,7 +241,7 @@ static void on_writable(void* acp, grpc_error_handle error) { // your program or another program on the same computer // opened too many network connections. The "easy" fix: // don't do that! - gpr_log(GPR_ERROR, "kernel out of buffers"); + LOG(ERROR) << "kernel out of buffers"; gpr_mu_unlock(&ac->mu); grpc_fd_notify_on_write(fd, &ac->write_closure); return; diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index 07906b6889c..1f9f9817e04 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -875,7 +875,7 @@ static void tcp_trace_read(grpc_tcp* tcp, grpc_error_handle error) for (i = 0; i < tcp->incoming_buffer->count; i++) { char* dump = grpc_dump_slice(tcp->incoming_buffer->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "READ DATA: %s", dump); + VLOG(2) << "READ DATA: " << dump; gpr_free(dump); } } @@ -1853,7 +1853,7 @@ static void tcp_handle_write(void* arg /* grpc_tcp */, tcp->write_cb = nullptr; tcp->current_zerocopy_send = nullptr; if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_INFO, "write: %s", grpc_core::StatusToString(error).c_str()); + LOG(INFO) << "write: " << grpc_core::StatusToString(error); } // No need to take a ref on error since tcp_flush provides a ref. grpc_core::Closure::Run(DEBUG_LOCATION, cb, error); @@ -1877,7 +1877,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, if (gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) { char* data = grpc_dump_slice(buf->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "WRITE DATA: %s", data); + VLOG(2) << "WRITE DATA: " << data; gpr_free(data); } } @@ -1921,7 +1921,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, notify_on_write(tcp); } else { if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_INFO, "write: %s", grpc_core::StatusToString(error).c_str()); + LOG(INFO) << "write: " << grpc_core::StatusToString(error); } grpc_core::Closure::Run(DEBUG_LOCATION, cb, error); } diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc index 181ab5b8e25..ee8f7350eb6 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc @@ -32,6 +32,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -221,7 +222,7 @@ grpc_error_handle grpc_tcp_server_prepare_socket( err = grpc_set_socket_zerocopy(fd); if (!err.ok()) { // it's not fatal, so just log it. - gpr_log(GPR_DEBUG, "Node does not support SO_ZEROCOPY, continuing."); + VLOG(2) << "Node does not support SO_ZEROCOPY, continuing."; } #endif err = grpc_set_socket_nonblocking(fd, 1); diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc index d04dddf8e46..495e800ea08 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc @@ -31,6 +31,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -115,7 +116,7 @@ grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, } else if (requested_port <= 0) { return GRPC_ERROR_CREATE("Bad get_unused_port()"); } - gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port); + VLOG(2) << "Picked unused port " << requested_port; } static bool v4_available = grpc_is_ipv4_availabile(); diff --git a/src/core/lib/iomgr/tcp_server_windows.cc b/src/core/lib/iomgr/tcp_server_windows.cc index 70b4a6a5920..b2a0ab25be8 100644 --- a/src/core/lib/iomgr/tcp_server_windows.cc +++ b/src/core/lib/iomgr/tcp_server_windows.cc @@ -28,6 +28,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -405,7 +406,7 @@ static void on_accept(void* arg, grpc_error_handle error) { if (!wsa_success) { if (!sp->shutting_down) { char* utf8_message = gpr_format_message(WSAGetLastError()); - gpr_log(GPR_ERROR, "on_accept error: %s", utf8_message); + LOG(ERROR) << "on_accept error: " << utf8_message; gpr_free(utf8_message); } closesocket(sock); @@ -415,7 +416,7 @@ static void on_accept(void* arg, grpc_error_handle error) { (char*)&sp->socket->socket, sizeof(sp->socket->socket)); if (err) { char* utf8_message = gpr_format_message(WSAGetLastError()); - gpr_log(GPR_ERROR, "setsockopt error: %s", utf8_message); + LOG(ERROR) << "setsockopt error: " << utf8_message; gpr_free(utf8_message); } int peer_name_len = (int)peer_name.len; @@ -432,7 +433,7 @@ static void on_accept(void* arg, grpc_error_handle error) { } } else { char* utf8_message = gpr_format_message(WSAGetLastError()); - gpr_log(GPR_ERROR, "getpeername error: %s", utf8_message); + LOG(ERROR) << "getpeername error: " << utf8_message; gpr_free(utf8_message); } std::string fd_name = absl::StrCat("tcp_server:", peer_name_string); diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 6e4197a8f83..9cab02d2877 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -89,7 +90,7 @@ static void start_timer_thread_and_unlock(void) { ++g_thread_count; gpr_mu_unlock(&g_mu); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "Spawn timer thread"); + LOG(INFO) << "Spawn timer thread"; } completed_thread* ct = static_cast(gpr_malloc(sizeof(*ct))); @@ -125,7 +126,7 @@ static void run_some_timers() { // waiter so that the next deadline is not missed if (!g_has_timed_waiter) { if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "kick untimed waiter"); + LOG(INFO) << "kick untimed waiter"; } gpr_cv_signal(&g_cv_wait); } @@ -133,7 +134,7 @@ static void run_some_timers() { } // without our lock, flush the exec_ctx if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "flush exec_ctx"); + LOG(INFO) << "flush exec_ctx"; } grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&g_mu); @@ -199,7 +200,7 @@ static bool wait_until(grpc_core::Timestamp next) { if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace) && next == grpc_core::Timestamp::InfFuture()) { - gpr_log(GPR_INFO, "sleep until kicked"); + LOG(INFO) << "sleep until kicked"; } gpr_cv_wait(&g_cv_wait, &g_mu, next.as_timespec(GPR_CLOCK_MONOTONIC)); @@ -251,7 +252,7 @@ static void timer_main_loop() { // Consequently, we can just sleep forever here and be happy at some // saved wakeup cycles. if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "timers not checked: expect another thread to"); + LOG(INFO) << "timers not checked: expect another thread to"; } next = grpc_core::Timestamp::InfFuture(); ABSL_FALLTHROUGH_INTENDED; @@ -277,7 +278,7 @@ static void timer_thread_cleanup(completed_thread* ct) { g_completed_threads = ct; gpr_mu_unlock(&g_mu); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "End timer thread"); + LOG(INFO) << "End timer thread"; } } @@ -318,18 +319,18 @@ void grpc_timer_manager_init(void) { static void stop_threads(void) { gpr_mu_lock(&g_mu); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "stop timer threads: threaded=%d", g_threaded); + LOG(INFO) << "stop timer threads: threaded=" << g_threaded; } if (g_threaded) { g_threaded = false; gpr_cv_broadcast(&g_cv_wait); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "num timer threads: %d", g_thread_count); + LOG(INFO) << "num timer threads: " << g_thread_count; } while (g_thread_count > 0) { gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "num timer threads: %d", g_thread_count); + LOG(INFO) << "num timer threads: " << g_thread_count; } gc_completed_threads(); } From 1e83bc69786c8d1265826faa635d56a0b9984b48 Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap Date: Fri, 17 May 2024 01:40:34 -0700 Subject: [PATCH 16/23] Automated rollback of commit f00dfb0f786a1483051a185e41321b9e21bb1f26. PiperOrigin-RevId: 634674403 --- src/core/lib/event_engine/ares_resolver.cc | 5 +++-- src/core/lib/event_engine/posix_engine/posix_endpoint.cc | 7 ++++--- src/core/lib/event_engine/posix_engine/posix_endpoint.h | 3 ++- src/core/lib/event_engine/posix_engine/posix_engine.cc | 3 ++- .../posix_engine/posix_engine_listener_utils.cc | 5 +++-- src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc | 5 +++-- .../lib/event_engine/posix_engine/traced_buffer_list.cc | 3 ++- .../event_engine/thread_pool/work_stealing_thread_pool.cc | 5 +++-- 8 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/core/lib/event_engine/ares_resolver.cc b/src/core/lib/event_engine/ares_resolver.cc index 4273616642c..58df73794b9 100644 --- a/src/core/lib/event_engine/ares_resolver.cc +++ b/src/core/lib/event_engine/ares_resolver.cc @@ -53,6 +53,7 @@ #include "absl/functional/any_invocable.h" #include "absl/hash/hash.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/match.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" @@ -200,7 +201,7 @@ AresResolver::CreateAresResolver( ares_channel channel; int status = ares_init_options(&channel, &opts, ARES_OPT_FLAGS); if (status != ARES_SUCCESS) { - gpr_log(GPR_ERROR, "ares_init_options failed, status: %d", status); + LOG(ERROR) << "ares_init_options failed, status: " << status; return AresStatusToAbslStatus( status, absl::StrCat("Failed to init c-ares channel: ", ares_strerror(status))); @@ -769,7 +770,7 @@ void AresResolver::OnTXTDoneLocked(void* arg, int status, int /*timeouts*/, result.size()); if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_ares_resolver)) { for (const auto& record : result) { - gpr_log(GPR_INFO, "%s", record.c_str()); + LOG(INFO) << record; } } // Clean up. diff --git a/src/core/lib/event_engine/posix_engine/posix_endpoint.cc b/src/core/lib/event_engine/posix_engine/posix_endpoint.cc index 7c8dd72052a..18d7dfb4623 100644 --- a/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +++ b/src/core/lib/event_engine/posix_engine/posix_endpoint.cc @@ -27,6 +27,7 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" @@ -718,7 +719,7 @@ bool PosixEndpointImpl::ProcessErrors() { return processed_err; } if (GPR_UNLIKELY((msg.msg_flags & MSG_CTRUNC) != 0)) { - gpr_log(GPR_ERROR, "Error message was truncated."); + LOG(ERROR) << "Error message was truncated."; } if (msg.msg_controllen == 0) { @@ -813,7 +814,7 @@ struct cmsghdr* PosixEndpointImpl::ProcessTimestamp(msghdr* msg, auto serr = reinterpret_cast(CMSG_DATA(next_cmsg)); if (serr->ee_errno != ENOMSG || serr->ee_origin != SO_EE_ORIGIN_TIMESTAMPING) { - gpr_log(GPR_ERROR, "Unexpected control message"); + LOG(ERROR) << "Unexpected control message"; return cmsg; } traced_buffers_.ProcessTimestamp(serr, opt_stats, tss); @@ -1303,7 +1304,7 @@ PosixEndpointImpl::PosixEndpointImpl(EventHandle* handle, if (setsockopt(fd_, SOL_SOCKET, SO_ZEROCOPY, &enable, sizeof(enable)) != 0) { zerocopy_enabled = false; - gpr_log(GPR_ERROR, "Failed to set zerocopy options on the socket."); + LOG(ERROR) << "Failed to set zerocopy options on the socket."; } } diff --git a/src/core/lib/event_engine/posix_engine/posix_endpoint.h b/src/core/lib/event_engine/posix_engine/posix_endpoint.h index c85c81e1eb1..9a0ca6b8db4 100644 --- a/src/core/lib/event_engine/posix_engine/posix_endpoint.h +++ b/src/core/lib/event_engine/posix_engine/posix_endpoint.h @@ -30,6 +30,7 @@ #include "absl/functional/any_invocable.h" #include "absl/hash/hash.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -183,7 +184,7 @@ class TcpZerocopySendCtx { if (send_records_ == nullptr || free_send_records_ == nullptr) { gpr_free(send_records_); gpr_free(free_send_records_); - gpr_log(GPR_INFO, "Disabling TCP TX zerocopy due to memory pressure.\n"); + LOG(INFO) << "Disabling TCP TX zerocopy due to memory pressure.\n"; memory_limited_ = true; enabled_ = false; } else { diff --git a/src/core/lib/event_engine/posix_engine/posix_engine.cc b/src/core/lib/event_engine/posix_engine/posix_engine.cc index 189866faa73..f5c1bf6c3d2 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine.cc +++ b/src/core/lib/event_engine/posix_engine/posix_engine.cc @@ -26,6 +26,7 @@ #include "absl/cleanup/cleanup.h" #include "absl/functional/any_invocable.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -231,7 +232,7 @@ void AsyncConnect::OnWritable(absl::Status status) // your program or another program on the same computer // opened too many network connections. The "easy" fix: // don't do that! - gpr_log(GPR_ERROR, "kernel out of buffers"); + LOG(ERROR) << "kernel out of buffers"; mu_.Unlock(); fd->NotifyOnWrite(on_writable_); // Don't run the cleanup function for this case. diff --git a/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc b/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc index cbd8902d325..ebcbec1771b 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc +++ b/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc @@ -23,6 +23,7 @@ #include "absl/cleanup/cleanup.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_replace.h" @@ -156,7 +157,7 @@ absl::Status PrepareSocket(const PosixTcpOptions& options, #ifdef GRPC_LINUX_ERRQUEUE if (!socket.sock.SetSocketZeroCopy().ok()) { // it's not fatal, so just log it. - gpr_log(GPR_DEBUG, "Node does not support SO_ZEROCOPY, continuing."); + VLOG(2) << "Node does not support SO_ZEROCOPY, continuing."; } else { socket.zero_copy_enabled = true; } @@ -244,7 +245,7 @@ absl::StatusOr ListenerContainerAddAllLocalAddresses( auto result = GetUnusedPort(); GRPC_RETURN_IF_ERROR(result.status()); requested_port = *result; - gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port); + VLOG(2) << "Picked unused port " << requested_port; } if (getifaddrs(&ifa) != 0 || ifa == nullptr) { return absl::FailedPreconditionError( diff --git a/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc b/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc index d2cf5f6f426..987a010084c 100644 --- a/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +++ b/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc @@ -18,6 +18,7 @@ #include #include "absl/cleanup/cleanup.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/types/optional.h" @@ -653,7 +654,7 @@ void PosixSocketWrapper::TrySetSocketTcpUserTimeout( } if (newval != timeout) { // Do not fail on failing to set TCP_USER_TIMEOUT - gpr_log(GPR_ERROR, "Failed to set TCP_USER_TIMEOUT"); + LOG(ERROR) << "Failed to set TCP_USER_TIMEOUT"; return; } } @@ -684,7 +685,7 @@ bool PosixSocketWrapper::IsIpv6LoopbackAvailable() { int fd = socket(AF_INET6, SOCK_STREAM, 0); bool loopback_available = false; if (fd < 0) { - gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed."); + LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed."; } else { sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); diff --git a/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc b/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc index 314e451c664..1171cb76624 100644 --- a/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc +++ b/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc @@ -22,6 +22,7 @@ #include #include "absl/functional/any_invocable.h" +#include "absl/log/log.h" #include #include @@ -48,7 +49,7 @@ void FillGprFromTimestamp(gpr_timespec* gts, const struct timespec* ts) { void DefaultTimestampsCallback(void* /*arg*/, Timestamps* /*ts*/, absl::Status /*shudown_err*/) { - gpr_log(GPR_DEBUG, "Timestamps callback has not been registered"); + VLOG(2) << "Timestamps callback has not been registered"; } // The saved callback function that will be invoked when we get all the diff --git a/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc b/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc index eeaed8abb3c..f22f9484d32 100644 --- a/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc +++ b/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc @@ -27,6 +27,7 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/time/clock.h" #include "absl/time/time.h" #include "absl/types/optional.h" @@ -267,7 +268,7 @@ void WorkStealingThreadPool::WorkStealingThreadPoolImpl::StartThread() { } void WorkStealingThreadPool::WorkStealingThreadPoolImpl::Quiesce() { - gpr_log(GPR_INFO, "WorkStealingThreadPoolImpl::Quiesce"); + LOG(INFO) << "WorkStealingThreadPoolImpl::Quiesce"; SetShutdown(true); // Wait until all threads have exited. // Note that if this is a threadpool thread then we won't exit this thread @@ -319,7 +320,7 @@ bool WorkStealingThreadPool::WorkStealingThreadPoolImpl::IsQuiesced() { } void WorkStealingThreadPool::WorkStealingThreadPoolImpl::PrepareFork() { - gpr_log(GPR_INFO, "WorkStealingThreadPoolImpl::PrepareFork"); + LOG(INFO) << "WorkStealingThreadPoolImpl::PrepareFork"; SetForking(true); work_signal_.SignalAll(); auto threads_were_shut_down = living_thread_count_.BlockUntilThreadCount( From fb6a57b153c1290c08028cd909d759fcd393ff22 Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Fri, 17 May 2024 10:17:25 -0700 Subject: [PATCH 17/23] Add grpc-java 1.63.1 to client_matrix.py (#36651) Closes #36651 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36651 from sergiitk:java-1.63.1 409d48e1fb79138e5105e6e5daed4503b54d2db0 PiperOrigin-RevId: 634815551 --- tools/interop_matrix/client_matrix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/interop_matrix/client_matrix.py b/tools/interop_matrix/client_matrix.py index e5aad848f6c..92db7dc425c 100644 --- a/tools/interop_matrix/client_matrix.py +++ b/tools/interop_matrix/client_matrix.py @@ -441,7 +441,7 @@ LANG_RELEASE_MATRIX = { ("v1.59.1", ReleaseInfo()), ("v1.60.1", ReleaseInfo()), ("v1.61.0", ReleaseInfo()), - ("v1.63.0", ReleaseInfo()), + ("v1.63.1", ReleaseInfo()), ("v1.64.0", ReleaseInfo()), ] ), From a47065e696f61d5f46b9618479bf45c985c19bb0 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Fri, 17 May 2024 16:40:33 -0700 Subject: [PATCH 18/23] [release] Add 1.64.0 to interop tests (#36650) grpc_interop_matrix_adhoc run - https://fusion2.corp.google.com/ci/kokoro/prod:grpc%2Fcore%2Fexperimental%2Flinux%2Fgrpc_interop_matrix_adhoc/activity/1e50bcde-9646-488e-88ae-e700a0863f71/summary Closes #36650 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36650 from yashykt:Add164ToInterop 92a6913722526fd90390e05fdd5d62b489b5984e PiperOrigin-RevId: 634919389 --- tools/interop_matrix/client_matrix.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/interop_matrix/client_matrix.py b/tools/interop_matrix/client_matrix.py index 92db7dc425c..3e79add7698 100644 --- a/tools/interop_matrix/client_matrix.py +++ b/tools/interop_matrix/client_matrix.py @@ -133,6 +133,7 @@ LANG_RELEASE_MATRIX = { ("v1.61.0", ReleaseInfo()), ("v1.62.0", ReleaseInfo()), ("v1.63.0", ReleaseInfo()), + ("v1.64.0", ReleaseInfo()), ] ), "go": OrderedDict( @@ -789,6 +790,12 @@ LANG_RELEASE_MATRIX = { runtimes=["python"], testcases_file="python__master" ), ), + ( + "v1.64.0", + ReleaseInfo( + runtimes=["python"], testcases_file="python__master" + ), + ), ] ), "node": OrderedDict( @@ -886,6 +893,7 @@ LANG_RELEASE_MATRIX = { ("v1.61.0", ReleaseInfo()), ("v1.62.0", ReleaseInfo()), ("v1.63.0", ReleaseInfo()), + ("v1.64.0", ReleaseInfo()), ] ), "php": OrderedDict( @@ -947,6 +955,7 @@ LANG_RELEASE_MATRIX = { ("v1.61.0", ReleaseInfo()), ("v1.62.0", ReleaseInfo()), ("v1.63.0", ReleaseInfo()), + ("v1.64.0", ReleaseInfo()), ] ), "csharp": OrderedDict( From 986428d2526609d71cc7125602e06c1d83f3782c Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap <139093547+tanvi-jagtap@users.noreply.github.com> Date: Fri, 17 May 2024 20:07:11 -0700 Subject: [PATCH 19/23] [grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging - gpr_log (#36636) [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 #36636 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36636 from tanvi-jagtap:regex_test_cpp f2cac9c5a49f8d6025989160b9d9d6954dc8cc2d PiperOrigin-RevId: 634954173 --- test/cpp/interop/interop_server.cc | 28 ++++----- test/cpp/interop/interop_test.cc | 8 +-- test/cpp/interop/observability_client.cc | 29 +++++---- test/cpp/interop/reconnect_interop_client.cc | 8 +-- test/cpp/interop/stress_test.cc | 57 +++++++++-------- test/cpp/interop/xds_federation_client.cc | 20 +++--- test/cpp/interop/xds_interop_client.cc | 21 +++---- test/cpp/interop/xds_interop_server.cc | 3 +- .../microbenchmarks/bm_cq_multiple_threads.cc | 4 +- .../callback_streaming_ping_pong.h | 5 +- .../microbenchmarks/callback_test_service.cc | 3 +- test/cpp/qps/client.h | 25 ++++---- test/cpp/qps/client_callback.cc | 8 +-- .../qps/inproc_sync_unary_ping_pong_test.cc | 4 +- test/cpp/qps/qps_json_driver.cc | 22 +++---- test/cpp/qps/qps_openloop_test.cc | 4 +- test/cpp/qps/qps_worker.cc | 62 +++++++++---------- .../qps/secure_sync_unary_ping_pong_test.cc | 4 +- test/cpp/qps/usage_timer.cc | 5 +- .../load_reporter/load_reporter_test.cc | 10 +-- test/cpp/server/server_request_call_test.cc | 19 +++--- 21 files changed, 168 insertions(+), 181 deletions(-) diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index 32f005598ec..fb7d3430107 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -23,9 +23,9 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include -#include #include #include #include @@ -119,22 +119,20 @@ bool CheckExpectedCompression(const ServerContext& context, if (compression_expected) { if (received_compression == GRPC_COMPRESS_NONE) { // Expected some compression, got NONE. This is an error. - gpr_log(GPR_ERROR, - "Expected compression but got uncompressed request from client."); + LOG(ERROR) + << "Expected compression but got uncompressed request from client."; return false; } if (!(inspector.WasCompressed())) { - gpr_log(GPR_ERROR, - "Failure: Requested compression in a compressable request, but " - "compression bit in message flags not set."); + LOG(ERROR) << "Failure: Requested compression in a compressable request, " + "but compression bit in message flags not set."; return false; } } else { // Didn't expect compression -> make sure the request is uncompressed if (inspector.WasCompressed()) { - gpr_log(GPR_ERROR, - "Failure: Didn't requested compression, but compression bit in " - "message flags set."); + LOG(ERROR) << "Failure: Didn't requested compression, but compression " + "bit in message flags set."; return false; } } @@ -197,8 +195,9 @@ class TestServiceImpl : public TestService::Service { MaybeEchoMetadata(context); if (request->has_response_compressed()) { const bool compression_requested = request->response_compressed().value(); - gpr_log(GPR_DEBUG, "Request for compression (%s) present for %s", - compression_requested ? "enabled" : "disabled", __func__); + VLOG(2) << "Request for compression (" + << (compression_requested ? "enabled" : "disabled") + << ") present for " << __func__; if (compression_requested) { // Any level would do, let's go for HIGH because we are overachievers. context->set_compression_level(GRPC_COMPRESS_LEVEL_HIGH); @@ -247,8 +246,9 @@ class TestServiceImpl : public TestService::Service { context->set_compression_level(GRPC_COMPRESS_LEVEL_HIGH); const bool compression_requested = request->response_parameters(i).compressed().value(); - gpr_log(GPR_DEBUG, "Request for compression (%s) present for %s", - compression_requested ? "enabled" : "disabled", __func__); + VLOG(2) << "Request for compression (" + << (compression_requested ? "enabled" : "disabled") + << ") present for " << __func__; if (!compression_requested) { wopts.set_no_compression(); } // else, compression is already enabled via the context. @@ -445,7 +445,7 @@ void grpc::testing::interop::RunServer( grpc::ServerBuilder::experimental_type(&builder).EnableCallMetricRecording( nullptr); std::unique_ptr server(builder.BuildAndStart()); - gpr_log(GPR_INFO, "Server listening on %s", server_address.str().c_str()); + LOG(INFO) << "Server listening on " << server_address.str(); // Signal that the server has started. if (server_started_condition) { diff --git a/test/cpp/interop/interop_test.cc b/test/cpp/interop/interop_test.cc index d8eaf556601..d46e2a531cd 100644 --- a/test/cpp/interop/interop_test.cc +++ b/test/cpp/interop/interop_test.cc @@ -29,10 +29,10 @@ #include #include "absl/flags/flag.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include -#include #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/socket_utils_posix.h" @@ -65,7 +65,7 @@ int test_client(const char* root, const char* host, int port) { return 1; } // wait for client - gpr_log(GPR_INFO, "Waiting for client: %s", host); + LOG(INFO) << "Waiting for client: " << host; if (waitpid(cli, &status, 0) == -1) return 2; if (!WIFEXITED(status)) return 4; if (WEXITSTATUS(status)) return WEXITSTATUS(status); @@ -86,7 +86,7 @@ int main(int argc, char** argv) { // concurrently running test binary srand(getpid()); if (!grpc_ipv6_loopback_available()) { - gpr_log(GPR_INFO, "Can't bind to ::1. Skipping IPv6 tests."); + LOG(INFO) << "Can't bind to ::1. Skipping IPv6 tests."; do_ipv6 = 0; } // figure out where we are @@ -126,7 +126,7 @@ int main(int argc, char** argv) { if (ret != 0) return ret; } // wait for server - gpr_log(GPR_INFO, "Waiting for server"); + LOG(INFO) << "Waiting for server"; kill(svr, SIGINT); if (waitpid(svr, &status, 0) == -1) return 2; if (!WIFEXITED(status)) return 4; diff --git a/test/cpp/interop/observability_client.cc b/test/cpp/interop/observability_client.cc index 5e39495ae68..247ab1d1738 100644 --- a/test/cpp/interop/observability_client.cc +++ b/test/cpp/interop/observability_client.cc @@ -20,13 +20,13 @@ #include #include "absl/flags/flag.h" +#include "absl/log/log.h" #include "opentelemetry/exporters/prometheus/exporter_factory.h" #include "opentelemetry/exporters/prometheus/exporter_options.h" #include "opentelemetry/sdk/metrics/meter_provider.h" #include #include -#include #include #include #include @@ -160,8 +160,8 @@ bool ParseAdditionalMetadataFlag( while (start_pos < flag.length()) { size_t colon_pos = flag.find(':', start_pos); if (colon_pos == std::string::npos) { - gpr_log(GPR_ERROR, - "Couldn't parse metadata flag: extra characters at end of flag"); + LOG(ERROR) + << "Couldn't parse metadata flag: extra characters at end of flag"; return false; } size_t semicolon_pos = flag.find(';', colon_pos); @@ -175,10 +175,9 @@ bool ParseAdditionalMetadataFlag( "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; if (key.find_first_not_of(alphanum_and_hyphen) != std::string::npos) { - gpr_log(GPR_ERROR, - "Couldn't parse metadata flag: key contains characters other " - "than alphanumeric and hyphens: %s", - key.c_str()); + LOG(ERROR) << "Couldn't parse metadata flag: key contains characters " + "other than alphanumeric and hyphens: " + << key; return false; } @@ -189,8 +188,8 @@ bool ParseAdditionalMetadataFlag( } } - gpr_log(GPR_INFO, "Adding additional metadata with key %s and value %s", - key.c_str(), value.c_str()); + LOG(INFO) << "Adding additional metadata with key " << key << " and value " + << value; additional_metadata->insert({key, value}); if (semicolon_pos == std::string::npos) { @@ -208,15 +207,14 @@ bool ParseAdditionalMetadataFlag( int main(int argc, char** argv) { grpc::testing::TestEnvironment env(&argc, argv); grpc::testing::InitTest(&argc, &argv, true); - gpr_log(GPR_INFO, "Testing these cases: %s", - absl::GetFlag(FLAGS_test_case).c_str()); + LOG(INFO) << "Testing these cases: " << absl::GetFlag(FLAGS_test_case); int ret = 0; if (absl::GetFlag(FLAGS_enable_observability)) { // TODO(someone): remove deprecated usage // NOLINTNEXTLINE(clang-diagnostic-deprecated-declarations) auto status = grpc::experimental::GcpObservabilityInit(); - gpr_log(GPR_DEBUG, "GcpObservabilityInit() status_code: %d", status.code()); + VLOG(2) << "GcpObservabilityInit() status_code: " << status.code(); if (!status.ok()) { return 1; } @@ -225,7 +223,7 @@ int main(int argc, char** argv) { // TODO(stanleycheung): switch to CsmObservabilityBuilder once xds setup is // ready if (absl::GetFlag(FLAGS_enable_otel_plugin)) { - gpr_log(GPR_DEBUG, "Registering Prometheus exporter"); + VLOG(2) << "Registering Prometheus exporter"; opentelemetry::exporter::metrics::PrometheusExporterOptions opts; // default was "localhost:9464" which causes connection issue across GKE // pods @@ -389,8 +387,9 @@ int main(int argc, char** argv) { if (!test_cases.empty()) test_cases += "\n"; test_cases += action.first; } - gpr_log(GPR_ERROR, "Unsupported test case %s. Valid options are\n%s", - absl::GetFlag(FLAGS_test_case).c_str(), test_cases.c_str()); + LOG(ERROR) << "Unsupported test case " << absl::GetFlag(FLAGS_test_case) + << ". Valid options are\n" + << test_cases; ret = 1; } diff --git a/test/cpp/interop/reconnect_interop_client.cc b/test/cpp/interop/reconnect_interop_client.cc index cf658db0414..bdc7b27aa07 100644 --- a/test/cpp/interop/reconnect_interop_client.cc +++ b/test/cpp/interop/reconnect_interop_client.cc @@ -21,9 +21,9 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include -#include #include #include #include @@ -76,7 +76,7 @@ int main(int argc, char** argv) { control_stub->Start(&start_context, reconnect_params, &empty_response); CHECK(start_status.ok()); - gpr_log(GPR_INFO, "Starting connections with retries."); + LOG(INFO) << "Starting connections with retries."; server_address.str(""); server_address << absl::GetFlag(FLAGS_server_host) << ':' << absl::GetFlag(FLAGS_server_retry_port); @@ -100,13 +100,13 @@ int main(int argc, char** argv) { Status retry_status = retry_stub->Start(&retry_context, reconnect_params, &empty_response); CHECK(retry_status.error_code() == grpc::StatusCode::DEADLINE_EXCEEDED); - gpr_log(GPR_INFO, "Done retrying, getting final data from server"); + LOG(INFO) << "Done retrying, getting final data from server"; ClientContext stop_context; ReconnectInfo response; Status stop_status = control_stub->Stop(&stop_context, Empty(), &response); CHECK(stop_status.ok()); CHECK(response.passed() == true); - gpr_log(GPR_INFO, "Passed"); + LOG(INFO) << "Passed"; return 0; } diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc index 1e1b6ffe0bd..b37c608a369 100644 --- a/test/cpp/interop/stress_test.cc +++ b/test/cpp/interop/stress_test.cc @@ -24,8 +24,8 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" -#include #include #include #include @@ -176,7 +176,7 @@ bool ParseTestCasesString(const std::string& test_cases, // Token is in the form : size_t colon_pos = it->find(':'); if (colon_pos == std::string::npos) { - gpr_log(GPR_ERROR, "Error in parsing test case string: %s", it->c_str()); + LOG(ERROR) << "Error in parsing test case string: " << it->c_str(); is_success = false; break; } @@ -185,7 +185,7 @@ bool ParseTestCasesString(const std::string& test_cases, int weight = std::stoi(it->substr(colon_pos + 1)); TestCaseType test_case = GetTestTypeFromName(test_name); if (test_case == UNKNOWN_TEST) { - gpr_log(GPR_ERROR, "Unknown test case: %s", test_name.c_str()); + LOG(ERROR) << "Unknown test case: " << test_name; is_success = false; break; } @@ -199,33 +199,32 @@ bool ParseTestCasesString(const std::string& test_cases, // For debugging purposes void LogParameterInfo(const std::vector& addresses, const std::vector>& tests) { - gpr_log(GPR_INFO, "server_addresses: %s", - absl::GetFlag(FLAGS_server_addresses).c_str()); - gpr_log(GPR_INFO, "test_cases : %s", absl::GetFlag(FLAGS_test_cases).c_str()); - gpr_log(GPR_INFO, "sleep_duration_ms: %d", - absl::GetFlag(FLAGS_sleep_duration_ms)); - gpr_log(GPR_INFO, "test_duration_secs: %d", - absl::GetFlag(FLAGS_test_duration_secs)); - gpr_log(GPR_INFO, "num_channels_per_server: %d", - absl::GetFlag(FLAGS_num_channels_per_server)); - gpr_log(GPR_INFO, "num_stubs_per_channel: %d", - absl::GetFlag(FLAGS_num_stubs_per_channel)); - gpr_log(GPR_INFO, "log_level: %d", absl::GetFlag(FLAGS_log_level)); - gpr_log(GPR_INFO, "do_not_abort_on_transient_failures: %s", - absl::GetFlag(FLAGS_do_not_abort_on_transient_failures) ? "true" - : "false"); + LOG(INFO) << "server_addresses: " << absl::GetFlag(FLAGS_server_addresses); + LOG(INFO) << "test_cases : " << absl::GetFlag(FLAGS_test_cases); + LOG(INFO) << "sleep_duration_ms: " << absl::GetFlag(FLAGS_sleep_duration_ms); + LOG(INFO) << "test_duration_secs: " + << absl::GetFlag(FLAGS_test_duration_secs); + LOG(INFO) << "num_channels_per_server: " + << absl::GetFlag(FLAGS_num_channels_per_server); + LOG(INFO) << "num_stubs_per_channel: " + << absl::GetFlag(FLAGS_num_stubs_per_channel); + LOG(INFO) << "log_level: " << absl::GetFlag(FLAGS_log_level); + LOG(INFO) << "do_not_abort_on_transient_failures: " + << (absl::GetFlag(FLAGS_do_not_abort_on_transient_failures) + ? "true" + : "false"); int num = 0; for (auto it = addresses.begin(); it != addresses.end(); it++) { - gpr_log(GPR_INFO, "%d:%s", ++num, it->c_str()); + LOG(INFO) << ++num << ":" << it->c_str(); } num = 0; for (auto it = tests.begin(); it != tests.end(); it++) { TestCaseType test_case = it->first; int weight = it->second; - gpr_log(GPR_INFO, "%d. TestCaseType: %d, Weight: %d", ++num, test_case, - weight); + LOG(INFO) << ++num << ". TestCaseType: " << test_case + << ", Weight: " << weight; } } @@ -234,8 +233,8 @@ int main(int argc, char** argv) { if (absl::GetFlag(FLAGS_log_level) > GPR_LOG_SEVERITY_ERROR || absl::GetFlag(FLAGS_log_level) < GPR_LOG_SEVERITY_DEBUG) { - gpr_log(GPR_ERROR, "log_level should be an integer between %d and %d", - GPR_LOG_SEVERITY_DEBUG, GPR_LOG_SEVERITY_ERROR); + LOG(ERROR) << "log_level should be an integer between " + << GPR_LOG_SEVERITY_DEBUG << " and " << GPR_LOG_SEVERITY_ERROR; return 1; } @@ -253,14 +252,14 @@ int main(int argc, char** argv) { // Parse test cases and weights if (absl::GetFlag(FLAGS_test_cases).length() == 0) { - gpr_log(GPR_ERROR, "No test cases supplied"); + LOG(ERROR) << "No test cases supplied"; return 1; } std::vector> tests; if (!ParseTestCasesString(absl::GetFlag(FLAGS_test_cases), tests)) { - gpr_log(GPR_ERROR, "Error in parsing test cases string %s ", - absl::GetFlag(FLAGS_test_cases).c_str()); + LOG(ERROR) << "Error in parsing test cases string " + << absl::GetFlag(FLAGS_test_cases); return 1; } @@ -269,7 +268,7 @@ int main(int argc, char** argv) { WeightedRandomTestSelector test_selector(tests); MetricsServiceImpl metrics_service; - gpr_log(GPR_INFO, "Starting test(s).."); + LOG(INFO) << "Starting test(s).."; std::vector test_threads; std::vector> clients; @@ -295,8 +294,8 @@ int main(int argc, char** argv) { for (int channel_idx = 0; channel_idx < absl::GetFlag(FLAGS_num_channels_per_server); channel_idx++) { - gpr_log(GPR_INFO, "Starting test with %s channel_idx=%d..", it->c_str(), - channel_idx); + LOG(INFO) << "Starting test with " << it->c_str() + << " channel_idx=" << channel_idx << ".."; grpc::testing::ChannelCreationFunc channel_creation_func = std::bind(static_cast (*)( const std::string&, const std::string&, diff --git a/test/cpp/interop/xds_federation_client.cc b/test/cpp/interop/xds_federation_client.cc index 4efc58f9d8d..8c8c4ffc6b7 100644 --- a/test/cpp/interop/xds_federation_client.cc +++ b/test/cpp/interop/xds_federation_client.cc @@ -21,11 +21,11 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_split.h" #include #include -#include #include "src/core/util/string.h" #include "test/core/test_util/test_config.h" @@ -74,8 +74,7 @@ ABSL_FLAG(std::string, test_case, "rpc_soak", int main(int argc, char** argv) { grpc::testing::TestEnvironment env(&argc, argv); grpc::testing::InitTest(&argc, &argv, true); - gpr_log(GPR_INFO, "Testing these cases: %s", - absl::GetFlag(FLAGS_test_case).c_str()); + LOG(INFO) << "Testing these cases: " << absl::GetFlag(FLAGS_test_case); std::string test_case = absl::GetFlag(FLAGS_test_case); // validate flags std::vector uris = @@ -83,14 +82,13 @@ int main(int argc, char** argv) { std::vector creds = absl::StrSplit(absl::GetFlag(FLAGS_credentials_types), ','); if (uris.size() != creds.size()) { - gpr_log(GPR_ERROR, - "Number of entries in --server_uris %ld != number of entries in " - "--credentials_types %ld", - uris.size(), creds.size()); + LOG(ERROR) << "Number of entries in --server_uris " << uris.size() + << " != number of entries in --credentials_types " + << creds.size(); CHECK(0); } if (uris.empty()) { - gpr_log(GPR_ERROR, "--server_uris has zero entries"); + LOG(ERROR) << "--server_uris has zero entries"; CHECK(0); } // construct and start clients @@ -121,8 +119,8 @@ int main(int argc, char** argv) { absl::GetFlag(FLAGS_soak_request_size), absl::GetFlag(FLAGS_soak_response_size)); } else { - gpr_log(GPR_ERROR, - "Invalid test case, must be either rpc_soak or channel_soak"); + LOG(ERROR) + << "Invalid test case, must be either rpc_soak or channel_soak"; CHECK(0); } })); @@ -130,6 +128,6 @@ int main(int argc, char** argv) { for (auto& thd : threads) { thd.join(); } - gpr_log(GPR_INFO, "All clients done!"); + LOG(INFO) << "All clients done!"; return 0; } diff --git a/test/cpp/interop/xds_interop_client.cc b/test/cpp/interop/xds_interop_client.cc index c539a9bdc82..8480c24691d 100644 --- a/test/cpp/interop/xds_interop_client.cc +++ b/test/cpp/interop/xds_interop_client.cc @@ -33,6 +33,7 @@ #include "absl/algorithm/container.h" #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_split.h" #include "opentelemetry/exporters/prometheus/exporter_factory.h" #include "opentelemetry/exporters/prometheus/exporter_options.h" @@ -354,15 +355,11 @@ class XdsUpdateClientConfigureServiceImpl } if (request_payload_size > 0 && config.type == ClientConfigureRequest::EMPTY_CALL) { - gpr_log(GPR_ERROR, - "request_payload_size should not be set " - "for EMPTY_CALL"); + LOG(ERROR) << "request_payload_size should not be set for EMPTY_CALL"; } if (response_payload_size > 0 && config.type == ClientConfigureRequest::EMPTY_CALL) { - gpr_log(GPR_ERROR, - "response_payload_size should not be set " - "for EMPTY_CALL"); + LOG(ERROR) << "response_payload_size should not be set for EMPTY_CALL"; } config.request_payload_size = request_payload_size; std::string payload(config.request_payload_size, '0'); @@ -429,7 +426,7 @@ void RunTestLoop(std::chrono::duration duration_per_query, } grpc::CsmObservability EnableCsmObservability() { - gpr_log(GPR_DEBUG, "Registering Prometheus exporter"); + VLOG(2) << "Registering Prometheus exporter"; opentelemetry::exporter::metrics::PrometheusExporterOptions opts; // default was "localhost:9464" which causes connection issue across GKE // pods @@ -463,7 +460,7 @@ void RunServer(const int port, StatsWatchers* stats_watchers, builder.AddListeningPort(server_address.str(), grpc::InsecureServerCredentials()); std::unique_ptr server(builder.BuildAndStart()); - gpr_log(GPR_DEBUG, "Server listening on %s", server_address.str().c_str()); + VLOG(2) << "Server listening on " << server_address.str(); server->Wait(); } @@ -513,15 +510,11 @@ void BuildRpcConfigsFromFlags(RpcConfigurationsQueue* rpc_configs_queue) { } if (request_payload_size > 0 && config.type == ClientConfigureRequest::EMPTY_CALL) { - gpr_log(GPR_ERROR, - "request_payload_size should not be set " - "for EMPTY_CALL"); + LOG(ERROR) << "request_payload_size should not be set for EMPTY_CALL"; } if (response_payload_size > 0 && config.type == ClientConfigureRequest::EMPTY_CALL) { - gpr_log(GPR_ERROR, - "response_payload_size should not be set " - "for EMPTY_CALL"); + LOG(ERROR) << "response_payload_size should not be set for EMPTY_CALL"; } config.request_payload_size = request_payload_size; std::string payload(config.request_payload_size, '0'); diff --git a/test/cpp/interop/xds_interop_server.cc b/test/cpp/interop/xds_interop_server.cc index 27b6317b4a3..ecb951e64c0 100644 --- a/test/cpp/interop/xds_interop_server.cc +++ b/test/cpp/interop/xds_interop_server.cc @@ -19,6 +19,7 @@ #include #include "absl/flags/flag.h" +#include "absl/log/log.h" #include "opentelemetry/exporters/prometheus/exporter_factory.h" #include "opentelemetry/exporters/prometheus/exporter_options.h" #include "opentelemetry/sdk/metrics/meter_provider.h" @@ -44,7 +45,7 @@ ABSL_FLAG(bool, enable_csm_observability, false, "Whether to enable CSM Observability"); grpc::CsmObservability EnableCsmObservability() { - gpr_log(GPR_DEBUG, "Registering Prometheus exporter"); + VLOG(2) << "Registering Prometheus exporter"; opentelemetry::exporter::metrics::PrometheusExporterOptions opts; // default was "localhost:9464" which causes connection issue across GKE // pods diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc index efcb40a8d94..e0144995e0d 100644 --- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc +++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc @@ -23,10 +23,10 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include -#include #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/time.h" @@ -77,7 +77,7 @@ static grpc_error_handle pollset_work(grpc_pollset* ps, grpc_pollset_worker** /*worker*/, grpc_core::Timestamp deadline) { if (deadline == grpc_core::Timestamp::ProcessEpoch()) { - gpr_log(GPR_DEBUG, "no-op"); + VLOG(2) << "no-op"; return absl::OkStatus(); } diff --git a/test/cpp/microbenchmarks/callback_streaming_ping_pong.h b/test/cpp/microbenchmarks/callback_streaming_ping_pong.h index 3ac9a30b538..7987200a245 100644 --- a/test/cpp/microbenchmarks/callback_streaming_ping_pong.h +++ b/test/cpp/microbenchmarks/callback_streaming_ping_pong.h @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/cpp/microbenchmarks/callback_test_service.h" @@ -54,7 +55,7 @@ class BidiClient : public grpc::ClientBidiReactor { void OnReadDone(bool ok) override { if (!ok) { - gpr_log(GPR_ERROR, "Client read failed"); + LOG(ERROR) << "Client read failed"; return; } MaybeWrite(); @@ -62,7 +63,7 @@ class BidiClient : public grpc::ClientBidiReactor { void OnWriteDone(bool ok) override { if (!ok) { - gpr_log(GPR_ERROR, "Client write failed"); + LOG(ERROR) << "Client write failed"; return; } writes_complete_++; diff --git a/test/cpp/microbenchmarks/callback_test_service.cc b/test/cpp/microbenchmarks/callback_test_service.cc index 3b22041d4f3..af732280af4 100644 --- a/test/cpp/microbenchmarks/callback_test_service.cc +++ b/test/cpp/microbenchmarks/callback_test_service.cc @@ -19,6 +19,7 @@ #include "test/cpp/microbenchmarks/callback_test_service.h" #include "absl/log/check.h" +#include "absl/log/log.h" namespace grpc { namespace testing { @@ -93,7 +94,7 @@ CallbackStreamingTestService::BidiStream(CallbackServerContext* context) { } void OnWriteDone(bool ok) override { if (!ok) { - gpr_log(GPR_ERROR, "Server write failed"); + LOG(ERROR) << "Server write failed"; return; } StartRead(&request_); diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index fa5ceae31b5..792d271242b 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -29,11 +29,11 @@ #include #include +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/strings/match.h" #include "absl/strings/str_format.h" -#include #include #include #include @@ -203,10 +203,10 @@ class Client { if (median_latency_collection_interval_seconds_ > 0) { std::vector medians_per_interval = threads_[0]->GetMedianPerIntervalList(); - gpr_log(GPR_INFO, "Num threads: %zu", threads_.size()); - gpr_log(GPR_INFO, "Number of medians: %zu", medians_per_interval.size()); + LOG(INFO) << "Num threads: " << threads_.size(); + LOG(INFO) << "Number of medians: " << medians_per_interval.size(); for (size_t j = 0; j < medians_per_interval.size(); j++) { - gpr_log(GPR_INFO, "%f", medians_per_interval[j]); + LOG(INFO) << medians_per_interval[j]; } } @@ -318,8 +318,8 @@ class Client { &client_->start_requests_, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(20, GPR_TIMESPAN)))) { - gpr_log(GPR_INFO, "%" PRIdPTR ": Waiting for benchmark to start (%d)", - idx_, wait_loop); + LOG(INFO) << idx_ << ": Waiting for benchmark to start (" << wait_loop + << ")"; wait_loop++; } @@ -463,9 +463,8 @@ class ClientImpl : public Client { !channel_connect_timeout_str->empty()) { connect_deadline_seconds = atoi(channel_connect_timeout_str->c_str()); } - gpr_log(GPR_INFO, - "Waiting for up to %d seconds for all channels to connect", - connect_deadline_seconds); + LOG(INFO) << "Waiting for up to " << connect_deadline_seconds + << " seconds for all channels to connect"; gpr_timespec connect_deadline = gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(connect_deadline_seconds, GPR_TIMESPAN)); @@ -476,7 +475,7 @@ class ClientImpl : public Client { Channel* channel = c.get_channel(); grpc_connectivity_state last_observed = channel->GetState(true); if (last_observed == GRPC_CHANNEL_READY) { - gpr_log(GPR_INFO, "Channel %p connected!", channel); + LOG(INFO) << "Channel " << channel << " connected!"; } else { num_remaining++; channel->NotifyOnStateChange(last_observed, connect_deadline, &cq, @@ -495,7 +494,7 @@ class ClientImpl : public Client { } else { grpc_connectivity_state last_observed = channel->GetState(true); if (last_observed == GRPC_CHANNEL_READY) { - gpr_log(GPR_INFO, "Channel %p connected!", channel); + LOG(INFO) << "Channel " << channel << " connected!"; num_remaining--; } else { channel->NotifyOnStateChange(last_observed, connect_deadline, &cq, @@ -534,7 +533,7 @@ class ClientImpl : public Client { target, type, config.security_params().server_host_override(), !config.security_params().use_test_ca(), std::shared_ptr(), args); - gpr_log(GPR_INFO, "Connecting to %s", target.c_str()); + LOG(INFO) << "Connecting to " << target; is_inproc_ = false; } else { std::string tgt = target; @@ -557,7 +556,7 @@ class ClientImpl : public Client { } else if (channel_arg.value_case() == ChannelArg::kIntValue) { args->SetInt(channel_arg.name(), channel_arg.int_value()); } else { - gpr_log(GPR_ERROR, "Empty channel arg value."); + LOG(ERROR) << "Empty channel arg value."; } } } diff --git a/test/cpp/qps/client_callback.cc b/test/cpp/qps/client_callback.cc index 65ad207de63..51cead4e3ea 100644 --- a/test/cpp/qps/client_callback.cc +++ b/test/cpp/qps/client_callback.cc @@ -25,11 +25,11 @@ #include #include +#include "absl/log/log.h" #include "absl/memory/memory.h" #include #include -#include #include #include #include @@ -126,7 +126,7 @@ class CallbackClient int num_threads = config.async_client_threads(); if (num_threads <= 0) { // Use dynamic sizing num_threads = cores_; - gpr_log(GPR_INFO, "Sizing callback client to %d threads", num_threads); + LOG(INFO) << "Sizing callback client to " << num_threads << " threads"; } return num_threads; } @@ -268,7 +268,7 @@ class CallbackStreamingPingPongReactor final void OnWriteDone(bool ok) override { if (!ok) { - gpr_log(GPR_ERROR, "Error writing RPC"); + LOG(ERROR) << "Error writing RPC"; } if ((!ok || client_->ThreadCompleted()) && !writes_done_started_.test_and_set()) { @@ -284,7 +284,7 @@ class CallbackStreamingPingPongReactor final (client_->messages_per_stream() != 0 && ++messages_issued_ >= client_->messages_per_stream())) { if (!ok) { - gpr_log(GPR_ERROR, "Error reading RPC"); + LOG(ERROR) << "Error reading RPC"; } if (!writes_done_started_.test_and_set()) { StartWritesDone(); diff --git a/test/cpp/qps/inproc_sync_unary_ping_pong_test.cc b/test/cpp/qps/inproc_sync_unary_ping_pong_test.cc index 614891004b3..e876e50cf78 100644 --- a/test/cpp/qps/inproc_sync_unary_ping_pong_test.cc +++ b/test/cpp/qps/inproc_sync_unary_ping_pong_test.cc @@ -18,7 +18,7 @@ #include -#include +#include "absl/log/log.h" #include "src/core/lib/gprpp/crash.h" #include "test/core/test_util/test_config.h" @@ -36,7 +36,7 @@ static const int WARMUP = 1; static const int BENCHMARK = 3; static void RunSynchronousUnaryPingPong() { - gpr_log(GPR_INFO, "Running Synchronous Unary Ping Pong"); + LOG(INFO) << "Running Synchronous Unary Ping Pong"; ClientConfig client_config; client_config.set_client_type(SYNC_CLIENT); diff --git a/test/cpp/qps/qps_json_driver.cc b/test/cpp/qps/qps_json_driver.cc index ee70ec76c0d..50734258b50 100644 --- a/test/cpp/qps/qps_json_driver.cc +++ b/test/cpp/qps/qps_json_driver.cc @@ -23,8 +23,8 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" -#include #include #include "src/core/lib/gprpp/crash.h" @@ -104,10 +104,8 @@ ConstructPerWorkerCredentialTypesMap() { } size_t comma = next_entry.find(','); if (comma == std::string::npos) { - gpr_log(GPR_ERROR, - "Expectd --per_worker_credential_types to be a list " - "of the form: 'addr1,cred_type1;addr2,cred_type2;...' " - "into."); + LOG(ERROR) << "Expectd --per_worker_credential_types to be a list of the " + "form: 'addr1,cred_type1;addr2,cred_type2;...' into."; abort(); } std::string addr = next_entry.substr(0, comma); @@ -185,9 +183,9 @@ static double BinarySearch( double mid = low + (high - low) / 2; double current_cpu_load = GetCpuLoad(scenario, mid, per_worker_credential_types, success); - gpr_log(GPR_DEBUG, "Binary Search: current_offered_load %.0f", mid); + VLOG(2) << absl::StrFormat("Binary Search: current_offered_load %.0f", mid); if (!*success) { - gpr_log(GPR_ERROR, "Client/Server Failure"); + LOG(ERROR) << "Client/Server Failure"; break; } if (targeted_cpu_load <= current_cpu_load) { @@ -209,7 +207,7 @@ static double SearchOfferedLoad( double current_cpu_load = GetCpuLoad(scenario, current_offered_load, per_worker_credential_types, success); if (current_cpu_load > targeted_cpu_load) { - gpr_log(GPR_ERROR, "Initial offered load too high"); + LOG(ERROR) << "Initial offered load too high"; return -1; } @@ -217,8 +215,8 @@ static double SearchOfferedLoad( current_offered_load *= 2; current_cpu_load = GetCpuLoad(scenario, current_offered_load, per_worker_credential_types, success); - gpr_log(GPR_DEBUG, "Binary Search: current_offered_load %.0f", - current_offered_load); + VLOG(2) << absl::StrFormat("Binary Search: current_offered_load %.0f", + current_offered_load); } double targeted_offered_load = @@ -280,11 +278,11 @@ static bool QpsDriver() { SearchOfferedLoad(absl::GetFlag(FLAGS_initial_search_value), absl::GetFlag(FLAGS_targeted_cpu_load), scenario, per_worker_credential_types, &success); - gpr_log(GPR_INFO, "targeted_offered_load %f", targeted_offered_load); + LOG(INFO) << "targeted_offered_load " << targeted_offered_load; GetCpuLoad(scenario, targeted_offered_load, per_worker_credential_types, &success); } else { - gpr_log(GPR_ERROR, "Unimplemented search param"); + LOG(ERROR) << "Unimplemented search param"; } } } diff --git a/test/cpp/qps/qps_openloop_test.cc b/test/cpp/qps/qps_openloop_test.cc index b48798a936d..21c83418427 100644 --- a/test/cpp/qps/qps_openloop_test.cc +++ b/test/cpp/qps/qps_openloop_test.cc @@ -18,7 +18,7 @@ #include -#include +#include "absl/log/log.h" #include "src/core/lib/gprpp/crash.h" #include "test/core/test_util/test_config.h" @@ -36,7 +36,7 @@ static const int WARMUP = 1; static const int BENCHMARK = 3; static void RunQPS() { - gpr_log(GPR_INFO, "Running QPS test, open-loop"); + LOG(INFO) << "Running QPS test, open-loop"; ClientConfig client_config; client_config.set_client_type(ASYNC_CLIENT); diff --git a/test/cpp/qps/qps_worker.cc b/test/cpp/qps/qps_worker.cc index b41cbbc6afc..f2b444fc9c8 100644 --- a/test/cpp/qps/qps_worker.cc +++ b/test/cpp/qps/qps_worker.cc @@ -26,12 +26,12 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include #include #include -#include #include #include #include @@ -52,10 +52,10 @@ namespace grpc { namespace testing { static std::unique_ptr CreateClient(const ClientConfig& config) { - gpr_log(GPR_INFO, "Starting client of type %s %s %d", - ClientType_Name(config.client_type()).c_str(), - RpcType_Name(config.rpc_type()).c_str(), - config.payload_config().has_bytebuf_params()); + LOG(INFO) << "Starting client of type " + << ClientType_Name(config.client_type()) << " " + << RpcType_Name(config.rpc_type()) << " " + << config.payload_config().has_bytebuf_params(); switch (config.client_type()) { case ClientType::SYNC_CLIENT: @@ -72,8 +72,8 @@ static std::unique_ptr CreateClient(const ClientConfig& config) { } static std::unique_ptr CreateServer(const ServerConfig& config) { - gpr_log(GPR_INFO, "Starting server of type %s", - ServerType_Name(config.server_type()).c_str()); + LOG(INFO) << "Starting server of type " + << ServerType_Name(config.server_type()); switch (config.server_type()) { case ServerType::SYNC_SERVER: @@ -110,7 +110,7 @@ class WorkerServiceImpl final : public WorkerService::Service { Status RunClient( ServerContext* ctx, ServerReaderWriter* stream) override { - gpr_log(GPR_INFO, "RunClient: Entering"); + LOG(INFO) << "RunClient: Entering"; InstanceGuard g(this); if (!g.Acquired()) { return Status(StatusCode::RESOURCE_EXHAUSTED, "Client worker busy"); @@ -118,14 +118,14 @@ class WorkerServiceImpl final : public WorkerService::Service { ScopedProfile profile("qps_client.prof", false); Status ret = RunClientBody(ctx, stream); - gpr_log(GPR_INFO, "RunClient: Returning"); + LOG(INFO) << "RunClient: Returning"; return ret; } Status RunServer( ServerContext* ctx, ServerReaderWriter* stream) override { - gpr_log(GPR_INFO, "RunServer: Entering"); + LOG(INFO) << "RunServer: Entering"; InstanceGuard g(this); if (!g.Acquired()) { return Status(StatusCode::RESOURCE_EXHAUSTED, "Server worker busy"); @@ -133,7 +133,7 @@ class WorkerServiceImpl final : public WorkerService::Service { ScopedProfile profile("qps_server.prof", false); Status ret = RunServerBody(ctx, stream); - gpr_log(GPR_INFO, "RunServer: Returning"); + LOG(INFO) << "RunServer: Returning"; return ret; } @@ -194,34 +194,34 @@ class WorkerServiceImpl final : public WorkerService::Service { if (!args.has_setup()) { return Status(StatusCode::INVALID_ARGUMENT, "Invalid setup arg"); } - gpr_log(GPR_INFO, "RunClientBody: about to create client"); + LOG(INFO) << "RunClientBody: about to create client"; std::unique_ptr client = CreateClient(args.setup()); if (!client) { return Status(StatusCode::INVALID_ARGUMENT, "Couldn't create client"); } - gpr_log(GPR_INFO, "RunClientBody: client created"); + LOG(INFO) << "RunClientBody: client created"; ClientStatus status; if (!stream->Write(status)) { return Status(StatusCode::UNKNOWN, "Client couldn't report init status"); } - gpr_log(GPR_INFO, "RunClientBody: creation status reported"); + LOG(INFO) << "RunClientBody: creation status reported"; while (stream->Read(&args)) { - gpr_log(GPR_INFO, "RunClientBody: Message read"); + LOG(INFO) << "RunClientBody: Message read"; if (!args.has_mark()) { - gpr_log(GPR_INFO, "RunClientBody: Message is not a mark!"); + LOG(INFO) << "RunClientBody: Message is not a mark!"; return Status(StatusCode::INVALID_ARGUMENT, "Invalid mark"); } *status.mutable_stats() = client->Mark(args.mark().reset()); if (!stream->Write(status)) { return Status(StatusCode::UNKNOWN, "Client couldn't respond to mark"); } - gpr_log(GPR_INFO, "RunClientBody: Mark response given"); + LOG(INFO) << "RunClientBody: Mark response given"; } - gpr_log(GPR_INFO, "RunClientBody: Awaiting Threads Completion"); + LOG(INFO) << "RunClientBody: Awaiting Threads Completion"; client->AwaitThreadsCompletion(); - gpr_log(GPR_INFO, "RunClientBody: Returning"); + LOG(INFO) << "RunClientBody: Returning"; return Status::OK; } @@ -237,7 +237,7 @@ class WorkerServiceImpl final : public WorkerService::Service { if (server_port_ > 0 && args.setup().port() == 0) { args.mutable_setup()->set_port(server_port_); } - gpr_log(GPR_INFO, "RunServerBody: about to create server"); + LOG(INFO) << "RunServerBody: about to create server"; std::unique_ptr server = CreateServer(args.setup()); if (g_inproc_servers != nullptr) { g_inproc_servers->push_back(server.get()); @@ -245,28 +245,28 @@ class WorkerServiceImpl final : public WorkerService::Service { if (!server) { return Status(StatusCode::INVALID_ARGUMENT, "Couldn't create server"); } - gpr_log(GPR_INFO, "RunServerBody: server created"); + LOG(INFO) << "RunServerBody: server created"; ServerStatus status; status.set_port(server->port()); status.set_cores(server->cores()); if (!stream->Write(status)) { return Status(StatusCode::UNKNOWN, "Server couldn't report init status"); } - gpr_log(GPR_INFO, "RunServerBody: creation status reported"); + LOG(INFO) << "RunServerBody: creation status reported"; while (stream->Read(&args)) { - gpr_log(GPR_INFO, "RunServerBody: Message read"); + LOG(INFO) << "RunServerBody: Message read"; if (!args.has_mark()) { - gpr_log(GPR_INFO, "RunServerBody: Message not a mark!"); + LOG(INFO) << "RunServerBody: Message not a mark!"; return Status(StatusCode::INVALID_ARGUMENT, "Invalid mark"); } *status.mutable_stats() = server->Mark(args.mark().reset()); if (!stream->Write(status)) { return Status(StatusCode::UNKNOWN, "Server couldn't respond to mark"); } - gpr_log(GPR_INFO, "RunServerBody: Mark response given"); + LOG(INFO) << "RunServerBody: Mark response given"; } - gpr_log(GPR_INFO, "RunServerBody: Returning"); + LOG(INFO) << "RunServerBody: Returning"; return Status::OK; } @@ -293,13 +293,11 @@ QpsWorker::QpsWorker(int driver_port, int server_port, server_ = builder->BuildAndStart(); if (server_ == nullptr) { - gpr_log(GPR_ERROR, - "QpsWorker: Fail to BuildAndStart(driver_port=%d, server_port=%d)", - driver_port, server_port); + LOG(ERROR) << "QpsWorker: Fail to BuildAndStart(driver_port=" << driver_port + << ", server_port=" << server_port << ")"; } else { - gpr_log(GPR_INFO, - "QpsWorker: BuildAndStart(driver_port=%d, server_port=%d) done", - driver_port, server_port); + LOG(INFO) << "QpsWorker: BuildAndStart(driver_port=" << driver_port + << ", server_port=" << server_port << ") done"; } } diff --git a/test/cpp/qps/secure_sync_unary_ping_pong_test.cc b/test/cpp/qps/secure_sync_unary_ping_pong_test.cc index a23f9e48802..6829f0dcd29 100644 --- a/test/cpp/qps/secure_sync_unary_ping_pong_test.cc +++ b/test/cpp/qps/secure_sync_unary_ping_pong_test.cc @@ -18,7 +18,7 @@ #include -#include +#include "absl/log/log.h" #include "src/core/lib/gprpp/crash.h" #include "test/core/test_util/test_config.h" @@ -36,7 +36,7 @@ static const int WARMUP = 1; static const int BENCHMARK = 3; static void RunSynchronousUnaryPingPong() { - gpr_log(GPR_INFO, "Running Synchronous Unary Ping Pong"); + LOG(INFO) << "Running Synchronous Unary Ping Pong"; ClientConfig client_config; client_config.set_client_type(SYNC_CLIENT); diff --git a/test/cpp/qps/usage_timer.cc b/test/cpp/qps/usage_timer.cc index ac0584f6bd2..0f717141d25 100644 --- a/test/cpp/qps/usage_timer.cc +++ b/test/cpp/qps/usage_timer.cc @@ -22,7 +22,8 @@ #include #include -#include +#include "absl/log/log.h" + #include #include "src/core/lib/gprpp/crash.h" @@ -74,7 +75,7 @@ static void get_cpu_usage(unsigned long long* total_cpu_time, // Use the parameters to avoid unused-parameter warning (void)total_cpu_time; (void)idle_cpu_time; - gpr_log(GPR_INFO, "get_cpu_usage(): Non-linux platform is not supported."); + LOG(INFO) << "get_cpu_usage(): Non-linux platform is not supported."; #endif } diff --git a/test/cpp/server/load_reporter/load_reporter_test.cc b/test/cpp/server/load_reporter/load_reporter_test.cc index e64356c1389..fd1d4aeef67 100644 --- a/test/cpp/server/load_reporter/load_reporter_test.cc +++ b/test/cpp/server/load_reporter/load_reporter_test.cc @@ -25,6 +25,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "opencensus/stats/testing/test_utils.h" @@ -174,9 +175,8 @@ class LbFeedbackTest : public LoadReporterTest { DoubleNear(expected_qps, expected_qps * 0.3)); ASSERT_THAT(static_cast(lb_feedback.errors_per_second()), DoubleNear(expected_eps, expected_eps * 0.3)); - gpr_log(GPR_INFO, - "Verified LB feedback matches the samples of index [%zu, %zu).", - start, start + count); + LOG(INFO) << "Verified LB feedback matches the samples of index [" << start + << ", " << start + count << ")."; } const std::vector> kQpsEpsSamples = { @@ -487,11 +487,11 @@ TEST_F(LoadReportTest, BasicReport) { // First fetch. load_reporter_->FetchAndSample(); load_reporter_->GenerateLoads(kHostname1, kLbId1); - gpr_log(GPR_INFO, "First load generated."); + LOG(INFO) << "First load generated."; // Second fetch. load_reporter_->FetchAndSample(); load_reporter_->GenerateLoads(kHostname2, kLbId2); - gpr_log(GPR_INFO, "Second load generated."); + LOG(INFO) << "Second load generated."; // TODO(juanlishen): Verify the data. } diff --git a/test/cpp/server/server_request_call_test.cc b/test/cpp/server/server_request_call_test.cc index 8bb02394179..96bbf15400a 100644 --- a/test/cpp/server/server_request_call_test.cc +++ b/test/cpp/server/server_request_call_test.cc @@ -20,9 +20,9 @@ #include +#include "absl/log/log.h" #include "absl/strings/str_format.h" -#include #include #include #include @@ -90,7 +90,7 @@ TEST(ServerRequestCallTest, ShortDeadlineDoesNotCauseOkayFalse) { // Send a simple response after a small delay that would ensure the client // deadline is exceeded. - gpr_log(GPR_INFO, "Got request %d", n); + LOG(INFO) << "Got request " << n; testing::EchoResponse response; response.set_message("foobar"); // A bit of sleep to make sure the deadline elapses. @@ -99,12 +99,11 @@ TEST(ServerRequestCallTest, ShortDeadlineDoesNotCauseOkayFalse) { { std::lock_guard lock(mu); if (shutting_down) { - gpr_log(GPR_INFO, - "shut down while processing call, not calling Finish()"); + LOG(INFO) << "shut down while processing call, not calling Finish()"; // Continue flushing the CQ. continue; } - gpr_log(GPR_INFO, "Finishing request %d", n); + LOG(INFO) << "Finishing request " << n; responder.Finish(response, grpc::Status::OK, reinterpret_cast(2)); if (!cq->Next(&tag, &ok)) { @@ -119,7 +118,7 @@ TEST(ServerRequestCallTest, ShortDeadlineDoesNotCauseOkayFalse) { grpc::CreateChannel(address, InsecureChannelCredentials())); for (int i = 0; i < 100; i++) { - gpr_log(GPR_INFO, "Sending %d.", i); + LOG(INFO) << "Sending " << i; testing::EchoRequest request; ///////// @@ -138,12 +137,12 @@ TEST(ServerRequestCallTest, ShortDeadlineDoesNotCauseOkayFalse) { std::chrono::milliseconds(1)); grpc::Status status = stub->Echo(&ctx, request, &response); EXPECT_EQ(StatusCode::DEADLINE_EXCEEDED, status.error_code()); - gpr_log(GPR_INFO, "Success."); + LOG(INFO) << "Success."; } - gpr_log(GPR_INFO, "Done sending RPCs."); + LOG(INFO) << "Done sending RPCs."; // Shut down everything properly. - gpr_log(GPR_INFO, "Shutting down."); + LOG(INFO) << "Shutting down."; { std::lock_guard lock(mu); shutting_down = true; @@ -226,7 +225,7 @@ TEST(ServerRequestCallTest, MultithreadedUnimplementedService) { } // Shut down everything properly. - gpr_log(GPR_INFO, "Shutting down."); + LOG(INFO) << "Shutting down."; shutdown.store(true); server->Shutdown(); cq->Shutdown(); From a79a8111af512d2013b50521928205c279a60df2 Mon Sep 17 00:00:00 2001 From: Yijie Ma Date: Mon, 20 May 2024 12:09:37 -0700 Subject: [PATCH 20/23] [EventEngine] Enable the EventEngine DNS Resolver on Windows (#36286) Closes #36286 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36286 from yijiem:enable-win-ee-dns 9276c47326383dd60f78d8c20f66ab048f1e928a PiperOrigin-RevId: 635531420 --- bazel/experiments.bzl | 6 ++++++ src/core/lib/experiments/experiments.cc | 2 +- src/core/lib/experiments/experiments.h | 3 ++- src/core/lib/experiments/rollouts.yaml | 4 +--- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bazel/experiments.bzl b/bazel/experiments.bzl index 013e8ae208a..e3aeb05464d 100644 --- a/bazel/experiments.bzl +++ b/bazel/experiments.bzl @@ -74,6 +74,9 @@ EXPERIMENTS = { ], }, "on": { + "cancel_ares_query_test": [ + "event_engine_dns", + ], "core_end2end_test": [ "event_engine_client", "event_engine_listener", @@ -90,6 +93,9 @@ EXPERIMENTS = { "lb_unit_test": [ "pick_first_new", ], + "resolver_component_tests_runner_invoker": [ + "event_engine_dns", + ], "xds_end2end_test": [ "pick_first_new", ], diff --git a/src/core/lib/experiments/experiments.cc b/src/core/lib/experiments/experiments.cc index a8996e8e124..468884ec583 100644 --- a/src/core/lib/experiments/experiments.cc +++ b/src/core/lib/experiments/experiments.cc @@ -328,7 +328,7 @@ const ExperimentMetadata g_experiment_metadata[] = { {"event_engine_client", description_event_engine_client, additional_constraints_event_engine_client, nullptr, 0, true, true}, {"event_engine_dns", description_event_engine_dns, - additional_constraints_event_engine_dns, nullptr, 0, false, false}, + additional_constraints_event_engine_dns, nullptr, 0, true, false}, {"event_engine_listener", description_event_engine_listener, additional_constraints_event_engine_listener, nullptr, 0, true, true}, {"free_large_allocator", description_free_large_allocator, diff --git a/src/core/lib/experiments/experiments.h b/src/core/lib/experiments/experiments.h index db7c9664bcd..9e3ba9148ba 100644 --- a/src/core/lib/experiments/experiments.h +++ b/src/core/lib/experiments/experiments.h @@ -99,7 +99,8 @@ inline bool IsCanaryClientPrivacyEnabled() { return false; } inline bool IsClientPrivacyEnabled() { return false; } #define GRPC_EXPERIMENT_IS_INCLUDED_EVENT_ENGINE_CLIENT inline bool IsEventEngineClientEnabled() { return true; } -inline bool IsEventEngineDnsEnabled() { return false; } +#define GRPC_EXPERIMENT_IS_INCLUDED_EVENT_ENGINE_DNS +inline bool IsEventEngineDnsEnabled() { return true; } #define GRPC_EXPERIMENT_IS_INCLUDED_EVENT_ENGINE_LISTENER inline bool IsEventEngineListenerEnabled() { return true; } inline bool IsFreeLargeAllocatorEnabled() { return false; } diff --git a/src/core/lib/experiments/rollouts.yaml b/src/core/lib/experiments/rollouts.yaml index 97018a672cd..7187f8c2952 100644 --- a/src/core/lib/experiments/rollouts.yaml +++ b/src/core/lib/experiments/rollouts.yaml @@ -64,9 +64,7 @@ # not tested on iOS at all ios: broken posix: true - # TODO(yijiem): resolve when the WindowsEventEngine DNS Resolver is - # implemented - windows: broken + windows: true - name: event_engine_listener default: # not tested on iOS at all From d3960484c01cffab161438207ee174c756260a77 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Mon, 20 May 2024 13:37:08 -0700 Subject: [PATCH 21/23] [StatsPlugin] Fix use-after-free issue (#36664) Fix https://github.com/grpc/grpc/issues/36663 Closes #36664 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36664 from yashykt:StatsPluginFixUseAfterFree 107c34134999298353290e461d4353ade2027496 PiperOrigin-RevId: 635555326 --- src/core/lib/surface/legacy_channel.cc | 12 ++++++------ test/cpp/ext/otel/otel_plugin_test.cc | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/core/lib/surface/legacy_channel.cc b/src/core/lib/surface/legacy_channel.cc index 104924d42b7..d8f53540e32 100644 --- a/src/core/lib/surface/legacy_channel.cc +++ b/src/core/lib/surface/legacy_channel.cc @@ -93,13 +93,13 @@ absl::StatusOr> LegacyChannel::Create( *(*r)->stats_plugin_group = GlobalStatsPluginRegistry::GetStatsPluginsForServer(args); } else { - experimental::StatsPluginChannelScope scope( - target, args.GetOwnedString(GRPC_ARG_DEFAULT_AUTHORITY) - .value_or(CoreConfiguration::Get() - .resolver_registry() - .GetDefaultAuthority(target))); + std::string authority = args.GetOwnedString(GRPC_ARG_DEFAULT_AUTHORITY) + .value_or(CoreConfiguration::Get() + .resolver_registry() + .GetDefaultAuthority(target)); *(*r)->stats_plugin_group = - GlobalStatsPluginRegistry::GetStatsPluginsForChannel(scope); + GlobalStatsPluginRegistry::GetStatsPluginsForChannel( + experimental::StatsPluginChannelScope(target, authority)); } return MakeOrphanable( grpc_channel_stack_type_is_client(builder.channel_stack_type()), diff --git a/test/cpp/ext/otel/otel_plugin_test.cc b/test/cpp/ext/otel/otel_plugin_test.cc index e616f075d13..4cc39847910 100644 --- a/test/cpp/ext/otel/otel_plugin_test.cc +++ b/test/cpp/ext/otel/otel_plugin_test.cc @@ -471,6 +471,28 @@ TEST_F(OpenTelemetryPluginEnd2EndTest, NoMeterProviderRegistered) { SendRPC(); } +// Test that the otel plugin sees the expected channel target and default +// authority. +TEST_F(OpenTelemetryPluginEnd2EndTest, VerifyChannelScopeTargetAndAuthority) { + Init(std::move( + Options() + .set_metric_names({grpc::OpenTelemetryPluginBuilder:: + kClientAttemptStartedInstrumentName}) + .set_channel_scope_filter( + [&](const OpenTelemetryPluginBuilder::ChannelScope& scope) { + return scope.target() == canonical_server_address_ && + scope.default_authority() == server_address_; + }))); + SendRPC(); + const char* kMetricName = "grpc.client.attempt.started"; + auto data = ReadCurrentMetricsData( + [&](const absl::flat_hash_map< + std::string, + std::vector>& + data) { return !data.contains(kMetricName); }); + ASSERT_EQ(data[kMetricName].size(), 1); +} + // Test that a channel scope filter returning true records metrics on the // channel. TEST_F(OpenTelemetryPluginEnd2EndTest, ChannelScopeFilterReturnsTrue) { From a509c6b4e7283666e383dd50a64ef168b3ce2a4b Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Mon, 20 May 2024 16:58:54 -0700 Subject: [PATCH 22/23] [logging] Fix logging for when metrics/tracing is not enabled (#36671) https://github.com/grpc/grpc/pull/36598 made a change to the logging filter which required `CallTracerAnnotationInterface` to always be present on the call. That is only the case when metrics/tracing is enabled, which is not always the case. Also, modify the test to test that logging works even if metrics/tracing is not enabled. Internal ref - b/341794662 Closes #36671 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36671 from yashykt:FixLogging 4f736e7e56ce6ec4eacec869c72f70d46ce2f002 PiperOrigin-RevId: 635610705 --- .../ext/filters/logging/logging_filter.cc | 33 +++++++++++-------- src/core/lib/promise/context.h | 6 ++++ test/cpp/ext/filters/logging/library.h | 1 - .../logging_census_integration_test.cc | 1 + 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/core/ext/filters/logging/logging_filter.cc b/src/core/ext/filters/logging/logging_filter.cc index a89cca9c657..06ee67de012 100644 --- a/src/core/ext/filters/logging/logging_filter.cc +++ b/src/core/ext/filters/logging/logging_filter.cc @@ -369,13 +369,14 @@ void ClientLoggingFilter::Call::OnClientInitialMetadata( return; } call_data_->LogClientHeader( - /*is_client=*/true, GetContext(), md); + /*is_client=*/true, MaybeGetContext(), md); } void ClientLoggingFilter::Call::OnServerInitialMetadata(ServerMetadata& md) { if (!call_data_.has_value()) return; call_data_->LogServerHeader( - /*is_client=*/true, GetContext(), &md); + /*is_client=*/true, MaybeGetContext(), + &md); } void ClientLoggingFilter::Call::OnServerTrailingMetadata(ServerMetadata& md) { @@ -383,32 +384,33 @@ void ClientLoggingFilter::Call::OnServerTrailingMetadata(ServerMetadata& md) { if (md.get(GrpcCallWasCancelled()).value_or(false) && md.get(GrpcStatusMetadata()) == GRPC_STATUS_CANCELLED) { call_data_->LogCancel( - /*is_client=*/true, GetContext()); + /*is_client=*/true, MaybeGetContext()); return; } call_data_->LogServerTrailer( - /*is_client=*/true, GetContext(), &md); + /*is_client=*/true, MaybeGetContext(), + &md); } void ClientLoggingFilter::Call::OnClientToServerMessage( const Message& message) { if (!call_data_.has_value()) return; call_data_->LogClientMessage( - /*is_client=*/true, GetContext(), + /*is_client=*/true, MaybeGetContext(), message.payload()); } void ClientLoggingFilter::Call::OnClientToServerHalfClose() { if (!call_data_.has_value()) return; call_data_->LogClientHalfClose( - /*is_client=*/true, GetContext()); + /*is_client=*/true, MaybeGetContext()); } void ClientLoggingFilter::Call::OnServerToClientMessage( const Message& message) { if (!call_data_.has_value()) return; call_data_->LogServerMessage( - /*is_client=*/true, GetContext(), + /*is_client=*/true, MaybeGetContext(), message.payload()); } @@ -432,13 +434,15 @@ void ServerLoggingFilter::Call::OnClientInitialMetadata(ClientMetadata& md) { return; } call_data_->LogClientHeader( - /*is_client=*/false, GetContext(), md); + /*is_client=*/false, MaybeGetContext(), + md); } void ServerLoggingFilter::Call::OnServerInitialMetadata(ServerMetadata& md) { if (!call_data_.has_value()) return; call_data_->LogServerHeader( - /*is_client=*/false, GetContext(), &md); + /*is_client=*/false, MaybeGetContext(), + &md); } void ServerLoggingFilter::Call::OnServerTrailingMetadata(ServerMetadata& md) { @@ -446,32 +450,33 @@ void ServerLoggingFilter::Call::OnServerTrailingMetadata(ServerMetadata& md) { if (md.get(GrpcCallWasCancelled()).value_or(false) && md.get(GrpcStatusMetadata()) == GRPC_STATUS_CANCELLED) { call_data_->LogCancel( - /*is_client=*/false, GetContext()); + /*is_client=*/false, MaybeGetContext()); return; } call_data_->LogServerTrailer( - /*is_client=*/false, GetContext(), &md); + /*is_client=*/false, MaybeGetContext(), + &md); } void ServerLoggingFilter::Call::OnClientToServerMessage( const Message& message) { if (!call_data_.has_value()) return; call_data_->LogClientMessage( - /*is_client=*/false, GetContext(), + /*is_client=*/false, MaybeGetContext(), message.payload()); } void ServerLoggingFilter::Call::OnClientToServerHalfClose() { if (!call_data_.has_value()) return; call_data_->LogClientHalfClose( - /*is_client=*/false, GetContext()); + /*is_client=*/false, MaybeGetContext()); } void ServerLoggingFilter::Call::OnServerToClientMessage( const Message& message) { if (!call_data_.has_value()) return; call_data_->LogServerMessage( - /*is_client=*/false, GetContext(), + /*is_client=*/false, MaybeGetContext(), message.payload()); } diff --git a/src/core/lib/promise/context.h b/src/core/lib/promise/context.h index 4b1f9ef6369..47b2bac39f2 100644 --- a/src/core/lib/promise/context.h +++ b/src/core/lib/promise/context.h @@ -119,6 +119,12 @@ T* GetContext() { return p; } +// Retrieve the current value of a context, or nullptr if the value is unset. +template +T* MaybeGetContext() { + return promise_detail::Context::get(); +} + // Given a promise and a context, return a promise that has that context set. template promise_detail::WithContext WithContext(F f, T* context) { diff --git a/test/cpp/ext/filters/logging/library.h b/test/cpp/ext/filters/logging/library.h index f1339aa177a..bce76c1a228 100644 --- a/test/cpp/ext/filters/logging/library.h +++ b/test/cpp/ext/filters/logging/library.h @@ -104,7 +104,6 @@ class LoggingTest : public ::testing::Test { protected: static void SetUpTestSuite() { g_test_logging_sink = new TestLoggingSink; - grpc::RegisterOpenCensusPlugin(); grpc_core::RegisterLoggingFilter(g_test_logging_sink); } diff --git a/test/cpp/ext/filters/logging/logging_census_integration_test.cc b/test/cpp/ext/filters/logging/logging_census_integration_test.cc index baff506f59c..b8c196d1c09 100644 --- a/test/cpp/ext/filters/logging/logging_census_integration_test.cc +++ b/test/cpp/ext/filters/logging/logging_census_integration_test.cc @@ -319,5 +319,6 @@ TEST_F(LoggingCensusIntegrationTest, Basic) { int main(int argc, char** argv) { grpc::testing::TestEnvironment env(&argc, argv); ::testing::InitGoogleTest(&argc, argv); + grpc::RegisterOpenCensusPlugin(); return RUN_ALL_TESTS(); } From 5a7a07a7e3b7f0ef2beef2295f1d350012e5cbdb Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Mon, 20 May 2024 17:35:53 -0700 Subject: [PATCH 23/23] [PSM Interop] Skip Circuit Breaking test in the legacy test driver (#36672) Circuit breaking ported to the new framework: https://github.com/grpc/psm-interop/blob/main/tests/circuit_breaking_test.py. To avoid backports, skipping it in the legacy test driver. ref b/227678751 Closes #36672 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36672 from sergiitk:psm-interop-legacy-circuit-breaking 2cebe22a6bf0f4582dfcf7da788723301f77ef2d PiperOrigin-RevId: 635619565 --- .../linux/grpc_xds_bazel_python_test_in_docker.sh | 2 +- .../internal_ci/linux/grpc_xds_bazel_test_in_docker.sh | 2 +- tools/run_tests/run_xds_tests.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/internal_ci/linux/grpc_xds_bazel_python_test_in_docker.sh b/tools/internal_ci/linux/grpc_xds_bazel_python_test_in_docker.sh index f3eefec5833..9821ede6575 100755 --- a/tools/internal_ci/linux/grpc_xds_bazel_python_test_in_docker.sh +++ b/tools/internal_ci/linux/grpc_xds_bazel_python_test_in_docker.sh @@ -69,7 +69,7 @@ export PYTHONUNBUFFERED=true GRPC_VERBOSITY=debug GRPC_TRACE=xds_client,xds_resolver,xds_cluster_manager_lb,cds_lb,xds_cluster_resolver_lb,priority_lb,xds_cluster_impl_lb,weighted_target_lb "$PYTHON" \ /var/local/git/grpc/tools/run_tests/run_xds_tests.py \ --halt_after_fail \ - --test_case="ping_pong,circuit_breaking" \ + --test_case="ping_pong" \ --project_id=grpc-testing \ --project_num=830293263384 \ --source_image=projects/grpc-testing/global/images/xds-test-server-5 \ diff --git a/tools/internal_ci/linux/grpc_xds_bazel_test_in_docker.sh b/tools/internal_ci/linux/grpc_xds_bazel_test_in_docker.sh index cd820579bdf..bcb69ad113c 100755 --- a/tools/internal_ci/linux/grpc_xds_bazel_test_in_docker.sh +++ b/tools/internal_ci/linux/grpc_xds_bazel_test_in_docker.sh @@ -70,7 +70,7 @@ bazel build test/cpp/interop:xds_interop_client GRPC_VERBOSITY=debug GRPC_TRACE=xds_client,xds_resolver,xds_cluster_manager_lb,cds_lb,xds_cluster_resolver_lb,priority_lb,xds_cluster_impl_lb,weighted_target_lb "$PYTHON" \ /var/local/git/grpc/tools/run_tests/run_xds_tests.py \ --halt_after_fail \ - --test_case="ping_pong,circuit_breaking" \ + --test_case="ping_pong" \ --project_id=grpc-testing \ --project_num=830293263384 \ --source_image=projects/grpc-testing/global/images/xds-test-server-5 \ diff --git a/tools/run_tests/run_xds_tests.py b/tools/run_tests/run_xds_tests.py index 9c33ba10b3e..a72f2aa2e14 100755 --- a/tools/run_tests/run_xds_tests.py +++ b/tools/run_tests/run_xds_tests.py @@ -4066,6 +4066,16 @@ try: client_env["GRPC_XDS_EXPERIMENTAL_ENABLE_TIMEOUT"] = "true" client_env["GRPC_XDS_EXPERIMENTAL_FAULT_INJECTION"] = "true" for test_case in args.test_case: + # Circuit breaking ported to the new framework. + # https://github.com/grpc/psm-interop/blob/main/tests/circuit_breaking_test.py + # To avoid backports, skipping it in the driver. + if test_case == "circuit_breaking": + logger.info( + "Ported to https://github.com/grpc/psm-interop/" + "blob/main/tests/circuit_breaking_test.py" + ) + continue + if test_case in _V3_TEST_CASES and not args.xds_v3_support: logger.info( "skipping test %s due to missing v3 support", test_case