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

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37069 from tanvi-jagtap:src_core_lib_security a95b1b9543
PiperOrigin-RevId: 647857734
pull/37105/head
Tanvi Jagtap 5 months ago committed by Copybara-Service
parent fcb8b2c92f
commit a54538f125
  1. 16
      src/core/lib/security/authorization/grpc_authorization_policy_provider.cc
  2. 27
      src/core/lib/security/authorization/grpc_server_authz_filter.cc
  3. 9
      src/core/lib/security/context/security_context.cc
  4. 22
      src/core/lib/security/credentials/jwt/jwt_credentials.cc
  5. 28
      src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
  6. 23
      src/core/lib/security/credentials/plugin/plugin_credentials.cc
  7. 6
      src/core/lib/security/security_connector/security_connector.cc
  8. 16
      src/core/lib/security/transport/server_auth_filter.cc

@ -19,12 +19,12 @@
#include <utility>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/types/optional.h"
#include <grpc/grpc_security.h>
#include <grpc/slice.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/string_util.h>
#include <grpc/support/time.h>
@ -114,10 +114,9 @@ FileWatcherAuthorizationPolicyProvider::FileWatcherAuthorizationPolicyProvider(
}
absl::Status status = provider->ForceUpdate();
if (GRPC_TRACE_FLAG_ENABLED(grpc_authz_api) && !status.ok()) {
gpr_log(GPR_ERROR,
"authorization policy reload status. code=%d error_details=%s",
static_cast<int>(status.code()),
std::string(status.message()).c_str());
LOG(ERROR) << "authorization policy reload status. code="
<< static_cast<int>(status.code())
<< " error_details=" << status.message();
}
}
};
@ -169,10 +168,9 @@ absl::Status FileWatcherAuthorizationPolicyProvider::ForceUpdate() {
cb_(contents_changed, absl::OkStatus());
}
if (GRPC_TRACE_FLAG_ENABLED(grpc_authz_api)) {
gpr_log(GPR_INFO,
"authorization policy reload status: successfully loaded new "
"policy\n%s",
file_contents_.c_str());
LOG(INFO) << "authorization policy reload status: successfully loaded new "
"policy\n"
<< file_contents_;
}
return absl::OkStatus();
}

@ -19,10 +19,10 @@
#include <string>
#include <utility>
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/str_join.h"
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include "src/core/lib/channel/channel_stack.h"
@ -65,14 +65,11 @@ GrpcServerAuthzFilter::Create(const ChannelArgs& args, ChannelFilter::Args) {
bool GrpcServerAuthzFilter::IsAuthorized(ClientMetadata& initial_metadata) {
EvaluateArgs args(&initial_metadata, &per_channel_evaluate_args_);
if (GRPC_TRACE_FLAG_ENABLED(grpc_authz_api)) {
gpr_log(GPR_DEBUG,
"checking request: url_path=%s, transport_security_type=%s, "
"uri_sans=[%s], dns_sans=[%s], subject=%s",
std::string(args.GetPath()).c_str(),
std::string(args.GetTransportSecurityType()).c_str(),
absl::StrJoin(args.GetUriSans(), ",").c_str(),
absl::StrJoin(args.GetDnsSans(), ",").c_str(),
std::string(args.GetSubject()).c_str());
VLOG(2) << "checking request: url_path=" << args.GetPath()
<< ", transport_security_type=" << args.GetTransportSecurityType()
<< ", uri_sans=[" << absl::StrJoin(args.GetUriSans(), ",")
<< "], dns_sans=[" << absl::StrJoin(args.GetDnsSans(), ",")
<< "], subject=" << args.GetSubject();
}
grpc_authorization_policy_provider::AuthorizationEngines engines =
provider_->engines();
@ -81,8 +78,8 @@ bool GrpcServerAuthzFilter::IsAuthorized(ClientMetadata& initial_metadata) {
engines.deny_engine->Evaluate(args);
if (decision.type == AuthorizationEngine::Decision::Type::kDeny) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_authz_api)) {
gpr_log(GPR_INFO, "chand=%p: request denied by policy %s.", this,
decision.matching_policy_name.c_str());
LOG(INFO) << "chand=" << this << ": request denied by policy "
<< decision.matching_policy_name;
}
return false;
}
@ -92,15 +89,15 @@ bool GrpcServerAuthzFilter::IsAuthorized(ClientMetadata& initial_metadata) {
engines.allow_engine->Evaluate(args);
if (decision.type == AuthorizationEngine::Decision::Type::kAllow) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_authz_api)) {
gpr_log(GPR_DEBUG, "chand=%p: request allowed by policy %s.", this,
decision.matching_policy_name.c_str());
VLOG(2) << "chand=" << this << ": request allowed by policy "
<< decision.matching_policy_name;
}
return true;
}
}
if (GRPC_TRACE_FLAG_ENABLED(grpc_authz_api)) {
gpr_log(GPR_INFO, "chand=%p: request denied, no matching policy found.",
this);
LOG(INFO) << "chand=" << this
<< ": request denied, no matching policy found.";
}
return false;
}

@ -28,7 +28,6 @@
#include <grpc/credentials.h>
#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/string_util.h>
@ -157,8 +156,8 @@ int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context* ctx,
"grpc_auth_context_set_peer_identity_property_name(ctx=%p, name=%s)", 2,
(ctx, name));
if (prop == nullptr) {
gpr_log(GPR_ERROR, "Property name %s not found in auth context.",
name != nullptr ? name : "NULL");
LOG(ERROR) << "Property name " << (name != nullptr ? name : "NULL")
<< " not found in auth context.";
return 0;
}
ctx->set_peer_identity_property_name(prop->name);
@ -311,8 +310,8 @@ grpc_arg grpc_auth_context_to_arg(grpc_auth_context* c) {
grpc_auth_context* grpc_auth_context_from_arg(const grpc_arg* arg) {
if (strcmp(arg->key, GRPC_AUTH_CONTEXT_ARG) != 0) return nullptr;
if (arg->type != GRPC_ARG_POINTER) {
gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type,
GRPC_AUTH_CONTEXT_ARG);
LOG(ERROR) << "Invalid type " << arg->type << " for arg "
<< GRPC_AUTH_CONTEXT_ARG;
return nullptr;
}
return static_cast<grpc_auth_context*>(arg->value.pointer.p);

@ -32,7 +32,6 @@
#include <grpc/credentials.h>
#include <grpc/support/alloc.h>
#include <grpc/support/json.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
@ -117,9 +116,8 @@ grpc_service_account_jwt_access_credentials::
: key_(key) {
gpr_timespec max_token_lifetime = grpc_max_auth_token_lifetime();
if (gpr_time_cmp(token_lifetime, max_token_lifetime) > 0) {
gpr_log(GPR_INFO,
"Cropping token lifetime to maximum allowed value (%d secs).",
static_cast<int>(max_token_lifetime.tv_sec));
LOG(INFO) << "Cropping token lifetime to maximum allowed value ("
<< max_token_lifetime.tv_sec << " secs).";
token_lifetime = grpc_max_auth_token_lifetime();
}
jwt_lifetime_ = token_lifetime;
@ -158,15 +156,13 @@ grpc_call_credentials* grpc_service_account_jwt_access_credentials_create(
const char* json_key, gpr_timespec token_lifetime, void* reserved) {
if (GRPC_TRACE_FLAG_ENABLED(api)) {
char* clean_json = redact_private_key(json_key);
gpr_log(GPR_INFO,
"grpc_service_account_jwt_access_credentials_create("
"json_key=%s, "
"token_lifetime="
"gpr_timespec { tv_sec: %" PRId64
", tv_nsec: %d, clock_type: %d }, "
"reserved=%p)",
clean_json, token_lifetime.tv_sec, token_lifetime.tv_nsec,
static_cast<int>(token_lifetime.clock_type), reserved);
LOG(INFO) << "grpc_service_account_jwt_access_credentials_create("
<< "json_key=" << clean_json
<< ", token_lifetime=gpr_timespec { tv_sec: "
<< token_lifetime.tv_sec
<< ", tv_nsec: " << token_lifetime.tv_nsec
<< ", clock_type: " << token_lifetime.clock_type
<< " }, reserved=" << reserved << ")";
gpr_free(clean_json);
}
CHECK_EQ(reserved, nullptr);

@ -41,7 +41,6 @@
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
#include <grpc/support/json.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/string_util.h>
#include <grpc/support/time.h>
@ -118,8 +117,7 @@ grpc_auth_refresh_token grpc_auth_refresh_token_create_from_string(
Json json;
auto json_or = grpc_core::JsonParse(json_string);
if (!json_or.ok()) {
gpr_log(GPR_ERROR, "JSON parsing failed: %s",
json_or.status().ToString().c_str());
LOG(ERROR) << "JSON parsing failed: " << json_or.status();
} else {
json = std::move(*json_or);
}
@ -175,9 +173,10 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response(
}
if (response->status != 200) {
gpr_log(GPR_ERROR, "Call to http server ended with error %d [%s].",
response->status,
null_terminated_body != nullptr ? null_terminated_body : "");
LOG(ERROR) << "Call to http server ended with error " << response->status
<< " ["
<< (null_terminated_body != nullptr ? null_terminated_body : "")
<< "]";
status = GRPC_CREDENTIALS_ERROR;
goto end;
} else {
@ -188,8 +187,8 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response(
auto json = grpc_core::JsonParse(
null_terminated_body != nullptr ? null_terminated_body : "");
if (!json.ok()) {
gpr_log(GPR_ERROR, "Could not parse JSON from %s: %s",
null_terminated_body, json.status().ToString().c_str());
LOG(ERROR) << "Could not parse JSON from " << null_terminated_body << ": "
<< json.status();
status = GRPC_CREDENTIALS_ERROR;
goto end;
}
@ -514,10 +513,9 @@ grpc_call_credentials* grpc_google_refresh_token_credentials_create(
grpc_auth_refresh_token token =
grpc_auth_refresh_token_create_from_string(json_refresh_token);
if (GRPC_TRACE_FLAG_ENABLED(api)) {
gpr_log(GPR_INFO,
"grpc_refresh_token_credentials_create(json_refresh_token=%s, "
"reserved=%p)",
create_loggable_refresh_token(&token).c_str(), reserved);
LOG(INFO) << "grpc_refresh_token_credentials_create(json_refresh_token="
<< create_loggable_refresh_token(&token)
<< ", reserved=" << reserved << ")";
}
CHECK_EQ(reserved, nullptr);
return grpc_refresh_token_credentials_create_from_auth_refresh_token(token)
@ -542,7 +540,7 @@ grpc_error_handle LoadTokenFile(const char* path, grpc_slice* token) {
auto slice = LoadFile(path, /*add_null_terminator=*/true);
if (!slice.ok()) return slice.status();
if (slice->length() == 0) {
gpr_log(GPR_ERROR, "Token file %s is empty", path);
LOG(ERROR) << "Token file " << path << " is empty";
return GRPC_ERROR_CREATE("Token file is empty.");
}
*token = slice->TakeCSlice();
@ -706,8 +704,8 @@ grpc_call_credentials* grpc_sts_credentials_create(
absl::StatusOr<grpc_core::URI> sts_url =
grpc_core::ValidateStsCredentialsOptions(options);
if (!sts_url.ok()) {
gpr_log(GPR_ERROR, "STS Credentials creation failed. Error: %s.",
sts_url.status().ToString().c_str());
LOG(ERROR) << "STS Credentials creation failed. Error: "
<< sts_url.status();
return nullptr;
}
return grpc_core::MakeRefCounted<grpc_core::StsTokenFetcherCredentials>(

@ -28,7 +28,6 @@
#include "absl/strings/string_view.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include "src/core/lib/iomgr/error.h"
@ -124,10 +123,8 @@ void grpc_plugin_credentials::PendingRequest::RequestMetadataReady(
grpc_core::RefCountedPtr<grpc_plugin_credentials::PendingRequest> r(
static_cast<grpc_plugin_credentials::PendingRequest*>(request));
if (GRPC_TRACE_FLAG_ENABLED(plugin_credentials)) {
gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p: plugin returned "
"asynchronously",
r->creds(), r.get());
LOG(INFO) << "plugin_credentials[" << r->creds() << "]: request " << r.get()
<< ": plugin returned asynchronously";
}
for (size_t i = 0; i < num_md; ++i) {
grpc_metadata p;
@ -155,8 +152,8 @@ grpc_plugin_credentials::GetRequestMetadata(
args);
// Invoke the plugin. The callback holds a ref to us.
if (GRPC_TRACE_FLAG_ENABLED(plugin_credentials)) {
gpr_log(GPR_INFO, "plugin_credentials[%p]: request %p: invoking plugin",
this, request.get());
LOG(INFO) << "plugin_credentials[" << this << "]: request " << request.get()
<< ": invoking plugin";
}
grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX];
size_t num_creds_md = 0;
@ -173,19 +170,15 @@ grpc_plugin_credentials::GetRequestMetadata(
&status, &error_details)) {
child_request.release();
if (GRPC_TRACE_FLAG_ENABLED(plugin_credentials)) {
gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p: plugin will return "
"asynchronously",
this, request.get());
LOG(INFO) << "plugin_credentials[" << this << "]: request "
<< request.get() << ": plugin will return asynchronously";
}
return [request] { return request->PollAsyncResult(); };
}
// Synchronous return.
if (GRPC_TRACE_FLAG_ENABLED(plugin_credentials)) {
gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p: plugin returned "
"synchronously",
this, request.get());
LOG(INFO) << "plugin_credentials[" << this << "]: request " << request.get()
<< ": plugin returned synchronously";
}
auto result = request->ProcessPluginResult(creds_md, num_creds_md, status,
error_details);

@ -23,8 +23,8 @@
#include <utility>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include "src/core/lib/channel/channel_args.h"
@ -105,8 +105,8 @@ grpc_arg grpc_security_connector_to_arg(grpc_security_connector* sc) {
grpc_security_connector* grpc_security_connector_from_arg(const grpc_arg* arg) {
if (strcmp(arg->key, GRPC_ARG_SECURITY_CONNECTOR) != 0) return nullptr;
if (arg->type != GRPC_ARG_POINTER) {
gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type,
GRPC_ARG_SECURITY_CONNECTOR);
LOG(ERROR) << "Invalid type " << arg->type << " for arg "
<< GRPC_ARG_SECURITY_CONNECTOR;
return nullptr;
}
return static_cast<grpc_security_connector*>(arg->value.pointer.p);

@ -24,6 +24,7 @@
#include <utility>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
@ -32,7 +33,6 @@
#include <grpc/grpc_security.h>
#include <grpc/status.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include "src/core/lib/channel/channel_args.h"
@ -132,11 +132,10 @@ ServerAuthFilter::RunApplicationCode::RunApplicationCode(
ServerAuthFilter* filter, ClientMetadata& metadata)
: state_(GetContext<Arena>()->ManagedNew<State>(metadata)) {
if (GRPC_TRACE_FLAG_ENABLED(call)) {
gpr_log(GPR_ERROR,
"%s[server-auth]: Delegate to application: filter=%p this=%p "
"auth_ctx=%p",
GetContext<Activity>()->DebugTag().c_str(), filter, this,
filter->auth_context_.get());
LOG(ERROR) << GetContext<Activity>()->DebugTag()
<< "[server-auth]: Delegate to application: filter=" << filter
<< " this=" << this
<< " auth_ctx=" << filter->auth_context_.get();
}
filter->server_credentials_->auth_metadata_processor().process(
filter->server_credentials_->auth_metadata_processor().state,
@ -162,9 +161,8 @@ void ServerAuthFilter::RunApplicationCode::OnMdProcessingDone(
// TODO(ZhenLian): Implement support for response_md.
if (response_md != nullptr && num_response_md > 0) {
gpr_log(GPR_ERROR,
"response_md in auth metadata processing not supported for now. "
"Ignoring...");
LOG(ERROR) << "response_md in auth metadata processing not supported for "
"now. Ignoring...";
}
if (status == GRPC_STATUS_OK) {

Loading…
Cancel
Save