From 3b585815a09b42b57e7ee436fddd7c8c413b4e92 Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap <139093547+tanvi-jagtap@users.noreply.github.com> Date: Sat, 15 Jun 2024 05:16:54 -0700 Subject: [PATCH] [Gpr_To_Absl_Logging] Migrating from gpr to absl logging - gpr_log (#36884) [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 #36884 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36884 from tanvi-jagtap:large_file_02 23fdd777ce9644a7a72efaed222e7e31e1943ad7 PiperOrigin-RevId: 643594188 --- .../load_balancing/xds/xds_override_host.cc | 155 ++++++++---------- 1 file changed, 66 insertions(+), 89 deletions(-) diff --git a/src/core/load_balancing/xds/xds_override_host.cc b/src/core/load_balancing/xds/xds_override_host.cc index b2fd8c2c3af..daab6472d1c 100644 --- a/src/core/load_balancing/xds/xds_override_host.cc +++ b/src/core/load_balancing/xds/xds_override_host.cc @@ -45,7 +45,6 @@ #include #include -#include #include #include "src/core/client_channel/client_channel_internal.h" @@ -466,8 +465,8 @@ XdsOverrideHostLb::Picker::Picker( picker_(std::move(picker)), override_host_health_status_set_(override_host_health_status_set) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, "[xds_override_host_lb %p] constructed new picker %p", - policy_.get(), this); + LOG(INFO) << "[xds_override_host_lb " << policy_.get() + << "] constructed new picker " << this; } } @@ -489,18 +488,16 @@ XdsOverrideHostLb::Picker::PickOverridenHost( if (!override_host_health_status_set_.Contains( it->second->eds_health_status())) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "Subchannel %s health status is not overridden (%s)", - std::string(address).c_str(), - it->second->eds_health_status().ToString()); + LOG(INFO) << "Subchannel " << address + << " health status is not overridden (" + << it->second->eds_health_status().ToString() << ")"; } continue; } auto subchannel = it->second->GetSubchannelRef(); if (subchannel == nullptr) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, "No subchannel for %s", - std::string(address).c_str()); + LOG(INFO) << "No subchannel for " << address; } if (address_with_no_subchannel.empty()) { address_with_no_subchannel = it->first; @@ -512,8 +509,7 @@ XdsOverrideHostLb::Picker::PickOverridenHost( // Found a READY subchannel. Pass back the actual address list // and return the subchannel. if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, "Picker override found READY subchannel %s", - std::string(address).c_str()); + LOG(INFO) << "Picker override found READY subchannel " << address; } it->second->set_last_used_time(); override_host_attr->set_actual_address_list(it->second->address_list()); @@ -610,10 +606,8 @@ XdsOverrideHostLb::IdleTimer::IdleTimer(RefCountedPtr policy, // with lock contention and CPU usage due to sweeps over the map. duration = std::max(duration, Duration::Seconds(5)); if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] idle timer %p: subchannel cleanup " - "pass will run in %s", - policy_.get(), this, duration.ToString().c_str()); + LOG(INFO) << "[xds_override_host_lb " << policy_.get() << "] idle timer " + << this << ": subchannel cleanup pass will run in " << duration; } timer_handle_ = policy_->channel_control_helper()->GetEventEngine()->RunAfter( duration, [self = RefAsSubclass()]() mutable { @@ -629,8 +623,8 @@ XdsOverrideHostLb::IdleTimer::IdleTimer(RefCountedPtr policy, void XdsOverrideHostLb::IdleTimer::Orphan() { if (timer_handle_.has_value()) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, "[xds_override_host_lb %p] idle timer %p: cancelling", - policy_.get(), this); + LOG(INFO) << "[xds_override_host_lb " << policy_.get() << "] idle timer " + << this << ": cancelling"; } policy_->channel_control_helper()->GetEventEngine()->Cancel(*timer_handle_); timer_handle_.reset(); @@ -642,8 +636,8 @@ void XdsOverrideHostLb::IdleTimer::OnTimerLocked() { if (timer_handle_.has_value()) { timer_handle_.reset(); if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, "[xds_override_host_lb %p] idle timer %p: timer fired", - policy_.get(), this); + LOG(INFO) << "[xds_override_host_lb " << policy_.get() << "] idle timer " + << this << ": timer fired"; } policy_->CleanupSubchannels(); } @@ -656,21 +650,20 @@ void XdsOverrideHostLb::IdleTimer::OnTimerLocked() { XdsOverrideHostLb::XdsOverrideHostLb(Args args) : LoadBalancingPolicy(std::move(args)) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, "[xds_override_host_lb %p] created", this); + LOG(INFO) << "[xds_override_host_lb " << this << "] created"; } } XdsOverrideHostLb::~XdsOverrideHostLb() { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] destroying xds_override_host LB policy", - this); + LOG(INFO) << "[xds_override_host_lb " << this + << "] destroying xds_override_host LB policy"; } } void XdsOverrideHostLb::ShutdownLocked() { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, "[xds_override_host_lb %p] shutting down", this); + LOG(INFO) << "[xds_override_host_lb " << this << "] shutting down"; } shutting_down_ = true; ResetState(); @@ -703,9 +696,8 @@ void XdsOverrideHostLb::ResetState() { void XdsOverrideHostLb::ReportTransientFailure(absl::Status status) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] reporting TRANSIENT_FAILURE: %s", this, - status.ToString().c_str()); + LOG(INFO) << "[xds_override_host_lb " << this + << "] reporting TRANSIENT_FAILURE: " << status; } ResetState(); channel_control_helper()->UpdateState( @@ -741,10 +733,9 @@ class ChildEndpointIterator final : public EndpointAddressesIterator { XdsHealthStatus status = GetEndpointHealthStatus(endpoint); if (status.status() != XdsHealthStatus::kDraining) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] endpoint %s: not draining, " - "passing to child", - this, endpoint.ToString().c_str()); + LOG(INFO) << "[xds_override_host_lb " << this << "] endpoint " + << endpoint.ToString() + << ": not draining, passing to child"; } callback(endpoint); } @@ -757,7 +748,7 @@ class ChildEndpointIterator final : public EndpointAddressesIterator { absl::Status XdsOverrideHostLb::UpdateLocked(UpdateArgs args) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, "[xds_override_host_lb %p] Received update", this); + LOG(INFO) << "[xds_override_host_lb " << this << "] Received update"; } // Grab new LB policy config. if (args.config == nullptr) { @@ -787,11 +778,11 @@ absl::Status XdsOverrideHostLb::UpdateLocked(UpdateArgs args) { override_host_status_set_ = it->second->cluster->override_host_statuses; connection_idle_timeout_ = it->second->cluster->connection_idle_timeout; if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] override host status set: %s " - "connection idle timeout: %s", - this, override_host_status_set_.ToString().c_str(), - connection_idle_timeout_.ToString().c_str()); + LOG(INFO) << "[xds_override_host_lb " << this + << "] override host status set: " + << override_host_status_set_.ToString() + << " connection idle timeout: " + << connection_idle_timeout_.ToString(); } // Update address map and wrap endpoint iterator for child policy. if (args.addresses.ok()) { @@ -800,8 +791,8 @@ absl::Status XdsOverrideHostLb::UpdateLocked(UpdateArgs args) { std::make_shared(std::move(*args.addresses)); } else { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, "[xds_override_host_lb %p] address error: %s", this, - args.addresses.status().ToString().c_str()); + LOG(INFO) << "[xds_override_host_lb " << this + << "] address error: " << args.addresses.status(); } } // Create child policy if needed. @@ -815,9 +806,8 @@ absl::Status XdsOverrideHostLb::UpdateLocked(UpdateArgs args) { update_args.config = new_config->child_config(); update_args.args = args_; if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] Updating child policy handler %p", this, - child_policy_.get()); + LOG(INFO) << "[xds_override_host_lb " << this + << "] Updating child policy handler " << child_policy_.get(); } return child_policy_->UpdateLocked(std::move(update_args)); } @@ -827,11 +817,10 @@ void XdsOverrideHostLb::MaybeUpdatePickerLocked() { auto xds_override_host_picker = MakeRefCounted( RefAsSubclass(), picker_, override_host_status_set_); if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] updating connectivity: state=%s " - "status=(%s) picker=%p", - this, ConnectivityStateName(state_), status_.ToString().c_str(), - xds_override_host_picker.get()); + LOG(INFO) << "[xds_override_host_lb " << this + << "] updating connectivity: state=" + << ConnectivityStateName(state_) << " status=(" << status_ + << ") picker=" << xds_override_host_picker.get(); } channel_control_helper()->UpdateState(state_, status_, std::move(xds_override_host_picker)); @@ -849,9 +838,8 @@ OrphanablePtr XdsOverrideHostLb::CreateChildPolicyLocked( MakeOrphanable(std::move(lb_policy_args), &xds_override_host_lb_trace); if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] Created new child policy handler %p", - this, lb_policy.get()); + LOG(INFO) << "[xds_override_host_lb " << this + << "] Created new child policy handler " << lb_policy.get(); } // Add our interested_parties pollset_set to that of the newly created // child policy. This will make the child policy progress upon activity on @@ -877,10 +865,10 @@ void XdsOverrideHostLb::UpdateAddressMap( if (status.status() == XdsHealthStatus::kDraining && !override_host_status_set_.Contains(status)) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] endpoint %s: draining but not in " - "override_host_status set -- ignoring", - this, endpoint.ToString().c_str()); + LOG(INFO) << "[xds_override_host_lb " << this << "] endpoint " + << endpoint.ToString() + << ": draining but not in override_host_status set -- " + "ignoring"; } return; } @@ -890,10 +878,8 @@ void XdsOverrideHostLb::UpdateAddressMap( auto key = grpc_sockaddr_to_string(&address, /*normalize=*/false); if (!key.ok()) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] no key for endpoint address; " - "not adding to map", - this); + LOG(INFO) << "[xds_override_host_lb " << this + << "] no key for endpoint address; not adding to map"; } } else { addresses.push_back(*std::move(key)); @@ -922,8 +908,8 @@ void XdsOverrideHostLb::UpdateAddressMap( for (auto it = subchannel_map_.begin(); it != subchannel_map_.end();) { if (addresses_for_map.find(it->first) == addresses_for_map.end()) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, "[xds_override_host_lb %p] removing map key %s", - this, it->first.c_str()); + LOG(INFO) << "[xds_override_host_lb " << this << "] removing map key " + << it->first; } it->second->UnsetSubchannel(&subchannel_refs_to_drop); it = subchannel_map_.erase(it); @@ -937,19 +923,18 @@ void XdsOverrideHostLb::UpdateAddressMap( auto it = subchannel_map_.find(address); if (it == subchannel_map_.end()) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, "[xds_override_host_lb %p] adding map key %s", this, - address.c_str()); + LOG(INFO) << "[xds_override_host_lb " << this << "] adding map key " + << address; } it = subchannel_map_.emplace(address, MakeRefCounted()) .first; } if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] map key %s: setting " - "eds_health_status=%s address_list=%s", - this, address.c_str(), - address_info.eds_health_status.ToString(), - address_info.address_list.c_str()); + LOG(INFO) << "[xds_override_host_lb " << this << "] map key " << address + << ": setting " + << "eds_health_status=" + << address_info.eds_health_status.ToString() + << " address_list=" << address_info.address_list.c_str(); } it->second->set_eds_health_status(address_info.eds_health_status); it->second->set_address_list(std::move(address_info.address_list)); @@ -989,9 +974,8 @@ XdsOverrideHostLb::AdoptSubchannel( void XdsOverrideHostLb::CreateSubchannelForAddress(absl::string_view address) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] creating owned subchannel for %s", this, - std::string(address).c_str()); + LOG(INFO) << "[xds_override_host_lb " << this + << "] creating owned subchannel for " << address; } auto addr = StringToSockaddr(address); CHECK(addr.ok()); @@ -1033,9 +1017,8 @@ void XdsOverrideHostLb::CleanupSubchannels() { auto subchannel = p.second->TakeOwnedSubchannel(); if (subchannel != nullptr) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] dropping subchannel for %s", - this, p.first.c_str()); + LOG(INFO) << "[xds_override_host_lb " << this + << "] dropping subchannel for " << p.first; } subchannel_refs_to_drop.push_back(std::move(subchannel)); } @@ -1061,11 +1044,9 @@ RefCountedPtr XdsOverrideHostLb::Helper::CreateSubchannel( const ChannelArgs& args) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { auto key = grpc_sockaddr_to_string(&address, /*normalize=*/false); - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] creating subchannel for %s, " - "per_address_args=%s, args=%s", - this, key.value_or("").c_str(), - per_address_args.ToString().c_str(), args.ToString().c_str()); + LOG(INFO) << "[xds_override_host_lb " << this + << "] creating subchannel for " << key.value_or("") + << ", per_address_args=" << per_address_args << ", args=" << args; } auto subchannel = parent()->channel_control_helper()->CreateSubchannel( address, per_address_args, args); @@ -1113,9 +1094,8 @@ void XdsOverrideHostLb::SubchannelWrapper::CancelConnectivityStateWatch( void XdsOverrideHostLb::SubchannelWrapper::Orphaned() { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb %p] subchannel wrapper %p orphaned", - policy_.get(), this); + LOG(INFO) << "[xds_override_host_lb " << policy_.get() + << "] subchannel wrapper " << this << " orphaned"; } if (!IsWorkSerializerDispatchEnabled()) { wrapped_subchannel()->CancelConnectivityStateWatch(watcher_); @@ -1227,9 +1207,8 @@ void XdsOverrideHostLb::SubchannelEntry::OnSubchannelWrapperOrphan( if (subchannel != wrapper) return; if (last_used_time_ < (Timestamp::Now() - connection_idle_timeout)) { if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb] removing unowned subchannel wrapper %p", - subchannel); + LOG(INFO) << "[xds_override_host_lb] removing unowned subchannel wrapper " + << subchannel; } subchannel_ = nullptr; } else { @@ -1238,10 +1217,8 @@ void XdsOverrideHostLb::SubchannelEntry::OnSubchannelWrapperOrphan( // the wrapper with the same underlying subchannel, and we hold // our own ref to it. if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - gpr_log(GPR_INFO, - "[xds_override_host_lb] subchannel wrapper %p: cloning " - "to gain ownership", - subchannel); + LOG(INFO) << "[xds_override_host_lb] subchannel wrapper " << subchannel + << ": cloning to gain ownership"; } subchannel_ = wrapper->Clone(); }