[Gpr_To_Absl_Logging] Migrating from gpr to absl logging - gpr_log (#37053)

[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 #37053

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37053 from tanvi-jagtap:large_file_02 54224e3d63
PiperOrigin-RevId: 648565511
pull/37138/head^2
Tanvi Jagtap 5 months ago committed by Copybara-Service
parent 4f951aa32a
commit f9340bc776
  1. 102
      src/core/resolver/xds/xds_dependency_manager.cc

@ -19,6 +19,7 @@
#include <set> #include <set>
#include "absl/log/check.h" #include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/strings/str_join.h" #include "absl/strings/str_join.h"
#include <grpc/support/port_platform.h> #include <grpc/support/port_platform.h>
@ -360,9 +361,8 @@ XdsDependencyManager::XdsDependencyManager(
args_(std::move(args)), args_(std::move(args)),
interested_parties_(interested_parties) { interested_parties_(interested_parties) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, LOG(INFO) << "[XdsDependencyManager " << this
"[XdsDependencyManager %p] starting watch for listener %s", this, << "] starting watch for listener " << listener_resource_name_;
listener_resource_name_.c_str());
} }
auto listener_watcher = MakeRefCounted<ListenerWatcher>(Ref()); auto listener_watcher = MakeRefCounted<ListenerWatcher>(Ref());
listener_watcher_ = listener_watcher.get(); listener_watcher_ = listener_watcher.get();
@ -372,7 +372,7 @@ XdsDependencyManager::XdsDependencyManager(
void XdsDependencyManager::Orphan() { void XdsDependencyManager::Orphan() {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, "[XdsDependencyManager %p] shutting down", this); LOG(INFO) << "[XdsDependencyManager " << this << "] shutting down";
} }
if (listener_watcher_ != nullptr) { if (listener_watcher_ != nullptr) {
XdsListenerResourceType::CancelWatch( XdsListenerResourceType::CancelWatch(
@ -405,8 +405,8 @@ void XdsDependencyManager::Orphan() {
void XdsDependencyManager::OnListenerUpdate( void XdsDependencyManager::OnListenerUpdate(
std::shared_ptr<const XdsListenerResource> listener) { std::shared_ptr<const XdsListenerResource> listener) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, "[XdsDependencyManager %p] received Listener update", LOG(INFO) << "[XdsDependencyManager " << this
this); << "] received Listener update";
} }
if (xds_client_ == nullptr) return; if (xds_client_ == nullptr) return;
const auto* hcm = absl::get_if<XdsListenerResource::HttpConnectionManager>( const auto* hcm = absl::get_if<XdsListenerResource::HttpConnectionManager>(
@ -438,10 +438,9 @@ void XdsDependencyManager::OnListenerUpdate(
// Start watch for the new RDS resource name. // Start watch for the new RDS resource name.
route_config_name_ = rds_name; route_config_name_ = rds_name;
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log( LOG(INFO) << "[XdsDependencyManager " << this
GPR_INFO, << "] starting watch for route config "
"[XdsDependencyManager %p] starting watch for route config %s", << route_config_name_;
this, route_config_name_.c_str());
} }
auto watcher = auto watcher =
MakeRefCounted<RouteConfigWatcher>(Ref(), route_config_name_); MakeRefCounted<RouteConfigWatcher>(Ref(), route_config_name_);
@ -526,9 +525,9 @@ void XdsDependencyManager::OnRouteConfigUpdate(
const std::string& name, const std::string& name,
std::shared_ptr<const XdsRouteConfigResource> route_config) { std::shared_ptr<const XdsRouteConfigResource> route_config) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, LOG(INFO) << "[XdsDependencyManager " << this
"[XdsDependencyManager %p] received RouteConfig update for %s", << "] received RouteConfig update for "
this, name.empty() ? "<inline>" : name.c_str()); << (name.empty() ? "<inline>" : name);
} }
if (xds_client_ == nullptr) return; if (xds_client_ == nullptr) return;
// Ignore updates for stale names. // Ignore updates for stale names.
@ -561,10 +560,9 @@ void XdsDependencyManager::OnRouteConfigUpdate(
void XdsDependencyManager::OnError(std::string context, absl::Status status) { void XdsDependencyManager::OnError(std::string context, absl::Status status) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, LOG(INFO) << "[XdsDependencyManager " << this
"[XdsDependencyManager %p] received Listener or RouteConfig " << "] received Listener or RouteConfig error: " << context << " "
"error: %s %s", << status;
this, context.c_str(), status.ToString().c_str());
} }
if (xds_client_ == nullptr) return; if (xds_client_ == nullptr) return;
if (current_virtual_host_ != nullptr) return; if (current_virtual_host_ != nullptr) return;
@ -573,7 +571,7 @@ void XdsDependencyManager::OnError(std::string context, absl::Status status) {
void XdsDependencyManager::OnResourceDoesNotExist(std::string context) { void XdsDependencyManager::OnResourceDoesNotExist(std::string context) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, "[XdsDependencyManager %p] %s", this, context.c_str()); LOG(INFO) << "[XdsDependencyManager " << this << "] " << context;
} }
if (xds_client_ == nullptr) return; if (xds_client_ == nullptr) return;
current_virtual_host_ = nullptr; current_virtual_host_ = nullptr;
@ -584,8 +582,8 @@ void XdsDependencyManager::OnClusterUpdate(
const std::string& name, const std::string& name,
std::shared_ptr<const XdsClusterResource> cluster) { std::shared_ptr<const XdsClusterResource> cluster) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, "[XdsDependencyManager %p] received Cluster update: %s", LOG(INFO) << "[XdsDependencyManager " << this
this, name.c_str()); << "] received Cluster update: " << name;
} }
if (xds_client_ == nullptr) return; if (xds_client_ == nullptr) return;
auto it = cluster_watchers_.find(name); auto it = cluster_watchers_.find(name);
@ -597,8 +595,8 @@ void XdsDependencyManager::OnClusterUpdate(
void XdsDependencyManager::OnClusterError(const std::string& name, void XdsDependencyManager::OnClusterError(const std::string& name,
absl::Status status) { absl::Status status) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, "[XdsDependencyManager %p] received Cluster error: %s %s", LOG(INFO) << "[XdsDependencyManager " << this
this, name.c_str(), status.ToString().c_str()); << "] received Cluster error: " << name << " " << status;
} }
if (xds_client_ == nullptr) return; if (xds_client_ == nullptr) return;
auto it = cluster_watchers_.find(name); auto it = cluster_watchers_.find(name);
@ -612,8 +610,8 @@ void XdsDependencyManager::OnClusterError(const std::string& name,
void XdsDependencyManager::OnClusterDoesNotExist(const std::string& name) { void XdsDependencyManager::OnClusterDoesNotExist(const std::string& name) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, "[XdsDependencyManager %p] Cluster does not exist: %s", LOG(INFO) << "[XdsDependencyManager " << this
this, name.c_str()); << "] Cluster does not exist: " << name;
} }
if (xds_client_ == nullptr) return; if (xds_client_ == nullptr) return;
auto it = cluster_watchers_.find(name); auto it = cluster_watchers_.find(name);
@ -627,8 +625,8 @@ void XdsDependencyManager::OnEndpointUpdate(
const std::string& name, const std::string& name,
std::shared_ptr<const XdsEndpointResource> endpoint) { std::shared_ptr<const XdsEndpointResource> endpoint) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, "[XdsDependencyManager %p] received Endpoint update: %s", LOG(INFO) << "[XdsDependencyManager " << this
this, name.c_str()); << "] received Endpoint update: " << name;
} }
if (xds_client_ == nullptr) return; if (xds_client_ == nullptr) return;
auto it = endpoint_watchers_.find(name); auto it = endpoint_watchers_.find(name);
@ -659,9 +657,8 @@ void XdsDependencyManager::OnEndpointUpdate(
void XdsDependencyManager::OnEndpointError(const std::string& name, void XdsDependencyManager::OnEndpointError(const std::string& name,
absl::Status status) { absl::Status status) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, LOG(INFO) << "[XdsDependencyManager " << this
"[XdsDependencyManager %p] received Endpoint error: %s %s", this, << "] received Endpoint error: " << name << " " << status;
name.c_str(), status.ToString().c_str());
} }
if (xds_client_ == nullptr) return; if (xds_client_ == nullptr) return;
auto it = endpoint_watchers_.find(name); auto it = endpoint_watchers_.find(name);
@ -675,8 +672,8 @@ void XdsDependencyManager::OnEndpointError(const std::string& name,
void XdsDependencyManager::OnEndpointDoesNotExist(const std::string& name) { void XdsDependencyManager::OnEndpointDoesNotExist(const std::string& name) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, "[XdsDependencyManager %p] Endpoint does not exist: %s", LOG(INFO) << "[XdsDependencyManager " << this
this, name.c_str()); << "] Endpoint does not exist: " << name;
} }
if (xds_client_ == nullptr) return; if (xds_client_ == nullptr) return;
auto it = endpoint_watchers_.find(name); auto it = endpoint_watchers_.find(name);
@ -690,8 +687,8 @@ void XdsDependencyManager::OnEndpointDoesNotExist(const std::string& name) {
void XdsDependencyManager::OnDnsResult(const std::string& dns_name, void XdsDependencyManager::OnDnsResult(const std::string& dns_name,
Resolver::Result result) { Resolver::Result result) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, "[XdsDependencyManager %p] received DNS update: %s", this, LOG(INFO) << "[XdsDependencyManager " << this
dns_name.c_str()); << "] received DNS update: " << dns_name;
} }
if (xds_client_ == nullptr) return; if (xds_client_ == nullptr) return;
auto it = dns_resolvers_.find(dns_name); auto it = dns_resolvers_.find(dns_name);
@ -749,9 +746,8 @@ bool XdsDependencyManager::PopulateClusterConfigMap(
if (state.watcher == nullptr) { if (state.watcher == nullptr) {
auto watcher = MakeRefCounted<ClusterWatcher>(Ref(), name); auto watcher = MakeRefCounted<ClusterWatcher>(Ref(), name);
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, LOG(INFO) << "[XdsDependencyManager " << this
"[XdsDependencyManager %p] starting watch for cluster %s", this, << "] starting watch for cluster " << name;
std::string(name).c_str());
} }
state.watcher = watcher.get(); state.watcher = watcher.get();
XdsClusterResourceType::StartWatch(xds_client_.get(), name, XdsClusterResourceType::StartWatch(xds_client_.get(), name,
@ -777,9 +773,8 @@ bool XdsDependencyManager::PopulateClusterConfigMap(
auto& eds_state = endpoint_watchers_[eds_resource_name]; auto& eds_state = endpoint_watchers_[eds_resource_name];
if (eds_state.watcher == nullptr) { if (eds_state.watcher == nullptr) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, LOG(INFO) << "[XdsDependencyManager " << this
"[XdsDependencyManager %p] starting watch for endpoint %s", << "] starting watch for endpoint " << eds_resource_name;
this, std::string(eds_resource_name).c_str());
} }
auto watcher = auto watcher =
MakeRefCounted<EndpointWatcher>(Ref(), eds_resource_name); MakeRefCounted<EndpointWatcher>(Ref(), eds_resource_name);
@ -806,9 +801,8 @@ bool XdsDependencyManager::PopulateClusterConfigMap(
auto& dns_state = dns_resolvers_[logical_dns.hostname]; auto& dns_state = dns_resolvers_[logical_dns.hostname];
if (dns_state.resolver == nullptr) { if (dns_state.resolver == nullptr) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, LOG(INFO) << "[XdsDependencyManager " << this
"[XdsDependencyManager %p] starting DNS resolver for %s", << "] starting DNS resolver for " << logical_dns.hostname;
this, logical_dns.hostname.c_str());
} }
auto* fake_resolver_response_generator = args_.GetPointer< auto* fake_resolver_response_generator = args_.GetPointer<
FakeResolverResponseGenerator>( FakeResolverResponseGenerator>(
@ -974,9 +968,8 @@ void XdsDependencyManager::MaybeReportUpdate() {
continue; continue;
} }
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, LOG(INFO) << "[XdsDependencyManager " << this
"[XdsDependencyManager %p] cancelling watch for cluster %s", this, << "] cancelling watch for cluster " << cluster_name;
cluster_name.c_str());
} }
XdsClusterResourceType::CancelWatch(xds_client_.get(), cluster_name, XdsClusterResourceType::CancelWatch(xds_client_.get(), cluster_name,
it->second.watcher, it->second.watcher,
@ -993,9 +986,8 @@ void XdsDependencyManager::MaybeReportUpdate() {
continue; continue;
} }
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, LOG(INFO) << "[XdsDependencyManager " << this
"[XdsDependencyManager %p] cancelling watch for EDS resource %s", << "] cancelling watch for EDS resource " << eds_resource_name;
this, eds_resource_name.c_str());
} }
XdsEndpointResourceType::CancelWatch(xds_client_.get(), eds_resource_name, XdsEndpointResourceType::CancelWatch(xds_client_.get(), eds_resource_name,
it->second.watcher, it->second.watcher,
@ -1011,24 +1003,22 @@ void XdsDependencyManager::MaybeReportUpdate() {
continue; continue;
} }
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, LOG(INFO) << "[XdsDependencyManager " << this
"[XdsDependencyManager %p] shutting down DNS resolver for %s", << "] shutting down DNS resolver for " << dns_name;
this, dns_name.c_str());
} }
dns_resolvers_.erase(it++); dns_resolvers_.erase(it++);
} }
// If we have all the data we need, then send an update. // If we have all the data we need, then send an update.
if (!have_all_resources) { if (!have_all_resources) {
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, LOG(INFO) << "[XdsDependencyManager " << this
"[XdsDependencyManager %p] missing data -- NOT returning config", << "] missing data -- NOT returning config";
this);
} }
return; return;
} }
if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) {
gpr_log(GPR_INFO, "[XdsDependencyManager %p] returning config: %s", this, LOG(INFO) << "[XdsDependencyManager " << this
config->ToString().c_str()); << "] returning config: " << config->ToString();
} }
watcher_->OnUpdate(std::move(config)); watcher_->OnUpdate(std::move(config));
} }

Loading…
Cancel
Save