diff --git a/CMakeLists.txt b/CMakeLists.txt index 449d17ec767..1b107dddb0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1052,6 +1052,7 @@ if(gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_cxx dualstack_socket_test) endif() + add_dependencies(buildtests_cxx dump_args_test) add_dependencies(buildtests_cxx duplicate_header_bad_client_test) add_dependencies(buildtests_cxx empty_batch_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX) @@ -12390,6 +12391,41 @@ endif() endif() if(gRPC_BUILD_TESTS) +add_executable(dump_args_test + src/core/lib/gprpp/dump_args.cc + test/core/gprpp/dump_args_test.cc +) +target_compile_features(dump_args_test PUBLIC cxx_std_14) +target_include_directories(dump_args_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(dump_args_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + absl::any_invocable + absl::check +) + + +endif() +if(gRPC_BUILD_TESTS) + add_executable(duplicate_header_bad_client_test test/core/bad_client/bad_client.cc test/core/bad_client/tests/duplicate_header.cc diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index d15f905f347..7458cc04b7f 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -8661,6 +8661,20 @@ targets: - linux - posix - mac +- name: dump_args_test + gtest: true + build: test + language: c++ + headers: + - src/core/lib/gprpp/dump_args.h + src: + - src/core/lib/gprpp/dump_args.cc + - test/core/gprpp/dump_args_test.cc + deps: + - gtest + - absl/functional:any_invocable + - absl/log:check + uses_polling: false - name: duplicate_header_bad_client_test gtest: true build: test diff --git a/src/core/BUILD b/src/core/BUILD index 87225db6d7c..b15bf14f933 100644 --- a/src/core/BUILD +++ b/src/core/BUILD @@ -48,6 +48,25 @@ grpc_cc_library( language = "c++", ) +grpc_cc_library( + name = "dump_args", + srcs = [ + "lib/gprpp/dump_args.cc", + ], + hdrs = [ + "lib/gprpp/dump_args.h", + ], + external_deps = [ + "absl/functional:any_invocable", + "absl/log:check", + "absl/strings", + ], + language = "c++", + deps = [ + "//:gpr_platform", + ], +) + grpc_cc_library( name = "slice_cast", hdrs = [ diff --git a/src/core/ext/transport/binder/transport/binder_transport.cc b/src/core/ext/transport/binder/transport/binder_transport.cc index b5e32e913b7..65512675d96 100644 --- a/src/core/ext/transport/binder/transport/binder_transport.cc +++ b/src/core/ext/transport/binder/transport/binder_transport.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" @@ -141,7 +142,7 @@ static void AssignMetadata(grpc_metadata_batch* mb, static void cancel_stream_locked(grpc_binder_transport* transport, grpc_binder_stream* stream, grpc_error_handle error) { - gpr_log(GPR_INFO, "cancel_stream_locked"); + LOG(INFO) << "cancel_stream_locked"; if (!stream->is_closed) { CHECK(stream->cancel_self_error.ok()); stream->is_closed = true; @@ -200,7 +201,7 @@ static void recv_initial_metadata_locked(void* arg, CHECK(stream->recv_initial_metadata); CHECK(stream->recv_initial_metadata_ready); if (!args->initial_metadata.ok()) { - gpr_log(GPR_ERROR, "Failed to parse initial metadata"); + LOG(ERROR) << "Failed to parse initial metadata"; return absl_status_to_grpc_error(args->initial_metadata.status()); } if (!stream->is_client) { @@ -237,11 +238,11 @@ static void recv_message_locked(void* arg, grpc_error_handle /*error*/) { CHECK(stream->recv_message); CHECK(stream->recv_message_ready); if (!args->message.ok()) { - gpr_log(GPR_ERROR, "Failed to receive message"); + LOG(ERROR) << "Failed to receive message"; if (args->message.status().message() == grpc_binder::TransportStreamReceiver:: kGrpcBinderTransportCancelledGracefully) { - gpr_log(GPR_ERROR, "message cancelled gracefully"); + LOG(ERROR) << "message cancelled gracefully"; // Cancelled because we've already received trailing metadata. // It's not an error in this case. return absl::OkStatus(); @@ -281,13 +282,13 @@ static void recv_trailing_metadata_locked(void* arg, CHECK(stream->recv_trailing_metadata); CHECK(stream->recv_trailing_metadata_finished); if (!args->trailing_metadata.ok()) { - gpr_log(GPR_ERROR, "Failed to receive trailing metadata"); + LOG(ERROR) << "Failed to receive trailing metadata"; return absl_status_to_grpc_error(args->trailing_metadata.status()); } if (!stream->is_client) { // Client will not send non-empty trailing metadata. if (!args->trailing_metadata.value().empty()) { - gpr_log(GPR_ERROR, "Server receives non-empty trailing metadata."); + LOG(ERROR) << "Server receives non-empty trailing metadata."; return absl::CancelledError(); } } else { @@ -371,7 +372,7 @@ class MetadataEncoder { static void accept_stream_locked(void* gt, grpc_error_handle /*error*/) { grpc_binder_transport* transport = static_cast(gt); if (transport->accept_stream_fn) { - gpr_log(GPR_INFO, "Accepting a stream"); + LOG(INFO) << "Accepting a stream"; // must pass in a non-null value. (*transport->accept_stream_fn)(transport->accept_stream_user_data, transport, transport); @@ -449,7 +450,7 @@ static void perform_stream_op_locked(void* stream_op, std::make_unique(tx_code, transport->is_client); if (op->send_initial_metadata) { - gpr_log(GPR_INFO, "send_initial_metadata"); + LOG(INFO) << "send_initial_metadata"; grpc_binder::Metadata init_md; auto batch = op->payload->send_initial_metadata.send_initial_metadata; @@ -459,12 +460,12 @@ static void perform_stream_op_locked(void* stream_op, tx->SetPrefix(init_md); } if (op->send_message) { - gpr_log(GPR_INFO, "send_message"); + LOG(INFO) << "send_message"; tx->SetData(op->payload->send_message.send_message->JoinIntoString()); } if (op->send_trailing_metadata) { - gpr_log(GPR_INFO, "send_trailing_metadata"); + LOG(INFO) << "send_trailing_metadata"; auto batch = op->payload->send_trailing_metadata.send_trailing_metadata; grpc_binder::Metadata trailing_metadata; @@ -477,7 +478,7 @@ static void perform_stream_op_locked(void* stream_op, tx->SetSuffix(trailing_metadata); } if (op->recv_initial_metadata) { - gpr_log(GPR_INFO, "recv_initial_metadata"); + LOG(INFO) << "recv_initial_metadata"; stream->recv_initial_metadata_ready = op->payload->recv_initial_metadata.recv_initial_metadata_ready; stream->recv_initial_metadata = @@ -500,7 +501,7 @@ static void perform_stream_op_locked(void* stream_op, }); } if (op->recv_message) { - gpr_log(GPR_INFO, "recv_message"); + LOG(INFO) << "recv_message"; stream->recv_message_ready = op->payload->recv_message.recv_message_ready; stream->recv_message = op->payload->recv_message.recv_message; stream->call_failed_before_recv_message = @@ -523,7 +524,7 @@ static void perform_stream_op_locked(void* stream_op, }); } if (op->recv_trailing_metadata) { - gpr_log(GPR_INFO, "recv_trailing_metadata"); + LOG(INFO) << "recv_trailing_metadata"; stream->recv_trailing_metadata_finished = op->payload->recv_trailing_metadata.recv_trailing_metadata_ready; stream->recv_trailing_metadata = @@ -571,7 +572,7 @@ static void perform_stream_op_locked(void* stream_op, if (op->on_complete != nullptr) { grpc_core::ExecCtx::Run(DEBUG_LOCATION, op->on_complete, absl_status_to_grpc_error(status)); - gpr_log(GPR_INFO, "on_complete closure scheduled"); + LOG(INFO) << "on_complete closure scheduled"; } GRPC_BINDER_STREAM_UNREF(stream, "perform_stream_op"); } diff --git a/src/core/ext/transport/binder/wire_format/wire_reader_impl.cc b/src/core/ext/transport/binder/wire_format/wire_reader_impl.cc index 8595f8bf149..02cd6cf09cd 100644 --- a/src/core/ext/transport/binder/wire_format/wire_reader_impl.cc +++ b/src/core/ext/transport/binder/wire_format/wire_reader_impl.cc @@ -26,6 +26,7 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/status/statusor.h" @@ -136,9 +137,9 @@ void WireReaderImpl::SendSetupTransport(Binder* binder) { std::unique_ptr WireReaderImpl::RecvSetupTransport() { // TODO(b/191941760): avoid blocking, handle wire_writer_noti lifetime // better - gpr_log(GPR_DEBUG, "start waiting for noti"); + VLOG(2) << "start waiting for noti"; connection_noti_.WaitForNotification(); - gpr_log(GPR_DEBUG, "end waiting for noti"); + VLOG(2) << "end waiting for noti"; return std::move(other_end_binder_); } @@ -153,8 +154,8 @@ absl::Status WireReaderImpl::ProcessTransaction(transaction_code_t code, BinderTransportTxCode::SETUP_TRANSPORT) && code <= static_cast( BinderTransportTxCode::PING_RESPONSE))) { - gpr_log(GPR_INFO, - "Received unknown control message. Shutdown transport gracefully."); + LOG(INFO) + << "Received unknown control message. Shutdown transport gracefully."; // TODO(waynetu): Shutdown transport gracefully. return absl::OkStatus(); } @@ -210,8 +211,8 @@ absl::Status WireReaderImpl::ProcessTransaction(transaction_code_t code, break; } case BinderTransportTxCode::SHUTDOWN_TRANSPORT: { - gpr_log(GPR_ERROR, - "Received SHUTDOWN_TRANSPORT request but not implemented yet."); + LOG(ERROR) + << "Received SHUTDOWN_TRANSPORT request but not implemented yet."; return absl::UnimplementedError("SHUTDOWN_TRANSPORT"); } case BinderTransportTxCode::ACKNOWLEDGE_BYTES: { @@ -286,16 +287,16 @@ absl::Status WireReaderImpl::ProcessStreamingTransaction( tx_process_result.ToString().c_str()); // Something went wrong when receiving transaction. Cancel failed requests. if (cancellation_flags & kFlagPrefix) { - gpr_log(GPR_INFO, "cancelling initial metadata"); + LOG(INFO) << "cancelling initial metadata"; transport_stream_receiver_->NotifyRecvInitialMetadata(code, tx_process_result); } if (cancellation_flags & kFlagMessageData) { - gpr_log(GPR_INFO, "cancelling message data"); + LOG(INFO) << "cancelling message data"; transport_stream_receiver_->NotifyRecvMessage(code, tx_process_result); } if (cancellation_flags & kFlagSuffix) { - gpr_log(GPR_INFO, "cancelling trailing metadata"); + LOG(INFO) << "cancelling trailing metadata"; transport_stream_receiver_->NotifyRecvTrailingMetadata( code, tx_process_result, 0); } @@ -338,7 +339,7 @@ absl::Status WireReaderImpl::ProcessStreamingTransactionImpl( // intended behavior. // TODO(waynetu): What should be returned here? if (flags == 0) { - gpr_log(GPR_INFO, "[WARNING] Receive empty transaction. Ignored."); + LOG(INFO) << "[WARNING] Receive empty transaction. Ignored."; return absl::OkStatus(); } diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 9a28649dd52..4acd9b51b3f 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -35,6 +35,7 @@ #include "absl/container/flat_hash_map.h" #include "absl/hash/hash.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/meta/type_traits.h" #include "absl/random/random.h" #include "absl/status/status.h" @@ -1324,7 +1325,7 @@ static bool contains_non_ok_status(grpc_metadata_batch* batch) { static void log_metadata(const grpc_metadata_batch* md_batch, uint32_t id, bool is_client, bool is_initial) { - gpr_log(GPR_INFO, "--metadata--"); + LOG(INFO) << "--metadata--"; const std::string prefix = absl::StrCat( "HTTP:", id, is_initial ? ":HDR" : ":TRL", is_client ? ":CLI:" : ":SVR:"); md_batch->Log([&prefix](absl::string_view key, absl::string_view value) { diff --git a/src/core/lib/gprpp/dump_args.cc b/src/core/lib/gprpp/dump_args.cc new file mode 100644 index 00000000000..e5bc183246b --- /dev/null +++ b/src/core/lib/gprpp/dump_args.cc @@ -0,0 +1,54 @@ +// Copyright 2024 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/core/lib/gprpp/dump_args.h" + +#include "absl/log/check.h" +#include "absl/strings/ascii.h" +#include "absl/strings/string_view.h" + +namespace grpc_core { +namespace dump_args_detail { + +std::ostream& operator<<(std::ostream& out, const DumpArgs& args) { + // Parse the argument string into a vector of keys. + // #__VA_ARGS__ produces a stringified version of the arguments passed to the + // macro. It's comma separated, and we can use that to split the string into + // keys. Those keys might include parenthesis for e.g. argument lists, and so + // we need to skip commas that are inside parenthesis. + std::vector keys; + int depth = 0; + const char* start = args.arg_string_; + for (const char* p = args.arg_string_; *p; ++p) { + if (*p == '(') { + ++depth; + } else if (*p == ')') { + --depth; + } else if (*p == ',' && depth == 0) { + keys.push_back(absl::string_view(start, p - start)); + start = p + 1; + } + } + keys.push_back(start); + CHECK_EQ(keys.size(), args.arg_dumpers_.size()); + for (size_t i = 0; i < keys.size(); i++) { + if (i != 0) out << ", "; + out << absl::StripAsciiWhitespace(keys[i]) << " = "; + args.arg_dumpers_[i](out); + } + return out; +} + +} // namespace dump_args_detail +} // namespace grpc_core \ No newline at end of file diff --git a/src/core/lib/gprpp/dump_args.h b/src/core/lib/gprpp/dump_args.h new file mode 100644 index 00000000000..c2b66ce2be3 --- /dev/null +++ b/src/core/lib/gprpp/dump_args.h @@ -0,0 +1,69 @@ +// Copyright 2024 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef GRPC_SRC_CORE_LIB_GPRPP_DUMP_ARGS_H +#define GRPC_SRC_CORE_LIB_GPRPP_DUMP_ARGS_H + +#include +#include + +#include "absl/functional/any_invocable.h" + +namespace grpc_core { +namespace dump_args_detail { + +// Helper function... just ignore the initializer list passed into it. +// Allows doing 'statements' via parameter pack expansion in C++11 - given +// template : +// do_these_things({foo()...}); +// will execute foo() for each T in Ts. +template +void do_these_things(std::initializer_list) {} + +class DumpArgs { + public: + template + explicit DumpArgs(const char* arg_string, const Args&... args) + : arg_string_(arg_string) { + do_these_things( + {AddDumper([a = &args](std::ostream& os) { os << *a; })...}); + } + + friend std::ostream& operator<<(std::ostream& out, const DumpArgs& args); + + private: + int AddDumper(absl::AnyInvocable dumper) { + arg_dumpers_.push_back(std::move(dumper)); + return 0; + } + + const char* arg_string_; + std::vector> arg_dumpers_; +}; + +} // namespace dump_args_detail +} // namespace grpc_core + +// Helper to print a list of variables and their values. +// Each type must be streamable to std::ostream. +// Usage: +// int a = 1; +// int b = 2; +// LOG(INFO) << GRPC_DUMP_ARGS(a, b) +// Output: +// a = 1, b = 2 +#define GRPC_DUMP_ARGS(...) \ + grpc_core::dump_args_detail::DumpArgs(#__VA_ARGS__, __VA_ARGS__) + +#endif // GRPC_SRC_CORE_LIB_GPRPP_DUMP_ARGS_H diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index c36f3833d9f..6461b10a6cb 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -41,6 +41,7 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" @@ -100,14 +101,14 @@ static int epoll_create_and_cloexec() { #ifdef GRPC_LINUX_EPOLL_CREATE1 int fd = epoll_create1(EPOLL_CLOEXEC); if (fd < 0) { - gpr_log(GPR_ERROR, "epoll_create1 unavailable"); + LOG(ERROR) << "epoll_create1 unavailable"; } #else int fd = epoll_create(MAX_EPOLL_EVENTS); if (fd < 0) { - gpr_log(GPR_ERROR, "epoll_create unavailable"); + LOG(ERROR) << "epoll_create unavailable"; } else if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { - gpr_log(GPR_ERROR, "fcntl following epoll_create failed"); + LOG(ERROR) << "fcntl following epoll_create failed"; return -1; } #endif @@ -891,7 +892,7 @@ static bool check_neighborhood_for_available_poller( } } else { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_INFO, " .. beaten to choose next poller"); + LOG(INFO) << " .. beaten to choose next poller"; } } // even if we didn't win the cas, there's a worker, we can stop @@ -990,7 +991,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, gpr_cv_destroy(&worker->cv); } if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_INFO, " .. remove worker"); + LOG(INFO) << " .. remove worker"; } if (EMPTIED == worker_remove(pollset, worker)) { pollset_maybe_finish_shutdown(pollset); @@ -1081,7 +1082,7 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset, if (root_worker == nullptr) { pollset->kicked_without_poller = true; if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_INFO, " .. kicked_without_poller"); + LOG(INFO) << " .. kicked_without_poller"; } goto done; } @@ -1146,7 +1147,7 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset, } } else { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_INFO, " .. kicked while waking up"); + LOG(INFO) << " .. kicked while waking up"; } goto done; } @@ -1156,7 +1157,7 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset, if (specific_worker->state == KICKED) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_INFO, " .. specific worker already kicked"); + LOG(INFO) << " .. specific worker already kicked"; } goto done; } else if (g_current_thread_worker == specific_worker) { @@ -1169,21 +1170,21 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset, reinterpret_cast( gpr_atm_no_barrier_load(&g_active_poller))) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_INFO, " .. kick active poller"); + LOG(INFO) << " .. kick active poller"; } SET_KICK_STATE(specific_worker, KICKED); ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd); goto done; } else if (specific_worker->initialized_cv) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_INFO, " .. kick waiting worker"); + LOG(INFO) << " .. kick waiting worker"; } SET_KICK_STATE(specific_worker, KICKED); gpr_cv_signal(&specific_worker->cv); goto done; } else { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_INFO, " .. kick non-waiting worker"); + LOG(INFO) << " .. kick non-waiting worker"; } SET_KICK_STATE(specific_worker, KICKED); goto done; @@ -1311,7 +1312,7 @@ static void reset_event_manager_on_fork() { static bool init_epoll1_linux() { if (!g_is_shutdown) return true; if (!grpc_has_wakeup_fd()) { - gpr_log(GPR_ERROR, "Skipping epoll1 because of no wakeup fd."); + LOG(ERROR) << "Skipping epoll1 because of no wakeup fd."; return false; } diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index 880b10c1764..46c54c9502e 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -46,6 +46,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -212,7 +213,7 @@ class TcpZerocopySendCtx { if (send_records_ == nullptr || free_send_records_ == nullptr) { gpr_free(send_records_); gpr_free(free_send_records_); - gpr_log(GPR_INFO, "Disabling TCP TX zerocopy due to memory pressure.\n"); + LOG(INFO) << "Disabling TCP TX zerocopy due to memory pressure.\n"; memory_limited_ = true; } else { for (int idx = 0; idx < max_sends_; ++idx) { @@ -836,7 +837,7 @@ static void tcp_destroy(grpc_endpoint* ep) { static void perform_reclamation(grpc_tcp* tcp) ABSL_LOCKS_EXCLUDED(tcp->read_mu) { if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) { - gpr_log(GPR_INFO, "TCP: benign reclamation to free memory"); + LOG(INFO) << "TCP: benign reclamation to free memory"; } tcp->read_mu.Lock(); if (tcp->incoming_buffer != nullptr) { @@ -1294,7 +1295,7 @@ static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg, if (setsockopt(tcp->fd, SOL_SOCKET, SO_TIMESTAMPING, static_cast(&opt), sizeof(opt)) != 0) { if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_ERROR, "Failed to set timestamping options on the socket."); + LOG(ERROR) << "Failed to set timestamping options on the socket."; } return false; } @@ -1380,7 +1381,7 @@ struct cmsghdr* process_timestamp(grpc_tcp* tcp, msghdr* msg, cmsghdr* opt_stats = nullptr; if (next_cmsg == nullptr) { if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_ERROR, "Received timestamp without extended error"); + LOG(ERROR) << "Received timestamp without extended error"; } return cmsg; } @@ -1392,7 +1393,7 @@ struct cmsghdr* process_timestamp(grpc_tcp* tcp, msghdr* msg, next_cmsg = CMSG_NXTHDR(msg, opt_stats); if (next_cmsg == nullptr) { if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_ERROR, "Received timestamp without extended error"); + LOG(ERROR) << "Received timestamp without extended error"; } return opt_stats; } @@ -1402,7 +1403,7 @@ struct cmsghdr* process_timestamp(grpc_tcp* tcp, msghdr* msg, !(next_cmsg->cmsg_type == IP_RECVERR || next_cmsg->cmsg_type == IPV6_RECVERR)) { if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_ERROR, "Unexpected control message"); + LOG(ERROR) << "Unexpected control message"; } return cmsg; } @@ -1412,7 +1413,7 @@ struct cmsghdr* process_timestamp(grpc_tcp* tcp, msghdr* msg, auto serr = reinterpret_cast(CMSG_DATA(next_cmsg)); if (serr->ee_errno != ENOMSG || serr->ee_origin != SO_EE_ORIGIN_TIMESTAMPING) { - gpr_log(GPR_ERROR, "Unexpected control message"); + LOG(ERROR) << "Unexpected control message"; return cmsg; } tcp->tb_list.ProcessTimestamp(serr, opt_stats, tss); @@ -1462,7 +1463,7 @@ static bool process_errors(grpc_tcp* tcp) { return processed_err; } if (GPR_UNLIKELY((msg.msg_flags & MSG_CTRUNC) != 0)) { - gpr_log(GPR_ERROR, "Error message was truncated."); + LOG(ERROR) << "Error message was truncated."; } if (msg.msg_controllen == 0) { @@ -1539,14 +1540,14 @@ static bool tcp_write_with_timestamps(grpc_tcp* /*tcp*/, struct msghdr* /*msg*/, ssize_t* /*sent_length*/, int* /* saved_errno */, int /*additional_flags*/) { - gpr_log(GPR_ERROR, "Write with timestamps not supported for this platform"); + LOG(ERROR) << "Write with timestamps not supported for this platform"; CHECK(0); return false; } static void tcp_handle_error(void* /*arg*/ /* grpc_tcp */, grpc_error_handle /*error*/) { - gpr_log(GPR_ERROR, "Error handling is not supported for this platform"); + LOG(ERROR) << "Error handling is not supported for this platform"; CHECK(0); } #endif // GRPC_LINUX_ERRQUEUE @@ -1842,7 +1843,7 @@ static void tcp_handle_write(void* arg /* grpc_tcp */, : tcp_flush(tcp, &error); if (!flush_result) { if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_INFO, "write: delayed"); + LOG(INFO) << "write: delayed"; } notify_on_write(tcp); // tcp_flush does not populate error if it has returned false. @@ -1915,7 +1916,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, tcp->write_cb = cb; tcp->current_zerocopy_send = zerocopy_send_record; if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_INFO, "write: delayed"); + LOG(INFO) << "write: delayed"; } notify_on_write(tcp); } else { @@ -2029,7 +2030,7 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd, if (err == 0) { tcp->tcp_zerocopy_send_ctx.set_enabled(true); } else { - gpr_log(GPR_ERROR, "Failed to set zerocopy options on the socket."); + LOG(ERROR) << "Failed to set zerocopy options on the socket."; } #endif } diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc index 0e927aa075d..49cc8e21be1 100644 --- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc +++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc @@ -42,6 +42,7 @@ #endif #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" @@ -114,7 +115,7 @@ static const EVP_MD* evp_md_from_alg(const char* alg) { static Json parse_json_part_from_jwt(const char* str, size_t len) { std::string string; if (!absl::WebSafeBase64Unescape(absl::string_view(str, len), &string)) { - gpr_log(GPR_ERROR, "Invalid base64."); + LOG(ERROR) << "Invalid base64."; return Json(); // JSON null } auto json = grpc_core::JsonParse(string); @@ -163,13 +164,13 @@ static jose_header* jose_header_from_json(Json json) { Json::Object::const_iterator it; jose_header* h = grpc_core::Zalloc(); if (json.type() != Json::Type::kObject) { - gpr_log(GPR_ERROR, "JSON value is not an object"); + LOG(ERROR) << "JSON value is not an object"; goto error; } // Check alg field. it = json.object().find("alg"); if (it == json.object().end()) { - gpr_log(GPR_ERROR, "Missing alg field."); + LOG(ERROR) << "Missing alg field."; goto error; } // We only support RSA-1.5 signatures for now. @@ -180,7 +181,7 @@ static jose_header* jose_header_from_json(Json json) { if (it->second.type() != Json::Type::kString || strncmp(alg_value, "RS", 2) != 0 || evp_md_from_alg(alg_value) == nullptr) { - gpr_log(GPR_ERROR, "Invalid alg field"); + LOG(ERROR) << "Invalid alg field"; goto error; } h->alg = alg_value; @@ -319,13 +320,13 @@ grpc_jwt_verifier_status grpc_jwt_claims_check(const grpc_jwt_claims* claims, skewed_now = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), grpc_jwt_verifier_clock_skew); if (gpr_time_cmp(skewed_now, claims->nbf) < 0) { - gpr_log(GPR_ERROR, "JWT is not valid yet."); + LOG(ERROR) << "JWT is not valid yet."; return GRPC_JWT_VERIFIER_TIME_CONSTRAINT_FAILURE; } skewed_now = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), grpc_jwt_verifier_clock_skew); if (gpr_time_cmp(skewed_now, claims->exp) > 0) { - gpr_log(GPR_ERROR, "JWT is expired."); + LOG(ERROR) << "JWT is expired."; return GRPC_JWT_VERIFIER_TIME_CONSTRAINT_FAILURE; } @@ -430,7 +431,7 @@ struct grpc_jwt_verifier { static Json json_from_http(const grpc_http_response* response) { if (response == nullptr) { - gpr_log(GPR_ERROR, "HTTP response is NULL."); + LOG(ERROR) << "HTTP response is NULL."; return Json(); // JSON null } if (response->status != 200) { @@ -441,7 +442,7 @@ static Json json_from_http(const grpc_http_response* response) { auto json = grpc_core::JsonParse( absl::string_view(response->body, response->body_length)); if (!json.ok()) { - gpr_log(GPR_ERROR, "Invalid JSON found in response."); + LOG(ERROR) << "Invalid JSON found in response."; return Json(); // JSON null } return std::move(*json); @@ -464,12 +465,12 @@ static EVP_PKEY* extract_pkey_from_x509(const char* x509_str) { BIO_write(bio, x509_str, static_cast(len)); x509 = PEM_read_bio_X509(bio, nullptr, nullptr, nullptr); if (x509 == nullptr) { - gpr_log(GPR_ERROR, "Unable to parse x509 cert."); + LOG(ERROR) << "Unable to parse x509 cert."; goto end; } result = X509_get_pubkey(x509); if (result == nullptr) { - gpr_log(GPR_ERROR, "Cannot find public key in X509 cert."); + LOG(ERROR) << "Cannot find public key in X509 cert."; } end: @@ -482,7 +483,7 @@ static BIGNUM* bignum_from_base64(const char* b64) { if (b64 == nullptr) return nullptr; std::string string; if (!absl::WebSafeBase64Unescape(b64, &string)) { - gpr_log(GPR_ERROR, "Invalid base64 for big num."); + LOG(ERROR) << "Invalid base64 for big num."; return nullptr; } return BN_bin2bn(reinterpret_cast(string.data()), @@ -540,27 +541,27 @@ static EVP_PKEY* pkey_from_jwk(const Json& json, const char* kty) { #if OPENSSL_VERSION_NUMBER < 0x30000000L rsa = RSA_new(); if (rsa == nullptr) { - gpr_log(GPR_ERROR, "Could not create rsa key."); + LOG(ERROR) << "Could not create rsa key."; goto end; } #endif it = json.object().find("n"); if (it == json.object().end()) { - gpr_log(GPR_ERROR, "Missing RSA public key field."); + LOG(ERROR) << "Missing RSA public key field."; goto end; } tmp_n = bignum_from_base64(validate_string_field(it->second, "n")); if (tmp_n == nullptr) goto end; it = json.object().find("e"); if (it == json.object().end()) { - gpr_log(GPR_ERROR, "Missing RSA public key field."); + LOG(ERROR) << "Missing RSA public key field."; goto end; } tmp_e = bignum_from_base64(validate_string_field(it->second, "e")); if (tmp_e == nullptr) goto end; #if OPENSSL_VERSION_NUMBER < 0x30000000L if (!RSA_set0_key(rsa, tmp_n, tmp_e, nullptr)) { - gpr_log(GPR_ERROR, "Cannot set RSA key from inputs."); + LOG(ERROR) << "Cannot set RSA key from inputs."; goto end; } // RSA_set0_key takes ownership on success. @@ -573,21 +574,21 @@ static EVP_PKEY* pkey_from_jwk(const Json& json, const char* kty) { if (!OSSL_PARAM_BLD_push_BN(bld, "n", tmp_n) || !OSSL_PARAM_BLD_push_BN(bld, "e", tmp_e) || (params = OSSL_PARAM_BLD_to_param(bld)) == NULL) { - gpr_log(GPR_ERROR, "Could not create OSSL_PARAM"); + LOG(ERROR) << "Could not create OSSL_PARAM"; goto end; } ctx = EVP_PKEY_CTX_new_from_name(nullptr, "RSA", nullptr); if (ctx == nullptr) { - gpr_log(GPR_ERROR, "Could not create rsa key."); + LOG(ERROR) << "Could not create rsa key."; goto end; } if (EVP_PKEY_fromdata_init(ctx) <= 0) { - gpr_log(GPR_ERROR, "Could not create rsa key."); + LOG(ERROR) << "Could not create rsa key."; goto end; } if (EVP_PKEY_fromdata(ctx, &result, EVP_PKEY_KEYPAIR, params) <= 0) { - gpr_log(GPR_ERROR, "Cannot set RSA key from inputs."); + LOG(ERROR) << "Cannot set RSA key from inputs."; goto end; } #endif @@ -618,8 +619,7 @@ static EVP_PKEY* find_verification_key(const Json& json, const char* header_alg, return extract_pkey_from_x509(cur->string().c_str()); } if (jwt_keys->type() != Json::Type::kArray) { - gpr_log(GPR_ERROR, - "Unexpected value type of keys property in jwks key set."); + LOG(ERROR) << "Unexpected value type of keys property in jwks key set."; return nullptr; } // Key format is specified in: @@ -661,21 +661,21 @@ static int verify_jwt_signature(EVP_PKEY* key, const char* alg, CHECK_NE(md, nullptr); // Checked before. if (md_ctx == nullptr) { - gpr_log(GPR_ERROR, "Could not create EVP_MD_CTX."); + LOG(ERROR) << "Could not create EVP_MD_CTX."; goto end; } if (EVP_DigestVerifyInit(md_ctx, nullptr, md, nullptr, key) != 1) { - gpr_log(GPR_ERROR, "EVP_DigestVerifyInit failed."); + LOG(ERROR) << "EVP_DigestVerifyInit failed."; goto end; } if (EVP_DigestVerifyUpdate(md_ctx, GRPC_SLICE_START_PTR(signed_data), GRPC_SLICE_LENGTH(signed_data)) != 1) { - gpr_log(GPR_ERROR, "EVP_DigestVerifyUpdate failed."); + LOG(ERROR) << "EVP_DigestVerifyUpdate failed."; goto end; } if (EVP_DigestVerifyFinal(md_ctx, GRPC_SLICE_START_PTR(signature), GRPC_SLICE_LENGTH(signature)) != 1) { - gpr_log(GPR_ERROR, "JWT signature verification failed."); + LOG(ERROR) << "JWT signature verification failed."; goto end; } @@ -742,7 +742,7 @@ static void on_openid_config_retrieved(void* user_data, if (json.type() == Json::Type::kNull) goto error; cur = find_property_by_name(json, "jwks_uri"); if (cur == nullptr) { - gpr_log(GPR_ERROR, "Could not find jwks_uri in openid config."); + LOG(ERROR) << "Could not find jwks_uri in openid config."; goto error; } jwks_uri = validate_string_field(*cur, "jwks_uri"); @@ -843,11 +843,11 @@ static void retrieve_key_and_verify(verifier_cb_ctx* ctx) { CHECK(ctx != nullptr && ctx->header != nullptr && ctx->claims != nullptr); iss = ctx->claims->iss; if (ctx->header->kid == nullptr) { - gpr_log(GPR_ERROR, "Missing kid in jose header."); + LOG(ERROR) << "Missing kid in jose header."; goto error; } if (iss == nullptr) { - gpr_log(GPR_ERROR, "Missing iss in claims."); + LOG(ERROR) << "Missing iss in claims."; goto error; } @@ -862,7 +862,7 @@ static void retrieve_key_and_verify(verifier_cb_ctx* ctx) { CHECK_NE(ctx->verifier, nullptr); mapping = verifier_get_mapping(ctx->verifier, email_domain); if (mapping == nullptr) { - gpr_log(GPR_ERROR, "Missing mapping for issuer email."); + LOG(ERROR) << "Missing mapping for issuer email."; goto error; } host = gpr_strdup(mapping->key_url_prefix); diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 4c425b87470..6d2457dba2d 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -34,6 +34,7 @@ #include "absl/base/thread_annotations.h" #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" @@ -1138,8 +1139,7 @@ void FilterStackCall::RecvTrailingFilter(grpc_metadata_batch* b, } else if (!is_client()) { SetFinalStatus(absl::OkStatus()); } else { - gpr_log(GPR_DEBUG, - "Received trailing metadata with no error and no status"); + VLOG(2) << "Received trailing metadata with no error and no status"; SetFinalStatus(grpc_error_set_int(GRPC_ERROR_CREATE("No status received"), StatusIntProperty::kRpcStatus, GRPC_STATUS_UNKNOWN)); diff --git a/src/core/load_balancing/xds/xds_override_host.cc b/src/core/load_balancing/xds/xds_override_host.cc index c8821ca0a91..41b3eb36ef6 100644 --- a/src/core/load_balancing/xds/xds_override_host.cc +++ b/src/core/load_balancing/xds/xds_override_host.cc @@ -32,6 +32,7 @@ #include "absl/base/thread_annotations.h" #include "absl/functional/function_ref.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" @@ -530,7 +531,7 @@ XdsOverrideHostLb::Picker::PickOverridenHost( // a connection attempt and queue the pick until that attempt completes. if (idle_subchannel != nullptr) { if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_override_host_trace)) { - gpr_log(GPR_INFO, "Picker override found IDLE subchannel"); + LOG(INFO) << "Picker override found IDLE subchannel"; } // Deletes itself after the connection is requested. new SubchannelConnectionRequester(std::move(idle_subchannel)); @@ -540,7 +541,7 @@ XdsOverrideHostLb::Picker::PickOverridenHost( // queue the pick and wait for the connection attempt to complete. if (found_connecting) { if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_override_host_trace)) { - gpr_log(GPR_INFO, "Picker override found CONNECTING subchannel"); + LOG(INFO) << "Picker override found CONNECTING subchannel"; } return PickResult::Queue(); } @@ -549,7 +550,7 @@ XdsOverrideHostLb::Picker::PickOverridenHost( // creation of a subchannel for that entry. if (!address_with_no_subchannel.empty()) { if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_override_host_trace)) { - gpr_log(GPR_INFO, "Picker override found entry with no subchannel"); + LOG(INFO) << "Picker override found entry with no subchannel"; } if (!IsWorkSerializerDispatchEnabled()) { new SubchannelCreationRequester(policy_, address_with_no_subchannel); diff --git a/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc b/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc index 11849b655b8..fa22ca884b7 100644 --- a/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +++ b/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc @@ -23,6 +23,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "upb/mem/arena.hpp" #include @@ -87,7 +88,7 @@ typedef struct alts_tsi_handshaker_result { static tsi_result handshaker_result_extract_peer( const tsi_handshaker_result* self, tsi_peer* peer) { if (self == nullptr || peer == nullptr) { - gpr_log(GPR_ERROR, "Invalid argument to handshaker_result_extract_peer()"); + LOG(ERROR) << "Invalid argument to handshaker_result_extract_peer()"; return TSI_INVALID_ARGUMENT; } alts_tsi_handshaker_result* result = @@ -97,7 +98,7 @@ static tsi_result handshaker_result_extract_peer( tsi_result ok = tsi_construct_peer(kTsiAltsNumOfPeerProperties, peer); int index = 0; if (ok != TSI_OK) { - gpr_log(GPR_ERROR, "Failed to construct tsi peer"); + LOG(ERROR) << "Failed to construct tsi peer"; return ok; } CHECK_NE(&peer->properties[index], nullptr); @@ -106,7 +107,7 @@ static tsi_result handshaker_result_extract_peer( &peer->properties[index]); if (ok != TSI_OK) { tsi_peer_destruct(peer); - gpr_log(GPR_ERROR, "Failed to set tsi peer property"); + LOG(ERROR) << "Failed to set tsi peer property"; return ok; } index++; @@ -116,7 +117,7 @@ static tsi_result handshaker_result_extract_peer( &peer->properties[index]); if (ok != TSI_OK) { tsi_peer_destruct(peer); - gpr_log(GPR_ERROR, "Failed to set tsi peer property"); + LOG(ERROR) << "Failed to set tsi peer property"; } index++; CHECK_NE(&peer->properties[index], nullptr); @@ -126,7 +127,7 @@ static tsi_result handshaker_result_extract_peer( GRPC_SLICE_LENGTH(result->rpc_versions), &peer->properties[index]); if (ok != TSI_OK) { tsi_peer_destruct(peer); - gpr_log(GPR_ERROR, "Failed to set tsi peer property"); + LOG(ERROR) << "Failed to set tsi peer property"; } index++; CHECK_NE(&peer->properties[index], nullptr); @@ -136,7 +137,7 @@ static tsi_result handshaker_result_extract_peer( GRPC_SLICE_LENGTH(result->serialized_context), &peer->properties[index]); if (ok != TSI_OK) { tsi_peer_destruct(peer); - gpr_log(GPR_ERROR, "Failed to set tsi peer property"); + LOG(ERROR) << "Failed to set tsi peer property"; } index++; CHECK_NE(&peer->properties[index], nullptr); @@ -146,7 +147,7 @@ static tsi_result handshaker_result_extract_peer( &peer->properties[index]); if (ok != TSI_OK) { tsi_peer_destruct(peer); - gpr_log(GPR_ERROR, "Failed to set tsi peer property"); + LOG(ERROR) << "Failed to set tsi peer property"; } CHECK(++index == kTsiAltsNumOfPeerProperties); return ok; @@ -163,8 +164,7 @@ static tsi_result handshaker_result_create_zero_copy_grpc_protector( const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, tsi_zero_copy_grpc_protector** protector) { if (self == nullptr || protector == nullptr) { - gpr_log(GPR_ERROR, - "Invalid arguments to create_zero_copy_grpc_protector()"); + LOG(ERROR) << "Invalid arguments to create_zero_copy_grpc_protector()"; return TSI_INVALID_ARGUMENT; } alts_tsi_handshaker_result* result = @@ -198,7 +198,7 @@ static tsi_result handshaker_result_create_zero_copy_grpc_protector( /*is_integrity_only=*/false, /*enable_extra_copy=*/false, max_output_protected_frame_size, protector); if (ok != TSI_OK) { - gpr_log(GPR_ERROR, "Failed to create zero-copy grpc protector"); + LOG(ERROR) << "Failed to create zero-copy grpc protector"; } return ok; } @@ -207,8 +207,8 @@ static tsi_result handshaker_result_create_frame_protector( const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, tsi_frame_protector** protector) { if (self == nullptr || protector == nullptr) { - gpr_log(GPR_ERROR, - "Invalid arguments to handshaker_result_create_frame_protector()"); + LOG(ERROR) + << "Invalid arguments to handshaker_result_create_frame_protector()"; return TSI_INVALID_ARGUMENT; } alts_tsi_handshaker_result* result = @@ -219,7 +219,7 @@ static tsi_result handshaker_result_create_frame_protector( kAltsAes128GcmRekeyKeyLength, result->is_client, /*is_rekey=*/true, max_output_protected_frame_size, protector); if (ok != TSI_OK) { - gpr_log(GPR_ERROR, "Failed to create frame protector"); + LOG(ERROR) << "Failed to create frame protector"; } return ok; } @@ -228,8 +228,7 @@ static tsi_result handshaker_result_get_unused_bytes( const tsi_handshaker_result* self, const unsigned char** bytes, size_t* bytes_size) { if (self == nullptr || bytes == nullptr || bytes_size == nullptr) { - gpr_log(GPR_ERROR, - "Invalid arguments to handshaker_result_get_unused_bytes()"); + LOG(ERROR) << "Invalid arguments to handshaker_result_get_unused_bytes()"; return TSI_INVALID_ARGUMENT; } alts_tsi_handshaker_result* result = @@ -267,7 +266,7 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp, bool is_client, tsi_handshaker_result** result) { if (result == nullptr || resp == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to create_handshaker_result()"); + LOG(ERROR) << "Invalid arguments to create_handshaker_result()"; return TSI_INVALID_ARGUMENT; } const grpc_gcp_HandshakerResult* hresult = @@ -275,42 +274,42 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp, const grpc_gcp_Identity* identity = grpc_gcp_HandshakerResult_peer_identity(hresult); if (identity == nullptr) { - gpr_log(GPR_ERROR, "Invalid identity"); + LOG(ERROR) << "Invalid identity"; return TSI_FAILED_PRECONDITION; } upb_StringView peer_service_account = grpc_gcp_Identity_service_account(identity); if (peer_service_account.size == 0) { - gpr_log(GPR_ERROR, "Invalid peer service account"); + LOG(ERROR) << "Invalid peer service account"; return TSI_FAILED_PRECONDITION; } upb_StringView key_data = grpc_gcp_HandshakerResult_key_data(hresult); if (key_data.size < kAltsAes128GcmRekeyKeyLength) { - gpr_log(GPR_ERROR, "Bad key length"); + LOG(ERROR) << "Bad key length"; return TSI_FAILED_PRECONDITION; } const grpc_gcp_RpcProtocolVersions* peer_rpc_version = grpc_gcp_HandshakerResult_peer_rpc_versions(hresult); if (peer_rpc_version == nullptr) { - gpr_log(GPR_ERROR, "Peer does not set RPC protocol versions."); + LOG(ERROR) << "Peer does not set RPC protocol versions."; return TSI_FAILED_PRECONDITION; } upb_StringView application_protocol = grpc_gcp_HandshakerResult_application_protocol(hresult); if (application_protocol.size == 0) { - gpr_log(GPR_ERROR, "Invalid application protocol"); + LOG(ERROR) << "Invalid application protocol"; return TSI_FAILED_PRECONDITION; } upb_StringView record_protocol = grpc_gcp_HandshakerResult_record_protocol(hresult); if (record_protocol.size == 0) { - gpr_log(GPR_ERROR, "Invalid record protocol"); + LOG(ERROR) << "Invalid record protocol"; return TSI_FAILED_PRECONDITION; } const grpc_gcp_Identity* local_identity = grpc_gcp_HandshakerResult_local_identity(hresult); if (local_identity == nullptr) { - gpr_log(GPR_ERROR, "Invalid local identity"); + LOG(ERROR) << "Invalid local identity"; return TSI_FAILED_PRECONDITION; } upb_StringView local_service_account = @@ -331,7 +330,7 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp, bool serialized = grpc_gcp_rpc_protocol_versions_encode( peer_rpc_version, rpc_versions_arena.ptr(), &sresult->rpc_versions); if (!serialized) { - gpr_log(GPR_ERROR, "Failed to serialize peer's RPC protocol versions."); + LOG(ERROR) << "Failed to serialize peer's RPC protocol versions."; return TSI_FAILED_PRECONDITION; } upb::Arena context_arena; @@ -348,7 +347,7 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp, context, const_cast(peer_rpc_version)); grpc_gcp_Identity* peer_identity = const_cast(identity); if (peer_identity == nullptr) { - gpr_log(GPR_ERROR, "Null peer identity in ALTS context."); + LOG(ERROR) << "Null peer identity in ALTS context."; return TSI_FAILED_PRECONDITION; } if (grpc_gcp_Identity_attributes_size(identity) != 0) { @@ -372,7 +371,7 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp, char* serialized_ctx = grpc_gcp_AltsContext_serialize( context, context_arena.ptr(), &serialized_ctx_length); if (serialized_ctx == nullptr) { - gpr_log(GPR_ERROR, "Failed to serialize peer's ALTS context."); + LOG(ERROR) << "Failed to serialize peer's ALTS context."; return TSI_FAILED_PRECONDITION; } sresult->serialized_context = @@ -388,7 +387,7 @@ static void on_handshaker_service_resp_recv(void* arg, grpc_error_handle error) { alts_handshaker_client* client = static_cast(arg); if (client == nullptr) { - gpr_log(GPR_ERROR, "ALTS handshaker client is nullptr"); + LOG(ERROR) << "ALTS handshaker client is nullptr"; return; } bool success = true; @@ -440,7 +439,7 @@ static tsi_result alts_tsi_handshaker_continue_handshaker_next( handshaker->client_vtable_for_testing, handshaker->is_client, handshaker->max_frame_size, error); if (client == nullptr) { - gpr_log(GPR_ERROR, "Failed to create ALTS handshaker client"); + LOG(ERROR) << "Failed to create ALTS handshaker client"; if (error != nullptr) *error = "Failed to create ALTS handshaker client"; return TSI_FAILED_PRECONDITION; } @@ -449,7 +448,7 @@ static tsi_result alts_tsi_handshaker_continue_handshaker_next( CHECK_EQ(handshaker->client, nullptr); handshaker->client = client; if (handshaker->shutdown) { - gpr_log(GPR_INFO, "TSI handshake shutdown"); + LOG(INFO) << "TSI handshake shutdown"; if (error != nullptr) *error = "TSI handshaker shutdown"; return TSI_HANDSHAKE_SHUTDOWN; } @@ -529,7 +528,7 @@ static tsi_result handshaker_next( size_t* /*bytes_to_send_size*/, tsi_handshaker_result** /*result*/, tsi_handshaker_on_next_done_cb cb, void* user_data, std::string* error) { if (self == nullptr || cb == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to handshaker_next()"); + LOG(ERROR) << "Invalid arguments to handshaker_next()"; if (error != nullptr) *error = "invalid argument"; return TSI_INVALID_ARGUMENT; } @@ -538,7 +537,7 @@ static tsi_result handshaker_next( { grpc_core::MutexLock lock(&handshaker->mu); if (handshaker->shutdown) { - gpr_log(GPR_INFO, "TSI handshake shutdown"); + LOG(INFO) << "TSI handshake shutdown"; if (error != nullptr) *error = "handshake shutdown"; return TSI_HANDSHAKE_SHUTDOWN; } @@ -569,7 +568,7 @@ static tsi_result handshaker_next( tsi_result ok = alts_tsi_handshaker_continue_handshaker_next( handshaker, received_bytes, received_bytes_size, cb, user_data, error); if (ok != TSI_OK) { - gpr_log(GPR_ERROR, "Failed to schedule ALTS handshaker requests"); + LOG(ERROR) << "Failed to schedule ALTS handshaker requests"; return ok; } } @@ -651,7 +650,7 @@ tsi_result alts_tsi_handshaker_create( size_t user_specified_max_frame_size) { if (handshaker_service_url == nullptr || self == nullptr || options == nullptr || (is_client && target_name == nullptr)) { - gpr_log(GPR_ERROR, "Invalid arguments to alts_tsi_handshaker_create()"); + LOG(ERROR) << "Invalid arguments to alts_tsi_handshaker_create()"; return TSI_INVALID_ARGUMENT; } bool use_dedicated_cq = interested_parties == nullptr; diff --git a/test/core/gprpp/BUILD b/test/core/gprpp/BUILD index b6ca769f46d..177c5809b0c 100644 --- a/test/core/gprpp/BUILD +++ b/test/core/gprpp/BUILD @@ -60,6 +60,20 @@ grpc_cc_test( ], ) +grpc_cc_test( + name = "dump_args_test", + srcs = ["dump_args_test.cc"], + external_deps = [ + "gtest", + ], + language = "C++", + uses_event_engine = False, + uses_polling = False, + deps = [ + "//src/core:dump_args", + ], +) + # TODO(hork): solidify fork support requirements for EventEngines grpc_cc_test( name = "fork_test", diff --git a/test/core/gprpp/dump_args_test.cc b/test/core/gprpp/dump_args_test.cc new file mode 100644 index 00000000000..2207d4eab62 --- /dev/null +++ b/test/core/gprpp/dump_args_test.cc @@ -0,0 +1,44 @@ +// Copyright 2024 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/core/lib/gprpp/dump_args.h" + +#include + +#include "gtest/gtest.h" + +template +std::string Stringify(const T& t) { + std::ostringstream oss; + oss << t; + return oss.str(); +} + +int add(int a, int b) { return a + b; } + +TEST(DumpArgsTest, Basic) { + int a = 1; + int b = 2; + int c = 3; + EXPECT_EQ("a = 1, b = 2, c = 3", Stringify(GRPC_DUMP_ARGS(a, b, c))); +} + +TEST(DumpArgsTest, FunctionCall) { + EXPECT_EQ("add(1, 2) = 3", Stringify(GRPC_DUMP_ARGS(add(1, 2)))); +} + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tools/distrib/fix_build_deps.py b/tools/distrib/fix_build_deps.py index 03dbcc9137b..0a114910e3e 100755 --- a/tools/distrib/fix_build_deps.py +++ b/tools/distrib/fix_build_deps.py @@ -64,6 +64,7 @@ EXTERNAL_DEPS = { "absl/functional/bind_front.h": "absl/functional:bind_front", "absl/functional/function_ref.h": "absl/functional:function_ref", "absl/hash/hash.h": "absl/hash", + "absl/log/check.h": "absl/log:check", "absl/memory/memory.h": "absl/memory", "absl/meta/type_traits.h": "absl/meta:type_traits", "absl/numeric/int128.h": "absl/numeric:int128", @@ -543,9 +544,11 @@ def make_library(library): # once EventEngine lands we can clean this up deps = Choices( library, - {"//:grpc_base": ["//:grpc", "//:grpc_unsecure"]} - if library.startswith("//test/") - else {}, + ( + {"//:grpc_base": ["//:grpc", "//:grpc_unsecure"]} + if library.startswith("//test/") + else {} + ), ) external_deps = Choices(None, {}) for hdr in hdrs: diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 61b98ca9bd1..a733817a370 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -2969,6 +2969,30 @@ ], "uses_polling": true }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "dump_args_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": false + }, { "args": [], "benchmark": false,