Skip to content

Commit

Permalink
[export] [grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl loggi…
Browse files Browse the repository at this point in the history
…ng - 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.

----
DO NOT SUBMIT. This PR is for testing purposes only. [cl/633802443](http://cl/633802443)

PiperOrigin-RevId: 633802443
  • Loading branch information
tanvi-jagtap authored and Copybara-Service committed May 15, 2024
1 parent befeeba commit c3bcc4a
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 109 deletions.
25 changes: 12 additions & 13 deletions src/core/tsi/alts/frame_protector/alts_frame_protector.cc
Expand Up @@ -24,10 +24,10 @@
#include <algorithm>
#include <memory>

#include "absl/log/log.h"
#include "absl/types/span.h"

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>

#include "src/core/lib/gprpp/memory.h"
Expand Down Expand Up @@ -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;
}
Expand All @@ -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<alts_frame_protector*>(self);
Expand All @@ -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;
}
}
Expand All @@ -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;
Expand All @@ -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<alts_frame_protector*>(self);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<alts_frame_protector*>(self);
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -370,16 +370,15 @@ 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;
alts_frame_protector* impl = grpc_core::Zalloc<alts_frame_protector>();
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;
}
Expand Down
50 changes: 23 additions & 27 deletions src/core/tsi/alts/handshaker/alts_handshaker_client.cc
Expand Up @@ -21,6 +21,7 @@
#include <list>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/strings/numbers.h"
#include "upb/mem/arena.hpp"

Expand Down Expand Up @@ -205,13 +206,11 @@ 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()",
Expand All @@ -220,14 +219,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);
Expand All @@ -249,7 +248,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);
Expand All @@ -258,7 +257,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;
Expand All @@ -281,7 +280,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);
Expand All @@ -299,7 +298,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
Expand Down Expand Up @@ -357,7 +356,7 @@ static tsi_result continue_make_grpc_call(alts_grpc_handshaker_client* client,
if (client->grpc_caller(client->call, ops, static_cast<size_t>(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;
Expand Down Expand Up @@ -544,21 +543,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<alts_grpc_handshaker_client*>(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;
}
Expand Down Expand Up @@ -603,21 +602,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<alts_grpc_handshaker_client*>(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;
}
Expand All @@ -640,7 +639,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 =
Expand All @@ -649,14 +648,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;
}
Expand Down Expand Up @@ -716,7 +715,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();
Expand Down Expand Up @@ -891,8 +890,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;
}

Expand All @@ -902,8 +900,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;
}

Expand All @@ -913,8 +910,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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/tsi/alts/handshaker/alts_tsi_utils.cc
Expand Up @@ -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 <grpc/byte_buffer_reader.h>
#include <grpc/support/port_platform.h>
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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 <grpc/support/port_platform.h>
Expand Down Expand Up @@ -100,7 +101,7 @@ bool grpc_gcp_rpc_protocol_versions_decode(
reinterpret_cast<const char*>(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);
Expand Down
Expand Up @@ -21,6 +21,7 @@
#include <string.h>

#include "absl/log/check.h"
#include "absl/log/log.h"

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c3bcc4a

Please sign in to comment.