[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
pull/36619/head
Tanvi Jagtap 12 months ago committed by Copybara-Service
parent 2d2d5a3c41
commit 841af82bba
  1. 3
      src/core/lib/security/authorization/evaluate_args.cc
  2. 3
      src/core/lib/security/context/security_context.cc
  3. 4
      src/core/lib/security/credentials/alts/check_gcp_environment.cc
  4. 3
      src/core/lib/security/credentials/call_creds_util.cc
  5. 3
      src/core/lib/security/credentials/google_default/google_default_credentials.cc
  6. 19
      src/core/lib/security/credentials/jwt/json_token.cc
  7. 3
      src/core/lib/security/credentials/jwt/jwt_credentials.cc
  8. 15
      src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
  9. 3
      src/core/lib/security/credentials/plugin/plugin_credentials.cc
  10. 9
      src/core/lib/security/credentials/ssl/ssl_credentials.cc
  11. 3
      src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc
  12. 9
      src/core/lib/security/credentials/tls/tls_credentials.cc
  13. 6
      src/core/lib/security/security_connector/load_system_roots_supported.cc
  14. 3
      src/core/lib/security/security_connector/ssl/ssl_security_connector.cc
  15. 15
      src/core/lib/security/security_connector/ssl_utils.cc
  16. 5
      src/core/lib/security/security_connector/tls/tls_security_connector.cc

@ -16,6 +16,7 @@
#include <string.h>
#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 = 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;

@ -23,6 +23,7 @@
#include <algorithm>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include <grpc/credentials.h>
#include <grpc/grpc_security.h>
@ -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<grpc_client_security_context*>(

@ -22,6 +22,8 @@
#include <stdio.h>
#include <string.h>
#include "absl/log/log.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
@ -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];

@ -18,6 +18,7 @@
#include <string.h>
#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) {

@ -24,6 +24,7 @@
#include <string>
#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<grpc_channel_security_connector> sc =

@ -30,6 +30,7 @@
#include <openssl/rsa.h>
#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<size_t>(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<unsigned char*>(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 =

@ -25,6 +25,7 @@
#include <utility>
#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_call_credentials>
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<grpc_service_account_jwt_access_credentials>(

@ -28,6 +28,7 @@
#include <vector>
#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_call_credentials>
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<grpc_google_refresh_token_credentials>(

@ -22,6 +22,7 @@
#include <memory>
#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;
}

@ -24,6 +24,7 @@
#include <utility>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/types/optional.h"
#include <grpc/impl/channel_arg_names.h>
@ -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<grpc_ssl_server_credentials_options*>(
@ -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;
}

@ -21,6 +21,7 @@
#include <memory>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include <grpc/grpc_crl_provider.h>
#include <grpc/support/log.h>
@ -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 : "");
}

@ -22,6 +22,7 @@
#include <string>
#include <utility>
#include "absl/log/log.h"
#include "absl/types/optional.h"
#include <grpc/grpc.h>
@ -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;
}

@ -32,6 +32,8 @@
#include <sys/stat.h>
#include <unistd.h>
#include "absl/log/log.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -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;
}
}
}

@ -25,6 +25,7 @@
#include <utility>
#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;
}

@ -26,6 +26,7 @@
#include <vector>
#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<absl::string_view> 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_auth_context> 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();

@ -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.";
}
}
}

Loading…
Cancel
Save