diff --git a/BUILD b/BUILD index 81e1ad65cd1..0c611f2db1e 100644 --- a/BUILD +++ b/BUILD @@ -296,6 +296,7 @@ GRPC_PUBLIC_HDRS = [ "include/grpc/grpc_posix.h", "include/grpc/grpc_security.h", "include/grpc/grpc_security_constants.h", + "include/grpc/passive_listener.h", "include/grpc/slice.h", "include/grpc/slice_buffer.h", "include/grpc/status.h", @@ -457,6 +458,7 @@ GRPCXX_PUBLIC_HDRS = [ "include/grpcpp/impl/service_type.h", "include/grpcpp/impl/status.h", "include/grpcpp/impl/sync.h", + "include/grpcpp/passive_listener.h", "include/grpcpp/resource_quota.h", "include/grpcpp/security/audit_logging.h", "include/grpcpp/security/tls_crl_provider.h", @@ -581,6 +583,7 @@ grpc_cc_library( defines = ["GRPC_NO_XDS"], external_deps = [ "absl/base:core_headers", + "absl/log:log", ], language = "c++", public_hdrs = GRPC_PUBLIC_HDRS, @@ -652,6 +655,7 @@ grpc_cc_library( }), external_deps = [ "absl/base:core_headers", + "absl/log:log", ], language = "c++", public_hdrs = GRPC_PUBLIC_HDRS, @@ -730,31 +734,6 @@ grpc_cc_library( grpc_cc_library( name = "gpr", srcs = [ - "//src/core:lib/gpr/alloc.cc", - "//src/core:lib/gpr/android/log.cc", - "//src/core:lib/gpr/iphone/cpu.cc", - "//src/core:lib/gpr/linux/cpu.cc", - "//src/core:lib/gpr/linux/log.cc", - "//src/core:lib/gpr/log.cc", - "//src/core:lib/gpr/msys/tmpfile.cc", - "//src/core:lib/gpr/posix/cpu.cc", - "//src/core:lib/gpr/posix/log.cc", - "//src/core:lib/gpr/posix/string.cc", - "//src/core:lib/gpr/posix/sync.cc", - "//src/core:lib/gpr/posix/time.cc", - "//src/core:lib/gpr/posix/tmpfile.cc", - "//src/core:lib/gpr/string.cc", - "//src/core:lib/gpr/sync.cc", - "//src/core:lib/gpr/sync_abseil.cc", - "//src/core:lib/gpr/time.cc", - "//src/core:lib/gpr/time_precise.cc", - "//src/core:lib/gpr/windows/cpu.cc", - "//src/core:lib/gpr/windows/log.cc", - "//src/core:lib/gpr/windows/string.cc", - "//src/core:lib/gpr/windows/string_util.cc", - "//src/core:lib/gpr/windows/sync.cc", - "//src/core:lib/gpr/windows/time.cc", - "//src/core:lib/gpr/windows/tmpfile.cc", "//src/core:lib/gprpp/crash.cc", "//src/core:lib/gprpp/fork.cc", "//src/core:lib/gprpp/host_port.cc", @@ -764,12 +743,33 @@ grpc_cc_library( "//src/core:lib/gprpp/time_util.cc", "//src/core:lib/gprpp/windows/stat.cc", "//src/core:lib/gprpp/windows/thd.cc", + "//src/core:util/alloc.cc", + "//src/core:util/android/log.cc", + "//src/core:util/iphone/cpu.cc", + "//src/core:util/linux/cpu.cc", + "//src/core:util/linux/log.cc", + "//src/core:util/log.cc", + "//src/core:util/msys/tmpfile.cc", + "//src/core:util/posix/cpu.cc", + "//src/core:util/posix/log.cc", + "//src/core:util/posix/string.cc", + "//src/core:util/posix/sync.cc", + "//src/core:util/posix/time.cc", + "//src/core:util/posix/tmpfile.cc", + "//src/core:util/string.cc", + "//src/core:util/sync.cc", + "//src/core:util/sync_abseil.cc", + "//src/core:util/time.cc", + "//src/core:util/time_precise.cc", + "//src/core:util/windows/cpu.cc", + "//src/core:util/windows/log.cc", + "//src/core:util/windows/string.cc", + "//src/core:util/windows/string_util.cc", + "//src/core:util/windows/sync.cc", + "//src/core:util/windows/time.cc", + "//src/core:util/windows/tmpfile.cc", ], hdrs = [ - "//src/core:lib/gpr/alloc.h", - "//src/core:lib/gpr/string.h", - "//src/core:lib/gpr/time_precise.h", - "//src/core:lib/gpr/tmpfile.h", "//src/core:lib/gprpp/crash.h", "//src/core:lib/gprpp/fork.h", "//src/core:lib/gprpp/host_port.h", @@ -779,15 +779,19 @@ grpc_cc_library( "//src/core:lib/gprpp/sync.h", "//src/core:lib/gprpp/thd.h", "//src/core:lib/gprpp/time_util.h", + "//src/core:util/alloc.h", + "//src/core:util/string.h", + "//src/core:util/time_precise.h", + "//src/core:util/tmpfile.h", ], external_deps = [ "absl/base", "absl/base:core_headers", "absl/base:log_severity", "absl/functional:any_invocable", - "absl/log", "absl/log:check", "absl/log:globals", + "absl/log:log", "absl/memory", "absl/random", "absl/status", @@ -883,7 +887,7 @@ grpc_cc_library( grpc_cc_library( name = "grpc_public_hdrs", - hdrs = GRPC_PUBLIC_HDRS, + hdrs = GRPC_PUBLIC_HDRS + GRPC_PUBLIC_EVENT_ENGINE_HDRS, external_deps = [ "absl/status:statusor", "absl/strings", @@ -904,6 +908,7 @@ grpc_cc_library( hdrs = GRPCXX_PUBLIC_HDRS, external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings:cord", "absl/synchronization", "protobuf_headers", @@ -934,6 +939,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings:cord", ], language = "c++", @@ -1003,6 +1009,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -1062,6 +1069,7 @@ grpc_cc_library( ], external_deps = [ "absl/container:flat_hash_set", + "absl/log:log", "absl/strings", "absl/types:optional", "absl/types:span", @@ -1134,6 +1142,7 @@ grpc_cc_library( "absl/functional:any_invocable", "absl/hash", "absl/log:check", + "absl/log:log", "absl/memory", "absl/meta:type_traits", "absl/status", @@ -1247,6 +1256,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", "absl/synchronization", ], @@ -1297,6 +1307,7 @@ grpc_cc_library( "include/grpcpp/security/alts_util.h", ], external_deps = [ + "absl/log:log", "@com_google_protobuf//upb:base", "@com_google_protobuf//upb:mem", "@com_google_protobuf//upb:message", @@ -1379,6 +1390,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/status:statusor", "absl/strings", "absl/types:optional", @@ -1438,6 +1450,7 @@ grpc_cc_library( external_deps = [ "absl/container:inlined_vector", "absl/log:check", + "absl/log:log", ], language = "c++", deps = [ @@ -1489,6 +1502,9 @@ grpc_cc_library( hdrs = [ "//src/core:lib/surface/api_trace.h", ], + external_deps = [ + "absl/log:log", + ], language = "c++", deps = [ "gpr", @@ -1643,6 +1659,7 @@ grpc_cc_library( "absl/container:flat_hash_set", "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -1806,6 +1823,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/types:optional", @@ -1895,6 +1913,7 @@ grpc_cc_library( "absl/container:flat_hash_set", "absl/hash", "absl/log:check", + "absl/log:log", "absl/random", "absl/status", "absl/status:statusor", @@ -1924,9 +1943,7 @@ grpc_cc_library( "promise", "ref_counted_ptr", "stats", - "//src/core:1999", "//src/core:activity", - "//src/core:arena", "//src/core:arena_promise", "//src/core:cancel_callback", "//src/core:channel_args", @@ -1940,6 +1957,7 @@ grpc_cc_library( "//src/core:error", "//src/core:error_utils", "//src/core:experiments", + "//src/core:interception_chain", "//src/core:iomgr_fwd", "//src/core:map", "//src/core:metadata_batch", @@ -2013,6 +2031,7 @@ grpc_cc_library( "absl/functional:any_invocable", "absl/functional:function_ref", "absl/log:check", + "absl/log:log", "absl/meta:type_traits", "absl/status", "absl/status:statusor", @@ -2059,10 +2078,12 @@ grpc_cc_library( "//src/core:arena_promise", "//src/core:atomic_utils", "//src/core:bitset", + "//src/core:call_destination", "//src/core:call_filters", "//src/core:call_final_info", "//src/core:call_finalization", "//src/core:call_spine", + "//src/core:cancel_callback", "//src/core:channel_args", "//src/core:channel_args_preconditioning", "//src/core:channel_fwd", @@ -2140,6 +2161,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", ], language = "c++", deps = [ @@ -2172,6 +2194,9 @@ grpc_cc_library( "src/cpp/server/load_reporter/load_reporting_service_server_builder_option.cc", "src/cpp/server/load_reporter/util.cc", ], + external_deps = [ + "absl/log:log", + ], language = "c++", public_hdrs = [ "include/grpcpp/ext/server_load_reporting.h", @@ -2200,6 +2225,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/memory", "protobuf_headers", ], @@ -2224,6 +2250,9 @@ grpc_cc_library( hdrs = [ "src/cpp/server/load_reporter/get_cpu_stats.h", ], + external_deps = [ + "absl/log:log", + ], language = "c++", deps = [ "gpr", @@ -2242,6 +2271,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "opencensus-stats", "opencensus-tags", "protobuf_headers", @@ -2287,6 +2317,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/container:inlined_vector", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -2394,6 +2425,7 @@ grpc_cc_library( "//src/core:tsi/alts/handshaker/transport_security_common_api.h", ], external_deps = [ + "absl/log:log", "@com_google_protobuf//upb:base", "@com_google_protobuf//upb:mem", ], @@ -2452,6 +2484,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -2508,6 +2541,7 @@ grpc_cc_library( "//src/core:grpc_backend_metric_provider", "//src/core:grpc_crl_provider", "//src/core:grpc_service_config", + "//src/core:grpc_transport_chttp2_server", "//src/core:grpc_transport_inproc", "//src/core:json", "//src/core:json_reader", @@ -2535,6 +2569,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -2566,6 +2601,7 @@ grpc_cc_library( "grpc_security_base", "grpc_service_config_impl", "grpc_trace", + "grpc_transport_chttp2", "grpc_unsecure", "grpcpp_backend_metric_recorder", "grpcpp_call_metric_recorder", @@ -2587,6 +2623,7 @@ grpc_cc_library( "//src/core:grpc_backend_metric_provider", "//src/core:grpc_insecure_credentials", "//src/core:grpc_service_config", + "//src/core:grpc_transport_chttp2_server", "//src/core:grpc_transport_inproc", "//src/core:ref_counted", "//src/core:resource_quota", @@ -2689,6 +2726,7 @@ grpc_cc_library( ], external_deps = [ "absl/base:core_headers", + "absl/log:log", "absl/strings", ], language = "c++", @@ -2965,6 +3003,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/container:inlined_vector", "absl/log:check", + "absl/log:log", ], language = "c++", visibility = ["@grpc:client_channel"], @@ -2985,7 +3024,10 @@ grpc_cc_library( name = "grpc_trace", srcs = ["//src/core:lib/debug/trace.cc"], hdrs = ["//src/core:lib/debug/trace.h"], - external_deps = ["absl/strings"], + external_deps = [ + "absl/log:log", + "absl/strings", + ], language = "c++", visibility = ["@grpc:trace"], deps = [ @@ -3130,6 +3172,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/container:inlined_vector", "absl/log:check", + "absl/log:log", "absl/status", "absl/strings:str_format", ], @@ -3166,6 +3209,7 @@ grpc_cc_library( ], external_deps = [ "absl/base:core_headers", + "absl/log:log", "absl/status", "absl/strings", "absl/types:optional", @@ -3212,6 +3256,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings:str_format", ], visibility = [ @@ -3243,6 +3288,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -3277,6 +3323,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", "absl/strings:str_format", ], @@ -3305,6 +3352,9 @@ grpc_cc_library( hdrs = [ "//src/core:lib/iomgr/internal_errqueue.h", ], + external_deps = [ + "absl/log:log", + ], tags = ["nofixdeps"], visibility = ["@grpc:iomgr_internal_errqueue"], deps = [ @@ -3323,6 +3373,7 @@ grpc_cc_library( "//src/core:lib/iomgr/buffer_list.h", ], external_deps = [ + "absl/log:log", "absl/strings", "absl/strings:str_format", "absl/types:optional", @@ -3369,6 +3420,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -3536,6 +3588,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -3569,6 +3622,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/status", "absl/strings", "@com_google_protobuf//upb:base", @@ -3611,6 +3665,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/strings", ], @@ -3667,6 +3722,7 @@ grpc_cc_library( "absl/container:inlined_vector", "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -3801,6 +3857,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -3865,6 +3922,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/functional:bind_front", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -3919,6 +3977,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/strings", "absl/types:optional", @@ -3963,6 +4022,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", ], language = "c++", visibility = [ @@ -3990,6 +4050,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -4050,7 +4111,10 @@ grpc_cc_library( "//src/core:lib/security/security_connector/load_system_roots_supported.h", "//src/core:lib/security/util/json_util.h", ], - external_deps = ["absl/strings"], + external_deps = [ + "absl/log:log", + "absl/strings", + ], language = "c++", visibility = ["@grpc:public"], deps = [ @@ -4082,6 +4146,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", "@com_google_protobuf//upb:base", "@com_google_protobuf//upb:mem", @@ -4142,6 +4207,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/types:span", "libcrypto", "libssl", @@ -4173,6 +4239,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/memory", "libssl", ], @@ -4204,6 +4271,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -4252,6 +4320,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -4337,6 +4406,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/cleanup", "absl/log:check", + "absl/log:log", "absl/memory", "absl/status", "absl/status:statusor", @@ -4503,6 +4573,7 @@ grpc_cc_library( external_deps = [ "absl/functional:function_ref", "absl/log:check", + "absl/log:log", "absl/status", "absl/strings", ], @@ -4559,6 +4630,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/random:bit_gen_ref", "absl/status", "absl/strings", @@ -4601,6 +4673,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", ], deps = [ @@ -4714,6 +4787,7 @@ grpc_cc_library( "absl/container:flat_hash_map", "absl/hash", "absl/log:check", + "absl/log:log", "absl/meta:type_traits", "absl/random", "absl/random:bit_gen_ref", @@ -4832,14 +4906,15 @@ grpc_cc_library( grpc_cc_library( name = "subprocess", srcs = [ - "//src/core:lib/gpr/subprocess_posix.cc", - "//src/core:lib/gpr/subprocess_windows.cc", + "//src/core:util/subprocess_posix.cc", + "//src/core:util/subprocess_windows.cc", ], hdrs = [ - "//src/core:lib/gpr/subprocess.h", + "//src/core:util/subprocess.h", ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", "absl/types:span", ], diff --git a/CMakeLists.txt b/CMakeLists.txt index 787db67baa0..d0172728836 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) @@ -1457,7 +1458,6 @@ if(gRPC_BUILD_TESTS) add_dependencies(buildtests_cxx test_core_event_engine_posix_timer_heap_test) add_dependencies(buildtests_cxx test_core_event_engine_posix_timer_list_test) add_dependencies(buildtests_cxx test_core_event_engine_slice_buffer_test) - add_dependencies(buildtests_cxx test_core_gpr_time_test) add_dependencies(buildtests_cxx test_core_gprpp_time_test) add_dependencies(buildtests_cxx test_core_iomgr_timer_heap_test) add_dependencies(buildtests_cxx test_core_security_credentials_test) @@ -1467,6 +1467,7 @@ if(gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_cxx test_core_transport_test_suite_chaotic_good_test) endif() + add_dependencies(buildtests_cxx test_core_util_time_test) add_dependencies(buildtests_cxx test_cpp_client_credentials_test) add_dependencies(buildtests_cxx test_cpp_end2end_ssl_credentials_test) add_dependencies(buildtests_cxx test_cpp_ext_chaotic_good_test) @@ -1660,32 +1661,6 @@ add_library(gpr src/core/lib/config/config_vars_non_generated.cc src/core/lib/config/load_config.cc src/core/lib/event_engine/thread_local.cc - src/core/lib/gpr/alloc.cc - src/core/lib/gpr/android/log.cc - src/core/lib/gpr/atm.cc - src/core/lib/gpr/iphone/cpu.cc - src/core/lib/gpr/linux/cpu.cc - src/core/lib/gpr/linux/log.cc - src/core/lib/gpr/log.cc - src/core/lib/gpr/msys/tmpfile.cc - src/core/lib/gpr/posix/cpu.cc - src/core/lib/gpr/posix/log.cc - src/core/lib/gpr/posix/string.cc - src/core/lib/gpr/posix/sync.cc - src/core/lib/gpr/posix/time.cc - src/core/lib/gpr/posix/tmpfile.cc - src/core/lib/gpr/string.cc - src/core/lib/gpr/sync.cc - src/core/lib/gpr/sync_abseil.cc - src/core/lib/gpr/time.cc - src/core/lib/gpr/time_precise.cc - src/core/lib/gpr/windows/cpu.cc - src/core/lib/gpr/windows/log.cc - src/core/lib/gpr/windows/string.cc - src/core/lib/gpr/windows/string_util.cc - src/core/lib/gpr/windows/sync.cc - src/core/lib/gpr/windows/time.cc - src/core/lib/gpr/windows/tmpfile.cc src/core/lib/gprpp/crash.cc src/core/lib/gprpp/examine_stack.cc src/core/lib/gprpp/fork.cc @@ -1701,6 +1676,32 @@ add_library(gpr src/core/lib/gprpp/windows/env.cc src/core/lib/gprpp/windows/stat.cc src/core/lib/gprpp/windows/thd.cc + src/core/util/alloc.cc + src/core/util/android/log.cc + src/core/util/atm.cc + src/core/util/iphone/cpu.cc + src/core/util/linux/cpu.cc + src/core/util/linux/log.cc + src/core/util/log.cc + src/core/util/msys/tmpfile.cc + src/core/util/posix/cpu.cc + src/core/util/posix/log.cc + src/core/util/posix/string.cc + src/core/util/posix/sync.cc + src/core/util/posix/time.cc + src/core/util/posix/tmpfile.cc + src/core/util/string.cc + src/core/util/sync.cc + src/core/util/sync_abseil.cc + src/core/util/time.cc + src/core/util/time_precise.cc + src/core/util/windows/cpu.cc + src/core/util/windows/log.cc + src/core/util/windows/string.cc + src/core/util/windows/string_util.cc + src/core/util/windows/sync.cc + src/core/util/windows/time.cc + src/core/util/windows/tmpfile.cc ) target_compile_features(gpr PUBLIC cxx_std_14) @@ -2501,6 +2502,7 @@ add_library(grpc src/core/lib/transport/call_spine.cc src/core/lib/transport/connectivity_state.cc src/core/lib/transport/error_utils.cc + src/core/lib/transport/interception_chain.cc src/core/lib/transport/message.cc src/core/lib/transport/metadata.cc src/core/lib/transport/metadata_batch.cc @@ -2746,6 +2748,7 @@ foreach(_hdr include/grpc/impl/propagation_bits.h include/grpc/impl/slice_type.h include/grpc/load_reporting.h + include/grpc/passive_listener.h include/grpc/slice.h include/grpc/slice_buffer.h include/grpc/status.h @@ -3253,6 +3256,7 @@ add_library(grpc_unsecure src/core/lib/transport/call_spine.cc src/core/lib/transport/connectivity_state.cc src/core/lib/transport/error_utils.cc + src/core/lib/transport/interception_chain.cc src/core/lib/transport/message.cc src/core/lib/transport/metadata.cc src/core/lib/transport/metadata_batch.cc @@ -3446,6 +3450,7 @@ foreach(_hdr include/grpc/impl/propagation_bits.h include/grpc/impl/slice_type.h include/grpc/load_reporting.h + include/grpc/passive_listener.h include/grpc/slice.h include/grpc/slice_buffer.h include/grpc/status.h @@ -4314,6 +4319,7 @@ foreach(_hdr include/grpcpp/impl/service_type.h include/grpcpp/impl/status.h include/grpcpp/impl/sync.h + include/grpcpp/passive_listener.h include/grpcpp/resource_quota.h include/grpcpp/security/audit_logging.h include/grpcpp/security/auth_context.h @@ -4731,8 +4737,8 @@ endif() if(gRPC_BUILD_TESTS) add_library(grpc++_test_util - src/core/lib/gpr/subprocess_posix.cc - src/core/lib/gpr/subprocess_windows.cc + src/core/util/subprocess_posix.cc + src/core/util/subprocess_windows.cc test/core/end2end/data/client_certs.cc test/core/end2end/data/server1_cert.cc test/core/end2end/data/server1_key.cc @@ -5054,6 +5060,7 @@ foreach(_hdr include/grpcpp/impl/service_type.h include/grpcpp/impl/status.h include/grpcpp/impl/sync.h + include/grpcpp/passive_listener.h include/grpcpp/resource_quota.h include/grpcpp/security/audit_logging.h include/grpcpp/security/auth_context.h @@ -5361,6 +5368,7 @@ add_library(grpc_authorization_provider src/core/lib/transport/call_spine.cc src/core/lib/transport/connectivity_state.cc src/core/lib/transport/error_utils.cc + src/core/lib/transport/interception_chain.cc src/core/lib/transport/message.cc src/core/lib/transport/metadata.cc src/core/lib/transport/metadata_batch.cc @@ -5504,6 +5512,7 @@ foreach(_hdr include/grpc/impl/propagation_bits.h include/grpc/impl/slice_type.h include/grpc/load_reporting.h + include/grpc/passive_listener.h include/grpc/slice.h include/grpc/slice_buffer.h include/grpc/status.h @@ -6080,8 +6089,8 @@ if(gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_executable(address_sorting_test_unsecure - src/core/lib/gpr/subprocess_posix.cc - src/core/lib/gpr/subprocess_windows.cc + src/core/util/subprocess_posix.cc + src/core/util/subprocess_windows.cc test/core/test_util/cmdline.cc test/core/test_util/fuzzer_util.cc test/core/test_util/grpc_profiler.cc @@ -6304,7 +6313,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(alloc_test - test/core/gpr/alloc_test.cc + test/core/util/alloc_test.cc ) if(WIN32 AND MSVC) if(BUILD_SHARED_LIBS) @@ -7615,8 +7624,8 @@ if(gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_executable(bad_ssl_alpn_test - src/core/lib/gpr/subprocess_posix.cc - src/core/lib/gpr/subprocess_windows.cc + src/core/util/subprocess_posix.cc + src/core/util/subprocess_windows.cc test/core/bad_ssl/bad_ssl_test.cc test/core/end2end/cq_verifier.cc test/core/test_util/cmdline.cc @@ -7671,8 +7680,8 @@ if(gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_executable(bad_ssl_cert_test - src/core/lib/gpr/subprocess_posix.cc - src/core/lib/gpr/subprocess_windows.cc + src/core/util/subprocess_posix.cc + src/core/util/subprocess_windows.cc test/core/bad_ssl/bad_ssl_test.cc test/core/end2end/cq_verifier.cc test/core/test_util/cmdline.cc @@ -11713,7 +11722,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(cpu_test - test/core/gpr/cpu_test.cc + test/core/util/cpu_test.cc ) if(WIN32 AND MSVC) if(BUILD_SHARED_LIBS) @@ -12385,6 +12394,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 @@ -12874,7 +12918,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(env_test - test/core/gpr/env_test.cc + test/core/util/env_test.cc ) if(WIN32 AND MSVC) if(BUILD_SHARED_LIBS) @@ -19074,7 +19118,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(log_test - test/core/gpr/log_test.cc + test/core/util/log_test.cc ) if(WIN32 AND MSVC) if(BUILD_SHARED_LIBS) @@ -26833,6 +26877,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.grpc.pb.h + test/core/event_engine/event_engine_test_utils.cc test/core/test_util/cmdline.cc test/core/test_util/fuzzer_util.cc test/core/test_util/grpc_profiler.cc @@ -28495,7 +28540,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(spinlock_test - test/core/gpr/spinlock_test.cc + test/core/util/spinlock_test.cc ) if(WIN32 AND MSVC) if(BUILD_SHARED_LIBS) @@ -29241,7 +29286,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(string_test - test/core/gpr/string_test.cc + test/core/util/string_test.cc ) if(WIN32 AND MSVC) if(BUILD_SHARED_LIBS) @@ -29326,7 +29371,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(sync_test - test/core/gpr/sync_test.cc + test/core/util/sync_test.cc ) if(WIN32 AND MSVC) if(BUILD_SHARED_LIBS) @@ -29953,48 +29998,6 @@ target_link_libraries(test_core_event_engine_slice_buffer_test ) -endif() -if(gRPC_BUILD_TESTS) - -add_executable(test_core_gpr_time_test - test/core/gpr/time_test.cc -) -if(WIN32 AND MSVC) - if(BUILD_SHARED_LIBS) - target_compile_definitions(test_core_gpr_time_test - PRIVATE - "GPR_DLL_IMPORTS" - "GRPC_DLL_IMPORTS" - ) - endif() -endif() -target_compile_features(test_core_gpr_time_test PUBLIC cxx_std_14) -target_include_directories(test_core_gpr_time_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(test_core_gpr_time_test - ${_gRPC_ALLTARGETS_LIBRARIES} - gtest - grpc_test_util -) - - endif() if(gRPC_BUILD_TESTS) @@ -30342,6 +30345,48 @@ endif() endif() if(gRPC_BUILD_TESTS) +add_executable(test_core_util_time_test + test/core/util/time_test.cc +) +if(WIN32 AND MSVC) + if(BUILD_SHARED_LIBS) + target_compile_definitions(test_core_util_time_test + PRIVATE + "GPR_DLL_IMPORTS" + "GRPC_DLL_IMPORTS" + ) + endif() +endif() +target_compile_features(test_core_util_time_test PUBLIC cxx_std_14) +target_include_directories(test_core_util_time_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(test_core_util_time_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + grpc_test_util +) + + +endif() +if(gRPC_BUILD_TESTS) + add_executable(test_cpp_client_credentials_test test/cpp/client/credentials_test.cc test/cpp/util/tls_test_utils.cc @@ -32019,7 +32064,7 @@ endif() if(gRPC_BUILD_TESTS) add_executable(useful_test - test/core/gpr/useful_test.cc + test/core/util/useful_test.cc ) target_compile_features(useful_test PUBLIC cxx_std_14) target_include_directories(useful_test diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 6d868d6bc27..5c36c24f156 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -40,6 +40,7 @@ for general contribution guidelines. - [vishalpowar](https://github.com/vishalpowar), Google LLC - [wenbozhu](https://github.com/wenbozhu), Google LLC - [yashykt](https://github.com/yashykt), Google LLC +- [yijiem](https://github.com/yijiem), Google LLC - [ZhouyihaiDing](https://github.com/ZhouyihaiDing), Google LLC diff --git a/Makefile b/Makefile index a62edd7fca3..5e22b66b5ee 100644 --- a/Makefile +++ b/Makefile @@ -1141,32 +1141,6 @@ LIBGRPC_SRC = \ src/core/lib/event_engine/work_queue/basic_work_queue.cc \ src/core/lib/experiments/config.cc \ src/core/lib/experiments/experiments.cc \ - src/core/lib/gpr/alloc.cc \ - src/core/lib/gpr/android/log.cc \ - src/core/lib/gpr/atm.cc \ - src/core/lib/gpr/iphone/cpu.cc \ - src/core/lib/gpr/linux/cpu.cc \ - src/core/lib/gpr/linux/log.cc \ - src/core/lib/gpr/log.cc \ - src/core/lib/gpr/msys/tmpfile.cc \ - src/core/lib/gpr/posix/cpu.cc \ - src/core/lib/gpr/posix/log.cc \ - src/core/lib/gpr/posix/string.cc \ - src/core/lib/gpr/posix/sync.cc \ - src/core/lib/gpr/posix/time.cc \ - src/core/lib/gpr/posix/tmpfile.cc \ - src/core/lib/gpr/string.cc \ - src/core/lib/gpr/sync.cc \ - src/core/lib/gpr/sync_abseil.cc \ - src/core/lib/gpr/time.cc \ - src/core/lib/gpr/time_precise.cc \ - src/core/lib/gpr/windows/cpu.cc \ - src/core/lib/gpr/windows/log.cc \ - src/core/lib/gpr/windows/string.cc \ - src/core/lib/gpr/windows/string_util.cc \ - src/core/lib/gpr/windows/sync.cc \ - src/core/lib/gpr/windows/time.cc \ - src/core/lib/gpr/windows/tmpfile.cc \ src/core/lib/gprpp/crash.cc \ src/core/lib/gprpp/examine_stack.cc \ src/core/lib/gprpp/fork.cc \ @@ -1387,6 +1361,7 @@ LIBGRPC_SRC = \ src/core/lib/transport/call_spine.cc \ src/core/lib/transport/connectivity_state.cc \ src/core/lib/transport/error_utils.cc \ + src/core/lib/transport/interception_chain.cc \ src/core/lib/transport/message.cc \ src/core/lib/transport/metadata.cc \ src/core/lib/transport/metadata_batch.cc \ @@ -1484,6 +1459,32 @@ LIBGRPC_SRC = \ src/core/tsi/ssl_transport_security_utils.cc \ src/core/tsi/transport_security.cc \ src/core/tsi/transport_security_grpc.cc \ + src/core/util/alloc.cc \ + src/core/util/android/log.cc \ + src/core/util/atm.cc \ + src/core/util/iphone/cpu.cc \ + src/core/util/linux/cpu.cc \ + src/core/util/linux/log.cc \ + src/core/util/log.cc \ + src/core/util/msys/tmpfile.cc \ + src/core/util/posix/cpu.cc \ + src/core/util/posix/log.cc \ + src/core/util/posix/string.cc \ + src/core/util/posix/sync.cc \ + src/core/util/posix/time.cc \ + src/core/util/posix/tmpfile.cc \ + src/core/util/string.cc \ + src/core/util/sync.cc \ + src/core/util/sync_abseil.cc \ + src/core/util/time.cc \ + src/core/util/time_precise.cc \ + src/core/util/windows/cpu.cc \ + src/core/util/windows/log.cc \ + src/core/util/windows/string.cc \ + src/core/util/windows/string_util.cc \ + src/core/util/windows/sync.cc \ + src/core/util/windows/time.cc \ + src/core/util/windows/tmpfile.cc \ src/core/xds/grpc/certificate_provider_store.cc \ src/core/xds/grpc/file_watcher_certificate_provider_factory.cc \ src/core/xds/grpc/xds_audit_logger_registry.cc \ @@ -1775,6 +1776,7 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/propagation_bits.h \ include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ + include/grpc/passive_listener.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ include/grpc/status.h \ diff --git a/Package.swift b/Package.swift index 9a1f76a9dc2..2cfe0e1798e 100644 --- a/Package.swift +++ b/Package.swift @@ -93,6 +93,7 @@ let package = Package( "include/grpc/impl/propagation_bits.h", "include/grpc/impl/slice_type.h", "include/grpc/load_reporting.h", + "include/grpc/passive_listener.h", "include/grpc/slice.h", "include/grpc/slice_buffer.h", "include/grpc/status.h", @@ -1254,38 +1255,6 @@ let package = Package( "src/core/lib/experiments/config.h", "src/core/lib/experiments/experiments.cc", "src/core/lib/experiments/experiments.h", - "src/core/lib/gpr/alloc.cc", - "src/core/lib/gpr/alloc.h", - "src/core/lib/gpr/android/log.cc", - "src/core/lib/gpr/atm.cc", - "src/core/lib/gpr/iphone/cpu.cc", - "src/core/lib/gpr/linux/cpu.cc", - "src/core/lib/gpr/linux/log.cc", - "src/core/lib/gpr/log.cc", - "src/core/lib/gpr/msys/tmpfile.cc", - "src/core/lib/gpr/posix/cpu.cc", - "src/core/lib/gpr/posix/log.cc", - "src/core/lib/gpr/posix/string.cc", - "src/core/lib/gpr/posix/sync.cc", - "src/core/lib/gpr/posix/time.cc", - "src/core/lib/gpr/posix/tmpfile.cc", - "src/core/lib/gpr/spinlock.h", - "src/core/lib/gpr/string.cc", - "src/core/lib/gpr/string.h", - "src/core/lib/gpr/sync.cc", - "src/core/lib/gpr/sync_abseil.cc", - "src/core/lib/gpr/time.cc", - "src/core/lib/gpr/time_precise.cc", - "src/core/lib/gpr/time_precise.h", - "src/core/lib/gpr/tmpfile.h", - "src/core/lib/gpr/useful.h", - "src/core/lib/gpr/windows/cpu.cc", - "src/core/lib/gpr/windows/log.cc", - "src/core/lib/gpr/windows/string.cc", - "src/core/lib/gpr/windows/string_util.cc", - "src/core/lib/gpr/windows/sync.cc", - "src/core/lib/gpr/windows/time.cc", - "src/core/lib/gpr/windows/tmpfile.cc", "src/core/lib/gprpp/atomic_utils.h", "src/core/lib/gprpp/bitset.h", "src/core/lib/gprpp/chunked_vector.h", @@ -1748,6 +1717,7 @@ let package = Package( "src/core/lib/transport/bdp_estimator.h", "src/core/lib/transport/call_arena_allocator.cc", "src/core/lib/transport/call_arena_allocator.h", + "src/core/lib/transport/call_destination.h", "src/core/lib/transport/call_filters.cc", "src/core/lib/transport/call_filters.h", "src/core/lib/transport/call_final_info.cc", @@ -1760,6 +1730,8 @@ let package = Package( "src/core/lib/transport/error_utils.cc", "src/core/lib/transport/error_utils.h", "src/core/lib/transport/http2_errors.h", + "src/core/lib/transport/interception_chain.cc", + "src/core/lib/transport/interception_chain.h", "src/core/lib/transport/message.cc", "src/core/lib/transport/message.h", "src/core/lib/transport/metadata.cc", @@ -1952,6 +1924,38 @@ let package = Package( "src/core/tsi/transport_security_grpc.cc", "src/core/tsi/transport_security_grpc.h", "src/core/tsi/transport_security_interface.h", + "src/core/util/alloc.cc", + "src/core/util/alloc.h", + "src/core/util/android/log.cc", + "src/core/util/atm.cc", + "src/core/util/iphone/cpu.cc", + "src/core/util/linux/cpu.cc", + "src/core/util/linux/log.cc", + "src/core/util/log.cc", + "src/core/util/msys/tmpfile.cc", + "src/core/util/posix/cpu.cc", + "src/core/util/posix/log.cc", + "src/core/util/posix/string.cc", + "src/core/util/posix/sync.cc", + "src/core/util/posix/time.cc", + "src/core/util/posix/tmpfile.cc", + "src/core/util/spinlock.h", + "src/core/util/string.cc", + "src/core/util/string.h", + "src/core/util/sync.cc", + "src/core/util/sync_abseil.cc", + "src/core/util/time.cc", + "src/core/util/time_precise.cc", + "src/core/util/time_precise.h", + "src/core/util/tmpfile.h", + "src/core/util/useful.h", + "src/core/util/windows/cpu.cc", + "src/core/util/windows/log.cc", + "src/core/util/windows/string.cc", + "src/core/util/windows/string_util.cc", + "src/core/util/windows/sync.cc", + "src/core/util/windows/time.cc", + "src/core/util/windows/tmpfile.cc", "src/core/xds/grpc/certificate_provider_store.cc", "src/core/xds/grpc/certificate_provider_store.h", "src/core/xds/grpc/file_watcher_certificate_provider_factory.cc", diff --git a/bazel/experiments.bzl b/bazel/experiments.bzl index abd1166647f..e3aeb05464d 100644 --- a/bazel/experiments.bzl +++ b/bazel/experiments.bzl @@ -31,12 +31,10 @@ EXPERIMENT_ENABLES = { "monitoring_experiment": "monitoring_experiment", "multiping": "multiping", "peer_state_based_framing": "peer_state_based_framing", - "pending_queue_cap": "pending_queue_cap", "pick_first_new": "pick_first_new", "promise_based_client_call": "event_engine_client,event_engine_listener,promise_based_client_call", - "promise_based_server_call": "promise_based_server_call", - "chaotic_good": "chaotic_good,event_engine_client,event_engine_listener,promise_based_client_call,promise_based_server_call", - "promise_based_inproc_transport": "event_engine_client,event_engine_listener,promise_based_client_call,promise_based_inproc_transport,promise_based_server_call", + "chaotic_good": "chaotic_good,event_engine_client,event_engine_listener,promise_based_client_call", + "promise_based_inproc_transport": "event_engine_client,event_engine_listener,promise_based_client_call,promise_based_inproc_transport", "rstpit": "rstpit", "schedule_cancellation_over_write": "schedule_cancellation_over_write", "server_privacy": "server_privacy", @@ -59,17 +57,10 @@ EXPERIMENTS = { "dbg": { }, "off": { - "core_end2end_test": [ - "event_engine_client", - "promise_based_server_call", - ], "endpoint_test": [ "tcp_frame_size_tuning", "tcp_rcv_lowat", ], - "event_engine_client_test": [ - "event_engine_client", - ], "flow_control_test": [ "multiping", "peer_state_based_framing", @@ -77,27 +68,34 @@ EXPERIMENTS = { "tcp_frame_size_tuning", "tcp_rcv_lowat", ], - "logging_test": [ - "promise_based_server_call", - ], "resource_quota_test": [ "free_large_allocator", "unconstrained_max_quota_buffer_size", ], }, "on": { + "cancel_ares_query_test": [ + "event_engine_dns", + ], "core_end2end_test": [ + "event_engine_client", "event_engine_listener", ], "cpp_lb_end2end_test": [ "pick_first_new", ], + "event_engine_client_test": [ + "event_engine_client", + ], "event_engine_listener_test": [ "event_engine_listener", ], "lb_unit_test": [ "pick_first_new", ], + "resolver_component_tests_runner_invoker": [ + "event_engine_dns", + ], "xds_end2end_test": [ "pick_first_new", ], @@ -107,9 +105,6 @@ EXPERIMENTS = { "dbg": { }, "off": { - "core_end2end_test": [ - "promise_based_server_call", - ], "endpoint_test": [ "tcp_frame_size_tuning", "tcp_rcv_lowat", @@ -121,9 +116,6 @@ EXPERIMENTS = { "tcp_frame_size_tuning", "tcp_rcv_lowat", ], - "logging_test": [ - "promise_based_server_call", - ], "resource_quota_test": [ "free_large_allocator", "unconstrained_max_quota_buffer_size", @@ -149,7 +141,6 @@ EXPERIMENTS = { "chaotic_good", "event_engine_client", "promise_based_client_call", - "promise_based_server_call", ], "endpoint_test": [ "tcp_frame_size_tuning", @@ -168,9 +159,6 @@ EXPERIMENTS = { "lame_client_test": [ "promise_based_client_call", ], - "logging_test": [ - "promise_based_server_call", - ], "resource_quota_test": [ "free_large_allocator", "unconstrained_max_quota_buffer_size", diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index dd845a6d959..f72466229e9 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -55,11 +55,6 @@ libs: - src/core/lib/config/config_vars.h - src/core/lib/config/load_config.h - src/core/lib/event_engine/thread_local.h - - src/core/lib/gpr/alloc.h - - src/core/lib/gpr/string.h - - src/core/lib/gpr/time_precise.h - - src/core/lib/gpr/tmpfile.h - - src/core/lib/gpr/useful.h - src/core/lib/gprpp/construct_destruct.h - src/core/lib/gprpp/crash.h - src/core/lib/gprpp/debug_location.h @@ -76,37 +71,16 @@ libs: - src/core/lib/gprpp/tchar.h - src/core/lib/gprpp/thd.h - src/core/lib/gprpp/time_util.h + - src/core/util/alloc.h + - src/core/util/string.h + - src/core/util/time_precise.h + - src/core/util/tmpfile.h + - src/core/util/useful.h src: - src/core/lib/config/config_vars.cc - src/core/lib/config/config_vars_non_generated.cc - src/core/lib/config/load_config.cc - src/core/lib/event_engine/thread_local.cc - - src/core/lib/gpr/alloc.cc - - src/core/lib/gpr/android/log.cc - - src/core/lib/gpr/atm.cc - - src/core/lib/gpr/iphone/cpu.cc - - src/core/lib/gpr/linux/cpu.cc - - src/core/lib/gpr/linux/log.cc - - src/core/lib/gpr/log.cc - - src/core/lib/gpr/msys/tmpfile.cc - - src/core/lib/gpr/posix/cpu.cc - - src/core/lib/gpr/posix/log.cc - - src/core/lib/gpr/posix/string.cc - - src/core/lib/gpr/posix/sync.cc - - src/core/lib/gpr/posix/time.cc - - src/core/lib/gpr/posix/tmpfile.cc - - src/core/lib/gpr/string.cc - - src/core/lib/gpr/sync.cc - - src/core/lib/gpr/sync_abseil.cc - - src/core/lib/gpr/time.cc - - src/core/lib/gpr/time_precise.cc - - src/core/lib/gpr/windows/cpu.cc - - src/core/lib/gpr/windows/log.cc - - src/core/lib/gpr/windows/string.cc - - src/core/lib/gpr/windows/string_util.cc - - src/core/lib/gpr/windows/sync.cc - - src/core/lib/gpr/windows/time.cc - - src/core/lib/gpr/windows/tmpfile.cc - src/core/lib/gprpp/crash.cc - src/core/lib/gprpp/examine_stack.cc - src/core/lib/gprpp/fork.cc @@ -122,6 +96,32 @@ libs: - src/core/lib/gprpp/windows/env.cc - src/core/lib/gprpp/windows/stat.cc - src/core/lib/gprpp/windows/thd.cc + - src/core/util/alloc.cc + - src/core/util/android/log.cc + - src/core/util/atm.cc + - src/core/util/iphone/cpu.cc + - src/core/util/linux/cpu.cc + - src/core/util/linux/log.cc + - src/core/util/log.cc + - src/core/util/msys/tmpfile.cc + - src/core/util/posix/cpu.cc + - src/core/util/posix/log.cc + - src/core/util/posix/string.cc + - src/core/util/posix/sync.cc + - src/core/util/posix/time.cc + - src/core/util/posix/tmpfile.cc + - src/core/util/string.cc + - src/core/util/sync.cc + - src/core/util/sync_abseil.cc + - src/core/util/time.cc + - src/core/util/time_precise.cc + - src/core/util/windows/cpu.cc + - src/core/util/windows/log.cc + - src/core/util/windows/string.cc + - src/core/util/windows/string_util.cc + - src/core/util/windows/sync.cc + - src/core/util/windows/time.cc + - src/core/util/windows/tmpfile.cc deps: - absl/base:base - absl/base:core_headers @@ -198,6 +198,7 @@ libs: - include/grpc/impl/propagation_bits.h - include/grpc/impl/slice_type.h - include/grpc/load_reporting.h + - include/grpc/passive_listener.h - include/grpc/slice.h - include/grpc/slice_buffer.h - include/grpc/status.h @@ -881,7 +882,6 @@ libs: - src/core/lib/event_engine/work_queue/work_queue.h - src/core/lib/experiments/config.h - src/core/lib/experiments/experiments.h - - src/core/lib/gpr/spinlock.h - src/core/lib/gprpp/atomic_utils.h - src/core/lib/gprpp/bitset.h - src/core/lib/gprpp/chunked_vector.h @@ -1109,6 +1109,7 @@ libs: - src/core/lib/transport/batch_builder.h - src/core/lib/transport/bdp_estimator.h - src/core/lib/transport/call_arena_allocator.h + - src/core/lib/transport/call_destination.h - src/core/lib/transport/call_filters.h - src/core/lib/transport/call_final_info.h - src/core/lib/transport/call_spine.h @@ -1116,6 +1117,7 @@ libs: - src/core/lib/transport/custom_metadata.h - src/core/lib/transport/error_utils.h - src/core/lib/transport/http2_errors.h + - src/core/lib/transport/interception_chain.h - src/core/lib/transport/message.h - src/core/lib/transport/metadata.h - src/core/lib/transport/metadata_batch.h @@ -1211,6 +1213,7 @@ libs: - src/core/tsi/transport_security.h - src/core/tsi/transport_security_grpc.h - src/core/tsi/transport_security_interface.h + - src/core/util/spinlock.h - src/core/xds/grpc/certificate_provider_store.h - src/core/xds/grpc/file_watcher_certificate_provider_factory.h - src/core/xds/grpc/upb_utils.h @@ -1920,6 +1923,7 @@ libs: - src/core/lib/transport/call_spine.cc - src/core/lib/transport/connectivity_state.cc - src/core/lib/transport/error_utils.cc + - src/core/lib/transport/interception_chain.cc - src/core/lib/transport/message.cc - src/core/lib/transport/metadata.cc - src/core/lib/transport/metadata_batch.cc @@ -2182,6 +2186,7 @@ libs: - include/grpc/impl/propagation_bits.h - include/grpc/impl/slice_type.h - include/grpc/load_reporting.h + - include/grpc/passive_listener.h - include/grpc/slice.h - include/grpc/slice_buffer.h - include/grpc/status.h @@ -2415,7 +2420,6 @@ libs: - src/core/lib/event_engine/work_queue/work_queue.h - src/core/lib/experiments/config.h - src/core/lib/experiments/experiments.h - - src/core/lib/gpr/spinlock.h - src/core/lib/gprpp/atomic_utils.h - src/core/lib/gprpp/bitset.h - src/core/lib/gprpp/chunked_vector.h @@ -2607,6 +2611,7 @@ libs: - src/core/lib/transport/batch_builder.h - src/core/lib/transport/bdp_estimator.h - src/core/lib/transport/call_arena_allocator.h + - src/core/lib/transport/call_destination.h - src/core/lib/transport/call_filters.h - src/core/lib/transport/call_final_info.h - src/core/lib/transport/call_spine.h @@ -2614,6 +2619,7 @@ libs: - src/core/lib/transport/custom_metadata.h - src/core/lib/transport/error_utils.h - src/core/lib/transport/http2_errors.h + - src/core/lib/transport/interception_chain.h - src/core/lib/transport/message.h - src/core/lib/transport/metadata.h - src/core/lib/transport/metadata_batch.h @@ -2677,6 +2683,7 @@ libs: - src/core/tsi/transport_security.h - src/core/tsi/transport_security_grpc.h - src/core/tsi/transport_security_interface.h + - src/core/util/spinlock.h - third_party/upb/upb/generated_code_support.h - third_party/upb/upb/mini_descriptor/build_enum.h - third_party/upb/upb/mini_descriptor/decode.h @@ -3030,6 +3037,7 @@ libs: - src/core/lib/transport/call_spine.cc - src/core/lib/transport/connectivity_state.cc - src/core/lib/transport/error_utils.cc + - src/core/lib/transport/interception_chain.cc - src/core/lib/transport/message.cc - src/core/lib/transport/metadata.cc - src/core/lib/transport/metadata_batch.cc @@ -3786,6 +3794,7 @@ libs: - include/grpcpp/impl/service_type.h - include/grpcpp/impl/status.h - include/grpcpp/impl/sync.h + - include/grpcpp/passive_listener.h - include/grpcpp/resource_quota.h - include/grpcpp/security/audit_logging.h - include/grpcpp/security/auth_context.h @@ -4006,7 +4015,7 @@ libs: language: c++ public_headers: [] headers: - - src/core/lib/gpr/subprocess.h + - src/core/util/subprocess.h - test/core/end2end/data/ssl_test_data.h - test/core/test_util/cmdline.h - test/core/test_util/evaluate_args_test_util.h @@ -4025,8 +4034,8 @@ libs: - test/cpp/util/subprocess.h - test/cpp/util/test_credentials_provider.h src: - - src/core/lib/gpr/subprocess_posix.cc - - src/core/lib/gpr/subprocess_windows.cc + - src/core/util/subprocess_posix.cc + - src/core/util/subprocess_windows.cc - test/core/end2end/data/client_certs.cc - test/core/end2end/data/server1_cert.cc - test/core/end2end/data/server1_key.cc @@ -4213,6 +4222,7 @@ libs: - include/grpcpp/impl/service_type.h - include/grpcpp/impl/status.h - include/grpcpp/impl/sync.h + - include/grpcpp/passive_listener.h - include/grpcpp/resource_quota.h - include/grpcpp/security/audit_logging.h - include/grpcpp/security/auth_context.h @@ -4361,6 +4371,7 @@ libs: - include/grpc/impl/propagation_bits.h - include/grpc/impl/slice_type.h - include/grpc/load_reporting.h + - include/grpc/passive_listener.h - include/grpc/slice.h - include/grpc/slice_buffer.h - include/grpc/status.h @@ -4499,7 +4510,6 @@ libs: - src/core/lib/event_engine/work_queue/work_queue.h - src/core/lib/experiments/config.h - src/core/lib/experiments/experiments.h - - src/core/lib/gpr/spinlock.h - src/core/lib/gprpp/atomic_utils.h - src/core/lib/gprpp/bitset.h - src/core/lib/gprpp/chunked_vector.h @@ -4600,6 +4610,7 @@ libs: - src/core/lib/promise/activity.h - src/core/lib/promise/all_ok.h - src/core/lib/promise/arena_promise.h + - src/core/lib/promise/cancel_callback.h - src/core/lib/promise/context.h - src/core/lib/promise/detail/basic_seq.h - src/core/lib/promise/detail/join_state.h @@ -4681,6 +4692,7 @@ libs: - src/core/lib/surface/wait_for_cq_end_op.h - src/core/lib/transport/batch_builder.h - src/core/lib/transport/call_arena_allocator.h + - src/core/lib/transport/call_destination.h - src/core/lib/transport/call_filters.h - src/core/lib/transport/call_final_info.h - src/core/lib/transport/call_spine.h @@ -4688,6 +4700,7 @@ libs: - src/core/lib/transport/custom_metadata.h - src/core/lib/transport/error_utils.h - src/core/lib/transport/http2_errors.h + - src/core/lib/transport/interception_chain.h - src/core/lib/transport/message.h - src/core/lib/transport/metadata.h - src/core/lib/transport/metadata_batch.h @@ -4717,6 +4730,7 @@ libs: - src/core/tsi/transport_security.h - src/core/tsi/transport_security_grpc.h - src/core/tsi/transport_security_interface.h + - src/core/util/spinlock.h - third_party/upb/upb/generated_code_support.h - third_party/upb/upb/mini_descriptor/build_enum.h - third_party/upb/upb/mini_descriptor/decode.h @@ -4984,6 +4998,7 @@ libs: - src/core/lib/transport/call_spine.cc - src/core/lib/transport/connectivity_state.cc - src/core/lib/transport/error_utils.cc + - src/core/lib/transport/interception_chain.cc - src/core/lib/transport/message.cc - src/core/lib/transport/metadata.cc - src/core/lib/transport/metadata_batch.cc @@ -5267,7 +5282,7 @@ targets: build: test language: c++ headers: - - src/core/lib/gpr/subprocess.h + - src/core/util/subprocess.h - test/core/test_util/cmdline.h - test/core/test_util/evaluate_args_test_util.h - test/core/test_util/fuzzer_util.h @@ -5283,8 +5298,8 @@ targets: - test/cpp/util/string_ref_helper.h - test/cpp/util/subprocess.h src: - - src/core/lib/gpr/subprocess_posix.cc - - src/core/lib/gpr/subprocess_windows.cc + - src/core/util/subprocess_posix.cc + - src/core/util/subprocess_windows.cc - test/core/test_util/cmdline.cc - test/core/test_util/fuzzer_util.cc - test/core/test_util/grpc_profiler.cc @@ -5392,7 +5407,7 @@ targets: language: c++ headers: [] src: - - test/core/gpr/alloc_test.cc + - test/core/util/alloc_test.cc deps: - gtest - grpc_test_util @@ -5870,7 +5885,7 @@ targets: build: test language: c++ headers: - - src/core/lib/gpr/subprocess.h + - src/core/util/subprocess.h - test/core/end2end/cq_verifier.h - test/core/test_util/cmdline.h - test/core/test_util/evaluate_args_test_util.h @@ -5883,8 +5898,8 @@ targets: - test/core/test_util/slice_splitter.h - test/core/test_util/tracer_util.h src: - - src/core/lib/gpr/subprocess_posix.cc - - src/core/lib/gpr/subprocess_windows.cc + - src/core/util/subprocess_posix.cc + - src/core/util/subprocess_windows.cc - test/core/bad_ssl/bad_ssl_test.cc - test/core/end2end/cq_verifier.cc - test/core/test_util/cmdline.cc @@ -5908,7 +5923,7 @@ targets: build: test language: c++ headers: - - src/core/lib/gpr/subprocess.h + - src/core/util/subprocess.h - test/core/end2end/cq_verifier.h - test/core/test_util/cmdline.h - test/core/test_util/evaluate_args_test_util.h @@ -5921,8 +5936,8 @@ targets: - test/core/test_util/slice_splitter.h - test/core/test_util/tracer_util.h src: - - src/core/lib/gpr/subprocess_posix.cc - - src/core/lib/gpr/subprocess_windows.cc + - src/core/util/subprocess_posix.cc + - src/core/util/subprocess_windows.cc - test/core/bad_ssl/bad_ssl_test.cc - test/core/end2end/cq_verifier.cc - test/core/test_util/cmdline.cc @@ -6221,8 +6236,8 @@ targets: build: test language: c++ headers: - - src/core/lib/gpr/useful.h - src/core/lib/gprpp/bitset.h + - src/core/util/useful.h src: - test/core/gprpp/bitset_test.cc deps: @@ -6358,7 +6373,6 @@ targets: - src/core/lib/event_engine/event_engine_context.h - src/core/lib/experiments/config.h - src/core/lib/experiments/experiments.h - - src/core/lib/gpr/spinlock.h - src/core/lib/gprpp/atomic_utils.h - src/core/lib/gprpp/bitset.h - src/core/lib/gprpp/chunked_vector.h @@ -6424,6 +6438,7 @@ targets: - src/core/lib/transport/simple_slice_based_metadata.h - src/core/lib/transport/status_conversion.h - src/core/lib/transport/timeout_encoding.h + - src/core/util/spinlock.h - test/core/promise/poll_matcher.h - third_party/upb/upb/generated_code_support.h - third_party/upb/upb/mini_descriptor/build_enum.h @@ -7646,7 +7661,6 @@ targets: - src/core/lib/event_engine/event_engine_context.h - src/core/lib/experiments/config.h - src/core/lib/experiments/experiments.h - - src/core/lib/gpr/spinlock.h - src/core/lib/gprpp/atomic_utils.h - src/core/lib/gprpp/bitset.h - src/core/lib/gprpp/chunked_vector.h @@ -7690,6 +7704,7 @@ targets: - src/core/lib/slice/slice_internal.h - src/core/lib/slice/slice_refcount.h - src/core/lib/slice/slice_string_helpers.h + - src/core/util/spinlock.h - third_party/upb/upb/generated_code_support.h - third_party/upb/upb/mini_descriptor/build_enum.h - third_party/upb/upb/mini_descriptor/decode.h @@ -8387,7 +8402,7 @@ targets: language: c++ headers: [] src: - - test/core/gpr/cpu_test.cc + - test/core/util/cpu_test.cc deps: - gtest - grpc_test_util @@ -8656,6 +8671,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 @@ -8966,7 +8995,7 @@ targets: language: c++ headers: [] src: - - test/core/gpr/env_test.cc + - test/core/util/env_test.cc deps: - gtest - grpc_test_util @@ -9145,7 +9174,6 @@ targets: - src/core/lib/event_engine/event_engine_context.h - src/core/lib/experiments/config.h - src/core/lib/experiments/experiments.h - - src/core/lib/gpr/spinlock.h - src/core/lib/gprpp/atomic_utils.h - src/core/lib/gprpp/bitset.h - src/core/lib/gprpp/down_cast.h @@ -9173,6 +9201,7 @@ targets: - src/core/lib/slice/slice_internal.h - src/core/lib/slice/slice_refcount.h - src/core/lib/slice/slice_string_helpers.h + - src/core/util/spinlock.h - third_party/upb/upb/generated_code_support.h - third_party/upb/upb/mini_descriptor/build_enum.h - third_party/upb/upb/mini_descriptor/decode.h @@ -9756,7 +9785,6 @@ targets: - src/core/lib/event_engine/event_engine_context.h - src/core/lib/experiments/config.h - src/core/lib/experiments/experiments.h - - src/core/lib/gpr/spinlock.h - src/core/lib/gprpp/atomic_utils.h - src/core/lib/gprpp/bitset.h - src/core/lib/gprpp/cpp_impl_of.h @@ -9801,6 +9829,7 @@ targets: - src/core/lib/slice/slice_string_helpers.h - src/core/lib/transport/bdp_estimator.h - src/core/lib/transport/http2_errors.h + - src/core/util/spinlock.h - third_party/upb/upb/generated_code_support.h - third_party/upb/upb/mini_descriptor/build_enum.h - third_party/upb/upb/mini_descriptor/decode.h @@ -9887,7 +9916,6 @@ targets: - src/core/lib/event_engine/event_engine_context.h - src/core/lib/experiments/config.h - src/core/lib/experiments/experiments.h - - src/core/lib/gpr/spinlock.h - src/core/lib/gprpp/atomic_utils.h - src/core/lib/gprpp/bitset.h - src/core/lib/gprpp/cpp_impl_of.h @@ -9939,6 +9967,7 @@ targets: - src/core/lib/slice/slice_internal.h - src/core/lib/slice/slice_refcount.h - src/core/lib/slice/slice_string_helpers.h + - src/core/util/spinlock.h - test/core/promise/test_wakeup_schedulers.h - third_party/upb/upb/generated_code_support.h - third_party/upb/upb/mini_descriptor/build_enum.h @@ -11640,7 +11669,6 @@ targets: - src/core/lib/event_engine/work_queue/work_queue.h - src/core/lib/experiments/config.h - src/core/lib/experiments/experiments.h - - src/core/lib/gpr/spinlock.h - src/core/lib/gprpp/atomic_utils.h - src/core/lib/gprpp/bitset.h - src/core/lib/gprpp/chunked_vector.h @@ -11739,6 +11767,7 @@ targets: - src/core/lib/promise/activity.h - src/core/lib/promise/all_ok.h - src/core/lib/promise/arena_promise.h + - src/core/lib/promise/cancel_callback.h - src/core/lib/promise/context.h - src/core/lib/promise/detail/basic_seq.h - src/core/lib/promise/detail/join_state.h @@ -11833,6 +11862,7 @@ targets: - src/core/service_config/service_config_call_data.h - src/core/service_config/service_config_parser.h - src/core/tsi/alts/handshaker/transport_security_common_api.h + - src/core/util/spinlock.h - test/core/promise/poll_matcher.h - third_party/upb/upb/generated_code_support.h - third_party/upb/upb/mini_descriptor/build_enum.h @@ -12132,7 +12162,6 @@ targets: - src/core/lib/event_engine/event_engine_context.h - src/core/lib/experiments/config.h - src/core/lib/experiments/experiments.h - - src/core/lib/gpr/spinlock.h - src/core/lib/gprpp/atomic_utils.h - src/core/lib/gprpp/bitset.h - src/core/lib/gprpp/cpp_impl_of.h @@ -12176,6 +12205,7 @@ targets: - src/core/lib/slice/slice_internal.h - src/core/lib/slice/slice_refcount.h - src/core/lib/slice/slice_string_helpers.h + - src/core/util/spinlock.h - test/core/promise/test_context.h - third_party/upb/upb/generated_code_support.h - third_party/upb/upb/mini_descriptor/build_enum.h @@ -12748,7 +12778,7 @@ targets: language: c++ headers: [] src: - - test/core/gpr/log_test.cc + - test/core/util/log_test.cc deps: - gtest - grpc_test_util @@ -12805,7 +12835,6 @@ targets: - src/core/lib/event_engine/event_engine_context.h - src/core/lib/experiments/config.h - src/core/lib/experiments/experiments.h - - src/core/lib/gpr/spinlock.h - src/core/lib/gprpp/atomic_utils.h - src/core/lib/gprpp/bitset.h - src/core/lib/gprpp/cpp_impl_of.h @@ -12857,6 +12886,7 @@ targets: - src/core/lib/slice/slice_internal.h - src/core/lib/slice/slice_refcount.h - src/core/lib/slice/slice_string_helpers.h + - src/core/util/spinlock.h - test/core/promise/test_wakeup_schedulers.h - third_party/upb/upb/generated_code_support.h - third_party/upb/upb/mini_descriptor/build_enum.h @@ -14046,7 +14076,6 @@ targets: - src/core/lib/debug/trace.h - src/core/lib/experiments/config.h - src/core/lib/experiments/experiments.h - - src/core/lib/gpr/spinlock.h - src/core/lib/gprpp/bitset.h - src/core/lib/gprpp/manual_constructor.h - src/core/lib/gprpp/status_helper.h @@ -14063,6 +14092,7 @@ targets: - src/core/lib/slice/slice_internal.h - src/core/lib/slice/slice_refcount.h - src/core/lib/slice/slice_string_helpers.h + - src/core/util/spinlock.h - third_party/upb/upb/generated_code_support.h - third_party/upb/upb/mini_descriptor/build_enum.h - third_party/upb/upb/mini_descriptor/decode.h @@ -17784,6 +17814,7 @@ targets: build: test language: c++ headers: + - test/core/event_engine/event_engine_test_utils.h - test/core/test_util/cmdline.h - test/core/test_util/evaluate_args_test_util.h - test/core/test_util/fuzzer_util.h @@ -17799,6 +17830,7 @@ targets: - src/proto/grpc/testing/echo_messages.proto - src/proto/grpc/testing/simple_messages.proto - src/proto/grpc/testing/xds/v3/orca_load_report.proto + - test/core/event_engine/event_engine_test_utils.cc - test/core/test_util/cmdline.cc - test/core/test_util/fuzzer_util.cc - test/core/test_util/grpc_profiler.cc @@ -18661,7 +18693,7 @@ targets: language: c++ headers: [] src: - - test/core/gpr/spinlock_test.cc + - test/core/util/spinlock_test.cc deps: - gtest - grpc_test_util @@ -18956,7 +18988,7 @@ targets: language: c++ headers: [] src: - - test/core/gpr/string_test.cc + - test/core/util/string_test.cc deps: - gtest - grpc_test_util @@ -18985,7 +19017,7 @@ targets: language: c++ headers: [] src: - - test/core/gpr/sync_test.cc + - test/core/util/sync_test.cc deps: - gtest - grpc_test_util @@ -19024,9 +19056,9 @@ targets: build: test language: c++ headers: - - src/core/lib/gpr/useful.h - src/core/lib/gprpp/bitset.h - src/core/lib/gprpp/table.h + - src/core/util/useful.h src: - test/core/gprpp/table_test.cc deps: @@ -19313,17 +19345,6 @@ targets: - absl/status:statusor - absl/utility:utility - gpr -- name: test_core_gpr_time_test - gtest: true - build: test - language: c++ - headers: [] - src: - - test/core/gpr/time_test.cc - deps: - - gtest - - grpc_test_util - uses_polling: false - name: test_core_gprpp_time_test gtest: true build: test @@ -19495,6 +19516,17 @@ targets: - linux - posix uses_polling: false +- name: test_core_util_time_test + gtest: true + build: test + language: c++ + headers: [] + src: + - test/core/util/time_test.cc + deps: + - gtest + - grpc_test_util + uses_polling: false - name: test_cpp_client_credentials_test gtest: true build: test @@ -20195,8 +20227,8 @@ targets: build: test language: c++ headers: - - src/core/lib/gpr/useful.h - src/core/lib/gprpp/unique_type_name.h + - src/core/util/useful.h src: - test/core/gprpp/unique_type_name_test.cc deps: @@ -20232,9 +20264,9 @@ targets: build: test language: c++ headers: - - src/core/lib/gpr/useful.h + - src/core/util/useful.h src: - - test/core/gpr/useful_test.cc + - test/core/util/useful_test.cc deps: - gtest uses_polling: false diff --git a/config.m4 b/config.m4 index d44618c5775..672e7101589 100644 --- a/config.m4 +++ b/config.m4 @@ -516,32 +516,6 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/event_engine/work_queue/basic_work_queue.cc \ src/core/lib/experiments/config.cc \ src/core/lib/experiments/experiments.cc \ - src/core/lib/gpr/alloc.cc \ - src/core/lib/gpr/android/log.cc \ - src/core/lib/gpr/atm.cc \ - src/core/lib/gpr/iphone/cpu.cc \ - src/core/lib/gpr/linux/cpu.cc \ - src/core/lib/gpr/linux/log.cc \ - src/core/lib/gpr/log.cc \ - src/core/lib/gpr/msys/tmpfile.cc \ - src/core/lib/gpr/posix/cpu.cc \ - src/core/lib/gpr/posix/log.cc \ - src/core/lib/gpr/posix/string.cc \ - src/core/lib/gpr/posix/sync.cc \ - src/core/lib/gpr/posix/time.cc \ - src/core/lib/gpr/posix/tmpfile.cc \ - src/core/lib/gpr/string.cc \ - src/core/lib/gpr/sync.cc \ - src/core/lib/gpr/sync_abseil.cc \ - src/core/lib/gpr/time.cc \ - src/core/lib/gpr/time_precise.cc \ - src/core/lib/gpr/windows/cpu.cc \ - src/core/lib/gpr/windows/log.cc \ - src/core/lib/gpr/windows/string.cc \ - src/core/lib/gpr/windows/string_util.cc \ - src/core/lib/gpr/windows/sync.cc \ - src/core/lib/gpr/windows/time.cc \ - src/core/lib/gpr/windows/tmpfile.cc \ src/core/lib/gprpp/crash.cc \ src/core/lib/gprpp/examine_stack.cc \ src/core/lib/gprpp/fork.cc \ @@ -762,6 +736,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/transport/call_spine.cc \ src/core/lib/transport/connectivity_state.cc \ src/core/lib/transport/error_utils.cc \ + src/core/lib/transport/interception_chain.cc \ src/core/lib/transport/message.cc \ src/core/lib/transport/metadata.cc \ src/core/lib/transport/metadata_batch.cc \ @@ -859,6 +834,32 @@ if test "$PHP_GRPC" != "no"; then src/core/tsi/ssl_transport_security_utils.cc \ src/core/tsi/transport_security.cc \ src/core/tsi/transport_security_grpc.cc \ + src/core/util/alloc.cc \ + src/core/util/android/log.cc \ + src/core/util/atm.cc \ + src/core/util/iphone/cpu.cc \ + src/core/util/linux/cpu.cc \ + src/core/util/linux/log.cc \ + src/core/util/log.cc \ + src/core/util/msys/tmpfile.cc \ + src/core/util/posix/cpu.cc \ + src/core/util/posix/log.cc \ + src/core/util/posix/string.cc \ + src/core/util/posix/sync.cc \ + src/core/util/posix/time.cc \ + src/core/util/posix/tmpfile.cc \ + src/core/util/string.cc \ + src/core/util/sync.cc \ + src/core/util/sync_abseil.cc \ + src/core/util/time.cc \ + src/core/util/time_precise.cc \ + src/core/util/windows/cpu.cc \ + src/core/util/windows/log.cc \ + src/core/util/windows/string.cc \ + src/core/util/windows/string_util.cc \ + src/core/util/windows/sync.cc \ + src/core/util/windows/time.cc \ + src/core/util/windows/tmpfile.cc \ src/core/xds/grpc/certificate_provider_store.cc \ src/core/xds/grpc/file_watcher_certificate_provider_factory.cc \ src/core/xds/grpc/xds_audit_logger_registry.cc \ @@ -1525,13 +1526,6 @@ if test "$PHP_GRPC" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/event_engine/windows) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/event_engine/work_queue) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/experiments) - PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gpr) - PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gpr/android) - PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gpr/iphone) - PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gpr/linux) - PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gpr/msys) - PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gpr/posix) - PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gpr/windows) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gprpp) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gprpp/linux) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gprpp/posix) @@ -1605,6 +1599,13 @@ if test "$PHP_GRPC" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/alts/zero_copy_frame_protector) PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/ssl/key_logging) PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/ssl/session_cache) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/util) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/util/android) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/util/iphone) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/util/linux) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/util/msys) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/util/posix) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/util/windows) PHP_ADD_BUILD_DIR($ext_builddir/src/core/xds/grpc) PHP_ADD_BUILD_DIR($ext_builddir/src/core/xds/xds_client) PHP_ADD_BUILD_DIR($ext_builddir/src/php/ext/grpc) diff --git a/config.w32 b/config.w32 index 0d0a85c04d7..c430f747c0a 100644 --- a/config.w32 +++ b/config.w32 @@ -481,32 +481,6 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\event_engine\\work_queue\\basic_work_queue.cc " + "src\\core\\lib\\experiments\\config.cc " + "src\\core\\lib\\experiments\\experiments.cc " + - "src\\core\\lib\\gpr\\alloc.cc " + - "src\\core\\lib\\gpr\\android\\log.cc " + - "src\\core\\lib\\gpr\\atm.cc " + - "src\\core\\lib\\gpr\\iphone\\cpu.cc " + - "src\\core\\lib\\gpr\\linux\\cpu.cc " + - "src\\core\\lib\\gpr\\linux\\log.cc " + - "src\\core\\lib\\gpr\\log.cc " + - "src\\core\\lib\\gpr\\msys\\tmpfile.cc " + - "src\\core\\lib\\gpr\\posix\\cpu.cc " + - "src\\core\\lib\\gpr\\posix\\log.cc " + - "src\\core\\lib\\gpr\\posix\\string.cc " + - "src\\core\\lib\\gpr\\posix\\sync.cc " + - "src\\core\\lib\\gpr\\posix\\time.cc " + - "src\\core\\lib\\gpr\\posix\\tmpfile.cc " + - "src\\core\\lib\\gpr\\string.cc " + - "src\\core\\lib\\gpr\\sync.cc " + - "src\\core\\lib\\gpr\\sync_abseil.cc " + - "src\\core\\lib\\gpr\\time.cc " + - "src\\core\\lib\\gpr\\time_precise.cc " + - "src\\core\\lib\\gpr\\windows\\cpu.cc " + - "src\\core\\lib\\gpr\\windows\\log.cc " + - "src\\core\\lib\\gpr\\windows\\string.cc " + - "src\\core\\lib\\gpr\\windows\\string_util.cc " + - "src\\core\\lib\\gpr\\windows\\sync.cc " + - "src\\core\\lib\\gpr\\windows\\time.cc " + - "src\\core\\lib\\gpr\\windows\\tmpfile.cc " + "src\\core\\lib\\gprpp\\crash.cc " + "src\\core\\lib\\gprpp\\examine_stack.cc " + "src\\core\\lib\\gprpp\\fork.cc " + @@ -727,6 +701,7 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\transport\\call_spine.cc " + "src\\core\\lib\\transport\\connectivity_state.cc " + "src\\core\\lib\\transport\\error_utils.cc " + + "src\\core\\lib\\transport\\interception_chain.cc " + "src\\core\\lib\\transport\\message.cc " + "src\\core\\lib\\transport\\metadata.cc " + "src\\core\\lib\\transport\\metadata_batch.cc " + @@ -824,6 +799,32 @@ if (PHP_GRPC != "no") { "src\\core\\tsi\\ssl_transport_security_utils.cc " + "src\\core\\tsi\\transport_security.cc " + "src\\core\\tsi\\transport_security_grpc.cc " + + "src\\core\\util\\alloc.cc " + + "src\\core\\util\\android\\log.cc " + + "src\\core\\util\\atm.cc " + + "src\\core\\util\\iphone\\cpu.cc " + + "src\\core\\util\\linux\\cpu.cc " + + "src\\core\\util\\linux\\log.cc " + + "src\\core\\util\\log.cc " + + "src\\core\\util\\msys\\tmpfile.cc " + + "src\\core\\util\\posix\\cpu.cc " + + "src\\core\\util\\posix\\log.cc " + + "src\\core\\util\\posix\\string.cc " + + "src\\core\\util\\posix\\sync.cc " + + "src\\core\\util\\posix\\time.cc " + + "src\\core\\util\\posix\\tmpfile.cc " + + "src\\core\\util\\string.cc " + + "src\\core\\util\\sync.cc " + + "src\\core\\util\\sync_abseil.cc " + + "src\\core\\util\\time.cc " + + "src\\core\\util\\time_precise.cc " + + "src\\core\\util\\windows\\cpu.cc " + + "src\\core\\util\\windows\\log.cc " + + "src\\core\\util\\windows\\string.cc " + + "src\\core\\util\\windows\\string_util.cc " + + "src\\core\\util\\windows\\sync.cc " + + "src\\core\\util\\windows\\time.cc " + + "src\\core\\util\\windows\\tmpfile.cc " + "src\\core\\xds\\grpc\\certificate_provider_store.cc " + "src\\core\\xds\\grpc\\file_watcher_certificate_provider_factory.cc " + "src\\core\\xds\\grpc\\xds_audit_logger_registry.cc " + @@ -1662,13 +1663,6 @@ if (PHP_GRPC != "no") { FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\event_engine\\windows"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\event_engine\\work_queue"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\experiments"); - FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gpr"); - FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gpr\\android"); - FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gpr\\iphone"); - FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gpr\\linux"); - FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gpr\\msys"); - FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gpr\\posix"); - FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gpr\\windows"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gprpp"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gprpp\\linux"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gprpp\\posix"); @@ -1745,6 +1739,13 @@ if (PHP_GRPC != "no") { FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\ssl"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\ssl\\key_logging"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\ssl\\session_cache"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\util"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\util\\android"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\util\\iphone"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\util\\linux"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\util\\msys"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\util\\posix"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\util\\windows"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\xds"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\xds\\grpc"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\xds\\xds_client"); diff --git a/examples/cpp/otel/BUILD b/examples/cpp/otel/BUILD index 0a9b75c5464..561ce270df2 100644 --- a/examples/cpp/otel/BUILD +++ b/examples/cpp/otel/BUILD @@ -14,11 +14,22 @@ licenses(["notice"]) +cc_library( + name = "util", + srcs = ["util.cc"], + hdrs = ["util.h"], + deps = [ + "//:grpc++", + "@io_opentelemetry_cpp//sdk/src/metrics", + ], +) + cc_binary( name = "greeter_callback_client", srcs = ["greeter_callback_client.cc"], defines = ["BAZEL_BUILD"], deps = [ + "util", "//:grpc++", "//:grpcpp_otel_plugin", "//examples/protos:helloworld_cc_grpc", @@ -34,6 +45,7 @@ cc_binary( srcs = ["greeter_callback_server.cc"], defines = ["BAZEL_BUILD"], deps = [ + "util", "//:grpc++", "//:grpc++_reflection", "//:grpcpp_otel_plugin", diff --git a/examples/cpp/otel/CMakeLists.txt b/examples/cpp/otel/CMakeLists.txt index 5a3ecaa1767..e4028a214f9 100644 --- a/examples/cpp/otel/CMakeLists.txt +++ b/examples/cpp/otel/CMakeLists.txt @@ -50,6 +50,7 @@ add_custom_command( # Include generated *.pb.h files include_directories("${CMAKE_CURRENT_BINARY_DIR}") +include_directories("${CMAKE_SOURCE_DIR}") # hw_grpc_proto add_library(hw_grpc_proto @@ -62,6 +63,13 @@ target_link_libraries(hw_grpc_proto ${_GRPC_GRPCPP} ${_PROTOBUF_LIBPROTOBUF}) +# util +add_library(util + "util.cc") +target_link_libraries(util + opentelemetry-cpp::metrics + ${_GRPC_GRPCPP}) + # Targets greeter_callback_(client|server) foreach(_target greeter_callback_client greeter_callback_server) @@ -75,5 +83,6 @@ foreach(_target ${_REFLECTION} ${_GRPC_GRPCPP} gRPC::grpcpp_otel_plugin + util ${_PROTOBUF_LIBPROTOBUF}) endforeach() diff --git a/examples/cpp/otel/greeter_callback_client.cc b/examples/cpp/otel/greeter_callback_client.cc index 653d68971c8..32a2049b4cf 100644 --- a/examples/cpp/otel/greeter_callback_client.cc +++ b/examples/cpp/otel/greeter_callback_client.cc @@ -33,9 +33,11 @@ #include #ifdef BAZEL_BUILD +#include "examples/cpp/otel/util.h" #include "examples/protos/helloworld.grpc.pb.h" #else #include "helloworld.grpc.pb.h" +#include "util.h" #endif ABSL_FLAG(std::string, target, "localhost:50051", "Server address"); @@ -110,6 +112,10 @@ int main(int argc, char** argv) { opentelemetry::exporter::metrics::PrometheusExporterFactory::Create(opts); auto meter_provider = std::make_shared(); + // The default histogram boundaries are not granular enough for RPCs. Override + // the "grpc.client.attempt.duration" view as recommended by + // https://github.com/grpc/proposal/blob/master/A66-otel-stats.md. + AddLatencyView(meter_provider.get(), "grpc.client.attempt.duration", "s"); meter_provider->AddMetricReader(std::move(prometheus_exporter)); auto status = grpc::OpenTelemetryPluginBuilder() .SetMeterProvider(std::move(meter_provider)) diff --git a/examples/cpp/otel/greeter_callback_server.cc b/examples/cpp/otel/greeter_callback_server.cc index 0e5f1a1b9e4..8e7e7cda052 100644 --- a/examples/cpp/otel/greeter_callback_server.cc +++ b/examples/cpp/otel/greeter_callback_server.cc @@ -33,9 +33,11 @@ #include #ifdef BAZEL_BUILD +#include "examples/cpp/otel/util.h" #include "examples/protos/helloworld.grpc.pb.h" #else #include "helloworld.grpc.pb.h" +#include "util.h" #endif ABSL_FLAG(uint16_t, port, 50051, "Server port for the service"); @@ -96,6 +98,10 @@ int main(int argc, char** argv) { opentelemetry::exporter::metrics::PrometheusExporterFactory::Create(opts); auto meter_provider = std::make_shared(); + // The default histogram boundaries are not granular enough for RPCs. Override + // the "grpc.server.call.duration" view as recommended by + // https://github.com/grpc/proposal/blob/master/A66-otel-stats.md. + AddLatencyView(meter_provider.get(), "grpc.server.call.duration", "s"); meter_provider->AddMetricReader(std::move(prometheus_exporter)); auto status = grpc::OpenTelemetryPluginBuilder() .SetMeterProvider(std::move(meter_provider)) diff --git a/examples/cpp/otel/util.cc b/examples/cpp/otel/util.cc new file mode 100644 index 00000000000..8777481ea00 --- /dev/null +++ b/examples/cpp/otel/util.cc @@ -0,0 +1,50 @@ +// +// +// 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. +// +// + +#ifdef BAZEL_BUILD +#include "examples/cpp/otel/util.h" +#else +#include "util.h" +#endif + +#include "opentelemetry/sdk/metrics/view/instrument_selector_factory.h" +#include "opentelemetry/sdk/metrics/view/meter_selector_factory.h" +#include "opentelemetry/sdk/metrics/view/view_factory.h" + +#include + +void AddLatencyView(opentelemetry::sdk::metrics::MeterProvider* provider, + const std::string& name, const std::string& unit) { + auto histogram_config = std::make_shared< + opentelemetry::sdk::metrics::HistogramAggregationConfig>(); + histogram_config->boundaries_ = { + 0, 0.00001, 0.00005, 0.0001, 0.0003, 0.0006, 0.0008, 0.001, 0.002, + 0.003, 0.004, 0.005, 0.006, 0.008, 0.01, 0.013, 0.016, 0.02, + 0.025, 0.03, 0.04, 0.05, 0.065, 0.08, 0.1, 0.13, 0.16, + 0.2, 0.25, 0.3, 0.4, 0.5, 0.65, 0.8, 1, 2, + 5, 10, 20, 50, 100}; + provider->AddView( + opentelemetry::sdk::metrics::InstrumentSelectorFactory::Create( + opentelemetry::sdk::metrics::InstrumentType::kHistogram, name, unit), + opentelemetry::sdk::metrics::MeterSelectorFactory::Create( + "grpc-c++", grpc::Version(), ""), + opentelemetry::sdk::metrics::ViewFactory::Create( + name, "", unit, + opentelemetry::sdk::metrics::AggregationType::kHistogram, + std::move(histogram_config))); +} diff --git a/examples/cpp/otel/util.h b/examples/cpp/otel/util.h new file mode 100644 index 00000000000..4fe1681b4fa --- /dev/null +++ b/examples/cpp/otel/util.h @@ -0,0 +1,31 @@ +// +// +// 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 GRPCPP_EXAMPLES_CPP_OTEL_UTIL_H +#define GRPCPP_EXAMPLES_CPP_OTEL_UTIL_H + +#include + +#include "opentelemetry/sdk/metrics/meter_provider.h" + +// Helper function that adds view for gRPC latency instrument \a name with unit +// \a unit with bucket boundaries that are more useful for RPCs. +void AddLatencyView(opentelemetry::sdk::metrics::MeterProvider* provider, + const std::string& name, const std::string& unit); + +#endif // GRPCPP_EXAMPLES_CPP_OTEL_UTIL_H diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 94651c55feb..457103324f9 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -176,6 +176,7 @@ Pod::Spec.new do |s| 'include/grpcpp/impl/service_type.h', 'include/grpcpp/impl/status.h', 'include/grpcpp/impl/sync.h', + 'include/grpcpp/passive_listener.h', 'include/grpcpp/resource_quota.h', 'include/grpcpp/security/audit_logging.h', 'include/grpcpp/security/auth_context.h', @@ -963,12 +964,6 @@ Pod::Spec.new do |s| 'src/core/lib/event_engine/work_queue/work_queue.h', 'src/core/lib/experiments/config.h', 'src/core/lib/experiments/experiments.h', - 'src/core/lib/gpr/alloc.h', - 'src/core/lib/gpr/spinlock.h', - 'src/core/lib/gpr/string.h', - 'src/core/lib/gpr/time_precise.h', - 'src/core/lib/gpr/tmpfile.h', - 'src/core/lib/gpr/useful.h', 'src/core/lib/gprpp/atomic_utils.h', 'src/core/lib/gprpp/bitset.h', 'src/core/lib/gprpp/chunked_vector.h', @@ -1212,6 +1207,7 @@ Pod::Spec.new do |s| 'src/core/lib/transport/batch_builder.h', 'src/core/lib/transport/bdp_estimator.h', 'src/core/lib/transport/call_arena_allocator.h', + 'src/core/lib/transport/call_destination.h', 'src/core/lib/transport/call_filters.h', 'src/core/lib/transport/call_final_info.h', 'src/core/lib/transport/call_spine.h', @@ -1219,6 +1215,7 @@ Pod::Spec.new do |s| 'src/core/lib/transport/custom_metadata.h', 'src/core/lib/transport/error_utils.h', 'src/core/lib/transport/http2_errors.h', + 'src/core/lib/transport/interception_chain.h', 'src/core/lib/transport/message.h', 'src/core/lib/transport/metadata.h', 'src/core/lib/transport/metadata_batch.h', @@ -1314,6 +1311,12 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security.h', 'src/core/tsi/transport_security_grpc.h', 'src/core/tsi/transport_security_interface.h', + 'src/core/util/alloc.h', + 'src/core/util/spinlock.h', + 'src/core/util/string.h', + 'src/core/util/time_precise.h', + 'src/core/util/tmpfile.h', + 'src/core/util/useful.h', 'src/core/xds/grpc/certificate_provider_store.h', 'src/core/xds/grpc/file_watcher_certificate_provider_factory.h', 'src/core/xds/grpc/upb_utils.h', @@ -2232,12 +2235,6 @@ Pod::Spec.new do |s| 'src/core/lib/event_engine/work_queue/work_queue.h', 'src/core/lib/experiments/config.h', 'src/core/lib/experiments/experiments.h', - 'src/core/lib/gpr/alloc.h', - 'src/core/lib/gpr/spinlock.h', - 'src/core/lib/gpr/string.h', - 'src/core/lib/gpr/time_precise.h', - 'src/core/lib/gpr/tmpfile.h', - 'src/core/lib/gpr/useful.h', 'src/core/lib/gprpp/atomic_utils.h', 'src/core/lib/gprpp/bitset.h', 'src/core/lib/gprpp/chunked_vector.h', @@ -2481,6 +2478,7 @@ Pod::Spec.new do |s| 'src/core/lib/transport/batch_builder.h', 'src/core/lib/transport/bdp_estimator.h', 'src/core/lib/transport/call_arena_allocator.h', + 'src/core/lib/transport/call_destination.h', 'src/core/lib/transport/call_filters.h', 'src/core/lib/transport/call_final_info.h', 'src/core/lib/transport/call_spine.h', @@ -2488,6 +2486,7 @@ Pod::Spec.new do |s| 'src/core/lib/transport/custom_metadata.h', 'src/core/lib/transport/error_utils.h', 'src/core/lib/transport/http2_errors.h', + 'src/core/lib/transport/interception_chain.h', 'src/core/lib/transport/message.h', 'src/core/lib/transport/metadata.h', 'src/core/lib/transport/metadata_batch.h', @@ -2583,6 +2582,12 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security.h', 'src/core/tsi/transport_security_grpc.h', 'src/core/tsi/transport_security_interface.h', + 'src/core/util/alloc.h', + 'src/core/util/spinlock.h', + 'src/core/util/string.h', + 'src/core/util/time_precise.h', + 'src/core/util/tmpfile.h', + 'src/core/util/useful.h', 'src/core/xds/grpc/certificate_provider_store.h', 'src/core/xds/grpc/file_watcher_certificate_provider_factory.h', 'src/core/xds/grpc/upb_utils.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 4e6d835dc2a..2d2af17efc5 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -82,7 +82,7 @@ Pod::Spec.new do |s| ' "$(PODS_TARGET_SRCROOT)/third_party/utf8_range"'\ ' "$(PODS_TARGET_SRCROOT)/third_party/xxhash"', # If we don't set these two settings, `include/grpc/support/time.h` and - # `src/core/lib/gpr/string.h` shadow the system `` and ``, breaking the + # `src/core/util/string.h` shadow the system `` and ``, breaking the # build. 'USE_HEADERMAP' => 'NO', 'ALWAYS_SEARCH_USER_PATHS' => 'NO', @@ -168,6 +168,7 @@ Pod::Spec.new do |s| 'include/grpc/impl/propagation_bits.h', 'include/grpc/impl/slice_type.h', 'include/grpc/load_reporting.h', + 'include/grpc/passive_listener.h', 'include/grpc/slice.h', 'include/grpc/slice_buffer.h', 'include/grpc/status.h', @@ -1373,38 +1374,6 @@ Pod::Spec.new do |s| 'src/core/lib/experiments/config.h', 'src/core/lib/experiments/experiments.cc', 'src/core/lib/experiments/experiments.h', - 'src/core/lib/gpr/alloc.cc', - 'src/core/lib/gpr/alloc.h', - 'src/core/lib/gpr/android/log.cc', - 'src/core/lib/gpr/atm.cc', - 'src/core/lib/gpr/iphone/cpu.cc', - 'src/core/lib/gpr/linux/cpu.cc', - 'src/core/lib/gpr/linux/log.cc', - 'src/core/lib/gpr/log.cc', - 'src/core/lib/gpr/msys/tmpfile.cc', - 'src/core/lib/gpr/posix/cpu.cc', - 'src/core/lib/gpr/posix/log.cc', - 'src/core/lib/gpr/posix/string.cc', - 'src/core/lib/gpr/posix/sync.cc', - 'src/core/lib/gpr/posix/time.cc', - 'src/core/lib/gpr/posix/tmpfile.cc', - 'src/core/lib/gpr/spinlock.h', - 'src/core/lib/gpr/string.cc', - 'src/core/lib/gpr/string.h', - 'src/core/lib/gpr/sync.cc', - 'src/core/lib/gpr/sync_abseil.cc', - 'src/core/lib/gpr/time.cc', - 'src/core/lib/gpr/time_precise.cc', - 'src/core/lib/gpr/time_precise.h', - 'src/core/lib/gpr/tmpfile.h', - 'src/core/lib/gpr/useful.h', - 'src/core/lib/gpr/windows/cpu.cc', - 'src/core/lib/gpr/windows/log.cc', - 'src/core/lib/gpr/windows/string.cc', - 'src/core/lib/gpr/windows/string_util.cc', - 'src/core/lib/gpr/windows/sync.cc', - 'src/core/lib/gpr/windows/time.cc', - 'src/core/lib/gpr/windows/tmpfile.cc', 'src/core/lib/gprpp/atomic_utils.h', 'src/core/lib/gprpp/bitset.h', 'src/core/lib/gprpp/chunked_vector.h', @@ -1863,6 +1832,7 @@ Pod::Spec.new do |s| 'src/core/lib/transport/bdp_estimator.h', 'src/core/lib/transport/call_arena_allocator.cc', 'src/core/lib/transport/call_arena_allocator.h', + 'src/core/lib/transport/call_destination.h', 'src/core/lib/transport/call_filters.cc', 'src/core/lib/transport/call_filters.h', 'src/core/lib/transport/call_final_info.cc', @@ -1875,6 +1845,8 @@ Pod::Spec.new do |s| 'src/core/lib/transport/error_utils.cc', 'src/core/lib/transport/error_utils.h', 'src/core/lib/transport/http2_errors.h', + 'src/core/lib/transport/interception_chain.cc', + 'src/core/lib/transport/interception_chain.h', 'src/core/lib/transport/message.cc', 'src/core/lib/transport/message.h', 'src/core/lib/transport/metadata.cc', @@ -2067,6 +2039,38 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security_grpc.cc', 'src/core/tsi/transport_security_grpc.h', 'src/core/tsi/transport_security_interface.h', + 'src/core/util/alloc.cc', + 'src/core/util/alloc.h', + 'src/core/util/android/log.cc', + 'src/core/util/atm.cc', + 'src/core/util/iphone/cpu.cc', + 'src/core/util/linux/cpu.cc', + 'src/core/util/linux/log.cc', + 'src/core/util/log.cc', + 'src/core/util/msys/tmpfile.cc', + 'src/core/util/posix/cpu.cc', + 'src/core/util/posix/log.cc', + 'src/core/util/posix/string.cc', + 'src/core/util/posix/sync.cc', + 'src/core/util/posix/time.cc', + 'src/core/util/posix/tmpfile.cc', + 'src/core/util/spinlock.h', + 'src/core/util/string.cc', + 'src/core/util/string.h', + 'src/core/util/sync.cc', + 'src/core/util/sync_abseil.cc', + 'src/core/util/time.cc', + 'src/core/util/time_precise.cc', + 'src/core/util/time_precise.h', + 'src/core/util/tmpfile.h', + 'src/core/util/useful.h', + 'src/core/util/windows/cpu.cc', + 'src/core/util/windows/log.cc', + 'src/core/util/windows/string.cc', + 'src/core/util/windows/string_util.cc', + 'src/core/util/windows/sync.cc', + 'src/core/util/windows/time.cc', + 'src/core/util/windows/tmpfile.cc', 'src/core/xds/grpc/certificate_provider_store.cc', 'src/core/xds/grpc/certificate_provider_store.h', 'src/core/xds/grpc/file_watcher_certificate_provider_factory.cc', @@ -3011,12 +3015,6 @@ Pod::Spec.new do |s| 'src/core/lib/event_engine/work_queue/work_queue.h', 'src/core/lib/experiments/config.h', 'src/core/lib/experiments/experiments.h', - 'src/core/lib/gpr/alloc.h', - 'src/core/lib/gpr/spinlock.h', - 'src/core/lib/gpr/string.h', - 'src/core/lib/gpr/time_precise.h', - 'src/core/lib/gpr/tmpfile.h', - 'src/core/lib/gpr/useful.h', 'src/core/lib/gprpp/atomic_utils.h', 'src/core/lib/gprpp/bitset.h', 'src/core/lib/gprpp/chunked_vector.h', @@ -3260,6 +3258,7 @@ Pod::Spec.new do |s| 'src/core/lib/transport/batch_builder.h', 'src/core/lib/transport/bdp_estimator.h', 'src/core/lib/transport/call_arena_allocator.h', + 'src/core/lib/transport/call_destination.h', 'src/core/lib/transport/call_filters.h', 'src/core/lib/transport/call_final_info.h', 'src/core/lib/transport/call_spine.h', @@ -3267,6 +3266,7 @@ Pod::Spec.new do |s| 'src/core/lib/transport/custom_metadata.h', 'src/core/lib/transport/error_utils.h', 'src/core/lib/transport/http2_errors.h', + 'src/core/lib/transport/interception_chain.h', 'src/core/lib/transport/message.h', 'src/core/lib/transport/metadata.h', 'src/core/lib/transport/metadata_batch.h', @@ -3362,6 +3362,12 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security.h', 'src/core/tsi/transport_security_grpc.h', 'src/core/tsi/transport_security_interface.h', + 'src/core/util/alloc.h', + 'src/core/util/spinlock.h', + 'src/core/util/string.h', + 'src/core/util/time_precise.h', + 'src/core/util/tmpfile.h', + 'src/core/util/useful.h', 'src/core/xds/grpc/certificate_provider_store.h', 'src/core/xds/grpc/file_watcher_certificate_provider_factory.h', 'src/core/xds/grpc/upb_utils.h', diff --git a/grpc.gemspec b/grpc.gemspec index 53f5845e405..7104853d64f 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -99,6 +99,7 @@ Gem::Specification.new do |s| s.files += %w( include/grpc/impl/propagation_bits.h ) s.files += %w( include/grpc/impl/slice_type.h ) s.files += %w( include/grpc/load_reporting.h ) + s.files += %w( include/grpc/passive_listener.h ) s.files += %w( include/grpc/slice.h ) s.files += %w( include/grpc/slice_buffer.h ) s.files += %w( include/grpc/status.h ) @@ -1260,38 +1261,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/experiments/config.h ) s.files += %w( src/core/lib/experiments/experiments.cc ) s.files += %w( src/core/lib/experiments/experiments.h ) - s.files += %w( src/core/lib/gpr/alloc.cc ) - s.files += %w( src/core/lib/gpr/alloc.h ) - s.files += %w( src/core/lib/gpr/android/log.cc ) - s.files += %w( src/core/lib/gpr/atm.cc ) - s.files += %w( src/core/lib/gpr/iphone/cpu.cc ) - s.files += %w( src/core/lib/gpr/linux/cpu.cc ) - s.files += %w( src/core/lib/gpr/linux/log.cc ) - s.files += %w( src/core/lib/gpr/log.cc ) - s.files += %w( src/core/lib/gpr/msys/tmpfile.cc ) - s.files += %w( src/core/lib/gpr/posix/cpu.cc ) - s.files += %w( src/core/lib/gpr/posix/log.cc ) - s.files += %w( src/core/lib/gpr/posix/string.cc ) - s.files += %w( src/core/lib/gpr/posix/sync.cc ) - s.files += %w( src/core/lib/gpr/posix/time.cc ) - s.files += %w( src/core/lib/gpr/posix/tmpfile.cc ) - s.files += %w( src/core/lib/gpr/spinlock.h ) - s.files += %w( src/core/lib/gpr/string.cc ) - s.files += %w( src/core/lib/gpr/string.h ) - s.files += %w( src/core/lib/gpr/sync.cc ) - s.files += %w( src/core/lib/gpr/sync_abseil.cc ) - s.files += %w( src/core/lib/gpr/time.cc ) - s.files += %w( src/core/lib/gpr/time_precise.cc ) - s.files += %w( src/core/lib/gpr/time_precise.h ) - s.files += %w( src/core/lib/gpr/tmpfile.h ) - s.files += %w( src/core/lib/gpr/useful.h ) - s.files += %w( src/core/lib/gpr/windows/cpu.cc ) - s.files += %w( src/core/lib/gpr/windows/log.cc ) - s.files += %w( src/core/lib/gpr/windows/string.cc ) - s.files += %w( src/core/lib/gpr/windows/string_util.cc ) - s.files += %w( src/core/lib/gpr/windows/sync.cc ) - s.files += %w( src/core/lib/gpr/windows/time.cc ) - s.files += %w( src/core/lib/gpr/windows/tmpfile.cc ) s.files += %w( src/core/lib/gprpp/atomic_utils.h ) s.files += %w( src/core/lib/gprpp/bitset.h ) s.files += %w( src/core/lib/gprpp/chunked_vector.h ) @@ -1750,6 +1719,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/transport/bdp_estimator.h ) s.files += %w( src/core/lib/transport/call_arena_allocator.cc ) s.files += %w( src/core/lib/transport/call_arena_allocator.h ) + s.files += %w( src/core/lib/transport/call_destination.h ) s.files += %w( src/core/lib/transport/call_filters.cc ) s.files += %w( src/core/lib/transport/call_filters.h ) s.files += %w( src/core/lib/transport/call_final_info.cc ) @@ -1762,6 +1732,8 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/transport/error_utils.cc ) s.files += %w( src/core/lib/transport/error_utils.h ) s.files += %w( src/core/lib/transport/http2_errors.h ) + s.files += %w( src/core/lib/transport/interception_chain.cc ) + s.files += %w( src/core/lib/transport/interception_chain.h ) s.files += %w( src/core/lib/transport/message.cc ) s.files += %w( src/core/lib/transport/message.h ) s.files += %w( src/core/lib/transport/metadata.cc ) @@ -1954,6 +1926,38 @@ Gem::Specification.new do |s| s.files += %w( src/core/tsi/transport_security_grpc.cc ) s.files += %w( src/core/tsi/transport_security_grpc.h ) s.files += %w( src/core/tsi/transport_security_interface.h ) + s.files += %w( src/core/util/alloc.cc ) + s.files += %w( src/core/util/alloc.h ) + s.files += %w( src/core/util/android/log.cc ) + s.files += %w( src/core/util/atm.cc ) + s.files += %w( src/core/util/iphone/cpu.cc ) + s.files += %w( src/core/util/linux/cpu.cc ) + s.files += %w( src/core/util/linux/log.cc ) + s.files += %w( src/core/util/log.cc ) + s.files += %w( src/core/util/msys/tmpfile.cc ) + s.files += %w( src/core/util/posix/cpu.cc ) + s.files += %w( src/core/util/posix/log.cc ) + s.files += %w( src/core/util/posix/string.cc ) + s.files += %w( src/core/util/posix/sync.cc ) + s.files += %w( src/core/util/posix/time.cc ) + s.files += %w( src/core/util/posix/tmpfile.cc ) + s.files += %w( src/core/util/spinlock.h ) + s.files += %w( src/core/util/string.cc ) + s.files += %w( src/core/util/string.h ) + s.files += %w( src/core/util/sync.cc ) + s.files += %w( src/core/util/sync_abseil.cc ) + s.files += %w( src/core/util/time.cc ) + s.files += %w( src/core/util/time_precise.cc ) + s.files += %w( src/core/util/time_precise.h ) + s.files += %w( src/core/util/tmpfile.h ) + s.files += %w( src/core/util/useful.h ) + s.files += %w( src/core/util/windows/cpu.cc ) + s.files += %w( src/core/util/windows/log.cc ) + s.files += %w( src/core/util/windows/string.cc ) + s.files += %w( src/core/util/windows/string_util.cc ) + s.files += %w( src/core/util/windows/sync.cc ) + s.files += %w( src/core/util/windows/time.cc ) + s.files += %w( src/core/util/windows/tmpfile.cc ) s.files += %w( src/core/xds/grpc/certificate_provider_store.cc ) s.files += %w( src/core/xds/grpc/certificate_provider_store.h ) s.files += %w( src/core/xds/grpc/file_watcher_certificate_provider_factory.cc ) diff --git a/include/grpc/module.modulemap b/include/grpc/module.modulemap index c9219532826..30427e21d05 100644 --- a/include/grpc/module.modulemap +++ b/include/grpc/module.modulemap @@ -38,6 +38,7 @@ header "byte_buffer.h" header "impl/propagation_bits.h" header "impl/slice_type.h" header "load_reporting.h" + header "passive_listener.h" header "slice.h" header "slice_buffer.h" header "status.h" diff --git a/include/grpc/passive_listener.h b/include/grpc/passive_listener.h new file mode 100644 index 00000000000..fffc789dba0 --- /dev/null +++ b/include/grpc/passive_listener.h @@ -0,0 +1,62 @@ +// Copyright 2024 The 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_PASSIVE_LISTENER_H +#define GRPC_PASSIVE_LISTENER_H + +#include + +#include +#include +// #include + +namespace grpc_core { +class Server; + +namespace experimental { +class PassiveListenerImpl; + +/// -- EXPERIMENTAL API -- +/// Interface for used for Server Endpoint injection. +class PassiveListener { + public: + virtual ~PassiveListener() = default; + /// -- EXPERIMENTAL API -- + /// + /// Takes an Endpoint for an established connection, and treats it as if the + /// connection had been accepted by the server. + /// + /// The server must be started before endpoints can be accepted. + virtual absl::Status AcceptConnectedEndpoint( + std::unique_ptr + endpoint) = 0; + + /// -- EXPERIMENTAL API -- + /// + /// Takes a connected file descriptor, and treats it as if the server had + /// accepted the connection itself. + /// + /// Returns a failure status if the server's active EventEngine does not + /// support Endpoint creation from fds. + virtual absl::Status AcceptConnectedFd(int fd) = 0; +}; + +} // namespace experimental +} // namespace grpc_core + +absl::Status grpc_server_add_passive_listener( + grpc_core::Server* server, grpc_server_credentials* credentials, + std::shared_ptr + passive_listener); + +#endif /* GRPC_PASSIVE_LISTENER_H */ diff --git a/include/grpc/support/log.h b/include/grpc/support/log.h index 6e5cf4b7157..2cba30164ff 100644 --- a/include/grpc/support/log.h +++ b/include/grpc/support/log.h @@ -99,12 +99,6 @@ GPRAPI void gpr_assertion_failed(const char* filename, int line, } \ } while (0) -#ifndef NDEBUG -#define GPR_DEBUG_ASSERT(x) GPR_ASSERT(x) -#else -#define GPR_DEBUG_ASSERT(x) GPR_ASSERT(true || (x)) -#endif - #ifdef __cplusplus } #endif diff --git a/include/grpcpp/ext/otel_plugin.h b/include/grpcpp/ext/otel_plugin.h index c9327d68d09..1b6bb9eb762 100644 --- a/include/grpcpp/ext/otel_plugin.h +++ b/include/grpcpp/ext/otel_plugin.h @@ -88,11 +88,25 @@ class OpenTelemetryPluginBuilder { /// If `SetMeterProvider()` is not called, no metrics are collected. OpenTelemetryPluginBuilder& SetMeterProvider( std::shared_ptr meter_provider); - /// If set, \a target_attribute_filter is called per channel to decide whether - /// to record the target attribute on client or to replace it with "other". - /// This helps reduce the cardinality on metrics in cases where many channels - /// are created with different targets in the same binary (which might happen - /// for example, if the channel target string uses IP addresses directly). + /// DEPRECATED: If set, \a target_attribute_filter is called per channel to + /// decide whether to record the target attribute on client or to replace it + /// with "other". This helps reduce the cardinality on metrics in cases where + /// many channels are created with different targets in the same binary (which + /// might happen for example, if the channel target string uses IP addresses + /// directly). + /// This filtration only works for the per-call metrics - + /// grpc.client.attempt.started + /// grpc.client.attempt.duration + /// grpc.client.attempt.sent_total_compressed_message_size + /// grpc.client.attempt.rcvd_total_compressed_message_size + /// For example, the grpc.target attribute on pick first lb policy metrics + /// defined in + /// https://github.com/grpc/proposal/blob/master/A78-grpc-metrics-wrr-pf-xds.md + /// will not be filtered. Please contact the grpc team if this filtration is + /// of interest to you. + GRPC_DEPRECATED( + "Does not work as expected. Please raise an issue on " + "https://github.com/grpc/grpc if this would be of use to you.") OpenTelemetryPluginBuilder& SetTargetAttributeFilter( absl::AnyInvocable target_attribute_filter); diff --git a/include/grpcpp/passive_listener.h b/include/grpcpp/passive_listener.h new file mode 100644 index 00000000000..8def9592b5e --- /dev/null +++ b/include/grpcpp/passive_listener.h @@ -0,0 +1,27 @@ +// Copyright 2024 The 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 GRPCPP_PASSIVE_LISTENER_H +#define GRPCPP_PASSIVE_LISTENER_H + +#include + +namespace grpc { +namespace experimental { + +using grpc_core::experimental::PassiveListener; + +} // namespace experimental +} // namespace grpc + +#endif // GRPCPP_PASSIVE_LISTENER_H diff --git a/include/grpcpp/security/server_credentials.h b/include/grpcpp/security/server_credentials.h index fe8c546190d..e3f5c2bbbfe 100644 --- a/include/grpcpp/security/server_credentials.h +++ b/include/grpcpp/security/server_credentials.h @@ -84,6 +84,7 @@ class ServerCredentials : private grpc::internal::GrpcLibrary { // Needed for access to AddPortToServer. friend class Server; // Needed for access to c_creds_. + friend class ServerBuilder; friend std::shared_ptr grpc::XdsServerCredentials( const std::shared_ptr& fallback_credentials); diff --git a/include/grpcpp/security/tls_credentials_options.h b/include/grpcpp/security/tls_credentials_options.h index 6adf9faac64..11c40f04086 100644 --- a/include/grpcpp/security/tls_credentials_options.h +++ b/include/grpcpp/security/tls_credentials_options.h @@ -103,6 +103,8 @@ class TlsCredentialsOptions { // call is covered by the cert that the peer presented. // We will perform such checks by default. This should be disabled if // verifiers other than the host name verifier is used. + // Deprecated: This function will be removed in the 1.66 release. This will be + // replaced by and handled within the custom verifier settings. void set_check_call_host(bool check_call_host); // Deprecated in favor of set_crl_provider. The @@ -111,6 +113,8 @@ class TlsCredentialsOptions { // If set, gRPC will read all hashed x.509 CRL files in the directory and // enforce the CRL files on all TLS handshakes. Only supported for OpenSSL // version > 1.1. + // Deprecated: This function will be removed in the 1.66 release. Use the + // set_crl_provider function instead. void set_crl_directory(const std::string& path); void set_crl_provider(std::shared_ptr crl_provider); @@ -184,6 +188,7 @@ class TlsServerCredentialsOptions final : public TlsCredentialsOptions { // WARNING: This API is extremely dangerous and should not be used. If the // server's trust bundle is too large, then the TLS server will be unable to // form a ServerHello, and hence will be unusable. + // Deprecated: This function will be removed in the 1.66 release. void set_send_client_ca_list(bool send_client_ca_list); private: diff --git a/include/grpcpp/server_builder.h b/include/grpcpp/server_builder.h index e6266a90d98..e66ca4301cd 100644 --- a/include/grpcpp/server_builder.h +++ b/include/grpcpp/server_builder.h @@ -25,13 +25,17 @@ #include #include +#include +#include #include #include #include #include #include #include +#include #include +#include #include #include #include @@ -291,6 +295,18 @@ class ServerBuilder { void EnableCallMetricRecording( experimental::ServerMetricRecorder* server_metric_recorder = nullptr); + // Creates a passive listener for Server Endpoint injection. + /// + /// \a PasiveListener lets applications provide pre-established connections + /// to gRPC Servers. The server will behave as if it accepted the connection + /// itself on its own listening addresses. + /// + /// This can be called multiple times to create passive listeners with + /// different server credentials. + ServerBuilder& AddPassiveListener( + std::shared_ptr creds, + std::unique_ptr& passive_listener); + private: ServerBuilder* builder_; }; @@ -364,6 +380,17 @@ class ServerBuilder { private: friend class grpc::testing::ServerBuilderPluginTest; + struct UnstartedPassiveListener { + std::weak_ptr + passive_listener; + std::shared_ptr credentials; + UnstartedPassiveListener( + std::weak_ptr listener, + std::shared_ptr creds) + : passive_listener(std::move(listener)), + credentials(std::move(creds)) {} + }; + struct SyncServerSettings { SyncServerSettings() : num_cqs(1), min_pollers(1), max_pollers(2), cq_timeout_msec(10000) {} @@ -388,6 +415,7 @@ class ServerBuilder { std::vector> options_; std::vector> services_; std::vector ports_; + std::vector unstarted_passive_listeners_; SyncServerSettings sync_server_settings_; diff --git a/package.xml b/package.xml index e7600613939..3cd01a87805 100644 --- a/package.xml +++ b/package.xml @@ -81,6 +81,7 @@ + @@ -1242,38 +1243,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1732,6 +1701,7 @@ + @@ -1744,6 +1714,8 @@ + + @@ -1936,6 +1908,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/core/BUILD b/src/core/BUILD index ec15ddb027c..53457328bfd 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 = [ @@ -197,6 +216,7 @@ grpc_cc_library( external_deps = [ "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/strings", ], language = "c++", @@ -218,7 +238,7 @@ grpc_cc_library( grpc_cc_library( name = "useful", - hdrs = ["lib/gpr/useful.h"], + hdrs = ["util/useful.h"], external_deps = [ "absl/strings", "absl/types:variant", @@ -243,7 +263,7 @@ grpc_cc_library( grpc_cc_library( name = "gpr_atm", srcs = [ - "lib/gpr/atm.cc", + "util/atm.cc", ], language = "c++", public_hdrs = [ @@ -279,7 +299,7 @@ grpc_cc_library( name = "gpr_spinlock", srcs = [], hdrs = [ - "lib/gpr/spinlock.h", + "util/spinlock.h", ], language = "c++", deps = [ @@ -395,6 +415,7 @@ grpc_cc_library( "lib/gprpp/validation_errors.h", ], external_deps = [ + "absl/log:log", "absl/status", "absl/strings", ], @@ -511,7 +532,10 @@ grpc_cc_library( grpc_cc_library( name = "map_pipe", - external_deps = ["absl/status"], + external_deps = [ + "absl/log:log", + "absl/status", + ], language = "c++", public_hdrs = [ "lib/promise/map_pipe.h", @@ -540,6 +564,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/strings", "absl/strings:str_format", ], @@ -639,7 +664,10 @@ grpc_cc_library( grpc_cc_library( name = "promise_like", - external_deps = ["absl/meta:type_traits"], + external_deps = [ + "absl/functional:any_invocable", + "absl/meta:type_traits", + ], language = "c++", public_hdrs = [ "lib/promise/detail/promise_like.h", @@ -754,6 +782,7 @@ grpc_cc_library( name = "join_state", external_deps = [ "absl/log:check", + "absl/log:log", ], language = "c++", public_hdrs = [ @@ -843,6 +872,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/strings", ], language = "c++", @@ -982,6 +1012,7 @@ grpc_cc_library( name = "latch", external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", ], language = "c++", @@ -1000,6 +1031,7 @@ grpc_cc_library( name = "inter_activity_latch", external_deps = [ "absl/base:core_headers", + "absl/log:log", "absl/strings", ], language = "c++", @@ -1022,6 +1054,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", "absl/strings:str_format", "absl/types:optional", @@ -1045,6 +1078,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", "absl/types:optional", "absl/types:variant", @@ -1156,6 +1190,7 @@ grpc_cc_library( name = "for_each", external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/strings", ], @@ -1178,6 +1213,7 @@ grpc_cc_library( name = "ref_counted", external_deps = [ "absl/log:check", + "absl/log:log", ], language = "c++", public_hdrs = ["lib/gprpp/ref_counted.h"], @@ -1194,6 +1230,7 @@ grpc_cc_library( name = "dual_ref_counted", external_deps = [ "absl/log:check", + "absl/log:log", ], language = "c++", public_hdrs = ["lib/gprpp/dual_ref_counted.h"], @@ -1389,6 +1426,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/container:flat_hash_set", "absl/log:check", + "absl/log:log", "absl/status", "absl/strings", "absl/types:optional", @@ -1439,6 +1477,9 @@ grpc_cc_library( hdrs = [ "lib/resource_quota/arena.h", ], + external_deps = [ + "absl/log:log", + ], visibility = [ "@grpc:alt_grpc_base_legacy", ], @@ -1538,6 +1579,9 @@ grpc_cc_library( hdrs = [ "lib/slice/slice_refcount.h", ], + external_deps = [ + "absl/log:log", + ], public_hdrs = [ "//:include/grpc/slice.h", ], @@ -1605,6 +1649,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/strings:str_format", ], @@ -1632,6 +1677,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings:str_format", ], visibility = ["@grpc:alt_grpc_base_legacy"], @@ -1653,6 +1699,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings:str_format", "absl/types:optional", ], @@ -1734,6 +1781,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", ], deps = [ "//:config_vars", @@ -1883,6 +1931,7 @@ grpc_cc_library( "absl/container:flat_hash_set", "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/time", "absl/types:optional", ], @@ -1933,6 +1982,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/time", "absl/types:optional", ], @@ -2090,6 +2140,7 @@ grpc_cc_library( "absl/container:inlined_vector", "absl/functional:function_ref", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -2196,6 +2247,7 @@ grpc_cc_library( ], external_deps = [ "absl/functional:any_invocable", + "absl/log:log", "absl/status", "absl/types:optional", ], @@ -2220,6 +2272,7 @@ grpc_cc_library( "absl/functional:any_invocable", "absl/hash", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -2281,6 +2334,7 @@ grpc_cc_library( external_deps = [ "absl/cleanup", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -2313,6 +2367,7 @@ grpc_cc_library( external_deps = [ "absl/cleanup", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -2340,6 +2395,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -2376,6 +2432,7 @@ grpc_cc_library( "absl/functional:any_invocable", "absl/hash", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -2418,6 +2475,7 @@ grpc_cc_library( hdrs = ["lib/event_engine/windows/windows_engine.h"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -2472,6 +2530,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/status", "absl/strings:str_format", ], @@ -2501,6 +2560,7 @@ grpc_cc_library( "absl/cleanup", "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/status", "absl/strings:str_format", ], @@ -2529,6 +2589,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings:str_format", @@ -2563,6 +2624,7 @@ grpc_cc_library( external_deps = [ "absl/container:flat_hash_map", "absl/log:check", + "absl/log:log", "absl/strings", "absl/strings:str_format", ], @@ -2597,6 +2659,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -2623,6 +2686,9 @@ grpc_cc_library( hdrs = [ "lib/event_engine/trace.h", ], + external_deps = [ + "absl/log:log", + ], deps = [ "//:gpr", "//:gpr_platform", @@ -2813,6 +2879,7 @@ grpc_cc_library( "absl/functional:any_invocable", "absl/hash", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -2869,6 +2936,7 @@ grpc_cc_library( hdrs = ["lib/transport/bdp_estimator.h"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", ], deps = [ @@ -3054,6 +3122,7 @@ grpc_cc_library( external_deps = [ "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/strings", "absl/types:optional", ], @@ -3064,6 +3133,7 @@ grpc_cc_library( "channel_fwd", "channel_stack_trace", "channel_stack_type", + "interception_chain", "//:channel_stack_builder", "//:debug_location", "//:gpr", @@ -3081,6 +3151,7 @@ grpc_cc_library( deps = [ "channel_args", "//:channelz", + "//:event_engine_base_hdrs", "//:gpr_platform", ], ) @@ -3130,7 +3201,10 @@ grpc_cc_library( hdrs = [ "service_config/service_config_parser.h", ], - external_deps = ["absl/strings"], + external_deps = [ + "absl/log:log", + "absl/strings", + ], language = "c++", deps = [ "channel_args", @@ -3159,6 +3233,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/meta:type_traits", "absl/strings", "absl/strings:str_format", @@ -3334,6 +3409,7 @@ grpc_cc_library( "client_channel/retry_service_config.h", ], external_deps = [ + "absl/log:log", "absl/strings", "absl/types:optional", ], @@ -3384,6 +3460,7 @@ grpc_cc_library( "client_channel/backup_poller.h", ], external_deps = [ + "absl/log:log", "absl/status", ], language = "c++", @@ -3407,6 +3484,7 @@ grpc_cc_library( "service_config/service_config_channel_arg_filter.cc", ], external_deps = [ + "absl/log:log", "absl/status", "absl/status:statusor", "absl/types:optional", @@ -3493,6 +3571,7 @@ grpc_cc_library( hdrs = ["load_balancing/lb_policy_registry.h"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -3603,6 +3682,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -3742,6 +3822,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", ], deps = [ @@ -3789,6 +3870,7 @@ grpc_cc_library( "lib/security/authorization/grpc_server_authz_filter.h", ], external_deps = [ + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -3831,6 +3913,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/container:flat_hash_map", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -3864,6 +3947,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -3944,6 +4028,9 @@ grpc_cc_library( hdrs = [ "tsi/local_transport_security.h", ], + external_deps = [ + "absl/log:log", + ], language = "c++", deps = [ "//:event_engine_base_hdrs", @@ -3965,6 +4052,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -4012,6 +4100,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/strings", "absl/strings:str_format", @@ -4057,6 +4146,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status:statusor", "absl/strings", "absl/types:optional", @@ -4139,6 +4229,7 @@ grpc_cc_library( "absl/container:inlined_vector", "absl/functional:bind_front", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -4225,6 +4316,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -4287,6 +4379,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -4333,6 +4426,7 @@ grpc_cc_library( "lib/http/httpcli_ssl_credentials.h", ], external_deps = [ + "absl/log:log", "absl/status", "absl/strings", "absl/types:optional", @@ -4407,6 +4501,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -4557,6 +4652,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/meta:type_traits", "absl/random", "absl/status", @@ -4638,6 +4734,7 @@ grpc_cc_library( "ext/filters/message_size/message_size_filter.h", ], external_deps = [ + "absl/log:log", "absl/status:statusor", "absl/strings", "absl/strings:str_format", @@ -4686,6 +4783,7 @@ grpc_cc_library( ], external_deps = [ "absl/base:core_headers", + "absl/log:log", "absl/meta:type_traits", "absl/random", "absl/status", @@ -4825,6 +4923,7 @@ grpc_cc_library( "absl/container:inlined_vector", "absl/functional:function_ref", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -4942,6 +5041,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/hash", "absl/log:check", + "absl/log:log", "absl/random", "absl/status", "absl/status:statusor", @@ -5076,6 +5176,7 @@ grpc_cc_library( "absl/cleanup", "absl/functional:bind_front", "absl/log:check", + "absl/log:log", "absl/memory", "absl/random", "absl/status", @@ -5260,6 +5361,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -5338,6 +5440,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -5398,6 +5501,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -5448,6 +5552,7 @@ grpc_cc_library( "load_balancing/xds/xds_cluster_manager.cc", ], external_deps = [ + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -5491,6 +5596,7 @@ grpc_cc_library( "load_balancing/xds/xds_wrr_locality.cc", ], external_deps = [ + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -5560,6 +5666,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -5607,6 +5714,7 @@ grpc_cc_library( external_deps = [ "absl/functional:function_ref", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/types:optional", @@ -5644,6 +5752,7 @@ grpc_cc_library( external_deps = [ "absl/algorithm:container", "absl/log:check", + "absl/log:log", "absl/random", "absl/status", "absl/status:statusor", @@ -5730,7 +5839,10 @@ grpc_cc_library( hdrs = [ "lib/transport/connectivity_state.h", ], - external_deps = ["absl/status"], + external_deps = [ + "absl/log:log", + "absl/status", + ], deps = [ "closure", "error", @@ -5765,6 +5877,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/container:inlined_vector", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -5815,6 +5928,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/meta:type_traits", "absl/random", "absl/status", @@ -5868,6 +5982,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/meta:type_traits", "absl/random", "absl/status", @@ -5938,6 +6053,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/meta:type_traits", "absl/random", "absl/status", @@ -5987,6 +6103,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -6035,6 +6152,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/meta:type_traits", "absl/random", "absl/status", @@ -6084,6 +6202,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/functional:function_ref", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -6145,6 +6264,7 @@ grpc_cc_library( ], external_deps = [ "absl/container:inlined_vector", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -6189,6 +6309,7 @@ grpc_cc_library( "ext/filters/backend_metrics/backend_metric_filter.h", ], external_deps = [ + "absl/log:log", "absl/status:statusor", "absl/strings", "absl/types:optional", @@ -6229,6 +6350,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -6293,6 +6415,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/cleanup", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -6334,7 +6457,10 @@ grpc_cc_library( hdrs = [ "resolver/dns/dns_resolver_plugin.h", ], - external_deps = ["absl/strings"], + external_deps = [ + "absl/log:log", + "absl/strings", + ], language = "c++", deps = [ "experiments", @@ -6358,6 +6484,7 @@ grpc_cc_library( ], external_deps = [ "absl/functional:bind_front", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -6391,6 +6518,7 @@ grpc_cc_library( "resolver/sockaddr/sockaddr_resolver.cc", ], external_deps = [ + "absl/log:log", "absl/status:statusor", "absl/strings", ], @@ -6415,6 +6543,7 @@ grpc_cc_library( "resolver/binder/binder_resolver.cc", ], external_deps = [ + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -6476,6 +6605,7 @@ grpc_cc_library( "absl/container:flat_hash_map", "absl/container:flat_hash_set", "absl/log:check", + "absl/log:log", "absl/strings", ], language = "c++", @@ -6499,6 +6629,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/meta:type_traits", "absl/random", "absl/status", @@ -6560,6 +6691,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status:statusor", "absl/strings", "absl/types:optional", @@ -6627,6 +6759,7 @@ grpc_cc_library( external_deps = [ "absl/functional:function_ref", "absl/log:check", + "absl/log:log", "absl/status", "absl/strings", "absl/strings:str_format", @@ -6821,6 +6954,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings:str_format", @@ -6878,6 +7012,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -6892,6 +7027,8 @@ grpc_cc_library( "connection_quota", "error", "error_utils", + "event_engine_extensions", + "event_engine_query_extensions", "grpc_insecure_credentials", "handshaker_registry", "iomgr_fwd", @@ -6937,6 +7074,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -6954,6 +7092,7 @@ grpc_cc_library( "experiments", "iomgr_fwd", "metadata_batch", + "resource_quota", "slice", "slice_buffer", "status_helper", @@ -7062,6 +7201,7 @@ grpc_cc_library( external_deps = [ "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -7115,6 +7255,7 @@ grpc_cc_library( "ext/filters/logging/logging_filter.h", ], external_deps = [ + "absl/log:log", "absl/numeric:int128", "absl/random", "absl/random:distributions", @@ -7193,7 +7334,10 @@ grpc_cc_library( hdrs = [ "ext/transport/chaotic_good/chaotic_good_transport.h", ], - external_deps = ["absl/random"], + external_deps = [ + "absl/log:log", + "absl/random", + ], language = "c++", deps = [ "chaotic_good_frame", @@ -7222,6 +7366,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/container:flat_hash_map", "absl/log:check", + "absl/log:log", "absl/random", "absl/random:bit_gen_ref", "absl/status", @@ -7280,6 +7425,7 @@ grpc_cc_library( "absl/container:flat_hash_map", "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/random", "absl/random:bit_gen_ref", "absl/status", @@ -7365,6 +7511,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", ], deps = [ "call_final_info", @@ -7475,6 +7622,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", ], deps = [ "1999", @@ -7612,6 +7760,7 @@ grpc_cc_library( external_deps = [ "absl/container:flat_hash_map", "absl/log:check", + "absl/log:log", "absl/random", "absl/random:bit_gen_ref", "absl/status", @@ -7677,6 +7826,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/random", "absl/random:bit_gen_ref", "absl/status", diff --git a/src/core/channelz/channel_trace.cc b/src/core/channelz/channel_trace.cc index 60b0a937c96..6e6884cd703 100644 --- a/src/core/channelz/channel_trace.cc +++ b/src/core/channelz/channel_trace.cc @@ -28,10 +28,10 @@ #include #include "src/core/channelz/channelz.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/slice/slice.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/util/string.h" namespace grpc_core { namespace channelz { diff --git a/src/core/channelz/channelz.cc b/src/core/channelz/channelz.cc index 728976cb678..699ee188af6 100644 --- a/src/core/channelz/channelz.cc +++ b/src/core/channelz/channelz.cc @@ -37,12 +37,12 @@ #include "src/core/lib/address_utils/parse_address.h" #include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/iomgr/resolved_address.h" #include "src/core/lib/json/json_writer.h" #include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/uri/uri_parser.h" +#include "src/core/util/string.h" +#include "src/core/util/useful.h" namespace grpc_core { namespace channelz { diff --git a/src/core/channelz/channelz.h b/src/core/channelz/channelz.h index c7dd8561f57..5ecf702c845 100644 --- a/src/core/channelz/channelz.h +++ b/src/core/channelz/channelz.h @@ -38,13 +38,13 @@ #include #include "src/core/channelz/channel_trace.h" -#include "src/core/lib/gpr/time_precise.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/per_cpu.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" #include "src/core/lib/json/json.h" +#include "src/core/util/time_precise.h" +#include "src/core/util/useful.h" // Channel arg key for channelz node. #define GRPC_ARG_CHANNELZ_CHANNEL_NODE "grpc.internal.channelz_channel_node" @@ -72,7 +72,7 @@ class ListenSocketNode; namespace testing { class CallCountingHelperPeer; -class ChannelNodePeer; +class SubchannelNodePeer; } // namespace testing // base class for all channelz entities @@ -228,9 +228,6 @@ class ChannelNode final : public BaseNode { void RemoveChildSubchannel(intptr_t child_uuid); private: - // Allows the channel trace test to access trace_. - friend class testing::ChannelNodePeer; - void PopulateChildRefs(Json::Object* json); std::string target_; @@ -277,6 +274,9 @@ class SubchannelNode final : public BaseNode { void RecordCallSucceeded() { call_counter_.RecordCallSucceeded(); } private: + // Allows the channel trace test to access trace_. + friend class testing::SubchannelNodePeer; + std::atomic connectivity_state_{GRPC_CHANNEL_IDLE}; Mutex socket_mu_; RefCountedPtr child_socket_ ABSL_GUARDED_BY(socket_mu_); diff --git a/src/core/channelz/channelz_registry.cc b/src/core/channelz/channelz_registry.cc index 5efbc60e8db..0ba7a2ac438 100644 --- a/src/core/channelz/channelz_registry.cc +++ b/src/core/channelz/channelz_registry.cc @@ -25,6 +25,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -171,7 +172,7 @@ void ChannelzRegistry::InternalLogAllEntities() { } for (size_t i = 0; i < nodes.size(); ++i) { std::string json = nodes[i]->RenderJsonString(); - gpr_log(GPR_INFO, "%s", json.c_str()); + LOG(INFO) << json; } } diff --git a/src/core/client_channel/client_channel_filter.cc b/src/core/client_channel/client_channel_filter.cc index 1ffcfb5e4ca..10918a8cba7 100644 --- a/src/core/client_channel/client_channel_filter.cc +++ b/src/core/client_channel/client_channel_filter.cc @@ -68,7 +68,6 @@ #include "src/core/lib/config/core_configuration.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/experiments/experiments.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/manual_constructor.h" @@ -104,6 +103,7 @@ #include "src/core/resolver/resolver_registry.h" #include "src/core/service_config/service_config_call_data.h" #include "src/core/service_config/service_config_impl.h" +#include "src/core/util/useful.h" // // Client channel filter diff --git a/src/core/client_channel/client_channel_filter.h b/src/core/client_channel/client_channel_filter.h index 28c21d3280c..9e11e12d223 100644 --- a/src/core/client_channel/client_channel_filter.h +++ b/src/core/client_channel/client_channel_filter.h @@ -48,7 +48,6 @@ #include "src/core/lib/channel/channel_fwd.h" #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/context.h" -#include "src/core/lib/gpr/time_precise.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -71,6 +70,7 @@ #include "src/core/load_balancing/lb_policy.h" #include "src/core/resolver/resolver.h" #include "src/core/service_config/service_config.h" +#include "src/core/util/time_precise.h" // // Client channel filter diff --git a/src/core/client_channel/config_selector.cc b/src/core/client_channel/config_selector.cc index 2cba7a1a215..9264e4c1618 100644 --- a/src/core/client_channel/config_selector.cc +++ b/src/core/client_channel/config_selector.cc @@ -19,7 +19,7 @@ #include "src/core/client_channel/config_selector.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/client_channel/config_selector.h b/src/core/client_channel/config_selector.h index c6067e44f3b..0a0a6d54c80 100644 --- a/src/core/client_channel/config_selector.h +++ b/src/core/client_channel/config_selector.h @@ -33,13 +33,13 @@ #include "src/core/client_channel/client_channel_internal.h" #include "src/core/lib/channel/channel_fwd.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/resource_quota/arena.h" #include "src/core/lib/slice/slice.h" #include "src/core/lib/transport/metadata_batch.h" #include "src/core/service_config/service_config.h" +#include "src/core/util/useful.h" // Channel arg key for ConfigSelector. #define GRPC_ARG_CONFIG_SELECTOR "grpc.internal.config_selector" diff --git a/src/core/client_channel/dynamic_filters.cc b/src/core/client_channel/dynamic_filters.cc index ce51dd2b2c2..c589f860807 100644 --- a/src/core/client_channel/dynamic_filters.cc +++ b/src/core/client_channel/dynamic_filters.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include @@ -32,10 +33,10 @@ #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/channel_stack_builder_impl.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/alloc.h" #include "src/core/lib/gprpp/status_helper.h" #include "src/core/lib/surface/channel_stack_type.h" #include "src/core/lib/surface/lame_client.h" +#include "src/core/util/alloc.h" // Conversion between call and call stack. #define CALL_TO_CALL_STACK(call) \ @@ -68,7 +69,7 @@ DynamicFilters::Call::Call(Args args, grpc_error_handle* error) *error = grpc_call_stack_init(channel_stack_->channel_stack_.get(), 1, Destroy, this, &call_args); if (GPR_UNLIKELY(!error->ok())) { - gpr_log(GPR_ERROR, "error: %s", StatusToString(*error).c_str()); + LOG(ERROR) << "error: " << StatusToString(*error); return; } grpc_call_stack_set_pollset_or_pollset_set(call_stack, args.pollent); diff --git a/src/core/client_channel/dynamic_filters.h b/src/core/client_channel/dynamic_filters.h index 5db94fa672f..d6aa9b4cf7e 100644 --- a/src/core/client_channel/dynamic_filters.h +++ b/src/core/client_channel/dynamic_filters.h @@ -28,7 +28,6 @@ #include "src/core/lib/channel/channel_fwd.h" #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/context.h" -#include "src/core/lib/gpr/time_precise.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -39,6 +38,7 @@ #include "src/core/lib/iomgr/polling_entity.h" #include "src/core/lib/resource_quota/arena.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/time_precise.h" namespace grpc_core { diff --git a/src/core/client_channel/retry_filter.h b/src/core/client_channel/retry_filter.h index 4730015ecdb..0da23f845b2 100644 --- a/src/core/client_channel/retry_filter.h +++ b/src/core/client_channel/retry_filter.h @@ -40,10 +40,10 @@ #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/context.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/useful.h" extern grpc_core::TraceFlag grpc_retry_trace; diff --git a/src/core/client_channel/retry_filter_legacy_call_data.cc b/src/core/client_channel/retry_filter_legacy_call_data.cc index dffd5ddb4e2..8f1d48d48ae 100644 --- a/src/core/client_channel/retry_filter_legacy_call_data.cc +++ b/src/core/client_channel/retry_filter_legacy_call_data.cc @@ -35,7 +35,6 @@ #include "src/core/lib/channel/context.h" #include "src/core/lib/channel/status_util.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/construct_destruct.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/orphanable.h" @@ -54,6 +53,7 @@ #include "src/core/lib/transport/error_utils.h" #include "src/core/lib/transport/metadata_batch.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/client_channel/subchannel.cc b/src/core/client_channel/subchannel.cc index e8ef1f5e861..d0f9edefeab 100644 --- a/src/core/client_channel/subchannel.cc +++ b/src/core/client_channel/subchannel.cc @@ -27,6 +27,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/strings/cord.h" #include "absl/strings/str_cat.h" @@ -51,8 +52,6 @@ #include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/stats_data.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/alloc.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/status_helper.h" @@ -68,6 +67,8 @@ #include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/error_utils.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/alloc.h" +#include "src/core/util/useful.h" // Backoff parameters. #define GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS 1 @@ -196,7 +197,7 @@ SubchannelCall::SubchannelCall(Args args, grpc_error_handle* error) *error = grpc_call_stack_init(connected_subchannel_->channel_stack(), 1, SubchannelCall::Destroy, this, &call_args); if (GPR_UNLIKELY(!error->ok())) { - gpr_log(GPR_ERROR, "error: %s", StatusToString(*error).c_str()); + LOG(ERROR) << "error: " << StatusToString(*error); return; } grpc_call_stack_set_pollset_or_pollset_set(callstk, args.pollent); diff --git a/src/core/client_channel/subchannel.h b/src/core/client_channel/subchannel.h index 6fbe389da5c..f59a3810208 100644 --- a/src/core/client_channel/subchannel.h +++ b/src/core/client_channel/subchannel.h @@ -37,7 +37,6 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_fwd.h" #include "src/core/lib/channel/context.h" -#include "src/core/lib/gpr/time_precise.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/dual_ref_counted.h" #include "src/core/lib/gprpp/orphanable.h" @@ -59,6 +58,7 @@ #include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/metadata_batch.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/time_precise.h" namespace grpc_core { diff --git a/src/core/client_channel/subchannel_pool_interface.h b/src/core/client_channel/subchannel_pool_interface.h index fa8e828c393..6c02214ccdc 100644 --- a/src/core/client_channel/subchannel_pool_interface.h +++ b/src/core/client_channel/subchannel_pool_interface.h @@ -27,10 +27,10 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/resolved_address.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/client_channel/subchannel_stream_client.cc b/src/core/client_channel/subchannel_stream_client.cc index 89f4fd9e05d..2ee082ef1fa 100644 --- a/src/core/client_channel/subchannel_stream_client.cc +++ b/src/core/client_channel/subchannel_stream_client.cc @@ -29,7 +29,6 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/time_precise.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/status_helper.h" #include "src/core/lib/gprpp/sync.h" @@ -37,6 +36,7 @@ #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/resource_quota/resource_quota.h" #include "src/core/lib/transport/error_utils.h" +#include "src/core/util/time_precise.h" #define SUBCHANNEL_STREAM_INITIAL_CONNECT_BACKOFF_SECONDS 1 #define SUBCHANNEL_STREAM_RECONNECT_BACKOFF_MULTIPLIER 1.6 diff --git a/src/core/ext/filters/backend_metrics/backend_metric_filter.cc b/src/core/ext/filters/backend_metrics/backend_metric_filter.cc index c3ce55921d8..d9f02b41bf7 100644 --- a/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +++ b/src/core/ext/filters/backend_metrics/backend_metric_filter.cc @@ -52,6 +52,7 @@ TraceFlag grpc_backend_metric_filter_trace(false, "backend_metric_filter"); const NoInterceptor BackendMetricFilter::Call::OnClientInitialMetadata; const NoInterceptor BackendMetricFilter::Call::OnServerInitialMetadata; const NoInterceptor BackendMetricFilter::Call::OnClientToServerMessage; +const NoInterceptor BackendMetricFilter::Call::OnClientToServerHalfClose; const NoInterceptor BackendMetricFilter::Call::OnServerToClientMessage; const NoInterceptor BackendMetricFilter::Call::OnFinalize; diff --git a/src/core/ext/filters/backend_metrics/backend_metric_filter.h b/src/core/ext/filters/backend_metrics/backend_metric_filter.h index d97b0c8cb65..114fc3cc7bc 100644 --- a/src/core/ext/filters/backend_metrics/backend_metric_filter.h +++ b/src/core/ext/filters/backend_metrics/backend_metric_filter.h @@ -44,6 +44,7 @@ class BackendMetricFilter : public ImplementChannelFilter { static const NoInterceptor OnServerInitialMetadata; void OnServerTrailingMetadata(ServerMetadata& md); static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnFinalize; }; diff --git a/src/core/ext/filters/fault_injection/fault_injection_filter.cc b/src/core/ext/filters/fault_injection/fault_injection_filter.cc index 87d5a4d2f1f..ae64f83ddc8 100644 --- a/src/core/ext/filters/fault_injection/fault_injection_filter.cc +++ b/src/core/ext/filters/fault_injection/fault_injection_filter.cc @@ -58,6 +58,7 @@ TraceFlag grpc_fault_injection_filter_trace(false, "fault_injection_filter"); const NoInterceptor FaultInjectionFilter::Call::OnServerInitialMetadata; const NoInterceptor FaultInjectionFilter::Call::OnServerTrailingMetadata; const NoInterceptor FaultInjectionFilter::Call::OnClientToServerMessage; +const NoInterceptor FaultInjectionFilter::Call::OnClientToServerHalfClose; const NoInterceptor FaultInjectionFilter::Call::OnServerToClientMessage; const NoInterceptor FaultInjectionFilter::Call::OnFinalize; diff --git a/src/core/ext/filters/fault_injection/fault_injection_filter.h b/src/core/ext/filters/fault_injection/fault_injection_filter.h index b6b1b811cde..515df16a853 100644 --- a/src/core/ext/filters/fault_injection/fault_injection_filter.h +++ b/src/core/ext/filters/fault_injection/fault_injection_filter.h @@ -58,6 +58,7 @@ class FaultInjectionFilter static const NoInterceptor OnServerInitialMetadata; static const NoInterceptor OnServerTrailingMetadata; static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnFinalize; }; diff --git a/src/core/ext/filters/http/client/http_client_filter.cc b/src/core/ext/filters/http/client/http_client_filter.cc index 390df545efe..6af2b959be3 100644 --- a/src/core/ext/filters/http/client/http_client_filter.cc +++ b/src/core/ext/filters/http/client/http_client_filter.cc @@ -54,6 +54,7 @@ namespace grpc_core { const NoInterceptor HttpClientFilter::Call::OnServerToClientMessage; const NoInterceptor HttpClientFilter::Call::OnClientToServerMessage; +const NoInterceptor HttpClientFilter::Call::OnClientToServerHalfClose; const NoInterceptor HttpClientFilter::Call::OnFinalize; const grpc_channel_filter HttpClientFilter::kFilter = diff --git a/src/core/ext/filters/http/client/http_client_filter.h b/src/core/ext/filters/http/client/http_client_filter.h index f5d7875da5e..f985337f2ca 100644 --- a/src/core/ext/filters/http/client/http_client_filter.h +++ b/src/core/ext/filters/http/client/http_client_filter.h @@ -47,6 +47,7 @@ class HttpClientFilter : public ImplementChannelFilter { absl::Status OnServerInitialMetadata(ServerMetadata& md); absl::Status OnServerTrailingMetadata(ServerMetadata& md); static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnFinalize; }; diff --git a/src/core/ext/filters/http/client_authority_filter.cc b/src/core/ext/filters/http/client_authority_filter.cc index 1d5258493e4..b6970d9ecb5 100644 --- a/src/core/ext/filters/http/client_authority_filter.cc +++ b/src/core/ext/filters/http/client_authority_filter.cc @@ -40,6 +40,7 @@ namespace grpc_core { const NoInterceptor ClientAuthorityFilter::Call::OnServerInitialMetadata; const NoInterceptor ClientAuthorityFilter::Call::OnServerTrailingMetadata; const NoInterceptor ClientAuthorityFilter::Call::OnClientToServerMessage; +const NoInterceptor ClientAuthorityFilter::Call::OnClientToServerHalfClose; const NoInterceptor ClientAuthorityFilter::Call::OnServerToClientMessage; const NoInterceptor ClientAuthorityFilter::Call::OnFinalize; diff --git a/src/core/ext/filters/http/client_authority_filter.h b/src/core/ext/filters/http/client_authority_filter.h index 44229c6cdde..da154fbac5d 100644 --- a/src/core/ext/filters/http/client_authority_filter.h +++ b/src/core/ext/filters/http/client_authority_filter.h @@ -52,6 +52,7 @@ class ClientAuthorityFilter final static const NoInterceptor OnServerInitialMetadata; static const NoInterceptor OnServerTrailingMetadata; static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnFinalize; }; diff --git a/src/core/ext/filters/http/message_compress/compression_filter.cc b/src/core/ext/filters/http/message_compress/compression_filter.cc index b688b866cf9..ed077de6e70 100644 --- a/src/core/ext/filters/http/message_compress/compression_filter.cc +++ b/src/core/ext/filters/http/message_compress/compression_filter.cc @@ -57,8 +57,10 @@ namespace grpc_core { +const NoInterceptor ServerCompressionFilter::Call::OnClientToServerHalfClose; const NoInterceptor ServerCompressionFilter::Call::OnServerTrailingMetadata; const NoInterceptor ServerCompressionFilter::Call::OnFinalize; +const NoInterceptor ClientCompressionFilter::Call::OnClientToServerHalfClose; const NoInterceptor ClientCompressionFilter::Call::OnServerTrailingMetadata; const NoInterceptor ClientCompressionFilter::Call::OnFinalize; diff --git a/src/core/ext/filters/http/message_compress/compression_filter.h b/src/core/ext/filters/http/message_compress/compression_filter.h index 99e57a0ac1d..5d82846d01d 100644 --- a/src/core/ext/filters/http/message_compress/compression_filter.h +++ b/src/core/ext/filters/http/message_compress/compression_filter.h @@ -129,6 +129,7 @@ class ClientCompressionFilter final absl::StatusOr OnServerToClientMessage( MessageHandle message, ClientCompressionFilter* filter); + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerTrailingMetadata; static const NoInterceptor OnFinalize; @@ -165,6 +166,7 @@ class ServerCompressionFilter final MessageHandle OnServerToClientMessage(MessageHandle message, ServerCompressionFilter* filter); + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerTrailingMetadata; static const NoInterceptor OnFinalize; diff --git a/src/core/ext/filters/http/server/http_server_filter.cc b/src/core/ext/filters/http/server/http_server_filter.cc index 925cc73c23e..4d92cef6eaa 100644 --- a/src/core/ext/filters/http/server/http_server_filter.cc +++ b/src/core/ext/filters/http/server/http_server_filter.cc @@ -50,6 +50,7 @@ namespace grpc_core { const NoInterceptor HttpServerFilter::Call::OnClientToServerMessage; +const NoInterceptor HttpServerFilter::Call::OnClientToServerHalfClose; const NoInterceptor HttpServerFilter::Call::OnServerToClientMessage; const NoInterceptor HttpServerFilter::Call::OnFinalize; diff --git a/src/core/ext/filters/http/server/http_server_filter.h b/src/core/ext/filters/http/server/http_server_filter.h index 282973ddecd..a1f330e58bb 100644 --- a/src/core/ext/filters/http/server/http_server_filter.h +++ b/src/core/ext/filters/http/server/http_server_filter.h @@ -50,6 +50,7 @@ class HttpServerFilter : public ImplementChannelFilter { void OnServerInitialMetadata(ServerMetadata& md); void OnServerTrailingMetadata(ServerMetadata& md); static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnFinalize; }; diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc b/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc index 7937ab6fe74..100584f5ba1 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc +++ b/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc @@ -74,6 +74,7 @@ constexpr char kEmptyAddressLengthString[] = "00"; const NoInterceptor ServerLoadReportingFilter::Call::OnServerInitialMetadata; const NoInterceptor ServerLoadReportingFilter::Call::OnClientToServerMessage; +const NoInterceptor ServerLoadReportingFilter::Call::OnClientToServerHalfClose; const NoInterceptor ServerLoadReportingFilter::Call::OnServerToClientMessage; absl::StatusOr> diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_filter.h b/src/core/ext/filters/load_reporting/server_load_reporting_filter.h index f11c8c38bcf..76684093a0b 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_filter.h +++ b/src/core/ext/filters/load_reporting/server_load_reporting_filter.h @@ -54,6 +54,7 @@ class ServerLoadReportingFilter void OnServerTrailingMetadata(ServerMetadata& md, ServerLoadReportingFilter* filter); static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; void OnFinalize(const grpc_call_final_info* final_info, ServerLoadReportingFilter* filter); diff --git a/src/core/ext/filters/logging/logging_filter.cc b/src/core/ext/filters/logging/logging_filter.cc index 1c76e64b06a..06ee67de012 100644 --- a/src/core/ext/filters/logging/logging_filter.cc +++ b/src/core/ext/filters/logging/logging_filter.cc @@ -31,6 +31,7 @@ #include #include +#include "absl/log/log.h" #include "absl/numeric/int128.h" #include "absl/random/random.h" #include "absl/random/uniform_int_distribution.h" @@ -73,6 +74,9 @@ namespace grpc_core { +const NoInterceptor ClientLoggingFilter::Call::OnFinalize; +const NoInterceptor ServerLoggingFilter::Call::OnFinalize; + namespace { LoggingSink* g_logging_sink = nullptr; @@ -157,7 +161,7 @@ LoggingSink::Entry::Address PeerStringToAddress(const Slice& peer_string) { LoggingSink::Entry::Address address; absl::StatusOr uri = URI::Parse(peer_string.as_string_view()); if (!uri.ok()) { - gpr_log(GPR_DEBUG, "peer_string is in invalid format and cannot be logged"); + VLOG(2) << "peer_string is in invalid format and cannot be logged"; return address; } @@ -195,152 +199,148 @@ void EncodeMessageToPayload(const SliceBuffer* message, uint32_t log_len, } } -class CallData { - public: - CallData(bool is_client, const CallArgs& call_args, - const std::string& authority) - : call_id_(GetCallId()) { - absl::string_view path; - if (auto* value = call_args.client_initial_metadata->get_pointer( - HttpPathMetadata())) { - path = value->as_string_view(); - } - std::vector parts = - absl::StrSplit(path, '/', absl::SkipEmpty()); - if (parts.size() == 2) { - service_name_ = std::move(parts[0]); - method_name_ = std::move(parts[1]); +} // namespace + +namespace logging_filter_detail { + +CallData::CallData(bool is_client, + const ClientMetadata& client_initial_metadata, + const std::string& authority) + : call_id_(GetCallId()) { + absl::string_view path; + if (auto* value = client_initial_metadata.get_pointer(HttpPathMetadata())) { + path = value->as_string_view(); + } + std::vector parts = absl::StrSplit(path, '/', absl::SkipEmpty()); + if (parts.size() == 2) { + service_name_ = std::move(parts[0]); + method_name_ = std::move(parts[1]); + } + config_ = g_logging_sink->FindMatch(is_client, service_name_, method_name_); + if (config_.ShouldLog()) { + if (auto* value = + client_initial_metadata.get_pointer(HttpAuthorityMetadata())) { + authority_ = std::string(value->as_string_view()); + } else { + authority_ = authority; } - config_ = g_logging_sink->FindMatch(is_client, service_name_, method_name_); - if (config_.ShouldLog()) { - if (auto* value = call_args.client_initial_metadata->get_pointer( - HttpAuthorityMetadata())) { - authority_ = std::string(value->as_string_view()); - } else { - authority_ = authority; - } + } +} + +void CallData::LogClientHeader(bool is_client, + CallTracerAnnotationInterface* tracer, + const ClientMetadata& metadata) { + LoggingSink::Entry entry; + if (!is_client) { + if (auto* value = metadata.get_pointer(PeerString())) { + peer_ = PeerStringToAddress(*value); } } + SetCommonEntryFields(&entry, is_client, tracer, + LoggingSink::Entry::EventType::kClientHeader); + MetadataEncoder encoder(&entry.payload, nullptr, + config_.max_metadata_bytes()); + metadata.Encode(&encoder); + entry.payload_truncated = encoder.truncated(); + g_logging_sink->LogEntry(std::move(entry)); +} - bool ShouldLog() { return config_.ShouldLog(); } +void CallData::LogClientHalfClose(bool is_client, + CallTracerAnnotationInterface* tracer) { + LoggingSink::Entry entry; + SetCommonEntryFields(&entry, is_client, tracer, + LoggingSink::Entry::EventType::kClientHalfClose); + g_logging_sink->LogEntry(std::move(entry)); +} - void LogClientHeader(bool is_client, CallTracerAnnotationInterface* tracer, - const ClientMetadataHandle& metadata) { - LoggingSink::Entry entry; - if (!is_client) { +void CallData::LogServerHeader(bool is_client, + CallTracerAnnotationInterface* tracer, + const ServerMetadata* metadata) { + LoggingSink::Entry entry; + if (metadata != nullptr) { + entry.is_trailer_only = metadata->get(GrpcTrailersOnly()).value_or(false); + if (is_client) { if (auto* value = metadata->get_pointer(PeerString())) { peer_ = PeerStringToAddress(*value); } } - SetCommonEntryFields(&entry, is_client, tracer, - LoggingSink::Entry::EventType::kClientHeader); + } + SetCommonEntryFields(&entry, is_client, tracer, + LoggingSink::Entry::EventType::kServerHeader); + if (metadata != nullptr) { MetadataEncoder encoder(&entry.payload, nullptr, config_.max_metadata_bytes()); metadata->Encode(&encoder); entry.payload_truncated = encoder.truncated(); - g_logging_sink->LogEntry(std::move(entry)); - } - - void LogClientHalfClose(bool is_client, - CallTracerAnnotationInterface* tracer) { - LoggingSink::Entry entry; - SetCommonEntryFields(&entry, is_client, tracer, - LoggingSink::Entry::EventType::kClientHalfClose); - g_logging_sink->LogEntry(std::move(entry)); - } - - void LogServerHeader(bool is_client, CallTracerAnnotationInterface* tracer, - const ServerMetadata* metadata) { - LoggingSink::Entry entry; - if (metadata != nullptr) { - entry.is_trailer_only = metadata->get(GrpcTrailersOnly()).value_or(false); - if (is_client) { - if (auto* value = metadata->get_pointer(PeerString())) { - peer_ = PeerStringToAddress(*value); - } - } - } - SetCommonEntryFields(&entry, is_client, tracer, - LoggingSink::Entry::EventType::kServerHeader); - if (metadata != nullptr) { - MetadataEncoder encoder(&entry.payload, nullptr, - config_.max_metadata_bytes()); - metadata->Encode(&encoder); - entry.payload_truncated = encoder.truncated(); - } - g_logging_sink->LogEntry(std::move(entry)); } + g_logging_sink->LogEntry(std::move(entry)); +} - void LogServerTrailer(bool is_client, CallTracerAnnotationInterface* tracer, - const ServerMetadata* metadata) { - LoggingSink::Entry entry; - SetCommonEntryFields(&entry, is_client, tracer, - LoggingSink::Entry::EventType::kServerTrailer); - if (metadata != nullptr) { - entry.is_trailer_only = metadata->get(GrpcTrailersOnly()).value_or(false); - MetadataEncoder encoder(&entry.payload, &entry.payload.status_details, - config_.max_metadata_bytes()); - metadata->Encode(&encoder); - entry.payload_truncated = encoder.truncated(); - } - g_logging_sink->LogEntry(std::move(entry)); +void CallData::LogServerTrailer(bool is_client, + CallTracerAnnotationInterface* tracer, + const ServerMetadata* metadata) { + LoggingSink::Entry entry; + SetCommonEntryFields(&entry, is_client, tracer, + LoggingSink::Entry::EventType::kServerTrailer); + if (metadata != nullptr) { + entry.is_trailer_only = metadata->get(GrpcTrailersOnly()).value_or(false); + MetadataEncoder encoder(&entry.payload, &entry.payload.status_details, + config_.max_metadata_bytes()); + metadata->Encode(&encoder); + entry.payload_truncated = encoder.truncated(); } + g_logging_sink->LogEntry(std::move(entry)); +} - void LogClientMessage(bool is_client, CallTracerAnnotationInterface* tracer, - const SliceBuffer* message) { - LoggingSink::Entry entry; - SetCommonEntryFields(&entry, is_client, tracer, - LoggingSink::Entry::EventType::kClientMessage); - EncodeMessageToPayload(message, config_.max_message_bytes(), &entry); - g_logging_sink->LogEntry(std::move(entry)); - } +void CallData::LogClientMessage(bool is_client, + CallTracerAnnotationInterface* tracer, + const SliceBuffer* message) { + LoggingSink::Entry entry; + SetCommonEntryFields(&entry, is_client, tracer, + LoggingSink::Entry::EventType::kClientMessage); + EncodeMessageToPayload(message, config_.max_message_bytes(), &entry); + g_logging_sink->LogEntry(std::move(entry)); +} - void LogServerMessage(bool is_client, CallTracerAnnotationInterface* tracer, - const SliceBuffer* message) { - LoggingSink::Entry entry; - SetCommonEntryFields(&entry, is_client, tracer, - LoggingSink::Entry::EventType::kServerMessage); - EncodeMessageToPayload(message, config_.max_message_bytes(), &entry); - g_logging_sink->LogEntry(std::move(entry)); - } +void CallData::LogServerMessage(bool is_client, + CallTracerAnnotationInterface* tracer, + const SliceBuffer* message) { + LoggingSink::Entry entry; + SetCommonEntryFields(&entry, is_client, tracer, + LoggingSink::Entry::EventType::kServerMessage); + EncodeMessageToPayload(message, config_.max_message_bytes(), &entry); + g_logging_sink->LogEntry(std::move(entry)); +} - void LogCancel(bool is_client, CallTracerAnnotationInterface* tracer) { - LoggingSink::Entry entry; - SetCommonEntryFields(&entry, is_client, tracer, - LoggingSink::Entry::EventType::kCancel); - g_logging_sink->LogEntry(std::move(entry)); - } +void CallData::LogCancel(bool is_client, + CallTracerAnnotationInterface* tracer) { + LoggingSink::Entry entry; + SetCommonEntryFields(&entry, is_client, tracer, + LoggingSink::Entry::EventType::kCancel); + g_logging_sink->LogEntry(std::move(entry)); +} - private: - void SetCommonEntryFields(LoggingSink::Entry* entry, bool is_client, - CallTracerAnnotationInterface* tracer, - LoggingSink::Entry::EventType event_type) { - entry->call_id = call_id_; - entry->sequence_id = sequence_id_++; - entry->type = event_type; - entry->logger = is_client ? LoggingSink::Entry::Logger::kClient - : LoggingSink::Entry::Logger::kServer; - entry->authority = authority_; - entry->peer = peer_; - entry->service_name = service_name_; - entry->method_name = method_name_; - entry->timestamp = Timestamp::Now(); - if (tracer != nullptr) { - entry->trace_id = tracer->TraceId(); - entry->span_id = tracer->SpanId(); - entry->is_sampled = tracer->IsSampled(); - } +void CallData::SetCommonEntryFields(LoggingSink::Entry* entry, bool is_client, + CallTracerAnnotationInterface* tracer, + LoggingSink::Entry::EventType event_type) { + entry->call_id = call_id_; + entry->sequence_id = sequence_id_++; + entry->type = event_type; + entry->logger = is_client ? LoggingSink::Entry::Logger::kClient + : LoggingSink::Entry::Logger::kServer; + entry->authority = authority_; + entry->peer = peer_; + entry->service_name = service_name_; + entry->method_name = method_name_; + entry->timestamp = Timestamp::Now(); + if (tracer != nullptr) { + entry->trace_id = tracer->TraceId(); + entry->span_id = tracer->SpanId(); + entry->is_sampled = tracer->IsSampled(); } - absl::uint128 call_id_; - uint32_t sequence_id_ = 0; - std::string service_name_; - std::string method_name_; - std::string authority_; - LoggingSink::Entry::Address peer_; - LoggingSink::Config config_; -}; +} -} // namespace +} // namespace logging_filter_detail absl::StatusOr> ClientLoggingFilter::Create(const ChannelArgs& args, @@ -361,84 +361,57 @@ ClientLoggingFilter::Create(const ChannelArgs& args, return std::make_unique(""); } -// Construct a promise for one call. -ArenaPromise ClientLoggingFilter::MakeCallPromise( - CallArgs call_args, NextPromiseFactory next_promise_factory) { - CallData* calld = GetContext()->ManagedNew( - true, call_args, default_authority_); - if (!calld->ShouldLog()) { - return next_promise_factory(std::move(call_args)); +void ClientLoggingFilter::Call::OnClientInitialMetadata( + ClientMetadata& md, ClientLoggingFilter* filter) { + call_data_.emplace(true, md, filter->default_authority_); + if (!call_data_->ShouldLog()) { + call_data_.reset(); + return; + } + call_data_->LogClientHeader( + /*is_client=*/true, MaybeGetContext(), md); +} + +void ClientLoggingFilter::Call::OnServerInitialMetadata(ServerMetadata& md) { + if (!call_data_.has_value()) return; + call_data_->LogServerHeader( + /*is_client=*/true, MaybeGetContext(), + &md); +} + +void ClientLoggingFilter::Call::OnServerTrailingMetadata(ServerMetadata& md) { + if (!call_data_.has_value()) return; + if (md.get(GrpcCallWasCancelled()).value_or(false) && + md.get(GrpcStatusMetadata()) == GRPC_STATUS_CANCELLED) { + call_data_->LogCancel( + /*is_client=*/true, MaybeGetContext()); + return; } - calld->LogClientHeader( - /*is_client=*/true, - static_cast( - GetContext() - [GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE] - .value), - call_args.client_initial_metadata); - call_args.server_initial_metadata->InterceptAndMap( - [calld](ServerMetadataHandle metadata) { - calld->LogServerHeader( - /*is_client=*/true, - static_cast( - GetContext() - [GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE] - .value), - metadata.get()); - return metadata; - }); - call_args.client_to_server_messages->InterceptAndMapWithHalfClose( - [calld](MessageHandle message) { - calld->LogClientMessage( - /*is_client=*/true, - static_cast( - GetContext() - [GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE] - .value), - message->payload()); - return message; - }, - [calld] { - calld->LogClientHalfClose( - /*is_client=*/true, - static_cast( - GetContext() - [GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE] - .value)); - }); - call_args.server_to_client_messages->InterceptAndMap( - [calld](MessageHandle message) { - calld->LogServerMessage( - /*is_client=*/true, - static_cast( - GetContext() - [GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE] - .value), - message->payload()); - return message; - }); - return OnCancel( - Map(next_promise_factory(std::move(call_args)), - [calld](ServerMetadataHandle md) { - calld->LogServerTrailer( - /*is_client=*/true, - static_cast( - GetContext() - [GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE] - .value), - md.get()); - return md; - }), - // TODO(yashykt/ctiller): GetContext is not - // valid for the cancellation function requiring us to capture it here. - // This ought to be easy to fix once client side promises are completely - // rolled out. - [calld, ctx = GetContext()]() { - calld->LogCancel( - /*is_client=*/true, - static_cast( - ctx[GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE].value)); - }); + call_data_->LogServerTrailer( + /*is_client=*/true, MaybeGetContext(), + &md); +} + +void ClientLoggingFilter::Call::OnClientToServerMessage( + const Message& message) { + if (!call_data_.has_value()) return; + call_data_->LogClientMessage( + /*is_client=*/true, MaybeGetContext(), + message.payload()); +} + +void ClientLoggingFilter::Call::OnClientToServerHalfClose() { + if (!call_data_.has_value()) return; + call_data_->LogClientHalfClose( + /*is_client=*/true, MaybeGetContext()); +} + +void ClientLoggingFilter::Call::OnServerToClientMessage( + const Message& message) { + if (!call_data_.has_value()) return; + call_data_->LogServerMessage( + /*is_client=*/true, MaybeGetContext(), + message.payload()); } const grpc_channel_filter ClientLoggingFilter::kFilter = @@ -454,79 +427,57 @@ ServerLoggingFilter::Create(const ChannelArgs& /*args*/, } // Construct a promise for one call. -ArenaPromise ServerLoggingFilter::MakeCallPromise( - CallArgs call_args, NextPromiseFactory next_promise_factory) { - CallData* calld = GetContext()->ManagedNew( - false, call_args, /*default_authority=*/""); - if (!calld->ShouldLog()) { - return next_promise_factory(std::move(call_args)); +void ServerLoggingFilter::Call::OnClientInitialMetadata(ClientMetadata& md) { + call_data_.emplace(false, md, ""); + if (!call_data_->ShouldLog()) { + call_data_.reset(); + return; } - auto* call_tracer = static_cast( - GetContext() - [GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE] - .value); - calld->LogClientHeader( - /*is_client=*/false, call_tracer, call_args.client_initial_metadata); - call_args.server_initial_metadata->InterceptAndMap( - [calld](ServerMetadataHandle metadata) { - calld->LogServerHeader( - /*is_client=*/false, - static_cast( - GetContext() - [GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE] - .value), - metadata.get()); - return metadata; - }); - call_args.client_to_server_messages->InterceptAndMapWithHalfClose( - [calld](MessageHandle message) { - calld->LogClientMessage( - /*is_client=*/false, - static_cast( - GetContext() - [GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE] - .value), - message->payload()); - return message; - }, - [calld] { - calld->LogClientHalfClose( - /*is_client=*/false, - static_cast( - GetContext() - [GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE] - .value)); - }); - call_args.server_to_client_messages->InterceptAndMap( - [calld](MessageHandle message) { - calld->LogServerMessage( - /*is_client=*/false, - static_cast( - GetContext() - [GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE] - .value), - message->payload()); - return message; - }); - return OnCancel( - Map(next_promise_factory(std::move(call_args)), - [calld](ServerMetadataHandle md) { - calld->LogServerTrailer( - /*is_client=*/false, - static_cast( - GetContext() - [GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE] - .value), - md.get()); - return md; - }), - // TODO(yashykt/ctiller): GetContext is not - // valid for the cancellation function requiring us to capture - // call_tracer. - [calld, call_tracer]() { - calld->LogCancel( - /*is_client=*/false, call_tracer); - }); + call_data_->LogClientHeader( + /*is_client=*/false, MaybeGetContext(), + md); +} + +void ServerLoggingFilter::Call::OnServerInitialMetadata(ServerMetadata& md) { + if (!call_data_.has_value()) return; + call_data_->LogServerHeader( + /*is_client=*/false, MaybeGetContext(), + &md); +} + +void ServerLoggingFilter::Call::OnServerTrailingMetadata(ServerMetadata& md) { + if (!call_data_.has_value()) return; + if (md.get(GrpcCallWasCancelled()).value_or(false) && + md.get(GrpcStatusMetadata()) == GRPC_STATUS_CANCELLED) { + call_data_->LogCancel( + /*is_client=*/false, MaybeGetContext()); + return; + } + call_data_->LogServerTrailer( + /*is_client=*/false, MaybeGetContext(), + &md); +} + +void ServerLoggingFilter::Call::OnClientToServerMessage( + const Message& message) { + if (!call_data_.has_value()) return; + call_data_->LogClientMessage( + /*is_client=*/false, MaybeGetContext(), + message.payload()); +} + +void ServerLoggingFilter::Call::OnClientToServerHalfClose() { + if (!call_data_.has_value()) return; + call_data_->LogClientHalfClose( + /*is_client=*/false, MaybeGetContext()); +} + +void ServerLoggingFilter::Call::OnServerToClientMessage( + const Message& message) { + if (!call_data_.has_value()) return; + call_data_->LogServerMessage( + /*is_client=*/false, MaybeGetContext(), + message.payload()); } const grpc_channel_filter ServerLoggingFilter::kFilter = @@ -539,11 +490,11 @@ void RegisterLoggingFilter(LoggingSink* sink) { g_logging_sink = sink; CoreConfiguration::RegisterBuilder([](CoreConfiguration::Builder* builder) { builder->channel_init() - ->RegisterFilter(GRPC_SERVER_CHANNEL) + ->RegisterV2Filter(GRPC_SERVER_CHANNEL) // TODO(yashykt) : Figure out a good place to place this channel arg .IfChannelArg("grpc.experimental.enable_observability", true); builder->channel_init() - ->RegisterFilter(GRPC_CLIENT_CHANNEL) + ->RegisterV2Filter(GRPC_CLIENT_CHANNEL) // TODO(yashykt) : Figure out a good place to place this channel arg .IfChannelArg("grpc.experimental.enable_observability", true); }); diff --git a/src/core/ext/filters/logging/logging_filter.h b/src/core/ext/filters/logging/logging_filter.h index 7d42abbc337..30c28a5b57a 100644 --- a/src/core/ext/filters/logging/logging_filter.h +++ b/src/core/ext/filters/logging/logging_filter.h @@ -35,7 +35,46 @@ namespace grpc_core { -class ClientLoggingFilter final : public ChannelFilter { +namespace logging_filter_detail { + +class CallData { + public: + CallData(bool is_client, const ClientMetadata& client_initial_metadata, + const std::string& authority); + + bool ShouldLog() { return config_.ShouldLog(); } + + void LogClientHeader(bool is_client, CallTracerAnnotationInterface* tracer, + const ClientMetadata& metadata); + void LogClientHalfClose(bool is_client, + CallTracerAnnotationInterface* tracer); + void LogServerHeader(bool is_client, CallTracerAnnotationInterface* tracer, + const ServerMetadata* metadata); + void LogServerTrailer(bool is_client, CallTracerAnnotationInterface* tracer, + const ServerMetadata* metadata); + void LogClientMessage(bool is_client, CallTracerAnnotationInterface* tracer, + const SliceBuffer* message); + void LogServerMessage(bool is_client, CallTracerAnnotationInterface* tracer, + const SliceBuffer* message); + void LogCancel(bool is_client, CallTracerAnnotationInterface* tracer); + + private: + void SetCommonEntryFields(LoggingSink::Entry* entry, bool is_client, + CallTracerAnnotationInterface* tracer, + LoggingSink::Entry::EventType event_type); + absl::uint128 call_id_; + uint32_t sequence_id_ = 0; + std::string service_name_; + std::string method_name_; + std::string authority_; + LoggingSink::Entry::Address peer_; + LoggingSink::Config config_; +}; + +} // namespace logging_filter_detail + +class ClientLoggingFilter final + : public ImplementChannelFilter { public: static const grpc_channel_filter kFilter; @@ -45,24 +84,46 @@ class ClientLoggingFilter final : public ChannelFilter { explicit ClientLoggingFilter(std::string default_authority) : default_authority_(std::move(default_authority)) {} - // Construct a promise for one call. - ArenaPromise MakeCallPromise( - CallArgs call_args, NextPromiseFactory next_promise_factory) override; + class Call { + public: + void OnClientInitialMetadata(ClientMetadata& md, + ClientLoggingFilter* filter); + void OnServerInitialMetadata(ServerMetadata& md); + void OnServerTrailingMetadata(ServerMetadata& md); + void OnClientToServerMessage(const Message& message); + void OnClientToServerHalfClose(); + void OnServerToClientMessage(const Message& message); + static const NoInterceptor OnFinalize; + + private: + absl::optional call_data_; + }; private: const std::string default_authority_; }; -class ServerLoggingFilter final : public ChannelFilter { +class ServerLoggingFilter final + : public ImplementChannelFilter { public: static const grpc_channel_filter kFilter; static absl::StatusOr> Create( const ChannelArgs& args, ChannelFilter::Args /*filter_args*/); - // Construct a promise for one call. - ArenaPromise MakeCallPromise( - CallArgs call_args, NextPromiseFactory next_promise_factory) override; + class Call { + public: + void OnClientInitialMetadata(ClientMetadata& md); + void OnServerInitialMetadata(ServerMetadata& md); + void OnServerTrailingMetadata(ServerMetadata& md); + void OnClientToServerMessage(const Message& message); + void OnClientToServerHalfClose(); + void OnServerToClientMessage(const Message& message); + static const NoInterceptor OnFinalize; + + private: + absl::optional call_data_; + }; }; void RegisterLoggingFilter(LoggingSink* sink); diff --git a/src/core/ext/filters/logging/logging_sink.h b/src/core/ext/filters/logging/logging_sink.h index b4bf47b3c8c..b013cd9072e 100644 --- a/src/core/ext/filters/logging/logging_sink.h +++ b/src/core/ext/filters/logging/logging_sink.h @@ -27,6 +27,7 @@ #include #include "absl/numeric/int128.h" +#include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "src/core/lib/gprpp/time.h" @@ -73,8 +74,42 @@ class LoggingSink { kCancel }; + static std::string EventTypeString(EventType type) { + switch (type) { + case EventType::kUnknown: + return "UNKNOWN"; + case EventType::kClientHeader: + return "CLIENT_HEADER"; + case EventType::kServerHeader: + return "SERVER_HEADER"; + case EventType::kClientMessage: + return "CLIENT_MESSAGE"; + case EventType::kServerMessage: + return "SERVER_MESSAGE"; + case EventType::kClientHalfClose: + return "CLIENT_HALF_CLOSE"; + case EventType::kServerTrailer: + return "SERVER_TRAILER"; + case EventType::kCancel: + return "CANCEL"; + } + return absl::StrCat("INVALID(", static_cast(type), ")"); + } + enum class Logger { kUnknown = 0, kClient, kServer }; + static std::string LoggerString(Logger logger) { + switch (logger) { + case Logger::kUnknown: + return "UNKNOWN"; + case Logger::kClient: + return "CLIENT"; + case Logger::kServer: + return "SERVER"; + } + return absl::StrCat("INVALID(", static_cast(logger), ")"); + } + struct Payload { std::map metadata; Duration timeout; @@ -118,6 +153,16 @@ class LoggingSink { virtual void LogEntry(Entry entry) = 0; }; +inline std::ostream& operator<<(std::ostream& out, + const LoggingSink::Entry::EventType& type) { + return out << LoggingSink::Entry::EventTypeString(type); +} + +inline std::ostream& operator<<(std::ostream& out, + const LoggingSink::Entry::Logger& logger) { + return out << LoggingSink::Entry::LoggerString(logger); +} + } // namespace grpc_core #endif // GRPC_SRC_CORE_EXT_FILTERS_LOGGING_LOGGING_SINK_H diff --git a/src/core/ext/filters/message_size/message_size_filter.cc b/src/core/ext/filters/message_size/message_size_filter.cc index 0933d633272..2c73c63a370 100644 --- a/src/core/ext/filters/message_size/message_size_filter.cc +++ b/src/core/ext/filters/message_size/message_size_filter.cc @@ -51,10 +51,12 @@ namespace grpc_core { const NoInterceptor ClientMessageSizeFilter::Call::OnClientInitialMetadata; const NoInterceptor ClientMessageSizeFilter::Call::OnServerInitialMetadata; const NoInterceptor ClientMessageSizeFilter::Call::OnServerTrailingMetadata; +const NoInterceptor ClientMessageSizeFilter::Call::OnClientToServerHalfClose; const NoInterceptor ClientMessageSizeFilter::Call::OnFinalize; const NoInterceptor ServerMessageSizeFilter::Call::OnClientInitialMetadata; const NoInterceptor ServerMessageSizeFilter::Call::OnServerInitialMetadata; const NoInterceptor ServerMessageSizeFilter::Call::OnServerTrailingMetadata; +const NoInterceptor ServerMessageSizeFilter::Call::OnClientToServerHalfClose; const NoInterceptor ServerMessageSizeFilter::Call::OnFinalize; // diff --git a/src/core/ext/filters/message_size/message_size_filter.h b/src/core/ext/filters/message_size/message_size_filter.h index 89d21201a5c..1637bfe3561 100644 --- a/src/core/ext/filters/message_size/message_size_filter.h +++ b/src/core/ext/filters/message_size/message_size_filter.h @@ -105,6 +105,7 @@ class ServerMessageSizeFilter final static const NoInterceptor OnFinalize; ServerMetadataHandle OnClientToServerMessage( const Message& message, ServerMessageSizeFilter* filter); + static const NoInterceptor OnClientToServerHalfClose; ServerMetadataHandle OnServerToClientMessage( const Message& message, ServerMessageSizeFilter* filter); }; @@ -133,6 +134,7 @@ class ClientMessageSizeFilter final static const NoInterceptor OnServerTrailingMetadata; static const NoInterceptor OnFinalize; ServerMetadataHandle OnClientToServerMessage(const Message& message); + static const NoInterceptor OnClientToServerHalfClose; ServerMetadataHandle OnServerToClientMessage(const Message& message); private: diff --git a/src/core/ext/filters/rbac/rbac_filter.cc b/src/core/ext/filters/rbac/rbac_filter.cc index 7c75f46ae7d..c89c6962e19 100644 --- a/src/core/ext/filters/rbac/rbac_filter.cc +++ b/src/core/ext/filters/rbac/rbac_filter.cc @@ -46,6 +46,7 @@ namespace grpc_core { const NoInterceptor RbacFilter::Call::OnServerInitialMetadata; const NoInterceptor RbacFilter::Call::OnServerTrailingMetadata; const NoInterceptor RbacFilter::Call::OnClientToServerMessage; +const NoInterceptor RbacFilter::Call::OnClientToServerHalfClose; const NoInterceptor RbacFilter::Call::OnServerToClientMessage; const NoInterceptor RbacFilter::Call::OnFinalize; diff --git a/src/core/ext/filters/rbac/rbac_filter.h b/src/core/ext/filters/rbac/rbac_filter.h index a4c41cbdd0b..d033b799d5f 100644 --- a/src/core/ext/filters/rbac/rbac_filter.h +++ b/src/core/ext/filters/rbac/rbac_filter.h @@ -55,6 +55,7 @@ class RbacFilter : public ImplementChannelFilter { static const NoInterceptor OnServerInitialMetadata; static const NoInterceptor OnServerTrailingMetadata; static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnFinalize; }; diff --git a/src/core/ext/filters/stateful_session/stateful_session_filter.cc b/src/core/ext/filters/stateful_session/stateful_session_filter.cc index 5ae22cd864d..f383f3fb9ed 100644 --- a/src/core/ext/filters/stateful_session/stateful_session_filter.cc +++ b/src/core/ext/filters/stateful_session/stateful_session_filter.cc @@ -60,6 +60,7 @@ namespace grpc_core { TraceFlag grpc_stateful_session_filter_trace(false, "stateful_session_filter"); const NoInterceptor StatefulSessionFilter::Call::OnClientToServerMessage; +const NoInterceptor StatefulSessionFilter::Call::OnClientToServerHalfClose; const NoInterceptor StatefulSessionFilter::Call::OnServerToClientMessage; const NoInterceptor StatefulSessionFilter::Call::OnFinalize; diff --git a/src/core/ext/filters/stateful_session/stateful_session_filter.h b/src/core/ext/filters/stateful_session/stateful_session_filter.h index 5cd534843aa..64c488bce33 100644 --- a/src/core/ext/filters/stateful_session/stateful_session_filter.h +++ b/src/core/ext/filters/stateful_session/stateful_session_filter.h @@ -86,6 +86,7 @@ class StatefulSessionFilter void OnServerInitialMetadata(ServerMetadata& md); void OnServerTrailingMetadata(ServerMetadata& md); static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnFinalize; diff --git a/src/core/ext/gcp/metadata_query.cc b/src/core/ext/gcp/metadata_query.cc index 24422cb780f..dd2e0603641 100644 --- a/src/core/ext/gcp/metadata_query.cc +++ b/src/core/ext/gcp/metadata_query.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" @@ -120,7 +121,7 @@ void MetadataQuery::OnDone(void* arg, grpc_error_handle error) { absl::StrFormat("MetadataServer Could not parse zone: %s", std::string(body).c_str())); if (GRPC_TRACE_FLAG_ENABLED(grpc_metadata_query_trace)) { - gpr_log(GPR_INFO, "%s", result.status().ToString().c_str()); + LOG(INFO) << result.status().ToString(); } } else { result = std::string(body.substr(pos + 1)); diff --git a/src/core/ext/transport/binder/client/channel_create.cc b/src/core/ext/transport/binder/client/channel_create.cc index e590b9db51c..9f757f69bc7 100644 --- a/src/core/ext/transport/binder/client/channel_create.cc +++ b/src/core/ext/transport/binder/client/channel_create.cc @@ -35,6 +35,7 @@ #ifdef GPR_SUPPORT_BINDER_TRANSPORT #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/strings/substitute.h" #include "absl/time/clock.h" @@ -111,7 +112,7 @@ std::shared_ptr CreateCustomBinderChannel( std::string connection_id = grpc_binder::GetConnectionIdGenerator()->Generate(uri); - gpr_log(GPR_ERROR, "connection id is %s", connection_id.c_str()); + LOG(ERROR) << "connection id is " << connection_id; // After invoking this Java method, Java code will put endpoint binder into // `EndpointBinderPool` after the connection succeeds diff --git a/src/core/ext/transport/binder/client/endpoint_binder_pool.cc b/src/core/ext/transport/binder/client/endpoint_binder_pool.cc index 5932ce7a9bf..012d7f03063 100644 --- a/src/core/ext/transport/binder/client/endpoint_binder_pool.cc +++ b/src/core/ext/transport/binder/client/endpoint_binder_pool.cc @@ -15,6 +15,7 @@ #include "src/core/ext/transport/binder/client/endpoint_binder_pool.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include @@ -36,11 +37,11 @@ Java_io_grpc_binder_cpp_GrpcBinderConnection_notifyConnected__Ljava_lang_String_ JNIEnv* jni_env, jobject, jstring conn_id_jstring, jobject ibinder) { jboolean isCopy; const char* conn_id = jni_env->GetStringUTFChars(conn_id_jstring, &isCopy); - gpr_log(GPR_INFO, "%s invoked with conn_id = %s", __func__, conn_id); + LOG(INFO) << __func__ << " invoked with conn_id = " << conn_id; CHECK_NE(ibinder, nullptr); grpc_binder::ndk_util::SpAIBinder aibinder = grpc_binder::FromJavaBinder(jni_env, ibinder); - gpr_log(GPR_INFO, "%s got aibinder = %p", __func__, aibinder.get()); + LOG(INFO) << __func__ << " got aibinder = " << aibinder.get(); auto b = std::make_unique(aibinder); CHECK(b != nullptr); grpc_binder::GetEndpointBinderPool()->AddEndpointBinder(conn_id, @@ -58,7 +59,7 @@ namespace grpc_binder { void EndpointBinderPool::GetEndpointBinder( std::string conn_id, std::function)> cb) { - gpr_log(GPR_INFO, "EndpointBinder requested. conn_id = %s", conn_id.c_str()); + LOG(INFO) << "EndpointBinder requested. conn_id = " << conn_id; std::unique_ptr b; { grpc_core::MutexLock l(&m_); @@ -68,9 +69,8 @@ void EndpointBinderPool::GetEndpointBinder( CHECK(b != nullptr); } else { if (pending_requests_.count(conn_id) != 0) { - gpr_log(GPR_ERROR, - "Duplicate GetEndpointBinder requested. conn_id = %s", - conn_id.c_str()); + LOG(ERROR) << "Duplicate GetEndpointBinder requested. conn_id = " + << conn_id; return; } pending_requests_[conn_id] = std::move(cb); @@ -83,15 +83,14 @@ void EndpointBinderPool::GetEndpointBinder( void EndpointBinderPool::AddEndpointBinder( std::string conn_id, std::unique_ptr b) { - gpr_log(GPR_INFO, "EndpointBinder added. conn_id = %s", conn_id.c_str()); + LOG(INFO) << "EndpointBinder added. conn_id = " << conn_id; CHECK(b != nullptr); // cb will be set in the following block if there is a pending callback std::function)> cb = nullptr; { grpc_core::MutexLock l(&m_); if (binder_map_.count(conn_id) != 0) { - gpr_log(GPR_ERROR, "EndpointBinder already in the pool. conn_id = %s", - conn_id.c_str()); + LOG(ERROR) << "EndpointBinder already in the pool. conn_id = " << conn_id; return; } if (pending_requests_.count(conn_id)) { diff --git a/src/core/ext/transport/binder/client/jni_utils.cc b/src/core/ext/transport/binder/client/jni_utils.cc index 9255b7f1d17..1133604a175 100644 --- a/src/core/ext/transport/binder/client/jni_utils.cc +++ b/src/core/ext/transport/binder/client/jni_utils.cc @@ -15,6 +15,7 @@ #include "src/core/ext/transport/binder/client/jni_utils.h" #include "absl/log/check.h" +#include "absl/log/log.h" // IWYU pragma: keep #include @@ -83,7 +84,7 @@ void TryEstablishConnection(JNIEnv* env, jobject application, jmethodID mid = env->GetStaticMethodID(cl, method.c_str(), type.c_str()); if (mid == nullptr) { - gpr_log(GPR_ERROR, "No method id %s", method.c_str()); + LOG(ERROR) << "No method id " << method; } env->CallStaticVoidMethod(cl, mid, application, @@ -107,7 +108,7 @@ void TryEstablishConnectionWithUri(JNIEnv* env, jobject application, jmethodID mid = env->GetStaticMethodID(cl, method.c_str(), type.c_str()); if (mid == nullptr) { - gpr_log(GPR_ERROR, "No method id %s", method.c_str()); + LOG(ERROR) << "No method id " << method; } env->CallStaticVoidMethod(cl, mid, application, @@ -126,7 +127,7 @@ bool IsSignatureMatch(JNIEnv* env, jobject context, int uid1, int uid2) { jmethodID mid = env->GetStaticMethodID(cl, method.c_str(), type.c_str()); if (mid == nullptr) { - gpr_log(GPR_ERROR, "No method id %s", method.c_str()); + LOG(ERROR) << "No method id " << method; } jboolean result = env->CallStaticBooleanMethod(cl, mid, context, uid1, uid2); diff --git a/src/core/ext/transport/binder/server/binder_server.cc b/src/core/ext/transport/binder/server/binder_server.cc index faf1641d7d1..6f4d932f436 100644 --- a/src/core/ext/transport/binder/server/binder_server.cc +++ b/src/core/ext/transport/binder/server/binder_server.cc @@ -160,7 +160,7 @@ class BinderServerListener : public Server::ListenerInterface { on_destroy_done_ = on_destroy_done; } - void Orphan() override { delete this; } + void Orphan() override { Unref(); } ~BinderServerListener() override { ExecCtx::Get()->Flush(); @@ -240,9 +240,8 @@ bool AddBinderPort(const std::string& addr, grpc_server* server, } std::string conn_id = addr.substr(kBinderUriScheme.size()); Server* core_server = Server::FromC(server); - core_server->AddListener( - OrphanablePtr(new BinderServerListener( - core_server, conn_id, std::move(factory), security_policy))); + core_server->AddListener(MakeOrphanable( + core_server, conn_id, std::move(factory), security_policy)); return true; } diff --git a/src/core/ext/transport/binder/transport/binder_transport.cc b/src/core/ext/transport/binder/transport/binder_transport.cc index b5e32e913b7..7c832505d9d 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 { @@ -296,7 +297,7 @@ static void recv_trailing_metadata_locked(void* arg, // Append status to metadata // TODO(b/192208695): See if we can avoid to manually put status // code into the header - gpr_log(GPR_INFO, "status = %d", args->status); + LOG(INFO) << "status = " << args->status; stream->recv_trailing_metadata->Set( grpc_core::GrpcStatusMetadata(), static_cast(args->status)); @@ -349,7 +350,7 @@ class MetadataEncoder { } void Encode(grpc_core::GrpcStatusMetadata, grpc_status_code status) { - gpr_log(GPR_INFO, "send trailing metadata status = %d", status); + LOG(INFO) << "send trailing metadata status = " << status; tx_->SetStatus(status); } @@ -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); @@ -394,7 +395,7 @@ static void perform_stream_op_locked(void* stream_op, CHECK(!op->send_initial_metadata && !op->send_message && !op->send_trailing_metadata && !op->recv_initial_metadata && !op->recv_message && !op->recv_trailing_metadata); - gpr_log(GPR_INFO, "cancel_stream is_client = %d", stream->is_client); + LOG(INFO) << "cancel_stream is_client = " << stream->is_client; if (!stream->is_client) { // Send trailing metadata to inform the other end about the cancellation, // regardless if we'd already done that or not. @@ -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/utils/ndk_binder.cc b/src/core/ext/transport/binder/utils/ndk_binder.cc index 1c0ae278ac4..08b0c824cb8 100644 --- a/src/core/ext/transport/binder/utils/ndk_binder.cc +++ b/src/core/ext/transport/binder/utils/ndk_binder.cc @@ -23,6 +23,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include @@ -60,10 +61,10 @@ void SetJvm(JNIEnv* env) { JavaVM* jvm = nullptr; jint error = env->GetJavaVM(&jvm); if (error != JNI_OK) { - gpr_log(GPR_ERROR, "Failed to get JVM"); + LOG(ERROR) << "Failed to get JVM"; } g_jvm = jvm; - gpr_log(GPR_INFO, "JVM cached"); + LOG(INFO) << "JVM cached"; } // `SetJvm` need to be called in the process before `AttachJvm`. This is always @@ -77,14 +78,14 @@ bool AttachJvm() { // Note: The following code would be run at most once per thread. grpc_core::MutexLock lock(&g_jvm_mu); if (g_jvm == nullptr) { - gpr_log(GPR_ERROR, "JVM not cached yet"); + LOG(ERROR) << "JVM not cached yet"; return false; } JNIEnv* env_unused; // Note that attach a thread that is already attached is a no-op, so it is // fine to call this again if the thread has already been attached by other. g_jvm->AttachCurrentThread(&env_unused, /* thr_args= */ nullptr); - gpr_log(GPR_INFO, "JVM attached successfully"); + LOG(INFO) << "JVM attached successfully"; g_is_jvm_attached = true; return true; } @@ -151,7 +152,7 @@ binder_status_t AIBinder_transact(AIBinder* binder, transaction_code_t code, AParcel** in, AParcel** out, binder_flags_t flags) { if (!AttachJvm()) { - gpr_log(GPR_ERROR, "failed to attach JVM. AIBinder_transact might fail."); + LOG(ERROR) << "failed to attach JVM. AIBinder_transact might fail."; } FORWARD(AIBinder_transact)(binder, code, in, out, flags); } diff --git a/src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc b/src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc index 7005a59aa6e..9546109aa61 100644 --- a/src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc +++ b/src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc @@ -23,8 +23,7 @@ #include #include "absl/log/check.h" - -#include +#include "absl/log/log.h" #include "src/core/lib/gprpp/crash.h" @@ -36,7 +35,7 @@ const absl::string_view void TransportStreamReceiverImpl::RegisterRecvInitialMetadata( StreamIdentifier id, InitialMetadataCallbackType cb) { - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; absl::StatusOr initial_metadata{}; { grpc_core::MutexLock l(&m_); @@ -64,7 +63,7 @@ void TransportStreamReceiverImpl::RegisterRecvInitialMetadata( void TransportStreamReceiverImpl::RegisterRecvMessage( StreamIdentifier id, MessageDataCallbackType cb) { - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; absl::StatusOr message{}; { grpc_core::MutexLock l(&m_); @@ -98,7 +97,7 @@ void TransportStreamReceiverImpl::RegisterRecvMessage( void TransportStreamReceiverImpl::RegisterRecvTrailingMetadata( StreamIdentifier id, TrailingMetadataCallbackType cb) { - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; std::pair, int> trailing_metadata{}; { grpc_core::MutexLock l(&m_); @@ -122,7 +121,7 @@ void TransportStreamReceiverImpl::RegisterRecvTrailingMetadata( void TransportStreamReceiverImpl::NotifyRecvInitialMetadata( StreamIdentifier id, absl::StatusOr initial_metadata) { - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; if (!is_client_ && accept_stream_callback_ && initial_metadata.ok()) { accept_stream_callback_(); } @@ -143,7 +142,7 @@ void TransportStreamReceiverImpl::NotifyRecvInitialMetadata( void TransportStreamReceiverImpl::NotifyRecvMessage( StreamIdentifier id, absl::StatusOr message) { - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; MessageDataCallbackType cb; { grpc_core::MutexLock l(&m_); @@ -166,7 +165,7 @@ void TransportStreamReceiverImpl::NotifyRecvTrailingMetadata( // assumes in-order commitments of transactions and that trailing metadata is // parsed after message data, we can safely cancel all upcoming callbacks of // recv_message. - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; OnRecvTrailingMetadata(id); TrailingMetadataCallbackType cb; { @@ -233,7 +232,7 @@ void TransportStreamReceiverImpl::CancelTrailingMetadataCallback( } void TransportStreamReceiverImpl::OnRecvTrailingMetadata(StreamIdentifier id) { - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; m_.Lock(); trailing_metadata_recvd_.insert(id); m_.Unlock(); @@ -245,7 +244,7 @@ void TransportStreamReceiverImpl::OnRecvTrailingMetadata(StreamIdentifier id) { } void TransportStreamReceiverImpl::CancelStream(StreamIdentifier id) { - gpr_log(GPR_INFO, "%s id = %d is_client = %d", __func__, id, is_client_); + LOG(INFO) << __func__ << " id = " << id << " is_client = " << is_client_; CancelInitialMetadataCallback(id, absl::CancelledError("Stream cancelled")); CancelMessageCallback(id, absl::CancelledError("Stream cancelled")); CancelTrailingMetadataCallback(id, absl::CancelledError("Stream cancelled")); diff --git a/src/core/ext/transport/binder/wire_format/binder_android.cc b/src/core/ext/transport/binder/wire_format/binder_android.cc index fc816447c59..6ca9b6dcecd 100644 --- a/src/core/ext/transport/binder/wire_format/binder_android.cc +++ b/src/core/ext/transport/binder/wire_format/binder_android.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" @@ -65,7 +66,7 @@ ndk_util::binder_status_t f_onTransact(ndk_util::AIBinder* binder, const ndk_util::AParcel* in, ndk_util::AParcel* /*out*/) { gpr_log(GPR_INFO, __func__); - gpr_log(GPR_INFO, "tx code = %u", code); + LOG(INFO) << "tx code = " << code; auto* user_data = static_cast(ndk_util::AIBinder_getUserData(binder)); @@ -79,7 +80,7 @@ ndk_util::binder_status_t f_onTransact(ndk_util::AIBinder* binder, if (status.ok()) { return ndk_util::STATUS_OK; } else { - gpr_log(GPR_ERROR, "Callback failed: %s", status.ToString().c_str()); + LOG(ERROR) << "Callback failed: " << status.ToString(); return ndk_util::STATUS_UNKNOWN_ERROR; } } 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/binder/wire_format/wire_writer.cc b/src/core/ext/transport/binder/wire_format/wire_writer.cc index f81d1d6172f..6379bd17ff4 100644 --- a/src/core/ext/transport/binder/wire_format/wire_writer.cc +++ b/src/core/ext/transport/binder/wire_format/wire_writer.cc @@ -22,6 +22,7 @@ #include "absl/cleanup/cleanup.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/types/variant.h" #include @@ -78,7 +79,7 @@ absl::Status WriteTrailingMetadata(const Transaction& tx, } else { // client suffix currently is always empty according to the wireformat if (!tx.GetSuffixMetadata().empty()) { - gpr_log(GPR_ERROR, "Got non-empty suffix metadata from client."); + LOG(ERROR) << "Got non-empty suffix metadata from client."; } } return absl::OkStatus(); @@ -218,8 +219,7 @@ void WireWriterImpl::RunScheduledTxInternal(RunScheduledTxArgs* args) { return absl::OkStatus(); }); if (!result.ok()) { - gpr_log(GPR_ERROR, "Failed to make binder transaction %s", - result.ToString().c_str()); + LOG(ERROR) << "Failed to make binder transaction " << result; } delete args; return; @@ -242,8 +242,7 @@ void WireWriterImpl::RunScheduledTxInternal(RunScheduledTxArgs* args) { if (CanBeSentInOneTransaction(*stream_tx->tx.get())) { // NOLINT absl::Status result = RpcCallFastPath(std::move(stream_tx->tx)); if (!result.ok()) { - gpr_log(GPR_ERROR, "Failed to handle non-chunked RPC call %s", - result.ToString().c_str()); + LOG(ERROR) << "Failed to handle non-chunked RPC call " << result; } delete args; return; @@ -256,8 +255,7 @@ void WireWriterImpl::RunScheduledTxInternal(RunScheduledTxArgs* args) { return RunStreamTx(stream_tx, parcel, &is_last_chunk); }); if (!result.ok()) { - gpr_log(GPR_ERROR, "Failed to make binder transaction %s", - result.ToString().c_str()); + LOG(ERROR) << "Failed to make binder transaction " << result; } if (!is_last_chunk) { { @@ -290,7 +288,7 @@ absl::Status WireWriterImpl::SendAck(int64_t num_bytes) { // Ensure combiner will be run if this is not called from top-level gRPC API // entrypoint. grpc_core::ExecCtx exec_ctx; - gpr_log(GPR_INFO, "Ack %" PRId64 " bytes received", num_bytes); + LOG(INFO) << "Ack " << num_bytes << " bytes received"; if (is_transacting_) { // This can happen because NDK might call our registered callback function // in the same thread while we are telling it to send a transaction @@ -298,10 +296,8 @@ absl::Status WireWriterImpl::SendAck(int64_t num_bytes) { // the same thread or the other thread. We are currently in the call stack // of other transaction, Liveness of ACK is still guaranteed even if this is // a race with another thread. - gpr_log( - GPR_INFO, - "Scheduling ACK transaction instead of directly execute it to avoid " - "deadlock."); + LOG(INFO) << "Scheduling ACK transaction instead of directly execute it to " + "avoid deadlock."; auto args = new RunScheduledTxArgs(); args->writer = this; args->tx = RunScheduledTxArgs::AckTx(); @@ -318,8 +314,7 @@ absl::Status WireWriterImpl::SendAck(int64_t num_bytes) { return absl::OkStatus(); }); if (!result.ok()) { - gpr_log(GPR_ERROR, "Failed to make binder transaction %s", - result.ToString().c_str()); + LOG(ERROR) << "Failed to make binder transaction " << result; } return result; } @@ -328,7 +323,7 @@ void WireWriterImpl::OnAckReceived(int64_t num_bytes) { // Ensure combiner will be run if this is not called from top-level gRPC API // entrypoint. grpc_core::ExecCtx exec_ctx; - gpr_log(GPR_INFO, "OnAckReceived %" PRId64, num_bytes); + LOG(INFO) << "OnAckReceived " << num_bytes; // Do not try to obtain `write_mu_` in this function. NDKBinder might invoke // the callback to notify us about new incoming binder transaction when we are // sending transaction. i.e. `write_mu_` might have already been acquired by diff --git a/src/core/ext/transport/chaotic_good/server/chaotic_good_server.cc b/src/core/ext/transport/chaotic_good/server/chaotic_good_server.cc index e00bcc1b379..8af652a292c 100644 --- a/src/core/ext/transport/chaotic_good/server/chaotic_good_server.cc +++ b/src/core/ext/transport/chaotic_good/server/chaotic_good_server.cc @@ -22,6 +22,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/random/bit_gen_ref.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -99,12 +100,12 @@ absl::StatusOr ChaoticGoodServerListener::Bind( grpc_event_engine::experimental::EventEngine::ResolvedAddress addr) { if (grpc_chaotic_good_trace.enabled()) { auto str = grpc_event_engine::experimental::ResolvedAddressToString(addr); - gpr_log(GPR_INFO, "CHAOTIC_GOOD: Listen on %s", - str.ok() ? str->c_str() : str.status().ToString().c_str()); + LOG(INFO) << "CHAOTIC_GOOD: Listen on " + << (str.ok() ? str->c_str() : str.status().ToString()); } EventEngine::Listener::AcceptCallback accept_cb = - [self = Ref()](std::unique_ptr ep, - MemoryAllocator) { + [self = RefAsSubclass()]( + std::unique_ptr ep, MemoryAllocator) { ExecCtx exec_ctx; MutexLock lock(&self->mu_); if (self->shutdown_) return; @@ -123,8 +124,7 @@ absl::StatusOr ChaoticGoodServerListener::Bind( grpc_event_engine::experimental::ChannelArgsEndpointConfig(args_), std::make_unique("chaotic_good_server_listener")); if (!ee_listener.ok()) { - gpr_log(GPR_ERROR, "Bind failed: %s", - ee_listener.status().ToString().c_str()); + LOG(ERROR) << "Bind failed: " << ee_listener.status().ToString(); return ee_listener.status(); } ee_listener_ = std::move(ee_listener.value()); @@ -139,9 +139,9 @@ absl::Status ChaoticGoodServerListener::StartListening() { CHECK(ee_listener_ != nullptr); auto status = ee_listener_->Start(); if (!status.ok()) { - gpr_log(GPR_ERROR, "Start listening failed: %s", status.ToString().c_str()); + LOG(ERROR) << "Start listening failed: " << status.ToString(); } else if (grpc_chaotic_good_trace.enabled()) { - gpr_log(GPR_INFO, "CHAOTIC_GOOD: Started listening"); + LOG(INFO) << "CHAOTIC_GOOD: Started listening"; } return status; } @@ -149,7 +149,8 @@ absl::Status ChaoticGoodServerListener::StartListening() { ChaoticGoodServerListener::ActiveConnection::ActiveConnection( RefCountedPtr listener, std::unique_ptr endpoint) - : memory_allocator_(listener->memory_allocator_), listener_(listener) { + : memory_allocator_(listener->memory_allocator_), + listener_(std::move(listener)) { handshaking_state_ = MakeRefCounted(Ref()); handshaking_state_->Start(std::move(endpoint)); } @@ -160,7 +161,7 @@ ChaoticGoodServerListener::ActiveConnection::~ActiveConnection() { void ChaoticGoodServerListener::ActiveConnection::Orphan() { if (grpc_chaotic_good_trace.enabled()) { - gpr_log(GPR_INFO, "ActiveConnection::Orphan() %p", this); + LOG(INFO) << "ActiveConnection::Orphan() " << this; } if (handshaking_state_ != nullptr) { handshaking_state_->Shutdown(); @@ -192,8 +193,7 @@ void ChaoticGoodServerListener::ActiveConnection::NewConnectionID() { void ChaoticGoodServerListener::ActiveConnection::Done( absl::optional error) { if (error.has_value()) { - gpr_log(GPR_ERROR, "ActiveConnection::Done:%p %s", this, - std::string(*error).c_str()); + LOG(ERROR) << "ActiveConnection::Done:" << this << " " << *error; } // Can easily be holding various locks here: bounce through EE to ensure no // deadlocks. @@ -458,7 +458,7 @@ Timestamp ChaoticGoodServerListener::ActiveConnection::HandshakingState:: void ChaoticGoodServerListener::Orphan() { if (grpc_chaotic_good_trace.enabled()) { - gpr_log(GPR_INFO, "ChaoticGoodServerListener::Orphan()"); + LOG(INFO) << "ChaoticGoodServerListener::Orphan()"; } { absl::flat_hash_set> connection_list; @@ -480,8 +480,8 @@ int grpc_server_add_chaotic_good_port(grpc_server* server, const char* addr) { const auto resolved_or = grpc_core::GetDNSResolver()->LookupHostnameBlocking( parsed_addr, absl::StrCat(0xd20)); if (!resolved_or.ok()) { - gpr_log(GPR_ERROR, "Failed to resolve %s: %s", addr, - resolved_or.status().ToString().c_str()); + LOG(ERROR) << "Failed to resolve " << addr << ": " + << resolved_or.status().ToString(); return 0; } int port_num = 0; @@ -496,8 +496,8 @@ int grpc_server_add_chaotic_good_port(grpc_server* server, const char* addr) { ->c_str()); auto bind_result = listener->Bind(ee_addr); if (!bind_result.ok()) { - gpr_log(GPR_ERROR, "Failed to bind to %s: %s", addr, - bind_result.status().ToString().c_str()); + LOG(ERROR) << "Failed to bind to " << addr << ": " + << bind_result.status().ToString(); return 0; } if (port_num == 0) { diff --git a/src/core/ext/transport/chaotic_good/server/chaotic_good_server.h b/src/core/ext/transport/chaotic_good/server/chaotic_good_server.h index 404bbbf946d..0479016c15b 100644 --- a/src/core/ext/transport/chaotic_good/server/chaotic_good_server.h +++ b/src/core/ext/transport/chaotic_good/server/chaotic_good_server.h @@ -49,9 +49,7 @@ namespace grpc_core { namespace chaotic_good { -class ChaoticGoodServerListener final - : public Server::ListenerInterface, - public RefCounted { +class ChaoticGoodServerListener final : public Server::ListenerInterface { public: static absl::AnyInvocable DefaultConnectionIDGenerator() { return [bitgen = absl::BitGen()]() mutable { diff --git a/src/core/ext/transport/chaotic_good/server_transport.cc b/src/core/ext/transport/chaotic_good/server_transport.cc index c139c6e44e0..98fbf4e915e 100644 --- a/src/core/ext/transport/chaotic_good/server_transport.cc +++ b/src/core/ext/transport/chaotic_good/server_transport.cc @@ -235,37 +235,27 @@ auto ChaoticGoodServerTransport::DeserializeAndPushFragmentToNewCall( FrameHeader frame_header, BufferPair buffers, ChaoticGoodTransport& transport) { ClientFragmentFrame fragment_frame; - ScopedArenaPtr arena(acceptor_->CreateArena()); + ScopedArenaPtr arena(call_arena_allocator_->MakeArena()); absl::Status status = transport.DeserializeFrame( frame_header, std::move(buffers), arena.get(), fragment_frame, FrameLimits{1024 * 1024 * 1024, aligned_bytes_ - 1}); absl::optional call_initiator; if (status.ok()) { - auto create_call_result = acceptor_->CreateCall( - std::move(fragment_frame.headers), arena.release()); - if (grpc_chaotic_good_trace.enabled()) { - gpr_log(GPR_INFO, - "CHAOTIC_GOOD: DeserializeAndPushFragmentToNewCall: " - "create_call_result=%s", - create_call_result.ok() - ? "ok" - : create_call_result.status().ToString().c_str()); - } - if (create_call_result.ok()) { - call_initiator.emplace(std::move(*create_call_result)); - auto add_result = NewStream(frame_header.stream_id, *call_initiator); - if (add_result.ok()) { - call_initiator->SpawnGuarded( - "server-write", [this, stream_id = frame_header.stream_id, - call_initiator = *call_initiator]() { - return CallOutboundLoop(stream_id, call_initiator); - }); - } else { - call_initiator.reset(); - status = add_result; - } + auto call = + MakeCallPair(std::move(fragment_frame.headers), event_engine_.get(), + arena.release(), call_arena_allocator_, nullptr); + call_initiator.emplace(std::move(call.initiator)); + auto add_result = NewStream(frame_header.stream_id, *call_initiator); + if (add_result.ok()) { + call_destination_->StartCall(std::move(call.handler)); + call_initiator->SpawnGuarded( + "server-write", [this, stream_id = frame_header.stream_id, + call_initiator = *call_initiator]() { + return CallOutboundLoop(stream_id, call_initiator); + }); } else { - status = create_call_result.status(); + call_initiator.reset(); + status = add_result; } } return MaybePushFragmentIntoCall(std::move(call_initiator), std::move(status), @@ -366,10 +356,13 @@ ChaoticGoodServerTransport::ChaoticGoodServerTransport( PromiseEndpoint data_endpoint, std::shared_ptr event_engine, HPackParser hpack_parser, HPackCompressor hpack_encoder) - : outgoing_frames_(4), - allocator_(args.GetObject() - ->memory_quota() - ->CreateMemoryAllocator("chaotic-good")) { + : call_arena_allocator_(MakeRefCounted( + args.GetObject() + ->memory_quota() + ->CreateMemoryAllocator("chaotic-good"), + 1024)), + event_engine_(event_engine), + outgoing_frames_(4) { auto transport = MakeRefCounted( std::move(control_endpoint), std::move(data_endpoint), std::move(hpack_parser), std::move(hpack_encoder)); @@ -381,20 +374,25 @@ ChaoticGoodServerTransport::ChaoticGoodServerTransport( OnTransportActivityDone("reader")); } -void ChaoticGoodServerTransport::SetAcceptor(Acceptor* acceptor) { - CHECK_EQ(acceptor_, nullptr); - CHECK_NE(acceptor, nullptr); - acceptor_ = acceptor; +void ChaoticGoodServerTransport::SetCallDestination( + RefCountedPtr call_destination) { + CHECK(call_destination_ == nullptr); + CHECK(call_destination != nullptr); + call_destination_ = call_destination; got_acceptor_.Set(); } -ChaoticGoodServerTransport::~ChaoticGoodServerTransport() { - if (writer_ != nullptr) { - writer_.reset(); - } - if (reader_ != nullptr) { - reader_.reset(); +void ChaoticGoodServerTransport::Orphan() { + ActivityPtr writer; + ActivityPtr reader; + { + MutexLock lock(&mu_); + writer = std::move(writer_); + reader = std::move(reader_); } + writer.reset(); + reader.reset(); + Unref(); } void ChaoticGoodServerTransport::AbortWithError() { diff --git a/src/core/ext/transport/chaotic_good/server_transport.h b/src/core/ext/transport/chaotic_good/server_transport.h index a34ac92b73e..140641abcf6 100644 --- a/src/core/ext/transport/chaotic_good/server_transport.h +++ b/src/core/ext/transport/chaotic_good/server_transport.h @@ -86,7 +86,6 @@ class ChaoticGoodServerTransport final : public ServerTransport { std::shared_ptr event_engine, HPackParser hpack_parser, HPackCompressor hpack_encoder); - ~ChaoticGoodServerTransport() override; FilterStackTransport* filter_stack_transport() override { return nullptr; } ClientTransport* client_transport() override { return nullptr; } @@ -96,9 +95,10 @@ class ChaoticGoodServerTransport final : public ServerTransport { void SetPollsetSet(grpc_stream*, grpc_pollset_set*) override {} void PerformOp(grpc_transport_op*) override; grpc_endpoint* GetEndpoint() override { return nullptr; } - void Orphan() override { Unref(); } + void Orphan() override; - void SetAcceptor(Acceptor* acceptor) override; + void SetCallDestination( + RefCountedPtr call_destination) override; void AbortWithError(); private: @@ -137,7 +137,10 @@ class ChaoticGoodServerTransport final : public ServerTransport { auto PushFragmentIntoCall(CallInitiator call_initiator, ClientFragmentFrame frame, uint32_t stream_id); - Acceptor* acceptor_ = nullptr; + RefCountedPtr call_destination_; + const RefCountedPtr call_arena_allocator_; + const std::shared_ptr + event_engine_; InterActivityLatch got_acceptor_; MpscReceiver outgoing_frames_; // Assigned aligned bytes from setting frame. @@ -146,7 +149,6 @@ class ChaoticGoodServerTransport final : public ServerTransport { // Map of stream incoming server frames, key is stream_id. StreamMap stream_map_ ABSL_GUARDED_BY(mu_); uint32_t last_seen_new_stream_id_ = 0; - grpc_event_engine::experimental::MemoryAllocator allocator_; ActivityPtr writer_ ABSL_GUARDED_BY(mu_); ActivityPtr reader_ ABSL_GUARDED_BY(mu_); ConnectivityStateTracker state_tracker_ ABSL_GUARDED_BY(mu_){ diff --git a/src/core/ext/transport/chttp2/alpn/alpn.cc b/src/core/ext/transport/chttp2/alpn/alpn.cc index 70f576a4448..cb9c2d6e34d 100644 --- a/src/core/ext/transport/chttp2/alpn/alpn.cc +++ b/src/core/ext/transport/chttp2/alpn/alpn.cc @@ -23,7 +23,7 @@ #include #include -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" // in order of preference static const char* const supported_versions[] = {"h2"}; diff --git a/src/core/ext/transport/chttp2/client/chttp2_connector.cc b/src/core/ext/transport/chttp2/client/chttp2_connector.cc index 2d64d03e4ff..37f1a565736 100644 --- a/src/core/ext/transport/chttp2/client/chttp2_connector.cc +++ b/src/core/ext/transport/chttp2/client/chttp2_connector.cc @@ -25,6 +25,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" @@ -311,7 +312,7 @@ class Chttp2SecureClientChannelFactory : public ClientChannelFactory { absl::StatusOr> CreateChannel(const char* target, const ChannelArgs& args) { if (target == nullptr) { - gpr_log(GPR_ERROR, "cannot create channel with NULL target name"); + LOG(ERROR) << "cannot create channel with NULL target name"; return absl::InvalidArgumentError("channel target is NULL"); } return ChannelCreate(target, args, GRPC_CLIENT_CHANNEL, nullptr); diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index 9b7770e4930..3388e234fd9 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -30,6 +30,7 @@ #include "absl/base/thread_annotations.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" @@ -42,9 +43,9 @@ #include #include #include +#include #include #include -#include #include #include "src/core/channelz/channelz.h" @@ -58,6 +59,8 @@ #include "src/core/lib/config/core_configuration.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/event_engine/channel_args_endpoint_config.h" +#include "src/core/lib/event_engine/extensions/supports_fd.h" +#include "src/core/lib/event_engine/query_extensions.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -67,6 +70,7 @@ #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/endpoint.h" +#include "src/core/lib/iomgr/event_engine_shims/endpoint.h" #include "src/core/lib/iomgr/iomgr_fwd.h" #include "src/core/lib/iomgr/pollset_set.h" #include "src/core/lib/iomgr/resolve_address.h" @@ -93,9 +97,11 @@ #endif // GPR_SUPPORT_CHANNELS_FROM_FD namespace grpc_core { -namespace { -using ::grpc_event_engine::experimental::EventEngine; +using grpc_event_engine::experimental::ChannelArgsEndpointConfig; +using grpc_event_engine::experimental::EventEngine; +using grpc_event_engine::experimental::EventEngineSupportsFdExtension; +using grpc_event_engine::experimental::QueryExtension; const char kUnixUriPrefix[] = "unix:"; const char kUnixAbstractUriPrefix[] = "unix-abstract:"; @@ -112,14 +118,23 @@ class Chttp2ServerListener : public Server::ListenerInterface { Server* server, const char* name, const ChannelArgs& args, Chttp2ServerArgsModifier args_modifier); + static Chttp2ServerListener* CreateForPassiveListener( + Server* server, const ChannelArgs& args, + std::shared_ptr passive_listener); + // Do not instantiate directly. Use one of the factory methods above. Chttp2ServerListener(Server* server, const ChannelArgs& args, - Chttp2ServerArgsModifier args_modifier); + Chttp2ServerArgsModifier args_modifier, + grpc_server_config_fetcher* config_fetcher, + std::shared_ptr + passive_listener = nullptr); ~Chttp2ServerListener() override; void Start(Server* server, const std::vector* pollsets) override; + void AcceptConnectedEndpoint(std::unique_ptr endpoint); + channelz::ListenSocketNode* channelz_listen_socket_node() const override { return channelz_listen_socket_.get(); } @@ -129,6 +144,8 @@ class Chttp2ServerListener : public Server::ListenerInterface { void Orphan() override; private: + friend class experimental::PassiveListenerImpl; + class ConfigFetcherWatcher : public grpc_server_config_fetcher::WatcherInterface { public: @@ -235,34 +252,8 @@ class Chttp2ServerListener : public Server::ListenerInterface { static void DestroyListener(Server* /*server*/, void* arg, grpc_closure* destroy_done); - // The interface required by RefCountedPtr<> has been manually implemented - // here to take a ref on tcp_server_ instead. Note that, the handshaker - // needs tcp_server_ to exist for the lifetime of the handshake since it's - // needed by acceptor. Sharing refs between the listener and tcp_server_ is - // just an optimization to avoid taking additional refs on the listener, - // since TcpServerShutdownComplete already holds a ref to the listener. - void IncrementRefCount() { grpc_tcp_server_ref(tcp_server_); } - void IncrementRefCount(const DebugLocation& /* location */, - const char* /* reason */) { - IncrementRefCount(); - } - - GRPC_MUST_USE_RESULT RefCountedPtr Ref() { - IncrementRefCount(); - return RefCountedPtr(this); - } - GRPC_MUST_USE_RESULT RefCountedPtr Ref( - const DebugLocation& /* location */, const char* /* reason */) { - return Ref(); - } - - void Unref() { grpc_tcp_server_unref(tcp_server_); } - void Unref(const DebugLocation& /* location */, const char* /* reason */) { - Unref(); - } - - Server* const server_; - grpc_tcp_server* tcp_server_; + Server* const server_ = nullptr; + grpc_tcp_server* tcp_server_ = nullptr; grpc_resolved_address resolved_address_; Chttp2ServerArgsModifier const args_modifier_; ConfigFetcherWatcher* config_fetcher_watcher_ = nullptr; @@ -285,6 +276,10 @@ class Chttp2ServerListener : public Server::ListenerInterface { RefCountedPtr channelz_listen_socket_; MemoryQuotaRefPtr memory_quota_; ConnectionQuotaRefPtr connection_quota_; + grpc_server_config_fetcher* config_fetcher_ = nullptr; + // TODO(yashykt): consider using absl::variant<> to minimize memory usage for + // disjoint cases where different fields are used. + std::shared_ptr passive_listener_; }; // @@ -331,8 +326,7 @@ void Chttp2ServerListener::ConfigFetcherWatcher::UpdateConnectionManager( grpc_error_handle error = grpc_tcp_server_add_port( listener_->tcp_server_, &listener_->resolved_address_, &port_temp); if (!error.ok()) { - gpr_log(GPR_ERROR, "Error adding port to server: %s", - StatusToString(error).c_str()); + LOG(ERROR) << "Error adding port to server: " << StatusToString(error); // TODO(yashykt): We wouldn't need to assert here if we bound to the // port earlier during AddPort. CHECK(0); @@ -381,13 +375,17 @@ Chttp2ServerListener::ActiveConnection::HandshakingState::HandshakingState( handshake_mgr_(MakeRefCounted()), deadline_(GetConnectionDeadline(args)), interested_parties_(grpc_pollset_set_create()) { - grpc_pollset_set_add_pollset(interested_parties_, accepting_pollset_); + if (accepting_pollset != nullptr) { + grpc_pollset_set_add_pollset(interested_parties_, accepting_pollset_); + } CoreConfiguration::Get().handshaker_registry().AddHandshakers( HANDSHAKER_SERVER, args, interested_parties_, handshake_mgr_.get()); } Chttp2ServerListener::ActiveConnection::HandshakingState::~HandshakingState() { - grpc_pollset_set_del_pollset(interested_parties_, accepting_pollset_); + if (accepting_pollset_ != nullptr) { + grpc_pollset_set_del_pollset(interested_parties_, accepting_pollset_); + } grpc_pollset_set_destroy(interested_parties_); gpr_free(acceptor_); } @@ -536,8 +534,8 @@ void Chttp2ServerListener::ActiveConnection::HandshakingState::OnHandshakeDone( }); } else { // Failed to create channel from transport. Clean up. - gpr_log(GPR_ERROR, "Failed to create channel: %s", - StatusToString(channel_init_err).c_str()); + LOG(ERROR) << "Failed to create channel: " + << StatusToString(channel_init_err); transport->Orphan(); grpc_slice_buffer_destroy(args->read_buffer); gpr_free(args->read_buffer); @@ -589,7 +587,11 @@ Chttp2ServerListener::ActiveConnection::ActiveConnection( grpc_schedule_on_exec_ctx); } -Chttp2ServerListener::ActiveConnection::~ActiveConnection() {} +Chttp2ServerListener::ActiveConnection::~ActiveConnection() { + if (listener_ != nullptr && listener_->tcp_server_ != nullptr) { + grpc_tcp_server_unref(listener_->tcp_server_); + } +} void Chttp2ServerListener::ActiveConnection::Orphan() { OrphanablePtr handshaking_state; @@ -637,6 +639,9 @@ void Chttp2ServerListener::ActiveConnection::Start( const ChannelArgs& args) { RefCountedPtr handshaking_state_ref; listener_ = std::move(listener); + if (listener_->tcp_server_ != nullptr) { + grpc_tcp_server_ref(listener_->tcp_server_); + } { ReleasableMutexLock lock(&mu_); if (shutdown_) { @@ -709,83 +714,82 @@ void Chttp2ServerListener::ActiveConnection::OnDrainGraceTimeExpiry() { grpc_error_handle Chttp2ServerListener::Create( Server* server, grpc_resolved_address* addr, const ChannelArgs& args, Chttp2ServerArgsModifier args_modifier, int* port_num) { - Chttp2ServerListener* listener = nullptr; - // The bulk of this method is inside of a lambda to make cleanup - // easier without using goto. - grpc_error_handle error = [&]() { - grpc_error_handle error; - // Create Chttp2ServerListener. - listener = new Chttp2ServerListener(server, args, args_modifier); - error = grpc_tcp_server_create( - &listener->tcp_server_shutdown_complete_, - grpc_event_engine::experimental::ChannelArgsEndpointConfig(args), - OnAccept, listener, &listener->tcp_server_); + // Create Chttp2ServerListener. + OrphanablePtr listener = + MakeOrphanable(server, args, args_modifier, + server->config_fetcher()); + // The tcp_server will be unreffed when the listener is orphaned, which could + // be at the end of this function if the listener was not added to the + // server's set of listeners. + grpc_error_handle error = grpc_tcp_server_create( + &listener->tcp_server_shutdown_complete_, ChannelArgsEndpointConfig(args), + OnAccept, listener.get(), &listener->tcp_server_); + if (!error.ok()) return error; + if (listener->config_fetcher_ != nullptr) { + listener->resolved_address_ = *addr; + // TODO(yashykt): Consider binding so as to be able to return the port + // number. + } else { + error = grpc_tcp_server_add_port(listener->tcp_server_, addr, port_num); if (!error.ok()) return error; - if (server->config_fetcher() != nullptr) { - listener->resolved_address_ = *addr; - // TODO(yashykt): Consider binding so as to be able to return the port - // number. - } else { - error = grpc_tcp_server_add_port(listener->tcp_server_, addr, port_num); - if (!error.ok()) return error; - } - // Create channelz node. - if (args.GetBool(GRPC_ARG_ENABLE_CHANNELZ) - .value_or(GRPC_ENABLE_CHANNELZ_DEFAULT)) { - auto string_address = grpc_sockaddr_to_uri(addr); - if (!string_address.ok()) { - return GRPC_ERROR_CREATE(string_address.status().ToString()); - } - listener->channelz_listen_socket_ = - MakeRefCounted( - *string_address, - absl::StrCat("chttp2 listener ", *string_address)); - } - // Register with the server only upon success - server->AddListener(OrphanablePtr(listener)); - return absl::OkStatus(); - }(); - if (!error.ok()) { - if (listener != nullptr) { - if (listener->tcp_server_ != nullptr) { - // listener is deleted when tcp_server_ is shutdown. - grpc_tcp_server_unref(listener->tcp_server_); - } else { - delete listener; - } + } + // Create channelz node. + if (args.GetBool(GRPC_ARG_ENABLE_CHANNELZ) + .value_or(GRPC_ENABLE_CHANNELZ_DEFAULT)) { + auto string_address = grpc_sockaddr_to_uri(addr); + if (!string_address.ok()) { + return GRPC_ERROR_CREATE(string_address.status().ToString()); } + listener->channelz_listen_socket_ = + MakeRefCounted( + *string_address, absl::StrCat("chttp2 listener ", *string_address)); } - return error; + // Register with the server only upon success + server->AddListener(std::move(listener)); + return absl::OkStatus(); } grpc_error_handle Chttp2ServerListener::CreateWithAcceptor( Server* server, const char* name, const ChannelArgs& args, Chttp2ServerArgsModifier args_modifier) { - Chttp2ServerListener* listener = - new Chttp2ServerListener(server, args, args_modifier); + auto listener = MakeOrphanable( + server, args, args_modifier, server->config_fetcher()); grpc_error_handle error = grpc_tcp_server_create( - &listener->tcp_server_shutdown_complete_, - grpc_event_engine::experimental::ChannelArgsEndpointConfig(args), - OnAccept, listener, &listener->tcp_server_); - if (!error.ok()) { - delete listener; - return error; - } + &listener->tcp_server_shutdown_complete_, ChannelArgsEndpointConfig(args), + OnAccept, listener.get(), &listener->tcp_server_); + if (!error.ok()) return error; // TODO(yangg) channelz TcpServerFdHandler** arg_val = args.GetPointer(name); *arg_val = grpc_tcp_server_create_fd_handler(listener->tcp_server_); - server->AddListener(OrphanablePtr(listener)); + server->AddListener(std::move(listener)); return absl::OkStatus(); } +Chttp2ServerListener* Chttp2ServerListener::CreateForPassiveListener( + Server* server, const ChannelArgs& args, + std::shared_ptr passive_listener) { + // TODO(hork): figure out how to handle channelz in this case + auto listener = MakeOrphanable( + server, args, /*args_modifier=*/ + [](const ChannelArgs& args, grpc_error_handle*) { return args; }, nullptr, + std::move(passive_listener)); + auto listener_ptr = listener.get(); + server->AddListener(std::move(listener)); + return listener_ptr; +} + Chttp2ServerListener::Chttp2ServerListener( Server* server, const ChannelArgs& args, - Chttp2ServerArgsModifier args_modifier) + Chttp2ServerArgsModifier args_modifier, + grpc_server_config_fetcher* config_fetcher, + std::shared_ptr passive_listener) : server_(server), args_modifier_(args_modifier), args_(args), memory_quota_(args.GetObject()->memory_quota()), - connection_quota_(MakeRefCounted()) { + connection_quota_(MakeRefCounted()), + config_fetcher_(config_fetcher), + passive_listener_(std::move(passive_listener)) { auto max_allowed_incoming_connections = args.GetInt(GRPC_ARG_MAX_ALLOWED_INCOMING_CONNECTIONS); if (max_allowed_incoming_connections.has_value()) { @@ -800,6 +804,9 @@ Chttp2ServerListener::~Chttp2ServerListener() { // Flush queued work before destroying handshaker factory, since that // may do a synchronous unref. ExecCtx::Get()->Flush(); + if (passive_listener_ != nullptr) { + passive_listener_->ListenerDestroyed(); + } if (on_destroy_done_ != nullptr) { ExecCtx::Run(DEBUG_LOCATION, on_destroy_done_, absl::OkStatus()); ExecCtx::Get()->Flush(); @@ -809,10 +816,11 @@ Chttp2ServerListener::~Chttp2ServerListener() { // Server callback: start listening on our ports void Chttp2ServerListener::Start( Server* /*server*/, const std::vector* /* pollsets */) { - if (server_->config_fetcher() != nullptr) { - auto watcher = std::make_unique(Ref()); + if (config_fetcher_ != nullptr) { + auto watcher = std::make_unique( + RefAsSubclass()); config_fetcher_watcher_ = watcher.get(); - server_->config_fetcher()->StartWatch( + config_fetcher_->StartWatch( grpc_sockaddr_to_string(&resolved_address_, false).value(), std::move(watcher)); } else { @@ -826,7 +834,9 @@ void Chttp2ServerListener::Start( } void Chttp2ServerListener::StartListening() { - grpc_tcp_server_start(tcp_server_, &server_->pollsets()); + if (tcp_server_ != nullptr) { + grpc_tcp_server_start(tcp_server_, &server_->pollsets()); + } } void Chttp2ServerListener::SetOnDestroyDone(grpc_closure* on_destroy_done) { @@ -834,6 +844,12 @@ void Chttp2ServerListener::SetOnDestroyDone(grpc_closure* on_destroy_done) { on_destroy_done_ = on_destroy_done; } +void Chttp2ServerListener::AcceptConnectedEndpoint( + std::unique_ptr endpoint) { + OnAccept(this, grpc_event_engine_endpoint_create(std::move(endpoint)), + /*accepting_pollset=*/nullptr, /*acceptor=*/nullptr); +} + void Chttp2ServerListener::OnAccept(void* arg, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { @@ -858,7 +874,7 @@ void Chttp2ServerListener::OnAccept(void* arg, grpc_endpoint* tcp, endpoint_cleanup(error); return; } - if (self->server_->config_fetcher() != nullptr) { + if (self->config_fetcher_ != nullptr) { if (connection_manager == nullptr) { grpc_error_handle error = GRPC_ERROR_CREATE( "No ConnectionManager configured. Closing connection."); @@ -899,7 +915,7 @@ void Chttp2ServerListener::OnAccept(void* arg, grpc_endpoint* tcp, // heap-use-after-free issues where `Ref()` is invoked when the ref of // tcp_server_ has already reached 0. (Ref() implementation of // Chttp2ServerListener is grpc_tcp_server_ref().) - listener_ref = self->Ref(); + listener_ref = self->RefAsSubclass(); self->connections_.emplace(connection.get(), std::move(connection)); } } @@ -914,7 +930,7 @@ void Chttp2ServerListener::TcpServerShutdownComplete( void* arg, grpc_error_handle /*error*/) { Chttp2ServerListener* self = static_cast(arg); self->channelz_listen_socket_.reset(); - delete self; + self->Unref(); } // Server callback: destroy the tcp listener (so we don't generate further @@ -923,7 +939,8 @@ void Chttp2ServerListener::Orphan() { // Cancel the watch before shutting down so as to avoid holding a ref to the // listener in the watcher. if (config_fetcher_watcher_ != nullptr) { - server_->config_fetcher()->CancelWatch(config_fetcher_watcher_); + CHECK_NE(config_fetcher_, nullptr); + config_fetcher_->CancelWatch(config_fetcher_watcher_); } std::map> connections; grpc_tcp_server* tcp_server; @@ -941,12 +958,14 @@ void Chttp2ServerListener::Orphan() { } tcp_server = tcp_server_; } - grpc_tcp_server_shutdown_listeners(tcp_server); - grpc_tcp_server_unref(tcp_server); + if (tcp_server != nullptr) { + grpc_tcp_server_shutdown_listeners(tcp_server); + grpc_tcp_server_unref(tcp_server); + } else { + Unref(); + } } -} // namespace - // // Chttp2ServerAddPort() // @@ -1018,7 +1037,7 @@ grpc_error_handle Chttp2ServerAddPort(Server* server, const char* addr, resolved_or->size() - error_list.size(), resolved_or->size()); error = GRPC_ERROR_CREATE_REFERENCING(msg.c_str(), error_list.data(), error_list.size()); - gpr_log(GPR_INFO, "WARNING: %s", StatusToString(error).c_str()); + LOG(INFO) << "WARNING: " << StatusToString(error); // we managed to bind some addresses: continue without error } return absl::OkStatus(); @@ -1047,6 +1066,50 @@ ChannelArgs ModifyArgsForConnection(const ChannelArgs& args, } } // namespace + +namespace experimental { + +absl::Status PassiveListenerImpl::AcceptConnectedEndpoint( + std::unique_ptr endpoint) { + CHECK_NE(server_.get(), nullptr); + RefCountedPtr listener; + { + MutexLock lock(&mu_); + if (listener_ != nullptr) { + listener = + listener_->RefIfNonZero().TakeAsSubclass(); + } + } + if (listener == nullptr) { + return absl::UnavailableError("passive listener already shut down"); + } + ExecCtx exec_ctx; + listener->AcceptConnectedEndpoint(std::move(endpoint)); + return absl::OkStatus(); +} + +absl::Status PassiveListenerImpl::AcceptConnectedFd(int fd) { + CHECK_NE(server_.get(), nullptr); + ExecCtx exec_ctx; + auto& args = server_->channel_args(); + auto* supports_fd = QueryExtension( + /*engine=*/args.GetObjectRef().get()); + if (supports_fd == nullptr) { + return absl::UnimplementedError( + "The server's EventEngine does not support adding endpoints from " + "connected file descriptors."); + } + auto endpoint = + supports_fd->CreateEndpointFromFd(fd, ChannelArgsEndpointConfig(args)); + return AcceptConnectedEndpoint(std::move(endpoint)); +} + +void PassiveListenerImpl::ListenerDestroyed() { + MutexLock lock(&mu_); + listener_ = nullptr; +} + +} // namespace experimental } // namespace grpc_core int grpc_server_add_http2_port(grpc_server* server, const char* addr, @@ -1094,7 +1157,7 @@ int grpc_server_add_http2_port(grpc_server* server, const char* addr, done: sc.reset(DEBUG_LOCATION, "server"); if (!err.ok()) { - gpr_log(GPR_ERROR, "%s", grpc_core::StatusToString(err).c_str()); + LOG(ERROR) << grpc_core::StatusToString(err); } return port_num; } @@ -1105,7 +1168,7 @@ void grpc_server_add_channel_from_fd(grpc_server* server, int fd, // For now, we only support insecure server credentials if (creds == nullptr || creds->type() != grpc_core::InsecureServerCredentials::Type()) { - gpr_log(GPR_ERROR, "Failed to create channel due to invalid creds"); + LOG(ERROR) << "Failed to create channel due to invalid creds"; return; } grpc_core::ExecCtx exec_ctx; @@ -1130,8 +1193,8 @@ void grpc_server_add_channel_from_fd(grpc_server* server, int fd, } grpc_chttp2_transport_start_reading(transport, nullptr, nullptr, nullptr); } else { - gpr_log(GPR_ERROR, "Failed to create channel: %s", - grpc_core::StatusToString(error).c_str()); + LOG(ERROR) << "Failed to create channel: " + << grpc_core::StatusToString(error); transport->Orphan(); } } @@ -1144,3 +1207,31 @@ void grpc_server_add_channel_from_fd(grpc_server* /* server */, int /* fd */, } #endif // GPR_SUPPORT_CHANNELS_FROM_FD + +absl::Status grpc_server_add_passive_listener( + grpc_core::Server* server, grpc_server_credentials* credentials, + std::shared_ptr + passive_listener) { + grpc_core::ExecCtx exec_ctx; + GRPC_API_TRACE("grpc_server_add_passive_listener(server=%p, credentials=%p)", + 2, (server, credentials)); + // Create security context. + if (credentials == nullptr) { + return absl::UnavailableError( + "No credentials specified for passive listener"); + } + auto sc = credentials->create_security_connector(grpc_core::ChannelArgs()); + if (sc == nullptr) { + return absl::UnavailableError( + absl::StrCat("Unable to create secure server with credentials of type ", + credentials->type().name())); + } + auto args = server->channel_args() + .SetObject(credentials->Ref()) + .SetObject(std::move(sc)); + passive_listener->listener_ = + grpc_core::Chttp2ServerListener::CreateForPassiveListener( + server, args, passive_listener); + passive_listener->server_ = server->Ref(); + return absl::OkStatus(); +} diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.h b/src/core/ext/transport/chttp2/server/chttp2_server.h index 26c178be917..25d38236aed 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.h +++ b/src/core/ext/transport/chttp2/server/chttp2_server.h @@ -21,6 +21,7 @@ #include +#include #include #include "src/core/lib/channel/channel_args.h" @@ -42,6 +43,38 @@ grpc_error_handle Chttp2ServerAddPort( Server* server, const char* addr, const ChannelArgs& args, Chttp2ServerArgsModifier connection_args_modifier, int* port_num); +class Chttp2ServerListener; +namespace experimental { + +// An implementation of the public C++ passive listener interface. +// The server builder holds a weak_ptr to one of these objects, and the +// application owns the instance. +class PassiveListenerImpl final : public PassiveListener { + public: + absl::Status AcceptConnectedEndpoint( + std::unique_ptr + endpoint) override ABSL_LOCKS_EXCLUDED(mu_); + + absl::Status AcceptConnectedFd(GRPC_UNUSED int fd) override + ABSL_LOCKS_EXCLUDED(mu_); + + void ListenerDestroyed() ABSL_LOCKS_EXCLUDED(mu_); + + private: + // note: the grpc_core::Server redundant namespace qualification is + // required for older gcc versions. + friend absl::Status(::grpc_server_add_passive_listener)( + grpc_core::Server* server, grpc_server_credentials* credentials, + std::shared_ptr + passive_listener); + + Mutex mu_; + // Data members will be populated when initialized. + RefCountedPtr server_; + Chttp2ServerListener* listener_; +}; + +} // namespace experimental } // namespace grpc_core #endif // GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_SERVER_CHTTP2_SERVER_H diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 9a28649dd52..5c2d1c5ae20 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" @@ -79,8 +80,6 @@ #include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/stats_data.h" #include "src/core/lib/experiments/experiments.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/bitset.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/debug_location.h" @@ -109,6 +108,8 @@ #include "src/core/lib/transport/metadata_info.h" #include "src/core/lib/transport/status_conversion.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/string.h" +#include "src/core/util/useful.h" #ifdef GRPC_POSIX_SOCKET_TCP #include "src/core/lib/iomgr/ev_posix.h" @@ -802,8 +803,8 @@ grpc_chttp2_stream::grpc_chttp2_stream(grpc_chttp2_transport* t, if (server_data) { id = static_cast(reinterpret_cast(server_data)); if (grpc_http_trace.enabled()) { - gpr_log(GPR_DEBUG, "HTTP:%p/%p creating accept stream %d [from %p]", t, - this, id, server_data); + VLOG(2) << "HTTP:" << t << "/" << this << " creating accept stream " << id + << " [from " << server_data << "]"; } *t->accepting_stream = this; t->stream_map.emplace(id, this); @@ -1036,8 +1037,8 @@ static void write_action(grpc_chttp2_transport* t) { max_frame_size = INT_MAX; } if (GRPC_TRACE_FLAG_ENABLED(grpc_ping_trace)) { - gpr_log(GPR_INFO, "%s[%p]: Write %" PRIdPTR " bytes", - t->is_client ? "CLIENT" : "SERVER", t, t->outbuf.Length()); + LOG(INFO) << (t->is_client ? "CLIENT" : "SERVER") << "[" << t << "]: Write " + << t->outbuf.Length() << " bytes"; } t->write_size_policy.BeginWrite(t->outbuf.Length()); grpc_endpoint_write(t->ep, t->outbuf.c_slice_buffer(), @@ -1050,8 +1051,8 @@ static void write_action_end(grpc_core::RefCountedPtr t, grpc_error_handle error) { auto* tp = t.get(); if (GRPC_TRACE_FLAG_ENABLED(grpc_ping_trace)) { - gpr_log(GPR_INFO, "%s[%p]: Finish write", - t->is_client ? "CLIENT" : "SERVER", t.get()); + LOG(INFO) << (t->is_client ? "CLIENT" : "SERVER") << "[" << t.get() + << "]: Finish write"; } tp->combiner->Run(grpc_core::InitTransportClosure( std::move(t), &tp->write_action_end_locked), @@ -1324,11 +1325,11 @@ 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--"); + VLOG(2) << "--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) { - gpr_log(GPR_INFO, "%s", absl::StrCat(prefix, key, ": ", value).c_str()); + VLOG(2) << absl::StrCat(prefix, key, ": ", value); }); } diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc index b7dbdb2f0a5..ea633e03a88 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.cc +++ b/src/core/ext/transport/chttp2/transport/flow_control.cc @@ -37,8 +37,8 @@ #include "src/core/ext/transport/chttp2/transport/http2_settings.h" #include "src/core/lib/experiments/experiments.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/resource_quota/memory_quota.h" +#include "src/core/util/useful.h" grpc_core::TraceFlag grpc_flowctl_trace(false, "flowctl"); diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.cc b/src/core/ext/transport/chttp2/transport/frame_settings.cc index eb3343d0c3d..2d8227057ad 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.cc +++ b/src/core/ext/transport/chttp2/transport/frame_settings.cc @@ -37,10 +37,10 @@ #include "src/core/ext/transport/chttp2/transport/internal.h" #include "src/core/ext/transport/chttp2/transport/legacy_frame.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/slice/slice.h" +#include "src/core/util/useful.h" static uint8_t* fill_header(uint8_t* out, uint32_t length, uint8_t flags) { *out++ = static_cast(length >> 16); diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc b/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc index d878c3c1b61..41d7d27c343 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc @@ -26,11 +26,11 @@ #include #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" -#include #include #include "src/core/ext/transport/chttp2/transport/hpack_constants.h" @@ -100,7 +100,7 @@ void HPackTable::SetMaxBytes(uint32_t max_bytes) { return; } if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) { - gpr_log(GPR_INFO, "Update hpack parser max size to %d", max_bytes); + LOG(INFO) << "Update hpack parser max size to " << max_bytes; } while (mem_used_ > max_bytes) { EvictOne(); @@ -112,7 +112,7 @@ bool HPackTable::SetCurrentTableSize(uint32_t bytes) { if (current_table_bytes_ == bytes) return true; if (bytes > max_bytes_) return false; if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) { - gpr_log(GPR_INFO, "Update hpack parser table size to %d", bytes); + LOG(INFO) << "Update hpack parser table size to " << bytes; } while (mem_used_ > bytes) { EvictOne(); diff --git a/src/core/ext/transport/chttp2/transport/http2_settings.cc b/src/core/ext/transport/chttp2/transport/http2_settings.cc index b3a6ab25417..ac9c1553301 100644 --- a/src/core/ext/transport/chttp2/transport/http2_settings.cc +++ b/src/core/ext/transport/chttp2/transport/http2_settings.cc @@ -25,8 +25,8 @@ #include #include "src/core/ext/transport/chttp2/transport/frame.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/transport/http2_errors.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/ext/transport/chttp2/transport/http2_settings.h b/src/core/ext/transport/chttp2/transport/http2_settings.h index 8d65aa91085..b5debf96c7e 100644 --- a/src/core/ext/transport/chttp2/transport/http2_settings.h +++ b/src/core/ext/transport/chttp2/transport/http2_settings.h @@ -28,8 +28,8 @@ #include #include "src/core/ext/transport/chttp2/transport/frame.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/transport/http2_errors.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index e74596eee01..a49d91263e5 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -29,6 +29,7 @@ #include "absl/base/attributes.h" #include "absl/container/flat_hash_map.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/random/bit_gen_ref.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" @@ -769,7 +770,7 @@ static grpc_error_handle init_header_frame_parser(grpc_chttp2_transport* t, frame_type = HPackParser::LogInfo::kTrailers; break; case 2: - gpr_log(GPR_ERROR, "too many header frames received"); + LOG(ERROR) << "too many header frames received"; return init_header_skip_frame_parser(t, priority_type, is_eoh); } if (frame_type == HPackParser::LogInfo::kTrailers && !t->header_eof) { @@ -889,10 +890,9 @@ static grpc_error_handle parse_frame_slice(grpc_chttp2_transport* t, int is_last) { grpc_chttp2_stream* s = t->incoming_stream; if (grpc_http_trace.enabled()) { - gpr_log(GPR_DEBUG, - "INCOMING[%p;%p]: Parse %" PRIdPTR "b %sframe fragment with %s", t, - s, GRPC_SLICE_LENGTH(slice), is_last ? "last " : "", - t->parser.name); + VLOG(2) << "INCOMING[" << t << ";" << s << "]: Parse " + << GRPC_SLICE_LENGTH(slice) << "b " << (is_last ? "last " : "") + << "frame fragment with " << t->parser.name; } grpc_error_handle err = t->parser.parser(t->parser.user_data, t, s, slice, is_last); diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index e9962375b62..6b99d9deee8 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -59,7 +59,6 @@ #include "src/core/lib/debug/stats_data.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/experiments/experiments.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/match.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -73,6 +72,7 @@ #include "src/core/lib/transport/http2_errors.h" #include "src/core/lib/transport/metadata_batch.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/useful.h" // IWYU pragma: no_include "src/core/lib/gprpp/orphanable.h" diff --git a/src/core/ext/transport/cronet/BUILD b/src/core/ext/transport/cronet/BUILD index 50897682381..1e7e8253e62 100644 --- a/src/core/ext/transport/cronet/BUILD +++ b/src/core/ext/transport/cronet/BUILD @@ -41,6 +41,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "cronet_c_for_grpc", ], language = "c++", diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index 7dd316bfca8..dbbd3e63123 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -28,6 +28,7 @@ #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/promise/promise.h" #include "src/core/lib/promise/try_seq.h" +#include "src/core/lib/resource_quota/resource_quota.h" #include "src/core/lib/surface/channel_create.h" #include "src/core/lib/transport/transport.h" #include "src/core/server/server.h" @@ -39,8 +40,18 @@ class InprocClientTransport; class InprocServerTransport final : public ServerTransport { public: - void SetAcceptor(Acceptor* acceptor) override { - acceptor_ = acceptor; + explicit InprocServerTransport(const ChannelArgs& args) + : event_engine_( + args.GetObjectRef()), + call_arena_allocator_(MakeRefCounted( + args.GetObject() + ->memory_quota() + ->CreateMemoryAllocator("inproc_server"), + 1024)) {} + + void SetCallDestination( + RefCountedPtr unstarted_call_handler) override { + unstarted_call_handler_ = unstarted_call_handler; ConnectionState expect = ConnectionState::kInitial; state_.compare_exchange_strong(expect, ConnectionState::kReady, std::memory_order_acq_rel, @@ -95,7 +106,11 @@ class InprocServerTransport final : public ServerTransport { case ConnectionState::kReady: break; } - return acceptor_->CreateCall(std::move(md), acceptor_->CreateArena()); + auto* arena = call_arena_allocator_->MakeArena(); + auto server_call = MakeCallPair(std::move(md), event_engine_.get(), arena, + call_arena_allocator_, nullptr); + unstarted_call_handler_->StartCall(std::move(server_call.handler)); + return std::move(server_call.initiator); } OrphanablePtr MakeClientTransport(); @@ -105,11 +120,14 @@ class InprocServerTransport final : public ServerTransport { std::atomic state_{ConnectionState::kInitial}; std::atomic disconnecting_{false}; - Acceptor* acceptor_; + RefCountedPtr unstarted_call_handler_; absl::Status disconnect_error_; Mutex state_tracker_mu_; ConnectivityStateTracker state_tracker_ ABSL_GUARDED_BY(state_tracker_mu_){ "inproc_server_transport", GRPC_CHANNEL_CONNECTING}; + const std::shared_ptr + event_engine_; + const RefCountedPtr call_arena_allocator_; }; class InprocClientTransport final : public ClientTransport { @@ -118,16 +136,19 @@ class InprocClientTransport final : public ClientTransport { RefCountedPtr server_transport) : server_transport_(std::move(server_transport)) {} - void StartCall(CallHandler call_handler) override { - call_handler.SpawnGuarded( + void StartCall(CallHandler child_call_handler) override { + child_call_handler.SpawnGuarded( "pull_initial_metadata", - TrySeq(call_handler.PullClientInitialMetadata(), + TrySeq(child_call_handler.PullClientInitialMetadata(), [server_transport = server_transport_, - call_handler](ClientMetadataHandle md) { - auto call_initiator = + child_call_handler](ClientMetadataHandle md) { + auto server_call_initiator = server_transport->AcceptCall(std::move(md)); - if (!call_initiator.ok()) return call_initiator.status(); - ForwardCall(call_handler, std::move(*call_initiator)); + if (!server_call_initiator.ok()) { + return server_call_initiator.status(); + } + ForwardCall(child_call_handler, + std::move(*server_call_initiator)); return absl::OkStatus(); })); } @@ -155,7 +176,6 @@ class InprocClientTransport final : public ClientTransport { bool UsePromiseBasedTransport() { if (!IsPromiseBasedInprocTransportEnabled()) return false; CHECK(IsPromiseBasedClientCallEnabled()); - CHECK(IsPromiseBasedServerCallEnabled()); return true; } @@ -180,7 +200,7 @@ OrphanablePtr MakeLameChannel(absl::string_view why, OrphanablePtr MakeInprocChannel(Server* server, ChannelArgs client_channel_args) { - auto transports = MakeInProcessTransportPair(); + auto transports = MakeInProcessTransportPair(server->channel_args()); auto client_transport = std::move(transports.first); auto server_transport = std::move(transports.second); auto error = @@ -205,8 +225,9 @@ OrphanablePtr MakeInprocChannel(Server* server, } // namespace std::pair, OrphanablePtr> -MakeInProcessTransportPair() { - auto server_transport = MakeOrphanable(); +MakeInProcessTransportPair(const ChannelArgs& server_channel_args) { + auto server_transport = + MakeOrphanable(server_channel_args); auto client_transport = server_transport->MakeClientTransport(); return std::make_pair(std::move(client_transport), std::move(server_transport)); diff --git a/src/core/ext/transport/inproc/inproc_transport.h b/src/core/ext/transport/inproc/inproc_transport.h index 676b5f1fa32..46dc9b540f1 100644 --- a/src/core/ext/transport/inproc/inproc_transport.h +++ b/src/core/ext/transport/inproc/inproc_transport.h @@ -30,7 +30,7 @@ extern grpc_core::TraceFlag grpc_inproc_trace; namespace grpc_core { std::pair, OrphanablePtr> -MakeInProcessTransportPair(); +MakeInProcessTransportPair(const ChannelArgs& server_channel_args); } diff --git a/src/core/ext/transport/inproc/legacy_inproc_transport.cc b/src/core/ext/transport/inproc/legacy_inproc_transport.cc index dd5c4663abc..9412fe41e4e 100644 --- a/src/core/ext/transport/inproc/legacy_inproc_transport.cc +++ b/src/core/ext/transport/inproc/legacy_inproc_transport.cc @@ -28,6 +28,7 @@ #include #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" @@ -319,7 +320,7 @@ void log_metadata(const grpc_metadata_batch* md_batch, bool is_client, std::string prefix = absl::StrCat( "INPROC:", is_initial ? "HDR:" : "TRL:", is_client ? "CLI:" : "SVR:"); md_batch->Log([&prefix](absl::string_view key, absl::string_view value) { - gpr_log(GPR_INFO, "%s", absl::StrCat(prefix, key, ": ", value).c_str()); + LOG(INFO) << absl::StrCat(prefix, key, ": ", value); }); } @@ -1268,8 +1269,8 @@ grpc_channel* grpc_legacy_inproc_channel_create(grpc_server* server, "inproc", client_args, GRPC_CLIENT_DIRECT_CHANNEL, client_transport); if (!new_channel.ok()) { CHECK(!channel); - gpr_log(GPR_ERROR, "Failed to create client channel: %s", - grpc_core::StatusToString(error).c_str()); + LOG(ERROR) << "Failed to create client channel: " + << grpc_core::StatusToString(error); intptr_t integer; grpc_status_code status = GRPC_STATUS_INTERNAL; if (grpc_error_get_int(error, grpc_core::StatusIntProperty::kRpcStatus, @@ -1286,8 +1287,8 @@ grpc_channel* grpc_legacy_inproc_channel_create(grpc_server* server, } } else { CHECK(!channel); - gpr_log(GPR_ERROR, "Failed to create server channel: %s", - grpc_core::StatusToString(error).c_str()); + LOG(ERROR) << "Failed to create server channel: " + << grpc_core::StatusToString(error); intptr_t integer; grpc_status_code status = GRPC_STATUS_INTERNAL; if (grpc_error_get_int(error, grpc_core::StatusIntProperty::kRpcStatus, diff --git a/src/core/handshaker/http_connect/http_connect_handshaker.cc b/src/core/handshaker/http_connect/http_connect_handshaker.cc index f8494e6cde1..32d218e06ea 100644 --- a/src/core/handshaker/http_connect/http_connect_handshaker.cc +++ b/src/core/handshaker/http_connect/http_connect_handshaker.cc @@ -41,7 +41,6 @@ #include "src/core/handshaker/handshaker_registry.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/config/core_configuration.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" @@ -53,6 +52,7 @@ #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/iomgr_fwd.h" #include "src/core/lib/iomgr/tcp_server.h" +#include "src/core/util/string.h" namespace grpc_core { diff --git a/src/core/handshaker/http_connect/http_proxy_mapper.cc b/src/core/handshaker/http_connect/http_proxy_mapper.cc index 5b150619e59..c989d281360 100644 --- a/src/core/handshaker/http_connect/http_proxy_mapper.cc +++ b/src/core/handshaker/http_connect/http_proxy_mapper.cc @@ -26,6 +26,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/ascii.h" @@ -47,12 +48,12 @@ #include "src/core/lib/address_utils/parse_address.h" #include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/memory.h" #include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/uri/uri_parser.h" +#include "src/core/util/string.h" namespace grpc_core { namespace { @@ -150,7 +151,7 @@ absl::optional GetHttpProxyServer( // User cred found *user_cred = authority_strs[0]; proxy_name = authority_strs[1]; - gpr_log(GPR_DEBUG, "userinfo found in proxy URI"); + VLOG(2) << "userinfo found in proxy URI"; } else { // Bad authority proxy_name = absl::nullopt; diff --git a/src/core/handshaker/security/secure_endpoint.cc b/src/core/handshaker/security/secure_endpoint.cc index d020d56ebd2..922b111cab4 100644 --- a/src/core/handshaker/security/secure_endpoint.cc +++ b/src/core/handshaker/security/secure_endpoint.cc @@ -42,7 +42,6 @@ #include "src/core/handshaker/security/tsi_error.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" @@ -58,6 +57,7 @@ #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/tsi/transport_security_grpc.h" #include "src/core/tsi/transport_security_interface.h" +#include "src/core/util/string.h" #define STAGING_BUFFER_SIZE 8192 diff --git a/src/core/lib/address_utils/parse_address.cc b/src/core/lib/address_utils/parse_address.cc index 62d4839b6e3..1b677f5f6cb 100644 --- a/src/core/lib/address_utils/parse_address.cc +++ b/src/core/lib/address_utils/parse_address.cc @@ -19,6 +19,7 @@ #include "src/core/lib/address_utils/parse_address.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include @@ -49,12 +50,12 @@ #include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/status_helper.h" #include "src/core/lib/iomgr/grpc_if_nametoindex.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/socket_utils.h" +#include "src/core/util/string.h" // IWYU pragma: no_include @@ -70,7 +71,7 @@ bool grpc_parse_unix(const grpc_core::URI& uri, grpc_error_handle error = grpc_core::UnixSockaddrPopulate(uri.path(), resolved_addr); if (!error.ok()) { - gpr_log(GPR_ERROR, "%s", grpc_core::StatusToString(error).c_str()); + LOG(ERROR) << "" << grpc_core::StatusToString(error); return false; } return true; @@ -86,7 +87,7 @@ bool grpc_parse_unix_abstract(const grpc_core::URI& uri, grpc_error_handle error = grpc_core::UnixAbstractSockaddrPopulate(uri.path(), resolved_addr); if (!error.ok()) { - gpr_log(GPR_ERROR, "%s", grpc_core::StatusToString(error).c_str()); + LOG(ERROR) << "" << grpc_core::StatusToString(error); return false; } return true; @@ -170,7 +171,7 @@ bool grpc_parse_vsock(const grpc_core::URI& uri, grpc_error_handle error = grpc_core::VSockaddrPopulate(uri.path(), resolved_addr); if (!error.ok()) { - gpr_log(GPR_ERROR, "%s", grpc_core::StatusToString(error).c_str()); + LOG(ERROR) << "" << grpc_core::StatusToString(error); return false; } return true; @@ -238,7 +239,7 @@ bool grpc_parse_ipv4_hostport(absl::string_view hostport, } // Parse port. if (port.empty()) { - if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv4 scheme"); + if (log_errors) LOG(ERROR) << "no port given for ipv4 scheme"; goto done; } int port_num; @@ -333,7 +334,7 @@ bool grpc_parse_ipv6_hostport(absl::string_view hostport, } // Parse port. if (port.empty()) { - if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv6 scheme"); + if (log_errors) LOG(ERROR) << "no port given for ipv6 scheme"; goto done; } int port_num; diff --git a/src/core/lib/avl/avl.h b/src/core/lib/avl/avl.h index e8b9539bee2..928db42ac93 100644 --- a/src/core/lib/avl/avl.h +++ b/src/core/lib/avl/avl.h @@ -23,9 +23,9 @@ #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/lib/channel/channel_args.cc b/src/core/lib/channel/channel_args.cc index f34408512c9..1e63ae38f9e 100644 --- a/src/core/lib/channel/channel_args.cc +++ b/src/core/lib/channel/channel_args.cc @@ -40,7 +40,7 @@ #include #include -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/lib/channel/channel_args.h b/src/core/lib/channel/channel_args.h index 97197f43715..31e0430a7c6 100644 --- a/src/core/lib/channel/channel_args.h +++ b/src/core/lib/channel/channel_args.h @@ -38,7 +38,6 @@ #include #include "src/core/lib/avl/avl.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/dual_ref_counted.h" #include "src/core/lib/gprpp/ref_counted.h" @@ -46,6 +45,7 @@ #include "src/core/lib/gprpp/ref_counted_string.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/surface/channel_stack_type.h" +#include "src/core/util/useful.h" // TODO(hork): When we're ready to allow setting via a channel arg from the // application, replace this with a macro in diff --git a/src/core/lib/channel/channel_stack.cc b/src/core/lib/channel/channel_stack.cc index 9b28a321db1..59c80a2d42d 100644 --- a/src/core/lib/channel/channel_stack.cc +++ b/src/core/lib/channel/channel_stack.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -31,8 +32,8 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_fwd.h" #include "src/core/lib/channel/channel_stack_trace.h" -#include "src/core/lib/gpr/alloc.h" #include "src/core/lib/surface/channel_init.h" +#include "src/core/util/alloc.h" using grpc_event_engine::experimental::EventEngine; @@ -121,7 +122,7 @@ grpc_error_handle grpc_channel_stack_init( const grpc_core::ChannelArgs& channel_args, const char* name, grpc_channel_stack* stack) { if (grpc_trace_channel_stack.enabled()) { - gpr_log(GPR_INFO, "CHANNEL_STACK: init %s", name); + LOG(INFO) << "CHANNEL_STACK: init " << name; for (size_t i = 0; i < filter_count; i++) { gpr_log(GPR_INFO, "CHANNEL_STACK: filter %s%s", filters[i]->name, filters[i]->make_call_promise ? " [promise-capable]" : ""); @@ -305,13 +306,6 @@ grpc_core::NextPromiseFactory ClientNext(grpc_channel_element* elem) { }; } -grpc_core::NextPromiseFactory ServerNext(grpc_channel_element* elem) { - return [elem](grpc_core::CallArgs args) { - return elem->filter->make_call_promise(elem, std::move(args), - ServerNext(elem - 1)); - }; -} - } // namespace grpc_core::ArenaPromise @@ -319,12 +313,6 @@ grpc_channel_stack::MakeClientCallPromise(grpc_core::CallArgs call_args) { return ClientNext(grpc_channel_stack_element(this, 0))(std::move(call_args)); } -grpc_core::ArenaPromise -grpc_channel_stack::MakeServerCallPromise(grpc_core::CallArgs call_args) { - return ServerNext(grpc_channel_stack_element(this, this->count - 1))( - std::move(call_args)); -} - void grpc_channel_stack::InitClientCallSpine( grpc_core::CallSpineInterface* call) { for (size_t i = 0; i < count; i++) { @@ -338,19 +326,6 @@ void grpc_channel_stack::InitClientCallSpine( } } -void grpc_channel_stack::InitServerCallSpine( - grpc_core::CallSpineInterface* call) { - for (size_t i = 0; i < count; i++) { - auto* elem = grpc_channel_stack_element(this, count - 1 - i); - if (elem->filter->init_call == nullptr) { - grpc_core::Crash( - absl::StrCat("Filter '", elem->filter->name, - "' does not support the call-v3 interface")); - } - elem->filter->init_call(elem, call); - } -} - void grpc_call_log_op(const char* file, int line, gpr_log_severity severity, grpc_call_element* elem, grpc_transport_stream_op_batch* op) { diff --git a/src/core/lib/channel/channel_stack.h b/src/core/lib/channel/channel_stack.h index affd34a4191..10b326e88d3 100644 --- a/src/core/lib/channel/channel_stack.h +++ b/src/core/lib/channel/channel_stack.h @@ -62,7 +62,6 @@ #include "src/core/lib/channel/context.h" #include "src/core/lib/channel/metrics.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/time_precise.h" #include "src/core/lib/gprpp/manual_constructor.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/time.h" @@ -74,6 +73,7 @@ #include "src/core/lib/resource_quota/arena.h" #include "src/core/lib/transport/call_final_info.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/time_precise.h" struct grpc_channel_element_args { grpc_channel_stack* channel_stack; @@ -241,7 +241,6 @@ struct grpc_channel_stack { MakeServerCallPromise(grpc_core::CallArgs call_args); void InitClientCallSpine(grpc_core::CallSpineInterface* call); - void InitServerCallSpine(grpc_core::CallSpineInterface* call); }; // A call stack tracks a set of related filters for one call, and guarantees diff --git a/src/core/lib/channel/connected_channel.cc b/src/core/lib/channel/connected_channel.cc index 48d8b7f25a7..bf6fe94471b 100644 --- a/src/core/lib/channel/connected_channel.cc +++ b/src/core/lib/channel/connected_channel.cc @@ -44,7 +44,6 @@ #include "src/core/lib/config/core_configuration.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/experiments/experiments.h" -#include "src/core/lib/gpr/alloc.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -79,6 +78,7 @@ #include "src/core/lib/transport/error_utils.h" #include "src/core/lib/transport/metadata_batch.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/alloc.h" typedef struct connected_channel_channel_data { grpc_core::Transport* transport; diff --git a/src/core/lib/channel/context.h b/src/core/lib/channel/context.h index ddcd01395a9..95ce62240bf 100644 --- a/src/core/lib/channel/context.h +++ b/src/core/lib/channel/context.h @@ -72,6 +72,7 @@ struct grpc_call_context_element { namespace grpc_core { class Call; +class CallTracerAnnotationInterface; // Bind the legacy context array into the new style structure // TODO(ctiller): remove as we migrate these contexts to the new system. @@ -89,6 +90,12 @@ struct OldStyleContext { static constexpr grpc_context_index kIndex = GRPC_CONTEXT_CALL; }; +template <> +struct OldStyleContext { + static constexpr grpc_context_index kIndex = + GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE; +}; + template class Context::kIndex)>> { public: diff --git a/src/core/lib/channel/metrics.cc b/src/core/lib/channel/metrics.cc index d662f3275ad..c3b734fc44d 100644 --- a/src/core/lib/channel/metrics.cc +++ b/src/core/lib/channel/metrics.cc @@ -34,12 +34,14 @@ GlobalInstrumentsRegistry::GetInstrumentList() { return *instruments; } -GlobalInstrumentsRegistry::GlobalUInt64CounterHandle -GlobalInstrumentsRegistry::RegisterUInt64Counter( +GlobalInstrumentsRegistry::InstrumentID +GlobalInstrumentsRegistry::RegisterInstrument( + GlobalInstrumentsRegistry::ValueType value_type, + GlobalInstrumentsRegistry::InstrumentType instrument_type, absl::string_view name, absl::string_view description, - absl::string_view unit, absl::Span label_keys, - absl::Span optional_label_keys, - bool enable_by_default) { + absl::string_view unit, bool enable_by_default, + absl::Span label_keys, + absl::Span optional_label_keys) { auto& instruments = GetInstrumentList(); for (const auto& descriptor : instruments) { if (descriptor.name == name) { @@ -47,11 +49,11 @@ GlobalInstrumentsRegistry::RegisterUInt64Counter( absl::StrFormat("Metric name %s has already been registered.", name)); } } - uint32_t index = instruments.size(); + InstrumentID index = instruments.size(); CHECK_LT(index, std::numeric_limits::max()); GlobalInstrumentDescriptor descriptor; - descriptor.value_type = ValueType::kUInt64; - descriptor.instrument_type = InstrumentType::kCounter; + descriptor.value_type = value_type; + descriptor.instrument_type = instrument_type; descriptor.index = index; descriptor.enable_by_default = enable_by_default; descriptor.name = name; @@ -61,169 +63,7 @@ GlobalInstrumentsRegistry::RegisterUInt64Counter( descriptor.optional_label_keys = {optional_label_keys.begin(), optional_label_keys.end()}; instruments.push_back(std::move(descriptor)); - GlobalUInt64CounterHandle handle; - handle.index = index; - return handle; -} - -GlobalInstrumentsRegistry::GlobalDoubleCounterHandle -GlobalInstrumentsRegistry::RegisterDoubleCounter( - absl::string_view name, absl::string_view description, - absl::string_view unit, absl::Span label_keys, - absl::Span optional_label_keys, - bool enable_by_default) { - auto& instruments = GetInstrumentList(); - for (const auto& descriptor : instruments) { - if (descriptor.name == name) { - Crash( - absl::StrFormat("Metric name %s has already been registered.", name)); - } - } - uint32_t index = instruments.size(); - CHECK_LT(index, std::numeric_limits::max()); - GlobalInstrumentDescriptor descriptor; - descriptor.value_type = ValueType::kDouble; - descriptor.instrument_type = InstrumentType::kCounter; - descriptor.index = index; - descriptor.enable_by_default = enable_by_default; - descriptor.name = name; - descriptor.description = description; - descriptor.unit = unit; - descriptor.label_keys = {label_keys.begin(), label_keys.end()}; - descriptor.optional_label_keys = {optional_label_keys.begin(), - optional_label_keys.end()}; - instruments.push_back(std::move(descriptor)); - GlobalDoubleCounterHandle handle; - handle.index = index; - return handle; -} - -GlobalInstrumentsRegistry::GlobalUInt64HistogramHandle -GlobalInstrumentsRegistry::RegisterUInt64Histogram( - absl::string_view name, absl::string_view description, - absl::string_view unit, absl::Span label_keys, - absl::Span optional_label_keys, - bool enable_by_default) { - auto& instruments = GetInstrumentList(); - for (const auto& descriptor : instruments) { - if (descriptor.name == name) { - Crash( - absl::StrFormat("Metric name %s has already been registered.", name)); - } - } - uint32_t index = instruments.size(); - CHECK_LT(index, std::numeric_limits::max()); - GlobalInstrumentDescriptor descriptor; - descriptor.value_type = ValueType::kUInt64; - descriptor.instrument_type = InstrumentType::kHistogram; - descriptor.index = index; - descriptor.enable_by_default = enable_by_default; - descriptor.name = name; - descriptor.description = description; - descriptor.unit = unit; - descriptor.label_keys = {label_keys.begin(), label_keys.end()}; - descriptor.optional_label_keys = {optional_label_keys.begin(), - optional_label_keys.end()}; - instruments.push_back(std::move(descriptor)); - GlobalUInt64HistogramHandle handle; - handle.index = index; - return handle; -} - -GlobalInstrumentsRegistry::GlobalDoubleHistogramHandle -GlobalInstrumentsRegistry::RegisterDoubleHistogram( - absl::string_view name, absl::string_view description, - absl::string_view unit, absl::Span label_keys, - absl::Span optional_label_keys, - bool enable_by_default) { - auto& instruments = GetInstrumentList(); - for (const auto& descriptor : instruments) { - if (descriptor.name == name) { - Crash( - absl::StrFormat("Metric name %s has already been registered.", name)); - } - } - uint32_t index = instruments.size(); - CHECK_LT(index, std::numeric_limits::max()); - GlobalInstrumentDescriptor descriptor; - descriptor.value_type = ValueType::kDouble; - descriptor.instrument_type = InstrumentType::kHistogram; - descriptor.index = index; - descriptor.enable_by_default = enable_by_default; - descriptor.name = name; - descriptor.description = description; - descriptor.unit = unit; - descriptor.label_keys = {label_keys.begin(), label_keys.end()}; - descriptor.optional_label_keys = {optional_label_keys.begin(), - optional_label_keys.end()}; - instruments.push_back(std::move(descriptor)); - GlobalDoubleHistogramHandle handle; - handle.index = index; - return handle; -} - -GlobalInstrumentsRegistry::GlobalCallbackInt64GaugeHandle -GlobalInstrumentsRegistry::RegisterCallbackInt64Gauge( - absl::string_view name, absl::string_view description, - absl::string_view unit, absl::Span label_keys, - absl::Span optional_label_keys, - bool enable_by_default) { - auto& instruments = GetInstrumentList(); - for (const auto& descriptor : instruments) { - if (descriptor.name == name) { - Crash( - absl::StrFormat("Metric name %s has already been registered.", name)); - } - } - uint32_t index = instruments.size(); - CHECK_LT(index, std::numeric_limits::max()); - GlobalInstrumentDescriptor descriptor; - descriptor.value_type = ValueType::kInt64; - descriptor.instrument_type = InstrumentType::kCallbackGauge; - descriptor.index = index; - descriptor.enable_by_default = enable_by_default; - descriptor.name = name; - descriptor.description = description; - descriptor.unit = unit; - descriptor.label_keys = {label_keys.begin(), label_keys.end()}; - descriptor.optional_label_keys = {optional_label_keys.begin(), - optional_label_keys.end()}; - instruments.push_back(std::move(descriptor)); - GlobalCallbackInt64GaugeHandle handle; - handle.index = index; - return handle; -} - -GlobalInstrumentsRegistry::GlobalCallbackDoubleGaugeHandle -GlobalInstrumentsRegistry::RegisterCallbackDoubleGauge( - absl::string_view name, absl::string_view description, - absl::string_view unit, absl::Span label_keys, - absl::Span optional_label_keys, - bool enable_by_default) { - auto& instruments = GetInstrumentList(); - for (const auto& descriptor : instruments) { - if (descriptor.name == name) { - Crash( - absl::StrFormat("Metric name %s has already been registered.", name)); - } - } - uint32_t index = instruments.size(); - CHECK_LT(index, std::numeric_limits::max()); - GlobalInstrumentDescriptor descriptor; - descriptor.value_type = ValueType::kDouble; - descriptor.instrument_type = InstrumentType::kCallbackGauge; - descriptor.index = index; - descriptor.enable_by_default = enable_by_default; - descriptor.name = name; - descriptor.description = description; - descriptor.unit = unit; - descriptor.label_keys = {label_keys.begin(), label_keys.end()}; - descriptor.optional_label_keys = {optional_label_keys.begin(), - optional_label_keys.end()}; - instruments.push_back(std::move(descriptor)); - GlobalCallbackDoubleGaugeHandle handle; - handle.index = index; - return handle; + return index; } void GlobalInstrumentsRegistry::ForEach( @@ -242,7 +82,7 @@ GlobalInstrumentsRegistry::GetInstrumentDescriptor( RegisteredMetricCallback::RegisteredMetricCallback( GlobalStatsPluginRegistry::StatsPluginGroup& stats_plugin_group, absl::AnyInvocable callback, - std::vector metrics, + std::vector metrics, Duration min_interval) : stats_plugin_group_(stats_plugin_group), callback_(std::move(callback)), @@ -259,15 +99,6 @@ RegisteredMetricCallback::~RegisteredMetricCallback() { } } -std::unique_ptr -GlobalStatsPluginRegistry::StatsPluginGroup::RegisterCallback( - absl::AnyInvocable callback, - std::vector metrics, - Duration min_interval) { - return std::make_unique( - *this, std::move(callback), std::move(metrics), min_interval); -} - void GlobalStatsPluginRegistry::StatsPluginGroup::AddClientCallTracers( const Slice& path, bool registered_method, grpc_call_context_element* call_context) { diff --git a/src/core/lib/channel/metrics.h b/src/core/lib/channel/metrics.h index 7c161c80829..797be93fd7d 100644 --- a/src/core/lib/channel/metrics.h +++ b/src/core/lib/channel/metrics.h @@ -17,6 +17,7 @@ #include #include +#include #include #include "absl/functional/any_invocable.h" @@ -45,6 +46,27 @@ constexpr absl::string_view kMetricLabelTarget = "grpc.target"; // startup, before the execution of the main function (during dynamic // initialization time). Using this API after the main function begins may // result into missing instruments. This API is thread-unsafe. +// +// The registration of instruments is done through the templated +// RegistrationBuilder API and gets back a handle with an opaque type. At +// runtime, the handle should be used with the StatsPluginGroup API to record +// metrics for the instruments. +// +// At dynamic initialization time: +// const auto kMetricHandle = +// GlobalInstrumentsRegistry::RegisterUInt64Counter( +// "name", +// "description", +// "unit", /*enable_by_default=*/false) +// .Labels(kLabel1, kLabel2, kLabel3) +// .OptionalLabels(kOptionalLabel1, kOptionalLabel2) +// .Build(); +// +// At runtime time: +// stats_plugin_group.AddCounter(kMetricHandle, 1, +// {"label_value_1", "label_value_2", "label_value_3"}, +// {"optional_label_value_1", "optional_label_value_2"}); +// class GlobalInstrumentsRegistry { public: enum class ValueType { @@ -78,46 +100,113 @@ class GlobalInstrumentsRegistry { // runs or between different versions. InstrumentID index; }; - struct GlobalUInt64CounterHandle : public GlobalInstrumentHandle {}; - struct GlobalDoubleCounterHandle : public GlobalInstrumentHandle {}; - struct GlobalUInt64HistogramHandle : public GlobalInstrumentHandle {}; - struct GlobalDoubleHistogramHandle : public GlobalInstrumentHandle {}; - struct GlobalCallbackInt64GaugeHandle : public GlobalInstrumentHandle {}; - struct GlobalCallbackDoubleGaugeHandle : public GlobalInstrumentHandle {}; - using GlobalCallbackHandle = absl::variant; + + template + struct TypedGlobalInstrumentHandle : public GlobalInstrumentHandle {}; + + template + class RegistrationBuilder { + public: + template + RegistrationBuilder Labels(Args&&... args) { + return RegistrationBuilder( + name_, description_, unit_, enable_by_default_, + std::array({args...}), + optional_label_keys_); + } + + template + RegistrationBuilder OptionalLabels( + Args&&... args) { + return RegistrationBuilder( + name_, description_, unit_, enable_by_default_, label_keys_, + std::array({args...})); + } + + TypedGlobalInstrumentHandle Build() { + TypedGlobalInstrumentHandle handle; + handle.index = RegisterInstrument(V, I, name_, description_, unit_, + enable_by_default_, label_keys_, + optional_label_keys_); + return handle; + } + + private: + friend class GlobalInstrumentsRegistry; + + RegistrationBuilder(absl::string_view name, absl::string_view description, + absl::string_view unit, bool enable_by_default) + : name_(name), + description_(description), + unit_(unit), + enable_by_default_(enable_by_default) {} + + RegistrationBuilder(absl::string_view name, absl::string_view description, + absl::string_view unit, bool enable_by_default, + std::array label_keys, + std::array optional_label_keys) + : name_(name), + description_(description), + unit_(unit), + enable_by_default_(enable_by_default), + label_keys_(std::move(label_keys)), + optional_label_keys_(std::move(optional_label_keys)) {} + + absl::string_view name_; + absl::string_view description_; + absl::string_view unit_; + bool enable_by_default_; + std::array label_keys_; + std::array optional_label_keys_; + }; // Creates instrument in the GlobalInstrumentsRegistry. - static GlobalUInt64CounterHandle RegisterUInt64Counter( - absl::string_view name, absl::string_view description, - absl::string_view unit, absl::Span label_keys, - absl::Span optional_label_keys, - bool enable_by_default); - static GlobalDoubleCounterHandle RegisterDoubleCounter( - absl::string_view name, absl::string_view description, - absl::string_view unit, absl::Span label_keys, - absl::Span optional_label_keys, - bool enable_by_default); - static GlobalUInt64HistogramHandle RegisterUInt64Histogram( - absl::string_view name, absl::string_view description, - absl::string_view unit, absl::Span label_keys, - absl::Span optional_label_keys, - bool enable_by_default); - static GlobalDoubleHistogramHandle RegisterDoubleHistogram( - absl::string_view name, absl::string_view description, - absl::string_view unit, absl::Span label_keys, - absl::Span optional_label_keys, - bool enable_by_default); - static GlobalCallbackInt64GaugeHandle RegisterCallbackInt64Gauge( - absl::string_view name, absl::string_view description, - absl::string_view unit, absl::Span label_keys, - absl::Span optional_label_keys, - bool enable_by_default); - static GlobalCallbackDoubleGaugeHandle RegisterCallbackDoubleGauge( - absl::string_view name, absl::string_view description, - absl::string_view unit, absl::Span label_keys, - absl::Span optional_label_keys, - bool enable_by_default); + static RegistrationBuilder + RegisterUInt64Counter(absl::string_view name, absl::string_view description, + absl::string_view unit, bool enable_by_default) { + return RegistrationBuilder(name, description, unit, enable_by_default); + } + static RegistrationBuilder + RegisterDoubleCounter(absl::string_view name, absl::string_view description, + absl::string_view unit, bool enable_by_default) { + return RegistrationBuilder(name, description, unit, enable_by_default); + } + static RegistrationBuilder + RegisterUInt64Histogram(absl::string_view name, absl::string_view description, + absl::string_view unit, bool enable_by_default) { + return RegistrationBuilder(name, description, unit, + enable_by_default); + } + static RegistrationBuilder + RegisterDoubleHistogram(absl::string_view name, absl::string_view description, + absl::string_view unit, bool enable_by_default) { + return RegistrationBuilder(name, description, unit, + enable_by_default); + } + static RegistrationBuilder + RegisterCallbackInt64Gauge(absl::string_view name, + absl::string_view description, + absl::string_view unit, bool enable_by_default) { + return RegistrationBuilder( + name, description, unit, enable_by_default); + } + static RegistrationBuilder + RegisterCallbackDoubleGauge(absl::string_view name, + absl::string_view description, + absl::string_view unit, bool enable_by_default) { + return RegistrationBuilder( + name, description, unit, enable_by_default); + } static void ForEach( absl::FunctionRef f); @@ -131,6 +220,12 @@ class GlobalInstrumentsRegistry { static std::vector& GetInstrumentList(); + static InstrumentID RegisterInstrument( + ValueType value_type, InstrumentType instrument_type, + absl::string_view name, absl::string_view description, + absl::string_view unit, bool enable_by_default, + absl::Span label_keys, + absl::Span optional_label_keys); }; // An interface for implementing callback-style metrics. @@ -139,13 +234,35 @@ class CallbackMetricReporter { public: virtual ~CallbackMetricReporter() = default; - virtual void Report( - GlobalInstrumentsRegistry::GlobalCallbackInt64GaugeHandle handle, - int64_t value, absl::Span label_values, + template + void Report( + GlobalInstrumentsRegistry::TypedGlobalInstrumentHandle< + GlobalInstrumentsRegistry::ValueType::kInt64, + GlobalInstrumentsRegistry::InstrumentType::kCallbackGauge, M, N> + handle, + int64_t value, std::array label_values, + std::array optional_values) { + ReportInt64(handle, value, label_values, optional_values); + } + template + void Report( + GlobalInstrumentsRegistry::TypedGlobalInstrumentHandle< + GlobalInstrumentsRegistry::ValueType::kDouble, + GlobalInstrumentsRegistry::InstrumentType::kCallbackGauge, M, N> + handle, + double value, std::array label_values, + std::array optional_values) { + ReportDouble(handle, value, label_values, optional_values); + } + + private: + virtual void ReportInt64( + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, int64_t value, + absl::Span label_values, absl::Span optional_values) = 0; - virtual void Report( - GlobalInstrumentsRegistry::GlobalCallbackDoubleGaugeHandle handle, - double value, absl::Span label_values, + virtual void ReportDouble( + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, double value, + absl::Span label_values, absl::Span optional_values) = 0; }; @@ -179,15 +296,15 @@ class StatsPlugin { // this measurement and must match with their corresponding keys in // GlobalInstrumentsRegistry::RegisterUInt64Counter(). virtual void AddCounter( - GlobalInstrumentsRegistry::GlobalUInt64CounterHandle handle, - uint64_t value, absl::Span label_values, + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, uint64_t value, + absl::Span label_values, absl::Span optional_label_values) = 0; // Adds \a value to the double counter specified by \a handle. \a label_values // and \a optional_label_values specify attributes that are associated with // this measurement and must match with their corresponding keys in // GlobalInstrumentsRegistry::RegisterDoubleCounter(). virtual void AddCounter( - GlobalInstrumentsRegistry::GlobalDoubleCounterHandle handle, double value, + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, double value, absl::Span label_values, absl::Span optional_label_values) = 0; // Records a uint64 \a value to the histogram specified by \a handle. \a @@ -195,16 +312,16 @@ class StatsPlugin { // associated with this measurement and must match with their corresponding // keys in GlobalInstrumentsRegistry::RegisterUInt64Histogram(). virtual void RecordHistogram( - GlobalInstrumentsRegistry::GlobalUInt64HistogramHandle handle, - uint64_t value, absl::Span label_values, + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, uint64_t value, + absl::Span label_values, absl::Span optional_label_values) = 0; // Records a double \a value to the histogram specified by \a handle. \a // label_values and \a optional_label_values specify attributes that are // associated with this measurement and must match with their corresponding // keys in GlobalInstrumentsRegistry::RegisterDoubleHistogram(). virtual void RecordHistogram( - GlobalInstrumentsRegistry::GlobalDoubleHistogramHandle handle, - double value, absl::Span label_values, + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, double value, + absl::Span label_values, absl::Span optional_label_values) = 0; // Adds a callback to be invoked when the stats plugin wants to // populate the corresponding metrics (see callback->metrics() for list). @@ -255,20 +372,53 @@ class GlobalStatsPluginRegistry { } // Adds a counter in all stats plugins within the group. See the StatsPlugin // interface for more documentation and valid types. - template - void AddCounter(HandleType handle, ValueType value, - absl::Span label_values, - absl::Span optional_values) { + template + void AddCounter( + GlobalInstrumentsRegistry::TypedGlobalInstrumentHandle< + GlobalInstrumentsRegistry::ValueType::kUInt64, + GlobalInstrumentsRegistry::InstrumentType::kCounter, M, N> + handle, + uint64_t value, std::array label_values, + std::array optional_values) { + for (auto& state : plugins_state_) { + state.plugin->AddCounter(handle, value, label_values, optional_values); + } + } + template + void AddCounter( + GlobalInstrumentsRegistry::TypedGlobalInstrumentHandle< + GlobalInstrumentsRegistry::ValueType::kDouble, + GlobalInstrumentsRegistry::InstrumentType::kCounter, M, N> + handle, + double value, std::array label_values, + std::array optional_values) { for (auto& state : plugins_state_) { state.plugin->AddCounter(handle, value, label_values, optional_values); } } // Records a value to a histogram in all stats plugins within the group. See // the StatsPlugin interface for more documentation and valid types. - template - void RecordHistogram(HandleType handle, ValueType value, - absl::Span label_values, - absl::Span optional_values) { + template + void RecordHistogram( + GlobalInstrumentsRegistry::TypedGlobalInstrumentHandle< + GlobalInstrumentsRegistry::ValueType::kUInt64, + GlobalInstrumentsRegistry::InstrumentType::kHistogram, M, N> + handle, + uint64_t value, std::array label_values, + std::array optional_values) { + for (auto& state : plugins_state_) { + state.plugin->RecordHistogram(handle, value, label_values, + optional_values); + } + } + template + void RecordHistogram( + GlobalInstrumentsRegistry::TypedGlobalInstrumentHandle< + GlobalInstrumentsRegistry::ValueType::kDouble, + GlobalInstrumentsRegistry::InstrumentType::kHistogram, M, N> + handle, + double value, std::array label_values, + std::array optional_values) { for (auto& state : plugins_state_) { state.plugin->RecordHistogram(handle, value, label_values, optional_values); @@ -285,11 +435,17 @@ class GlobalStatsPluginRegistry { // the lifetime of the callback; when the returned object is // destroyed, the callback is de-registered. The returned object // must not outlive the StatsPluginGroup object that created it. + template GRPC_MUST_USE_RESULT std::unique_ptr - RegisterCallback( - absl::AnyInvocable callback, - std::vector metrics, - Duration min_interval = Duration::Seconds(5)); + RegisterCallback(absl::AnyInvocable callback, + Duration min_interval, Args... args) { + AssertIsCallbackGaugeHandle(args...); + return std::make_unique( + *this, std::move(callback), + std::vector{ + args...}, + min_interval); + } // Adds all available client call tracers associated with the stats plugins // within the group to \a call_context. @@ -307,6 +463,24 @@ class GlobalStatsPluginRegistry { std::shared_ptr plugin; }; + // C++17 has fold expression that may simplify this. + template + static constexpr void AssertIsCallbackGaugeHandle( + GlobalInstrumentsRegistry::TypedGlobalInstrumentHandle) { + static_assert(V == GlobalInstrumentsRegistry::ValueType::kInt64 || + V == GlobalInstrumentsRegistry::ValueType::kDouble, + "ValueType must be kInt64 or kDouble"); + static_assert( + I == GlobalInstrumentsRegistry::InstrumentType::kCallbackGauge, + "InstrumentType must be kCallbackGauge"); + } + template + static constexpr void AssertIsCallbackGaugeHandle(T t, Args&&... args) { + AssertIsCallbackGaugeHandle(t); + AssertIsCallbackGaugeHandle(args...); + } + std::vector plugins_state_; }; @@ -335,7 +509,7 @@ class RegisteredMetricCallback { RegisteredMetricCallback( GlobalStatsPluginRegistry::StatsPluginGroup& stats_plugin_group, absl::AnyInvocable callback, - std::vector metrics, + std::vector metrics, Duration min_interval); ~RegisteredMetricCallback(); @@ -344,8 +518,8 @@ class RegisteredMetricCallback { void Run(CallbackMetricReporter& reporter) { callback_(reporter); } // Returns the set of metrics that this callback will modify. - const std::vector& metrics() - const { + const std::vector& + metrics() const { return metrics_; } @@ -356,7 +530,7 @@ class RegisteredMetricCallback { private: GlobalStatsPluginRegistry::StatsPluginGroup& stats_plugin_group_; absl::AnyInvocable callback_; - std::vector metrics_; + std::vector metrics_; Duration min_interval_; }; diff --git a/src/core/lib/channel/promise_based_filter.h b/src/core/lib/channel/promise_based_filter.h index c0735c45e61..5379bb6f66a 100644 --- a/src/core/lib/channel/promise_based_filter.h +++ b/src/core/lib/channel/promise_based_filter.h @@ -59,6 +59,7 @@ #include "src/core/lib/iomgr/polling_entity.h" #include "src/core/lib/promise/activity.h" #include "src/core/lib/promise/arena_promise.h" +#include "src/core/lib/promise/cancel_callback.h" #include "src/core/lib/promise/context.h" #include "src/core/lib/promise/pipe.h" #include "src/core/lib/promise/poll.h" @@ -354,31 +355,72 @@ template auto MapResult(absl::Status (Derived::Call::*fn)(ServerMetadata&), Promise x, FilterCallData* call_data) { DCHECK(fn == &Derived::Call::OnServerTrailingMetadata); - return Map(std::move(x), [call_data](ServerMetadataHandle md) { - auto status = call_data->call.OnServerTrailingMetadata(*md); - if (!status.ok()) return ServerMetadataFromStatus(status); - return md; - }); + return OnCancel( + Map(std::move(x), + [call_data](ServerMetadataHandle md) { + auto status = call_data->call.OnServerTrailingMetadata(*md); + if (!status.ok()) { + return ServerMetadataFromStatus(status); + } + return md; + }), + // TODO(yashykt/ctiller): GetContext is not + // valid for the cancellation function requiring us to capture it here. + // This ought to be easy to fix once client side promises are completely + // rolled out. + [call_data, ctx = GetContext()]() { + grpc_metadata_batch b; + b.Set(GrpcStatusMetadata(), GRPC_STATUS_CANCELLED); + b.Set(GrpcCallWasCancelled(), true); + promise_detail::Context context(ctx); + call_data->call.OnServerTrailingMetadata(b).IgnoreError(); + }); } template auto MapResult(void (Derived::Call::*fn)(ServerMetadata&), Promise x, FilterCallData* call_data) { DCHECK(fn == &Derived::Call::OnServerTrailingMetadata); - return Map(std::move(x), [call_data](ServerMetadataHandle md) { - call_data->call.OnServerTrailingMetadata(*md); - return md; - }); + return OnCancel( + Map(std::move(x), + [call_data](ServerMetadataHandle md) { + call_data->call.OnServerTrailingMetadata(*md); + return md; + }), + // TODO(yashykt/ctiller): GetContext is not + // valid for the cancellation function requiring us to capture it here. + // This ought to be easy to fix once client side promises are completely + // rolled out. + [call_data, ctx = GetContext()]() { + grpc_metadata_batch b; + b.Set(GrpcStatusMetadata(), GRPC_STATUS_CANCELLED); + b.Set(GrpcCallWasCancelled(), true); + promise_detail::Context context(ctx); + call_data->call.OnServerTrailingMetadata(b); + }); } template auto MapResult(void (Derived::Call::*fn)(ServerMetadata&, Derived*), Promise x, FilterCallData* call_data) { DCHECK(fn == &Derived::Call::OnServerTrailingMetadata); - return Map(std::move(x), [call_data](ServerMetadataHandle md) { - call_data->call.OnServerTrailingMetadata(*md, call_data->channel); - return md; - }); + return OnCancel( + Map(std::move(x), + [call_data](ServerMetadataHandle md) { + call_data->call.OnServerTrailingMetadata(*md, call_data->channel); + return md; + }), + // TODO(yashykt/ctiller): GetContext is not + // valid for the cancellation function requiring us to capture it here. + // This ought to be easy to fix once client side promises are completely + // rolled out. + [call_data, ctx = GetContext()]() { + grpc_metadata_batch b; + b.Set(GrpcStatusMetadata(), GRPC_STATUS_CANCELLED); + b.Set(GrpcCallWasCancelled(), true); + promise_detail::Context context(ctx); + call_data->call.OnServerTrailingMetadata(b, call_data->channel); + }); } template @@ -492,130 +534,193 @@ auto RunCall(Interceptor interceptor, CallArgs call_args, std::move(call_args), std::move(next_promise_factory), call_data); } -inline void InterceptClientToServerMessage(const NoInterceptor*, void*, - const CallArgs&) {} +template +inline auto InterceptClientToServerMessageHandler( + void (Derived::Call::*fn)(const Message&), + FilterCallData* call_data, const CallArgs&) { + DCHECK(fn == &Derived::Call::OnClientToServerMessage); + return [call_data](MessageHandle msg) -> absl::optional { + call_data->call.OnClientToServerMessage(*msg); + return std::move(msg); + }; +} template -inline void InterceptClientToServerMessage( +inline auto InterceptClientToServerMessageHandler( ServerMetadataHandle (Derived::Call::*fn)(const Message&), - FilterCallData* call_data, const CallArgs& call_args) { + FilterCallData* call_data, const CallArgs&) { DCHECK(fn == &Derived::Call::OnClientToServerMessage); - call_args.client_to_server_messages->InterceptAndMap( - [call_data](MessageHandle msg) -> absl::optional { - auto return_md = call_data->call.OnClientToServerMessage(*msg); - if (return_md == nullptr) return std::move(msg); - if (call_data->error_latch.is_set()) return absl::nullopt; - call_data->error_latch.Set(std::move(return_md)); - return absl::nullopt; - }); + return [call_data](MessageHandle msg) -> absl::optional { + auto return_md = call_data->call.OnClientToServerMessage(*msg); + if (return_md == nullptr) return std::move(msg); + if (call_data->error_latch.is_set()) return absl::nullopt; + call_data->error_latch.Set(std::move(return_md)); + return absl::nullopt; + }; } template -inline void InterceptClientToServerMessage( +inline auto InterceptClientToServerMessageHandler( ServerMetadataHandle (Derived::Call::*fn)(const Message&, Derived*), - FilterCallData* call_data, const CallArgs& call_args) { + FilterCallData* call_data, const CallArgs&) { DCHECK(fn == &Derived::Call::OnClientToServerMessage); - call_args.client_to_server_messages->InterceptAndMap( - [call_data](MessageHandle msg) -> absl::optional { - auto return_md = - call_data->call.OnClientToServerMessage(*msg, call_data->channel); - if (return_md == nullptr) return std::move(msg); - if (call_data->error_latch.is_set()) return absl::nullopt; - call_data->error_latch.Set(std::move(return_md)); - return absl::nullopt; - }); + return [call_data](MessageHandle msg) -> absl::optional { + auto return_md = + call_data->call.OnClientToServerMessage(*msg, call_data->channel); + if (return_md == nullptr) return std::move(msg); + if (call_data->error_latch.is_set()) return absl::nullopt; + call_data->error_latch.Set(std::move(return_md)); + return absl::nullopt; + }; } template -inline void InterceptClientToServerMessage( +inline auto InterceptClientToServerMessageHandler( MessageHandle (Derived::Call::*fn)(MessageHandle, Derived*), - FilterCallData* call_data, const CallArgs& call_args) { + FilterCallData* call_data, const CallArgs&) { DCHECK(fn == &Derived::Call::OnClientToServerMessage); - call_args.client_to_server_messages->InterceptAndMap( - [call_data](MessageHandle msg) -> absl::optional { - return call_data->call.OnClientToServerMessage(std::move(msg), - call_data->channel); - }); + return [call_data](MessageHandle msg) -> absl::optional { + return call_data->call.OnClientToServerMessage(std::move(msg), + call_data->channel); + }; } template -inline void InterceptClientToServerMessage( +inline auto InterceptClientToServerMessageHandler( absl::StatusOr (Derived::Call::*fn)(MessageHandle, Derived*), - FilterCallData* call_data, const CallArgs& call_args) { + FilterCallData* call_data, const CallArgs&) { DCHECK(fn == &Derived::Call::OnClientToServerMessage); + return [call_data](MessageHandle msg) -> absl::optional { + auto r = call_data->call.OnClientToServerMessage(std::move(msg), + call_data->channel); + if (r.ok()) return std::move(*r); + if (call_data->error_latch.is_set()) return absl::nullopt; + call_data->error_latch.Set(ServerMetadataFromStatus(r.status())); + return absl::nullopt; + }; +} + +template +inline void InterceptClientToServerMessage(HookFunction hook, + const NoInterceptor*, + FilterCallData* call_data, + const CallArgs& call_args) { call_args.client_to_server_messages->InterceptAndMap( - [call_data](MessageHandle msg) -> absl::optional { - auto r = call_data->call.OnClientToServerMessage(std::move(msg), - call_data->channel); - if (r.ok()) return std::move(*r); - if (call_data->error_latch.is_set()) return absl::nullopt; - call_data->error_latch.Set(ServerMetadataFromStatus(r.status())); - return absl::nullopt; - }); + InterceptClientToServerMessageHandler(hook, call_data, call_args)); } -inline void InterceptClientToServerMessage(const NoInterceptor*, void*, void*, - CallSpineInterface*) {} +template +inline void InterceptClientToServerMessage(HookFunction hook, + void (Derived::Call::*)(), + FilterCallData* call_data, + const CallArgs& call_args) { + call_args.client_to_server_messages->InterceptAndMapWithHalfClose( + InterceptClientToServerMessageHandler(hook, call_data, call_args), + [call_data]() { call_data->call.OnClientToServerHalfClose(); }); +} template -inline void InterceptClientToServerMessage( +inline void InterceptClientToServerMessage(const NoInterceptor*, + const NoInterceptor*, + FilterCallData*, + const CallArgs&) {} + +template +inline auto InterceptClientToServerMessageHandler( ServerMetadataHandle (Derived::Call::*fn)(const Message&), typename Derived::Call* call, Derived*, PipeBasedCallSpine* call_spine) { DCHECK(fn == &Derived::Call::OnClientToServerMessage); - call_spine->client_to_server_messages().receiver.InterceptAndMap( + return [call, call_spine](MessageHandle msg) -> absl::optional { auto return_md = call->OnClientToServerMessage(*msg); if (return_md == nullptr) return std::move(msg); call_spine->PushServerTrailingMetadata(std::move(return_md)); return absl::nullopt; - }); + }; } template -inline void InterceptClientToServerMessage( +inline auto InterceptClientToServerMessageHandler( + void (Derived::Call::*fn)(const Message&), typename Derived::Call* call, + Derived*, PipeBasedCallSpine*) { + DCHECK(fn == &Derived::Call::OnClientToServerMessage); + return [call](MessageHandle msg) -> absl::optional { + call->OnClientToServerMessage(*msg); + return std::move(msg); + }; +} + +template +inline auto InterceptClientToServerMessageHandler( ServerMetadataHandle (Derived::Call::*fn)(const Message&, Derived*), typename Derived::Call* call, Derived* channel, PipeBasedCallSpine* call_spine) { DCHECK(fn == &Derived::Call::OnClientToServerMessage); - call_spine->client_to_server_messages().receiver.InterceptAndMap( - [call, call_spine, - channel](MessageHandle msg) -> absl::optional { - auto return_md = call->OnClientToServerMessage(*msg, channel); - if (return_md == nullptr) return std::move(msg); - call_spine->PushServerTrailingMetadata(std::move(return_md)); - return absl::nullopt; - }); + return [call, call_spine, + channel](MessageHandle msg) -> absl::optional { + auto return_md = call->OnClientToServerMessage(*msg, channel); + if (return_md == nullptr) return std::move(msg); + call_spine->PushServerTrailingMetadata(std::move(return_md)); + return absl::nullopt; + }; } template -inline void InterceptClientToServerMessage( +inline auto InterceptClientToServerMessageHandler( MessageHandle (Derived::Call::*fn)(MessageHandle, Derived*), - typename Derived::Call* call, Derived* channel, - PipeBasedCallSpine* call_spine) { + typename Derived::Call* call, Derived* channel, PipeBasedCallSpine*) { DCHECK(fn == &Derived::Call::OnClientToServerMessage); - call_spine->client_to_server_messages().receiver.InterceptAndMap( - [call, channel](MessageHandle msg) { - return call->OnClientToServerMessage(std::move(msg), channel); - }); + return [call, channel](MessageHandle msg) { + return call->OnClientToServerMessage(std::move(msg), channel); + }; } template -inline void InterceptClientToServerMessage( +inline auto InterceptClientToServerMessageHandler( absl::StatusOr (Derived::Call::*fn)(MessageHandle, Derived*), typename Derived::Call* call, Derived* channel, PipeBasedCallSpine* call_spine) { DCHECK(fn == &Derived::Call::OnClientToServerMessage); + return [call, call_spine, + channel](MessageHandle msg) -> absl::optional { + auto r = call->OnClientToServerMessage(std::move(msg), channel); + if (r.ok()) return std::move(*r); + call_spine->PushServerTrailingMetadata( + ServerMetadataFromStatus(r.status())); + return absl::nullopt; + }; +} + +template +inline void InterceptClientToServerMessage(HookFunction fn, + const NoInterceptor*, + typename Derived::Call* call, + Derived* channel, + PipeBasedCallSpine* call_spine) { + DCHECK(fn == &Derived::Call::OnClientToServerMessage); call_spine->client_to_server_messages().receiver.InterceptAndMap( - [call, call_spine, - channel](MessageHandle msg) -> absl::optional { - auto r = call->OnClientToServerMessage(std::move(msg), channel); - if (r.ok()) return std::move(*r); - call_spine->PushServerTrailingMetadata( - ServerMetadataFromStatus(r.status())); - return absl::nullopt; - }); + InterceptClientToServerMessageHandler(fn, call, channel, call_spine)); } +template +inline void InterceptClientToServerMessage(HookFunction fn, + void (Derived::Call::*half_close)(), + typename Derived::Call* call, + Derived* channel, + PipeBasedCallSpine* call_spine) { + DCHECK(fn == &Derived::Call::OnClientToServerMessage); + DCHECK(half_close == &Derived::Call::OnClientToServerHalfClose); + call_spine->client_to_server_messages().receiver.InterceptAndMapWithHalfClose( + InterceptClientToServerMessageHandler(fn, call, channel, call_spine), + [call]() { call->OnClientToServerHalfClose(); }); +} + +template +inline void InterceptClientToServerMessage(const NoInterceptor*, + const NoInterceptor*, + typename Derived::Call*, Derived*, + PipeBasedCallSpine*) {} + inline void InterceptClientInitialMetadata(const NoInterceptor*, void*, void*, PipeBasedCallSpine*) {} @@ -861,6 +966,18 @@ inline void InterceptServerInitialMetadata( inline void InterceptServerToClientMessage(const NoInterceptor*, void*, const CallArgs&) {} +template +inline void InterceptServerToClientMessage( + void (Derived::Call::*fn)(const Message&), + FilterCallData* call_data, const CallArgs& call_args) { + DCHECK(fn == &Derived::Call::OnServerToClientMessage); + call_args.server_to_client_messages->InterceptAndMap( + [call_data](MessageHandle msg) -> absl::optional { + call_data->call.OnServerToClientMessage(*msg); + return std::move(msg); + }); +} + template inline void InterceptServerToClientMessage( ServerMetadataHandle (Derived::Call::*fn)(const Message&), @@ -923,6 +1040,18 @@ inline void InterceptServerToClientMessage( inline void InterceptServerToClientMessage(const NoInterceptor*, void*, void*, CallSpineInterface*) {} +template +inline void InterceptServerToClientMessage( + void (Derived::Call::*fn)(const Message&), typename Derived::Call* call, + Derived*, PipeBasedCallSpine* call_spine) { + DCHECK(fn == &Derived::Call::OnServerToClientMessage); + call_spine->server_to_client_messages().sender.InterceptAndMap( + [call](MessageHandle msg) -> absl::optional { + call->OnServerToClientMessage(*msg); + return std::move(msg); + }); +} + template inline void InterceptServerToClientMessage( ServerMetadataHandle (Derived::Call::*fn)(const Message&), @@ -1120,7 +1249,8 @@ class ImplementChannelFilter : public ChannelFilter, promise_filter_detail::InterceptClientInitialMetadata( &Derived::Call::OnClientInitialMetadata, call, d, c); promise_filter_detail::InterceptClientToServerMessage( - &Derived::Call::OnClientToServerMessage, call, d, c); + &Derived::Call::OnClientToServerMessage, + &Derived::Call::OnClientToServerHalfClose, call, d, c); promise_filter_detail::InterceptServerInitialMetadata( &Derived::Call::OnServerInitialMetadata, call, d, c); promise_filter_detail::InterceptServerToClientMessage( @@ -1139,7 +1269,8 @@ class ImplementChannelFilter : public ChannelFilter, auto* call = promise_filter_detail::MakeFilterCall( static_cast(this)); promise_filter_detail::InterceptClientToServerMessage( - &Derived::Call::OnClientToServerMessage, call, call_args); + &Derived::Call::OnClientToServerMessage, + &Derived::Call::OnClientToServerHalfClose, call, call_args); promise_filter_detail::InterceptServerInitialMetadata( &Derived::Call::OnServerInitialMetadata, call, call_args); promise_filter_detail::InterceptServerToClientMessage( diff --git a/src/core/lib/channel/status_util.cc b/src/core/lib/channel/status_util.cc index f846e360edf..7c78ac5504a 100644 --- a/src/core/lib/channel/status_util.cc +++ b/src/core/lib/channel/status_util.cc @@ -27,7 +27,7 @@ #include -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" struct status_string_entry { const char* str; diff --git a/src/core/lib/compression/compression.cc b/src/core/lib/compression/compression.cc index c03c882fb9c..d3aa8878466 100644 --- a/src/core/lib/compression/compression.cc +++ b/src/core/lib/compression/compression.cc @@ -28,9 +28,9 @@ #include "src/core/lib/compression/compression_internal.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/api_trace.h" +#include "src/core/util/useful.h" int grpc_compression_algorithm_is_message(grpc_compression_algorithm) { return 1; diff --git a/src/core/lib/compression/message_compress.cc b/src/core/lib/compression/message_compress.cc index 131f89eb64f..bb806509286 100644 --- a/src/core/lib/compression/message_compress.cc +++ b/src/core/lib/compression/message_compress.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -67,12 +68,12 @@ static int zlib_body(z_stream* zs, grpc_slice_buffer* input, } } while (zs->avail_out == 0); if (zs->avail_in) { - gpr_log(GPR_INFO, "zlib: not all input consumed"); + LOG(INFO) << "zlib: not all input consumed"; goto error; } } if (r != Z_STREAM_END) { - gpr_log(GPR_INFO, "zlib: Data error"); + LOG(INFO) << "zlib: Data error"; goto error; } @@ -165,7 +166,7 @@ static int compress_inner(grpc_compression_algorithm algorithm, case GRPC_COMPRESS_ALGORITHMS_COUNT: break; } - gpr_log(GPR_ERROR, "invalid compression algorithm %d", algorithm); + LOG(ERROR) << "invalid compression algorithm " << algorithm; return 0; } @@ -190,6 +191,6 @@ int grpc_msg_decompress(grpc_compression_algorithm algorithm, case GRPC_COMPRESS_ALGORITHMS_COUNT: break; } - gpr_log(GPR_ERROR, "invalid compression algorithm %d", algorithm); + LOG(ERROR) << "invalid compression algorithm " << algorithm; return 0; } diff --git a/src/core/lib/debug/event_log.h b/src/core/lib/debug/event_log.h index 8e36b8869b4..dd8aa07aa3d 100644 --- a/src/core/lib/debug/event_log.h +++ b/src/core/lib/debug/event_log.h @@ -27,9 +27,9 @@ #include -#include "src/core/lib/gpr/time_precise.h" #include "src/core/lib/gprpp/per_cpu.h" #include "src/core/lib/gprpp/sync.h" +#include "src/core/util/time_precise.h" namespace grpc_core { diff --git a/src/core/lib/debug/trace.cc b/src/core/lib/debug/trace.cc index 5b7e189bf9c..8500def37f7 100644 --- a/src/core/lib/debug/trace.cc +++ b/src/core/lib/debug/trace.cc @@ -22,6 +22,7 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/match.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" @@ -75,9 +76,9 @@ void TraceFlagList::Add(TraceFlag* flag) { } void TraceFlagList::LogAllTracers() { - gpr_log(GPR_DEBUG, "available tracers:"); + VLOG(2) << "available tracers:"; for (TraceFlag* t = root_tracer_; t != nullptr; t = t->next_tracer_) { - gpr_log(GPR_DEBUG, "\t%s", t->name_); + VLOG(2) << "\t" << t->name_; } } diff --git a/src/core/lib/event_engine/ares_resolver.cc b/src/core/lib/event_engine/ares_resolver.cc index 4273616642c..58df73794b9 100644 --- a/src/core/lib/event_engine/ares_resolver.cc +++ b/src/core/lib/event_engine/ares_resolver.cc @@ -53,6 +53,7 @@ #include "absl/functional/any_invocable.h" #include "absl/hash/hash.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/match.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" @@ -200,7 +201,7 @@ AresResolver::CreateAresResolver( ares_channel channel; int status = ares_init_options(&channel, &opts, ARES_OPT_FLAGS); if (status != ARES_SUCCESS) { - gpr_log(GPR_ERROR, "ares_init_options failed, status: %d", status); + LOG(ERROR) << "ares_init_options failed, status: " << status; return AresStatusToAbslStatus( status, absl::StrCat("Failed to init c-ares channel: ", ares_strerror(status))); @@ -769,7 +770,7 @@ void AresResolver::OnTXTDoneLocked(void* arg, int status, int /*timeouts*/, result.size()); if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_ares_resolver)) { for (const auto& record : result) { - gpr_log(GPR_INFO, "%s", record.c_str()); + LOG(INFO) << record; } } // Clean up. diff --git a/src/core/lib/event_engine/extensions/supports_fd.h b/src/core/lib/event_engine/extensions/supports_fd.h index 66ea1c2b345..30f0d2ad0e6 100644 --- a/src/core/lib/event_engine/extensions/supports_fd.h +++ b/src/core/lib/event_engine/extensions/supports_fd.h @@ -112,6 +112,13 @@ class EventEngineSupportsFdExtension { int fd, const EndpointConfig& config, MemoryAllocator memory_allocator) = 0; + /// Creates an EventEngine::Endpoint from an fd which is already assumed to be + /// connected to a remote peer. See \a CreatePosixEndpointFromFd for details. + /// This has the same behavior, but the \a memory_allocator is taken from the + /// EndpointConfig's resource quota. + virtual std::unique_ptr CreateEndpointFromFd( + int fd, const EndpointConfig& config) = 0; + /// Called when the posix listener has accepted a new client connection. /// \a listener_fd - The listening socket fd that accepted the new client /// connection. diff --git a/src/core/lib/event_engine/posix_engine/native_posix_dns_resolver.cc b/src/core/lib/event_engine/posix_engine/native_posix_dns_resolver.cc index 344471564e1..4e0f66fc1f7 100644 --- a/src/core/lib/event_engine/posix_engine/native_posix_dns_resolver.cc +++ b/src/core/lib/event_engine/posix_engine/native_posix_dns_resolver.cc @@ -34,8 +34,8 @@ #include "absl/strings/str_format.h" #include "src/core/lib/event_engine/posix_engine/native_posix_dns_resolver.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/host_port.h" +#include "src/core/util/useful.h" namespace grpc_event_engine { namespace experimental { diff --git a/src/core/lib/event_engine/posix_engine/posix_endpoint.cc b/src/core/lib/event_engine/posix_engine/posix_endpoint.cc index 7c8dd72052a..18d7dfb4623 100644 --- a/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +++ b/src/core/lib/event_engine/posix_engine/posix_endpoint.cc @@ -27,6 +27,7 @@ #include "absl/functional/any_invocable.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" @@ -718,7 +719,7 @@ bool PosixEndpointImpl::ProcessErrors() { 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) { @@ -813,7 +814,7 @@ struct cmsghdr* PosixEndpointImpl::ProcessTimestamp(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; } traced_buffers_.ProcessTimestamp(serr, opt_stats, tss); @@ -1303,7 +1304,7 @@ PosixEndpointImpl::PosixEndpointImpl(EventHandle* handle, if (setsockopt(fd_, SOL_SOCKET, SO_ZEROCOPY, &enable, sizeof(enable)) != 0) { zerocopy_enabled = false; - gpr_log(GPR_ERROR, "Failed to set zerocopy options on the socket."); + LOG(ERROR) << "Failed to set zerocopy options on the socket."; } } diff --git a/src/core/lib/event_engine/posix_engine/posix_endpoint.h b/src/core/lib/event_engine/posix_engine/posix_endpoint.h index c85c81e1eb1..9a0ca6b8db4 100644 --- a/src/core/lib/event_engine/posix_engine/posix_endpoint.h +++ b/src/core/lib/event_engine/posix_engine/posix_endpoint.h @@ -30,6 +30,7 @@ #include "absl/functional/any_invocable.h" #include "absl/hash/hash.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -183,7 +184,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; enabled_ = false; } else { diff --git a/src/core/lib/event_engine/posix_engine/posix_engine.cc b/src/core/lib/event_engine/posix_engine/posix_engine.cc index e96c969617c..f5c1bf6c3d2 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine.cc +++ b/src/core/lib/event_engine/posix_engine/posix_engine.cc @@ -26,6 +26,7 @@ #include "absl/cleanup/cleanup.h" #include "absl/functional/any_invocable.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -51,10 +52,10 @@ #include "src/core/lib/event_engine/tcp_socket_utils.h" #include "src/core/lib/event_engine/trace.h" #include "src/core/lib/event_engine/utils.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/no_destruct.h" #include "src/core/lib/gprpp/sync.h" +#include "src/core/util/useful.h" #ifdef GRPC_POSIX_SOCKET_TCP #include // IWYU pragma: keep @@ -231,7 +232,7 @@ void AsyncConnect::OnWritable(absl::Status status) // your program or another program on the same computer // opened too many network connections. The "easy" fix: // don't do that! - gpr_log(GPR_ERROR, "kernel out of buffers"); + LOG(ERROR) << "kernel out of buffers"; mu_.Unlock(); fd->NotifyOnWrite(on_writable_); // Don't run the cleanup function for this case. @@ -677,6 +678,22 @@ PosixEventEngine::CreatePosixEndpointFromFd(int fd, #endif // GRPC_PLATFORM_SUPPORTS_POSIX_POLLING } +std::unique_ptr PosixEventEngine::CreateEndpointFromFd( + int fd, const EndpointConfig& config) { + auto options = TcpOptionsFromEndpointConfig(config); + MemoryAllocator allocator; + if (options.memory_allocator_factory != nullptr) { + return CreatePosixEndpointFromFd( + fd, config, + options.memory_allocator_factory->CreateMemoryAllocator( + absl::StrCat("allocator:", fd))); + } + return CreatePosixEndpointFromFd( + fd, config, + options.resource_quota->memory_quota()->CreateMemoryAllocator( + absl::StrCat("allocator:", fd))); +} + absl::StatusOr> PosixEventEngine::CreateListener( Listener::AcceptCallback on_accept, diff --git a/src/core/lib/event_engine/posix_engine/posix_engine.h b/src/core/lib/event_engine/posix_engine/posix_engine.h index 257cd6b34b5..ea426c379c9 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine.h +++ b/src/core/lib/event_engine/posix_engine/posix_engine.h @@ -172,6 +172,8 @@ class PosixEventEngine final : public PosixEventEngineWithFdSupport, std::unique_ptr CreatePosixEndpointFromFd( int fd, const EndpointConfig& config, MemoryAllocator memory_allocator) override; + std::unique_ptr CreateEndpointFromFd( + int fd, const EndpointConfig& config) override; absl::StatusOr> CreateListener( Listener::AcceptCallback on_accept, diff --git a/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc b/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc index cbd8902d325..ebcbec1771b 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc +++ b/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc @@ -23,6 +23,7 @@ #include "absl/cleanup/cleanup.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_replace.h" @@ -156,7 +157,7 @@ absl::Status PrepareSocket(const PosixTcpOptions& options, #ifdef GRPC_LINUX_ERRQUEUE if (!socket.sock.SetSocketZeroCopy().ok()) { // it's not fatal, so just log it. - gpr_log(GPR_DEBUG, "Node does not support SO_ZEROCOPY, continuing."); + VLOG(2) << "Node does not support SO_ZEROCOPY, continuing."; } else { socket.zero_copy_enabled = true; } @@ -244,7 +245,7 @@ absl::StatusOr ListenerContainerAddAllLocalAddresses( auto result = GetUnusedPort(); GRPC_RETURN_IF_ERROR(result.status()); requested_port = *result; - gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port); + VLOG(2) << "Picked unused port " << requested_port; } if (getifaddrs(&ifa) != 0 || ifa == nullptr) { return absl::FailedPreconditionError( diff --git a/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc b/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc index 4fd73bc80cc..987a010084c 100644 --- a/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +++ b/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc @@ -18,6 +18,7 @@ #include #include "absl/cleanup/cleanup.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/types/optional.h" @@ -27,10 +28,10 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" // IWYU pragma: keep #include "src/core/lib/gprpp/time.h" #include "src/core/lib/iomgr/port.h" +#include "src/core/util/useful.h" #ifdef GRPC_POSIX_SOCKET_UTILS_COMMON #include // IWYU pragma: keep @@ -653,7 +654,7 @@ void PosixSocketWrapper::TrySetSocketTcpUserTimeout( } if (newval != timeout) { // Do not fail on failing to set TCP_USER_TIMEOUT - gpr_log(GPR_ERROR, "Failed to set TCP_USER_TIMEOUT"); + LOG(ERROR) << "Failed to set TCP_USER_TIMEOUT"; return; } } @@ -684,7 +685,7 @@ bool PosixSocketWrapper::IsIpv6LoopbackAvailable() { int fd = socket(AF_INET6, SOCK_STREAM, 0); bool loopback_available = false; if (fd < 0) { - gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed."); + LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed."; } else { sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); diff --git a/src/core/lib/event_engine/posix_engine/timer.cc b/src/core/lib/event_engine/posix_engine/timer.cc index 0473d3c0a6e..6f152ce494a 100644 --- a/src/core/lib/event_engine/posix_engine/timer.cc +++ b/src/core/lib/event_engine/posix_engine/timer.cc @@ -27,8 +27,8 @@ #include #include "src/core/lib/event_engine/posix_engine/timer_heap.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/time.h" +#include "src/core/util/useful.h" namespace grpc_event_engine { namespace experimental { diff --git a/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc b/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc index 314e451c664..1171cb76624 100644 --- a/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc +++ b/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc @@ -22,6 +22,7 @@ #include #include "absl/functional/any_invocable.h" +#include "absl/log/log.h" #include #include @@ -48,7 +49,7 @@ void FillGprFromTimestamp(gpr_timespec* gts, const struct timespec* ts) { void DefaultTimestampsCallback(void* /*arg*/, Timestamps* /*ts*/, absl::Status /*shudown_err*/) { - gpr_log(GPR_DEBUG, "Timestamps callback has not been registered"); + VLOG(2) << "Timestamps callback has not been registered"; } // The saved callback function that will be invoked when we get all the diff --git a/src/core/lib/event_engine/thread_pool/thread_count.h b/src/core/lib/event_engine/thread_pool/thread_count.h index 4e8754095c5..a3842275e7e 100644 --- a/src/core/lib/event_engine/thread_pool/thread_count.h +++ b/src/core/lib/event_engine/thread_pool/thread_count.h @@ -26,9 +26,9 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/sync.h" #include "src/core/lib/gprpp/time.h" +#include "src/core/util/useful.h" namespace grpc_event_engine { namespace experimental { diff --git a/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc b/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc index eeaed8abb3c..f22f9484d32 100644 --- a/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc +++ b/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc @@ -27,6 +27,7 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/time/clock.h" #include "absl/time/time.h" #include "absl/types/optional.h" @@ -267,7 +268,7 @@ void WorkStealingThreadPool::WorkStealingThreadPoolImpl::StartThread() { } void WorkStealingThreadPool::WorkStealingThreadPoolImpl::Quiesce() { - gpr_log(GPR_INFO, "WorkStealingThreadPoolImpl::Quiesce"); + LOG(INFO) << "WorkStealingThreadPoolImpl::Quiesce"; SetShutdown(true); // Wait until all threads have exited. // Note that if this is a threadpool thread then we won't exit this thread @@ -319,7 +320,7 @@ bool WorkStealingThreadPool::WorkStealingThreadPoolImpl::IsQuiesced() { } void WorkStealingThreadPool::WorkStealingThreadPoolImpl::PrepareFork() { - gpr_log(GPR_INFO, "WorkStealingThreadPoolImpl::PrepareFork"); + LOG(INFO) << "WorkStealingThreadPoolImpl::PrepareFork"; SetForking(true); work_signal_.SignalAll(); auto threads_were_shut_down = living_thread_count_.BlockUntilThreadCount( diff --git a/src/core/lib/experiments/experiments.cc b/src/core/lib/experiments/experiments.cc index 3f9e6a840ca..468884ec583 100644 --- a/src/core/lib/experiments/experiments.cc +++ b/src/core/lib/experiments/experiments.cc @@ -70,14 +70,6 @@ const char* const description_peer_state_based_framing = "on the peer's memory pressure which is reflected in its max http2 frame " "size."; const char* const additional_constraints_peer_state_based_framing = "{}"; -const char* const description_pending_queue_cap = - "In the sync & async apis (but not the callback api), cap the number of " - "received but unrequested requests in the server for each call type. A " - "received message is one that was read from the wire on the server. A " - "requested message is one explicitly requested by the application using " - "grpc_server_request_call or grpc_server_request_registered_call (or their " - "wrappers in the C++ API)."; -const char* const additional_constraints_pending_queue_cap = "{}"; const char* const description_pick_first_new = "New pick_first impl with memory reduction."; const char* const additional_constraints_pick_first_new = "{}"; @@ -88,23 +80,17 @@ const char* const additional_constraints_promise_based_client_call = "{}"; const uint8_t required_experiments_promise_based_client_call[] = { static_cast(grpc_core::kExperimentIdEventEngineClient), static_cast(grpc_core::kExperimentIdEventEngineListener)}; -const char* const description_promise_based_server_call = - "If set, use the new gRPC promise based call code when it's appropriate " - "(ie when all filters in a stack are promise based)"; -const char* const additional_constraints_promise_based_server_call = "{}"; const char* const description_chaotic_good = "If set, enable the chaotic good load transport (this is mostly here for " "testing)"; const char* const additional_constraints_chaotic_good = "{}"; const uint8_t required_experiments_chaotic_good[] = { - static_cast(grpc_core::kExperimentIdPromiseBasedClientCall), - static_cast(grpc_core::kExperimentIdPromiseBasedServerCall)}; + static_cast(grpc_core::kExperimentIdPromiseBasedClientCall)}; const char* const description_promise_based_inproc_transport = "Use promises for the in-process transport."; const char* const additional_constraints_promise_based_inproc_transport = "{}"; const uint8_t required_experiments_promise_based_inproc_transport[] = { - static_cast(grpc_core::kExperimentIdPromiseBasedClientCall), - static_cast(grpc_core::kExperimentIdPromiseBasedServerCall)}; + static_cast(grpc_core::kExperimentIdPromiseBasedClientCall)}; const char* const description_rstpit = "On RST_STREAM on a server, reduce MAX_CONCURRENT_STREAMS for a short " "duration"; @@ -177,22 +163,18 @@ const ExperimentMetadata g_experiment_metadata[] = { nullptr, 0, false, true}, {"peer_state_based_framing", description_peer_state_based_framing, additional_constraints_peer_state_based_framing, nullptr, 0, false, true}, - {"pending_queue_cap", description_pending_queue_cap, - additional_constraints_pending_queue_cap, nullptr, 0, true, true}, {"pick_first_new", description_pick_first_new, additional_constraints_pick_first_new, nullptr, 0, true, true}, {"promise_based_client_call", description_promise_based_client_call, additional_constraints_promise_based_client_call, required_experiments_promise_based_client_call, 2, false, true}, - {"promise_based_server_call", description_promise_based_server_call, - additional_constraints_promise_based_server_call, nullptr, 0, false, true}, {"chaotic_good", description_chaotic_good, - additional_constraints_chaotic_good, required_experiments_chaotic_good, 2, + additional_constraints_chaotic_good, required_experiments_chaotic_good, 1, false, true}, {"promise_based_inproc_transport", description_promise_based_inproc_transport, additional_constraints_promise_based_inproc_transport, - required_experiments_promise_based_inproc_transport, 2, false, false}, + required_experiments_promise_based_inproc_transport, 1, false, false}, {"rstpit", description_rstpit, additional_constraints_rstpit, nullptr, 0, false, true}, {"schedule_cancellation_over_write", @@ -270,14 +252,6 @@ const char* const description_peer_state_based_framing = "on the peer's memory pressure which is reflected in its max http2 frame " "size."; const char* const additional_constraints_peer_state_based_framing = "{}"; -const char* const description_pending_queue_cap = - "In the sync & async apis (but not the callback api), cap the number of " - "received but unrequested requests in the server for each call type. A " - "received message is one that was read from the wire on the server. A " - "requested message is one explicitly requested by the application using " - "grpc_server_request_call or grpc_server_request_registered_call (or their " - "wrappers in the C++ API)."; -const char* const additional_constraints_pending_queue_cap = "{}"; const char* const description_pick_first_new = "New pick_first impl with memory reduction."; const char* const additional_constraints_pick_first_new = "{}"; @@ -288,23 +262,17 @@ const char* const additional_constraints_promise_based_client_call = "{}"; const uint8_t required_experiments_promise_based_client_call[] = { static_cast(grpc_core::kExperimentIdEventEngineClient), static_cast(grpc_core::kExperimentIdEventEngineListener)}; -const char* const description_promise_based_server_call = - "If set, use the new gRPC promise based call code when it's appropriate " - "(ie when all filters in a stack are promise based)"; -const char* const additional_constraints_promise_based_server_call = "{}"; const char* const description_chaotic_good = "If set, enable the chaotic good load transport (this is mostly here for " "testing)"; const char* const additional_constraints_chaotic_good = "{}"; const uint8_t required_experiments_chaotic_good[] = { - static_cast(grpc_core::kExperimentIdPromiseBasedClientCall), - static_cast(grpc_core::kExperimentIdPromiseBasedServerCall)}; + static_cast(grpc_core::kExperimentIdPromiseBasedClientCall)}; const char* const description_promise_based_inproc_transport = "Use promises for the in-process transport."; const char* const additional_constraints_promise_based_inproc_transport = "{}"; const uint8_t required_experiments_promise_based_inproc_transport[] = { - static_cast(grpc_core::kExperimentIdPromiseBasedClientCall), - static_cast(grpc_core::kExperimentIdPromiseBasedServerCall)}; + static_cast(grpc_core::kExperimentIdPromiseBasedClientCall)}; const char* const description_rstpit = "On RST_STREAM on a server, reduce MAX_CONCURRENT_STREAMS for a short " "duration"; @@ -358,9 +326,9 @@ const ExperimentMetadata g_experiment_metadata[] = { {"client_privacy", description_client_privacy, additional_constraints_client_privacy, nullptr, 0, false, false}, {"event_engine_client", description_event_engine_client, - additional_constraints_event_engine_client, nullptr, 0, false, true}, + additional_constraints_event_engine_client, nullptr, 0, true, true}, {"event_engine_dns", description_event_engine_dns, - additional_constraints_event_engine_dns, nullptr, 0, false, false}, + additional_constraints_event_engine_dns, nullptr, 0, true, false}, {"event_engine_listener", description_event_engine_listener, additional_constraints_event_engine_listener, nullptr, 0, true, true}, {"free_large_allocator", description_free_large_allocator, @@ -377,22 +345,18 @@ const ExperimentMetadata g_experiment_metadata[] = { nullptr, 0, false, true}, {"peer_state_based_framing", description_peer_state_based_framing, additional_constraints_peer_state_based_framing, nullptr, 0, false, true}, - {"pending_queue_cap", description_pending_queue_cap, - additional_constraints_pending_queue_cap, nullptr, 0, true, true}, {"pick_first_new", description_pick_first_new, additional_constraints_pick_first_new, nullptr, 0, true, true}, {"promise_based_client_call", description_promise_based_client_call, additional_constraints_promise_based_client_call, required_experiments_promise_based_client_call, 2, false, true}, - {"promise_based_server_call", description_promise_based_server_call, - additional_constraints_promise_based_server_call, nullptr, 0, false, true}, {"chaotic_good", description_chaotic_good, - additional_constraints_chaotic_good, required_experiments_chaotic_good, 2, + additional_constraints_chaotic_good, required_experiments_chaotic_good, 1, false, true}, {"promise_based_inproc_transport", description_promise_based_inproc_transport, additional_constraints_promise_based_inproc_transport, - required_experiments_promise_based_inproc_transport, 2, false, false}, + required_experiments_promise_based_inproc_transport, 1, false, false}, {"rstpit", description_rstpit, additional_constraints_rstpit, nullptr, 0, false, true}, {"schedule_cancellation_over_write", @@ -470,14 +434,6 @@ const char* const description_peer_state_based_framing = "on the peer's memory pressure which is reflected in its max http2 frame " "size."; const char* const additional_constraints_peer_state_based_framing = "{}"; -const char* const description_pending_queue_cap = - "In the sync & async apis (but not the callback api), cap the number of " - "received but unrequested requests in the server for each call type. A " - "received message is one that was read from the wire on the server. A " - "requested message is one explicitly requested by the application using " - "grpc_server_request_call or grpc_server_request_registered_call (or their " - "wrappers in the C++ API)."; -const char* const additional_constraints_pending_queue_cap = "{}"; const char* const description_pick_first_new = "New pick_first impl with memory reduction."; const char* const additional_constraints_pick_first_new = "{}"; @@ -488,23 +444,17 @@ const char* const additional_constraints_promise_based_client_call = "{}"; const uint8_t required_experiments_promise_based_client_call[] = { static_cast(grpc_core::kExperimentIdEventEngineClient), static_cast(grpc_core::kExperimentIdEventEngineListener)}; -const char* const description_promise_based_server_call = - "If set, use the new gRPC promise based call code when it's appropriate " - "(ie when all filters in a stack are promise based)"; -const char* const additional_constraints_promise_based_server_call = "{}"; const char* const description_chaotic_good = "If set, enable the chaotic good load transport (this is mostly here for " "testing)"; const char* const additional_constraints_chaotic_good = "{}"; const uint8_t required_experiments_chaotic_good[] = { - static_cast(grpc_core::kExperimentIdPromiseBasedClientCall), - static_cast(grpc_core::kExperimentIdPromiseBasedServerCall)}; + static_cast(grpc_core::kExperimentIdPromiseBasedClientCall)}; const char* const description_promise_based_inproc_transport = "Use promises for the in-process transport."; const char* const additional_constraints_promise_based_inproc_transport = "{}"; const uint8_t required_experiments_promise_based_inproc_transport[] = { - static_cast(grpc_core::kExperimentIdPromiseBasedClientCall), - static_cast(grpc_core::kExperimentIdPromiseBasedServerCall)}; + static_cast(grpc_core::kExperimentIdPromiseBasedClientCall)}; const char* const description_rstpit = "On RST_STREAM on a server, reduce MAX_CONCURRENT_STREAMS for a short " "duration"; @@ -577,22 +527,18 @@ const ExperimentMetadata g_experiment_metadata[] = { nullptr, 0, false, true}, {"peer_state_based_framing", description_peer_state_based_framing, additional_constraints_peer_state_based_framing, nullptr, 0, false, true}, - {"pending_queue_cap", description_pending_queue_cap, - additional_constraints_pending_queue_cap, nullptr, 0, true, true}, {"pick_first_new", description_pick_first_new, additional_constraints_pick_first_new, nullptr, 0, true, true}, {"promise_based_client_call", description_promise_based_client_call, additional_constraints_promise_based_client_call, required_experiments_promise_based_client_call, 2, false, true}, - {"promise_based_server_call", description_promise_based_server_call, - additional_constraints_promise_based_server_call, nullptr, 0, false, true}, {"chaotic_good", description_chaotic_good, - additional_constraints_chaotic_good, required_experiments_chaotic_good, 2, + additional_constraints_chaotic_good, required_experiments_chaotic_good, 1, false, true}, {"promise_based_inproc_transport", description_promise_based_inproc_transport, additional_constraints_promise_based_inproc_transport, - required_experiments_promise_based_inproc_transport, 2, false, false}, + required_experiments_promise_based_inproc_transport, 1, false, false}, {"rstpit", description_rstpit, additional_constraints_rstpit, nullptr, 0, false, true}, {"schedule_cancellation_over_write", diff --git a/src/core/lib/experiments/experiments.h b/src/core/lib/experiments/experiments.h index faf13fca4cf..9e3ba9148ba 100644 --- a/src/core/lib/experiments/experiments.h +++ b/src/core/lib/experiments/experiments.h @@ -74,12 +74,9 @@ inline bool IsKeepaliveServerFixEnabled() { return false; } inline bool IsMonitoringExperimentEnabled() { return true; } inline bool IsMultipingEnabled() { return false; } inline bool IsPeerStateBasedFramingEnabled() { return false; } -#define GRPC_EXPERIMENT_IS_INCLUDED_PENDING_QUEUE_CAP -inline bool IsPendingQueueCapEnabled() { return true; } #define GRPC_EXPERIMENT_IS_INCLUDED_PICK_FIRST_NEW inline bool IsPickFirstNewEnabled() { return true; } inline bool IsPromiseBasedClientCallEnabled() { return false; } -inline bool IsPromiseBasedServerCallEnabled() { return false; } inline bool IsChaoticGoodEnabled() { return false; } inline bool IsPromiseBasedInprocTransportEnabled() { return false; } inline bool IsRstpitEnabled() { return false; } @@ -100,8 +97,10 @@ inline bool IsCallStatusOverrideOnCancellationEnabled() { return true; } inline bool IsCallV3Enabled() { return false; } inline bool IsCanaryClientPrivacyEnabled() { return false; } inline bool IsClientPrivacyEnabled() { return false; } -inline bool IsEventEngineClientEnabled() { return false; } -inline bool IsEventEngineDnsEnabled() { return false; } +#define GRPC_EXPERIMENT_IS_INCLUDED_EVENT_ENGINE_CLIENT +inline bool IsEventEngineClientEnabled() { return true; } +#define GRPC_EXPERIMENT_IS_INCLUDED_EVENT_ENGINE_DNS +inline bool IsEventEngineDnsEnabled() { return true; } #define GRPC_EXPERIMENT_IS_INCLUDED_EVENT_ENGINE_LISTENER inline bool IsEventEngineListenerEnabled() { return true; } inline bool IsFreeLargeAllocatorEnabled() { return false; } @@ -113,12 +112,9 @@ inline bool IsKeepaliveServerFixEnabled() { return false; } inline bool IsMonitoringExperimentEnabled() { return true; } inline bool IsMultipingEnabled() { return false; } inline bool IsPeerStateBasedFramingEnabled() { return false; } -#define GRPC_EXPERIMENT_IS_INCLUDED_PENDING_QUEUE_CAP -inline bool IsPendingQueueCapEnabled() { return true; } #define GRPC_EXPERIMENT_IS_INCLUDED_PICK_FIRST_NEW inline bool IsPickFirstNewEnabled() { return true; } inline bool IsPromiseBasedClientCallEnabled() { return false; } -inline bool IsPromiseBasedServerCallEnabled() { return false; } inline bool IsChaoticGoodEnabled() { return false; } inline bool IsPromiseBasedInprocTransportEnabled() { return false; } inline bool IsRstpitEnabled() { return false; } @@ -153,12 +149,9 @@ inline bool IsKeepaliveServerFixEnabled() { return false; } inline bool IsMonitoringExperimentEnabled() { return true; } inline bool IsMultipingEnabled() { return false; } inline bool IsPeerStateBasedFramingEnabled() { return false; } -#define GRPC_EXPERIMENT_IS_INCLUDED_PENDING_QUEUE_CAP -inline bool IsPendingQueueCapEnabled() { return true; } #define GRPC_EXPERIMENT_IS_INCLUDED_PICK_FIRST_NEW inline bool IsPickFirstNewEnabled() { return true; } inline bool IsPromiseBasedClientCallEnabled() { return false; } -inline bool IsPromiseBasedServerCallEnabled() { return false; } inline bool IsChaoticGoodEnabled() { return false; } inline bool IsPromiseBasedInprocTransportEnabled() { return false; } inline bool IsRstpitEnabled() { return false; } @@ -191,10 +184,8 @@ enum ExperimentIds { kExperimentIdMonitoringExperiment, kExperimentIdMultiping, kExperimentIdPeerStateBasedFraming, - kExperimentIdPendingQueueCap, kExperimentIdPickFirstNew, kExperimentIdPromiseBasedClientCall, - kExperimentIdPromiseBasedServerCall, kExperimentIdChaoticGood, kExperimentIdPromiseBasedInprocTransport, kExperimentIdRstpit, @@ -264,10 +255,6 @@ inline bool IsMultipingEnabled() { inline bool IsPeerStateBasedFramingEnabled() { return IsExperimentEnabled(kExperimentIdPeerStateBasedFraming); } -#define GRPC_EXPERIMENT_IS_INCLUDED_PENDING_QUEUE_CAP -inline bool IsPendingQueueCapEnabled() { - return IsExperimentEnabled(kExperimentIdPendingQueueCap); -} #define GRPC_EXPERIMENT_IS_INCLUDED_PICK_FIRST_NEW inline bool IsPickFirstNewEnabled() { return IsExperimentEnabled(kExperimentIdPickFirstNew); @@ -276,10 +263,6 @@ inline bool IsPickFirstNewEnabled() { inline bool IsPromiseBasedClientCallEnabled() { return IsExperimentEnabled(kExperimentIdPromiseBasedClientCall); } -#define GRPC_EXPERIMENT_IS_INCLUDED_PROMISE_BASED_SERVER_CALL -inline bool IsPromiseBasedServerCallEnabled() { - return IsExperimentEnabled(kExperimentIdPromiseBasedServerCall); -} #define GRPC_EXPERIMENT_IS_INCLUDED_CHAOTIC_GOOD inline bool IsChaoticGoodEnabled() { return IsExperimentEnabled(kExperimentIdChaoticGood); diff --git a/src/core/lib/experiments/experiments.yaml b/src/core/lib/experiments/experiments.yaml index 0712c8afd85..4d1a27e4d3c 100644 --- a/src/core/lib/experiments/experiments.yaml +++ b/src/core/lib/experiments/experiments.yaml @@ -64,7 +64,7 @@ If set, enable the chaotic good load transport (this is mostly here for testing) expiry: 2024/09/09 owner: ctiller@google.com - requires: [promise_based_client_call, promise_based_server_call] + requires: [promise_based_client_call] test_tags: [core_end2end_test] - name: client_privacy description: @@ -139,17 +139,6 @@ expiry: 2024/08/01 owner: vigneshbabu@google.com test_tags: ["flow_control_test"] -- name: pending_queue_cap - description: - In the sync & async apis (but not the callback api), cap the number of - received but unrequested requests in the server for each call type. - A received message is one that was read from the wire on the server. - A requested message is one explicitly requested by the application using - grpc_server_request_call or grpc_server_request_registered_call (or their - wrappers in the C++ API). - expiry: 2024/05/05 - owner: ctiller@google.com - test_tags: [] - name: pick_first_new description: New pick_first impl with memory reduction. expiry: 2024/07/30 @@ -170,14 +159,7 @@ owner: ctiller@google.com test_tags: [] allow_in_fuzzing_config: false # experiment currently crashes if enabled - requires: [promise_based_client_call, promise_based_server_call] -- name: promise_based_server_call - description: - If set, use the new gRPC promise based call code when it's appropriate - (ie when all filters in a stack are promise based) - expiry: 2024/06/14 - owner: ctiller@google.com - test_tags: ["core_end2end_test", "logging_test"] + requires: [promise_based_client_call] - name: rstpit description: On RST_STREAM on a server, reduce MAX_CONCURRENT_STREAMS for a short duration diff --git a/src/core/lib/experiments/rollouts.yaml b/src/core/lib/experiments/rollouts.yaml index 6f4e84827f0..7187f8c2952 100644 --- a/src/core/lib/experiments/rollouts.yaml +++ b/src/core/lib/experiments/rollouts.yaml @@ -58,17 +58,13 @@ # not tested on iOS at all ios: broken posix: false - # TODO(hork): resolve when the client end2end test flake rate reduces to - # a tolerable amount. - windows: false + windows: true - name: event_engine_dns default: # not tested on iOS at all ios: broken posix: true - # TODO(yijiem): resolve when the WindowsEventEngine DNS Resolver is - # implemented - windows: broken + windows: true - name: event_engine_listener default: # not tested on iOS at all @@ -96,8 +92,6 @@ ios: broken windows: broken posix: false -- name: promise_based_server_call - default: false - name: rstpit default: false - name: schedule_cancellation_over_write diff --git a/src/core/lib/gprpp/bitset.h b/src/core/lib/gprpp/bitset.h index 7cd96a4842a..ea941b0e10b 100644 --- a/src/core/lib/gprpp/bitset.h +++ b/src/core/lib/gprpp/bitset.h @@ -22,7 +22,7 @@ #include -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" namespace grpc_core { 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/gprpp/per_cpu.cc b/src/core/lib/gprpp/per_cpu.cc index 688fe2483a5..4cd06fd6513 100644 --- a/src/core/lib/gprpp/per_cpu.cc +++ b/src/core/lib/gprpp/per_cpu.cc @@ -17,7 +17,7 @@ #include #include -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/lib/gprpp/posix/thd.cc b/src/core/lib/gprpp/posix/thd.cc index be3f8224ea0..dd3124fad25 100644 --- a/src/core/lib/gprpp/posix/thd.cc +++ b/src/core/lib/gprpp/posix/thd.cc @@ -33,17 +33,18 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" // IWYU pragma: keep #include #include #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/fork.h" #include "src/core/lib/gprpp/strerror.h" #include "src/core/lib/gprpp/thd.h" +#include "src/core/util/useful.h" namespace grpc_core { namespace { @@ -213,7 +214,7 @@ void Thread::Kill(gpr_thd_id tid) { } #else // GPR_ANDROID void Thread::Kill(gpr_thd_id /* tid */) { - gpr_log(GPR_DEBUG, "Thread::Kill is not supported on Android."); + VLOG(2) << "Thread::Kill is not supported on Android."; } #endif diff --git a/src/core/lib/gprpp/time.h b/src/core/lib/gprpp/time.h index 35b762963b3..96963753d38 100644 --- a/src/core/lib/gprpp/time.h +++ b/src/core/lib/gprpp/time.h @@ -27,8 +27,8 @@ #include #include -#include "src/core/lib/gpr/time_precise.h" -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/time_precise.h" +#include "src/core/util/useful.h" #define GRPC_LOG_EVERY_N_SEC(n, severity, format, ...) \ do { \ diff --git a/src/core/lib/gprpp/unique_type_name.h b/src/core/lib/gprpp/unique_type_name.h index 9b7330cc792..2e71ab73f07 100644 --- a/src/core/lib/gprpp/unique_type_name.h +++ b/src/core/lib/gprpp/unique_type_name.h @@ -23,7 +23,7 @@ #include -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" // Provides a type name that is unique by instance rather than by // string content. This is useful in cases where there are different diff --git a/src/core/lib/gprpp/windows/thd.cc b/src/core/lib/gprpp/windows/thd.cc index 20a060f2b33..b5c6368cf40 100644 --- a/src/core/lib/gprpp/windows/thd.cc +++ b/src/core/lib/gprpp/windows/thd.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -149,12 +150,12 @@ namespace grpc_core { void Thread::Signal(gpr_thd_id /* tid */, int /* sig */) { // TODO(hork): Implement - gpr_log(GPR_DEBUG, "Thread signals are not supported on Windows."); + VLOG(2) << "Thread signals are not supported on Windows."; } void Thread::Kill(gpr_thd_id /* tid */) { // TODO(hork): Implement - gpr_log(GPR_DEBUG, "Thread::Kill is not supported on Windows."); + VLOG(2) << "Thread::Kill is not supported on Windows."; } Thread::Thread(const char* /* thd_name */, void (*thd_body)(void* arg), diff --git a/src/core/lib/gprpp/work_serializer.cc b/src/core/lib/gprpp/work_serializer.cc index 605877fddcd..88c10c00a8a 100644 --- a/src/core/lib/gprpp/work_serializer.cc +++ b/src/core/lib/gprpp/work_serializer.cc @@ -28,6 +28,7 @@ #include "absl/container/inlined_vector.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -151,7 +152,7 @@ void WorkSerializer::LegacyWorkSerializer::Run(std::function callback, // We took ownership of the WorkSerializer. Invoke callback and drain queue. SetCurrentThread(); if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) { - gpr_log(GPR_INFO, " Executing immediately"); + LOG(INFO) << " Executing immediately"; } callback(); // Delete the callback while still holding the WorkSerializer, so @@ -193,7 +194,7 @@ void WorkSerializer::LegacyWorkSerializer::Orphan() { refs_.fetch_sub(MakeRefPair(0, 1), std::memory_order_acq_rel); if (GetOwners(prev_ref_pair) == 0 && GetSize(prev_ref_pair) == 1) { if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) { - gpr_log(GPR_INFO, " Destroying"); + LOG(INFO) << " Destroying"; } delete this; } @@ -232,7 +233,7 @@ void WorkSerializer::LegacyWorkSerializer::DrainQueueOwned() { // up orphaning the work serializer. In that case, delete the object. if (GetSize(prev_ref_pair) == 1) { if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) { - gpr_log(GPR_INFO, " Queue Drained. Destroying"); + LOG(INFO) << " Queue Drained. Destroying"; } delete this; return; @@ -252,7 +253,7 @@ void WorkSerializer::LegacyWorkSerializer::DrainQueueOwned() { if (GetSize(expected) == 0) { // WorkSerializer got orphaned while this was running if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) { - gpr_log(GPR_INFO, " Queue Drained. Destroying"); + LOG(INFO) << " Queue Drained. Destroying"; } delete this; return; @@ -272,7 +273,7 @@ void WorkSerializer::LegacyWorkSerializer::DrainQueueOwned() { // This can happen due to a race condition within the mpscq // implementation or because of a race with Run()/Schedule(). if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) { - gpr_log(GPR_INFO, " Queue returned nullptr, trying again"); + LOG(INFO) << " Queue returned nullptr, trying again"; } } if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) { diff --git a/src/core/lib/http/httpcli_security_connector.cc b/src/core/lib/http/httpcli_security_connector.cc index 36b8cd84857..7db2021b71c 100644 --- a/src/core/lib/http/httpcli_security_connector.cc +++ b/src/core/lib/http/httpcli_security_connector.cc @@ -20,6 +20,7 @@ #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -173,7 +174,7 @@ class HttpRequestSSLCredentials : public grpc_channel_credentials { const tsi_ssl_root_certs_store* root_store = DefaultSslRootStore::GetRootStore(); if (root_store == nullptr) { - gpr_log(GPR_ERROR, "Could not get default pem root certs."); + LOG(ERROR) << "Could not get default pem root certs."; return nullptr; } absl::optional target_string = diff --git a/src/core/lib/iomgr/buffer_list.cc b/src/core/lib/iomgr/buffer_list.cc index 6de9d89c05b..aedb4227073 100644 --- a/src/core/lib/iomgr/buffer_list.cc +++ b/src/core/lib/iomgr/buffer_list.cc @@ -18,6 +18,8 @@ #include "src/core/lib/iomgr/buffer_list.h" +#include "absl/log/log.h" + #include #include #include @@ -42,7 +44,7 @@ void FillGprFromTimestamp(gpr_timespec* gts, const struct timespec* ts) { void DefaultTimestampsCallback(void* /*arg*/, Timestamps* /*ts*/, absl::Status /*shudown_err*/) { - gpr_log(GPR_DEBUG, "Timestamps callback has not been registered"); + VLOG(2) << "Timestamps callback has not been registered"; } // The saved callback function that will be invoked when we get all the @@ -321,7 +323,7 @@ void grpc_tcp_set_write_timestamps_callback( // Can't comment out the name because some compilers and formatters don't // like the sequence */* , which would arise from */*fn*/. (void)fn; - gpr_log(GPR_DEBUG, "Timestamps callback is not enabled for this platform"); + VLOG(2) << "Timestamps callback is not enabled for this platform"; } } // namespace grpc_core diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc index 6c44bdb0650..c6fb49cea1a 100644 --- a/src/core/lib/iomgr/call_combiner.cc +++ b/src/core/lib/iomgr/call_combiner.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -130,13 +131,13 @@ void CallCombiner::Start(grpc_closure* closure, grpc_error_handle error, } if (prev_size == 0) { if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " EXECUTING IMMEDIATELY"); + LOG(INFO) << " EXECUTING IMMEDIATELY"; } // Queue was empty, so execute this closure immediately. ScheduleClosure(closure, error); } else { if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " QUEUING"); + LOG(INFO) << " QUEUING"; } // Queue was not empty, so add closure to queue. closure->error_data.error = internal::StatusAllocHeapPtr(error); @@ -160,7 +161,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) { if (prev_size > 1) { while (true) { if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " checking queue"); + LOG(INFO) << " checking queue"; } bool empty; grpc_closure* closure = @@ -169,7 +170,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) { // This can happen either due to a race condition within the mpscq // code or because of a race with Start(). if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " queue returned no result; checking again"); + LOG(INFO) << " queue returned no result; checking again"; } continue; } @@ -184,7 +185,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) { break; } } else if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { - gpr_log(GPR_INFO, " queue empty"); + LOG(INFO) << " queue empty"; } } diff --git a/src/core/lib/iomgr/endpoint_cfstream.cc b/src/core/lib/iomgr/endpoint_cfstream.cc index bdbbfc04861..631f310a2b4 100644 --- a/src/core/lib/iomgr/endpoint_cfstream.cc +++ b/src/core/lib/iomgr/endpoint_cfstream.cc @@ -31,7 +31,6 @@ #include #include "src/core/lib/address_utils/sockaddr_utils.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/iomgr/cfstream_handle.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/endpoint.h" @@ -41,6 +40,7 @@ #include "src/core/lib/slice/slice.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" +#include "src/core/util/string.h" extern grpc_core::TraceFlag grpc_tcp_trace; diff --git a/src/core/lib/iomgr/endpoint_pair_posix.cc b/src/core/lib/iomgr/endpoint_pair_posix.cc index 3c45720785e..42d0e7acdb6 100644 --- a/src/core/lib/iomgr/endpoint_pair_posix.cc +++ b/src/core/lib/iomgr/endpoint_pair_posix.cc @@ -37,13 +37,13 @@ #include #include "src/core/lib/event_engine/channel_args_endpoint_config.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/endpoint_pair.h" #include "src/core/lib/iomgr/socket_utils_posix.h" #include "src/core/lib/iomgr/tcp_posix.h" #include "src/core/lib/iomgr/unix_sockets_posix.h" #include "src/core/lib/resource_quota/api.h" +#include "src/core/util/string.h" static void create_sockets(int sv[2]) { int flags; diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index 95ea6c9c8d0..b070a764fb3 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -36,9 +36,9 @@ #endif #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/strerror.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/util/useful.h" grpc_core::DebugOnlyTraceFlag grpc_trace_error_refcount(false, "error_refcount"); diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index 66d7c552211..4d38a90c251 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -32,10 +32,10 @@ #include #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/spinlock.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/status_helper.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/util/spinlock.h" /// Opaque representation of an error. diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index c36f3833d9f..d40b20a93b7 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" @@ -50,8 +51,6 @@ #include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/stats_data.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/manual_constructor.h" #include "src/core/lib/gprpp/strerror.h" #include "src/core/lib/iomgr/block_annotate.h" @@ -60,6 +59,8 @@ #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/lockfree_event.h" #include "src/core/lib/iomgr/wakeup_fd_posix.h" +#include "src/core/util/string.h" +#include "src/core/util/useful.h" static grpc_wakeup_fd global_wakeup_fd; static bool g_is_shutdown = true; @@ -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/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index f4c417f7e0a..7d290d7d83e 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -34,6 +34,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -42,13 +43,13 @@ #include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/stats_data.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/block_annotate.h" #include "src/core/lib/iomgr/ev_poll_posix.h" #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/wakeup_fd_posix.h" +#include "src/core/util/useful.h" #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker*)1) @@ -583,7 +584,7 @@ static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { static void fd_notify_on_error(grpc_fd* /*fd*/, grpc_closure* closure) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_ERROR, "Polling engine does not support tracking errors."); + LOG(ERROR) << "Polling engine does not support tracking errors."; } grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, absl::CancelledError()); } @@ -602,7 +603,7 @@ static void fd_set_writable(grpc_fd* fd) { static void fd_set_error(grpc_fd* /*fd*/) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_ERROR, "Polling engine does not support tracking errors."); + LOG(ERROR) << "Polling engine does not support tracking errors."; } } @@ -1397,7 +1398,7 @@ const grpc_event_engine_vtable grpc_ev_poll_posix = { // check_engine_available = [](bool) { if (!grpc_has_wakeup_fd()) { - gpr_log(GPR_ERROR, "Skipping poll because of no wakeup fd."); + LOG(ERROR) << "Skipping poll because of no wakeup fd."; return false; } if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) { diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index 5e10ae02ba4..e204b4a697b 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -25,6 +25,7 @@ #include +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include "absl/strings/str_split.h" @@ -34,12 +35,12 @@ #include "src/core/lib/config/config_vars.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/ev_epoll1_linux.h" #include "src/core/lib/iomgr/ev_poll_posix.h" #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/internal_errqueue.h" +#include "src/core/util/useful.h" grpc_core::DebugOnlyTraceFlag grpc_polling_trace( false, "polling"); // Disabled by default @@ -109,7 +110,7 @@ static void try_engine(absl::string_view engine) { if (g_vtables[i] != nullptr && is(engine, g_vtables[i]->name) && g_vtables[i]->check_engine_available(engine == g_vtables[i]->name)) { g_event_engine = g_vtables[i]; - gpr_log(GPR_DEBUG, "Using polling engine: %s", g_event_engine->name); + VLOG(2) << "Using polling engine: " << g_event_engine->name; return; } } diff --git a/src/core/lib/iomgr/event_engine_shims/endpoint.cc b/src/core/lib/iomgr/event_engine_shims/endpoint.cc index 42bb4de4ace..42238e47062 100644 --- a/src/core/lib/iomgr/event_engine_shims/endpoint.cc +++ b/src/core/lib/iomgr/event_engine_shims/endpoint.cc @@ -19,6 +19,7 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" @@ -37,7 +38,6 @@ #include "src/core/lib/event_engine/shim.h" #include "src/core/lib/event_engine/tcp_socket_utils.h" #include "src/core/lib/event_engine/trace.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/construct_destruct.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/sync.h" @@ -49,6 +49,7 @@ #include "src/core/lib/iomgr/port.h" #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/transport/error_utils.h" +#include "src/core/util/string.h" extern grpc_core::TraceFlag grpc_tcp_trace; @@ -128,7 +129,7 @@ class EventEngineEndpointWrapper { for (i = 0; i < pending_read_buffer_->count; i++) { char* dump = grpc_dump_slice(pending_read_buffer_->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "READ DATA: %s", dump); + VLOG(2) << "READ DATA: " << dump; gpr_free(dump); } } @@ -159,7 +160,7 @@ class EventEngineEndpointWrapper { for (i = 0; i < slices->count; i++) { char* dump = grpc_dump_slice(slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "WRITE DATA: %s", dump); + VLOG(2) << "WRITE DATA: " << dump; gpr_free(dump); } } diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index c4932db76bf..68340c7df1c 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -36,12 +36,12 @@ #include #include -#include "src/core/lib/gpr/time_precise.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/fork.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/iomgr/closure.h" +#include "src/core/util/time_precise.h" #if !defined(_WIN32) || !defined(_DLL) #define EXEC_CTX exec_ctx_ diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index 6144b6128f1..827bfc10c9d 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -28,11 +28,11 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/memory.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/iomgr_internal.h" +#include "src/core/util/useful.h" #define MAX_DEPTH 2 diff --git a/src/core/lib/iomgr/executor.h b/src/core/lib/iomgr/executor.h index 306cc2b3200..e20f2f0242e 100644 --- a/src/core/lib/iomgr/executor.h +++ b/src/core/lib/iomgr/executor.h @@ -21,9 +21,9 @@ #include -#include "src/core/lib/gpr/spinlock.h" #include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/closure.h" +#include "src/core/util/spinlock.h" namespace grpc_core { diff --git a/src/core/lib/iomgr/fork_windows.cc b/src/core/lib/iomgr/fork_windows.cc index d8e73ed87c4..0e1583173d3 100644 --- a/src/core/lib/iomgr/fork_windows.cc +++ b/src/core/lib/iomgr/fork_windows.cc @@ -22,6 +22,8 @@ #ifndef GRPC_POSIX_FORK +#include "absl/log/log.h" + #include #include @@ -30,7 +32,7 @@ // AROUND VERY SPECIFIC USE CASES. // -void grpc_prefork() { gpr_log(GPR_ERROR, "Forking not supported on Windows"); } +void grpc_prefork() { LOG(ERROR) << "Forking not supported on Windows"; } void grpc_postfork_parent() {} diff --git a/src/core/lib/iomgr/internal_errqueue.cc b/src/core/lib/iomgr/internal_errqueue.cc index 3167cb035de..5223687a439 100644 --- a/src/core/lib/iomgr/internal_errqueue.cc +++ b/src/core/lib/iomgr/internal_errqueue.cc @@ -14,6 +14,8 @@ #include "src/core/lib/iomgr/internal_errqueue.h" +#include "absl/log/log.h" + #include #include @@ -37,7 +39,7 @@ bool KernelSupportsErrqueue() { // least 4.0.0 struct utsname buffer; if (uname(&buffer) != 0) { - gpr_log(GPR_ERROR, "uname: %s", StrError(errno).c_str()); + LOG(ERROR) << "uname: " << StrError(errno); return false; } char* release = buffer.release; @@ -48,7 +50,7 @@ bool KernelSupportsErrqueue() { if (strtol(release, nullptr, 10) >= 4) { return true; } else { - gpr_log(GPR_DEBUG, "ERRQUEUE support not enabled"); + VLOG(2) << "ERRQUEUE support not enabled"; } #endif // GRPC_LINUX_ERRQUEUE return false; diff --git a/src/core/lib/iomgr/iocp_windows.cc b/src/core/lib/iomgr/iocp_windows.cc index 0353aa7614a..a19c13ab7b6 100644 --- a/src/core/lib/iomgr/iocp_windows.cc +++ b/src/core/lib/iomgr/iocp_windows.cc @@ -27,6 +27,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -157,7 +158,7 @@ void grpc_iocp_add_socket(grpc_winsocket* socket) { (uintptr_t)socket, 0); if (!ret) { char* utf8_message = gpr_format_message(WSAGetLastError()); - gpr_log(GPR_ERROR, "Unable to add socket to iocp: %s", utf8_message); + LOG(ERROR) << "Unable to add socket to iocp: " << utf8_message; gpr_free(utf8_message); __debugbreak(); abort(); diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index 5cda83c1f19..6acf40a66d2 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -29,8 +29,6 @@ #include #include "src/core/lib/config/config_vars.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/buffer_list.h" @@ -40,6 +38,8 @@ #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/iomgr/timer_manager.h" +#include "src/core/util/string.h" +#include "src/core/util/useful.h" static gpr_mu g_mu; static gpr_cv g_rcv; diff --git a/src/core/lib/iomgr/resolve_address_posix.cc b/src/core/lib/iomgr/resolve_address_posix.cc index ee5f9092b9e..c9f2967b898 100644 --- a/src/core/lib/iomgr/resolve_address_posix.cc +++ b/src/core/lib/iomgr/resolve_address_posix.cc @@ -30,8 +30,6 @@ #include #include "src/core/lib/event_engine/default_event_engine.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/thd.h" @@ -44,6 +42,8 @@ #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/unix_sockets_posix.h" #include "src/core/lib/transport/error_utils.h" +#include "src/core/util/string.h" +#include "src/core/util/useful.h" namespace grpc_core { namespace { diff --git a/src/core/lib/iomgr/resolve_address_windows.cc b/src/core/lib/iomgr/resolve_address_windows.cc index bb5b78de1c8..054f7423816 100644 --- a/src/core/lib/iomgr/resolve_address_windows.cc +++ b/src/core/lib/iomgr/resolve_address_windows.cc @@ -35,7 +35,6 @@ #include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/event_engine/default_event_engine.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/thd.h" @@ -47,6 +46,7 @@ #include "src/core/lib/iomgr/resolve_address_windows.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/transport/error_utils.h" +#include "src/core/util/string.h" namespace grpc_core { namespace { diff --git a/src/core/lib/iomgr/socket_factory_posix.cc b/src/core/lib/iomgr/socket_factory_posix.cc index 0b511356a97..45a167dc4b2 100644 --- a/src/core/lib/iomgr/socket_factory_posix.cc +++ b/src/core/lib/iomgr/socket_factory_posix.cc @@ -26,8 +26,8 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/iomgr/socket_factory_posix.h" +#include "src/core/util/useful.h" void grpc_socket_factory_init(grpc_socket_factory* factory, const grpc_socket_factory_vtable* vtable) { diff --git a/src/core/lib/iomgr/socket_mutator.cc b/src/core/lib/iomgr/socket_mutator.cc index fd909c3e5e6..428cc0bdf3f 100644 --- a/src/core/lib/iomgr/socket_mutator.cc +++ b/src/core/lib/iomgr/socket_mutator.cc @@ -24,8 +24,8 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" +#include "src/core/util/useful.h" void grpc_socket_mutator_init(grpc_socket_mutator* mutator, const grpc_socket_mutator_vtable* vtable) { diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc index 2def9576b0c..7ebafa6897b 100644 --- a/src/core/lib/iomgr/socket_utils_common_posix.cc +++ b/src/core/lib/iomgr/socket_utils_common_posix.cc @@ -44,6 +44,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -51,10 +52,10 @@ #include #include "src/core/lib/address_utils/sockaddr_utils.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/strerror.h" #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/util/string.h" // set a socket to use zerocopy grpc_error_handle grpc_set_socket_zerocopy(int fd) { @@ -411,7 +412,7 @@ grpc_error_handle grpc_set_socket_tcp_user_timeout( } } else { if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_INFO, "TCP_USER_TIMEOUT not supported for this platform"); + LOG(INFO) << "TCP_USER_TIMEOUT not supported for this platform"; } } return absl::OkStatus(); @@ -442,7 +443,7 @@ static void probe_ipv6_once(void) { int fd = socket(AF_INET6, SOCK_STREAM, 0); g_ipv6_loopback_available = 0; if (fd < 0) { - gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed."); + LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed."; } else { grpc_sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index fc2cdc97407..44e524c6829 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -28,6 +28,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include @@ -217,7 +218,7 @@ static void probe_ipv6_once(void) { SOCKET s = socket(AF_INET6, SOCK_STREAM, 0); g_ipv6_loopback_available = 0; if (s == INVALID_SOCKET) { - gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed."); + LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed."; } else { grpc_sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index 22ecb3e1ef0..8fb50f6754e 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -30,6 +30,7 @@ #include "absl/container/flat_hash_map.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -39,7 +40,6 @@ #include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/event_engine/resolved_address_internal.h" #include "src/core/lib/event_engine/shim.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/event_engine_shims/tcp_client.h" @@ -54,6 +54,7 @@ #include "src/core/lib/iomgr/unix_sockets_posix.h" #include "src/core/lib/iomgr/vsock.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/util/string.h" extern grpc_core::TraceFlag grpc_tcp_trace; @@ -240,7 +241,7 @@ static void on_writable(void* acp, grpc_error_handle error) { // your program or another program on the same computer // opened too many network connections. The "easy" fix: // don't do that! - gpr_log(GPR_ERROR, "kernel out of buffers"); + LOG(ERROR) << "kernel out of buffers"; gpr_mu_unlock(&ac->mu); grpc_fd_notify_on_write(fd, &ac->write_closure); return; diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index 880b10c1764..1f9f9817e04 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 @@ -60,8 +61,6 @@ #include "src/core/lib/debug/stats_data.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/experiments/experiments.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/strerror.h" #include "src/core/lib/gprpp/sync.h" @@ -77,6 +76,8 @@ #include "src/core/lib/resource_quota/trace.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" +#include "src/core/util/string.h" +#include "src/core/util/useful.h" #ifndef SOL_TCP #define SOL_TCP IPPROTO_TCP @@ -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) { @@ -874,7 +875,7 @@ static void tcp_trace_read(grpc_tcp* tcp, grpc_error_handle error) for (i = 0; i < tcp->incoming_buffer->count; i++) { char* dump = grpc_dump_slice(tcp->incoming_buffer->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "READ DATA: %s", dump); + VLOG(2) << "READ DATA: " << dump; gpr_free(dump); } } @@ -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. @@ -1852,7 +1853,7 @@ static void tcp_handle_write(void* arg /* grpc_tcp */, tcp->write_cb = nullptr; tcp->current_zerocopy_send = nullptr; if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_INFO, "write: %s", grpc_core::StatusToString(error).c_str()); + LOG(INFO) << "write: " << grpc_core::StatusToString(error); } // No need to take a ref on error since tcp_flush provides a ref. grpc_core::Closure::Run(DEBUG_LOCATION, cb, error); @@ -1876,7 +1877,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, if (gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) { char* data = grpc_dump_slice(buf->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "WRITE DATA: %s", data); + VLOG(2) << "WRITE DATA: " << data; gpr_free(data); } } @@ -1915,12 +1916,12 @@ 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 { if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { - gpr_log(GPR_INFO, "write: %s", grpc_core::StatusToString(error).c_str()); + LOG(INFO) << "write: " << grpc_core::StatusToString(error); } grpc_core::Closure::Run(DEBUG_LOCATION, cb, error); } @@ -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/iomgr/tcp_server_utils_posix_common.cc b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc index 181ab5b8e25..ee8f7350eb6 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc @@ -32,6 +32,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -221,7 +222,7 @@ grpc_error_handle grpc_tcp_server_prepare_socket( err = grpc_set_socket_zerocopy(fd); if (!err.ok()) { // it's not fatal, so just log it. - gpr_log(GPR_DEBUG, "Node does not support SO_ZEROCOPY, continuing."); + VLOG(2) << "Node does not support SO_ZEROCOPY, continuing."; } #endif err = grpc_set_socket_nonblocking(fd, 1); diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc index d04dddf8e46..495e800ea08 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc @@ -31,6 +31,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -115,7 +116,7 @@ grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, } else if (requested_port <= 0) { return GRPC_ERROR_CREATE("Bad get_unused_port()"); } - gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port); + VLOG(2) << "Picked unused port " << requested_port; } static bool v4_available = grpc_is_ipv4_availabile(); diff --git a/src/core/lib/iomgr/tcp_server_windows.cc b/src/core/lib/iomgr/tcp_server_windows.cc index 70b4a6a5920..b2a0ab25be8 100644 --- a/src/core/lib/iomgr/tcp_server_windows.cc +++ b/src/core/lib/iomgr/tcp_server_windows.cc @@ -28,6 +28,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -405,7 +406,7 @@ static void on_accept(void* arg, grpc_error_handle error) { if (!wsa_success) { if (!sp->shutting_down) { char* utf8_message = gpr_format_message(WSAGetLastError()); - gpr_log(GPR_ERROR, "on_accept error: %s", utf8_message); + LOG(ERROR) << "on_accept error: " << utf8_message; gpr_free(utf8_message); } closesocket(sock); @@ -415,7 +416,7 @@ static void on_accept(void* arg, grpc_error_handle error) { (char*)&sp->socket->socket, sizeof(sp->socket->socket)); if (err) { char* utf8_message = gpr_format_message(WSAGetLastError()); - gpr_log(GPR_ERROR, "setsockopt error: %s", utf8_message); + LOG(ERROR) << "setsockopt error: " << utf8_message; gpr_free(utf8_message); } int peer_name_len = (int)peer_name.len; @@ -432,7 +433,7 @@ static void on_accept(void* arg, grpc_error_handle error) { } } else { char* utf8_message = gpr_format_message(WSAGetLastError()); - gpr_log(GPR_ERROR, "getpeername error: %s", utf8_message); + LOG(ERROR) << "getpeername error: " << utf8_message; gpr_free(utf8_message); } std::string fd_name = absl::StrCat("tcp_server:", peer_name_string); diff --git a/src/core/lib/iomgr/tcp_windows.cc b/src/core/lib/iomgr/tcp_windows.cc index 53174721ba1..4ff54f374b3 100644 --- a/src/core/lib/iomgr/tcp_windows.cc +++ b/src/core/lib/iomgr/tcp_windows.cc @@ -33,8 +33,6 @@ #include #include "src/core/lib/address_utils/sockaddr_utils.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/iocp_windows.h" #include "src/core/lib/iomgr/sockaddr.h" @@ -45,6 +43,8 @@ #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" +#include "src/core/util/string.h" +#include "src/core/util/useful.h" #if defined(__MSYS__) && defined(GPR_ARCH_64) // Nasty workaround for nasty bug when using the 64 bits msys compiler diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index bc6f47c2188..1b0ab4b71cc 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -31,8 +31,6 @@ #include #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/spinlock.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/manual_constructor.h" #include "src/core/lib/gprpp/time.h" @@ -41,6 +39,8 @@ #include "src/core/lib/iomgr/port.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/iomgr/timer_heap.h" +#include "src/core/util/spinlock.h" +#include "src/core/util/useful.h" #define INVALID_HEAP_INDEX 0xffffffffu diff --git a/src/core/lib/iomgr/timer_heap.cc b/src/core/lib/iomgr/timer_heap.cc index 9e3b47b31e5..8f7d950e699 100644 --- a/src/core/lib/iomgr/timer_heap.cc +++ b/src/core/lib/iomgr/timer_heap.cc @@ -23,8 +23,8 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/iomgr/port.h" +#include "src/core/util/useful.h" // Adjusts a heap so as to move a hole at position i closer to the root, // until a suitable position is found for element t. Then, copies t into that diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 6e4197a8f83..9cab02d2877 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -89,7 +90,7 @@ static void start_timer_thread_and_unlock(void) { ++g_thread_count; gpr_mu_unlock(&g_mu); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "Spawn timer thread"); + LOG(INFO) << "Spawn timer thread"; } completed_thread* ct = static_cast(gpr_malloc(sizeof(*ct))); @@ -125,7 +126,7 @@ static void run_some_timers() { // waiter so that the next deadline is not missed if (!g_has_timed_waiter) { if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "kick untimed waiter"); + LOG(INFO) << "kick untimed waiter"; } gpr_cv_signal(&g_cv_wait); } @@ -133,7 +134,7 @@ static void run_some_timers() { } // without our lock, flush the exec_ctx if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "flush exec_ctx"); + LOG(INFO) << "flush exec_ctx"; } grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&g_mu); @@ -199,7 +200,7 @@ static bool wait_until(grpc_core::Timestamp next) { if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace) && next == grpc_core::Timestamp::InfFuture()) { - gpr_log(GPR_INFO, "sleep until kicked"); + LOG(INFO) << "sleep until kicked"; } gpr_cv_wait(&g_cv_wait, &g_mu, next.as_timespec(GPR_CLOCK_MONOTONIC)); @@ -251,7 +252,7 @@ static void timer_main_loop() { // Consequently, we can just sleep forever here and be happy at some // saved wakeup cycles. if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "timers not checked: expect another thread to"); + LOG(INFO) << "timers not checked: expect another thread to"; } next = grpc_core::Timestamp::InfFuture(); ABSL_FALLTHROUGH_INTENDED; @@ -277,7 +278,7 @@ static void timer_thread_cleanup(completed_thread* ct) { g_completed_threads = ct; gpr_mu_unlock(&g_mu); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "End timer thread"); + LOG(INFO) << "End timer thread"; } } @@ -318,18 +319,18 @@ void grpc_timer_manager_init(void) { static void stop_threads(void) { gpr_mu_lock(&g_mu); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "stop timer threads: threaded=%d", g_threaded); + LOG(INFO) << "stop timer threads: threaded=" << g_threaded; } if (g_threaded) { g_threaded = false; gpr_cv_broadcast(&g_cv_wait); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "num timer threads: %d", g_thread_count); + LOG(INFO) << "num timer threads: " << g_thread_count; } while (g_thread_count > 0) { gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { - gpr_log(GPR_INFO, "num timer threads: %d", g_thread_count); + LOG(INFO) << "num timer threads: " << g_thread_count; } gc_completed_threads(); } diff --git a/src/core/lib/iomgr/unix_sockets_posix.cc b/src/core/lib/iomgr/unix_sockets_posix.cc index 52da21d84b1..15b2226b688 100644 --- a/src/core/lib/iomgr/unix_sockets_posix.cc +++ b/src/core/lib/iomgr/unix_sockets_posix.cc @@ -40,11 +40,11 @@ #include #include "src/core/lib/address_utils/parse_address.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/unix_sockets_posix.h" #include "src/core/lib/transport/error_utils.h" +#include "src/core/util/useful.h" void grpc_create_socketpair_if_unix(int sv[2]) { #ifdef GPR_WINDOWS diff --git a/src/core/lib/iomgr/vsock.cc b/src/core/lib/iomgr/vsock.cc index e28fed350f3..847dabe0f17 100644 --- a/src/core/lib/iomgr/vsock.cc +++ b/src/core/lib/iomgr/vsock.cc @@ -31,10 +31,10 @@ #include #include "src/core/lib/address_utils/parse_address.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/transport/error_utils.h" +#include "src/core/util/useful.h" absl::StatusOr> grpc_resolve_vsock_address( absl::string_view name) { diff --git a/src/core/lib/promise/context.h b/src/core/lib/promise/context.h index 4b1f9ef6369..47b2bac39f2 100644 --- a/src/core/lib/promise/context.h +++ b/src/core/lib/promise/context.h @@ -119,6 +119,12 @@ T* GetContext() { return p; } +// Retrieve the current value of a context, or nullptr if the value is unset. +template +T* MaybeGetContext() { + return promise_detail::Context::get(); +} + // Given a promise and a context, return a promise that has that context set. template promise_detail::WithContext WithContext(F f, T* context) { diff --git a/src/core/lib/promise/detail/promise_like.h b/src/core/lib/promise/detail/promise_like.h index a8b80172c22..8e73577675a 100644 --- a/src/core/lib/promise/detail/promise_like.h +++ b/src/core/lib/promise/detail/promise_like.h @@ -17,6 +17,7 @@ #include +#include "absl/functional/any_invocable.h" #include "absl/meta/type_traits.h" #include @@ -63,6 +64,10 @@ auto WrapInPoll(T&& x) -> decltype(PollWrapper::Wrap(std::forward(x))) { return PollWrapper::Wrap(std::forward(x)); } +// T -> T, const T& -> T +template +using RemoveCVRef = absl::remove_cv_t>; + template class PromiseLike; @@ -73,7 +78,7 @@ template class PromiseLike::type>::value>> { private: - GPR_NO_UNIQUE_ADDRESS F f_; + GPR_NO_UNIQUE_ADDRESS RemoveCVRef f_; public: // NOLINTNEXTLINE - internal detail that drastically simplifies calling code. @@ -82,10 +87,6 @@ class PromiseLike::Type; }; -// T -> T, const T& -> T -template -using RemoveCVRef = absl::remove_cv_t>; - } // namespace promise_detail } // namespace grpc_core diff --git a/src/core/lib/promise/detail/seq_state.h b/src/core/lib/promise/detail/seq_state.h index 3e69e60b741..841cd6cb042 100644 --- a/src/core/lib/promise/detail/seq_state.h +++ b/src/core/lib/promise/detail/seq_state.h @@ -23,6 +23,7 @@ #include "absl/base/attributes.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -144,22 +145,21 @@ struct SeqState { switch (state) { case State::kState0: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 1/2", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 1/2"; } auto result = prior.current_promise(); PromiseResult0* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 1/2 gets %s", this, - p != nullptr - ? (PromiseResultTraits0::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits0::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 1/2 gets " + << (p != nullptr + ? (PromiseResultTraits0::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits0::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { @@ -177,14 +177,14 @@ struct SeqState { default: case State::kState1: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 2/2", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 2/2"; } auto result = current_promise(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 2/2 gets %s", this, - result.ready() ? "ready" : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 2/2 gets " + << (result.ready() ? "ready" : "pending"); } auto* p = result.value_if_ready(); if (p == nullptr) return Pending{}; @@ -287,22 +287,21 @@ struct SeqState { switch (state) { case State::kState0: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 1/3", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 1/3"; } auto result = prior.prior.current_promise(); PromiseResult0* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 1/3 gets %s", this, - p != nullptr - ? (PromiseResultTraits0::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits0::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 1/3 gets " + << (p != nullptr + ? (PromiseResultTraits0::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits0::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { @@ -319,22 +318,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState1: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 2/3", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 2/3"; } auto result = prior.current_promise(); PromiseResult1* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 2/3 gets %s", this, - p != nullptr - ? (PromiseResultTraits1::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits1::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 2/3 gets " + << (p != nullptr + ? (PromiseResultTraits1::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits1::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { @@ -352,14 +350,14 @@ struct SeqState { default: case State::kState2: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 3/3", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 3/3"; } auto result = current_promise(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 3/3 gets %s", this, - result.ready() ? "ready" : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 3/3 gets " + << (result.ready() ? "ready" : "pending"); } auto* p = result.value_if_ready(); if (p == nullptr) return Pending{}; @@ -489,22 +487,21 @@ struct SeqState { switch (state) { case State::kState0: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 1/4", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 1/4"; } auto result = prior.prior.prior.current_promise(); PromiseResult0* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 1/4 gets %s", this, - p != nullptr - ? (PromiseResultTraits0::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits0::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 1/4 gets " + << (p != nullptr + ? (PromiseResultTraits0::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits0::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { @@ -521,22 +518,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState1: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 2/4", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 2/4"; } auto result = prior.prior.current_promise(); PromiseResult1* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 2/4 gets %s", this, - p != nullptr - ? (PromiseResultTraits1::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits1::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 2/4 gets " + << (p != nullptr + ? (PromiseResultTraits1::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits1::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { @@ -553,22 +549,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState2: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 3/4", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 3/4"; } auto result = prior.current_promise(); PromiseResult2* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 3/4 gets %s", this, - p != nullptr - ? (PromiseResultTraits2::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits2::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 3/4 gets " + << (p != nullptr + ? (PromiseResultTraits2::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits2::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { @@ -586,14 +581,14 @@ struct SeqState { default: case State::kState3: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 4/4", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 4/4"; } auto result = current_promise(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 4/4 gets %s", this, - result.ready() ? "ready" : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 4/4 gets " + << (result.ready() ? "ready" : "pending"); } auto* p = result.value_if_ready(); if (p == nullptr) return Pending{}; @@ -751,22 +746,21 @@ struct SeqState { switch (state) { case State::kState0: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 1/5", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 1/5"; } auto result = prior.prior.prior.prior.current_promise(); PromiseResult0* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 1/5 gets %s", this, - p != nullptr - ? (PromiseResultTraits0::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits0::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 1/5 gets " + << (p != nullptr + ? (PromiseResultTraits0::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits0::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { @@ -783,22 +777,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState1: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 2/5", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 2/5"; } auto result = prior.prior.prior.current_promise(); PromiseResult1* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 2/5 gets %s", this, - p != nullptr - ? (PromiseResultTraits1::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits1::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 2/5 gets " + << (p != nullptr + ? (PromiseResultTraits1::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits1::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { @@ -815,22 +808,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState2: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 3/5", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 3/5"; } auto result = prior.prior.current_promise(); PromiseResult2* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 3/5 gets %s", this, - p != nullptr - ? (PromiseResultTraits2::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits2::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 3/5 gets " + << (p != nullptr + ? (PromiseResultTraits2::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits2::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { @@ -847,22 +839,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState3: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 4/5", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 4/5"; } auto result = prior.current_promise(); PromiseResult3* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 4/5 gets %s", this, - p != nullptr - ? (PromiseResultTraits3::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits3::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 4/5 gets " + << (p != nullptr + ? (PromiseResultTraits3::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits3::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits3::IsOk(*p)) { @@ -880,14 +871,14 @@ struct SeqState { default: case State::kState4: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 5/5", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 5/5"; } auto result = current_promise(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 5/5 gets %s", this, - result.ready() ? "ready" : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 5/5 gets " + << (result.ready() ? "ready" : "pending"); } auto* p = result.value_if_ready(); if (p == nullptr) return Pending{}; @@ -1082,22 +1073,21 @@ struct SeqState { switch (state) { case State::kState0: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 1/6", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 1/6"; } auto result = prior.prior.prior.prior.prior.current_promise(); PromiseResult0* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 1/6 gets %s", this, - p != nullptr - ? (PromiseResultTraits0::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits0::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 1/6 gets " + << (p != nullptr + ? (PromiseResultTraits0::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits0::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { @@ -1115,22 +1105,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState1: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 2/6", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 2/6"; } auto result = prior.prior.prior.prior.current_promise(); PromiseResult1* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 2/6 gets %s", this, - p != nullptr - ? (PromiseResultTraits1::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits1::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 2/6 gets " + << (p != nullptr + ? (PromiseResultTraits1::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits1::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { @@ -1147,22 +1136,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState2: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 3/6", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 3/6"; } auto result = prior.prior.prior.current_promise(); PromiseResult2* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 3/6 gets %s", this, - p != nullptr - ? (PromiseResultTraits2::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits2::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 3/6 gets " + << (p != nullptr + ? (PromiseResultTraits2::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits2::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { @@ -1179,22 +1167,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState3: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 4/6", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 4/6"; } auto result = prior.prior.current_promise(); PromiseResult3* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 4/6 gets %s", this, - p != nullptr - ? (PromiseResultTraits3::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits3::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 4/6 gets " + << (p != nullptr + ? (PromiseResultTraits3::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits3::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits3::IsOk(*p)) { @@ -1211,22 +1198,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState4: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 5/6", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 5/6"; } auto result = prior.current_promise(); PromiseResult4* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 5/6 gets %s", this, - p != nullptr - ? (PromiseResultTraits4::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits4::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 5/6 gets " + << (p != nullptr + ? (PromiseResultTraits4::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits4::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits4::IsOk(*p)) { @@ -1249,9 +1235,9 @@ struct SeqState { } auto result = current_promise(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 6/6 gets %s", this, - result.ready() ? "ready" : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 6/6 gets " + << (result.ready() ? "ready" : "pending"); } auto* p = result.value_if_ready(); if (p == nullptr) return Pending{}; @@ -1478,22 +1464,21 @@ struct SeqState { switch (state) { case State::kState0: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 1/7", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 1/7"; } auto result = prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult0* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 1/7 gets %s", this, - p != nullptr - ? (PromiseResultTraits0::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits0::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 1/7 gets " + << (p != nullptr + ? (PromiseResultTraits0::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits0::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { @@ -1511,22 +1496,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState1: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 2/7", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 2/7"; } auto result = prior.prior.prior.prior.prior.current_promise(); PromiseResult1* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 2/7 gets %s", this, - p != nullptr - ? (PromiseResultTraits1::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits1::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 2/7 gets " + << (p != nullptr + ? (PromiseResultTraits1::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits1::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { @@ -1544,22 +1528,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState2: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 3/7", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 3/7"; } auto result = prior.prior.prior.prior.current_promise(); PromiseResult2* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 3/7 gets %s", this, - p != nullptr - ? (PromiseResultTraits2::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits2::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 3/7 gets " + << (p != nullptr + ? (PromiseResultTraits2::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits2::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { @@ -1576,22 +1559,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState3: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 4/7", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 4/7"; } auto result = prior.prior.prior.current_promise(); PromiseResult3* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 4/7 gets %s", this, - p != nullptr - ? (PromiseResultTraits3::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits3::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 4/7 gets " + << (p != nullptr + ? (PromiseResultTraits3::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits3::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits3::IsOk(*p)) { @@ -1608,22 +1590,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState4: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 5/7", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 5/7"; } auto result = prior.prior.current_promise(); PromiseResult4* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 5/7 gets %s", this, - p != nullptr - ? (PromiseResultTraits4::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits4::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 5/7 gets " + << (p != nullptr + ? (PromiseResultTraits4::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits4::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits4::IsOk(*p)) { @@ -1640,22 +1621,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState5: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 6/7", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 6/7"; } auto result = prior.current_promise(); PromiseResult5* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 6/7 gets %s", this, - p != nullptr - ? (PromiseResultTraits5::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits5::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 6/7 gets " + << (p != nullptr + ? (PromiseResultTraits5::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits5::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits5::IsOk(*p)) { @@ -1673,14 +1653,14 @@ struct SeqState { default: case State::kState6: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 7/7", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 7/7"; } auto result = current_promise(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 7/7 gets %s", this, - result.ready() ? "ready" : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 7/7 gets " + << (result.ready() ? "ready" : "pending"); } auto* p = result.value_if_ready(); if (p == nullptr) return Pending{}; @@ -1940,23 +1920,22 @@ struct SeqState { switch (state) { case State::kState0: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 1/8", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 1/8"; } auto result = prior.prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult0* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 1/8 gets %s", this, - p != nullptr - ? (PromiseResultTraits0::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits0::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 1/8 gets " + << (p != nullptr + ? (PromiseResultTraits0::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits0::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { @@ -1975,22 +1954,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState1: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 2/8", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 2/8"; } auto result = prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult1* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 2/8 gets %s", this, - p != nullptr - ? (PromiseResultTraits1::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits1::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 2/8 gets " + << (p != nullptr + ? (PromiseResultTraits1::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits1::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { @@ -2008,22 +1986,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState2: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 3/8", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 3/8"; } auto result = prior.prior.prior.prior.prior.current_promise(); PromiseResult2* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 3/8 gets %s", this, - p != nullptr - ? (PromiseResultTraits2::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits2::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 3/8 gets " + << (p != nullptr + ? (PromiseResultTraits2::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits2::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { @@ -2041,22 +2018,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState3: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 4/8", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 4/8"; } auto result = prior.prior.prior.prior.current_promise(); PromiseResult3* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 4/8 gets %s", this, - p != nullptr - ? (PromiseResultTraits3::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits3::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 4/8 gets " + << (p != nullptr + ? (PromiseResultTraits3::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits3::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits3::IsOk(*p)) { @@ -2073,22 +2049,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState4: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 5/8", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 5/8"; } auto result = prior.prior.prior.current_promise(); PromiseResult4* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 5/8 gets %s", this, - p != nullptr - ? (PromiseResultTraits4::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits4::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 5/8 gets " + << (p != nullptr + ? (PromiseResultTraits4::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits4::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits4::IsOk(*p)) { @@ -2105,22 +2080,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState5: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 6/8", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 6/8"; } auto result = prior.prior.current_promise(); PromiseResult5* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 6/8 gets %s", this, - p != nullptr - ? (PromiseResultTraits5::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits5::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 6/8 gets " + << (p != nullptr + ? (PromiseResultTraits5::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits5::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits5::IsOk(*p)) { @@ -2137,22 +2111,21 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; case State::kState6: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 7/8", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 7/8"; } auto result = prior.current_promise(); PromiseResult6* p = result.value_if_ready(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log( - whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 7/8 gets %s", this, - p != nullptr - ? (PromiseResultTraits6::IsOk(*p) - ? "ready" - : absl::StrCat("early-error:", - PromiseResultTraits6::ErrorString(*p)) - .c_str()) - : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 7/8 gets " + << (p != nullptr + ? (PromiseResultTraits6::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits6::ErrorString(*p))) + : "pending"); } if (p == nullptr) return Pending{}; if (!PromiseResultTraits6::IsOk(*p)) { @@ -2170,14 +2143,14 @@ struct SeqState { default: case State::kState7: { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: begin poll step 8/8", this); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 8/8"; } auto result = current_promise(); if (grpc_trace_promise_primitives.enabled()) { - gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_INFO, - "seq[%p]: poll step 8/8 gets %s", this, - result.ready() ? "ready" : "pending"); + LOG(INFO).AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 8/8 gets " + << (result.ready() ? "ready" : "pending"); } auto* p = result.value_if_ready(); if (p == nullptr) return Pending{}; diff --git a/src/core/lib/promise/map_pipe.h b/src/core/lib/promise/map_pipe.h index 8dd4223dce3..fef1f18994f 100644 --- a/src/core/lib/promise/map_pipe.h +++ b/src/core/lib/promise/map_pipe.h @@ -15,6 +15,7 @@ #ifndef GRPC_SRC_CORE_LIB_PROMISE_MAP_PIPE_H #define GRPC_SRC_CORE_LIB_PROMISE_MAP_PIPE_H +#include "absl/log/log.h" #include "absl/status/status.h" #include @@ -46,14 +47,14 @@ auto MapPipe(PipeReceiver src, PipeSender dst, Filter filter_factory) { return TrySeq( [] { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_DEBUG, "MapPipe: start map"); + VLOG(2) << "MapPipe: start map"; } return Empty{}; }, filter_factory.Make(std::move(t)), [&dst](T t) { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_DEBUG, "MapPipe: start push"); + VLOG(2) << "MapPipe: start push"; } return Map(dst.Push(std::move(t)), [](bool successful_push) { if (successful_push) { diff --git a/src/core/lib/promise/pipe.h b/src/core/lib/promise/pipe.h index c77919f697c..570f59e77a1 100644 --- a/src/core/lib/promise/pipe.h +++ b/src/core/lib/promise/pipe.h @@ -23,6 +23,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/types/optional.h" #include "absl/types/variant.h" @@ -119,7 +120,7 @@ class Center : public InterceptorList { // Add one ref to this object, and return this. void IncrementRefCount() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_DEBUG, "%s", DebugOpString("IncrementRefCount").c_str()); + VLOG(2) << DebugOpString("IncrementRefCount"); } refs_++; DCHECK_NE(refs_, 0); @@ -134,7 +135,7 @@ class Center : public InterceptorList { // If no refs remain, destroy this object void Unref() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_DEBUG, "%s", DebugOpString("Unref").c_str()); + VLOG(2) << DebugOpString("Unref"); } DCHECK_GT(refs_, 0); refs_--; @@ -149,7 +150,7 @@ class Center : public InterceptorList { // Return false if the recv end is closed. Poll Push(T* value) { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("Push").c_str()); + LOG(INFO) << DebugOpString("Push"); } DCHECK_NE(refs_, 0); switch (value_state_) { @@ -173,7 +174,7 @@ class Center : public InterceptorList { Poll PollAck() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("PollAck").c_str()); + LOG(INFO) << DebugOpString("PollAck"); } DCHECK_NE(refs_, 0); switch (value_state_) { @@ -201,7 +202,7 @@ class Center : public InterceptorList { // Return nullopt if the send end is closed and no value had been pushed. Poll> Next() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("Next").c_str()); + LOG(INFO) << DebugOpString("Next"); } DCHECK_NE(refs_, 0); switch (value_state_) { @@ -227,7 +228,7 @@ class Center : public InterceptorList { // but the pipe is closed, reports closed). Poll PollClosedForSender() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("PollClosedForSender").c_str()); + LOG(INFO) << DebugOpString("PollClosedForSender"); } DCHECK_NE(refs_, 0); switch (value_state_) { @@ -250,7 +251,7 @@ class Center : public InterceptorList { // but the pipe is closed, reports open). Poll PollClosedForReceiver() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("PollClosedForReceiver").c_str()); + LOG(INFO) << DebugOpString("PollClosedForReceiver"); } DCHECK_NE(refs_, 0); switch (value_state_) { @@ -271,7 +272,7 @@ class Center : public InterceptorList { Poll PollEmpty() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("PollEmpty").c_str()); + LOG(INFO) << DebugOpString("PollEmpty"); } DCHECK_NE(refs_, 0); switch (value_state_) { @@ -291,7 +292,7 @@ class Center : public InterceptorList { void AckNext() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("AckNext").c_str()); + LOG(INFO) << DebugOpString("AckNext"); } switch (value_state_) { case ValueState::kReady: @@ -318,7 +319,7 @@ class Center : public InterceptorList { void MarkClosed() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("MarkClosed").c_str()); + LOG(INFO) << DebugOpString("MarkClosed"); } switch (value_state_) { case ValueState::kEmpty: @@ -347,7 +348,7 @@ class Center : public InterceptorList { void MarkCancelled() { if (grpc_trace_promise_primitives.enabled()) { - gpr_log(GPR_INFO, "%s", DebugOpString("MarkCancelled").c_str()); + LOG(INFO) << DebugOpString("MarkCancelled"); } switch (value_state_) { case ValueState::kEmpty: diff --git a/src/core/lib/promise/status_flag.h b/src/core/lib/promise/status_flag.h index 38d4cf5b720..132b2079c07 100644 --- a/src/core/lib/promise/status_flag.h +++ b/src/core/lib/promise/status_flag.h @@ -171,6 +171,8 @@ class ValueOrFailure { T& value() { return value_.value(); } const T& operator*() const { return *value_; } T& operator*() { return *value_; } + const T* operator->() const { return &*value_; } + T* operator->() { return &*value_; } bool operator==(const ValueOrFailure& other) const { return value_ == other.value_; diff --git a/src/core/lib/resource_quota/arena.cc b/src/core/lib/resource_quota/arena.cc index 7a0f9e752f0..a2969abe241 100644 --- a/src/core/lib/resource_quota/arena.cc +++ b/src/core/lib/resource_quota/arena.cc @@ -24,7 +24,7 @@ #include #include -#include "src/core/lib/gpr/alloc.h" +#include "src/core/util/alloc.h" namespace { diff --git a/src/core/lib/resource_quota/arena.h b/src/core/lib/resource_quota/arena.h index 5985c9220fb..813004087b7 100644 --- a/src/core/lib/resource_quota/arena.h +++ b/src/core/lib/resource_quota/arena.h @@ -35,10 +35,10 @@ #include #include -#include "src/core/lib/gpr/alloc.h" #include "src/core/lib/gprpp/construct_destruct.h" #include "src/core/lib/promise/context.h" #include "src/core/lib/resource_quota/memory_quota.h" +#include "src/core/util/alloc.h" #define GRPC_ARENA_POOLED_ALLOCATIONS_USE_MALLOC // #define GRPC_ARENA_TRACE_POOLED_ALLOCATIONS diff --git a/src/core/lib/resource_quota/memory_quota.cc b/src/core/lib/resource_quota/memory_quota.cc index d6240f4e1d9..79702ce7fff 100644 --- a/src/core/lib/resource_quota/memory_quota.cc +++ b/src/core/lib/resource_quota/memory_quota.cc @@ -34,7 +34,6 @@ #include #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/mpscq.h" #include "src/core/lib/promise/exec_ctx_wakeup_scheduler.h" #include "src/core/lib/promise/loop.h" @@ -43,6 +42,7 @@ #include "src/core/lib/promise/seq.h" #include "src/core/lib/resource_quota/trace.h" #include "src/core/lib/slice/slice_refcount.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/lib/resource_quota/memory_quota.h b/src/core/lib/resource_quota/memory_quota.h index 1ccc6b246de..79de77cf793 100644 --- a/src/core/lib/resource_quota/memory_quota.h +++ b/src/core/lib/resource_quota/memory_quota.h @@ -39,7 +39,6 @@ #include "src/core/lib/debug/trace.h" #include "src/core/lib/experiments/experiments.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" @@ -48,6 +47,7 @@ #include "src/core/lib/promise/poll.h" #include "src/core/lib/resource_quota/periodic_update.h" #include "src/core/lib/resource_quota/trace.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/lib/resource_quota/periodic_update.cc b/src/core/lib/resource_quota/periodic_update.cc index b39ad44a44f..b4874fea1da 100644 --- a/src/core/lib/resource_quota/periodic_update.cc +++ b/src/core/lib/resource_quota/periodic_update.cc @@ -18,7 +18,7 @@ #include -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/lib/resource_quota/resource_quota.h b/src/core/lib/resource_quota/resource_quota.h index 37f1fa7c989..e17448f14eb 100644 --- a/src/core/lib/resource_quota/resource_quota.h +++ b/src/core/lib/resource_quota/resource_quota.h @@ -24,12 +24,12 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/cpp_impl_of.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/resource_quota/memory_quota.h" #include "src/core/lib/resource_quota/thread_quota.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/lib/security/authorization/authorization_policy_provider.h b/src/core/lib/security/authorization/authorization_policy_provider.h index cca363f38fd..a4dbc5e8a08 100644 --- a/src/core/lib/security/authorization/authorization_policy_provider.h +++ b/src/core/lib/security/authorization/authorization_policy_provider.h @@ -21,10 +21,10 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/dual_ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/security/authorization/authorization_engine.h" +#include "src/core/util/useful.h" struct grpc_authorization_policy_provider : public grpc_core::DualRefCounted { diff --git a/src/core/lib/security/authorization/authorization_policy_provider_vtable.cc b/src/core/lib/security/authorization/authorization_policy_provider_vtable.cc index ddf1a1201ad..8c8236e2367 100644 --- a/src/core/lib/security/authorization/authorization_policy_provider_vtable.cc +++ b/src/core/lib/security/authorization/authorization_policy_provider_vtable.cc @@ -16,9 +16,9 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/security/authorization/authorization_policy_provider.h" +#include "src/core/util/useful.h" namespace { diff --git a/src/core/lib/security/authorization/evaluate_args.cc b/src/core/lib/security/authorization/evaluate_args.cc index ce4e8c2947a..8da1bd7eeb3 100644 --- a/src/core/lib/security/authorization/evaluate_args.cc +++ b/src/core/lib/security/authorization/evaluate_args.cc @@ -16,6 +16,7 @@ #include +#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::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; diff --git a/src/core/lib/security/authorization/grpc_server_authz_filter.cc b/src/core/lib/security/authorization/grpc_server_authz_filter.cc index 5474847701a..7207b3897fa 100644 --- a/src/core/lib/security/authorization/grpc_server_authz_filter.cc +++ b/src/core/lib/security/authorization/grpc_server_authz_filter.cc @@ -41,6 +41,7 @@ TraceFlag grpc_authz_trace(false, "grpc_authz_api"); const NoInterceptor GrpcServerAuthzFilter::Call::OnServerInitialMetadata; const NoInterceptor GrpcServerAuthzFilter::Call::OnServerTrailingMetadata; const NoInterceptor GrpcServerAuthzFilter::Call::OnClientToServerMessage; +const NoInterceptor GrpcServerAuthzFilter::Call::OnClientToServerHalfClose; const NoInterceptor GrpcServerAuthzFilter::Call::OnServerToClientMessage; const NoInterceptor GrpcServerAuthzFilter::Call::OnFinalize; diff --git a/src/core/lib/security/authorization/grpc_server_authz_filter.h b/src/core/lib/security/authorization/grpc_server_authz_filter.h index b4b0a7463cd..742b3979d88 100644 --- a/src/core/lib/security/authorization/grpc_server_authz_filter.h +++ b/src/core/lib/security/authorization/grpc_server_authz_filter.h @@ -51,6 +51,7 @@ class GrpcServerAuthzFilter final static const NoInterceptor OnServerInitialMetadata; static const NoInterceptor OnServerTrailingMetadata; static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnFinalize; }; diff --git a/src/core/lib/security/authorization/rbac_translator.cc b/src/core/lib/security/authorization/rbac_translator.cc index 44a910476b2..7ae89a4d7a8 100644 --- a/src/core/lib/security/authorization/rbac_translator.cc +++ b/src/core/lib/security/authorization/rbac_translator.cc @@ -37,11 +37,11 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/json/json.h" #include "src/core/lib/json/json_reader.h" #include "src/core/lib/matchers/matchers.h" #include "src/core/lib/security/authorization/audit_logging.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index cac14517afc..0fc65da3f42 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -23,6 +23,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -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( diff --git a/src/core/lib/security/context/security_context.h b/src/core/lib/security/context/security_context.h index 1c1b85bfc63..f07b5b7cc19 100644 --- a/src/core/lib/security/context/security_context.h +++ b/src/core/lib/security/context/security_context.h @@ -33,12 +33,12 @@ #include #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/resource_quota/arena.h" #include "src/core/lib/security/credentials/credentials.h" // IWYU pragma: keep +#include "src/core/util/useful.h" extern grpc_core::DebugOnlyTraceFlag grpc_trace_auth_context_refcount; diff --git a/src/core/lib/security/credentials/alts/alts_credentials.h b/src/core/lib/security/credentials/alts/alts_credentials.h index 46a513a0026..e49ef34be4e 100644 --- a/src/core/lib/security/credentials/alts/alts_credentials.h +++ b/src/core/lib/security/credentials/alts/alts_credentials.h @@ -25,11 +25,11 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/security_connector/security_connector.h" +#include "src/core/util/useful.h" // Main struct for grpc ALTS channel credential. class grpc_alts_credentials final : public grpc_channel_credentials { diff --git a/src/core/lib/security/credentials/alts/check_gcp_environment.cc b/src/core/lib/security/credentials/alts/check_gcp_environment.cc index 3c98988a48e..ff7ce1e33bf 100644 --- a/src/core/lib/security/credentials/alts/check_gcp_environment.cc +++ b/src/core/lib/security/credentials/alts/check_gcp_environment.cc @@ -22,6 +22,8 @@ #include #include +#include "absl/log/log.h" + #include #include #include @@ -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]; diff --git a/src/core/lib/security/credentials/call_creds_util.cc b/src/core/lib/security/credentials/call_creds_util.cc index e946bd64716..c49dd918ab5 100644 --- a/src/core/lib/security/credentials/call_creds_util.cc +++ b/src/core/lib/security/credentials/call_creds_util.cc @@ -18,6 +18,7 @@ #include +#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) { diff --git a/src/core/lib/security/credentials/composite/composite_credentials.h b/src/core/lib/security/credentials/composite/composite_credentials.h index 230706ed935..bcf2915abaa 100644 --- a/src/core/lib/security/credentials/composite/composite_credentials.h +++ b/src/core/lib/security/credentials/composite/composite_credentials.h @@ -33,13 +33,13 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/promise/arena_promise.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/security_connector/security_connector.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/useful.h" // -- Composite channel credentials. -- diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc index dc58615e26a..4220938e31a 100644 --- a/src/core/lib/security/credentials/credentials.cc +++ b/src/core/lib/security/credentials/credentials.cc @@ -28,10 +28,10 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/surface/api_trace.h" +#include "src/core/util/useful.h" // -- Common. -- diff --git a/src/core/lib/security/credentials/fake/fake_credentials.h b/src/core/lib/security/credentials/fake/fake_credentials.h index a18d90d0344..214d9b3ac3e 100644 --- a/src/core/lib/security/credentials/fake/fake_credentials.h +++ b/src/core/lib/security/credentials/fake/fake_credentials.h @@ -30,7 +30,6 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/promise/arena_promise.h" @@ -38,6 +37,7 @@ #include "src/core/lib/security/security_connector/security_connector.h" #include "src/core/lib/slice/slice.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/useful.h" #define GRPC_ARG_FAKE_SECURITY_EXPECTED_TARGETS \ "grpc.fake_security.expected_targets" diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc index b3515b33f11..17455936444 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc @@ -24,6 +24,7 @@ #include #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 sc = diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.h b/src/core/lib/security/credentials/google_default/google_default_credentials.h index acf2fa6404b..8611cbdc254 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.h +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.h @@ -26,11 +26,11 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/security_connector/security_connector.h" +#include "src/core/util/useful.h" #define GRPC_GOOGLE_CLOUD_SDK_CONFIG_DIRECTORY "gcloud" #define GRPC_GOOGLE_WELL_KNOWN_CREDENTIALS_FILE \ diff --git a/src/core/lib/security/credentials/iam/iam_credentials.h b/src/core/lib/security/credentials/iam/iam_credentials.h index e5ed10316dc..592dffc4ebd 100644 --- a/src/core/lib/security/credentials/iam/iam_credentials.h +++ b/src/core/lib/security/credentials/iam/iam_credentials.h @@ -28,12 +28,12 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/promise/arena_promise.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/slice/slice.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/useful.h" class grpc_google_iam_credentials : public grpc_call_credentials { public: diff --git a/src/core/lib/security/credentials/jwt/json_token.cc b/src/core/lib/security/credentials/jwt/json_token.cc index 21bd06fd61b..2f1c5c35fc4 100644 --- a/src/core/lib/security/credentials/jwt/json_token.cc +++ b/src/core/lib/security/credentials/jwt/json_token.cc @@ -30,6 +30,7 @@ #include #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(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(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 = diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.cc b/src/core/lib/security/credentials/jwt/jwt_credentials.cc index bb69678b8f0..b1ae58f2dea 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.cc +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.cc @@ -25,6 +25,7 @@ #include #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_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( diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.h b/src/core/lib/security/credentials/jwt/jwt_credentials.h index 50df9094d0e..91332098eeb 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.h +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.h @@ -35,7 +35,6 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/promise/arena_promise.h" @@ -43,6 +42,7 @@ #include "src/core/lib/security/credentials/jwt/json_token.h" #include "src/core/lib/slice/slice.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/useful.h" class grpc_service_account_jwt_access_credentials : public grpc_call_credentials { diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc index 0e927aa075d..100e09012eb 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" @@ -54,7 +55,6 @@ #include #include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/manual_constructor.h" #include "src/core/lib/gprpp/memory.h" #include "src/core/lib/gprpp/orphanable.h" @@ -72,6 +72,7 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/uri/uri_parser.h" #include "src/core/tsi/ssl_types.h" +#include "src/core/util/string.h" using grpc_core::Json; @@ -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/security/credentials/local/local_credentials.h b/src/core/lib/security/credentials/local/local_credentials.h index 77765bc6242..9665db5d082 100644 --- a/src/core/lib/security/credentials/local/local_credentials.h +++ b/src/core/lib/security/credentials/local/local_credentials.h @@ -26,11 +26,11 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/security_connector/security_connector.h" +#include "src/core/util/useful.h" // Main class for grpc local channel credential. class grpc_local_credentials final : public grpc_channel_credentials { diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index 0c2862940db..63ecb7300e1 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -28,6 +28,7 @@ #include #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_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( diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h index 4bed299f406..491fbcb1768 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h @@ -32,7 +32,6 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -50,6 +49,7 @@ #include "src/core/lib/slice/slice.h" #include "src/core/lib/transport/transport.h" #include "src/core/lib/uri/uri_parser.h" +#include "src/core/util/useful.h" // Constants. #define GRPC_STS_POST_MINIMAL_BODY_FORMAT_STRING \ diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index be6ea721dee..f31b422a93f 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -22,6 +22,7 @@ #include #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; } diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.h b/src/core/lib/security/credentials/plugin/plugin_credentials.h index 715d071e14e..a81dd171202 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.h +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.h @@ -36,7 +36,6 @@ #include #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/unique_type_name.h" @@ -47,6 +46,7 @@ #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/slice/slice.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/useful.h" extern grpc_core::TraceFlag grpc_plugin_credentials_trace; diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.cc b/src/core/lib/security/credentials/ssl/ssl_credentials.cc index 1d178a35a22..9537ce1bb88 100644 --- a/src/core/lib/security/credentials/ssl/ssl_credentials.cc +++ b/src/core/lib/security/credentials/ssl/ssl_credentials.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/types/optional.h" #include @@ -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( @@ -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; } diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.h b/src/core/lib/security/credentials/ssl/ssl_credentials.h index dea04657f23..6651e50202a 100644 --- a/src/core/lib/security/credentials/ssl/ssl_credentials.h +++ b/src/core/lib/security/credentials/ssl/ssl_credentials.h @@ -30,13 +30,13 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/security_connector/security_connector.h" #include "src/core/lib/security/security_connector/ssl/ssl_security_connector.h" #include "src/core/tsi/ssl_transport_security.h" +#include "src/core/util/useful.h" class grpc_ssl_credentials : public grpc_channel_credentials { public: diff --git a/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h b/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h index fb5eaffaa38..d5908d974f0 100644 --- a/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +++ b/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h @@ -33,7 +33,6 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" @@ -41,6 +40,7 @@ #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h" #include "src/core/lib/security/security_connector/ssl_utils.h" +#include "src/core/util/useful.h" // Interface for a grpc_tls_certificate_provider that handles the process to // fetch credentials and validation contexts. Implementations are free to rely diff --git a/src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.h b/src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.h index 507464e3fe3..3cb2bba340c 100644 --- a/src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.h +++ b/src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.h @@ -30,10 +30,10 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/sync.h" #include "src/core/lib/gprpp/unique_type_name.h" +#include "src/core/util/useful.h" // An abstraction of the verifier that all verifier subclasses should extend. struct grpc_tls_certificate_verifier diff --git a/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc b/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc index 0b95cc01264..288b2debc00 100644 --- a/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +++ b/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -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 : ""); } diff --git a/src/core/lib/security/credentials/tls/tls_credentials.cc b/src/core/lib/security/credentials/tls/tls_credentials.cc index 573d56da9f5..de88b4dd342 100644 --- a/src/core/lib/security/credentials/tls/tls_credentials.cc +++ b/src/core/lib/security/credentials/tls/tls_credentials.cc @@ -22,6 +22,7 @@ #include #include +#include "absl/log/log.h" #include "absl/types/optional.h" #include @@ -31,33 +32,33 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.h" #include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h" #include "src/core/lib/security/security_connector/tls/tls_security_connector.h" #include "src/core/tsi/ssl/session_cache/ssl_session_cache.h" +#include "src/core/util/useful.h" 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; } diff --git a/src/core/lib/security/credentials/xds/xds_credentials.cc b/src/core/lib/security/credentials/xds/xds_credentials.cc index d04cf39f335..7de65edb356 100644 --- a/src/core/lib/security/credentials/xds/xds_credentials.cc +++ b/src/core/lib/security/credentials/xds/xds_credentials.cc @@ -27,12 +27,12 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h" #include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h" #include "src/core/lib/security/credentials/tls/tls_credentials.h" #include "src/core/lib/security/credentials/tls/tls_utils.h" #include "src/core/load_balancing/xds/xds_channel_args.h" +#include "src/core/util/useful.h" #include "src/core/xds/grpc/xds_certificate_provider.h" namespace grpc_core { diff --git a/src/core/lib/security/security_connector/fake/fake_security_connector.cc b/src/core/lib/security/security_connector/fake/fake_security_connector.cc index df335267390..21aa4bc62a5 100644 --- a/src/core/lib/security/security_connector/fake/fake_security_connector.cc +++ b/src/core/lib/security/security_connector/fake/fake_security_connector.cc @@ -41,8 +41,6 @@ #include "src/core/handshaker/handshaker.h" #include "src/core/handshaker/security/security_handshaker.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/host_port.h" @@ -60,6 +58,8 @@ #include "src/core/load_balancing/grpclb/grpclb.h" #include "src/core/tsi/fake_transport_security.h" #include "src/core/tsi/transport_security_interface.h" +#include "src/core/util/string.h" +#include "src/core/util/useful.h" namespace { class grpc_fake_channel_security_connector final diff --git a/src/core/lib/security/security_connector/load_system_roots_supported.cc b/src/core/lib/security/security_connector/load_system_roots_supported.cc index aaf72713a5f..a7dd8610de5 100644 --- a/src/core/lib/security/security_connector/load_system_roots_supported.cc +++ b/src/core/lib/security/security_connector/load_system_roots_supported.cc @@ -32,15 +32,17 @@ #include #include +#include "absl/log/log.h" + #include #include #include "src/core/lib/config/config_vars.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/load_file.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/security/security_connector/load_system_roots.h" #include "src/core/lib/security/security_connector/load_system_roots_supported.h" +#include "src/core/util/useful.h" namespace grpc_core { namespace { @@ -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; } } } diff --git a/src/core/lib/security/security_connector/load_system_roots_windows.cc b/src/core/lib/security/security_connector/load_system_roots_windows.cc index 280d0900410..74e5b664c6a 100644 --- a/src/core/lib/security/security_connector/load_system_roots_windows.cc +++ b/src/core/lib/security/security_connector/load_system_roots_windows.cc @@ -32,9 +32,9 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/security/security_connector/load_system_roots.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/util/useful.h" namespace grpc_core { namespace { diff --git a/src/core/lib/security/security_connector/security_connector.cc b/src/core/lib/security/security_connector/security_connector.cc index 2307ebb9bfe..3090ba61928 100644 --- a/src/core/lib/security/security_connector/security_connector.cc +++ b/src/core/lib/security/security_connector/security_connector.cc @@ -28,9 +28,9 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/security/credentials/credentials.h" +#include "src/core/util/useful.h" grpc_core::DebugOnlyTraceFlag grpc_trace_security_connector_refcount( false, "security_connector_refcount"); diff --git a/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc b/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc index c41c5521676..52ec0f39534 100644 --- a/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +++ b/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc @@ -25,6 +25,7 @@ #include #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; } diff --git a/src/core/lib/security/security_connector/ssl_utils.cc b/src/core/lib/security/security_connector/ssl_utils.cc index ec48677eb2c..1e69711bf33 100644 --- a/src/core/lib/security/security_connector/ssl_utils.cc +++ b/src/core/lib/security/security_connector/ssl_utils.cc @@ -26,6 +26,7 @@ #include #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" @@ -43,7 +44,6 @@ #include "src/core/ext/transport/chttp2/alpn/alpn.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/config/config_vars.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/load_file.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -51,6 +51,7 @@ #include "src/core/lib/security/security_connector/load_system_roots.h" #include "src/core/tsi/ssl_transport_security.h" #include "src/core/tsi/transport_security.h" +#include "src/core/util/useful.h" // -- Constants. -- @@ -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 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_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(); diff --git a/src/core/lib/security/security_connector/tls/tls_security_connector.cc b/src/core/lib/security/security_connector/tls/tls_security_connector.cc index cf0668d80b9..e74d9ca2bc4 100644 --- a/src/core/lib/security/security_connector/tls/tls_security_connector.cc +++ b/src/core/lib/security/security_connector/tls/tls_security_connector.cc @@ -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."; } } } diff --git a/src/core/lib/security/transport/auth_filters.h b/src/core/lib/security/transport/auth_filters.h index 06b8b6e6fae..3970ae1e4f3 100644 --- a/src/core/lib/security/transport/auth_filters.h +++ b/src/core/lib/security/transport/auth_filters.h @@ -115,6 +115,7 @@ class ServerAuthFilter final : public ImplementChannelFilter { } static const NoInterceptor OnServerInitialMetadata; static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnServerTrailingMetadata; static const NoInterceptor OnFinalize; diff --git a/src/core/lib/security/transport/server_auth_filter.cc b/src/core/lib/security/transport/server_auth_filter.cc index 4b6ef0a1f10..bfbfeb2d8ae 100644 --- a/src/core/lib/security/transport/server_auth_filter.cc +++ b/src/core/lib/security/transport/server_auth_filter.cc @@ -68,6 +68,7 @@ const grpc_channel_filter ServerAuthFilter::kFilter = "server-auth"); const NoInterceptor ServerAuthFilter::Call::OnClientToServerMessage; +const NoInterceptor ServerAuthFilter::Call::OnClientToServerHalfClose; const NoInterceptor ServerAuthFilter::Call::OnServerToClientMessage; const NoInterceptor ServerAuthFilter::Call::OnServerInitialMetadata; const NoInterceptor ServerAuthFilter::Call::OnServerTrailingMetadata; diff --git a/src/core/lib/slice/slice.h b/src/core/lib/slice/slice.h index 06388adc19e..2dc1d4164c7 100644 --- a/src/core/lib/slice/slice.h +++ b/src/core/lib/slice/slice.h @@ -30,10 +30,10 @@ #include #include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_refcount.h" +#include "src/core/util/string.h" // Herein lies grpc_core::Slice and its team of thin wrappers around grpc_slice. // They aim to keep you safe by providing strong guarantees around lifetime and diff --git a/src/core/lib/slice/slice_string_helpers.cc b/src/core/lib/slice/slice_string_helpers.cc index d56a7de8943..f2c4346cf25 100644 --- a/src/core/lib/slice/slice_string_helpers.cc +++ b/src/core/lib/slice/slice_string_helpers.cc @@ -20,7 +20,7 @@ #include -#include "src/core/lib/gpr/string.h" +#include "src/core/util/string.h" char* grpc_dump_slice(const grpc_slice& s, uint32_t flags) { return gpr_dump(reinterpret_cast GRPC_SLICE_START_PTR(s), diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 4c425b87470..cd9a15d0bd6 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" @@ -65,9 +66,6 @@ #include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/stats_data.h" #include "src/core/lib/experiments/experiments.h" -#include "src/core/lib/gpr/alloc.h" -#include "src/core/lib/gpr/time_precise.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/bitset.h" #include "src/core/lib/gprpp/cpp_impl_of.h" #include "src/core/lib/gprpp/crash.h" @@ -106,6 +104,9 @@ #include "src/core/lib/transport/metadata_batch.h" #include "src/core/lib/transport/transport.h" #include "src/core/server/server_interface.h" +#include "src/core/util/alloc.h" +#include "src/core/util/time_precise.h" +#include "src/core/util/useful.h" grpc_core::TraceFlag grpc_call_error_trace(false, "call_error"); grpc_core::TraceFlag grpc_compression_trace(false, "compression"); @@ -124,7 +125,7 @@ using GrpcClosure = Closure; Call::ParentCall* Call::GetOrCreateParentCall() { ParentCall* p = parent_call_.load(std::memory_order_acquire); if (p == nullptr) { - p = arena_->New(); + p = arena()->New(); ParentCall* expected = nullptr; if (!parent_call_.compare_exchange_strong(expected, p, std::memory_order_release, @@ -243,28 +244,6 @@ void Call::PropagateCancellationToChildren() { } } -char* Call::GetPeer() { - Slice peer_slice = GetPeerString(); - if (!peer_slice.empty()) { - absl::string_view peer_string_view = peer_slice.as_string_view(); - char* peer_string = - static_cast(gpr_malloc(peer_string_view.size() + 1)); - memcpy(peer_string, peer_string_view.data(), peer_string_view.size()); - peer_string[peer_string_view.size()] = '\0'; - return peer_string; - } - char* peer_string = grpc_channel_get_target(channel_->c_ptr()); - if (peer_string != nullptr) return peer_string; - return gpr_strdup("unknown"); -} - -void Call::DeleteThis() { - RefCountedPtr channel = std::move(channel_); - Arena* arena = arena_; - this->~Call(); - channel->DestroyArena(arena); -} - void Call::PrepareOutgoingInitialMetadata(const grpc_op& op, grpc_metadata_batch& md) { // TODO(juanlishen): If the user has already specified a compression @@ -279,7 +258,7 @@ void Call::PrepareOutgoingInitialMetadata(const grpc_op& op, op.data.send_initial_metadata.maybe_compression_level.level; level_set = true; } else { - const grpc_compression_options copts = channel()->compression_options(); + const grpc_compression_options copts = compression_options(); if (copts.default_level.is_set) { level_set = true; effective_compression_level = copts.default_level.level; @@ -311,13 +290,12 @@ void Call::ProcessIncomingInitialMetadata(grpc_metadata_batch& md) { md.Take(GrpcAcceptEncodingMetadata()) .value_or(CompressionAlgorithmSet{GRPC_COMPRESS_NONE}); - const grpc_compression_options compression_options = - channel_->compression_options(); + const grpc_compression_options copts = compression_options(); const grpc_compression_algorithm compression_algorithm = incoming_compression_algorithm_; - if (GPR_UNLIKELY(!CompressionAlgorithmSet::FromUint32( - compression_options.enabled_algorithms_bitset) - .IsSet(compression_algorithm))) { + if (GPR_UNLIKELY( + !CompressionAlgorithmSet::FromUint32(copts.enabled_algorithms_bitset) + .IsSet(compression_algorithm))) { // check if algorithm is supported by current channel config HandleCompressionAlgorithmDisabled(compression_algorithm); } @@ -347,7 +325,7 @@ void Call::HandleCompressionAlgorithmDisabled( grpc_compression_algorithm_name(compression_algorithm, &algo_name); std::string error_msg = absl::StrFormat("Compression algorithm '%s' is disabled.", algo_name); - gpr_log(GPR_ERROR, "%s", error_msg.c_str()); + LOG(ERROR) << error_msg; CancelWithError(grpc_error_set_int(absl::UnimplementedError(error_msg), StatusIntProperty::kRpcStatus, GRPC_STATUS_UNIMPLEMENTED)); @@ -367,22 +345,20 @@ void Call::UpdateDeadline(Timestamp deadline) { StatusIntProperty::kRpcStatus, GRPC_STATUS_DEADLINE_EXCEEDED)); return; } - auto* const event_engine = channel()->event_engine(); if (deadline_ != Timestamp::InfFuture()) { - if (!event_engine->Cancel(deadline_task_)) return; + if (!event_engine_->Cancel(deadline_task_)) return; } else { InternalRef("deadline"); } deadline_ = deadline; - deadline_task_ = event_engine->RunAfter(deadline - Timestamp::Now(), this); + deadline_task_ = event_engine_->RunAfter(deadline - Timestamp::Now(), this); } void Call::ResetDeadline() { { MutexLock lock(&deadline_mu_); if (deadline_ == Timestamp::InfFuture()) return; - auto* const event_engine = channel()->event_engine(); - if (!event_engine->Cancel(deadline_task_)) return; + if (!event_engine_->Cancel(deadline_task_)) return; deadline_ = Timestamp::InfFuture(); } InternalUnref("deadline[reset]"); @@ -397,11 +373,68 @@ void Call::Run() { InternalUnref("deadline[run]"); } +/////////////////////////////////////////////////////////////////////////////// +// ChannelBasedCall +// TODO(ctiller): once we remove the v2 client code this can be folded into +// FilterStackCall + +class ChannelBasedCall : public Call { + protected: + ChannelBasedCall(Arena* arena, bool is_client, Timestamp send_deadline, + RefCountedPtr channel) + : Call(is_client, send_deadline, channel->event_engine()), + arena_(arena), + channel_(std::move(channel)) { + DCHECK_NE(arena_, nullptr); + } + + Arena* arena() final { return arena_; } + + char* GetPeer() final { + Slice peer_slice = GetPeerString(); + if (!peer_slice.empty()) { + absl::string_view peer_string_view = peer_slice.as_string_view(); + char* peer_string = + static_cast(gpr_malloc(peer_string_view.size() + 1)); + memcpy(peer_string, peer_string_view.data(), peer_string_view.size()); + peer_string[peer_string_view.size()] = '\0'; + return peer_string; + } + char* peer_string = grpc_channel_get_target(channel_->c_ptr()); + if (peer_string != nullptr) return peer_string; + return gpr_strdup("unknown"); + } + + grpc_event_engine::experimental::EventEngine* event_engine() const override { + return channel_->event_engine(); + } + + grpc_compression_options compression_options() override { + return channel_->compression_options(); + } + + void DeleteThis() { + RefCountedPtr channel = std::move(channel_); + Arena* arena = arena_; + this->~ChannelBasedCall(); + channel->DestroyArena(arena); + } + + Channel* channel() const { return channel_.get(); } + + // Non-virtual arena accessor -- needed by PipeBasedCall + Arena* GetArena() { return arena_; } + + private: + Arena* const arena_; + RefCountedPtr channel_; +}; + /////////////////////////////////////////////////////////////////////////////// // FilterStackCall // To be removed once promise conversion is complete -class FilterStackCall final : public Call { +class FilterStackCall final : public ChannelBasedCall { public: ~FilterStackCall() override { for (int i = 0; i < GRPC_CONTEXT_COUNT; ++i) { @@ -430,10 +463,6 @@ class FilterStackCall final : public Call { GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(*this))); } - grpc_event_engine::experimental::EventEngine* event_engine() const override { - return channel()->event_engine(); - } - grpc_call_element* call_elem(size_t idx) { return grpc_call_stack_element(call_stack(), idx); } @@ -569,8 +598,8 @@ class FilterStackCall final : public Call { }; FilterStackCall(Arena* arena, const grpc_call_create_args& args) - : Call(arena, args.server_transport_data == nullptr, args.send_deadline, - args.channel->Ref()), + : ChannelBasedCall(arena, args.server_transport_data == nullptr, + args.send_deadline, args.channel->Ref()), cq_(args.cq), stream_op_payload_(context_) { context_[GRPC_CONTEXT_CALL].value = this; @@ -1138,8 +1167,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)); @@ -1874,15 +1902,15 @@ bool ValidateMetadata(size_t count, grpc_metadata* metadata) { // PromiseBasedCall // Will be folded into Call once the promise conversion is done -class BasicPromiseBasedCall : public Call, public Party { +class BasicPromiseBasedCall : public ChannelBasedCall, public Party { public: using Call::arena; BasicPromiseBasedCall(Arena* arena, uint32_t initial_external_refs, uint32_t initial_internal_refs, const grpc_call_create_args& args) - : Call(arena, args.server_transport_data == nullptr, args.send_deadline, - args.channel->Ref()), + : ChannelBasedCall(arena, args.server_transport_data == nullptr, + args.send_deadline, args.channel->Ref()), Party(initial_internal_refs), external_refs_(initial_external_refs), cq_(args.cq) { @@ -1903,7 +1931,6 @@ class BasicPromiseBasedCall : public Call, public Party { virtual void OrphanCall() = 0; - virtual ServerCallContext* server_call_context() { return nullptr; } void SetCompletionQueue(grpc_completion_queue* cq) final { cq_ = cq; GRPC_CQ_INTERNAL_REF(cq, "bind"); @@ -2533,10 +2560,6 @@ void CallContext::IncrementRefCount(const char* reason) { void CallContext::Unref(const char* reason) { call_->InternalUnref(reason); } -ServerCallContext* CallContext::server_call_context() { - return call_->server_call_context(); -} - RefCountedPtr CallContext::MakeCallSpine( CallArgs call_args) { return call_->MakeCallSpine(std::move(call_args)); @@ -2780,12 +2803,12 @@ class ClientPromiseBasedCall final : public PromiseBasedCall { void PublishInitialMetadata(ServerMetadata* metadata); ClientMetadataHandle send_initial_metadata_; - Pipe server_initial_metadata_{arena()}; + Pipe server_initial_metadata_{GetArena()}; Latch server_trailing_metadata_; Latch cancel_error_; Latch polling_entity_; - Pipe client_to_server_messages_{arena()}; - Pipe server_to_client_messages_{arena()}; + Pipe client_to_server_messages_{GetArena()}; + Pipe server_to_client_messages_{GetArena()}; bool is_trailers_only_ = false; bool scheduled_receive_status_ = false; bool scheduled_send_close_ = false; @@ -3092,242 +3115,7 @@ void ClientPromiseBasedCall::StartRecvStatusOnClient( #endif /////////////////////////////////////////////////////////////////////////////// -// ServerPromiseBasedCall - -#ifdef GRPC_EXPERIMENT_IS_INCLUDED_PROMISE_BASED_SERVER_CALL - -class ServerPromiseBasedCall final : public PromiseBasedCall, - public ServerCallContext { - public: - ServerPromiseBasedCall(Arena* arena, grpc_call_create_args* args); - - void OrphanCall() override {} - void CancelWithError(grpc_error_handle) override; - grpc_call_error StartBatch(const grpc_op* ops, size_t nops, void* notify_tag, - bool is_notify_tag_closure) override; - bool is_trailers_only() const override { - Crash("is_trailers_only not implemented for server calls"); - } - absl::string_view GetServerAuthority() const override { - const Slice* authority_metadata = - client_initial_metadata_->get_pointer(HttpAuthorityMetadata()); - if (authority_metadata == nullptr) return ""; - return authority_metadata->as_string_view(); - } - - // Polling order for the server promise stack: - // - // │ ┌───────────────────────────────────────┐ - // │ │ ServerPromiseBasedCall ├──► Lifetime management - // │ ├───────────────────────────────────────┤ - // │ │ ConnectedChannel ├─┐ - // │ ├───────────────────────────────────────┤ └► Interactions with the - // │ │ ... closest to transport filter │ transport - send/recv msgs - // │ ├───────────────────────────────────────┤ and metadata, call phase - // │ │ ... │ ordering - // │ ├───────────────────────────────────────┤ - // │ │ ... closest to app filter │ ┌► Request matching, initial - // │ ├───────────────────────────────────────┤ │ setup, publishing call to - // │ │ Server::ChannelData::MakeCallPromise ├─┘ application - // │ ├───────────────────────────────────────┤ - // │ │ MakeTopOfServerCallPromise ├──► Send trailing metadata - // ▼ └───────────────────────────────────────┘ - // Polling & - // instantiation - // order - - std::string DebugTag() const override { - return absl::StrFormat("SERVER_CALL[%p]: ", this); - } - - ServerCallContext* server_call_context() override { return this; } - - const void* server_stream_data() override { return server_transport_data_; } - void PublishInitialMetadata( - ClientMetadataHandle metadata, - grpc_metadata_array* publish_initial_metadata) override; - ArenaPromise MakeTopOfServerCallPromise( - CallArgs call_args, grpc_completion_queue* cq, - absl::FunctionRef publish) override; - - private: - class RecvCloseOpCancelState { - public: - // Request that receiver be filled in per - // grpc_op_recv_close_on_server. Returns true if the request can - // be fulfilled immediately. Returns false if the request will be - // fulfilled later. - bool ReceiveCloseOnServerOpStarted(int* receiver) { - uintptr_t state = state_.load(std::memory_order_acquire); - uintptr_t new_state; - do { - switch (state) { - case kUnset: - new_state = reinterpret_cast(receiver); - break; - case kFinishedWithFailure: - *receiver = 1; - return true; - case kFinishedWithSuccess: - *receiver = 0; - return true; - default: - Crash("Two threads offered ReceiveCloseOnServerOpStarted"); - } - } while (!state_.compare_exchange_weak(state, new_state, - std::memory_order_acq_rel, - std::memory_order_acquire)); - return false; - } - - // Mark the call as having completed. - // Returns true if this finishes a previous - // RequestReceiveCloseOnServer. - bool CompleteCallWithCancelledSetTo(bool cancelled) { - uintptr_t state = state_.load(std::memory_order_acquire); - uintptr_t new_state; - bool r; - do { - switch (state) { - case kUnset: - new_state = cancelled ? kFinishedWithFailure : kFinishedWithSuccess; - r = false; - break; - case kFinishedWithFailure: - return false; - case kFinishedWithSuccess: - Crash("unreachable"); - default: - new_state = cancelled ? kFinishedWithFailure : kFinishedWithSuccess; - r = true; - } - } while (!state_.compare_exchange_weak(state, new_state, - std::memory_order_acq_rel, - std::memory_order_acquire)); - if (r) *reinterpret_cast(state) = cancelled ? 1 : 0; - return r; - } - - std::string ToString() const { - auto state = state_.load(std::memory_order_relaxed); - switch (state) { - case kUnset: - return "Unset"; - case kFinishedWithFailure: - return "FinishedWithFailure"; - case kFinishedWithSuccess: - return "FinishedWithSuccess"; - default: - return absl::StrFormat("WaitingForReceiver(%p)", - reinterpret_cast(state)); - } - } - - private: - static constexpr uintptr_t kUnset = 0; - static constexpr uintptr_t kFinishedWithFailure = 1; - static constexpr uintptr_t kFinishedWithSuccess = 2; - // Holds one of kUnset, kFinishedWithFailure, or - // kFinishedWithSuccess OR an int* that wants to receive the - // final status. - std::atomic state_{kUnset}; - }; - - void CommitBatch(const grpc_op* ops, size_t nops, - const Completion& completion); - void Finish(ServerMetadataHandle result); - - ServerInterface* const server_; - const void* const server_transport_data_; - PipeSender* server_initial_metadata_ = nullptr; - PipeSender* server_to_client_messages_ = nullptr; - PipeReceiver* client_to_server_messages_ = nullptr; - Latch send_trailing_metadata_; - RecvCloseOpCancelState recv_close_op_cancel_state_; - ClientMetadataHandle client_initial_metadata_; - Completion recv_close_completion_; - std::atomic cancelled_{false}; -}; - -ServerPromiseBasedCall::ServerPromiseBasedCall(Arena* arena, - grpc_call_create_args* args) - : PromiseBasedCall(arena, 0, *args), - server_(args->server), - server_transport_data_(args->server_transport_data) { - global_stats().IncrementServerCallsCreated(); - channelz::ServerNode* channelz_node = server_->channelz_node(); - if (channelz_node != nullptr) { - channelz_node->RecordCallStarted(); - } - ScopedContext activity_context(this); - // TODO(yashykt): In the future, we want to also enable stats and trace - // collecting from when the call is created at the transport. The idea is that - // the transport would create the call tracer and pass it in as part of the - // metadata. - // TODO(yijiem): OpenCensus and internal Census is still using this way to - // set server call tracer. We need to refactor them to stats plugins - // (including removing the client channel filters). - if (args->server != nullptr && - args->server->server_call_tracer_factory() != nullptr) { - auto* server_call_tracer = - args->server->server_call_tracer_factory()->CreateNewServerCallTracer( - arena, args->server->channel_args()); - if (server_call_tracer != nullptr) { - // Note that we are setting both - // GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE and - // GRPC_CONTEXT_CALL_TRACER as a matter of convenience. In the future - // promise-based world, we would just a single tracer object for each - // stack (call, subchannel_call, server_call.) - ContextSet(GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE, - server_call_tracer, nullptr); - ContextSet(GRPC_CONTEXT_CALL_TRACER, server_call_tracer, nullptr); - } - } - args->channel->channel_stack()->stats_plugin_group->AddServerCallTracers( - context()); - Spawn("server_promise", - channel()->channel_stack()->MakeServerCallPromise( - CallArgs{nullptr, ClientInitialMetadataOutstandingToken::Empty(), - nullptr, nullptr, nullptr, nullptr}), - [this](ServerMetadataHandle result) { Finish(std::move(result)); }); -} - -void ServerPromiseBasedCall::Finish(ServerMetadataHandle result) { - if (grpc_call_trace.enabled()) { - gpr_log(GPR_INFO, "%s[call] Finish: recv_close_state:%s result:%s", - DebugTag().c_str(), recv_close_op_cancel_state_.ToString().c_str(), - result->DebugString().c_str()); - } - const auto status = - result->get(GrpcStatusMetadata()).value_or(GRPC_STATUS_UNKNOWN); - channelz::ServerNode* channelz_node = server_->channelz_node(); - if (channelz_node != nullptr) { - if (status == GRPC_STATUS_OK) { - channelz_node->RecordCallSucceeded(); - } else { - channelz_node->RecordCallFailed(); - } - } - bool was_cancelled = result->get(GrpcCallWasCancelled()).value_or(true); - if (recv_close_op_cancel_state_.CompleteCallWithCancelledSetTo( - was_cancelled)) { - FinishOpOnCompletion(&recv_close_completion_, - PendingOp::kReceiveCloseOnServer); - } - if (was_cancelled) set_failed_before_recv_message(); - if (server_initial_metadata_ != nullptr) { - server_initial_metadata_->Close(); - } - Slice message_slice; - if (Slice* message = result->get_pointer(GrpcMessageMetadata())) { - message_slice = message->Ref(); - } - AcceptTransportStatsFromContext(); - SetFinalizationStatus(status, std::move(message_slice)); - set_completed(); - ResetDeadline(); - PropagateCancellationToChildren(); -} +// CallSpine based Server Call grpc_call_error ValidateServerBatch(const grpc_op* ops, size_t nops) { BitSet<8> got_ops; @@ -3371,234 +3159,33 @@ grpc_call_error ValidateServerBatch(const grpc_op* ops, size_t nops) { return GRPC_CALL_OK; } -void ServerPromiseBasedCall::CommitBatch(const grpc_op* ops, size_t nops, - const Completion& completion) { - Party::BulkSpawner spawner(this); - for (size_t op_idx = 0; op_idx < nops; op_idx++) { - const grpc_op& op = ops[op_idx]; - switch (op.op) { - case GRPC_OP_SEND_INITIAL_METADATA: { - auto metadata = arena()->MakePooled(); - PrepareOutgoingInitialMetadata(op, *metadata); - CToMetadata(op.data.send_initial_metadata.metadata, - op.data.send_initial_metadata.count, metadata.get()); - if (grpc_call_trace.enabled()) { - gpr_log(GPR_INFO, "%s[call] Send initial metadata", - DebugTag().c_str()); - } - QueueSend(); - spawner.Spawn( - "call_send_initial_metadata", - [this, metadata = std::move(metadata)]() mutable { - EnactSend(); - return server_initial_metadata_->Push(std::move(metadata)); - }, - [this, - completion = AddOpToCompletion( - completion, PendingOp::kSendInitialMetadata)](bool r) mutable { - if (!r) { - set_failed_before_recv_message(); - FailCompletion(completion); - } - FinishOpOnCompletion(&completion, - PendingOp::kSendInitialMetadata); - }); - } break; - case GRPC_OP_SEND_MESSAGE: - StartSendMessage(op, completion, server_to_client_messages_, spawner); - break; - case GRPC_OP_RECV_MESSAGE: - if (cancelled_.load(std::memory_order_relaxed)) { - set_failed_before_recv_message(); - FailCompletion(completion); - break; - } - StartRecvMessage( - op, completion, []() { return []() { return Empty{}; }; }, - client_to_server_messages_, true, spawner); - break; - case GRPC_OP_SEND_STATUS_FROM_SERVER: { - auto metadata = arena()->MakePooled(); - CToMetadata(op.data.send_status_from_server.trailing_metadata, - op.data.send_status_from_server.trailing_metadata_count, - metadata.get()); - metadata->Set(GrpcStatusMetadata(), - op.data.send_status_from_server.status); - if (auto* details = op.data.send_status_from_server.status_details) { - // TODO(ctiller): this should not be a copy, but we have callers that - // allocate and pass in a slice created with - // grpc_slice_from_static_string and then delete the string after - // passing it in, which shouldn't be a supported API. - metadata->Set(GrpcMessageMetadata(), - Slice(grpc_slice_copy(*details))); - } - spawner.Spawn( - "call_send_status_from_server", - [this, metadata = std::move(metadata)]() mutable { - bool r = true; - if (send_trailing_metadata_.is_set()) { - r = false; - } else { - send_trailing_metadata_.Set(std::move(metadata)); - } - return Map(WaitForSendingStarted(), [this, r](Empty) { - server_initial_metadata_->Close(); - server_to_client_messages_->Close(); - return r; - }); - }, - [this, completion = AddOpToCompletion( - completion, PendingOp::kSendStatusFromServer)]( - bool ok) mutable { - if (!ok) { - set_failed_before_recv_message(); - FailCompletion(completion); - } - FinishOpOnCompletion(&completion, - PendingOp::kSendStatusFromServer); - }); - } break; - case GRPC_OP_RECV_CLOSE_ON_SERVER: - if (grpc_call_trace.enabled()) { - gpr_log(GPR_INFO, "%s[call] StartBatch: RecvClose %s", - DebugTag().c_str(), - recv_close_op_cancel_state_.ToString().c_str()); - } - ForceCompletionSuccess(completion); - recv_close_completion_ = - AddOpToCompletion(completion, PendingOp::kReceiveCloseOnServer); - if (recv_close_op_cancel_state_.ReceiveCloseOnServerOpStarted( - op.data.recv_close_on_server.cancelled)) { - FinishOpOnCompletion(&recv_close_completion_, - PendingOp::kReceiveCloseOnServer); - } - break; - case GRPC_OP_RECV_STATUS_ON_CLIENT: - case GRPC_OP_SEND_CLOSE_FROM_CLIENT: - case GRPC_OP_RECV_INITIAL_METADATA: - abort(); // unreachable - } - } -} - -grpc_call_error ServerPromiseBasedCall::StartBatch(const grpc_op* ops, - size_t nops, - void* notify_tag, - bool is_notify_tag_closure) { - if (nops == 0) { - EndOpImmediately(cq(), notify_tag, is_notify_tag_closure); - return GRPC_CALL_OK; - } - const grpc_call_error validation_result = ValidateServerBatch(ops, nops); - if (validation_result != GRPC_CALL_OK) { - return validation_result; - } - Completion completion = - StartCompletion(notify_tag, is_notify_tag_closure, ops); - CommitBatch(ops, nops, completion); - FinishOpOnCompletion(&completion, PendingOp::kStartingBatch); - return GRPC_CALL_OK; -} - -void ServerPromiseBasedCall::CancelWithError(absl::Status error) { - cancelled_.store(true, std::memory_order_relaxed); - Spawn( - "cancel_with_error", - [this, error = std::move(error)]() { - if (!send_trailing_metadata_.is_set()) { - auto md = ServerMetadataFromStatus(error); - md->Set(GrpcCallWasCancelled(), true); - send_trailing_metadata_.Set(std::move(md)); - } - if (server_to_client_messages_ != nullptr) { - server_to_client_messages_->Close(); - } - if (server_initial_metadata_ != nullptr) { - server_initial_metadata_->Close(); - } - return Empty{}; - }, - [](Empty) {}); -} -#endif - -#ifdef GRPC_EXPERIMENT_IS_INCLUDED_PROMISE_BASED_SERVER_CALL -void ServerPromiseBasedCall::PublishInitialMetadata( - ClientMetadataHandle metadata, - grpc_metadata_array* publish_initial_metadata) { - if (grpc_call_trace.enabled()) { - gpr_log(GPR_INFO, "%s[call] PublishInitialMetadata: %s", DebugTag().c_str(), - metadata->DebugString().c_str()); - } - PublishMetadataArray(metadata.get(), publish_initial_metadata, false); - client_initial_metadata_ = std::move(metadata); -} - -ArenaPromise -ServerPromiseBasedCall::MakeTopOfServerCallPromise( - CallArgs call_args, grpc_completion_queue* cq, - absl::FunctionRef publish) { - SetCompletionQueue(cq); - call_args.polling_entity->Set( - grpc_polling_entity_create_from_pollset(grpc_cq_pollset(cq))); - server_to_client_messages_ = call_args.server_to_client_messages; - client_to_server_messages_ = call_args.client_to_server_messages; - server_initial_metadata_ = call_args.server_initial_metadata; - absl::optional deadline = - client_initial_metadata_->get(GrpcTimeoutMetadata()); - if (deadline.has_value()) { - set_send_deadline(*deadline); - UpdateDeadline(*deadline); - } - ProcessIncomingInitialMetadata(*client_initial_metadata_); - ExternalRef(); - publish(c_ptr()); - return Seq(server_to_client_messages_->AwaitClosed(), - send_trailing_metadata_.Wait()); -} - -/////////////////////////////////////////////////////////////////////////////// -// CallSpine based Server Call - -class ServerCallSpine final : public PipeBasedCallSpine, - public ServerCallContext, - public BasicPromiseBasedCall { +class ServerCall final : public Call, public DualRefCounted { public: - ServerCallSpine(ClientMetadataHandle client_initial_metadata, - ServerInterface* server, Channel* channel, Arena* arena); - - // CallSpineInterface - Pipe& client_initial_metadata() override { - return client_initial_metadata_; - } - Pipe& server_initial_metadata() override { - return server_initial_metadata_; - } - Pipe& client_to_server_messages() override { - return client_to_server_messages_; - } - Pipe& server_to_client_messages() override { - return server_to_client_messages_; + ServerCall(ClientMetadataHandle client_initial_metadata, + CallHandler call_handler, ServerInterface* server, + grpc_completion_queue* cq) + : Call(false, + client_initial_metadata->get(GrpcTimeoutMetadata()) + .value_or(Timestamp::InfFuture()), + call_handler.event_engine()), + call_handler_(std::move(call_handler)), + client_initial_metadata_stored_(std::move(client_initial_metadata)), + cq_(cq), + server_(server) { + call_handler_.legacy_context()[GRPC_CONTEXT_CALL].value = + static_cast(this); + global_stats().IncrementServerCallsCreated(); } - Latch& cancel_latch() override { return cancel_latch_; } - Latch& was_cancelled_latch() override { return was_cancelled_latch_; } - Party& party() override { return *this; } - Arena* arena() override { return BasicPromiseBasedCall::arena(); } - void IncrementRefCount() override { InternalRef("CallSpine"); } - void Unref() override { InternalUnref("CallSpine"); } - // PromiseBasedCall - void OrphanCall() override { - ResetDeadline(); - CancelWithError(absl::CancelledError()); - } void CancelWithError(grpc_error_handle error) override { - SpawnInfallible("CancelWithError", [this, error = std::move(error)] { - auto status = ServerMetadataFromStatus(error); - status->Set(GrpcCallWasCancelled(), true); - PushServerTrailingMetadata(std::move(status)); - return Empty{}; - }); + call_handler_.SpawnInfallible( + "CancelWithError", + [self = WeakRefAsSubclass(), error = std::move(error)] { + auto status = ServerMetadataFromStatus(error); + status->Set(GrpcCallWasCancelled(), true); + self->call_handler_.PushServerTrailingMetadata(std::move(status)); + return Empty{}; + }); } bool is_trailers_only() const override { Crash("is_trailers_only not implemented for server calls"); @@ -3609,102 +3196,78 @@ class ServerCallSpine final : public PipeBasedCallSpine, grpc_call_error StartBatch(const grpc_op* ops, size_t nops, void* notify_tag, bool is_notify_tag_closure) override; - bool Completed() final { Crash("unimplemented"); } - bool failed_before_recv_message() const final { Crash("unimplemented"); } + Arena* arena() override { return call_handler_.arena(); } - ServerCallContext* server_call_context() override { return this; } - const void* server_stream_data() override { Crash("unimplemented"); } - void PublishInitialMetadata( - ClientMetadataHandle metadata, - grpc_metadata_array* publish_initial_metadata) override; - ArenaPromise MakeTopOfServerCallPromise( - CallArgs, grpc_completion_queue*, - absl::FunctionRef) override { - Crash("unimplemented"); + grpc_event_engine::experimental::EventEngine* event_engine() const override { + return call_handler_.event_engine(); } - void V2HackToStartCallWithoutACallFilterStack() override {} + void ExternalRef() override { Ref().release(); } + void ExternalUnref() override { Unref(); } + void InternalRef(const char*) override { WeakRef().release(); } + void InternalUnref(const char*) override { WeakUnref(); } - ClientMetadata& UnprocessedClientInitialMetadata() override { - Crash("not for v2"); + void Orphaned() override { + // TODO(ctiller): only when we're not already finished + CancelWithError(absl::CancelledError()); } - bool RunParty() override { - ScopedContext ctx(this); - return Party::RunParty(); + void ContextSet(grpc_context_index elem, void* value, + void (*destroy)(void*)) override { + call_handler_.legacy_context()[elem] = + grpc_call_context_element{value, destroy}; + } + + void* ContextGet(grpc_context_index elem) const override { + return call_handler_.legacy_context()[elem].value; + } + + void SetCompletionQueue(grpc_completion_queue*) override { + Crash("unimplemented"); + } + + grpc_compression_options compression_options() override { + return server_->compression_options(); } + grpc_call_stack* call_stack() override { return nullptr; } + + char* GetPeer() override { + Slice peer_slice = GetPeerString(); + if (!peer_slice.empty()) { + absl::string_view peer_string_view = peer_slice.as_string_view(); + char* peer_string = + static_cast(gpr_malloc(peer_string_view.size() + 1)); + memcpy(peer_string, peer_string_view.data(), peer_string_view.size()); + peer_string[peer_string_view.size()] = '\0'; + return peer_string; + } + return gpr_strdup("unknown"); + } + + bool Completed() final { Crash("unimplemented"); } + bool failed_before_recv_message() const final { Crash("unimplemented"); } + private: void CommitBatch(const grpc_op* ops, size_t nops, void* notify_tag, bool is_notify_tag_closure); - StatusFlag FinishRecvMessage(NextResult result); + StatusFlag FinishRecvMessage( + ValueOrFailure> result); - std::string DebugTag() const override { - return absl::StrFormat("SERVER_CALL_SPINE[%p]: ", this); - } - - // Initial metadata from client to server - Pipe client_initial_metadata_; - // Initial metadata from server to client - Pipe server_initial_metadata_; - // Messages travelling from the application to the transport. - Pipe client_to_server_messages_; - // Messages travelling from the transport to the application. - Pipe server_to_client_messages_; - // Latch that can be set to terminate the call - Latch cancel_latch_; - Latch was_cancelled_latch_; + std::string DebugTag() { return absl::StrFormat("SERVER_CALL[%p]: ", this); } + + CallHandler call_handler_; grpc_byte_buffer** recv_message_ = nullptr; ClientMetadataHandle client_initial_metadata_stored_; + grpc_completion_queue* const cq_; + ServerInterface* const server_; }; -ServerCallSpine::ServerCallSpine(ClientMetadataHandle client_initial_metadata, - ServerInterface* server, Channel* channel, - Arena* arena) - : BasicPromiseBasedCall(arena, 0, 1, - [channel, server]() -> grpc_call_create_args { - grpc_call_create_args args; - args.channel = channel->Ref(); - args.server = server; - args.parent = nullptr; - args.propagation_mask = 0; - args.cq = nullptr; - args.pollset_set_alternative = nullptr; - args.server_transport_data = - &args; // Arbitrary non-null pointer - args.send_deadline = Timestamp::InfFuture(); - return args; - }()), - client_initial_metadata_(arena), - server_initial_metadata_(arena), - client_to_server_messages_(arena), - server_to_client_messages_(arena) { - global_stats().IncrementServerCallsCreated(); - ScopedContext ctx(this); - channel->channel_stack()->InitServerCallSpine(this); - SpawnGuarded("push_client_initial_metadata", - [this, md = std::move(client_initial_metadata)]() mutable { - return Map(client_initial_metadata_.sender.Push(std::move(md)), - [](bool r) { return StatusFlag(r); }); - }); -} - -void ServerCallSpine::PublishInitialMetadata( - ClientMetadataHandle metadata, - grpc_metadata_array* publish_initial_metadata) { - if (grpc_call_trace.enabled()) { - gpr_log(GPR_INFO, "%s[call] PublishInitialMetadata: %s", DebugTag().c_str(), - metadata->DebugString().c_str()); - } - PublishMetadataArray(metadata.get(), publish_initial_metadata, false); - client_initial_metadata_stored_ = std::move(metadata); -} - -grpc_call_error ServerCallSpine::StartBatch(const grpc_op* ops, size_t nops, - void* notify_tag, - bool is_notify_tag_closure) { +grpc_call_error ServerCall::StartBatch(const grpc_op* ops, size_t nops, + void* notify_tag, + bool is_notify_tag_closure) { if (nops == 0) { - EndOpImmediately(cq(), notify_tag, is_notify_tag_closure); + EndOpImmediately(cq_, notify_tag, is_notify_tag_closure); return GRPC_CALL_OK; } const grpc_call_error validation_result = ValidateServerBatch(ops, nops); @@ -3716,63 +3279,86 @@ grpc_call_error ServerCallSpine::StartBatch(const grpc_op* ops, size_t nops, } namespace { -template +template class MaybeOpImpl { public: - using SetupResult = decltype(std::declval()(grpc_op())); using PromiseFactory = promise_detail::OncePromiseFactory; using Promise = typename PromiseFactory::Promise; - struct Dismissed {}; - using State = absl::variant; + static_assert(!std::is_same::value, + "PromiseFactory must return a promise"); + + MaybeOpImpl() : state_(State::kDismissed) {} + explicit MaybeOpImpl(SetupResult result) : state_(State::kPromiseFactory) { + Construct(&promise_factory_, std::move(result)); + } - // op_ is garbage but shouldn't be uninitialized - MaybeOpImpl() : state_(Dismissed{}), op_(GRPC_OP_RECV_STATUS_ON_CLIENT) {} - MaybeOpImpl(SetupResult result, grpc_op_type op) - : state_(PromiseFactory(std::move(result))), op_(op) {} + ~MaybeOpImpl() { + switch (state_) { + case State::kDismissed: + break; + case State::kPromiseFactory: + Destruct(&promise_factory_); + break; + case State::kPromise: + Destruct(&promise_); + break; + } + } MaybeOpImpl(const MaybeOpImpl&) = delete; MaybeOpImpl& operator=(const MaybeOpImpl&) = delete; - MaybeOpImpl(MaybeOpImpl&& other) noexcept - : state_(MoveState(other.state_)), op_(other.op_) {} - MaybeOpImpl& operator=(MaybeOpImpl&& other) noexcept { - op_ = other.op_; - if (absl::holds_alternative(state_)) { - state_.template emplace(); - return *this; + MaybeOpImpl(MaybeOpImpl&& other) noexcept : state_(other.state_) { + switch (state_) { + case State::kDismissed: + break; + case State::kPromiseFactory: + Construct(&promise_factory_, std::move(other.promise_factory_)); + break; + case State::kPromise: + Construct(&promise_, std::move(other.promise_)); + break; } - // Can't move after first poll => Promise is not an option - state_.template emplace( - std::move(absl::get(other.state_))); - return *this; } + MaybeOpImpl& operator=(MaybeOpImpl&& other) noexcept = delete; Poll operator()() { - if (absl::holds_alternative(state_)) return Success{}; - if (absl::holds_alternative(state_)) { - auto& factory = absl::get(state_); - auto promise = factory.Make(); - state_.template emplace(std::move(promise)); - } - if (grpc_call_trace.enabled()) { - gpr_log(GPR_INFO, "%sBeginPoll %s", - Activity::current()->DebugTag().c_str(), OpName(op_).c_str()); - } - auto& promise = absl::get(state_); - auto r = poll_cast(promise()); - if (grpc_call_trace.enabled()) { - gpr_log(GPR_INFO, "%sEndPoll %s --> %s", - Activity::current()->DebugTag().c_str(), OpName(op_).c_str(), + switch (state_) { + case State::kDismissed: + return Success{}; + case State::kPromiseFactory: { + auto promise = promise_factory_.Make(); + Destruct(&promise_factory_); + Construct(&promise_, std::move(promise)); + state_ = State::kPromise; + } + ABSL_FALLTHROUGH_INTENDED; + case State::kPromise: { + if (grpc_call_trace.enabled()) { + gpr_log(GPR_INFO, "%sBeginPoll %s", + Activity::current()->DebugTag().c_str(), OpName()); + } + auto r = poll_cast(promise_()); + if (grpc_call_trace.enabled()) { + gpr_log( + GPR_INFO, "%sEndPoll %s --> %s", + Activity::current()->DebugTag().c_str(), OpName(), r.pending() ? "PENDING" : (r.value().ok() ? "OK" : "FAILURE")); + } + return r; + } } - return r; + GPR_UNREACHABLE_CODE(return Pending{}); } private: - GPR_NO_UNIQUE_ADDRESS State state_; - GPR_NO_UNIQUE_ADDRESS grpc_op_type op_; + enum class State { + kDismissed, + kPromiseFactory, + kPromise, + }; - static std::string OpName(grpc_op_type op) { - switch (op) { + static const char* OpName() { + switch (kOp) { case GRPC_OP_SEND_INITIAL_METADATA: return "SendInitialMetadata"; case GRPC_OP_SEND_MESSAGE: @@ -3790,30 +3376,34 @@ class MaybeOpImpl { case GRPC_OP_RECV_STATUS_ON_CLIENT: return "RecvStatusOnClient"; } - return absl::StrCat("UnknownOp(", op, ")"); + Crash("Unreachable"); } - static State MoveState(State& state) { - if (absl::holds_alternative(state)) return Dismissed{}; - // Can't move after first poll => Promise is not an option - return std::move(absl::get(state)); - } + // gcc-12 has problems with this being a variant + GPR_NO_UNIQUE_ADDRESS State state_; + union { + PromiseFactory promise_factory_; + Promise promise_; + }; }; -// MaybeOp captures a fairly complicated dance we need to do for the batch API. -// We first check if an op is included or not, and if it is, we run the setup -// function in the context of the API call (NOT in the call party). -// This setup function returns a promise factory which we'll then run *in* the +// MaybeOp captures a fairly complicated dance we need to do for the batch +// API. We first check if an op is included or not, and if it is, we run the +// setup function in the context of the API call (NOT in the call party). This +// setup function returns a promise factory which we'll then run *in* the // party to do initial setup, and have it return the promise that we'll // ultimately poll on til completion. // Once we express our surface API in terms of core internal types this whole // dance will go away. -template -auto MaybeOp(const grpc_op* ops, uint8_t idx, SetupFn setup) { - if (idx == 255) { - return MaybeOpImpl(); +template +auto MaybeOp(const grpc_op* ops, const std::array& idxs, + SetupFn setup) { + using SetupResult = decltype(std::declval()(grpc_op())); + if (idxs[op_type] == 255) { + return MaybeOpImpl(); } else { - return MaybeOpImpl(setup(ops[idx]), ops[idx].op); + auto r = setup(ops[idxs[op_type]]); + return MaybeOpImpl(std::move(r)); } } @@ -3851,63 +3441,61 @@ PollBatchLogger LogPollBatch(void* tag, F f) { } } // namespace -StatusFlag ServerCallSpine::FinishRecvMessage( - NextResult result) { - if (result.has_value()) { - MessageHandle& message = *result; - NoteLastMessageFlags(message->flags()); - if ((message->flags() & GRPC_WRITE_INTERNAL_COMPRESS) && - (incoming_compression_algorithm() != GRPC_COMPRESS_NONE)) { - *recv_message_ = grpc_raw_compressed_byte_buffer_create( - nullptr, 0, incoming_compression_algorithm()); - } else { - *recv_message_ = grpc_raw_byte_buffer_create(nullptr, 0); - } - grpc_slice_buffer_move_into(message->payload()->c_slice_buffer(), - &(*recv_message_)->data.raw.slice_buffer); +StatusFlag ServerCall::FinishRecvMessage( + ValueOrFailure> result) { + if (!result.ok()) { if (grpc_call_trace.enabled()) { gpr_log(GPR_INFO, "%s[call] RecvMessage: outstanding_recv " - "finishes: received %" PRIdPTR " byte message", - DebugTag().c_str(), - (*recv_message_)->data.raw.slice_buffer.length); + "finishes: received end-of-stream with error", + DebugTag().c_str()); } + *recv_message_ = nullptr; recv_message_ = nullptr; - return Success{}; + return Failure{}; } - if (result.cancelled()) { + if (!result->has_value()) { if (grpc_call_trace.enabled()) { gpr_log(GPR_INFO, "%s[call] RecvMessage: outstanding_recv " - "finishes: received end-of-stream with error", + "finishes: received end-of-stream", DebugTag().c_str()); } *recv_message_ = nullptr; recv_message_ = nullptr; - return Failure{}; + return Success{}; } + MessageHandle& message = **result; + NoteLastMessageFlags(message->flags()); + if ((message->flags() & GRPC_WRITE_INTERNAL_COMPRESS) && + (incoming_compression_algorithm() != GRPC_COMPRESS_NONE)) { + *recv_message_ = grpc_raw_compressed_byte_buffer_create( + nullptr, 0, incoming_compression_algorithm()); + } else { + *recv_message_ = grpc_raw_byte_buffer_create(nullptr, 0); + } + grpc_slice_buffer_move_into(message->payload()->c_slice_buffer(), + &(*recv_message_)->data.raw.slice_buffer); if (grpc_call_trace.enabled()) { gpr_log(GPR_INFO, "%s[call] RecvMessage: outstanding_recv " - "finishes: received end-of-stream", - DebugTag().c_str()); + "finishes: received %" PRIdPTR " byte message", + DebugTag().c_str(), (*recv_message_)->data.raw.slice_buffer.length); } - *recv_message_ = nullptr; recv_message_ = nullptr; return Success{}; } -void ServerCallSpine::CommitBatch(const grpc_op* ops, size_t nops, - void* notify_tag, - bool is_notify_tag_closure) { +void ServerCall::CommitBatch(const grpc_op* ops, size_t nops, void* notify_tag, + bool is_notify_tag_closure) { std::array got_ops{255, 255, 255, 255, 255, 255, 255, 255}; for (size_t op_idx = 0; op_idx < nops; op_idx++) { const grpc_op& op = ops[op_idx]; got_ops[op.op] = op_idx; } - if (!is_notify_tag_closure) grpc_cq_begin_op(cq(), notify_tag); - auto send_initial_metadata = MaybeOp( - ops, got_ops[GRPC_OP_SEND_INITIAL_METADATA], [this](const grpc_op& op) { + if (!is_notify_tag_closure) grpc_cq_begin_op(cq_, notify_tag); + auto send_initial_metadata = MaybeOp( + ops, got_ops, [this](const grpc_op& op) { auto metadata = arena()->MakePooled(); PrepareOutgoingInitialMetadata(op, *metadata); CToMetadata(op.data.send_initial_metadata.metadata, @@ -3917,27 +3505,22 @@ void ServerCallSpine::CommitBatch(const grpc_op* ops, size_t nops, DebugTag().c_str()); } return [this, metadata = std::move(metadata)]() mutable { - return Map(server_initial_metadata_.sender.Push(std::move(metadata)), - [this](bool r) { - server_initial_metadata_.sender.Close(); - return StatusFlag(r); - }); + return call_handler_.PushServerInitialMetadata(std::move(metadata)); }; }); auto send_message = - MaybeOp(ops, got_ops[GRPC_OP_SEND_MESSAGE], [this](const grpc_op& op) { + MaybeOp(ops, got_ops, [this](const grpc_op& op) { SliceBuffer send; grpc_slice_buffer_swap( &op.data.send_message.send_message->data.raw.slice_buffer, send.c_slice_buffer()); auto msg = arena()->MakePooled(std::move(send), op.flags); return [this, msg = std::move(msg)]() mutable { - return Map(server_to_client_messages_.sender.Push(std::move(msg)), - [](bool r) { return StatusFlag(r); }); + return call_handler_.PushMessage(std::move(msg)); }; }); - auto send_trailing_metadata = MaybeOp( - ops, got_ops[GRPC_OP_SEND_STATUS_FROM_SERVER], [this](const grpc_op& op) { + auto send_trailing_metadata = MaybeOp( + ops, got_ops, [this](const grpc_op& op) { auto metadata = arena()->MakePooled(); CToMetadata(op.data.send_status_from_server.trailing_metadata, op.data.send_status_from_server.trailing_metadata_count, @@ -3958,18 +3541,18 @@ void ServerCallSpine::CommitBatch(const grpc_op* ops, size_t nops, return [this, metadata = std::move(metadata)]() mutable -> Poll { CHECK(metadata != nullptr); - PushServerTrailingMetadata(std::move(metadata)); + call_handler_.PushServerTrailingMetadata(std::move(metadata)); return Success{}; }; }; }); auto recv_message = - MaybeOp(ops, got_ops[GRPC_OP_RECV_MESSAGE], [this](const grpc_op& op) { + MaybeOp(ops, got_ops, [this](const grpc_op& op) { CHECK_EQ(recv_message_, nullptr); recv_message_ = op.data.recv_message.recv_message; return [this]() mutable { - return Map(client_to_server_messages_.receiver.Next(), - [this](NextResult msg) { + return Map(call_handler_.PullMessage(), + [this](ValueOrFailure> msg) { return FinishRecvMessage(std::move(msg)); }); }; @@ -3980,10 +3563,10 @@ void ServerCallSpine::CommitBatch(const grpc_op* ops, size_t nops, std::move(send_trailing_metadata)), std::move(recv_message)); if (got_ops[GRPC_OP_RECV_CLOSE_ON_SERVER] != 255) { - auto recv_trailing_metadata = MaybeOp( - ops, got_ops[GRPC_OP_RECV_CLOSE_ON_SERVER], [this](const grpc_op& op) { + auto recv_trailing_metadata = MaybeOp( + ops, got_ops, [this](const grpc_op& op) { return [this, cancelled = op.data.recv_close_on_server.cancelled]() { - return Map(WasCancelled(), + return Map(call_handler_.WasCancelled(), [cancelled, this](bool result) -> Success { ResetDeadline(); *cancelled = result ? 1 : 0; @@ -3991,7 +3574,7 @@ void ServerCallSpine::CommitBatch(const grpc_op* ops, size_t nops, }); }; }); - SpawnInfallible( + call_handler_.SpawnInfallible( "final-batch", [primary_ops = std::move(primary_ops), recv_trailing_metadata = std::move(recv_trailing_metadata), @@ -4001,37 +3584,38 @@ void ServerCallSpine::CommitBatch(const grpc_op* ops, size_t nops, Seq(std::move(primary_ops), std::move(recv_trailing_metadata), [is_notify_tag_closure, notify_tag, this](StatusFlag) { return WaitForCqEndOp(is_notify_tag_closure, notify_tag, - absl::OkStatus(), cq()); + absl::OkStatus(), cq_); })); }); } else { - SpawnInfallible("batch", [primary_ops = std::move(primary_ops), - is_notify_tag_closure, notify_tag, - this]() mutable { - return LogPollBatch( - notify_tag, - Seq(std::move(primary_ops), - [is_notify_tag_closure, notify_tag, this](StatusFlag r) { + call_handler_.SpawnInfallible( + "batch", [primary_ops = std::move(primary_ops), is_notify_tag_closure, + notify_tag, this]() mutable { + return LogPollBatch( + notify_tag, + Seq(std::move(primary_ops), [is_notify_tag_closure, notify_tag, + this](StatusFlag r) { return WaitForCqEndOp(is_notify_tag_closure, notify_tag, - StatusCast(r), cq()); + StatusCast(r), cq_); })); - }); + }); } } -RefCountedPtr MakeServerCall( - ClientMetadataHandle client_initial_metadata, ServerInterface* server, - Channel* channel, Arena* arena) { - return RefCountedPtr(arena->New( - std::move(client_initial_metadata), server, channel, arena)); +grpc_call* MakeServerCall(CallHandler call_handler, + ClientMetadataHandle client_initial_metadata, + ServerInterface* server, grpc_completion_queue* cq, + grpc_metadata_array* publish_initial_metadata) { + PublishMetadataArray(client_initial_metadata.get(), publish_initial_metadata, + false); + // TODO(ctiller): ideally we'd put this in the arena with the CallHandler, + // but there's an ownership problem: CallHandler owns the arena, and so would + // get destroyed before the base class Call destructor runs, leading to + // UB/crash. Investigate another path. + return (new ServerCall(std::move(client_initial_metadata), + std::move(call_handler), server, cq)) + ->c_ptr(); } -#else -RefCountedPtr MakeServerCall(ClientMetadataHandle, - ServerInterface*, Channel*, - Arena*) { - Crash("not implemented"); -} -#endif } // namespace grpc_core diff --git a/src/core/lib/surface/call.h b/src/core/lib/surface/call.h index 9fb12f279e4..c0ccaf842cc 100644 --- a/src/core/lib/surface/call.h +++ b/src/core/lib/surface/call.h @@ -38,7 +38,6 @@ #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/context.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/time_precise.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/iomgr/closure.h" @@ -52,6 +51,7 @@ #include "src/core/lib/surface/channel.h" #include "src/core/lib/transport/transport.h" #include "src/core/server/server_interface.h" +#include "src/core/util/time_precise.h" typedef void (*grpc_ioreq_completion_func)(grpc_call* call, int success, void* user_data); @@ -82,7 +82,7 @@ class Call : public CppImplOf, public grpc_event_engine::experimental::EventEngine:: Closure /* for deadlines */ { public: - Arena* arena() { return arena_; } + virtual Arena* arena() = 0; bool is_client() const { return is_client_; } virtual void ContextSet(grpc_context_index elem, void* value, @@ -92,7 +92,7 @@ class Call : public CppImplOf, void CancelWithStatus(grpc_status_code status, const char* description); virtual void CancelWithError(grpc_error_handle error) = 0; virtual void SetCompletionQueue(grpc_completion_queue* cq) = 0; - char* GetPeer(); + virtual char* GetPeer() = 0; virtual grpc_call_error StartBatch(const grpc_op* ops, size_t nops, void* notify_tag, bool is_notify_tag_closure) = 0; @@ -157,25 +157,15 @@ class Call : public CppImplOf, Call* sibling_prev = nullptr; }; - Call(Arena* arena, bool is_client, Timestamp send_deadline, - RefCountedPtr channel) - : channel_(std::move(channel)), - arena_(arena), - send_deadline_(send_deadline), - is_client_(is_client) { - DCHECK_NE(arena_, nullptr); - DCHECK(channel_ != nullptr); - } + Call(bool is_client, Timestamp send_deadline, + grpc_event_engine::experimental::EventEngine* event_engine) + : send_deadline_(send_deadline), + is_client_(is_client), + event_engine_(event_engine) {} ~Call() override = default; - void DeleteThis(); - ParentCall* GetOrCreateParentCall(); ParentCall* parent_call(); - Channel* channel() const { - DCHECK(channel_ != nullptr); - return channel_.get(); - } absl::Status InitParent(Call* parent, uint32_t propagation_mask); void PublishToParent(Call* parent); @@ -221,9 +211,9 @@ class Call : public CppImplOf, gpr_cycle_counter start_time() const { return start_time_; } + virtual grpc_compression_options compression_options() = 0; + private: - RefCountedPtr channel_; - Arena* const arena_; std::atomic parent_call_{nullptr}; ChildCall* child_ = nullptr; Timestamp send_deadline_; @@ -247,34 +237,13 @@ class Call : public CppImplOf, Timestamp deadline_ ABSL_GUARDED_BY(deadline_mu_) = Timestamp::InfFuture(); grpc_event_engine::experimental::EventEngine::TaskHandle ABSL_GUARDED_BY( deadline_mu_) deadline_task_; + grpc_event_engine::experimental::EventEngine* const event_engine_; gpr_cycle_counter start_time_ = gpr_get_cycle_counter(); }; class BasicPromiseBasedCall; class ServerPromiseBasedCall; -class ServerCallContext { - public: - virtual void PublishInitialMetadata( - ClientMetadataHandle metadata, - grpc_metadata_array* publish_initial_metadata) = 0; - - // Construct the top of the server call promise for the v2 filter stack. - // TODO(ctiller): delete when v3 is available. - virtual ArenaPromise MakeTopOfServerCallPromise( - CallArgs call_args, grpc_completion_queue* cq, - absl::FunctionRef publish) = 0; - - // Server stream data as supplied by the transport (so we can link the - // transport stream up with the call again). - // TODO(ctiller): legacy API - once we move transports to promises we'll - // create the promise directly and not need to pass around this token. - virtual const void* server_stream_data() = 0; - - protected: - ~ServerCallContext() = default; -}; - // TODO(ctiller): move more call things into this type class CallContext { public: @@ -300,8 +269,6 @@ class CallContext { gpr_atm* peer_string_atm_ptr(); gpr_cycle_counter call_start_time() { return start_time_; } - ServerCallContext* server_call_context(); - void set_traced(bool traced) { traced_ = traced; } bool traced() const { return traced_; } @@ -329,9 +296,10 @@ template <> struct ContextType {}; // TODO(ctiller): remove once call-v3 finalized -RefCountedPtr MakeServerCall( - ClientMetadataHandle client_initial_metadata, ServerInterface* server, - Channel* channel, Arena* arena); +grpc_call* MakeServerCall(CallHandler call_handler, + ClientMetadataHandle client_initial_metadata, + ServerInterface* server, grpc_completion_queue* cq, + grpc_metadata_array* publish_initial_metadata); } // namespace grpc_core diff --git a/src/core/lib/surface/call_log_batch.cc b/src/core/lib/surface/call_log_batch.cc index 6bb0abd0c24..dac553984d2 100644 --- a/src/core/lib/surface/call_log_batch.cc +++ b/src/core/lib/surface/call_log_batch.cc @@ -31,10 +31,10 @@ #include #include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/surface/call.h" +#include "src/core/util/string.h" static void add_metadata(const grpc_metadata* md, size_t count, std::vector* b) { diff --git a/src/core/lib/surface/channel_init.cc b/src/core/lib/surface/channel_init.cc index b94b189ffea..da694aa59be 100644 --- a/src/core/lib/surface/channel_init.cc +++ b/src/core/lib/surface/channel_init.cc @@ -27,6 +27,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" @@ -104,9 +105,9 @@ ChannelInit::FilterRegistration::ExcludeFromMinimalStack() { ChannelInit::FilterRegistration& ChannelInit::Builder::RegisterFilter( grpc_channel_stack_type type, const grpc_channel_filter* filter, - const ChannelFilterVtable* vtable, SourceLocation registration_source) { + FilterAdder filter_adder, SourceLocation registration_source) { filters_[type].emplace_back(std::make_unique( - filter, vtable, registration_source)); + filter, filter_adder, registration_source)); return *filters_[type].back(); } @@ -223,9 +224,10 @@ ChannelInit::StackConfig ChannelInit::BuildStackConfig( while (!dependencies.empty()) { auto filter = take_ready_dependency(); auto* registration = filter_to_registration[filter]; - filters.emplace_back( - filter, registration->vtable_, std::move(registration->predicates_), - registration->skip_v3_, registration->registration_source_); + filters.emplace_back(filter, registration->filter_adder_, + std::move(registration->predicates_), + registration->skip_v3_, + registration->registration_source_); for (auto& p : dependencies) { p.second.erase(filter); } @@ -312,7 +314,7 @@ ChannelInit::StackConfig ChannelInit::BuildStackConfig( const auto filter_str = absl::StrCat(" ", loc_strs[filter.filter], NameFromChannelFilter(filter.filter), after_str); - gpr_log(GPR_INFO, "%s", filter_str.c_str()); + LOG(INFO) << filter_str; } // Finally list out the terminal filters and where they were registered // from. @@ -324,7 +326,7 @@ ChannelInit::StackConfig ChannelInit::BuildStackConfig( strlen(NameFromChannelFilter(terminal.filter)), ' '), "[terminal]"); - gpr_log(GPR_INFO, "%s", filter_str.c_str()); + LOG(INFO) << filter_str; } } // Check if there are no terminal filters: this would be an error. @@ -397,7 +399,7 @@ bool ChannelInit::CreateStack(ChannelStackBuilder* builder) const { "\n"); } } - gpr_log(GPR_ERROR, "%s", error.c_str()); + LOG(ERROR) << error; return false; } for (const auto& post_processor : stack_config.post_processors) { @@ -406,78 +408,21 @@ bool ChannelInit::CreateStack(ChannelStackBuilder* builder) const { return true; } -absl::StatusOr ChannelInit::CreateStackSegment( - grpc_channel_stack_type type, const ChannelArgs& args) const { +void ChannelInit::AddToInterceptionChainBuilder( + grpc_channel_stack_type type, InterceptionChainBuilder& builder) const { const auto& stack_config = stack_configs_[type]; - std::vector filters; - size_t channel_data_size = 0; - size_t channel_data_alignment = 0; // Based on predicates build a list of filters to include in this segment. for (const auto& filter : stack_config.filters) { if (filter.skip_v3) continue; - if (!filter.CheckPredicates(args)) continue; - if (filter.vtable == nullptr) { - return absl::InvalidArgumentError( + if (!filter.CheckPredicates(builder.channel_args())) continue; + if (filter.filter_adder == nullptr) { + builder.Fail(absl::InvalidArgumentError( absl::StrCat("Filter ", NameFromChannelFilter(filter.filter), - " has no v3-callstack vtable")); + " has no v3-callstack vtable"))); + return; } - channel_data_alignment = - std::max(channel_data_alignment, filter.vtable->alignment); - if (channel_data_size % filter.vtable->alignment != 0) { - channel_data_size += filter.vtable->alignment - - (channel_data_size % filter.vtable->alignment); - } - filters.push_back({channel_data_size, filter.vtable}); - channel_data_size += filter.vtable->size; - } - // Shortcut for empty segments. - if (filters.empty()) return StackSegment(); - // Allocate memory for the channel data, initialize channel filters into it. - uint8_t* p = static_cast( - gpr_malloc_aligned(channel_data_size, channel_data_alignment)); - for (size_t i = 0; i < filters.size(); i++) { - auto r = filters[i].vtable->init(p + filters[i].offset, args); - if (!r.ok()) { - for (size_t j = 0; j < i; j++) { - filters[j].vtable->destroy(p + filters[j].offset); - } - gpr_free_aligned(p); - return r; - } - } - return StackSegment(std::move(filters), p); -} - -/////////////////////////////////////////////////////////////////////////////// -// ChannelInit::StackSegment - -ChannelInit::StackSegment::StackSegment(std::vector filters, - uint8_t* channel_data) - : data_(MakeRefCounted(std::move(filters), channel_data)) {} - -void ChannelInit::StackSegment::AddToCallFilterStack( - CallFilters::StackBuilder& builder) { - if (data_ == nullptr) return; - data_->AddToCallFilterStack(builder); - builder.AddOwnedObject(data_); -}; - -ChannelInit::StackSegment::ChannelData::ChannelData( - std::vector filters, uint8_t* channel_data) - : filters_(std::move(filters)), channel_data_(channel_data) {} - -void ChannelInit::StackSegment::ChannelData::AddToCallFilterStack( - CallFilters::StackBuilder& builder) { - for (const auto& filter : filters_) { - filter.vtable->add_to_stack_builder(channel_data_ + filter.offset, builder); - } -} - -ChannelInit::StackSegment::ChannelData::~ChannelData() { - for (const auto& filter : filters_) { - filter.vtable->destroy(channel_data_ + filter.offset); + filter.filter_adder(builder); } - gpr_free_aligned(channel_data_); } } // namespace grpc_core diff --git a/src/core/lib/surface/channel_init.h b/src/core/lib/surface/channel_init.h index fcfef582994..c5067394014 100644 --- a/src/core/lib/surface/channel_init.h +++ b/src/core/lib/surface/channel_init.h @@ -38,6 +38,7 @@ #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/surface/channel_stack_type.h" #include "src/core/lib/transport/call_filters.h" +#include "src/core/lib/transport/interception_chain.h" /// This module provides a way for plugins (and the grpc core library itself) /// to register mutators for channel stacks. @@ -68,6 +69,8 @@ class ChannelInit { using InclusionPredicate = absl::AnyInvocable; // Post processor for the channel stack - applied in PostProcessorSlot order using PostProcessor = absl::AnyInvocable; + // Function that can be called to add a filter to a stack builder + using FilterAdder = void (*)(InterceptionChainBuilder&); // Post processing slots - up to one PostProcessor per slot can be registered // They run after filters registered are added to the channel stack builder, // but before Build is called - allowing ad-hoc mutation to the channel stack. @@ -77,25 +80,15 @@ class ChannelInit { kCount }; - // Vtable-like data structure for channel data initialization - struct ChannelFilterVtable { - size_t size; - size_t alignment; - absl::Status (*init)(void* data, const ChannelArgs& args); - void (*destroy)(void* data); - void (*add_to_stack_builder)(void* data, - CallFilters::StackBuilder& builder); - }; - class FilterRegistration { public: // TODO(ctiller): Remove grpc_channel_filter* arg when that can be // deprecated (once filter stack is removed). explicit FilterRegistration(const grpc_channel_filter* filter, - const ChannelFilterVtable* vtable, + FilterAdder filter_adder, SourceLocation registration_source) : filter_(filter), - vtable_(vtable), + filter_adder_(filter_adder), registration_source_(registration_source) {} FilterRegistration(const FilterRegistration&) = delete; FilterRegistration& operator=(const FilterRegistration&) = delete; @@ -170,7 +163,7 @@ class ChannelInit { private: friend class ChannelInit; const grpc_channel_filter* const filter_; - const ChannelFilterVtable* const vtable_; + const FilterAdder filter_adder_; std::vector after_; std::vector before_; std::vector predicates_; @@ -188,16 +181,17 @@ class ChannelInit { // properties of the filter being registered. // TODO(ctiller): remove in favor of the version that does not mention // grpc_channel_filter - FilterRegistration& RegisterFilter( - grpc_channel_stack_type type, const grpc_channel_filter* filter, - const ChannelFilterVtable* vtable = nullptr, - SourceLocation registration_source = {}); + FilterRegistration& RegisterFilter(grpc_channel_stack_type type, + const grpc_channel_filter* filter, + FilterAdder filter_adder = nullptr, + SourceLocation registration_source = {}); template FilterRegistration& RegisterFilter( grpc_channel_stack_type type, SourceLocation registration_source = {}) { - return RegisterFilter(type, &Filter::kFilter, - VtableForType::vtable(), - registration_source); + return RegisterFilter( + type, &Filter::kFilter, + [](InterceptionChainBuilder& builder) { builder.Add(); }, + registration_source); } // Filter does not participate in v3 @@ -232,58 +226,13 @@ class ChannelInit { [static_cast(PostProcessorSlot::kCount)]; }; - // A set of channel filters that can be added to a call stack. - // TODO(ctiller): move this out so it can be used independently of - // the global registration mechanisms. - class StackSegment final { - public: - // Registration of one channel filter in the stack. - struct ChannelFilter { - size_t offset; - const ChannelFilterVtable* vtable; - }; - - StackSegment() = default; - explicit StackSegment(std::vector filters, - uint8_t* channel_data); - StackSegment(const StackSegment& other) = delete; - StackSegment& operator=(const StackSegment& other) = delete; - StackSegment(StackSegment&& other) noexcept = default; - StackSegment& operator=(StackSegment&& other) = default; - - // Add this segment to a call filter stack builder - void AddToCallFilterStack(CallFilters::StackBuilder& builder); - - private: - // Combined channel data for the stack - class ChannelData : public RefCounted { - public: - explicit ChannelData(std::vector filters, - uint8_t* channel_data); - ~ChannelData() override; - - void AddToCallFilterStack(CallFilters::StackBuilder& builder); - - private: - std::vector filters_; - uint8_t* channel_data_; - }; - - RefCountedPtr data_; - }; - /// Construct a channel stack of some sort: see channel_stack.h for details /// \a builder is the channel stack builder to build into. GRPC_MUST_USE_RESULT bool CreateStack(ChannelStackBuilder* builder) const; - // Create a segment of a channel stack. - // Terminators and post processors are not included in this construction: - // terminators are a legacy filter-stack concept, and post processors - // need to migrate to other mechanisms. - // TODO(ctiller): figure out other mechanisms. - absl::StatusOr CreateStackSegment( - grpc_channel_stack_type type, const ChannelArgs& args) const; + void AddToInterceptionChainBuilder(grpc_channel_stack_type type, + InterceptionChainBuilder& builder) const; private: // The type of object returned by a filter's Create method. @@ -292,16 +241,16 @@ class ChannelInit { typename decltype(T::Create(ChannelArgs(), {}))::value_type; struct Filter { - Filter(const grpc_channel_filter* filter, const ChannelFilterVtable* vtable, + Filter(const grpc_channel_filter* filter, FilterAdder filter_adder, std::vector predicates, bool skip_v3, SourceLocation registration_source) : filter(filter), - vtable(vtable), + filter_adder(filter_adder), predicates(std::move(predicates)), registration_source(registration_source), skip_v3(skip_v3) {} const grpc_channel_filter* filter; - const ChannelFilterVtable* vtable; + const FilterAdder filter_adder; std::vector predicates; SourceLocation registration_source; bool skip_v3 = false; @@ -313,17 +262,6 @@ class ChannelInit { std::vector post_processors; }; - template - struct VtableForType { - static const ChannelFilterVtable* vtable() { return nullptr; } - }; - - template - struct VtableForType> { - static const ChannelFilterVtable kVtable; - static const ChannelFilterVtable* vtable() { return &kVtable; } - }; - StackConfig stack_configs_[GRPC_NUM_CHANNEL_STACK_TYPES]; static StackConfig BuildStackConfig( @@ -331,22 +269,6 @@ class ChannelInit { PostProcessor* post_processors, grpc_channel_stack_type type); }; -template -const ChannelInit::ChannelFilterVtable - ChannelInit::VtableForType>::kVtable = { - sizeof(CreatedType), alignof(CreatedType), - [](void* data, const ChannelArgs& args) -> absl::Status { - // TODO(ctiller): fill in ChannelFilter::Args (2nd arg) - absl::StatusOr> r = T::Create(args, {}); - if (!r.ok()) return r.status(); - new (data) CreatedType(std::move(*r)); - return absl::OkStatus(); - }, - [](void* data) { Destruct(static_cast*>(data)); }, - [](void* data, CallFilters::StackBuilder& builder) { - builder.Add(static_cast*>(data)->get()); - }}; - } // namespace grpc_core #endif // GRPC_SRC_CORE_LIB_SURFACE_CHANNEL_INIT_H diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 5d777b50741..b439191f1bb 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -28,6 +28,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" @@ -42,7 +43,6 @@ #include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/stats_data.h" -#include "src/core/lib/gpr/spinlock.h" #include "src/core/lib/gprpp/atomic_utils.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/ref_counted.h" @@ -55,6 +55,7 @@ #include "src/core/lib/iomgr/pollset.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/event_string.h" +#include "src/core/util/spinlock.h" #ifdef GPR_WINDOWS #include "src/core/lib/experiments/experiments.h" @@ -260,7 +261,7 @@ struct cq_next_data { CHECK_EQ(queue.num_items(), 0); #ifndef NDEBUG if (pending_events.load(std::memory_order_acquire) != 0) { - gpr_log(GPR_ERROR, "Destroying CQ without draining it fully."); + LOG(ERROR) << "Destroying CQ without draining it fully."; } #endif } @@ -290,7 +291,7 @@ struct cq_pluck_data { CHECK(completed_head.next == reinterpret_cast(&completed_head)); #ifndef NDEBUG if (pending_events.load(std::memory_order_acquire) != 0) { - gpr_log(GPR_ERROR, "Destroying CQ without draining it fully."); + LOG(ERROR) << "Destroying CQ without draining it fully."; } #endif } @@ -327,7 +328,7 @@ struct cq_callback_data { ~cq_callback_data() { #ifndef NDEBUG if (pending_events.load(std::memory_order_acquire) != 0) { - gpr_log(GPR_ERROR, "Destroying CQ without draining it fully."); + LOG(ERROR) << "Destroying CQ without draining it fully."; } #endif } @@ -942,7 +943,7 @@ static void dump_pending_tags(grpc_completion_queue* cq) { parts.push_back(absl::StrFormat(" %p", cq->outstanding_tags[i])); } gpr_mu_unlock(cq->mu); - gpr_log(GPR_DEBUG, "%s", absl::StrJoin(parts, "").c_str()); + VLOG(2) << absl::StrJoin(parts, ""); } #else static void dump_pending_tags(grpc_completion_queue* /*cq*/) {} diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 3ff4c77f062..fc8e75484d2 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -19,6 +19,7 @@ #include "src/core/lib/surface/init.h" #include "absl/base/thread_annotations.h" +#include "absl/log/log.h" #include #include @@ -66,10 +67,10 @@ static bool g_shutting_down ABSL_GUARDED_BY(g_init_mu) = false; namespace grpc_core { void RegisterSecurityFilters(CoreConfiguration::Builder* builder) { builder->channel_init() - ->RegisterFilter(GRPC_CLIENT_SUBCHANNEL) + ->RegisterV2Filter(GRPC_CLIENT_SUBCHANNEL) .IfHasChannelArg(GRPC_ARG_SECURITY_CONNECTOR); builder->channel_init() - ->RegisterFilter(GRPC_CLIENT_DIRECT_CHANNEL) + ->RegisterV2Filter(GRPC_CLIENT_DIRECT_CHANNEL) .IfHasChannelArg(GRPC_ARG_SECURITY_CONNECTOR); builder->channel_init() ->RegisterFilter(GRPC_SERVER_CHANNEL) @@ -137,7 +138,7 @@ void grpc_shutdown_from_cleanup_thread(void* /*ignored*/) { return; } grpc_shutdown_internal_locked(); - gpr_log(GPR_DEBUG, "grpc_shutdown from cleanup thread done"); + VLOG(2) << "grpc_shutdown from cleanup thread done"; } void grpc_shutdown(void) { @@ -155,14 +156,14 @@ void grpc_shutdown(void) { 0) && grpc_core::ExecCtx::Get() == nullptr) { // just run clean-up when this is called on non-executor thread. - gpr_log(GPR_DEBUG, "grpc_shutdown starts clean-up now"); + VLOG(2) << "grpc_shutdown starts clean-up now"; g_shutting_down = true; grpc_shutdown_internal_locked(); - gpr_log(GPR_DEBUG, "grpc_shutdown done"); + VLOG(2) << "grpc_shutdown done"; } else { // spawn a detached thread to do the actual clean up in case we are // currently in an executor thread. - gpr_log(GPR_DEBUG, "grpc_shutdown spawns clean-up thread"); + VLOG(2) << "grpc_shutdown spawns clean-up thread"; g_initializations++; g_shutting_down = true; grpc_core::Thread cleanup_thread( diff --git a/src/core/lib/surface/lame_client.cc b/src/core/lib/surface/lame_client.cc index 8966f34ebf7..f573194a42e 100644 --- a/src/core/lib/surface/lame_client.cc +++ b/src/core/lib/surface/lame_client.cc @@ -36,7 +36,6 @@ #include "src/core/lib/channel/promise_based_filter.h" #include "src/core/lib/config/core_configuration.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" @@ -49,6 +48,7 @@ #include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/metadata_batch.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/useful.h" // Avoid some IWYU confusion: // IWYU pragma: no_include "src/core/lib/gprpp/orphanable.h" diff --git a/src/core/lib/surface/legacy_channel.cc b/src/core/lib/surface/legacy_channel.cc index 104924d42b7..d8f53540e32 100644 --- a/src/core/lib/surface/legacy_channel.cc +++ b/src/core/lib/surface/legacy_channel.cc @@ -93,13 +93,13 @@ absl::StatusOr> LegacyChannel::Create( *(*r)->stats_plugin_group = GlobalStatsPluginRegistry::GetStatsPluginsForServer(args); } else { - experimental::StatsPluginChannelScope scope( - target, args.GetOwnedString(GRPC_ARG_DEFAULT_AUTHORITY) - .value_or(CoreConfiguration::Get() - .resolver_registry() - .GetDefaultAuthority(target))); + std::string authority = args.GetOwnedString(GRPC_ARG_DEFAULT_AUTHORITY) + .value_or(CoreConfiguration::Get() + .resolver_registry() + .GetDefaultAuthority(target)); *(*r)->stats_plugin_group = - GlobalStatsPluginRegistry::GetStatsPluginsForChannel(scope); + GlobalStatsPluginRegistry::GetStatsPluginsForChannel( + experimental::StatsPluginChannelScope(target, authority)); } return MakeOrphanable( grpc_channel_stack_type_is_client(builder.channel_stack_type()), diff --git a/src/core/lib/transport/call_destination.h b/src/core/lib/transport/call_destination.h index 77683e230f5..938e0fd3725 100644 --- a/src/core/lib/transport/call_destination.h +++ b/src/core/lib/transport/call_destination.h @@ -51,6 +51,24 @@ class CallDestination : public DualRefCounted { virtual void HandleCall(CallHandler unstarted_call_handler) = 0; }; +template +auto MakeCallDestinationFromHandlerFunction(HC handle_call) { + class Impl : public CallDestination { + public: + explicit Impl(HC handle_call) : handle_call_(std::move(handle_call)) {} + + void Orphaned() override {} + + void HandleCall(CallHandler call_handler) override { + handle_call_(std::move(call_handler)); + } + + private: + HC handle_call_; + }; + return MakeRefCounted(std::move(handle_call)); +} + } // namespace grpc_core #endif // GRPC_SRC_CORE_LIB_TRANSPORT_CALL_DESTINATION_H diff --git a/src/core/lib/transport/call_filters.cc b/src/core/lib/transport/call_filters.cc index d4792c02bfe..2b89babdde4 100644 --- a/src/core/lib/transport/call_filters.cc +++ b/src/core/lib/transport/call_filters.cc @@ -29,6 +29,12 @@ void* Offset(void* base, size_t amt) { return static_cast(base) + amt; } namespace filters_detail { +void RunHalfClose(absl::Span ops, void* call_data) { + for (const auto& op : ops) { + op.half_close(Offset(call_data, op.call_offset), op.channel_data); + } +} + template OperationExecutor::~OperationExecutor() { if (promise_data_ != nullptr) { diff --git a/src/core/lib/transport/call_filters.h b/src/core/lib/transport/call_filters.h index a9e3a1c5b98..fd267fd1685 100644 --- a/src/core/lib/transport/call_filters.h +++ b/src/core/lib/transport/call_filters.h @@ -43,6 +43,7 @@ // - OnServerInitialMetadata - $VALUE_TYPE = ServerMetadata // - OnServerToClientMessage - $VALUE_TYPE = Message // - OnClientToServerMessage - $VALUE_TYPE = Message +// - OnClientToServerHalfClose - no value // - OnServerTrailingMetadata - $VALUE_TYPE = ServerMetadata // - OnFinalize - special, see below // These members define an interception point for a particular event in @@ -192,6 +193,16 @@ struct Operator { void (*early_destroy)(void* promise_data); }; +struct HalfCloseOperator { + // Pointer to corresponding channel data for this filter + void* channel_data; + // Offset of the call data for this filter within the call data memory + size_t call_offset; + void (*half_close)(void* call_data, void* channel_data); +}; + +void RunHalfClose(absl::Span ops, void* call_data); + // We divide operations into fallible and infallible. // Fallible operations can fail, and that failure terminates the call. // Infallible operations cannot fail. @@ -265,6 +276,32 @@ void AddOp(FilterType* channel_data, size_t call_offset, to); } +template +void AddHalfClose(FilterType* channel_data, size_t call_offset, + void (FilterType::Call::*)(), + std::vector& to) { + to.push_back( + HalfCloseOperator{channel_data, call_offset, [](void* call_data, void*) { + static_cast(call_data) + ->OnClientToServerHalfClose(); + }}); +} + +template +void AddHalfClose(FilterType* channel_data, size_t call_offset, + void (FilterType::Call::*)(FilterType*), + std::vector& to) { + to.push_back(HalfCloseOperator{ + channel_data, call_offset, [](void* call_data, void* channel_data) { + static_cast(call_data) + ->OnClientToServerHalfClose(static_cast(channel_data)); + }}); +} + +template +void AddHalfClose(FilterType*, size_t, const NoInterceptor*, + std::vector&) {} + // const NoInterceptor $EVENT // These do nothing, and specifically DO NOT add an operation to the layout. // Supported for fallible & infallible operations. @@ -852,6 +889,7 @@ struct StackData { Layout> client_initial_metadata; Layout> server_initial_metadata; Layout> client_to_server_messages; + std::vector client_to_server_half_close; Layout> server_to_client_messages; Layout> server_trailing_metadata; // A list of finalizers for this call. @@ -972,6 +1010,14 @@ struct StackData { channel_data, call_offset, client_to_server_messages); } + template + void AddClientToServerHalfClose(FilterType* channel_data, + size_t call_offset) { + AddHalfClose(channel_data, call_offset, + &FilterType::Call::OnClientToServerHalfClose, + client_to_server_half_close); + } + template void AddServerToClientMessageOp(FilterType* channel_data, size_t call_offset) { @@ -1217,6 +1263,7 @@ class ServerTrailingMetadataInterceptor { static const NoInterceptor OnClientInitialMetadata; static const NoInterceptor OnServerInitialMetadata; static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnFinalize; void OnServerTrailingMetadata(ServerMetadata& md, @@ -1240,11 +1287,54 @@ template const NoInterceptor ServerTrailingMetadataInterceptor::Call::OnClientToServerMessage; template +const NoInterceptor + ServerTrailingMetadataInterceptor::Call::OnClientToServerHalfClose; +template const NoInterceptor ServerTrailingMetadataInterceptor::Call::OnServerToClientMessage; template const NoInterceptor ServerTrailingMetadataInterceptor::Call::OnFinalize; +template +class ClientInitialMetadataInterceptor { + public: + class Call { + public: + auto OnClientInitialMetadata(ClientMetadata& md, + ClientInitialMetadataInterceptor* filter) { + return filter->fn_(md); + } + static const NoInterceptor OnServerInitialMetadata; + static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; + static const NoInterceptor OnServerToClientMessage; + static const NoInterceptor OnServerTrailingMetadata; + static const NoInterceptor OnFinalize; + }; + + explicit ClientInitialMetadataInterceptor(Fn fn) : fn_(std::move(fn)) {} + + private: + GPR_NO_UNIQUE_ADDRESS Fn fn_; +}; +template +const NoInterceptor + ClientInitialMetadataInterceptor::Call::OnServerInitialMetadata; +template +const NoInterceptor + ClientInitialMetadataInterceptor::Call::OnClientToServerMessage; +template +const NoInterceptor + ClientInitialMetadataInterceptor::Call::OnClientToServerHalfClose; +template +const NoInterceptor + ClientInitialMetadataInterceptor::Call::OnServerToClientMessage; +template +const NoInterceptor + ClientInitialMetadataInterceptor::Call::OnServerTrailingMetadata; +template +const NoInterceptor ClientInitialMetadataInterceptor::Call::OnFinalize; + } // namespace filters_detail // Execution environment for a stack of filters. @@ -1283,6 +1373,7 @@ class CallFilters { data_.AddClientInitialMetadataOp(filter, call_offset); data_.AddServerInitialMetadataOp(filter, call_offset); data_.AddClientToServerMessageOp(filter, call_offset); + data_.AddClientToServerHalfClose(filter, call_offset); data_.AddServerToClientMessageOp(filter, call_offset); data_.AddServerTrailingMetadataOp(filter, call_offset); data_.AddFinalizer(filter, call_offset, &FilterType::Call::OnFinalize); @@ -1302,6 +1393,14 @@ class CallFilters { AddOwnedObject([](void* p) { delete static_cast(p); }, p.release()); } + template + void AddOnClientInitialMetadata(Fn fn) { + auto filter = std::make_unique< + filters_detail::ClientInitialMetadataInterceptor>(std::move(fn)); + Add(filter.get()); + AddOwnedObject(std::move(filter)); + } + template void AddOnServerTrailingMetadata(Fn fn) { auto filter = std::make_unique< @@ -1549,6 +1648,8 @@ class CallFilters { filters_detail::OperationExecutor executor_; }; + template ( + filters_detail::StackData::*half_close_layout_ptr)> class PullMessage { public: explicit PullMessage(CallFilters* filters) : filters_(filters) {} @@ -1593,7 +1694,14 @@ class CallFilters { filters_->CancelDueToFailedPipeOperation(); return Failure{}; } - if (!**r) return absl::nullopt; + if (!**r) { + if (half_close_layout_ptr != nullptr) { + filters_detail::RunHalfClose( + filters_->stack_->data_.*half_close_layout_ptr, + filters_->call_data_); + } + return absl::nullopt; + } CHECK(filters_ != nullptr); return FinishOperationExecutor(executor_.Start( layout(), push()->TakeValue(), filters_->call_data_)); @@ -1821,7 +1929,8 @@ inline auto CallFilters::PushClientToServerMessage(MessageHandle message) { } inline auto CallFilters::PullClientToServerMessage() { - return ClientToServerMessagePromises::PullMessage{this}; + return ClientToServerMessagePromises::PullMessage< + &filters_detail::StackData::client_to_server_half_close>{this}; } inline auto CallFilters::PushServerToClientMessage(MessageHandle message) { @@ -1831,7 +1940,7 @@ inline auto CallFilters::PushServerToClientMessage(MessageHandle message) { } inline auto CallFilters::PullServerToClientMessage() { - return ServerToClientMessagePromises::PullMessage{this}; + return ServerToClientMessagePromises::PullMessage{this}; } inline auto CallFilters::PullServerTrailingMetadata() { diff --git a/src/core/lib/transport/call_spine.h b/src/core/lib/transport/call_spine.h index 8593e47e9c8..59c1fc2da16 100644 --- a/src/core/lib/transport/call_spine.h +++ b/src/core/lib/transport/call_spine.h @@ -518,6 +518,8 @@ class CallHandler { auto PullMessage() { return spine_->PullClientToServerMessage(); } + auto WasCancelled() { return spine_->WasCancelled(); } + template void SpawnGuarded(absl::string_view name, PromiseFactory promise_factory, DebugLocation whence = {}) { @@ -536,11 +538,15 @@ class CallHandler { Arena* arena() { return spine_->arena(); } - grpc_event_engine::experimental::EventEngine* event_engine() { + grpc_event_engine::experimental::EventEngine* event_engine() const { return DownCast(spine_.get())->event_engine(); } // TODO(ctiller): re-evaluate this API + const grpc_call_context_element* legacy_context() const { + return DownCast(spine_.get())->legacy_context(); + } + grpc_call_context_element* legacy_context() { return DownCast(spine_.get())->legacy_context(); } diff --git a/src/core/lib/transport/interception_chain.h b/src/core/lib/transport/interception_chain.h index 5b05e481ff6..e9dcb937b19 100644 --- a/src/core/lib/transport/interception_chain.h +++ b/src/core/lib/transport/interception_chain.h @@ -175,12 +175,23 @@ class InterceptionChainBuilder final { return *this; }; + // Add a filter that just mutates client initial metadata. + template + void AddOnClientInitialMetadata(F f) { + stack_builder().AddOnClientInitialMetadata(std::move(f)); + } + // Add a filter that just mutates server trailing metadata. template void AddOnServerTrailingMetadata(F f) { stack_builder().AddOnServerTrailingMetadata(std::move(f)); } + void Fail(absl::Status status) { + CHECK(!status.ok()) << status; + if (status_.ok()) status_ = std::move(status); + } + // Build this stack absl::StatusOr> Build( FinalDestination final_destination); diff --git a/src/core/lib/transport/transport.h b/src/core/lib/transport/transport.h index 65f57fdd475..5dbe2c6695f 100644 --- a/src/core/lib/transport/transport.h +++ b/src/core/lib/transport/transport.h @@ -55,6 +55,7 @@ #include "src/core/lib/promise/pipe.h" #include "src/core/lib/resource_quota/arena.h" #include "src/core/lib/slice/slice_buffer.h" +#include "src/core/lib/transport/call_destination.h" #include "src/core/lib/transport/call_final_info.h" #include "src/core/lib/transport/call_spine.h" #include "src/core/lib/transport/connectivity_state.h" @@ -481,6 +482,15 @@ typedef struct grpc_transport_op { grpc_handler_private_op_data handler_private; } grpc_transport_op; +// Allocate a grpc_transport_op, and preconfigure the on_complete closure to +// \a on_complete and then delete the returned transport op +grpc_transport_op* grpc_make_transport_op(grpc_closure* on_complete); +// Allocate a grpc_transport_stream_op_batch, and preconfigure the on_complete +// closure +// to \a on_complete and then delete the returned transport op +grpc_transport_stream_op_batch* grpc_make_transport_stream_op( + grpc_closure* on_complete); + void grpc_transport_stream_op_batch_finish_with_failure( grpc_transport_stream_op_batch* batch, grpc_error_handle error, grpc_core::CallCombiner* call_combiner); @@ -507,6 +517,21 @@ class Transport : public InternallyRefCounted { struct RawPointerChannelArgTag {}; static absl::string_view ChannelArgName() { return GRPC_ARG_TRANSPORT; } + // Though internally ref counted transports expose their "Ref" method to + // create a RefCountedPtr to themselves. The OrphanablePtr owner is the + // singleton decision maker on whether the transport should be destroyed or + // not. + // TODO(ctiller): consider moving to a DualRefCounted model (with the + // disadvantage that we would accidentally have many strong owners which is + // unnecessary for this type). + RefCountedPtr Ref() { + return InternallyRefCounted::Ref(); + } + template + RefCountedPtr RefAsSubclass() { + return InternallyRefCounted::RefAsSubclass(); + } + virtual FilterStackTransport* filter_stack_transport() = 0; virtual ClientTransport* client_transport() = 0; virtual ServerTransport* server_transport() = 0; @@ -527,6 +552,20 @@ class Transport : public InternallyRefCounted { // implementation of grpc_transport_perform_op virtual void PerformOp(grpc_transport_op* op) = 0; + void StartConnectivityWatch( + OrphanablePtr watcher) { + grpc_transport_op* op = grpc_make_transport_op(nullptr); + op->start_connectivity_watch = std::move(watcher); + PerformOp(op); + } + + void DisconnectWithError(grpc_error_handle error) { + CHECK(!error.ok()) << error; + grpc_transport_op* op = grpc_make_transport_op(nullptr); + op->disconnect_with_error = error; + PerformOp(op); + } + // implementation of grpc_transport_get_endpoint virtual grpc_endpoint* GetEndpoint() = 0; }; @@ -582,24 +621,9 @@ class ClientTransport : public Transport { class ServerTransport : public Transport { public: - // Acceptor helps transports create calls. - class Acceptor { - public: - // Returns an arena that can be used to allocate memory for initial metadata - // parsing, and later passed to CreateCall() as the underlying arena for - // that call. - virtual Arena* CreateArena() = 0; - // Create a call at the server (or fail) - // arena must have been previously allocated by CreateArena() - virtual absl::StatusOr CreateCall( - ClientMetadataHandle client_initial_metadata, Arena* arena) = 0; - - protected: - ~Acceptor() = default; - }; - // Called once slightly after transport setup to register the accept function. - virtual void SetAcceptor(Acceptor* acceptor) = 0; + virtual void SetCallDestination( + RefCountedPtr unstarted_call_handler) = 0; protected: ~ServerTransport() override = default; @@ -607,15 +631,6 @@ class ServerTransport : public Transport { } // namespace grpc_core -// Allocate a grpc_transport_op, and preconfigure the on_complete closure to -// \a on_complete and then delete the returned transport op -grpc_transport_op* grpc_make_transport_op(grpc_closure* on_complete); -// Allocate a grpc_transport_stream_op_batch, and preconfigure the on_complete -// closure -// to \a on_complete and then delete the returned transport op -grpc_transport_stream_op_batch* grpc_make_transport_stream_op( - grpc_closure* on_complete); - namespace grpc_core { // This is the key to be used for loading/storing keepalive_throttling in the // absl::Status object. diff --git a/src/core/load_balancing/grpclb/client_load_reporting_filter.cc b/src/core/load_balancing/grpclb/client_load_reporting_filter.cc index c3de43e4b94..e03fe8d70ce 100644 --- a/src/core/load_balancing/grpclb/client_load_reporting_filter.cc +++ b/src/core/load_balancing/grpclb/client_load_reporting_filter.cc @@ -41,6 +41,7 @@ namespace grpc_core { const NoInterceptor ClientLoadReportingFilter::Call::OnServerToClientMessage; const NoInterceptor ClientLoadReportingFilter::Call::OnClientToServerMessage; +const NoInterceptor ClientLoadReportingFilter::Call::OnClientToServerHalfClose; const NoInterceptor ClientLoadReportingFilter::Call::OnFinalize; const grpc_channel_filter ClientLoadReportingFilter::kFilter = diff --git a/src/core/load_balancing/grpclb/client_load_reporting_filter.h b/src/core/load_balancing/grpclb/client_load_reporting_filter.h index 941b97abf99..f8c5b7fbcc4 100644 --- a/src/core/load_balancing/grpclb/client_load_reporting_filter.h +++ b/src/core/load_balancing/grpclb/client_load_reporting_filter.h @@ -43,6 +43,7 @@ class ClientLoadReportingFilter final void OnServerTrailingMetadata(ServerMetadata& server_trailing_metadata); static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnFinalize; private: diff --git a/src/core/load_balancing/grpclb/grpclb.cc b/src/core/load_balancing/grpclb/grpclb.cc index d14b50af44f..fcc3034bf03 100644 --- a/src/core/load_balancing/grpclb/grpclb.cc +++ b/src/core/load_balancing/grpclb/grpclb.cc @@ -101,8 +101,6 @@ #include "src/core/lib/config/core_configuration.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/experiments/experiments.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/orphanable.h" @@ -143,6 +141,8 @@ #include "src/core/resolver/endpoint_addresses.h" #include "src/core/resolver/fake/fake_resolver.h" #include "src/core/resolver/resolver.h" +#include "src/core/util/string.h" +#include "src/core/util/useful.h" #define GRPC_GRPCLB_INITIAL_CONNECT_BACKOFF_SECONDS 1 #define GRPC_GRPCLB_RECONNECT_BACKOFF_MULTIPLIER 1.6 diff --git a/src/core/load_balancing/grpclb/grpclb_balancer_addresses.cc b/src/core/load_balancing/grpclb/grpclb_balancer_addresses.cc index 17f817eb7a1..a0552c57c70 100644 --- a/src/core/load_balancing/grpclb/grpclb_balancer_addresses.cc +++ b/src/core/load_balancing/grpclb/grpclb_balancer_addresses.cc @@ -23,7 +23,7 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" // Channel arg key for the list of balancer addresses. #define GRPC_ARG_GRPCLB_BALANCER_ADDRESSES \ diff --git a/src/core/load_balancing/pick_first/pick_first.cc b/src/core/load_balancing/pick_first/pick_first.cc index afcd49d547d..ae5cb82489b 100644 --- a/src/core/load_balancing/pick_first/pick_first.cc +++ b/src/core/load_balancing/pick_first/pick_first.cc @@ -47,7 +47,6 @@ #include "src/core/lib/config/core_configuration.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/experiments/experiments.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/orphanable.h" @@ -66,6 +65,7 @@ #include "src/core/load_balancing/lb_policy_factory.h" #include "src/core/load_balancing/subchannel_interface.h" #include "src/core/resolver/endpoint_addresses.h" +#include "src/core/util/useful.h" namespace grpc_core { @@ -84,19 +84,25 @@ const auto kMetricDisconnections = "grpc.lb.pick_first.disconnections", "EXPERIMENTAL. Number of times the selected subchannel becomes " "disconnected.", - "{disconnection}", {kMetricLabelTarget}, {}, false); + "{disconnection}", false) + .Labels(kMetricLabelTarget) + .Build(); const auto kMetricConnectionAttemptsSucceeded = GlobalInstrumentsRegistry::RegisterUInt64Counter( "grpc.lb.pick_first.connection_attempts_succeeded", "EXPERIMENTAL. Number of successful connection attempts.", "{attempt}", - {kMetricLabelTarget}, {}, false); + false) + .Labels(kMetricLabelTarget) + .Build(); const auto kMetricConnectionAttemptsFailed = GlobalInstrumentsRegistry::RegisterUInt64Counter( "grpc.lb.pick_first.connection_attempts_failed", "EXPERIMENTAL. Number of failed connection attempts.", "{attempt}", - {kMetricLabelTarget}, {}, false); + false) + .Labels(kMetricLabelTarget) + .Build(); class PickFirstConfig final : public LoadBalancingPolicy::Config { public: diff --git a/src/core/load_balancing/rls/rls.cc b/src/core/load_balancing/rls/rls.cc index 3e9f08a5b9c..53480d6f091 100644 --- a/src/core/load_balancing/rls/rls.cc +++ b/src/core/load_balancing/rls/rls.cc @@ -128,26 +128,27 @@ constexpr absl::string_view kMetricLabelPickResult = "grpc.lb.pick_result"; const auto kMetricCacheSize = GlobalInstrumentsRegistry::RegisterCallbackInt64Gauge( "grpc.lb.rls.cache_size", "EXPERIMENTAL. Size of the RLS cache.", "By", - {kMetricLabelTarget, kMetricLabelRlsServerTarget, - kMetricLabelRlsInstanceUuid}, - {}, false); + false) + .Labels(kMetricLabelTarget, kMetricLabelRlsServerTarget, + kMetricLabelRlsInstanceUuid) + .Build(); const auto kMetricCacheEntries = GlobalInstrumentsRegistry::RegisterCallbackInt64Gauge( "grpc.lb.rls.cache_entries", - "EXPERIMENTAL. Number of entries in the RLS cache.", "{entry}", - {kMetricLabelTarget, kMetricLabelRlsServerTarget, - kMetricLabelRlsInstanceUuid}, - {}, false); + "EXPERIMENTAL. Number of entries in the RLS cache.", "{entry}", false) + .Labels(kMetricLabelTarget, kMetricLabelRlsServerTarget, + kMetricLabelRlsInstanceUuid) + .Build(); const auto kMetricDefaultTargetPicks = GlobalInstrumentsRegistry::RegisterUInt64Counter( "grpc.lb.rls.default_target_picks", "EXPERIMENTAL. Number of LB picks sent to the default target.", - "{pick}", - {kMetricLabelTarget, kMetricLabelRlsServerTarget, - kMetricRlsDataPlaneTarget, kMetricLabelPickResult}, - {}, false); + "{pick}", false) + .Labels(kMetricLabelTarget, kMetricLabelRlsServerTarget, + kMetricRlsDataPlaneTarget, kMetricLabelPickResult) + .Build(); const auto kMetricTargetPicks = GlobalInstrumentsRegistry::RegisterUInt64Counter( @@ -156,17 +157,19 @@ const auto kMetricTargetPicks = "if the default target is also returned by the RLS server, RPCs sent " "to that target from the cache will be counted in this metric, not " "in grpc.rls.default_target_picks.", - "{pick}", - {kMetricLabelTarget, kMetricLabelRlsServerTarget, - kMetricRlsDataPlaneTarget, kMetricLabelPickResult}, - {}, false); + "{pick}", false) + .Labels(kMetricLabelTarget, kMetricLabelRlsServerTarget, + kMetricRlsDataPlaneTarget, kMetricLabelPickResult) + .Build(); const auto kMetricFailedPicks = GlobalInstrumentsRegistry::RegisterUInt64Counter( "grpc.lb.rls.failed_picks", "EXPERIMENTAL. Number of LB picks failed due to either a failed RLS " "request or the RLS channel being throttled.", - "{pick}", {kMetricLabelTarget, kMetricLabelRlsServerTarget}, {}, false); + "{pick}", false) + .Labels(kMetricLabelTarget, kMetricLabelRlsServerTarget) + .Build(); constexpr absl::string_view kRls = "rls_experimental"; const char kGrpc[] = "grpc"; @@ -754,9 +757,9 @@ class RlsLb final : public LoadBalancingPolicy { // Updates the picker in the work serializer. void UpdatePickerLocked() ABSL_LOCKS_EXCLUDED(&mu_); - void MaybeExportPickCount( - GlobalInstrumentsRegistry::GlobalUInt64CounterHandle handle, - absl::string_view target, const PickResult& pick_result); + template + void MaybeExportPickCount(HandleType handle, absl::string_view target, + const PickResult& pick_result); const std::string instance_uuid_; @@ -1961,7 +1964,7 @@ RlsLb::RlsLb(Args args) MutexLock lock(&mu_); cache_.ReportMetricsLocked(reporter); }, - {kMetricCacheSize, kMetricCacheEntries})) { + Duration::Seconds(5), kMetricCacheSize, kMetricCacheEntries)) { if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_rls_trace)) { gpr_log(GPR_INFO, "[rlslb %p] policy created", this); } @@ -2230,9 +2233,9 @@ void RlsLb::UpdatePickerLocked() { MakeRefCounted(RefAsSubclass(DEBUG_LOCATION, "Picker"))); } -void RlsLb::MaybeExportPickCount( - GlobalInstrumentsRegistry::GlobalUInt64CounterHandle handle, - absl::string_view target, const PickResult& pick_result) { +template +void RlsLb::MaybeExportPickCount(HandleType handle, absl::string_view target, + const PickResult& pick_result) { absl::string_view pick_result_string = Match( pick_result.result, [](const LoadBalancingPolicy::PickResult::Complete&) { diff --git a/src/core/load_balancing/weighted_round_robin/weighted_round_robin.cc b/src/core/load_balancing/weighted_round_robin/weighted_round_robin.cc index bf174c55a56..d0a4165f393 100644 --- a/src/core/load_balancing/weighted_round_robin/weighted_round_robin.cc +++ b/src/core/load_balancing/weighted_round_robin/weighted_round_robin.cc @@ -85,12 +85,16 @@ constexpr absl::string_view kWeightedRoundRobin = "weighted_round_robin"; constexpr absl::string_view kMetricLabelLocality = "grpc.lb.locality"; -const auto kMetricRrFallback = GlobalInstrumentsRegistry::RegisterUInt64Counter( - "grpc.lb.wrr.rr_fallback", - "EXPERIMENTAL. Number of scheduler updates in which there were not " - "enough endpoints with valid weight, which caused the WRR policy to " - "fall back to RR behavior.", - "{update}", {kMetricLabelTarget}, {kMetricLabelLocality}, false); +const auto kMetricRrFallback = + GlobalInstrumentsRegistry::RegisterUInt64Counter( + "grpc.lb.wrr.rr_fallback", + "EXPERIMENTAL. Number of scheduler updates in which there were not " + "enough endpoints with valid weight, which caused the WRR policy to " + "fall back to RR behavior.", + "{update}", false) + .Labels(kMetricLabelTarget) + .OptionalLabels(kMetricLabelLocality) + .Build(); const auto kMetricEndpointWeightNotYetUsable = GlobalInstrumentsRegistry::RegisterUInt64Counter( @@ -99,14 +103,20 @@ const auto kMetricEndpointWeightNotYetUsable = "don't yet have usable weight information (i.e., either the load " "report has not yet been received, or it is within the blackout " "period).", - "{endpoint}", {kMetricLabelTarget}, {kMetricLabelLocality}, false); + "{endpoint}", false) + .Labels(kMetricLabelTarget) + .OptionalLabels(kMetricLabelLocality) + .Build(); const auto kMetricEndpointWeightStale = GlobalInstrumentsRegistry::RegisterUInt64Counter( "grpc.lb.wrr.endpoint_weight_stale", "EXPERIMENTAL. Number of endpoints from each scheduler update whose " "latest weight is older than the expiration period.", - "{endpoint}", {kMetricLabelTarget}, {kMetricLabelLocality}, false); + "{endpoint}", false) + .Labels(kMetricLabelTarget) + .OptionalLabels(kMetricLabelLocality) + .Build(); const auto kMetricEndpointWeights = GlobalInstrumentsRegistry::RegisterDoubleHistogram( @@ -115,7 +125,10 @@ const auto kMetricEndpointWeights = "Each bucket will be a counter that is incremented once for every " "endpoint whose weight is within that range. Note that endpoints " "without usable weights will have weight 0.", - "{weight}", {kMetricLabelTarget}, {kMetricLabelLocality}, false); + "{weight}", false) + .Labels(kMetricLabelTarget) + .OptionalLabels(kMetricLabelLocality) + .Build(); // Config for WRR policy. class WeightedRoundRobinConfig final : public LoadBalancingPolicy::Config { 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/plugin_registry/grpc_plugin_registry.cc b/src/core/plugin_registry/grpc_plugin_registry.cc index c0205fa8497..80b4010593e 100644 --- a/src/core/plugin_registry/grpc_plugin_registry.cc +++ b/src/core/plugin_registry/grpc_plugin_registry.cc @@ -79,10 +79,11 @@ namespace { void RegisterBuiltins(CoreConfiguration::Builder* builder) { RegisterServerCallTracerFilter(builder); builder->channel_init() - ->RegisterFilter(GRPC_CLIENT_LAME_CHANNEL) + ->RegisterV2Filter(GRPC_CLIENT_LAME_CHANNEL) .Terminal(); builder->channel_init() ->RegisterFilter(GRPC_SERVER_CHANNEL, &Server::kServerTopFilter) + .SkipV3() .BeforeAll(); } diff --git a/src/core/resolver/binder/binder_resolver.cc b/src/core/resolver/binder/binder_resolver.cc index 903a5528470..7cd03f29193 100644 --- a/src/core/resolver/binder/binder_resolver.cc +++ b/src/core/resolver/binder/binder_resolver.cc @@ -37,6 +37,7 @@ #include #include +#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -126,12 +127,12 @@ class BinderResolverFactory final : public ResolverFactory { grpc_resolved_address addr; { if (!uri.authority().empty()) { - gpr_log(GPR_ERROR, "authority is not supported in binder scheme"); + LOG(ERROR) << "authority is not supported in binder scheme"; return false; } grpc_error_handle error = BinderAddrPopulate(uri.path(), &addr); if (!error.ok()) { - gpr_log(GPR_ERROR, "%s", StatusToString(error).c_str()); + LOG(ERROR) << StatusToString(error); return false; } } diff --git a/src/core/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/resolver/dns/c_ares/dns_resolver_ares.cc index 4fa22539ba1..06b9985c948 100644 --- a/src/core/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/resolver/dns/c_ares/dns_resolver_ares.cc @@ -24,6 +24,7 @@ #include #include "absl/base/thread_annotations.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/match.h" @@ -348,7 +349,7 @@ class AresClientChannelDNSResolverFactory final : public ResolverFactory { bool IsValidUri(const URI& uri) const override { if (absl::StripPrefix(uri.path(), "/").empty()) { - gpr_log(GPR_ERROR, "no server name supplied in dns URI"); + LOG(ERROR) << "no server name supplied in dns URI"; return false; } return true; diff --git a/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc b/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc index 55d2711d909..ef70bfc5b67 100644 --- a/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +++ b/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc @@ -39,7 +39,6 @@ #include #include "src/core/lib/address_utils/sockaddr_utils.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/memory.h" #include "src/core/lib/iomgr/iocp_windows.h" @@ -50,6 +49,7 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h" #include "src/core/resolver/dns/c_ares/grpc_ares_wrapper.h" +#include "src/core/util/string.h" // TODO(apolcyn): remove this hack after fixing upstream. // Our grpc/c-ares code on Windows uses the ares_set_socket_functions API, diff --git a/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc b/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc index 74ebe6d4054..7994a1900a5 100644 --- a/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc +++ b/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/string_view.h" #include @@ -60,7 +61,6 @@ #include "src/core/lib/address_utils/parse_address.h" #include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/time.h" @@ -71,6 +71,7 @@ #include "src/core/lib/iomgr/timer.h" #include "src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h" #include "src/core/resolver/dns/c_ares/grpc_ares_wrapper.h" +#include "src/core/util/string.h" using grpc_core::EndpointAddresses; using grpc_core::EndpointAddressesList; @@ -952,7 +953,7 @@ static bool resolve_as_ip_literal_locked( static bool target_matches_localhost_inner(const char* name, std::string* host, std::string* port) { if (!grpc_core::SplitHostPort(name, host, port)) { - gpr_log(GPR_ERROR, "Unable to split host and port for name: %s", name); + LOG(ERROR) << "Unable to split host and port for name: " << name; return false; } return gpr_stricmp(host->c_str(), "localhost") == 0; diff --git a/src/core/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc b/src/core/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc index 9b87b56c1f1..22b56fdd42c 100644 --- a/src/core/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +++ b/src/core/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc @@ -25,10 +25,10 @@ #include #include "src/core/lib/address_utils/parse_address.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/iomgr/socket_windows.h" #include "src/core/resolver/dns/c_ares/grpc_ares_wrapper.h" #include "src/core/resolver/endpoint_addresses.h" +#include "src/core/util/string.h" bool grpc_ares_query_ipv6() { return grpc_ipv6_loopback_available(); } diff --git a/src/core/resolver/dns/dns_resolver_plugin.cc b/src/core/resolver/dns/dns_resolver_plugin.cc index a0f92a6c600..122c3fd740e 100644 --- a/src/core/resolver/dns/dns_resolver_plugin.cc +++ b/src/core/resolver/dns/dns_resolver_plugin.cc @@ -15,6 +15,7 @@ #include +#include "absl/log/log.h" #include "absl/strings/match.h" #include @@ -32,14 +33,14 @@ namespace grpc_core { void RegisterDnsResolver(CoreConfiguration::Builder* builder) { #ifdef GRPC_IOS_EVENT_ENGINE_CLIENT - gpr_log(GPR_DEBUG, "Using EventEngine dns resolver"); + VLOG(2) << "Using EventEngine dns resolver"; builder->resolver_registry()->RegisterResolverFactory( std::make_unique()); return; #endif #ifndef GRPC_DO_NOT_INSTANTIATE_POSIX_POLLER if (IsEventEngineDnsEnabled()) { - gpr_log(GPR_DEBUG, "Using EventEngine dns resolver"); + VLOG(2) << "Using EventEngine dns resolver"; builder->resolver_registry()->RegisterResolverFactory( std::make_unique()); return; @@ -48,14 +49,14 @@ void RegisterDnsResolver(CoreConfiguration::Builder* builder) { auto resolver = ConfigVars::Get().DnsResolver(); // ---- Ares resolver ---- if (ShouldUseAresDnsResolver(resolver)) { - gpr_log(GPR_DEBUG, "Using ares dns resolver"); + VLOG(2) << "Using ares dns resolver"; RegisterAresDnsResolver(builder); return; } // ---- Native resolver ---- if (absl::EqualsIgnoreCase(resolver, "native") || !builder->resolver_registry()->HasResolverFactory("dns")) { - gpr_log(GPR_DEBUG, "Using native dns resolver"); + VLOG(2) << "Using native dns resolver"; RegisterNativeDnsResolver(builder); return; } diff --git a/src/core/resolver/dns/event_engine/event_engine_client_channel_resolver.cc b/src/core/resolver/dns/event_engine/event_engine_client_channel_resolver.cc index 8a9d1a49db9..743422ab603 100644 --- a/src/core/resolver/dns/event_engine/event_engine_client_channel_resolver.cc +++ b/src/core/resolver/dns/event_engine/event_engine_client_channel_resolver.cc @@ -26,6 +26,7 @@ #include "absl/base/thread_annotations.h" #include "absl/cleanup/cleanup.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/match.h" @@ -567,7 +568,7 @@ absl::optional EventEngineClientChannelDNSResolver:: bool EventEngineClientChannelDNSResolverFactory::IsValidUri( const URI& uri) const { if (absl::StripPrefix(uri.path(), "/").empty()) { - gpr_log(GPR_ERROR, "no server name supplied in dns URI"); + LOG(ERROR) << "no server name supplied in dns URI"; return false; } return true; diff --git a/src/core/resolver/dns/native/dns_resolver.cc b/src/core/resolver/dns/native/dns_resolver.cc index 43dddc719a4..8ecb92d4857 100644 --- a/src/core/resolver/dns/native/dns_resolver.cc +++ b/src/core/resolver/dns/native/dns_resolver.cc @@ -20,6 +20,7 @@ #include #include "absl/functional/bind_front.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" @@ -150,11 +151,11 @@ class NativeClientChannelDNSResolverFactory final : public ResolverFactory { bool IsValidUri(const URI& uri) const override { if (GPR_UNLIKELY(!uri.authority().empty())) { - gpr_log(GPR_ERROR, "authority based dns uri's not supported"); + LOG(ERROR) << "authority based dns uri's not supported"; return false; } if (absl::StripPrefix(uri.path(), "/").empty()) { - gpr_log(GPR_ERROR, "no server name supplied in dns URI"); + LOG(ERROR) << "no server name supplied in dns URI"; return false; } return true; diff --git a/src/core/resolver/endpoint_addresses.cc b/src/core/resolver/endpoint_addresses.cc index 9746123bd3c..19fbfdfbc16 100644 --- a/src/core/resolver/endpoint_addresses.cc +++ b/src/core/resolver/endpoint_addresses.cc @@ -35,7 +35,7 @@ #include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" // IWYU pragma: no_include diff --git a/src/core/resolver/fake/fake_resolver.cc b/src/core/resolver/fake/fake_resolver.cc index a5d1b53a929..99703f8a6ea 100644 --- a/src/core/resolver/fake/fake_resolver.cc +++ b/src/core/resolver/fake/fake_resolver.cc @@ -31,12 +31,12 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/config/core_configuration.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/work_serializer.h" #include "src/core/lib/uri/uri_parser.h" #include "src/core/resolver/resolver_factory.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/resolver/fake/fake_resolver.h b/src/core/resolver/fake/fake_resolver.h index c164c04ab38..75dc3ab0ca4 100644 --- a/src/core/resolver/fake/fake_resolver.h +++ b/src/core/resolver/fake/fake_resolver.h @@ -27,12 +27,12 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/notification.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" #include "src/core/resolver/resolver.h" +#include "src/core/util/useful.h" #define GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR \ "grpc.fake_resolver.response_generator" diff --git a/src/core/resolver/google_c2p/google_c2p_resolver.cc b/src/core/resolver/google_c2p/google_c2p_resolver.cc index 0fb3744a3e8..d58e9a81b3e 100644 --- a/src/core/resolver/google_c2p/google_c2p_resolver.cc +++ b/src/core/resolver/google_c2p/google_c2p_resolver.cc @@ -22,6 +22,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -282,7 +283,7 @@ class GoogleCloud2ProdResolverFactory final : public ResolverFactory { bool IsValidUri(const URI& uri) const override { if (GPR_UNLIKELY(!uri.authority().empty())) { - gpr_log(GPR_ERROR, "google-c2p URI scheme does not support authorities"); + LOG(ERROR) << "google-c2p URI scheme does not support authorities"; return false; } return true; diff --git a/src/core/resolver/xds/xds_resolver.cc b/src/core/resolver/xds/xds_resolver.cc index 1b062981a2d..6e51ab1d856 100644 --- a/src/core/resolver/xds/xds_resolver.cc +++ b/src/core/resolver/xds/xds_resolver.cc @@ -330,6 +330,7 @@ class XdsResolver final : public Resolver { static const NoInterceptor OnServerInitialMetadata; static const NoInterceptor OnServerTrailingMetadata; static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnFinalize; }; @@ -383,6 +384,8 @@ const NoInterceptor XdsResolver::ClusterSelectionFilter::Call::OnServerTrailingMetadata; const NoInterceptor XdsResolver::ClusterSelectionFilter::Call::OnClientToServerMessage; +const NoInterceptor + XdsResolver::ClusterSelectionFilter::Call::OnClientToServerHalfClose; const NoInterceptor XdsResolver::ClusterSelectionFilter::Call::OnServerToClientMessage; const NoInterceptor XdsResolver::ClusterSelectionFilter::Call::OnFinalize; diff --git a/src/core/server/server.cc b/src/core/server/server.cc index 04d0f52da3e..b891001f3d4 100644 --- a/src/core/server/server.cc +++ b/src/core/server/server.cc @@ -33,6 +33,7 @@ #include "absl/cleanup/cleanup.h" #include "absl/container/flat_hash_map.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/types/optional.h" @@ -53,10 +54,10 @@ #include "src/core/lib/config/core_configuration.h" #include "src/core/lib/debug/stats.h" #include "src/core/lib/experiments/experiments.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/mpscq.h" +#include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/status_helper.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/pollset_set.h" @@ -81,6 +82,8 @@ #include "src/core/lib/surface/wait_for_cq_end_op.h" #include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/error_utils.h" +#include "src/core/lib/transport/interception_chain.h" +#include "src/core/util/useful.h" namespace grpc_core { @@ -235,7 +238,8 @@ struct Server::RequestedCall { template void Complete(OptionalPayload payload, ClientMetadata& md) { - Timestamp deadline = GetContext()->deadline(); + Timestamp deadline = + md.get(GrpcTimeoutMetadata()).value_or(Timestamp::InfFuture()); switch (type) { case RequestedCall::Type::BATCH_CALL: CHECK(!payload.has_value()); @@ -288,23 +292,29 @@ struct Server::RequestedCall { // application to explicitly request RPCs and then matching those to incoming // RPCs, along with a slow path by which incoming RPCs are put on a locked // pending list if they aren't able to be matched to an application request. -class Server::RealRequestMatcherFilterStack : public RequestMatcherInterface { +class Server::RealRequestMatcher : public RequestMatcherInterface { public: - explicit RealRequestMatcherFilterStack(Server* server) + explicit RealRequestMatcher(Server* server) : server_(server), requests_per_cq_(server->cqs_.size()) {} - ~RealRequestMatcherFilterStack() override { + ~RealRequestMatcher() override { for (LockedMultiProducerSingleConsumerQueue& queue : requests_per_cq_) { CHECK_EQ(queue.Pop(), nullptr); } - CHECK(pending_.empty()); + CHECK(pending_filter_stack_.empty()); + CHECK(pending_promises_.empty()); } void ZombifyPending() override { - while (!pending_.empty()) { - pending_.front().calld->SetState(CallData::CallState::ZOMBIED); - pending_.front().calld->KillZombie(); - pending_.pop(); + while (!pending_filter_stack_.empty()) { + pending_filter_stack_.front().calld->SetState( + CallData::CallState::ZOMBIED); + pending_filter_stack_.front().calld->KillZombie(); + pending_filter_stack_.pop(); + } + while (!pending_promises_.empty()) { + pending_promises_.front()->Finish(absl::InternalError("Server closed")); + pending_promises_.pop(); } } @@ -329,35 +339,56 @@ class Server::RealRequestMatcherFilterStack : public RequestMatcherInterface { // matching calls struct NextPendingCall { RequestedCall* rc = nullptr; - CallData* pending; + CallData* pending_filter_stack = nullptr; + PendingCallPromises pending_promise; }; while (true) { NextPendingCall pending_call; { MutexLock lock(&server_->mu_call_); - while (!pending_.empty() && - pending_.front().Age() > server_->max_time_in_pending_queue_) { - pending_.front().calld->SetState(CallData::CallState::ZOMBIED); - pending_.front().calld->KillZombie(); - pending_.pop(); + while (!pending_filter_stack_.empty() && + pending_filter_stack_.front().Age() > + server_->max_time_in_pending_queue_) { + pending_filter_stack_.front().calld->SetState( + CallData::CallState::ZOMBIED); + pending_filter_stack_.front().calld->KillZombie(); + pending_filter_stack_.pop(); } - if (!pending_.empty()) { + if (!pending_promises_.empty()) { pending_call.rc = reinterpret_cast( requests_per_cq_[request_queue_index].Pop()); if (pending_call.rc != nullptr) { - pending_call.pending = pending_.front().calld; - pending_.pop(); + pending_call.pending_promise = + std::move(pending_promises_.front()); + pending_promises_.pop(); + } + } else if (!pending_filter_stack_.empty()) { + pending_call.rc = reinterpret_cast( + requests_per_cq_[request_queue_index].Pop()); + if (pending_call.rc != nullptr) { + pending_call.pending_filter_stack = + pending_filter_stack_.front().calld; + pending_filter_stack_.pop(); } } } if (pending_call.rc == nullptr) break; - if (!pending_call.pending->MaybeActivate()) { - // Zombied Call - pending_call.pending->KillZombie(); - requests_per_cq_[request_queue_index].Push( - &pending_call.rc->mpscq_node); + if (pending_call.pending_filter_stack != nullptr) { + if (!pending_call.pending_filter_stack->MaybeActivate()) { + // Zombied Call + pending_call.pending_filter_stack->KillZombie(); + requests_per_cq_[request_queue_index].Push( + &pending_call.rc->mpscq_node); + } else { + pending_call.pending_filter_stack->Publish(request_queue_index, + pending_call.rc); + } } else { - pending_call.pending->Publish(request_queue_index, pending_call.rc); + if (!pending_call.pending_promise->Finish( + server(), request_queue_index, pending_call.rc)) { + requests_per_cq_[request_queue_index].Push( + &pending_call.rc->mpscq_node); + } } } } @@ -395,7 +426,7 @@ class Server::RealRequestMatcherFilterStack : public RequestMatcherInterface { } if (rc == nullptr) { calld->SetState(CallData::CallState::PENDING); - pending_.push(PendingCall{calld}); + pending_filter_stack_.push(PendingCallFilterStack{calld}); return; } } @@ -403,91 +434,6 @@ class Server::RealRequestMatcherFilterStack : public RequestMatcherInterface { calld->Publish(cq_idx, rc); } - ArenaPromise> MatchRequest(size_t) override { - Crash("not implemented for filter stack request matcher"); - } - - Server* server() const final { return server_; } - - private: - Server* const server_; - struct PendingCall { - CallData* calld; - Timestamp created = Timestamp::Now(); - Duration Age() { return Timestamp::Now() - created; } - }; - std::queue pending_; - std::vector requests_per_cq_; -}; - -class Server::RealRequestMatcherPromises : public RequestMatcherInterface { - public: - explicit RealRequestMatcherPromises(Server* server) - : server_(server), requests_per_cq_(server->cqs_.size()) {} - - ~RealRequestMatcherPromises() override { - for (LockedMultiProducerSingleConsumerQueue& queue : requests_per_cq_) { - CHECK_EQ(queue.Pop(), nullptr); - } - } - - void ZombifyPending() override { - while (!pending_.empty()) { - pending_.front()->Finish(absl::InternalError("Server closed")); - pending_.pop(); - } - } - - void KillRequests(grpc_error_handle error) override { - for (size_t i = 0; i < requests_per_cq_.size(); i++) { - RequestedCall* rc; - while ((rc = reinterpret_cast( - requests_per_cq_[i].Pop())) != nullptr) { - server_->FailCall(i, rc, error); - } - } - } - - size_t request_queue_count() const override { - return requests_per_cq_.size(); - } - - void RequestCallWithPossiblePublish(size_t request_queue_index, - RequestedCall* call) override { - if (requests_per_cq_[request_queue_index].Push(&call->mpscq_node)) { - // this was the first queued request: we need to lock and start - // matching calls - struct NextPendingCall { - RequestedCall* rc = nullptr; - PendingCall pending; - }; - while (true) { - NextPendingCall pending_call; - { - MutexLock lock(&server_->mu_call_); - if (!pending_.empty()) { - pending_call.rc = reinterpret_cast( - requests_per_cq_[request_queue_index].Pop()); - if (pending_call.rc != nullptr) { - pending_call.pending = std::move(pending_.front()); - pending_.pop(); - } - } - } - if (pending_call.rc == nullptr) break; - if (!pending_call.pending->Finish(server(), request_queue_index, - pending_call.rc)) { - requests_per_cq_[request_queue_index].Push( - &pending_call.rc->mpscq_node); - } - } - } - } - - void MatchOrQueue(size_t, CallData*) override { - Crash("not implemented for promises"); - } - ArenaPromise> MatchRequest( size_t start_request_queue_index) override { for (size_t i = 0; i < requests_per_cq_.size(); i++) { @@ -509,10 +455,11 @@ class Server::RealRequestMatcherPromises : public RequestMatcherInterface { { std::vector> removed_pending; MutexLock lock(&server_->mu_call_); - while (!pending_.empty() && - pending_.front()->Age() > server_->max_time_in_pending_queue_) { - removed_pending.push_back(std::move(pending_.front())); - pending_.pop(); + while (!pending_promises_.empty() && + pending_promises_.front()->Age() > + server_->max_time_in_pending_queue_) { + removed_pending.push_back(std::move(pending_promises_.front())); + pending_promises_.pop(); } for (loop_count = 0; loop_count < requests_per_cq_.size(); loop_count++) { cq_idx = @@ -521,14 +468,14 @@ class Server::RealRequestMatcherPromises : public RequestMatcherInterface { if (rc != nullptr) break; } if (rc == nullptr) { - if (server_->pending_backlog_protector_.Reject(pending_.size(), + if (server_->pending_backlog_protector_.Reject(pending_promises_.size(), server_->bitgen_)) { return Immediate(absl::ResourceExhaustedError( "Too many pending requests for this server")); } auto w = std::make_shared( GetContext()->MakeOwningWaker()); - pending_.push(w); + pending_promises_.push(w); return OnCancel( [w]() -> Poll> { std::unique_ptr> r( @@ -546,6 +493,11 @@ class Server::RealRequestMatcherPromises : public RequestMatcherInterface { private: Server* const server_; + struct PendingCallFilterStack { + CallData* calld; + Timestamp created = Timestamp::Now(); + Duration Age() { return Timestamp::Now() - created; } + }; struct ActivityWaiter { using ResultType = absl::StatusOr; explicit ActivityWaiter(Waker waker) : waker(std::move(waker)) {} @@ -580,8 +532,9 @@ class Server::RealRequestMatcherPromises : public RequestMatcherInterface { std::atomic result{nullptr}; const Timestamp created = Timestamp::Now(); }; - using PendingCall = std::shared_ptr; - std::queue pending_; + using PendingCallPromises = std::shared_ptr; + std::queue pending_filter_stack_; + std::queue pending_promises_; std::vector requests_per_cq_; }; @@ -784,13 +737,40 @@ class ChannelBroadcaster { } // namespace +// +// Server::TransportConnectivityWatcher +// + +class Server::TransportConnectivityWatcher + : public AsyncConnectivityStateWatcherInterface { + public: + TransportConnectivityWatcher(RefCountedPtr transport, + RefCountedPtr server) + : transport_(std::move(transport)), server_(std::move(server)) {} + + private: + void OnConnectivityStateChange(grpc_connectivity_state new_state, + const absl::Status& /*status*/) override { + // Don't do anything until we are being shut down. + if (new_state != GRPC_CHANNEL_SHUTDOWN) return; + // Shut down channel. + MutexLock lock(&server_->mu_global_); + server_->connections_.erase(transport_.get()); + --server_->connections_open_; + server_->MaybeFinishShutdown(); + } + + RefCountedPtr transport_; + RefCountedPtr server_; +}; + // // Server // const grpc_channel_filter Server::kServerTopFilter = { Server::CallData::StartTransportStreamOpBatch, - Server::ChannelData::MakeCallPromise, + nullptr, [](grpc_channel_element*, CallSpineInterface*) { // TODO(ctiller): remove the server filter when call-v3 is finalized }, @@ -826,12 +806,91 @@ RefCountedPtr CreateChannelzNode( return channelz_node; } +absl::StatusOr CheckClientMetadata( + ValueOrFailure md) { + if (!md.ok()) { + return absl::InternalError("Missing metadata"); + } + if (!md.value()->get_pointer(HttpPathMetadata())) { + return absl::InternalError("Missing :path header"); + } + if (!md.value()->get_pointer(HttpAuthorityMetadata())) { + return absl::InternalError("Missing :authority header"); + } + return std::move(*md); +} } // namespace +auto Server::MatchAndPublishCall(CallHandler call_handler) { + call_handler.SpawnGuarded("request_matcher", [this, call_handler]() mutable { + return TrySeq( + // Wait for initial metadata to pass through all filters + Map(call_handler.PullClientInitialMetadata(), CheckClientMetadata), + // Match request with requested call + [this, call_handler](ClientMetadataHandle md) mutable { + auto* registered_method = static_cast( + md->get(GrpcRegisteredMethod()).value_or(nullptr)); + RequestMatcherInterface* rm; + grpc_server_register_method_payload_handling payload_handling = + GRPC_SRM_PAYLOAD_NONE; + if (registered_method == nullptr) { + rm = unregistered_request_matcher_.get(); + } else { + payload_handling = registered_method->payload_handling; + rm = registered_method->matcher.get(); + } + auto maybe_read_first_message = If( + payload_handling == GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER, + [call_handler]() mutable { return call_handler.PullMessage(); }, + []() -> ValueOrFailure> { + return ValueOrFailure>( + absl::nullopt); + }); + return TryJoin( + std::move(maybe_read_first_message), rm->MatchRequest(0), + [md = std::move(md)]() mutable { + return ValueOrFailure(std::move(md)); + }); + }, + // Publish call to cq + [call_handler, this](std::tuple, + RequestMatcherInterface::MatchResult, + ClientMetadataHandle> + r) { + RequestMatcherInterface::MatchResult& mr = std::get<1>(r); + auto md = std::move(std::get<2>(r)); + auto* rc = mr.TakeCall(); + rc->Complete(std::move(std::get<0>(r)), *md); + grpc_call* call = + MakeServerCall(call_handler, std::move(md), this, + rc->cq_bound_to_call, rc->initial_metadata); + *rc->call = call; + return Map(WaitForCqEndOp(false, rc->tag, absl::OkStatus(), mr.cq()), + [rc = std::unique_ptr(rc)](Empty) { + return absl::OkStatus(); + }); + }); + }); +} + +absl::StatusOr> +Server::MakeCallDestination(const ChannelArgs& args) { + InterceptionChainBuilder builder(args); + builder.AddOnClientInitialMetadata( + [this](ClientMetadata& md) { SetRegisteredMethodOnMetadata(md); }); + CoreConfiguration::Get().channel_init().AddToInterceptionChainBuilder( + GRPC_SERVER_CHANNEL, builder); + return builder.Build( + MakeCallDestinationFromHandlerFunction([this](CallHandler handler) { + return MatchAndPublishCall(std::move(handler)); + })); +} + Server::Server(const ChannelArgs& args) : channel_args_(args), channelz_node_(CreateChannelzNode(args)), server_call_tracer_factory_(ServerCallTracerFactory::Get(args)), + compression_options_(CompressionOptionsFromChannelArgs(args)), max_time_in_pending_queue_(Duration::Seconds( channel_args_ .GetInt(GRPC_ARG_SERVER_MAX_UNREQUESTED_TIME_IN_SERVER_SECONDS) @@ -862,15 +921,6 @@ void Server::AddListener(OrphanablePtr listener) { } void Server::Start() { - auto make_real_request_matcher = - [this]() -> std::unique_ptr { - if (IsPromiseBasedServerCallEnabled()) { - return std::make_unique(this); - } else { - return std::make_unique(this); - } - }; - started_ = true; for (grpc_completion_queue* cq : cqs_) { if (grpc_cq_can_listen(cq)) { @@ -878,11 +928,11 @@ void Server::Start() { } } if (unregistered_request_matcher_ == nullptr) { - unregistered_request_matcher_ = make_real_request_matcher(); + unregistered_request_matcher_ = std::make_unique(this); } for (auto& rm : registered_methods_) { if (rm.second->matcher == nullptr) { - rm.second->matcher = make_real_request_matcher(); + rm.second->matcher = std::make_unique(this); } } { @@ -913,37 +963,61 @@ grpc_error_handle Server::SetupTransport( const RefCountedPtr& socket_node) { // Create channel. global_stats().IncrementServerChannelsCreated(); - absl::StatusOr> channel = - LegacyChannel::Create("", args.SetObject(transport), GRPC_SERVER_CHANNEL); - if (!channel.ok()) { - return absl_status_to_grpc_error(channel.status()); - } - ChannelData* chand = static_cast( - grpc_channel_stack_element((*channel)->channel_stack(), 0)->channel_data); - // Set up CQs. - size_t cq_idx; - for (cq_idx = 0; cq_idx < cqs_.size(); cq_idx++) { - if (grpc_cq_pollset(cqs_[cq_idx]) == accepting_pollset) break; - } - if (cq_idx == cqs_.size()) { - // Completion queue not found. Pick a random one to publish new calls to. - cq_idx = static_cast(rand()) % std::max(1, cqs_.size()); - } // Set up channelz node. - intptr_t channelz_socket_uuid = 0; - if (socket_node != nullptr) { - channelz_socket_uuid = socket_node->uuid(); - channelz_node_->AddChildSocket(socket_node); - } - // Initialize chand. - chand->InitTransport(Ref(), std::move(*channel), cq_idx, transport, - channelz_socket_uuid); + if (transport->server_transport() != nullptr) { + // Take ownership + // TODO(ctiller): post-v3-transition make this method take an + // OrphanablePtr directly. + OrphanablePtr t(transport->server_transport()); + auto destination = MakeCallDestination(args.SetObject(transport)); + if (!destination.ok()) { + return absl_status_to_grpc_error(destination.status()); + } + // TODO(ctiller): add channelz node + t->SetCallDestination(std::move(*destination)); + MutexLock lock(&mu_global_); + if (ShutdownCalled()) { + t->DisconnectWithError(GRPC_ERROR_CREATE("Server shutdown")); + } + t->StartConnectivityWatch(MakeOrphanable( + t->RefAsSubclass(), Ref())); + LOG(INFO) << "Adding connection"; + connections_.emplace(std::move(t)); + ++connections_open_; + } else { + CHECK(transport->filter_stack_transport() != nullptr); + absl::StatusOr> channel = LegacyChannel::Create( + "", args.SetObject(transport), GRPC_SERVER_CHANNEL); + if (!channel.ok()) { + return absl_status_to_grpc_error(channel.status()); + } + ChannelData* chand = static_cast( + grpc_channel_stack_element((*channel)->channel_stack(), 0) + ->channel_data); + // Set up CQs. + size_t cq_idx; + for (cq_idx = 0; cq_idx < cqs_.size(); cq_idx++) { + if (grpc_cq_pollset(cqs_[cq_idx]) == accepting_pollset) break; + } + if (cq_idx == cqs_.size()) { + // Completion queue not found. Pick a random one to publish new calls to. + cq_idx = static_cast(rand()) % std::max(1, cqs_.size()); + } + intptr_t channelz_socket_uuid = 0; + if (socket_node != nullptr) { + channelz_socket_uuid = socket_node->uuid(); + channelz_node_->AddChildSocket(socket_node); + } + // Initialize chand. + chand->InitTransport(Ref(), std::move(*channel), cq_idx, transport, + channelz_socket_uuid); + } return absl::OkStatus(); } bool Server::HasOpenConnections() { MutexLock lock(&mu_global_); - return !channels_.empty(); + return !channels_.empty() || !connections_.empty(); } void Server::SetRegisteredMethodAllocator( @@ -1023,16 +1097,18 @@ void Server::MaybeFinishShutdown() { MutexLock lock(&mu_call_); KillPendingWorkLocked(GRPC_ERROR_CREATE("Server Shutdown")); } - if (!channels_.empty() || listeners_destroyed_ < listeners_.size()) { + if (!channels_.empty() || connections_open_ > 0 || + listeners_destroyed_ < listeners_.size()) { if (gpr_time_cmp(gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), last_shutdown_message_time_), gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) { last_shutdown_message_time_ = gpr_now(GPR_CLOCK_REALTIME); gpr_log(GPR_DEBUG, - "Waiting for %" PRIuPTR " channels and %" PRIuPTR "/%" PRIuPTR + "Waiting for %" PRIuPTR " channels %" PRIuPTR + " connections and %" PRIuPTR "/%" PRIuPTR " listeners to be destroyed before shutting down server", - channels_.size(), listeners_.size() - listeners_destroyed_, - listeners_.size()); + channels_.size(), connections_open_, + listeners_.size() - listeners_destroyed_, listeners_.size()); } return; } @@ -1095,6 +1171,7 @@ void DonePublishedShutdown(void* /*done_arg*/, grpc_cq_completion* storage) { // -- Once there are no more calls in progress, the channel is closed. void Server::ShutdownAndNotify(grpc_completion_queue* cq, void* tag) { ChannelBroadcaster broadcaster; + absl::flat_hash_set> removing_connections; { // Wait for startup to be finished. Locks mu_global. MutexLock lock(&mu_global_); @@ -1114,6 +1191,7 @@ void Server::ShutdownAndNotify(grpc_completion_queue* cq, void* tag) { } last_shutdown_message_time_ = gpr_now(GPR_CLOCK_REALTIME); broadcaster.FillChannelsLocked(GetChannelsLocked()); + removing_connections.swap(connections_); // Collect all unregistered then registered calls. { MutexLock lock(&mu_call_); @@ -1300,17 +1378,6 @@ Server::ChannelData::~ChannelData() { } } -Arena* Server::ChannelData::CreateArena() { return channel_->CreateArena(); } - -absl::StatusOr Server::ChannelData::CreateCall( - ClientMetadataHandle client_initial_metadata, Arena* arena) { - SetRegisteredMethodOnMetadata(*client_initial_metadata); - auto call = MakeServerCall(std::move(client_initial_metadata), server_.get(), - channel_.get(), arena); - InitCall(call); - return CallInitiator(std::move(call)); -} - void Server::ChannelData::InitTransport(RefCountedPtr server, OrphanablePtr channel, size_t cq_idx, Transport* transport, @@ -1327,22 +1394,15 @@ void Server::ChannelData::InitTransport(RefCountedPtr server, } // Start accept_stream transport op. grpc_transport_op* op = grpc_make_transport_op(nullptr); - int accept_stream_types = 0; - if (transport->filter_stack_transport() != nullptr) { - ++accept_stream_types; - op->set_accept_stream = true; - op->set_accept_stream_fn = AcceptStream; - op->set_registered_method_matcher_fn = [](void* arg, - ClientMetadata* metadata) { - static_cast(arg)->SetRegisteredMethodOnMetadata(*metadata); - }; - op->set_accept_stream_user_data = this; - } - if (transport->server_transport() != nullptr) { - ++accept_stream_types; - transport->server_transport()->SetAcceptor(this); - } - CHECK_EQ(accept_stream_types, 1); + CHECK(transport->filter_stack_transport() != nullptr); + op->set_accept_stream = true; + op->set_accept_stream_fn = AcceptStream; + op->set_registered_method_matcher_fn = [](void* arg, + ClientMetadata* metadata) { + static_cast(arg)->server_->SetRegisteredMethodOnMetadata( + *metadata); + }; + op->set_accept_stream_user_data = this; op->start_connectivity_watch = MakeOrphanable(this); if (server_->ShutdownCalled()) { op->disconnect_with_error = GRPC_ERROR_CREATE("Server shutdown"); @@ -1350,24 +1410,23 @@ void Server::ChannelData::InitTransport(RefCountedPtr server, transport->PerformOp(op); } -Server::RegisteredMethod* Server::ChannelData::GetRegisteredMethod( +Server::RegisteredMethod* Server::GetRegisteredMethod( const absl::string_view& host, const absl::string_view& path) { - if (server_->registered_methods_.empty()) return nullptr; + if (registered_methods_.empty()) return nullptr; // check for an exact match with host - auto it = server_->registered_methods_.find(std::make_pair(host, path)); - if (it != server_->registered_methods_.end()) { + auto it = registered_methods_.find(std::make_pair(host, path)); + if (it != registered_methods_.end()) { return it->second.get(); } // check for wildcard method definition (no host set) - it = server_->registered_methods_.find(std::make_pair("", path)); - if (it != server_->registered_methods_.end()) { + it = registered_methods_.find(std::make_pair("", path)); + if (it != registered_methods_.end()) { return it->second.get(); } return nullptr; } -void Server::ChannelData::SetRegisteredMethodOnMetadata( - ClientMetadata& metadata) { +void Server::SetRegisteredMethodOnMetadata(ClientMetadata& metadata) { auto* authority = metadata.get_pointer(HttpAuthorityMetadata()); if (authority == nullptr) { authority = metadata.get_pointer(HostMetadata()); @@ -1403,188 +1462,14 @@ void Server::ChannelData::AcceptStream(void* arg, Transport* /*transport*/, grpc_call* call; grpc_error_handle error = grpc_call_create(&args, &call); grpc_call_stack* call_stack = grpc_call_get_call_stack(call); - if (call_stack == nullptr) { // Promise based calls do not have a call stack - CHECK(error.ok()); - CHECK(IsPromiseBasedServerCallEnabled()); + CHECK_NE(call_stack, nullptr); + grpc_call_element* elem = grpc_call_stack_element(call_stack, 0); + auto* calld = static_cast(elem->call_data); + if (!error.ok()) { + calld->FailCallCreation(); return; - } else { - grpc_call_element* elem = grpc_call_stack_element(call_stack, 0); - auto* calld = static_cast(elem->call_data); - if (!error.ok()) { - calld->FailCallCreation(); - return; - } - calld->Start(elem); } -} - -namespace { -auto CancelledDueToServerShutdown() { - return [] { - return ServerMetadataFromStatus(absl::CancelledError("Server shutdown")); - }; -} -} // namespace - -void Server::ChannelData::InitCall(RefCountedPtr call) { - call->SpawnGuarded("request_matcher", [this, call]() { - return TrySeq( - // Wait for initial metadata to pass through all filters - Map(call->PullClientInitialMetadata(), - [](ValueOrFailure md) - -> absl::StatusOr { - if (!md.ok()) { - return absl::InternalError("Missing metadata"); - } - if (!md.value()->get_pointer(HttpPathMetadata())) { - return absl::InternalError("Missing :path header"); - } - if (!md.value()->get_pointer(HttpAuthorityMetadata())) { - return absl::InternalError("Missing :authority header"); - } - return std::move(*md); - }), - // Match request with requested call - [this, call](ClientMetadataHandle md) { - auto* registered_method = static_cast( - md->get(GrpcRegisteredMethod()).value_or(nullptr)); - RequestMatcherInterface* rm; - grpc_server_register_method_payload_handling payload_handling = - GRPC_SRM_PAYLOAD_NONE; - if (registered_method == nullptr) { - rm = server_->unregistered_request_matcher_.get(); - } else { - payload_handling = registered_method->payload_handling; - rm = registered_method->matcher.get(); - } - auto maybe_read_first_message = If( - payload_handling == GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER, - [call]() { return call->PullClientToServerMessage(); }, - []() -> ValueOrFailure> { - return ValueOrFailure>( - absl::nullopt); - }); - return TryJoin( - std::move(maybe_read_first_message), rm->MatchRequest(cq_idx()), - [md = std::move(md)]() mutable { - return ValueOrFailure(std::move(md)); - }); - }, - // Publish call to cq - [](std::tuple, - RequestMatcherInterface::MatchResult, - ClientMetadataHandle> - r) { - RequestMatcherInterface::MatchResult& mr = std::get<1>(r); - auto md = std::move(std::get<2>(r)); - auto* rc = mr.TakeCall(); - rc->Complete(std::move(std::get<0>(r)), *md); - auto* call_context = GetContext(); - const auto* deadline = md->get_pointer(GrpcTimeoutMetadata()); - if (deadline != nullptr) { - GetContext()->UpdateDeadline(*deadline); - } - *rc->call = call_context->c_call(); - grpc_call_ref(*rc->call); - grpc_call_set_completion_queue(call_context->c_call(), - rc->cq_bound_to_call); - call_context->server_call_context()->PublishInitialMetadata( - std::move(md), rc->initial_metadata); - // TODO(ctiller): publish metadata - return Map(WaitForCqEndOp(false, rc->tag, absl::OkStatus(), mr.cq()), - [rc = std::unique_ptr(rc)](Empty) { - return absl::OkStatus(); - }); - }); - }); -} - -ArenaPromise Server::ChannelData::MakeCallPromise( - grpc_channel_element* elem, CallArgs call_args, NextPromiseFactory) { - auto* chand = static_cast(elem->channel_data); - auto* server = chand->server_.get(); - if (server->ShutdownCalled()) return CancelledDueToServerShutdown(); - auto cleanup_ref = - absl::MakeCleanup([server] { server->ShutdownUnrefOnRequest(); }); - if (!server->ShutdownRefOnRequest()) return CancelledDueToServerShutdown(); - auto path_ptr = - call_args.client_initial_metadata->get_pointer(HttpPathMetadata()); - if (path_ptr == nullptr) { - return [] { - return ServerMetadataFromStatus( - absl::InternalError("Missing :path header")); - }; - } - auto host_ptr = - call_args.client_initial_metadata->get_pointer(HttpAuthorityMetadata()); - if (host_ptr == nullptr) { - return [] { - return ServerMetadataFromStatus( - absl::InternalError("Missing :authority header")); - }; - } - // Find request matcher. - RequestMatcherInterface* matcher; - RegisteredMethod* rm = static_cast( - call_args.client_initial_metadata->get(GrpcRegisteredMethod()) - .value_or(nullptr)); - ArenaPromise>> - maybe_read_first_message([] { return NextResult(); }); - if (rm != nullptr) { - matcher = rm->matcher.get(); - switch (rm->payload_handling) { - case GRPC_SRM_PAYLOAD_NONE: - break; - case GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER: - maybe_read_first_message = - Map(call_args.client_to_server_messages->Next(), - [](NextResult msg) - -> absl::StatusOr> { - return std::move(msg); - }); - } - } else { - matcher = server->unregistered_request_matcher_.get(); - } - return TrySeq( - std::move(maybe_read_first_message), - [cleanup_ref = std::move(cleanup_ref), matcher, - chand](NextResult payload) mutable { - return Map( - [cleanup_ref = std::move(cleanup_ref), - mr = matcher->MatchRequest(chand->cq_idx())]() mutable { - return mr(); - }, - [payload = std::move(payload)]( - absl::StatusOr mr) mutable - -> absl::StatusOr>> { - if (!mr.ok()) return mr.status(); - return std::make_pair(std::move(*mr), std::move(payload)); - }); - }, - [call_args = - std::move(call_args)](std::pair> - r) mutable { - auto& mr = r.first; - auto& payload = r.second; - auto* rc = mr.TakeCall(); - auto* cq_for_new_request = mr.cq(); - auto* server_call_context = - GetContext()->server_call_context(); - rc->Complete(std::move(payload), *call_args.client_initial_metadata); - server_call_context->PublishInitialMetadata( - std::move(call_args.client_initial_metadata), rc->initial_metadata); - return server_call_context->MakeTopOfServerCallPromise( - std::move(call_args), rc->cq_bound_to_call, - [rc, cq_for_new_request](grpc_call* call) { - *rc->call = call; - grpc_cq_end_op(cq_for_new_request, rc->tag, absl::OkStatus(), - Server::DoneRequestEvent, rc, &rc->completion, - true); - }); - }); + calld->Start(elem); } void Server::ChannelData::FinishDestroy(void* arg, @@ -1610,7 +1495,7 @@ void Server::ChannelData::Destroy() { GRPC_CLOSURE_INIT(&finish_destroy_channel_closure_, FinishDestroy, this, grpc_schedule_on_exec_ctx); if (GRPC_TRACE_FLAG_ENABLED(grpc_server_channel_trace)) { - gpr_log(GPR_INFO, "Disconnected client"); + LOG(INFO) << "Disconnected client"; } grpc_transport_op* op = grpc_make_transport_op(&finish_destroy_channel_closure_); diff --git a/src/core/server/server.h b/src/core/server/server.h index 486892b14d8..01b541c233e 100644 --- a/src/core/server/server.h +++ b/src/core/server/server.h @@ -38,7 +38,9 @@ #include "absl/strings/string_view.h" #include "absl/types/optional.h" +#include #include +#include #include #include #include @@ -74,6 +76,9 @@ "grpc.server.max_pending_requests_hard_limit" namespace grpc_core { +namespace experimental { +class PassiveListenerImpl; +} // namespace experimental extern TraceFlag grpc_server_channel_trace; @@ -112,7 +117,7 @@ class Server : public ServerInterface, /// Interface for listeners. /// Implementations must override the Orphan() method, which should stop /// listening and initiate destruction of the listener. - class ListenerInterface : public Orphanable { + class ListenerInterface : public InternallyRefCounted { public: ~ListenerInterface() override = default; @@ -211,17 +216,28 @@ class Server : public ServerInterface, void SendGoaways() ABSL_LOCKS_EXCLUDED(mu_global_, mu_call_); + grpc_compression_options compression_options() const override { + return compression_options_; + } + private: + // note: the grpc_core::Server redundant namespace qualification is + // required for older gcc versions. + // TODO(yashykt): eliminate this friend statement as part of your upcoming + // server listener refactoring. + friend absl::Status(::grpc_server_add_passive_listener)( + grpc_core::Server* server, grpc_server_credentials* credentials, + std::shared_ptr + passive_listener); struct RequestedCall; class RequestMatcherInterface; - class RealRequestMatcherFilterStack; - class RealRequestMatcherPromises; + class RealRequestMatcher; class AllocatingRequestMatcherBase; class AllocatingRequestMatcherBatch; class AllocatingRequestMatcherRegistered; - class ChannelData final : public ServerTransport::Acceptor { + class ChannelData final { public: ChannelData() = default; ~ChannelData(); @@ -234,26 +250,17 @@ class Server : public ServerInterface, Channel* channel() const { return channel_.get(); } size_t cq_idx() const { return cq_idx_; } - RegisteredMethod* GetRegisteredMethod(const absl::string_view& host, - const absl::string_view& path); // Filter vtable functions. static grpc_error_handle InitChannelElement( grpc_channel_element* elem, grpc_channel_element_args* args); static void DestroyChannelElement(grpc_channel_element* elem); - static ArenaPromise MakeCallPromise( - grpc_channel_element* elem, CallArgs call_args, NextPromiseFactory); void InitCall(RefCountedPtr call); - Arena* CreateArena() override; - absl::StatusOr CreateCall( - ClientMetadataHandle client_initial_metadata, Arena* arena) override; - private: class ConnectivityWatcher; static void AcceptStream(void* arg, Transport* /*transport*/, const void* transport_server_data); - void SetRegisteredMethodOnMetadata(ClientMetadata& metadata); void Destroy() ABSL_EXCLUSIVE_LOCKS_REQUIRED(server_->mu_global_); @@ -384,6 +391,12 @@ class Server : public ServerInterface, using is_transparent = void; }; + class TransportConnectivityWatcher; + + RegisteredMethod* GetRegisteredMethod(const absl::string_view& host, + const absl::string_view& path); + void SetRegisteredMethodOnMetadata(ClientMetadata& metadata); + static void ListenerDestroyDone(void* arg, grpc_error_handle error); static void DoneShutdownEvent(void* server, @@ -445,6 +458,10 @@ class Server : public ServerInterface, return shutdown_refs_.load(std::memory_order_acquire) == 0; } + auto MatchAndPublishCall(CallHandler call_handler); + absl::StatusOr> MakeCallDestination( + const ChannelArgs& args); + ChannelArgs const channel_args_; RefCountedPtr channelz_node_; std::unique_ptr config_fetcher_; @@ -453,6 +470,7 @@ class Server : public ServerInterface, std::vector cqs_; std::vector pollsets_; bool started_ = false; + const grpc_compression_options compression_options_; // The two following mutexes control access to server-state. // mu_global_ controls access to non-call-related state (e.g., channel state). @@ -500,6 +518,9 @@ class Server : public ServerInterface, absl::BitGen bitgen_ ABSL_GUARDED_BY(mu_call_); std::list channels_; + absl::flat_hash_set> connections_ + ABSL_GUARDED_BY(mu_global_); + size_t connections_open_ ABSL_GUARDED_BY(mu_global_) = 0; std::list listeners_; size_t listeners_destroyed_ = 0; diff --git a/src/core/server/server_call_tracer_filter.cc b/src/core/server/server_call_tracer_filter.cc index 6966b4ccc05..6ceb637d481 100644 --- a/src/core/server/server_call_tracer_filter.cc +++ b/src/core/server/server_call_tracer_filter.cc @@ -80,6 +80,7 @@ class ServerCallTracerFilter } static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; private: @@ -92,6 +93,7 @@ class ServerCallTracerFilter }; const NoInterceptor ServerCallTracerFilter::Call::OnClientToServerMessage; +const NoInterceptor ServerCallTracerFilter::Call::OnClientToServerHalfClose; const NoInterceptor ServerCallTracerFilter::Call::OnServerToClientMessage; const grpc_channel_filter ServerCallTracerFilter::kFilter = diff --git a/src/core/server/server_config_selector.h b/src/core/server/server_config_selector.h index dbead559c11..c6274f49f35 100644 --- a/src/core/server/server_config_selector.h +++ b/src/core/server/server_config_selector.h @@ -24,13 +24,13 @@ #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/dual_ref_counted.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/transport/metadata_batch.h" #include "src/core/service_config/service_config.h" #include "src/core/service_config/service_config_parser.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/server/server_config_selector_filter.cc b/src/core/server/server_config_selector_filter.cc index 4da3b75398c..b4acec5329e 100644 --- a/src/core/server/server_config_selector_filter.cc +++ b/src/core/server/server_config_selector_filter.cc @@ -72,6 +72,7 @@ class ServerConfigSelectorFilter final static const NoInterceptor OnServerInitialMetadata; static const NoInterceptor OnServerTrailingMetadata; static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnFinalize; }; @@ -158,6 +159,7 @@ absl::Status ServerConfigSelectorFilter::Call::OnClientInitialMetadata( const NoInterceptor ServerConfigSelectorFilter::Call::OnServerInitialMetadata; const NoInterceptor ServerConfigSelectorFilter::Call::OnServerTrailingMetadata; const NoInterceptor ServerConfigSelectorFilter::Call::OnClientToServerMessage; +const NoInterceptor ServerConfigSelectorFilter::Call::OnClientToServerHalfClose; const NoInterceptor ServerConfigSelectorFilter::Call::OnServerToClientMessage; const NoInterceptor ServerConfigSelectorFilter::Call::OnFinalize; diff --git a/src/core/server/server_interface.h b/src/core/server/server_interface.h index 3cb7b1702ff..431ad369714 100644 --- a/src/core/server/server_interface.h +++ b/src/core/server/server_interface.h @@ -17,6 +17,7 @@ #ifndef GRPC_SRC_CORE_SERVER_SERVER_INTERFACE_H #define GRPC_SRC_CORE_SERVER_SERVER_INTERFACE_H +#include #include #include "src/core/channelz/channelz.h" @@ -36,6 +37,7 @@ class ServerInterface { virtual const ChannelArgs& channel_args() const = 0; virtual channelz::ServerNode* channelz_node() const = 0; virtual ServerCallTracerFactory* server_call_tracer_factory() const = 0; + virtual grpc_compression_options compression_options() const = 0; }; } // namespace grpc_core diff --git a/src/core/server/xds_channel_stack_modifier.cc b/src/core/server/xds_channel_stack_modifier.cc index 2dfa03a1ed2..f9e280ea28a 100644 --- a/src/core/server/xds_channel_stack_modifier.cc +++ b/src/core/server/xds_channel_stack_modifier.cc @@ -27,9 +27,9 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/config/core_configuration.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/surface/channel_init.h" #include "src/core/lib/surface/channel_stack_type.h" +#include "src/core/util/useful.h" namespace grpc_core { namespace { diff --git a/src/core/server/xds_channel_stack_modifier.h b/src/core/server/xds_channel_stack_modifier.h index 78dc1db0b2c..4cea9e165e7 100644 --- a/src/core/server/xds_channel_stack_modifier.h +++ b/src/core/server/xds_channel_stack_modifier.h @@ -29,9 +29,9 @@ #include "src/core/lib/channel/channel_fwd.h" #include "src/core/lib/channel/channel_stack_builder.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/service_config/service_config.h b/src/core/service_config/service_config.h index 7935150fb2c..ba5fa8262ae 100644 --- a/src/core/service_config/service_config.h +++ b/src/core/service_config/service_config.h @@ -24,9 +24,9 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/service_config/service_config_parser.h" +#include "src/core/util/useful.h" // The main purpose of the code here is to parse the service config in // JSON form, which will look like this: diff --git a/src/core/service_config/service_config_channel_arg_filter.cc b/src/core/service_config/service_config_channel_arg_filter.cc index a2c9a973129..9afa99018fc 100644 --- a/src/core/service_config/service_config_channel_arg_filter.cc +++ b/src/core/service_config/service_config_channel_arg_filter.cc @@ -22,6 +22,7 @@ #include #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/types/optional.h" @@ -69,7 +70,7 @@ class ServiceConfigChannelArgFilter final auto service_config = ServiceConfigImpl::Create(args, *service_config_str); if (!service_config.ok()) { - gpr_log(GPR_ERROR, "%s", service_config.status().ToString().c_str()); + LOG(ERROR) << service_config.status().ToString(); } else { service_config_ = std::move(*service_config); } @@ -83,6 +84,7 @@ class ServiceConfigChannelArgFilter final static const NoInterceptor OnServerInitialMetadata; static const NoInterceptor OnServerTrailingMetadata; static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnFinalize; }; @@ -97,6 +99,8 @@ const NoInterceptor ServiceConfigChannelArgFilter::Call::OnServerTrailingMetadata; const NoInterceptor ServiceConfigChannelArgFilter::Call::OnClientToServerMessage; +const NoInterceptor + ServiceConfigChannelArgFilter::Call::OnClientToServerHalfClose; const NoInterceptor ServiceConfigChannelArgFilter::Call::OnServerToClientMessage; const NoInterceptor ServiceConfigChannelArgFilter::Call::OnFinalize; diff --git a/src/core/tsi/alts/frame_protector/alts_frame_protector.cc b/src/core/tsi/alts/frame_protector/alts_frame_protector.cc index 9b48b181d1f..09415c413d6 100644 --- a/src/core/tsi/alts/frame_protector/alts_frame_protector.cc +++ b/src/core/tsi/alts/frame_protector/alts_frame_protector.cc @@ -24,10 +24,10 @@ #include #include +#include "absl/log/log.h" #include "absl/types/span.h" #include -#include #include #include "src/core/lib/gprpp/memory.h" @@ -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; } @@ -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(self); @@ -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; } } @@ -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; @@ -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(self); @@ -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; } @@ -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(self); @@ -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; @@ -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; @@ -370,8 +370,7 @@ 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; @@ -379,7 +378,7 @@ tsi_result alts_create_frame_protector(const uint8_t* key, size_t key_size, 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; } diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc index 88cf0c06223..91afee2e5f5 100644 --- a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +++ b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/numbers.h" #include "upb/mem/arena.hpp" @@ -205,13 +206,13 @@ 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()", @@ -220,14 +221,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); @@ -249,7 +250,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); @@ -258,7 +259,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; @@ -281,7 +282,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); @@ -299,7 +300,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 @@ -357,7 +358,7 @@ static tsi_result continue_make_grpc_call(alts_grpc_handshaker_client* client, if (client->grpc_caller(client->call, ops, static_cast(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; @@ -544,21 +545,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(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; } @@ -603,21 +604,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(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; } @@ -640,7 +641,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 = @@ -649,14 +650,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; } @@ -716,7 +717,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(); @@ -891,8 +892,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; } @@ -902,8 +902,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; } @@ -913,8 +912,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; } 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/src/core/tsi/alts/handshaker/alts_tsi_utils.cc b/src/core/tsi/alts/handshaker/alts_tsi_utils.cc index 05e5400a7d8..0c4325844bd 100644 --- a/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +++ b/src/core/tsi/alts/handshaker/alts_tsi_utils.cc @@ -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 #include @@ -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; diff --git a/src/core/tsi/alts/handshaker/transport_security_common_api.cc b/src/core/tsi/alts/handshaker/transport_security_common_api.cc index bb3c209a711..79fafc8f0af 100644 --- a/src/core/tsi/alts/handshaker/transport_security_common_api.cc +++ b/src/core/tsi/alts/handshaker/transport_security_common_api.cc @@ -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 @@ -100,7 +101,7 @@ bool grpc_gcp_rpc_protocol_versions_decode( reinterpret_cast(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); diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc index 81df2cbb131..8d9a98dbc45 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -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; } @@ -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; } @@ -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 @@ -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; } diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc index 768c8b775b7..a9aac4948a9 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc @@ -18,6 +18,8 @@ #include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h" +#include "absl/log/log.h" + #include #include #include @@ -60,7 +62,7 @@ static tsi_result alts_grpc_privacy_integrity_protect( rp->iovec_rp, rp->iovec_buf, unprotected_slices->count, protected_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); grpc_core::CSliceUnref(protected_slice); return TSI_INTERNAL_ERROR; @@ -84,7 +86,7 @@ static tsi_result alts_grpc_privacy_integrity_unprotect( // Allocates memory for output frame. In privacy-integrity unprotect, the // unprotected data are stored in a newly allocated buffer. 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; } size_t unprotected_frame_size = @@ -105,7 +107,7 @@ static tsi_result alts_grpc_privacy_integrity_unprotect( rp->iovec_rp, header_iovec, rp->iovec_buf, protected_slices->count, unprotected_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); grpc_core::CSliceUnref(unprotected_slice); return TSI_INTERNAL_ERROR; diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc index bd1f1fc7fcd..da2eaf4bfad 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc @@ -26,10 +26,10 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/util/useful.h" const size_t kInitialIovecBufferSize = 8; diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc index 6847dfdaa96..3d29dc6de9e 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -93,7 +94,7 @@ static bool read_frame_size(const grpc_slice_buffer* sb, (static_cast(frame_size_buffer[1]) << 8) | static_cast(frame_size_buffer[0]); if (frame_size > kMaxFrameLength) { - gpr_log(GPR_ERROR, "Frame size is larger than maximum frame size"); + LOG(ERROR) << "Frame size is larger than maximum frame size"; return false; } // Returns frame size including frame length field. @@ -124,7 +125,7 @@ static tsi_result create_alts_grpc_record_protocol( kAesGcmTagLength, &crypter, &error_details); if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to create AEAD crypter, %s", error_details); + LOG(ERROR) << "Failed to create AEAD crypter, " << error_details; gpr_free(error_details); return TSI_INTERNAL_ERROR; } @@ -153,7 +154,7 @@ static tsi_result alts_zero_copy_grpc_protector_protect( grpc_slice_buffer* protected_slices) { if (self == nullptr || unprotected_slices == nullptr || protected_slices == nullptr) { - gpr_log(GPR_ERROR, "Invalid nullptr arguments to zero-copy grpc protect."); + LOG(ERROR) << "Invalid nullptr arguments to zero-copy grpc protect."; return TSI_INVALID_ARGUMENT; } alts_zero_copy_grpc_protector* protector = diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index a2aca84009b..2fffb042bb8 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -22,16 +22,17 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/memory.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/tsi/transport_security_grpc.h" +#include "src/core/tsi/transport_security_interface.h" // --- Constants. --- #define TSI_FAKE_FRAME_HEADER_SIZE 4 @@ -91,7 +92,7 @@ static const char* tsi_fake_handshake_message_strings[] = { static const char* tsi_fake_handshake_message_to_string(int msg) { if (msg < 0 || msg >= TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { - gpr_log(GPR_ERROR, "Invalid message %d", msg); + LOG(ERROR) << "Invalid message " << msg; return "UNKNOWN"; } return tsi_fake_handshake_message_strings[msg]; @@ -107,7 +108,7 @@ static tsi_result tsi_fake_handshake_message_from_string( return TSI_OK; } } - gpr_log(GPR_ERROR, "Invalid handshake message."); + LOG(ERROR) << "Invalid handshake message."; if (error != nullptr) *error = "invalid handshake message"; return TSI_DATA_CORRUPTED; } @@ -312,8 +313,8 @@ static tsi_result fake_protector_protect(tsi_frame_protector* self, result = tsi_fake_frame_decode(frame_header, &written_in_frame_size, frame, /*error=*/nullptr); if (result != TSI_INCOMPLETE_DATA) { - gpr_log(GPR_ERROR, "tsi_fake_frame_decode returned %s", - tsi_result_to_string(result)); + LOG(ERROR) << "tsi_fake_frame_decode returned " + << tsi_result_to_string(result); return result; } } @@ -469,7 +470,7 @@ static tsi_result fake_zero_copy_grpc_protector_unprotect( if (impl->parsed_frame_size == 0) { impl->parsed_frame_size = read_frame_size(&impl->protected_sb); if (impl->parsed_frame_size <= 4) { - gpr_log(GPR_ERROR, "Invalid frame size."); + LOG(ERROR) << "Invalid frame size."; return TSI_DATA_CORRUPTED; } } @@ -653,7 +654,7 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer( impl->next_message_to_send == TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { // We're done. if (GRPC_TRACE_FLAG_ENABLED(tsi_tracing_enabled)) { - gpr_log(GPR_INFO, "Server is done."); + LOG(INFO) << "Server is done."; } impl->result = TSI_OK; } else { @@ -694,15 +695,15 @@ static tsi_result fake_handshaker_process_bytes_from_peer( tsi_fake_handshake_message_to_string(expected_msg)); } if (GRPC_TRACE_FLAG_ENABLED(tsi_tracing_enabled)) { - gpr_log(GPR_INFO, "%s received %s.", impl->is_client ? "Client" : "Server", - tsi_fake_handshake_message_to_string(received_msg)); + LOG(INFO) << (impl->is_client ? "Client" : "Server") << " received " + << tsi_fake_handshake_message_to_string(received_msg); } tsi_fake_frame_reset(&impl->incoming_frame, 0 /* needs_draining */); impl->needs_incoming_message = 0; if (impl->next_message_to_send == TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { // We're done. if (GRPC_TRACE_FLAG_ENABLED(tsi_tracing_enabled)) { - gpr_log(GPR_INFO, "%s is done.", impl->is_client ? "Client" : "Server"); + LOG(INFO) << (impl->is_client ? "Client" : "Server") << " is done."; } impl->result = TSI_OK; } diff --git a/src/core/tsi/local_transport_security.cc b/src/core/tsi/local_transport_security.cc index 944aee67145..30a2ef7f670 100644 --- a/src/core/tsi/local_transport_security.cc +++ b/src/core/tsi/local_transport_security.cc @@ -22,8 +22,9 @@ #include #include +#include "absl/log/log.h" + #include -#include #include #include @@ -68,7 +69,7 @@ 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 get_unused_bytes()"); + LOG(ERROR) << "Invalid arguments to get_unused_bytes()"; return TSI_INVALID_ARGUMENT; } auto* result = reinterpret_cast( @@ -101,7 +102,7 @@ tsi_result create_handshaker_result(const unsigned char* received_bytes, size_t received_bytes_size, tsi_handshaker_result** self) { if (self == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to create_handshaker_result()"); + LOG(ERROR) << "Invalid arguments to create_handshaker_result()"; return TSI_INVALID_ARGUMENT; } local_tsi_handshaker_result* result = @@ -128,7 +129,7 @@ tsi_result handshaker_next(tsi_handshaker* self, tsi_handshaker_on_next_done_cb /*cb*/, void* /*user_data*/, std::string* error) { if (self == 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; } @@ -164,7 +165,7 @@ const tsi_handshaker_vtable handshaker_vtable = { tsi_result tsi_local_handshaker_create(tsi_handshaker** self) { if (self == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to local_tsi_handshaker_create()"); + LOG(ERROR) << "Invalid arguments to local_tsi_handshaker_create()"; return TSI_INVALID_ARGUMENT; } local_tsi_handshaker* handshaker = grpc_core::Zalloc(); diff --git a/src/core/tsi/ssl/session_cache/ssl_session_cache.cc b/src/core/tsi/ssl/session_cache/ssl_session_cache.cc index 4f33c4722ac..de89e3e85fe 100644 --- a/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +++ b/src/core/tsi/ssl/session_cache/ssl_session_cache.cc @@ -19,6 +19,7 @@ #include "src/core/tsi/ssl/session_cache/ssl_session_cache.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -64,9 +65,8 @@ class SslSessionLRUCache::Node { SslSessionLRUCache::SslSessionLRUCache(size_t capacity) : capacity_(capacity) { if (capacity == 0) { - gpr_log( - GPR_ERROR, - "SslSessionLRUCache capacity is zero. SSL sessions cannot be resumed."); + LOG(ERROR) << "SslSessionLRUCache capacity is zero. SSL sessions cannot be " + "resumed."; } } @@ -100,7 +100,7 @@ SslSessionLRUCache::Node* SslSessionLRUCache::FindLocked( void SslSessionLRUCache::Put(const char* key, SslSessionPtr session) { if (session == nullptr) { - gpr_log(GPR_ERROR, "Attempted to put null SSL session in session cache."); + LOG(ERROR) << "Attempted to put null SSL session in session cache."; return; } grpc_core::MutexLock lock(&lock_); diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc index eb092155ae2..6ec4e0a2546 100644 --- a/src/core/tsi/ssl_transport_security.cc +++ b/src/core/tsi/ssl_transport_security.cc @@ -23,6 +23,8 @@ #include +#include "src/core/tsi/transport_security_interface.h" + // TODO(jboeuf): refactor inet_ntop into a portability header. // Note: for whomever reads this and tries to refactor this, this // can't be in grpc, it has to be in gpr. @@ -46,6 +48,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -53,12 +56,10 @@ #include #include #include -#include #include #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/security/credentials/tls/grpc_tls_crl_provider.h" #include "src/core/tsi/ssl/key_logging/ssl_key_logging.h" @@ -66,6 +67,7 @@ #include "src/core/tsi/ssl_transport_security_utils.h" #include "src/core/tsi/ssl_types.h" #include "src/core/tsi/transport_security.h" +#include "src/core/util/useful.h" // --- Constants. --- @@ -204,7 +206,7 @@ static void init_openssl(void) { CRYPTO_set_locking_callback(openssl_locking_cb); CRYPTO_set_id_callback(openssl_thread_id_cb); } else { - gpr_log(GPR_INFO, "OpenSSL callback has already been set."); + LOG(INFO) << "OpenSSL callback has already been set."; } #endif g_ssl_ctx_ex_factory_index = @@ -234,7 +236,7 @@ static void ssl_log_where_info(const SSL* ssl, int where, int flag, // Used for debugging. TODO(jboeuf): Remove when code is mature enough. static void ssl_info_callback(const SSL* ssl, int where, int ret) { if (ret == 0) { - gpr_log(GPR_ERROR, "ssl_info_callback: error occurred.\n"); + LOG(ERROR) << "ssl_info_callback: error occurred.\n"; return; } @@ -277,30 +279,28 @@ static tsi_result ssl_get_x509_common_name(X509* cert, unsigned char** utf8, X509_NAME* subject_name = X509_get_subject_name(cert); int utf8_returned_size = 0; if (subject_name == nullptr) { - gpr_log(GPR_DEBUG, "Could not get subject name from certificate."); + VLOG(2) << "Could not get subject name from certificate."; return TSI_NOT_FOUND; } common_name_index = X509_NAME_get_index_by_NID(subject_name, NID_commonName, -1); if (common_name_index == -1) { - gpr_log(GPR_DEBUG, - "Could not get common name of subject from certificate."); + VLOG(2) << "Could not get common name of subject from certificate."; return TSI_NOT_FOUND; } common_name_entry = X509_NAME_get_entry(subject_name, common_name_index); if (common_name_entry == nullptr) { - gpr_log(GPR_ERROR, "Could not get common name entry from certificate."); + LOG(ERROR) << "Could not get common name entry from certificate."; return TSI_INTERNAL_ERROR; } common_name_asn1 = X509_NAME_ENTRY_get_data(common_name_entry); if (common_name_asn1 == nullptr) { - gpr_log(GPR_ERROR, - "Could not get common name entry asn1 from certificate."); + LOG(ERROR) << "Could not get common name entry asn1 from certificate."; return TSI_INTERNAL_ERROR; } utf8_returned_size = ASN1_STRING_to_UTF8(utf8, common_name_asn1); if (utf8_returned_size < 0) { - gpr_log(GPR_ERROR, "Could not extract utf8 from asn1 string."); + LOG(ERROR) << "Could not extract utf8 from asn1 string."; return TSI_OUT_OF_RESOURCES; } *utf8_size = static_cast(utf8_returned_size); @@ -336,7 +336,7 @@ static tsi_result peer_property_from_x509_subject(X509* cert, bool is_verified_root_cert) { X509_NAME* subject_name = X509_get_subject_name(cert); if (subject_name == nullptr) { - gpr_log(GPR_INFO, "Could not get subject name from certificate."); + LOG(INFO) << "Could not get subject name from certificate."; return TSI_NOT_FOUND; } BIO* bio = BIO_new(BIO_s_mem()); @@ -344,7 +344,7 @@ static tsi_result peer_property_from_x509_subject(X509* cert, char* contents; long len = BIO_get_mem_data(bio, &contents); if (len < 0) { - gpr_log(GPR_ERROR, "Could not get subject entry from certificate."); + LOG(ERROR) << "Could not get subject entry from certificate."; BIO_free(bio); return TSI_INTERNAL_ERROR; } @@ -409,7 +409,7 @@ static tsi_result add_subject_alt_names_properties_to_peer( property_name = TSI_X509_URI_PEER_PROPERTY; } if (name_size < 0) { - gpr_log(GPR_ERROR, "Could not get utf8 from asn1 string."); + LOG(ERROR) << "Could not get utf8 from asn1 string."; result = TSI_INTERNAL_ERROR; break; } @@ -435,14 +435,14 @@ static tsi_result add_subject_alt_names_properties_to_peer( } else if (subject_alt_name->d.iPAddress->length == 16) { af = AF_INET6; } else { - gpr_log(GPR_ERROR, "SAN IP Address contained invalid IP"); + LOG(ERROR) << "SAN IP Address contained invalid IP"; result = TSI_INTERNAL_ERROR; break; } const char* name = inet_ntop(af, subject_alt_name->d.iPAddress->data, ntop_buf, INET6_ADDRSTRLEN); if (name == nullptr) { - gpr_log(GPR_ERROR, "Could not get IP string from asn1 octet."); + LOG(ERROR) << "Could not get IP string from asn1 octet."; result = TSI_INTERNAL_ERROR; break; } @@ -605,7 +605,7 @@ static tsi_result ssl_ctx_use_engine_private_key(SSL_CTX* context, } engine_name = static_cast(gpr_zalloc(engine_name_length + 1)); memcpy(engine_name, engine_start, engine_name_length); - gpr_log(GPR_DEBUG, "ENGINE key: %s", engine_name); + VLOG(2) << "ENGINE key: " << engine_name; ENGINE_load_dynamic(); engine = ENGINE_by_id(engine_name); if (engine == nullptr) { @@ -613,7 +613,7 @@ static tsi_result ssl_ctx_use_engine_private_key(SSL_CTX* context, // current working directory. engine = ENGINE_by_id("dynamic"); if (engine == nullptr) { - gpr_log(GPR_ERROR, "Cannot load dynamic engine"); + LOG(ERROR) << "Cannot load dynamic engine"; result = TSI_INVALID_ARGUMENT; break; } @@ -622,29 +622,29 @@ static tsi_result ssl_ctx_use_engine_private_key(SSL_CTX* context, !ENGINE_ctrl_cmd_string(engine, "DIR_ADD", ".", 0) || !ENGINE_ctrl_cmd_string(engine, "LIST_ADD", "1", 0) || !ENGINE_ctrl_cmd_string(engine, "LOAD", NULL, 0)) { - gpr_log(GPR_ERROR, "Cannot find engine"); + LOG(ERROR) << "Cannot find engine"; result = TSI_INVALID_ARGUMENT; break; } } if (!ENGINE_set_default(engine, ENGINE_METHOD_ALL)) { - gpr_log(GPR_ERROR, "ENGINE_set_default with ENGINE_METHOD_ALL failed"); + LOG(ERROR) << "ENGINE_set_default with ENGINE_METHOD_ALL failed"; result = TSI_INVALID_ARGUMENT; break; } if (!ENGINE_init(engine)) { - gpr_log(GPR_ERROR, "ENGINE_init failed"); + LOG(ERROR) << "ENGINE_init failed"; result = TSI_INVALID_ARGUMENT; break; } private_key = ENGINE_load_private_key(engine, key_id, 0, 0); if (private_key == nullptr) { - gpr_log(GPR_ERROR, "ENGINE_load_private_key failed"); + LOG(ERROR) << "ENGINE_load_private_key failed"; result = TSI_INVALID_ARGUMENT; break; } if (!SSL_CTX_use_PrivateKey(context, private_key)) { - gpr_log(GPR_ERROR, "SSL_CTX_use_PrivateKey failed"); + LOG(ERROR) << "SSL_CTX_use_PrivateKey failed"; result = TSI_INVALID_ARGUMENT; break; } @@ -725,7 +725,7 @@ static tsi_result x509_store_load_certs(X509_STORE* cert_store, if (root_names != nullptr) { root_name = X509_get_subject_name(root); if (root_name == nullptr) { - gpr_log(GPR_ERROR, "Could not get name from root certificate."); + LOG(ERROR) << "Could not get name from root certificate."; result = TSI_INVALID_ARGUMENT; break; } @@ -742,7 +742,7 @@ static tsi_result x509_store_load_certs(X509_STORE* cert_store, unsigned long error = ERR_get_error(); if (ERR_GET_LIB(error) != ERR_LIB_X509 || ERR_GET_REASON(error) != X509_R_CERT_ALREADY_IN_HASH_TABLE) { - gpr_log(GPR_ERROR, "Could not add root certificate to ssl context."); + LOG(ERROR) << "Could not add root certificate to ssl context."; result = TSI_INTERNAL_ERROR; break; } @@ -751,7 +751,7 @@ static tsi_result x509_store_load_certs(X509_STORE* cert_store, num_roots++; } if (num_roots == 0) { - gpr_log(GPR_ERROR, "Could not load any root certificate."); + LOG(ERROR) << "Could not load any root certificate."; result = TSI_INVALID_ARGUMENT; } @@ -790,7 +790,7 @@ static tsi_result populate_ssl_context( result = ssl_ctx_use_certificate_chain(context, key_cert_pair->cert_chain, strlen(key_cert_pair->cert_chain)); if (result != TSI_OK) { - gpr_log(GPR_ERROR, "Invalid cert chain file."); + LOG(ERROR) << "Invalid cert chain file."; return result; } } @@ -798,21 +798,21 @@ static tsi_result populate_ssl_context( result = ssl_ctx_use_private_key(context, key_cert_pair->private_key, strlen(key_cert_pair->private_key)); if (result != TSI_OK || !SSL_CTX_check_private_key(context)) { - gpr_log(GPR_ERROR, "Invalid private key."); + LOG(ERROR) << "Invalid private key."; return result != TSI_OK ? result : TSI_INVALID_ARGUMENT; } } } if ((cipher_list != nullptr) && !SSL_CTX_set_cipher_list(context, cipher_list)) { - gpr_log(GPR_ERROR, "Invalid cipher list: %s.", cipher_list); + LOG(ERROR) << "Invalid cipher list: " << cipher_list; return TSI_INVALID_ARGUMENT; } { #if OPENSSL_VERSION_NUMBER < 0x30000000L EC_KEY* ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); if (!SSL_CTX_set_tmp_ecdh(context, ecdh)) { - gpr_log(GPR_ERROR, "Could not set ephemeral ECDH key."); + LOG(ERROR) << "Could not set ephemeral ECDH key."; EC_KEY_free(ecdh); return TSI_INTERNAL_ERROR; } @@ -820,7 +820,7 @@ static tsi_result populate_ssl_context( EC_KEY_free(ecdh); #else if (!SSL_CTX_set1_groups(context, kSslEcCurveNames, 1)) { - gpr_log(GPR_ERROR, "Could not set ephemeral ECDH key."); + LOG(ERROR) << "Could not set ephemeral ECDH key."; return TSI_INTERNAL_ERROR; } SSL_CTX_set_options(context, SSL_OP_SINGLE_ECDH_USE); @@ -840,7 +840,7 @@ tsi_result tsi_ssl_extract_x509_subject_names_from_pem_cert( cert = PEM_read_bio_X509(pem, nullptr, nullptr, const_cast("")); if (cert == nullptr) { - gpr_log(GPR_ERROR, "Invalid certificate"); + LOG(ERROR) << "Invalid certificate"; result = TSI_INVALID_ARGUMENT; } else { result = peer_from_x509(cert, 0, peer); @@ -863,8 +863,7 @@ static tsi_result build_alpn_protocol_name_list( size_t length = alpn_protocols[i] == nullptr ? 0 : strlen(alpn_protocols[i]); if (length == 0 || length > 255) { - gpr_log(GPR_ERROR, "Invalid protocol name length: %d.", - static_cast(length)); + LOG(ERROR) << "Invalid protocol name length: " << length; return TSI_INVALID_ARGUMENT; } *protocol_name_list_length += length + 1; @@ -893,13 +892,12 @@ static tsi_result build_alpn_protocol_name_list( static int verify_cb(int ok, X509_STORE_CTX* ctx) { int cert_error = X509_STORE_CTX_get_error(ctx); if (cert_error == X509_V_ERR_UNABLE_TO_GET_CRL) { - gpr_log(GPR_INFO, - "Certificate verification failed to find relevant CRL file. " - "Ignoring error."); + LOG(INFO) << "Certificate verification failed to find relevant CRL file. " + "Ignoring error."; return 1; } if (cert_error != 0) { - gpr_log(GPR_ERROR, "Certificate verify failed with code %d", cert_error); + LOG(ERROR) << "Certificate verify failed with code " << cert_error; } return ok; } @@ -943,8 +941,8 @@ static int RootCertExtractCallback(X509_STORE_CTX* ctx, void* /*arg*/) { if (ssl_index < 0) { char err_str[256]; ERR_error_string_n(ERR_get_error(), err_str, sizeof(err_str)); - gpr_log(GPR_ERROR, - "error getting the SSL index from the X509_STORE_CTX: %s", err_str); + LOG(ERROR) << "error getting the SSL index from the X509_STORE_CTX: " + << err_str; return ret; } SSL* ssl = static_cast(X509_STORE_CTX_get_ex_data(ctx, ssl_index)); @@ -962,7 +960,7 @@ static int RootCertExtractCallback(X509_STORE_CTX* ctx, void* /*arg*/) { int success = SSL_set_ex_data(ssl, g_ssl_ex_verified_root_cert_index, root_cert); if (success == 0) { - gpr_log(GPR_INFO, "Could not set verified root cert in SSL's ex_data"); + LOG(INFO) << "Could not set verified root cert in SSL's ex_data"; } else { #if OPENSSL_VERSION_NUMBER >= 0x10100000L X509_up_ref(root_cert); @@ -988,8 +986,7 @@ static grpc_core::experimental::CrlProvider* GetCrlProvider( } SSL* ssl = static_cast(X509_STORE_CTX_get_ex_data(ctx, ssl_index)); if (ssl == nullptr) { - gpr_log(GPR_INFO, - "error while fetching from CrlProvider. SSL object is null"); + LOG(INFO) << "error while fetching from CrlProvider. SSL object is null"; return nullptr; } SSL_CTX* ssl_ctx = SSL_get_SSL_CTX(ssl); @@ -1007,13 +1004,13 @@ static absl::StatusOr GetCrlFromProvider( } absl::StatusOr issuer_name = grpc_core::IssuerFromCert(cert); if (!issuer_name.ok()) { - gpr_log(GPR_INFO, "Could not get certificate issuer name"); + LOG(INFO) << "Could not get certificate issuer name"; return absl::InvalidArgumentError(issuer_name.status().message()); } absl::StatusOr akid = grpc_core::AkidFromCertificate(cert); std::string akid_to_use; if (!akid.ok()) { - gpr_log(GPR_INFO, "Could not get certificate authority key identifier."); + LOG(INFO) << "Could not get certificate authority key identifier."; } else { akid_to_use = *akid; } @@ -1046,12 +1043,12 @@ static bool ValidateCrl(X509* cert, X509* issuer, X509_CRL* crl) { // 6.3.3b verify issuer and scope valid = grpc_core::VerifyCrlCertIssuerNamesMatch(crl, cert); if (!valid) { - gpr_log(GPR_DEBUG, "CRL and cert issuer names mismatched."); + VLOG(2) << "CRL and cert issuer names mismatched."; return valid; } valid = grpc_core::HasCrlSignBit(issuer); if (!valid) { - gpr_log(GPR_DEBUG, "CRL issuer not allowed to sign CRLs."); + VLOG(2) << "CRL issuer not allowed to sign CRLs."; return valid; } // 6.3.3c Not supporting deltas @@ -1062,7 +1059,7 @@ static bool ValidateCrl(X509* cert, X509* issuer, X509_CRL* crl) { // 6.3.3g Verify CRL Signature valid = grpc_core::VerifyCrlSignature(crl, issuer); if (!valid) { - gpr_log(GPR_DEBUG, "Crl signature check failed."); + VLOG(2) << "Crl signature check failed."; } return valid; } @@ -1152,7 +1149,7 @@ static int CheckChainRevocation( static int CustomVerificationFunction(X509_STORE_CTX* ctx, void* arg) { int ret = X509_verify_cert(ctx); if (ret <= 0) { - gpr_log(GPR_DEBUG, "Failed to verify cert chain."); + VLOG(2) << "Failed to verify cert chain."; // Verification failed. We shouldn't expect to have a verified chain, so // there is no need to attempt to extract the root cert from it, check for // revocation, or check anything else. @@ -1162,7 +1159,7 @@ static int CustomVerificationFunction(X509_STORE_CTX* ctx, void* arg) { if (provider != nullptr) { ret = CheckChainRevocation(ctx, provider); if (ret <= 0) { - gpr_log(GPR_DEBUG, "The chain failed revocation checks."); + VLOG(2) << "The chain failed revocation checks."; return ret; } } @@ -1176,8 +1173,8 @@ static tsi_result tsi_set_min_and_max_tls_versions( SSL_CTX* ssl_context, tsi_tls_version min_tls_version, tsi_tls_version max_tls_version) { if (ssl_context == nullptr) { - gpr_log(GPR_INFO, - "Invalid nullptr argument to |tsi_set_min_and_max_tls_versions|."); + LOG(INFO) << "Invalid nullptr argument to " + "|tsi_set_min_and_max_tls_versions|."; return TSI_INVALID_ARGUMENT; } #if OPENSSL_VERSION_NUMBER >= 0x10100000 @@ -1198,7 +1195,7 @@ static tsi_result tsi_set_min_and_max_tls_versions( break; #endif default: - gpr_log(GPR_INFO, "TLS version is not supported."); + LOG(INFO) << "TLS version is not supported."; return TSI_FAILED_PRECONDITION; } @@ -1217,7 +1214,7 @@ static tsi_result tsi_set_min_and_max_tls_versions( #endif break; default: - gpr_log(GPR_INFO, "TLS version is not supported."); + LOG(INFO) << "TLS version is not supported."; return TSI_FAILED_PRECONDITION; } #endif @@ -1229,25 +1226,25 @@ static tsi_result tsi_set_min_and_max_tls_versions( tsi_ssl_root_certs_store* tsi_ssl_root_certs_store_create( const char* pem_roots) { if (pem_roots == nullptr) { - gpr_log(GPR_ERROR, "The root certificates are empty."); + LOG(ERROR) << "The root certificates are empty."; return nullptr; } tsi_ssl_root_certs_store* root_store = static_cast( gpr_zalloc(sizeof(tsi_ssl_root_certs_store))); if (root_store == nullptr) { - gpr_log(GPR_ERROR, "Could not allocate buffer for ssl_root_certs_store."); + LOG(ERROR) << "Could not allocate buffer for ssl_root_certs_store."; return nullptr; } root_store->store = X509_STORE_new(); if (root_store->store == nullptr) { - gpr_log(GPR_ERROR, "Could not allocate buffer for X509_STORE."); + LOG(ERROR) << "Could not allocate buffer for X509_STORE."; gpr_free(root_store); return nullptr; } tsi_result result = x509_store_load_certs(root_store->store, pem_roots, strlen(pem_roots), nullptr); if (result != TSI_OK) { - gpr_log(GPR_ERROR, "Could not load root certificates."); + LOG(ERROR) << "Could not load root certificates."; X509_STORE_free(root_store->store); gpr_free(root_store); return nullptr; @@ -1477,9 +1474,8 @@ static tsi_result ssl_handshaker_result_extract_peer( result = peer_property_from_x509_subject( verified_root_cert, &peer->properties[peer->property_count], true); if (result != TSI_OK) { - gpr_log(GPR_DEBUG, - "Problem extracting subject from verified_root_cert. result: %d", - static_cast(result)); + VLOG(2) << "Problem extracting subject from verified_root_cert. result: " + << result; } peer->property_count++; } @@ -1676,7 +1672,7 @@ static tsi_result ssl_handshaker_process_bytes_from_peer( bytes_written_into_ssl_size = BIO_write(impl->network_io, bytes, static_cast(*bytes_size)); if (bytes_written_into_ssl_size < 0) { - gpr_log(GPR_ERROR, "Could not write to memory BIO."); + LOG(ERROR) << "Could not write to memory BIO."; if (error != nullptr) *error = "could not write to memory BIO"; impl->result = TSI_INTERNAL_ERROR; return impl->result; @@ -1823,7 +1819,7 @@ static tsi_result ssl_handshaker_next(tsi_handshaker* self, ssl_bytes_remaining(impl, &unused_bytes, &unused_bytes_size, error); if (status != TSI_OK) return status; if (unused_bytes_size > received_bytes_size) { - gpr_log(GPR_ERROR, "More unused bytes than received bytes."); + LOG(ERROR) << "More unused bytes than received bytes."; gpr_free(unused_bytes); if (error != nullptr) *error = "More unused bytes than received bytes."; return TSI_INTERNAL_ERROR; @@ -1877,7 +1873,7 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client, tsi_ssl_handshaker* impl = nullptr; *handshaker = nullptr; if (ctx == nullptr) { - gpr_log(GPR_ERROR, "SSL Context is null. Should never happen."); + LOG(ERROR) << "SSL Context is null. Should never happen."; return TSI_INTERNAL_ERROR; } if (ssl == nullptr) { @@ -1887,7 +1883,7 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client, if (!BIO_new_bio_pair(&network_io, network_bio_buf_size, &ssl_io, ssl_bio_buf_size)) { - gpr_log(GPR_ERROR, "BIO_new_bio_pair failed."); + LOG(ERROR) << "BIO_new_bio_pair failed."; SSL_free(ssl); return TSI_OUT_OF_RESOURCES; } @@ -2076,7 +2072,7 @@ static int does_entry_match_name(absl::string_view entry, // Wildchar subdomain matching. if (entry.size() < 3 || entry[1] != '.') { // At least *.x - gpr_log(GPR_ERROR, "Invalid wildchar entry."); + LOG(ERROR) << "Invalid wildchar entry."; return 0; } size_t name_subdomain_pos = name.find('.'); @@ -2087,8 +2083,7 @@ static int does_entry_match_name(absl::string_view entry, entry.remove_prefix(2); // Remove *. size_t dot = name_subdomain.find('.'); if (dot == absl::string_view::npos || dot == name_subdomain.size() - 1) { - gpr_log(GPR_ERROR, "Invalid toplevel subdomain: %s", - std::string(name_subdomain).c_str()); + LOG(ERROR) << "Invalid toplevel subdomain: " << name_subdomain; return 0; } if (name_subdomain.back() == '.') { @@ -2115,7 +2110,7 @@ static int ssl_server_handshaker_factory_servername_callback(SSL* ssl, return SSL_TLSEXT_ERR_OK; } } - gpr_log(GPR_ERROR, "No match found for server name: %s.", servername); + LOG(ERROR) << "No match found for server name: " << servername; return SSL_TLSEXT_ERR_NOACK; } @@ -2222,7 +2217,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options( #endif if (ssl_context == nullptr) { grpc_core::LogSslErrorStack(); - gpr_log(GPR_ERROR, "Could not create ssl context."); + LOG(ERROR) << "Could not create ssl context."; return TSI_INVALID_ARGUMENT; } @@ -2289,7 +2284,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options( X509_VERIFY_PARAM_set_depth(param, kMaxChainLength); if (result != TSI_OK) { - gpr_log(GPR_ERROR, "Cannot load server root certificates."); + LOG(ERROR) << "Cannot load server root certificates."; break; } } @@ -2299,8 +2294,8 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options( options->alpn_protocols, options->num_alpn_protocols, &impl->alpn_protocol_list, &impl->alpn_protocol_list_length); if (result != TSI_OK) { - gpr_log(GPR_ERROR, "Building alpn list failed with error %s.", - tsi_result_to_string(result)); + LOG(ERROR) << "Building alpn list failed with error " + << tsi_result_to_string(result); break; } #if TSI_OPENSSL_ALPN_SUPPORT @@ -2308,7 +2303,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options( if (SSL_CTX_set_alpn_protos( ssl_context, impl->alpn_protocol_list, static_cast(impl->alpn_protocol_list_length))) { - gpr_log(GPR_ERROR, "Could not set alpn protocol list to context."); + LOG(ERROR) << "Could not set alpn protocol list to context."; result = TSI_INVALID_ARGUMENT; break; } @@ -2338,7 +2333,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options( X509_STORE_set_verify_cb(cert_store, verify_cb); if (!X509_STORE_load_locations(cert_store, nullptr, options->crl_directory)) { - gpr_log(GPR_ERROR, "Failed to load CRL File from directory."); + LOG(ERROR) << "Failed to load CRL File from directory."; } else { X509_VERIFY_PARAM* param = X509_STORE_get0_param(cert_store); X509_VERIFY_PARAM_set_flags( @@ -2443,7 +2438,7 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options( #endif if (impl->ssl_contexts[i] == nullptr) { grpc_core::LogSslErrorStack(); - gpr_log(GPR_ERROR, "Could not create ssl context."); + LOG(ERROR) << "Could not create ssl context."; result = TSI_OUT_OF_RESOURCES; break; } @@ -2465,7 +2460,7 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options( impl->ssl_contexts[i], kSslSessionIdContext, GPR_ARRAY_SIZE(kSslSessionIdContext)); if (set_sid_ctx_result == 0) { - gpr_log(GPR_ERROR, "Failed to set session id context."); + LOG(ERROR) << "Failed to set session id context."; result = TSI_INTERNAL_ERROR; break; } @@ -2475,7 +2470,7 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options( impl->ssl_contexts[i], const_cast(options->session_ticket_key), options->session_ticket_key_size) == 0) { - gpr_log(GPR_ERROR, "Invalid STEK size."); + LOG(ERROR) << "Invalid STEK size."; result = TSI_INVALID_ARGUMENT; break; } @@ -2488,7 +2483,7 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options( strlen(options->pem_client_root_certs), options->send_client_ca_list ? &root_names : nullptr); if (result != TSI_OK) { - gpr_log(GPR_ERROR, "Invalid verification certs."); + LOG(ERROR) << "Invalid verification certs."; break; } if (options->send_client_ca_list) { @@ -2536,7 +2531,7 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options( X509_STORE_set_verify_cb(cert_store, verify_cb); if (!X509_STORE_load_locations(cert_store, nullptr, options->crl_directory)) { - gpr_log(GPR_ERROR, "Failed to load CRL File from directory."); + LOG(ERROR) << "Failed to load CRL File from directory."; } else { X509_VERIFY_PARAM* param = X509_STORE_get0_param(cert_store); X509_VERIFY_PARAM_set_flags( diff --git a/src/core/tsi/ssl_transport_security_utils.cc b/src/core/tsi/ssl_transport_security_utils.cc index 2476d68c253..18404627691 100644 --- a/src/core/tsi/ssl_transport_security_utils.cc +++ b/src/core/tsi/ssl_transport_security_utils.cc @@ -30,6 +30,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -69,7 +70,7 @@ void LogSslErrorStack(void) { while ((err = ERR_get_error()) != 0) { char details[256]; ERR_error_string_n(static_cast(err), details, sizeof(details)); - gpr_log(GPR_ERROR, "%s", details); + LOG(ERROR) << details; } } @@ -82,12 +83,12 @@ tsi_result DoSslWrite(SSL* ssl, unsigned char* unprotected_bytes, if (ssl_write_result < 0) { ssl_write_result = SSL_get_error(ssl, ssl_write_result); if (ssl_write_result == SSL_ERROR_WANT_READ) { - gpr_log(GPR_ERROR, - "Peer tried to renegotiate SSL connection. This is unsupported."); + LOG(ERROR) + << "Peer tried to renegotiate SSL connection. This is unsupported."; return TSI_UNIMPLEMENTED; } else { - gpr_log(GPR_ERROR, "SSL_write failed with error %s.", - SslErrorString(ssl_write_result)); + LOG(ERROR) << "SSL_write failed with error " + << SslErrorString(ssl_write_result); return TSI_INTERNAL_ERROR; } } @@ -113,12 +114,12 @@ tsi_result DoSslRead(SSL* ssl, unsigned char* unprotected_bytes, "Peer tried to renegotiate SSL connection. This is unsupported."); return TSI_UNIMPLEMENTED; case SSL_ERROR_SSL: - gpr_log(GPR_ERROR, "Corruption detected."); + LOG(ERROR) << "Corruption detected."; LogSslErrorStack(); return TSI_DATA_CORRUPTED; default: - gpr_log(GPR_ERROR, "SSL_read failed with error %s.", - SslErrorString(read_from_ssl)); + LOG(ERROR) << "SSL_read failed with error " + << SslErrorString(read_from_ssl); return TSI_PROTOCOL_FAILURE; } } @@ -145,8 +146,7 @@ tsi_result SslProtectorProtect(const unsigned char* unprotected_bytes, read_from_ssl = BIO_read(network_io, protected_output_frames, static_cast(*protected_output_frames_size)); if (read_from_ssl < 0) { - gpr_log(GPR_ERROR, - "Could not read from BIO even though some data is pending"); + LOG(ERROR) << "Could not read from BIO even though some data is pending"; return TSI_INTERNAL_ERROR; } *protected_output_frames_size = static_cast(read_from_ssl); @@ -172,7 +172,7 @@ tsi_result SslProtectorProtect(const unsigned char* unprotected_bytes, read_from_ssl = BIO_read(network_io, protected_output_frames, static_cast(*protected_output_frames_size)); if (read_from_ssl < 0) { - gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); + LOG(ERROR) << "Could not read from BIO after SSL_write."; return TSI_INTERNAL_ERROR; } *protected_output_frames_size = static_cast(read_from_ssl); @@ -206,7 +206,7 @@ tsi_result SslProtectorProtectFlush(size_t& buffer_offset, read_from_ssl = BIO_read(network_io, protected_output_frames, static_cast(*protected_output_frames_size)); if (read_from_ssl <= 0) { - gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); + LOG(ERROR) << "Could not read from BIO after SSL_write."; return TSI_INTERNAL_ERROR; } *protected_output_frames_size = static_cast(read_from_ssl); @@ -243,8 +243,8 @@ tsi_result SslProtectorUnprotect(const unsigned char* protected_frames_bytes, written_into_ssl = BIO_write(network_io, protected_frames_bytes, static_cast(*protected_frames_bytes_size)); if (written_into_ssl < 0) { - gpr_log(GPR_ERROR, "Sending protected frame to ssl failed with %d", - written_into_ssl); + LOG(ERROR) << "Sending protected frame to ssl failed with " + << written_into_ssl; return TSI_INTERNAL_ERROR; } *protected_frames_bytes_size = static_cast(written_into_ssl); @@ -266,16 +266,15 @@ bool VerifyCrlSignature(X509_CRL* crl, X509* issuer) { if (ikey == nullptr) { // Can't verify signature because we couldn't get the pubkey, fail the // check. - gpr_log(GPR_DEBUG, "Could not public key from certificate."); + VLOG(2) << "Could not public key from certificate."; EVP_PKEY_free(ikey); return false; } int ret = X509_CRL_verify(crl, ikey); if (ret < 0) { - gpr_log(GPR_DEBUG, - "There was an unexpected problem checking the CRL signature."); + VLOG(2) << "There was an unexpected problem checking the CRL signature."; } else if (ret == 0) { - gpr_log(GPR_DEBUG, "CRL failed verification."); + VLOG(2) << "CRL failed verification."; } EVP_PKEY_free(ikey); return ret == 1; diff --git a/src/core/lib/gpr/.clang-format b/src/core/util/.clang-format similarity index 100% rename from src/core/lib/gpr/.clang-format rename to src/core/util/.clang-format diff --git a/src/core/lib/gpr/README.md b/src/core/util/README.md similarity index 100% rename from src/core/lib/gpr/README.md rename to src/core/util/README.md diff --git a/src/core/lib/gpr/alloc.cc b/src/core/util/alloc.cc similarity index 100% rename from src/core/lib/gpr/alloc.cc rename to src/core/util/alloc.cc diff --git a/src/core/lib/gpr/alloc.h b/src/core/util/alloc.h similarity index 87% rename from src/core/lib/gpr/alloc.h rename to src/core/util/alloc.h index de2e5697385..a369feb3ddd 100644 --- a/src/core/lib/gpr/alloc.h +++ b/src/core/util/alloc.h @@ -16,8 +16,8 @@ // // -#ifndef GRPC_SRC_CORE_LIB_GPR_ALLOC_H -#define GRPC_SRC_CORE_LIB_GPR_ALLOC_H +#ifndef GRPC_SRC_CORE_UTIL_ALLOC_H +#define GRPC_SRC_CORE_UTIL_ALLOC_H #include @@ -25,4 +25,4 @@ #define GPR_ROUND_UP_TO_ALIGNMENT_SIZE(x) \ (((x) + GPR_MAX_ALIGNMENT - 1u) & ~(GPR_MAX_ALIGNMENT - 1u)) -#endif // GRPC_SRC_CORE_LIB_GPR_ALLOC_H +#endif // GRPC_SRC_CORE_UTIL_ALLOC_H diff --git a/src/core/lib/gpr/android/log.cc b/src/core/util/android/log.cc similarity index 76% rename from src/core/lib/gpr/android/log.cc rename to src/core/util/android/log.cc index 34c705b8764..c368f3aa324 100644 --- a/src/core/lib/gpr/android/log.cc +++ b/src/core/util/android/log.cc @@ -57,23 +57,4 @@ void gpr_log(const char* file, int line, gpr_log_severity severity, free(message); } -void gpr_platform_log(gpr_log_func_args* args) { - const char* final_slash; - const char* display_file; - char* output = NULL; - - final_slash = strrchr(args->file, '/'); - if (final_slash == NULL) - display_file = args->file; - else - display_file = final_slash + 1; - - asprintf(&output, "%s:%d] %s", display_file, args->line, args->message); - - __android_log_write(severity_to_log_priority(args->severity), "GRPC", output); - - // allocated by asprintf => use free, not gpr_free - free(output); -} - #endif // GPR_ANDROID diff --git a/src/core/lib/gpr/atm.cc b/src/core/util/atm.cc similarity index 96% rename from src/core/lib/gpr/atm.cc rename to src/core/util/atm.cc index 73173539818..7e7a6834bb1 100644 --- a/src/core/lib/gpr/atm.cc +++ b/src/core/util/atm.cc @@ -20,7 +20,7 @@ #include -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" gpr_atm gpr_atm_no_barrier_clamped_add(gpr_atm* value, gpr_atm delta, gpr_atm min, gpr_atm max) { diff --git a/src/core/lib/gpr/iphone/cpu.cc b/src/core/util/iphone/cpu.cc similarity index 100% rename from src/core/lib/gpr/iphone/cpu.cc rename to src/core/util/iphone/cpu.cc diff --git a/src/core/lib/gpr/linux/cpu.cc b/src/core/util/linux/cpu.cc similarity index 100% rename from src/core/lib/gpr/linux/cpu.cc rename to src/core/util/linux/cpu.cc diff --git a/src/core/lib/gpr/linux/log.cc b/src/core/util/linux/log.cc similarity index 55% rename from src/core/lib/gpr/linux/log.cc rename to src/core/util/linux/log.cc index a24e28fa82c..f09ecb2dbbc 100644 --- a/src/core/lib/gpr/linux/log.cc +++ b/src/core/util/linux/log.cc @@ -47,10 +47,6 @@ #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/examine_stack.h" -int gpr_should_log_stacktrace(gpr_log_severity severity); - -static long sys_gettid(void) { return syscall(__NR_gettid); } - void gpr_log(const char* file, int line, gpr_log_severity severity, const char* format, ...) { // Avoid message construction if gpr_log_message won't log @@ -70,45 +66,4 @@ void gpr_log(const char* file, int line, gpr_log_severity severity, free(message); } -void gpr_platform_log(gpr_log_func_args* args) { - const char* final_slash; - const char* display_file; - char time_buffer[64]; - time_t timer; - gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); - struct tm tm; - static thread_local long tid(0); - if (tid == 0) tid = sys_gettid(); - - timer = static_cast(now.tv_sec); - final_slash = strrchr(args->file, '/'); - if (final_slash == nullptr) { - display_file = args->file; - } else { - display_file = final_slash + 1; - } - - if (!localtime_r(&timer, &tm)) { - strcpy(time_buffer, "error:localtime"); - } else if (0 == - strftime(time_buffer, sizeof(time_buffer), "%m%d %H:%M:%S", &tm)) { - strcpy(time_buffer, "error:strftime"); - } - - std::string prefix = absl::StrFormat( - "%s%s.%09" PRId32 " %7ld %s:%d]", gpr_log_severity_string(args->severity), - time_buffer, now.tv_nsec, tid, display_file, args->line); - - absl::optional stack_trace = - gpr_should_log_stacktrace(args->severity) - ? grpc_core::GetCurrentStackTrace() - : absl::nullopt; - if (stack_trace) { - fprintf(stderr, "%-70s %s\n%s\n", prefix.c_str(), args->message, - stack_trace->c_str()); - } else { - fprintf(stderr, "%-70s %s\n", prefix.c_str(), args->message); - } -} - #endif // GPR_LINUX_LOG diff --git a/src/core/lib/gpr/log.cc b/src/core/util/log.cc similarity index 93% rename from src/core/lib/gpr/log.cc rename to src/core/util/log.cc index 1755d99122d..9a6f68104e0 100644 --- a/src/core/lib/gpr/log.cc +++ b/src/core/util/log.cc @@ -31,8 +31,8 @@ #include #include "src/core/lib/config/config_vars.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" +#include "src/core/util/string.h" #ifndef GPR_DEFAULT_LOG_VERBOSITY_STRING #define GPR_DEFAULT_LOG_VERBOSITY_STRING "ERROR" @@ -77,10 +77,6 @@ int gpr_should_log(gpr_log_severity severity) { } void gpr_default_log(gpr_log_func_args* args) { - if (!grpc_core::ConfigVars::Get().AbslLogging()) { - gpr_platform_log(args); - return; - } switch (args->severity) { case GPR_LOG_SEVERITY_DEBUG: // Log DEBUG messages as VLOG(2). @@ -99,13 +95,6 @@ void gpr_default_log(gpr_log_func_args* args) { } } -int gpr_should_log_stacktrace(gpr_log_severity severity) { - return static_cast(severity) >= - gpr_atm_no_barrier_load(&g_min_severity_to_print_stacktrace) - ? 1 - : 0; -} - void gpr_log_message(const char* file, int line, gpr_log_severity severity, const char* message) { if (gpr_should_log(severity) == 0) { diff --git a/src/core/lib/gpr/msys/tmpfile.cc b/src/core/util/msys/tmpfile.cc similarity index 94% rename from src/core/lib/gpr/msys/tmpfile.cc rename to src/core/util/msys/tmpfile.cc index 42372a5ce65..41a04f1c75d 100644 --- a/src/core/lib/gpr/msys/tmpfile.cc +++ b/src/core/util/msys/tmpfile.cc @@ -29,9 +29,9 @@ #include #include -#include "src/core/lib/gpr/string_windows.h" -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/crash.h" +#include "src/core/util/string_windows.h" +#include "src/core/util/tmpfile.h" FILE* gpr_tmpfile(const char* prefix, char** tmp_filename_out) { FILE* result = NULL; diff --git a/src/core/lib/gpr/posix/cpu.cc b/src/core/util/posix/cpu.cc similarity index 98% rename from src/core/lib/gpr/posix/cpu.cc rename to src/core/util/posix/cpu.cc index 4b58d869f68..9d7c638aa12 100644 --- a/src/core/lib/gpr/posix/cpu.cc +++ b/src/core/util/posix/cpu.cc @@ -29,8 +29,8 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" +#include "src/core/util/useful.h" static long ncpus = 0; diff --git a/src/core/lib/gpr/posix/log.cc b/src/core/util/posix/log.cc similarity index 58% rename from src/core/lib/gpr/posix/log.cc rename to src/core/util/posix/log.cc index 4e933b7c4be..09791014ef8 100644 --- a/src/core/lib/gpr/posix/log.cc +++ b/src/core/util/posix/log.cc @@ -38,10 +38,6 @@ #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/examine_stack.h" -int gpr_should_log_stacktrace(gpr_log_severity severity); - -static intptr_t sys_gettid(void) { return (intptr_t)pthread_self(); } - void gpr_log(const char* file, int line, gpr_log_severity severity, const char* format, ...) { // Avoid message construction if gpr_log_message won't log @@ -70,42 +66,4 @@ void gpr_log(const char* file, int line, gpr_log_severity severity, gpr_free(allocated); } -void gpr_platform_log(gpr_log_func_args* args) { - const char* final_slash; - const char* display_file; - char time_buffer[64]; - time_t timer; - gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); - struct tm tm; - - timer = (time_t)now.tv_sec; - final_slash = strrchr(args->file, '/'); - if (final_slash == nullptr) - display_file = args->file; - else - display_file = final_slash + 1; - - if (!localtime_r(&timer, &tm)) { - strcpy(time_buffer, "error:localtime"); - } else if (0 == - strftime(time_buffer, sizeof(time_buffer), "%m%d %H:%M:%S", &tm)) { - strcpy(time_buffer, "error:strftime"); - } - - std::string prefix = absl::StrFormat( - "%s%s.%09d %7" PRIdPTR " %s:%d]", gpr_log_severity_string(args->severity), - time_buffer, (int)(now.tv_nsec), sys_gettid(), display_file, args->line); - - absl::optional stack_trace = - gpr_should_log_stacktrace(args->severity) - ? grpc_core::GetCurrentStackTrace() - : absl::nullopt; - if (stack_trace) { - fprintf(stderr, "%-70s %s\n%s\n", prefix.c_str(), args->message, - stack_trace->c_str()); - } else { - fprintf(stderr, "%-70s %s\n", prefix.c_str(), args->message); - } -} - #endif // defined(GPR_POSIX_LOG) diff --git a/src/core/lib/gpr/posix/string.cc b/src/core/util/posix/string.cc similarity index 100% rename from src/core/lib/gpr/posix/string.cc rename to src/core/util/posix/string.cc diff --git a/src/core/lib/gpr/posix/sync.cc b/src/core/util/posix/sync.cc similarity index 100% rename from src/core/lib/gpr/posix/sync.cc rename to src/core/util/posix/sync.cc diff --git a/src/core/lib/gpr/posix/time.cc b/src/core/util/posix/time.cc similarity index 98% rename from src/core/lib/gpr/posix/time.cc rename to src/core/util/posix/time.cc index f292198fede..6624b0fd656 100644 --- a/src/core/lib/gpr/posix/time.cc +++ b/src/core/util/posix/time.cc @@ -18,7 +18,7 @@ #include -#include "src/core/lib/gpr/time_precise.h" +#include "src/core/util/time_precise.h" #ifdef GPR_POSIX_TIME diff --git a/src/core/lib/gpr/posix/tmpfile.cc b/src/core/util/posix/tmpfile.cc similarity index 96% rename from src/core/lib/gpr/posix/tmpfile.cc rename to src/core/util/posix/tmpfile.cc index cbc2b4cf3d8..dbf399dba63 100644 --- a/src/core/lib/gpr/posix/tmpfile.cc +++ b/src/core/util/posix/tmpfile.cc @@ -31,10 +31,10 @@ #include #include -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/strerror.h" +#include "src/core/util/string.h" +#include "src/core/util/tmpfile.h" FILE* gpr_tmpfile(const char* prefix, char** tmp_filename) { FILE* result = nullptr; diff --git a/src/core/lib/gpr/spinlock.h b/src/core/util/spinlock.h similarity index 93% rename from src/core/lib/gpr/spinlock.h rename to src/core/util/spinlock.h index 085ec8b37b1..b46db8e2a6f 100644 --- a/src/core/lib/gpr/spinlock.h +++ b/src/core/util/spinlock.h @@ -16,8 +16,8 @@ // // -#ifndef GRPC_SRC_CORE_LIB_GPR_SPINLOCK_H -#define GRPC_SRC_CORE_LIB_GPR_SPINLOCK_H +#ifndef GRPC_SRC_CORE_UTIL_SPINLOCK_H +#define GRPC_SRC_CORE_UTIL_SPINLOCK_H #include @@ -50,4 +50,4 @@ struct gpr_spinlock { do { \ } while (!gpr_spinlock_trylock((lock))) -#endif // GRPC_SRC_CORE_LIB_GPR_SPINLOCK_H +#endif // GRPC_SRC_CORE_UTIL_SPINLOCK_H diff --git a/src/core/lib/gpr/string.cc b/src/core/util/string.cc similarity index 99% rename from src/core/lib/gpr/string.cc rename to src/core/util/string.cc index 4d23c89c78b..7efbd09f51f 100644 --- a/src/core/lib/gpr/string.cc +++ b/src/core/util/string.cc @@ -18,7 +18,7 @@ #include -#include "src/core/lib/gpr/string.h" +#include "src/core/util/string.h" #include #include @@ -34,8 +34,8 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" +#include "src/core/util/useful.h" char* gpr_strdup(const char* src) { char* dst; diff --git a/src/core/lib/gpr/string.h b/src/core/util/string.h similarity index 97% rename from src/core/lib/gpr/string.h rename to src/core/util/string.h index 7f4fae9df30..66f3d0f8344 100644 --- a/src/core/lib/gpr/string.h +++ b/src/core/util/string.h @@ -16,8 +16,8 @@ // // -#ifndef GRPC_SRC_CORE_LIB_GPR_STRING_H -#define GRPC_SRC_CORE_LIB_GPR_STRING_H +#ifndef GRPC_SRC_CORE_UTIL_STRING_H +#define GRPC_SRC_CORE_UTIL_STRING_H #include @@ -109,4 +109,4 @@ void* gpr_memrchr(const void* s, int c, size_t n); // Otherwise, it returns false. bool gpr_parse_bool_value(const char* value, bool* dst); -#endif // GRPC_SRC_CORE_LIB_GPR_STRING_H +#endif // GRPC_SRC_CORE_UTIL_STRING_H diff --git a/src/core/lib/gpr/subprocess.h b/src/core/util/subprocess.h similarity index 92% rename from src/core/lib/gpr/subprocess.h rename to src/core/util/subprocess.h index 71d4796fde6..569f10a0309 100644 --- a/src/core/lib/gpr/subprocess.h +++ b/src/core/util/subprocess.h @@ -16,8 +16,8 @@ // // -#ifndef GRPC_SRC_CORE_LIB_GPR_SUBPROCESS_H -#define GRPC_SRC_CORE_LIB_GPR_SUBPROCESS_H +#ifndef GRPC_SRC_CORE_UTIL_SUBPROCESS_H +#define GRPC_SRC_CORE_UTIL_SUBPROCESS_H #include @@ -43,4 +43,4 @@ int gpr_subprocess_join(gpr_subprocess* p); void gpr_subprocess_interrupt(gpr_subprocess* p); int gpr_subprocess_get_process_id(gpr_subprocess* p); -#endif // GRPC_SRC_CORE_LIB_GPR_SUBPROCESS_H +#endif // GRPC_SRC_CORE_UTIL_SUBPROCESS_H diff --git a/src/core/lib/gpr/subprocess_posix.cc b/src/core/util/subprocess_posix.cc similarity index 99% rename from src/core/lib/gpr/subprocess_posix.cc rename to src/core/util/subprocess_posix.cc index 5dc73a3fac5..f7232d38229 100644 --- a/src/core/lib/gpr/subprocess_posix.cc +++ b/src/core/util/subprocess_posix.cc @@ -34,9 +34,9 @@ #include #include -#include "src/core/lib/gpr/subprocess.h" #include "src/core/lib/gprpp/memory.h" #include "src/core/lib/gprpp/strerror.h" +#include "src/core/util/subprocess.h" struct gpr_subprocess { int pid; diff --git a/src/core/lib/gpr/subprocess_windows.cc b/src/core/util/subprocess_windows.cc similarity index 97% rename from src/core/lib/gpr/subprocess_windows.cc rename to src/core/util/subprocess_windows.cc index 3efadd2a9b0..d85b04b8b58 100644 --- a/src/core/lib/gpr/subprocess_windows.cc +++ b/src/core/util/subprocess_windows.cc @@ -30,10 +30,10 @@ #include #include -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/subprocess.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/tchar.h" +#include "src/core/util/string.h" +#include "src/core/util/subprocess.h" struct gpr_subprocess { PROCESS_INFORMATION pi; diff --git a/src/core/lib/gpr/sync.cc b/src/core/util/sync.cc similarity index 100% rename from src/core/lib/gpr/sync.cc rename to src/core/util/sync.cc diff --git a/src/core/lib/gpr/sync_abseil.cc b/src/core/util/sync_abseil.cc similarity index 100% rename from src/core/lib/gpr/sync_abseil.cc rename to src/core/util/sync_abseil.cc diff --git a/src/core/lib/gpr/time.cc b/src/core/util/time.cc similarity index 100% rename from src/core/lib/gpr/time.cc rename to src/core/util/time.cc diff --git a/src/core/lib/gpr/time_precise.cc b/src/core/util/time_precise.cc similarity index 99% rename from src/core/lib/gpr/time_precise.cc rename to src/core/util/time_precise.cc index 46efc61722e..b675777a19e 100644 --- a/src/core/lib/gpr/time_precise.cc +++ b/src/core/util/time_precise.cc @@ -28,8 +28,8 @@ #include #include -#include "src/core/lib/gpr/time_precise.h" #include "src/core/lib/gprpp/crash.h" +#include "src/core/util/time_precise.h" #ifndef GPR_CYCLE_COUNTER_CUSTOM #if GPR_CYCLE_COUNTER_RDTSC_32 || GPR_CYCLE_COUNTER_RDTSC_64 diff --git a/src/core/lib/gpr/time_precise.h b/src/core/util/time_precise.h similarity index 93% rename from src/core/lib/gpr/time_precise.h rename to src/core/util/time_precise.h index 0afb01e84ca..9decb6d4cfd 100644 --- a/src/core/lib/gpr/time_precise.h +++ b/src/core/util/time_precise.h @@ -16,8 +16,8 @@ // // -#ifndef GRPC_SRC_CORE_LIB_GPR_TIME_PRECISE_H -#define GRPC_SRC_CORE_LIB_GPR_TIME_PRECISE_H +#ifndef GRPC_SRC_CORE_UTIL_TIME_PRECISE_H +#define GRPC_SRC_CORE_UTIL_TIME_PRECISE_H #include @@ -66,4 +66,4 @@ void gpr_precise_clock_now(gpr_timespec* clk); gpr_timespec gpr_cycle_counter_to_time(gpr_cycle_counter cycles); gpr_timespec gpr_cycle_counter_sub(gpr_cycle_counter a, gpr_cycle_counter b); -#endif // GRPC_SRC_CORE_LIB_GPR_TIME_PRECISE_H +#endif // GRPC_SRC_CORE_UTIL_TIME_PRECISE_H diff --git a/src/core/lib/gpr/tmpfile.h b/src/core/util/tmpfile.h similarity index 88% rename from src/core/lib/gpr/tmpfile.h rename to src/core/util/tmpfile.h index 54826b03e75..d1ed3d0558c 100644 --- a/src/core/lib/gpr/tmpfile.h +++ b/src/core/util/tmpfile.h @@ -16,8 +16,8 @@ // // -#ifndef GRPC_SRC_CORE_LIB_GPR_TMPFILE_H -#define GRPC_SRC_CORE_LIB_GPR_TMPFILE_H +#ifndef GRPC_SRC_CORE_UTIL_TMPFILE_H +#define GRPC_SRC_CORE_UTIL_TMPFILE_H #include @@ -29,4 +29,4 @@ // unless an error occurs in which case it will be set to NULL. FILE* gpr_tmpfile(const char* prefix, char** tmp_filename); -#endif // GRPC_SRC_CORE_LIB_GPR_TMPFILE_H +#endif // GRPC_SRC_CORE_UTIL_TMPFILE_H diff --git a/src/core/lib/gpr/useful.h b/src/core/util/useful.h similarity index 97% rename from src/core/lib/gpr/useful.h rename to src/core/util/useful.h index b1196d449c4..d3ff937561e 100644 --- a/src/core/lib/gpr/useful.h +++ b/src/core/util/useful.h @@ -16,8 +16,8 @@ // // -#ifndef GRPC_SRC_CORE_LIB_GPR_USEFUL_H -#define GRPC_SRC_CORE_LIB_GPR_USEFUL_H +#ifndef GRPC_SRC_CORE_UTIL_USEFUL_H +#define GRPC_SRC_CORE_UTIL_USEFUL_H #include @@ -181,4 +181,4 @@ inline uint32_t RoundUpToPowerOf2(uint32_t v) { #define GPR_ARRAY_SIZE(array) (sizeof(array) / sizeof(*(array))) -#endif // GRPC_SRC_CORE_LIB_GPR_USEFUL_H +#endif // GRPC_SRC_CORE_UTIL_USEFUL_H diff --git a/src/core/lib/gpr/windows/cpu.cc b/src/core/util/windows/cpu.cc similarity index 100% rename from src/core/lib/gpr/windows/cpu.cc rename to src/core/util/windows/cpu.cc diff --git a/src/core/lib/gpr/windows/log.cc b/src/core/util/windows/log.cc similarity index 57% rename from src/core/lib/gpr/windows/log.cc rename to src/core/util/windows/log.cc index 4dc48698140..722e4bd9a83 100644 --- a/src/core/lib/gpr/windows/log.cc +++ b/src/core/util/windows/log.cc @@ -29,11 +29,9 @@ #include #include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/examine_stack.h" - -int gpr_should_log_stacktrace(gpr_log_severity severity); +#include "src/core/util/string.h" void gpr_log(const char* file, int line, gpr_log_severity severity, const char* format, ...) { @@ -72,45 +70,4 @@ void gpr_log(const char* file, int line, gpr_log_severity severity, gpr_free(message); } -// Simple starter implementation -void gpr_platform_log(gpr_log_func_args* args) { - const char* final_slash; - const char* display_file; - char time_buffer[64]; - time_t timer; - gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); - struct tm tm; - - timer = (time_t)now.tv_sec; - final_slash = strrchr(args->file, '\\'); - if (final_slash == NULL) - display_file = args->file; - else - display_file = final_slash + 1; - - if (localtime_s(&tm, &timer)) { - strcpy(time_buffer, "error:localtime"); - } else if (0 == - strftime(time_buffer, sizeof(time_buffer), "%m%d %H:%M:%S", &tm)) { - strcpy(time_buffer, "error:strftime"); - } - - absl::optional stack_trace = - gpr_should_log_stacktrace(args->severity) - ? grpc_core::GetCurrentStackTrace() - : absl::nullopt; - if (stack_trace) { - fprintf(stderr, "%s%s.%09u %5lu %s:%d] %s\n%s\n", - gpr_log_severity_string(args->severity), time_buffer, - (int)(now.tv_nsec), GetCurrentThreadId(), display_file, args->line, - args->message, stack_trace->c_str()); - } else { - fprintf(stderr, "%s%s.%09u %5lu %s:%d] %s\n", - gpr_log_severity_string(args->severity), time_buffer, - (int)(now.tv_nsec), GetCurrentThreadId(), display_file, args->line, - args->message); - } - fflush(stderr); -} - #endif // GPR_WINDOWS_LOG diff --git a/src/core/lib/gpr/windows/string.cc b/src/core/util/windows/string.cc similarity index 97% rename from src/core/lib/gpr/windows/string.cc rename to src/core/util/windows/string.cc index 603303120b1..c95c4b3fb16 100644 --- a/src/core/lib/gpr/windows/string.cc +++ b/src/core/util/windows/string.cc @@ -29,7 +29,7 @@ #include #include -#include "src/core/lib/gpr/string.h" +#include "src/core/util/string.h" int gpr_asprintf(char** strp, const char* format, ...) { va_list args; diff --git a/src/core/lib/gpr/windows/string_util.cc b/src/core/util/windows/string_util.cc similarity index 97% rename from src/core/lib/gpr/windows/string_util.cc rename to src/core/util/windows/string_util.cc index b56fdd17926..c39152e6037 100644 --- a/src/core/lib/gpr/windows/string_util.cc +++ b/src/core/util/windows/string_util.cc @@ -36,8 +36,8 @@ #include #include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/tchar.h" +#include "src/core/util/string.h" char* gpr_format_message(int messageid) { LPTSTR tmessage; diff --git a/src/core/lib/gpr/windows/sync.cc b/src/core/util/windows/sync.cc similarity index 100% rename from src/core/lib/gpr/windows/sync.cc rename to src/core/util/windows/sync.cc diff --git a/src/core/lib/gpr/windows/time.cc b/src/core/util/windows/time.cc similarity index 98% rename from src/core/lib/gpr/windows/time.cc rename to src/core/util/windows/time.cc index 0aafa4a5959..b80a4a5a14b 100644 --- a/src/core/lib/gpr/windows/time.cc +++ b/src/core/util/windows/time.cc @@ -31,8 +31,8 @@ #include #include -#include "src/core/lib/gpr/time_precise.h" #include "src/core/lib/gprpp/crash.h" +#include "src/core/util/time_precise.h" static LARGE_INTEGER g_start_time = []() { LARGE_INTEGER x; diff --git a/src/core/lib/gpr/windows/tmpfile.cc b/src/core/util/windows/tmpfile.cc similarity index 98% rename from src/core/lib/gpr/windows/tmpfile.cc rename to src/core/util/windows/tmpfile.cc index 37ac4f64bcb..cd3838bc4ee 100644 --- a/src/core/lib/gpr/windows/tmpfile.cc +++ b/src/core/util/windows/tmpfile.cc @@ -29,9 +29,9 @@ #include #include -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/tchar.h" +#include "src/core/util/tmpfile.h" FILE* gpr_tmpfile(const char* prefix, char** tmp_filename_out) { FILE* result = NULL; diff --git a/src/core/xds/grpc/certificate_provider_store.h b/src/core/xds/grpc/certificate_provider_store.h index 3099886f415..ffee3b0efba 100644 --- a/src/core/xds/grpc/certificate_provider_store.h +++ b/src/core/xds/grpc/certificate_provider_store.h @@ -29,7 +29,6 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" @@ -41,6 +40,7 @@ #include "src/core/lib/security/certificate_provider/certificate_provider_factory.h" #include "src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h" #include "src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/xds/grpc/xds_bootstrap_grpc.cc b/src/core/xds/grpc/xds_bootstrap_grpc.cc index ec1f44a3386..e6f97cdbfeb 100644 --- a/src/core/xds/grpc/xds_bootstrap_grpc.cc +++ b/src/core/xds/grpc/xds_bootstrap_grpc.cc @@ -37,7 +37,6 @@ #include #include "src/core/lib/config/core_configuration.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/json/json.h" @@ -45,6 +44,7 @@ #include "src/core/lib/json/json_reader.h" #include "src/core/lib/json/json_writer.h" #include "src/core/lib/security/credentials/channel_creds_registry.h" +#include "src/core/util/string.h" namespace grpc_core { diff --git a/src/core/xds/grpc/xds_certificate_provider.h b/src/core/xds/grpc/xds_certificate_provider.h index 482ff449313..14747d99c14 100644 --- a/src/core/xds/grpc/xds_certificate_provider.h +++ b/src/core/xds/grpc/xds_certificate_provider.h @@ -31,13 +31,13 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/matchers/matchers.h" #include "src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h" #include "src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h" +#include "src/core/util/useful.h" namespace grpc_core { diff --git a/src/core/xds/grpc/xds_client_grpc.cc b/src/core/xds/grpc/xds_client_grpc.cc index 4408f96e2b6..3b00fed06e4 100644 --- a/src/core/xds/grpc/xds_client_grpc.cc +++ b/src/core/xds/grpc/xds_client_grpc.cc @@ -24,6 +24,7 @@ #include #include "absl/base/thread_annotations.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -99,20 +100,20 @@ const auto kMetricResourceUpdatesValid = "EXPERIMENTAL. A counter of resources received that were considered " "valid. The counter will be incremented even for resources that " "have not changed.", - "{resource}", - {kMetricLabelTarget, kMetricLabelXdsServer, - kMetricLabelXdsResourceType}, - {}, false); + "{resource}", false) + .Labels(kMetricLabelTarget, kMetricLabelXdsServer, + kMetricLabelXdsResourceType) + .Build(); const auto kMetricResourceUpdatesInvalid = GlobalInstrumentsRegistry::RegisterUInt64Counter( "grpc.xds_client.resource_updates_invalid", "EXPERIMENTAL. A counter of resources received that were considered " "invalid.", - "{resource}", - {kMetricLabelTarget, kMetricLabelXdsServer, - kMetricLabelXdsResourceType}, - {}, false); + "{resource}", false) + .Labels(kMetricLabelTarget, kMetricLabelXdsServer, + kMetricLabelXdsResourceType) + .Build(); const auto kMetricServerFailure = GlobalInstrumentsRegistry::RegisterUInt64Counter( @@ -121,7 +122,9 @@ const auto kMetricServerFailure = "unhealthy. A server goes unhealthy when we have a connectivity " "failure or when the ADS stream fails without seeing a response " "message, as per gRFC A57.", - "{failure}", {kMetricLabelTarget, kMetricLabelXdsServer}, {}, false); + "{failure}", false) + .Labels(kMetricLabelTarget, kMetricLabelXdsServer) + .Build(); const auto kMetricConnected = GlobalInstrumentsRegistry::RegisterCallbackInt64Gauge( @@ -132,15 +135,17 @@ const auto kMetricConnected = "ADS stream fails without seeing a response message, as per gRFC " "A57. It will be set to 1 when we receive the first response on " "an ADS stream.", - "{bool}", {kMetricLabelTarget, kMetricLabelXdsServer}, {}, false); + "{bool}", false) + .Labels(kMetricLabelTarget, kMetricLabelXdsServer) + .Build(); const auto kMetricResources = GlobalInstrumentsRegistry::RegisterCallbackInt64Gauge( "grpc.xds_client.resources", "EXPERIMENTAL. Number of xDS resources.", - "{resource}", - {kMetricLabelTarget, kMetricLabelXdsAuthority, - kMetricLabelXdsResourceType, kMetricLabelXdsCacheState}, - {}, false); + "{resource}", false) + .Labels(kMetricLabelTarget, kMetricLabelXdsAuthority, + kMetricLabelXdsResourceType, kMetricLabelXdsCacheState) + .Build(); } // namespace @@ -216,7 +221,7 @@ absl::StatusOr GetBootstrapContents(const char* fallback_config) { // Finally, try fallback config. if (fallback_config != nullptr) { if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) { - gpr_log(GPR_INFO, "Got bootstrap contents from fallback config"); + LOG(INFO) << "Got bootstrap contents from fallback config"; } return fallback_config; } @@ -316,7 +321,7 @@ GrpcXdsClient::GrpcXdsClient( [this](CallbackMetricReporter& reporter) { ReportCallbackMetrics(reporter); }, - {kMetricConnected, kMetricResources})) {} + Duration::Seconds(5), kMetricConnected, kMetricResources)) {} void GrpcXdsClient::Orphaned() { registered_metric_callback_.reset(); diff --git a/src/core/xds/grpc/xds_client_grpc.h b/src/core/xds/grpc/xds_client_grpc.h index 0ed5c327e17..9fdb9bccceb 100644 --- a/src/core/xds/grpc/xds_client_grpc.h +++ b/src/core/xds/grpc/xds_client_grpc.h @@ -27,11 +27,11 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/metrics.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/iomgr_fwd.h" #include "src/core/resolver/endpoint_addresses.h" +#include "src/core/util/useful.h" #include "src/core/xds/grpc/certificate_provider_store.h" #include "src/core/xds/grpc/xds_bootstrap_grpc.h" #include "src/core/xds/xds_client/xds_client.h" diff --git a/src/core/xds/grpc/xds_endpoint.cc b/src/core/xds/grpc/xds_endpoint.cc index 78cd9a05613..c689a57d515 100644 --- a/src/core/xds/grpc/xds_endpoint.cc +++ b/src/core/xds/grpc/xds_endpoint.cc @@ -47,10 +47,10 @@ #include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/validation_errors.h" #include "src/core/lib/iomgr/resolved_address.h" +#include "src/core/util/string.h" #include "src/core/xds/grpc/upb_utils.h" #include "src/core/xds/grpc/xds_health_status.h" #include "src/core/xds/xds_client/xds_resource_type.h" diff --git a/src/core/xds/grpc/xds_http_rbac_filter.cc b/src/core/xds/grpc/xds_http_rbac_filter.cc index c0560f09e9e..05055448a7d 100644 --- a/src/core/xds/grpc/xds_http_rbac_filter.cc +++ b/src/core/xds/grpc/xds_http_rbac_filter.cc @@ -46,10 +46,10 @@ #include "src/core/ext/filters/rbac/rbac_filter.h" #include "src/core/ext/filters/rbac/rbac_service_config_parser.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/env.h" #include "src/core/lib/json/json.h" #include "src/core/lib/json/json_writer.h" +#include "src/core/util/string.h" #include "src/core/xds/grpc/upb_utils.h" #include "src/core/xds/grpc/xds_audit_logger_registry.h" #include "src/core/xds/grpc/xds_bootstrap_grpc.h" diff --git a/src/core/xds/grpc/xds_route_config.cc b/src/core/xds/grpc/xds_route_config.cc index b03a539f628..f0c8de69739 100644 --- a/src/core/xds/grpc/xds_route_config.cc +++ b/src/core/xds/grpc/xds_route_config.cc @@ -61,7 +61,6 @@ #include "src/core/lib/channel/status_util.h" #include "src/core/lib/config/core_configuration.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/match.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -70,6 +69,7 @@ #include "src/core/lib/json/json_writer.h" #include "src/core/lib/matchers/matchers.h" #include "src/core/load_balancing/lb_policy_registry.h" +#include "src/core/util/string.h" #include "src/core/xds/grpc/upb_utils.h" #include "src/core/xds/grpc/xds_cluster_specifier_plugin.h" #include "src/core/xds/grpc/xds_common_types.h" diff --git a/src/core/xds/xds_client/xds_bootstrap.cc b/src/core/xds/xds_client/xds_bootstrap.cc index 1a979727780..65b70778ef3 100644 --- a/src/core/xds/xds_client/xds_bootstrap.cc +++ b/src/core/xds/xds_client/xds_bootstrap.cc @@ -20,8 +20,8 @@ #include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/env.h" +#include "src/core/util/string.h" namespace grpc_core { diff --git a/src/core/xds/xds_client/xds_client_stats.h b/src/core/xds/xds_client/xds_client_stats.h index b8822ba1b3c..1bfc28c3f3e 100644 --- a/src/core/xds/xds_client/xds_client_stats.h +++ b/src/core/xds/xds_client/xds_client_stats.h @@ -32,12 +32,12 @@ #include #include "src/core/lib/channel/call_tracer.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/per_cpu.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" #include "src/core/resolver/endpoint_addresses.h" +#include "src/core/util/useful.h" #include "src/core/xds/xds_client/xds_bootstrap.h" namespace grpc_core { diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 3b48e20dcf6..dabe0ce79ad 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -25,6 +25,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_join.h" @@ -35,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -273,8 +273,7 @@ std::shared_ptr ServiceAccountJWTAccessCredentials( const std::string& json_key, long token_lifetime_seconds) { grpc::internal::GrpcLibrary init; // To call grpc_init(). if (token_lifetime_seconds <= 0) { - gpr_log(GPR_ERROR, - "Trying to create JWTCredentials with non-positive lifetime"); + LOG(ERROR) << "Trying to create JWTCredentials with non-positive lifetime"; return WrapCallCredentials(nullptr); } gpr_timespec lifetime = diff --git a/src/cpp/common/alts_util.cc b/src/cpp/common/alts_util.cc index 784b0157c42..df1a8a8cf5b 100644 --- a/src/cpp/common/alts_util.cc +++ b/src/cpp/common/alts_util.cc @@ -21,10 +21,10 @@ #include #include +#include "absl/log/log.h" #include "upb/mem/arena.hpp" #include -#include #include #include #include @@ -40,25 +40,25 @@ namespace experimental { std::unique_ptr GetAltsContextFromAuthContext( const std::shared_ptr& auth_context) { if (auth_context == nullptr) { - gpr_log(GPR_ERROR, "auth_context is nullptr."); + LOG(ERROR) << "auth_context is nullptr."; return nullptr; } std::vector ctx_vector = auth_context->FindPropertyValues(TSI_ALTS_CONTEXT); if (ctx_vector.size() != 1) { - gpr_log(GPR_ERROR, "contains zero or more than one ALTS context."); + LOG(ERROR) << "contains zero or more than one ALTS context."; return nullptr; } upb::Arena context_arena; grpc_gcp_AltsContext* ctx = grpc_gcp_AltsContext_parse( ctx_vector[0].data(), ctx_vector[0].size(), context_arena.ptr()); if (ctx == nullptr) { - gpr_log(GPR_ERROR, "fails to parse ALTS context."); + LOG(ERROR) << "fails to parse ALTS context."; return nullptr; } if (grpc_gcp_AltsContext_security_level(ctx) < GRPC_SECURITY_MIN || grpc_gcp_AltsContext_security_level(ctx) > GRPC_SECURITY_MAX) { - gpr_log(GPR_ERROR, "security_level is invalid."); + LOG(ERROR) << "security_level is invalid."; return nullptr; } return std::make_unique(AltsContext(ctx)); diff --git a/src/cpp/common/completion_queue_cc.cc b/src/cpp/common/completion_queue_cc.cc index 9c0b7d31bc0..b2c3463c053 100644 --- a/src/cpp/common/completion_queue_cc.cc +++ b/src/cpp/common/completion_queue_cc.cc @@ -19,19 +19,19 @@ #include "absl/base/thread_annotations.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include #include -#include #include #include #include #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/sync.h" #include "src/core/lib/gprpp/thd.h" +#include "src/core/util/useful.h" namespace grpc { namespace { @@ -134,8 +134,7 @@ CompletionQueue::CompletionQueue(grpc_completion_queue* take) void CompletionQueue::Shutdown() { #ifndef NDEBUG if (!ServerListEmpty()) { - gpr_log(GPR_ERROR, - "CompletionQueue shutdown being shutdown before its server."); + LOG(ERROR) << "CompletionQueue shutdown being shutdown before its server."; } #endif CompleteAvalanching(); diff --git a/src/cpp/ext/csm/BUILD b/src/cpp/ext/csm/BUILD index fda0e37dbe8..6ee6bef1d4a 100644 --- a/src/cpp/ext/csm/BUILD +++ b/src/cpp/ext/csm/BUILD @@ -42,6 +42,7 @@ grpc_cc_library( external_deps = [ "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/status:statusor", "absl/strings", "absl/types:optional", diff --git a/src/cpp/ext/csm/csm_observability.cc b/src/cpp/ext/csm/csm_observability.cc index 751a3f52418..c924db3fbdc 100644 --- a/src/cpp/ext/csm/csm_observability.cc +++ b/src/cpp/ext/csm/csm_observability.cc @@ -23,6 +23,7 @@ #include #include "absl/functional/any_invocable.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/types/optional.h" #include "google/cloud/opentelemetry/resource_detector.h" @@ -30,7 +31,6 @@ #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/resource/resource_detector.h" -#include #include #include @@ -56,7 +56,7 @@ bool CsmChannelTargetSelector(absl::string_view target) { if (!g_csm_plugin_enabled) return false; auto uri = grpc_core::URI::Parse(target); if (!uri.ok()) { - gpr_log(GPR_ERROR, "Failed to parse URI: %s", std::string(target).c_str()); + LOG(ERROR) << "Failed to parse URI: " << target; return false; } // CSM channels should have an "xds" scheme diff --git a/src/cpp/ext/gcp/BUILD b/src/cpp/ext/gcp/BUILD index a95fe68b71c..814bf9012a2 100644 --- a/src/cpp/ext/gcp/BUILD +++ b/src/cpp/ext/gcp/BUILD @@ -115,6 +115,7 @@ grpc_cc_library( ], external_deps = [ "absl/base:core_headers", + "absl/log:log", "absl/numeric:int128", "absl/strings", "absl/strings:str_format", @@ -157,6 +158,7 @@ grpc_cc_library( "absl/container:flat_hash_map", "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/types:optional", diff --git a/src/cpp/ext/gcp/observability_logging_sink.cc b/src/cpp/ext/gcp/observability_logging_sink.cc index 6d62c1e4079..e7f71d4f0e8 100644 --- a/src/cpp/ext/gcp/observability_logging_sink.cc +++ b/src/cpp/ext/gcp/observability_logging_sink.cc @@ -22,6 +22,7 @@ #include #include +#include "absl/log/log.h" #include "absl/numeric/int128.h" #include "absl/strings/escaping.h" #include "absl/strings/match.h" @@ -34,7 +35,6 @@ #include "google/protobuf/text_format.h" #include -#include #include #include #include @@ -360,22 +360,20 @@ void ObservabilityLoggingSink::FlushEntriesHelper( &(call->context), &(call->request), &(call->response), [this, call](Status status) { if (!status.ok()) { - gpr_log( - GPR_ERROR, - "GCP Observability Logging Error %d: %s. Dumping log entries.", - status.error_code(), status.error_message().c_str()); + LOG(ERROR) << "GCP Observability Logging Error " + << status.error_code() << ": " << status.error_message() + << ". Dumping log entries."; for (auto& entry : call->request.entries()) { std::string output; ::google::protobuf::TextFormat::PrintToString(entry.json_payload(), &output); - gpr_log( - GPR_INFO, "Log Entry recorded at time: %s : %s", - grpc_core::Timestamp::FromTimespecRoundUp( - gpr_timespec{entry.timestamp().seconds(), - entry.timestamp().nanos(), GPR_CLOCK_REALTIME}) - .ToString() - .c_str(), - output.c_str()); + LOG(INFO) << "Log Entry recorded at time: " + << grpc_core::Timestamp::FromTimespecRoundUp( + gpr_timespec{entry.timestamp().seconds(), + entry.timestamp().nanos(), + GPR_CLOCK_REALTIME}) + .ToString() + << " : " << output; } } delete call; @@ -414,16 +412,16 @@ void ObservabilityLoggingSink::MaybeTriggerFlushLocked() { if (entries_.empty()) return; if (entries_.size() > kMaxEntriesBeforeDump || entries_memory_footprint_ > kMaxMemoryFootprintBeforeDump) { - // Buffer limits have been reached. Dump entries with gpr_log - gpr_log(GPR_INFO, "Buffer limit reached. Dumping log entries."); + // Buffer limits have been reached. Dump entries with LOG + LOG(INFO) << "Buffer limit reached. Dumping log entries."; for (auto& entry : entries_) { google::protobuf::Struct proto; std::string timestamp = entry.timestamp.ToString(); EntryToJsonStructProto(std::move(entry), &proto); std::string output; ::google::protobuf::TextFormat::PrintToString(proto, &output); - gpr_log(GPR_INFO, "Log Entry recorded at time: %s : %s", - timestamp.c_str(), output.c_str()); + LOG(INFO) << "Log Entry recorded at time: " << timestamp << " : " + << output; } entries_.clear(); entries_memory_footprint_ = 0; diff --git a/src/cpp/ext/otel/otel_plugin.cc b/src/cpp/ext/otel/otel_plugin.cc index 18e0069a72a..acb81be35ee 100644 --- a/src/cpp/ext/otel/otel_plugin.cc +++ b/src/cpp/ext/otel/otel_plugin.cc @@ -249,27 +249,35 @@ OpenTelemetryPlugin::CallbackMetricReporter::CallbackMetricReporter( // that if a particular combination of labels was previously present but // is no longer present, we won't continue to report it. for (const auto& handle : key->metrics()) { - grpc_core::Match( - handle, - [&](const grpc_core::GlobalInstrumentsRegistry:: - GlobalCallbackInt64GaugeHandle& handle) { - auto& callback_gauge_state = - absl::get>>( - ot_plugin_->instruments_data_.at(handle.index).instrument); - callback_gauge_state->caches[key].clear(); - }, - [&](const grpc_core::GlobalInstrumentsRegistry:: - GlobalCallbackDoubleGaugeHandle& handle) { - auto& callback_gauge_state = - absl::get>>( - ot_plugin_->instruments_data_.at(handle.index).instrument); - callback_gauge_state->caches[key].clear(); - }); + const auto& descriptor = + grpc_core::GlobalInstrumentsRegistry::GetInstrumentDescriptor(handle); + GPR_ASSERT( + descriptor.instrument_type == + grpc_core::GlobalInstrumentsRegistry::InstrumentType::kCallbackGauge); + switch (descriptor.value_type) { + case grpc_core::GlobalInstrumentsRegistry::ValueType::kInt64: { + auto& callback_gauge_state = + absl::get>>( + ot_plugin_->instruments_data_.at(handle.index).instrument); + callback_gauge_state->caches[key].clear(); + break; + } + case grpc_core::GlobalInstrumentsRegistry::ValueType::kDouble: { + auto& callback_gauge_state = + absl::get>>( + ot_plugin_->instruments_data_.at(handle.index).instrument); + callback_gauge_state->caches[key].clear(); + break; + } + default: + grpc_core::Crash(absl::StrFormat( + "Unknown or unsupported value type: %d", descriptor.value_type)); + } } } -void OpenTelemetryPlugin::CallbackMetricReporter::Report( - grpc_core::GlobalInstrumentsRegistry::GlobalCallbackInt64GaugeHandle handle, +void OpenTelemetryPlugin::CallbackMetricReporter::ReportInt64( + grpc_core::GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, int64_t value, absl::Span label_values, absl::Span optional_values) { const auto& instrument_data = ot_plugin_->instruments_data_.at(handle.index); @@ -296,9 +304,8 @@ void OpenTelemetryPlugin::CallbackMetricReporter::Report( cell.insert_or_assign(std::move(key), value); } -void OpenTelemetryPlugin::CallbackMetricReporter::Report( - grpc_core::GlobalInstrumentsRegistry::GlobalCallbackDoubleGaugeHandle - handle, +void OpenTelemetryPlugin::CallbackMetricReporter::ReportDouble( + grpc_core::GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, double value, absl::Span label_values, absl::Span optional_values) { const auto& instrument_data = ot_plugin_->instruments_data_.at(handle.index); @@ -574,8 +581,8 @@ OpenTelemetryPlugin::IsEnabledForChannel( std::pair> OpenTelemetryPlugin::IsEnabledForServer( const grpc_core::ChannelArgs& args) const { - // Return true only if there is no server selector registered or if the server - // selector returns true. + // Return true only if there is no server selector registered or if the + // server selector returns true. if (server_selector_ == nullptr || server_selector_(args)) { return {true, std::make_shared(this, args)}; } @@ -583,7 +590,7 @@ OpenTelemetryPlugin::IsEnabledForServer( } void OpenTelemetryPlugin::AddCounter( - grpc_core::GlobalInstrumentsRegistry::GlobalUInt64CounterHandle handle, + grpc_core::GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, uint64_t value, absl::Span label_values, absl::Span optional_values) { const auto& instrument_data = instruments_data_.at(handle.index); @@ -607,7 +614,7 @@ void OpenTelemetryPlugin::AddCounter( } void OpenTelemetryPlugin::AddCounter( - grpc_core::GlobalInstrumentsRegistry::GlobalDoubleCounterHandle handle, + grpc_core::GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, double value, absl::Span label_values, absl::Span optional_values) { const auto& instrument_data = instruments_data_.at(handle.index); @@ -631,7 +638,7 @@ void OpenTelemetryPlugin::AddCounter( } void OpenTelemetryPlugin::RecordHistogram( - grpc_core::GlobalInstrumentsRegistry::GlobalUInt64HistogramHandle handle, + grpc_core::GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, uint64_t value, absl::Span label_values, absl::Span optional_values) { const auto& instrument_data = instruments_data_.at(handle.index); @@ -657,7 +664,7 @@ void OpenTelemetryPlugin::RecordHistogram( } void OpenTelemetryPlugin::RecordHistogram( - grpc_core::GlobalInstrumentsRegistry::GlobalDoubleHistogramHandle handle, + grpc_core::GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, double value, absl::Span label_values, absl::Span optional_values) { const auto& instrument_data = instruments_data_.at(handle.index); @@ -691,51 +698,59 @@ void OpenTelemetryPlugin::AddCallback( grpc_core::MutexLock lock(&mu_); callback_timestamps_.emplace(callback, grpc_core::Timestamp::InfPast()); for (const auto& handle : callback->metrics()) { - grpc_core::Match( - handle, - [&](const grpc_core::GlobalInstrumentsRegistry:: - GlobalCallbackInt64GaugeHandle& handle) { - const auto& instrument_data = instruments_data_.at(handle.index); - if (absl::holds_alternative(instrument_data.instrument)) { - // This instrument is disabled. - return; - } - auto* callback_gauge_state = - absl::get_if>>( - &instrument_data.instrument); - CHECK_NE(callback_gauge_state, nullptr); - (*callback_gauge_state) - ->caches.emplace(callback, - CallbackGaugeState::Cache{}); - if (!std::exchange((*callback_gauge_state)->ot_callback_registered, - true)) { - gauges_that_need_to_add_callback.push_back( - callback_gauge_state->get()); - } - }, - [&](const grpc_core::GlobalInstrumentsRegistry:: - GlobalCallbackDoubleGaugeHandle& handle) { - const auto& instrument_data = instruments_data_.at(handle.index); - if (absl::holds_alternative(instrument_data.instrument)) { - // This instrument is disabled. - return; - } - auto* callback_gauge_state = - absl::get_if>>( - &instrument_data.instrument); - CHECK_NE(callback_gauge_state, nullptr); - (*callback_gauge_state) - ->caches.emplace(callback, CallbackGaugeState::Cache{}); - if (!std::exchange((*callback_gauge_state)->ot_callback_registered, - true)) { - gauges_that_need_to_add_callback.push_back( - callback_gauge_state->get()); - } - }); + const auto& descriptor = + grpc_core::GlobalInstrumentsRegistry::GetInstrumentDescriptor(handle); + GPR_ASSERT( + descriptor.instrument_type == + grpc_core::GlobalInstrumentsRegistry::InstrumentType::kCallbackGauge); + switch (descriptor.value_type) { + case grpc_core::GlobalInstrumentsRegistry::ValueType::kInt64: { + const auto& instrument_data = instruments_data_.at(handle.index); + if (absl::holds_alternative(instrument_data.instrument)) { + // This instrument is disabled. + continue; + } + auto* callback_gauge_state = + absl::get_if>>( + &instrument_data.instrument); + CHECK_NE(callback_gauge_state, nullptr); + (*callback_gauge_state) + ->caches.emplace(callback, CallbackGaugeState::Cache{}); + if (!std::exchange((*callback_gauge_state)->ot_callback_registered, + true)) { + gauges_that_need_to_add_callback.push_back( + callback_gauge_state->get()); + } + break; + } + case grpc_core::GlobalInstrumentsRegistry::ValueType::kDouble: { + const auto& instrument_data = instruments_data_.at(handle.index); + if (absl::holds_alternative(instrument_data.instrument)) { + // This instrument is disabled. + continue; + } + auto* callback_gauge_state = + absl::get_if>>( + &instrument_data.instrument); + CHECK_NE(callback_gauge_state, nullptr); + (*callback_gauge_state) + ->caches.emplace(callback, CallbackGaugeState::Cache{}); + if (!std::exchange((*callback_gauge_state)->ot_callback_registered, + true)) { + gauges_that_need_to_add_callback.push_back( + callback_gauge_state->get()); + } + break; + } + default: + grpc_core::Crash(absl::StrFormat( + "Unknown or unsupported value type: %d", descriptor.value_type)); + } } } - // AddCallback internally grabs OpenTelemetry's observable_registry's lock. So - // we need to call it without our plugin lock otherwise we may deadlock. + // AddCallback internally grabs OpenTelemetry's observable_registry's + // lock. So we need to call it without our plugin lock otherwise we may + // deadlock. for (const auto& gauge : gauges_that_need_to_add_callback) { grpc_core::Match( gauge, @@ -759,50 +774,59 @@ void OpenTelemetryPlugin::RemoveCallback( grpc_core::MutexLock lock(&mu_); callback_timestamps_.erase(callback); for (const auto& handle : callback->metrics()) { - grpc_core::Match( - handle, - [&](const grpc_core::GlobalInstrumentsRegistry:: - GlobalCallbackInt64GaugeHandle& handle) { - const auto& instrument_data = instruments_data_.at(handle.index); - if (absl::holds_alternative(instrument_data.instrument)) { - // This instrument is disabled. - return; - } - auto* callback_gauge_state = - absl::get_if>>( - &instrument_data.instrument); - CHECK_NE(callback_gauge_state, nullptr); - CHECK((*callback_gauge_state)->ot_callback_registered); - CHECK_EQ((*callback_gauge_state)->caches.erase(callback), 1u); - if ((*callback_gauge_state)->caches.empty()) { - gauges_that_need_to_remove_callback.push_back( - callback_gauge_state->get()); - (*callback_gauge_state)->ot_callback_registered = false; - } - }, - [&](const grpc_core::GlobalInstrumentsRegistry:: - GlobalCallbackDoubleGaugeHandle& handle) { - const auto& instrument_data = instruments_data_.at(handle.index); - if (absl::holds_alternative(instrument_data.instrument)) { - // This instrument is disabled. - return; - } - auto* callback_gauge_state = - absl::get_if>>( - &instrument_data.instrument); - CHECK_NE(callback_gauge_state, nullptr); - CHECK((*callback_gauge_state)->ot_callback_registered); - CHECK_EQ((*callback_gauge_state)->caches.erase(callback), 1u); - if ((*callback_gauge_state)->caches.empty()) { - gauges_that_need_to_remove_callback.push_back( - callback_gauge_state->get()); - (*callback_gauge_state)->ot_callback_registered = false; - } - }); + const auto& descriptor = + grpc_core::GlobalInstrumentsRegistry::GetInstrumentDescriptor(handle); + GPR_ASSERT( + descriptor.instrument_type == + grpc_core::GlobalInstrumentsRegistry::InstrumentType::kCallbackGauge); + switch (descriptor.value_type) { + case grpc_core::GlobalInstrumentsRegistry::ValueType::kInt64: { + const auto& instrument_data = instruments_data_.at(handle.index); + if (absl::holds_alternative(instrument_data.instrument)) { + // This instrument is disabled. + continue; + } + auto* callback_gauge_state = + absl::get_if>>( + &instrument_data.instrument); + CHECK_NE(callback_gauge_state, nullptr); + CHECK((*callback_gauge_state)->ot_callback_registered); + CHECK_EQ((*callback_gauge_state)->caches.erase(callback), 1u); + if ((*callback_gauge_state)->caches.empty()) { + gauges_that_need_to_remove_callback.push_back( + callback_gauge_state->get()); + (*callback_gauge_state)->ot_callback_registered = false; + } + break; + } + case grpc_core::GlobalInstrumentsRegistry::ValueType::kDouble: { + const auto& instrument_data = instruments_data_.at(handle.index); + if (absl::holds_alternative(instrument_data.instrument)) { + // This instrument is disabled. + continue; + } + auto* callback_gauge_state = + absl::get_if>>( + &instrument_data.instrument); + CHECK_NE(callback_gauge_state, nullptr); + CHECK((*callback_gauge_state)->ot_callback_registered); + CHECK_EQ((*callback_gauge_state)->caches.erase(callback), 1u); + if ((*callback_gauge_state)->caches.empty()) { + gauges_that_need_to_remove_callback.push_back( + callback_gauge_state->get()); + (*callback_gauge_state)->ot_callback_registered = false; + } + break; + } + default: + grpc_core::Crash(absl::StrFormat( + "Unknown or unsupported value type: %d", descriptor.value_type)); + } } } - // RemoveCallback internally grabs OpenTelemetry's observable_registry's lock. - // So we need to call it without our plugin lock otherwise we may deadlock. + // RemoveCallback internally grabs OpenTelemetry's observable_registry's + // lock. So we need to call it without our plugin lock otherwise we may + // deadlock. for (const auto& gauge : gauges_that_need_to_remove_callback) { grpc_core::Match( gauge, @@ -842,7 +866,8 @@ void OpenTelemetryPlugin::CallbackGaugeState::Observe( } } -// OpenTelemetry calls our callback with its observable_registry's lock held. +// OpenTelemetry calls our callback with its observable_registry's lock +// held. template void OpenTelemetryPlugin::CallbackGaugeState::CallbackGaugeCallback( opentelemetry::metrics::ObserverResult result, void* arg) { diff --git a/src/cpp/ext/otel/otel_plugin.h b/src/cpp/ext/otel/otel_plugin.h index 6908f2b7ab4..49d2cc3e384 100644 --- a/src/cpp/ext/otel/otel_plugin.h +++ b/src/cpp/ext/otel/otel_plugin.h @@ -343,22 +343,20 @@ class OpenTelemetryPlugin : public grpc_core::StatsPlugin { grpc_core::RegisteredMetricCallback* key) ABSL_EXCLUSIVE_LOCKS_REQUIRED(ot_plugin->mu_); - void Report( - grpc_core::GlobalInstrumentsRegistry::GlobalCallbackInt64GaugeHandle - handle, + private: + void ReportInt64( + grpc_core::GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, int64_t value, absl::Span label_values, absl::Span optional_values) ABSL_EXCLUSIVE_LOCKS_REQUIRED( CallbackGaugeState::ot_plugin->mu_) override; - void Report( - grpc_core::GlobalInstrumentsRegistry::GlobalCallbackDoubleGaugeHandle - handle, + void ReportDouble( + grpc_core::GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, double value, absl::Span label_values, absl::Span optional_values) ABSL_EXCLUSIVE_LOCKS_REQUIRED( CallbackGaugeState::ot_plugin->mu_) override; - private: OpenTelemetryPlugin* ot_plugin_; grpc_core::RegisteredMetricCallback* key_; }; @@ -380,19 +378,19 @@ class OpenTelemetryPlugin : public grpc_core::StatsPlugin { std::pair> IsEnabledForServer(const grpc_core::ChannelArgs& args) const override; void AddCounter( - grpc_core::GlobalInstrumentsRegistry::GlobalUInt64CounterHandle handle, + grpc_core::GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, uint64_t value, absl::Span label_values, absl::Span optional_values) override; void AddCounter( - grpc_core::GlobalInstrumentsRegistry::GlobalDoubleCounterHandle handle, + grpc_core::GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, double value, absl::Span label_values, absl::Span optional_values) override; void RecordHistogram( - grpc_core::GlobalInstrumentsRegistry::GlobalUInt64HistogramHandle handle, + grpc_core::GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, uint64_t value, absl::Span label_values, absl::Span optional_values) override; void RecordHistogram( - grpc_core::GlobalInstrumentsRegistry::GlobalDoubleHistogramHandle handle, + grpc_core::GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, double value, absl::Span label_values, absl::Span optional_values) override; void AddCallback(grpc_core::RegisteredMetricCallback* callback) diff --git a/src/cpp/server/load_reporter/get_cpu_stats_unsupported.cc b/src/cpp/server/load_reporter/get_cpu_stats_unsupported.cc index 83734b9c9d7..2744c66b25e 100644 --- a/src/cpp/server/load_reporter/get_cpu_stats_unsupported.cc +++ b/src/cpp/server/load_reporter/get_cpu_stats_unsupported.cc @@ -20,7 +20,7 @@ #if !defined(GPR_LINUX) && !defined(GPR_WINDOWS) && !defined(GPR_APPLE) -#include +#include "absl/log/log.h" #include "src/core/lib/gprpp/crash.h" #include "src/cpp/server/load_reporter/get_cpu_stats.h" @@ -30,8 +30,8 @@ namespace load_reporter { std::pair GetCpuStatsImpl() { uint64_t busy = 0, total = 0; - gpr_log(GPR_ERROR, - "Platforms other than Linux, Windows, and MacOS are not supported."); + LOG(ERROR) + << "Platforms other than Linux, Windows, and MacOS are not supported."; return std::make_pair(busy, total); } diff --git a/src/cpp/server/load_reporter/util.cc b/src/cpp/server/load_reporter/util.cc index 8daac576d73..043d4ebb480 100644 --- a/src/cpp/server/load_reporter/util.cc +++ b/src/cpp/server/load_reporter/util.cc @@ -21,8 +21,9 @@ #include #include +#include "absl/log/log.h" + #include -#include #include #include #include @@ -41,7 +42,7 @@ void AddLoadReportingCost(grpc::ServerContext* ctx, cost_name.size()); ctx->AddTrailingMetadata(GRPC_LB_COST_MD_KEY, buf); } else { - gpr_log(GPR_ERROR, "Call metric value is not normal."); + LOG(ERROR) << "Call metric value is not normal."; } } diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index f989703fe1a..708b2364897 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -26,11 +26,12 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include #include -#include +#include #include #include #include @@ -47,11 +48,38 @@ #include #include -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" +#include "src/core/ext/transport/chttp2/server/chttp2_server.h" +#include "src/core/server/server.h" +#include "src/core/util/string.h" +#include "src/core/util/useful.h" #include "src/cpp/server/external_connection_acceptor_impl.h" namespace grpc { +namespace { + +// A PIMPL wrapper class that owns the only ref to the passive listener +// implementation. This is returned to the application. +class PassiveListenerOwner final + : public grpc_core::experimental::PassiveListener { + public: + explicit PassiveListenerOwner(std::shared_ptr listener) + : listener_(std::move(listener)) {} + + absl::Status AcceptConnectedEndpoint( + std::unique_ptr + endpoint) override { + return listener_->AcceptConnectedEndpoint(std::move(endpoint)); + } + + absl::Status AcceptConnectedFd(int fd) override { + return listener_->AcceptConnectedFd(fd); + } + + private: + std::shared_ptr listener_; +}; + +} // namespace static std::vector (*)()>* g_plugin_factory_list; @@ -111,10 +139,9 @@ ServerBuilder& ServerBuilder::RegisterService(const std::string& host, ServerBuilder& ServerBuilder::RegisterAsyncGenericService( AsyncGenericService* service) { if (generic_service_ || callback_generic_service_) { - gpr_log(GPR_ERROR, - "Adding multiple generic services is unsupported for now. " - "Dropping the service %p", - service); + LOG(ERROR) << "Adding multiple generic services is unsupported for now. " + "Dropping the service " + << service; } else { generic_service_ = service; } @@ -124,10 +151,9 @@ ServerBuilder& ServerBuilder::RegisterAsyncGenericService( ServerBuilder& ServerBuilder::RegisterCallbackGenericService( CallbackGenericService* service) { if (generic_service_ || callback_generic_service_) { - gpr_log(GPR_ERROR, - "Adding multiple generic services is unsupported for now. " - "Dropping the service %p", - service); + LOG(ERROR) << "Adding multiple generic services is unsupported for now. " + "Dropping the service " + << service; } else { callback_generic_service_ = service; } @@ -225,6 +251,18 @@ ServerBuilder& ServerBuilder::SetResourceQuota( return *this; } +ServerBuilder& ServerBuilder::experimental_type::AddPassiveListener( + std::shared_ptr creds, + std::unique_ptr& passive_listener) { + auto core_passive_listener = + std::make_shared(); + builder_->unstarted_passive_listeners_.emplace_back(core_passive_listener, + std::move(creds)); + passive_listener = + std::make_unique(std::move(core_passive_listener)); + return *builder_; +} + ServerBuilder& ServerBuilder::AddListeningPort( const std::string& addr_uri, std::shared_ptr creds, int* selected_port) { @@ -351,16 +389,16 @@ std::unique_ptr ServerBuilder::BuildAndStart() { if (has_sync_methods) { // This is a Sync server - gpr_log(GPR_INFO, - "Synchronous server. Num CQs: %d, Min pollers: %d, Max Pollers: " - "%d, CQ timeout (msec): %d", - sync_server_settings_.num_cqs, sync_server_settings_.min_pollers, - sync_server_settings_.max_pollers, - sync_server_settings_.cq_timeout_msec); + LOG(INFO) << "Synchronous server. Num CQs: " + << sync_server_settings_.num_cqs + << ", Min pollers: " << sync_server_settings_.min_pollers + << ", Max Pollers: " << sync_server_settings_.max_pollers + << ", CQ timeout (msec): " + << sync_server_settings_.cq_timeout_msec; } if (has_callback_methods) { - gpr_log(GPR_INFO, "Callback server."); + LOG(INFO) << "Callback server."; } std::unique_ptr server(new grpc::Server( @@ -398,9 +436,29 @@ std::unique_ptr ServerBuilder::BuildAndStart() { cq->RegisterServer(server.get()); } + for (auto& unstarted_listener : unstarted_passive_listeners_) { + has_frequently_polled_cqs = true; + auto passive_listener = unstarted_listener.passive_listener.lock(); + auto* core_server = grpc_core::Server::FromC(server->c_server()); + if (passive_listener != nullptr) { + auto* creds = unstarted_listener.credentials->c_creds(); + if (creds == nullptr) { + LOG(ERROR) << "Credentials missing for PassiveListener"; + return nullptr; + } + auto success = grpc_server_add_passive_listener( + core_server, creds, std::move(passive_listener)); + if (!success.ok()) { + LOG(ERROR) << "Failed to create a passive listener: " + << success.ToString(); + return nullptr; + } + } + } + if (!has_frequently_polled_cqs) { - gpr_log(GPR_ERROR, - "At least one of the completion queues must be frequently polled"); + LOG(ERROR) + << "At least one of the completion queues must be frequently polled"; return nullptr; } @@ -423,9 +481,8 @@ std::unique_ptr ServerBuilder::BuildAndStart() { } else { for (const auto& value : services_) { if (value->service->has_generic_methods()) { - gpr_log(GPR_ERROR, - "Some methods were marked generic but there is no " - "generic service registered."); + LOG(ERROR) << "Some methods were marked generic but there is no " + "generic service registered."; return nullptr; } } @@ -465,7 +522,7 @@ ServerBuilder& ServerBuilder::EnableWorkaround(grpc_workaround_list id) { case GRPC_WORKAROUND_ID_CRONET_COMPRESSION: return AddChannelArgument(GRPC_ARG_WORKAROUND_CRONET_COMPRESSION, 1); default: - gpr_log(GPR_ERROR, "Workaround %u does not exist or is obsolete.", id); + LOG(ERROR) << "Workaround " << id << " does not exist or is obsolete."; return *this; } } diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index ff3c3c7bdb3..099b8ca2141 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -30,13 +30,13 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include #include #include #include -#include #include #include #include @@ -446,7 +446,7 @@ class Server::SyncRequest final : public grpc::internal::CompletionQueueTag { deserialized_request_ = handler->Deserialize(call_, request_payload_, &request_status_, nullptr); if (!request_status_.ok()) { - gpr_log(GPR_DEBUG, "Failed to deserialize message."); + VLOG(2) << "Failed to deserialize message."; } request_payload_ = nullptr; interceptor_methods_.AddInterceptionHookPoint( @@ -689,7 +689,7 @@ class Server::CallbackRequest final req_->call_, req_->request_payload_, &req_->request_status_, &req_->handler_data_); if (!(req_->request_status_.ok())) { - gpr_log(GPR_DEBUG, "Failed to deserialize message."); + VLOG(2) << "Failed to deserialize message."; } req_->request_payload_ = nullptr; req_->interceptor_methods_.AddInterceptionHookPoint( @@ -1058,8 +1058,7 @@ bool Server::RegisterService(const std::string* addr, grpc::Service* service) { server_, method->name(), addr ? addr->c_str() : nullptr, PayloadHandlingForMethod(method.get()), 0); if (method_registration_tag == nullptr) { - gpr_log(GPR_DEBUG, "Attempt to register %s multiple times", - method->name()); + VLOG(2) << "Attempt to register " << method->name() << " multiple times"; return false; } diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index a5eae9ac62f..69d2f55237f 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -29,6 +29,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" @@ -38,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -347,7 +347,7 @@ void ServerContextBase::TryCancel() const { grpc_call_cancel_with_status(call_.call, GRPC_STATUS_CANCELLED, "Cancelled on the server side", nullptr); if (err != GRPC_CALL_OK) { - gpr_log(GPR_ERROR, "TryCancel failed with: %d", err); + LOG(ERROR) << "TryCancel failed with: " << err; } } diff --git a/src/cpp/thread_manager/thread_manager.cc b/src/cpp/thread_manager/thread_manager.cc index 1264bb3102e..1fd3ee20bc8 100644 --- a/src/cpp/thread_manager/thread_manager.cc +++ b/src/cpp/thread_manager/thread_manager.cc @@ -21,10 +21,9 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_format.h" -#include - #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/thd.h" @@ -41,7 +40,7 @@ ThreadManager::WorkerThread::WorkerThread(ThreadManager* thd_mgr) [](void* th) { static_cast(th)->Run(); }, this, &created_); if (!created_) { - gpr_log(GPR_ERROR, "Could not create grpc_sync_server worker-thread"); + LOG(ERROR) << "Could not create grpc_sync_server worker-thread"; } } diff --git a/src/objective-c/tests/CFStreamTests/CFStreamClientTests.mm b/src/objective-c/tests/CFStreamTests/CFStreamClientTests.mm index 6c90f0898dc..140d8609314 100644 --- a/src/objective-c/tests/CFStreamTests/CFStreamClientTests.mm +++ b/src/objective-c/tests/CFStreamTests/CFStreamClientTests.mm @@ -48,8 +48,8 @@ static void finish_connection() { } static void must_succeed(void* arg, grpc_error_handle error) { - GPR_ASSERT(g_connecting != nullptr); - GPR_ASSERT(error.ok()); + CHECK(g_connecting != nullptr); + CHECK(error.ok()); grpc_endpoint_shutdown(g_connecting, GRPC_ERROR_CREATE("must_succeed called")); grpc_endpoint_destroy(g_connecting); g_connecting = nullptr; @@ -57,8 +57,8 @@ static void must_succeed(void* arg, grpc_error_handle error) { } static void must_fail(void* arg, grpc_error_handle error) { - GPR_ASSERT(g_connecting == nullptr); - GPR_ASSERT(!error.ok()); + CHECK(g_connecting == nullptr); + CHECK(!error.ok()); NSLog(@"%s", grpc_core::StatusToString(error).c_str()); finish_connection(); } @@ -88,21 +88,21 @@ static void must_fail(void* arg, grpc_error_handle error) { gpr_log(GPR_DEBUG, "test_succeeds"); auto resolved_addr = grpc_core::StringToSockaddr("127.0.0.1:0"); - GPR_ASSERT(resolved_addr.ok()); + CHECK(resolved_addr.ok()); struct sockaddr_in* addr = reinterpret_cast(resolved_addr->addr); /* create a phony server */ svr_fd = socket(AF_INET, SOCK_STREAM, 0); - GPR_ASSERT(svr_fd >= 0); - GPR_ASSERT(0 == bind(svr_fd, (struct sockaddr*)addr, (socklen_t)resolved_addr->len)); - GPR_ASSERT(0 == listen(svr_fd, 1)); + CHECK(svr_fd >= 0); + CHECK(0 == bind(svr_fd, (struct sockaddr*)addr, (socklen_t)resolved_addr->len)); + CHECK(0 == listen(svr_fd, 1)); gpr_mu_lock(&g_mu); connections_complete_before = g_connections_complete; gpr_mu_unlock(&g_mu); /* connect to it */ - GPR_ASSERT(getsockname(svr_fd, (struct sockaddr*)addr, (socklen_t*)&resolved_addr->len) == 0); + CHECK(getsockname(svr_fd, (struct sockaddr*)addr, (socklen_t*)&resolved_addr->len) == 0); GRPC_CLOSURE_INIT(&done, must_succeed, nullptr, grpc_schedule_on_exec_ctx); auto args = grpc_core::CoreConfiguration::Get().channel_args_preconditioning().PreconditionChannelArgs( @@ -117,7 +117,7 @@ static void must_fail(void* arg, grpc_error_handle error) { r = accept(svr_fd, reinterpret_cast(addr), reinterpret_cast(&resolved_addr->len)); } while (r == -1 && errno == EINTR); - GPR_ASSERT(r >= 0); + CHECK(r >= 0); close(r); grpc_core::ExecCtx::Get()->Flush(); @@ -145,14 +145,14 @@ static void must_fail(void* arg, grpc_error_handle error) { gpr_log(GPR_DEBUG, "test_fails"); auto resolved_addr = grpc_core::StringToSockaddr("127.0.0.1:0"); - GPR_ASSERT(resolved_addr.ok()); + CHECK(resolved_addr.ok()); struct sockaddr_in* addr = reinterpret_cast(resolved_addr->addr); svr_fd = socket(AF_INET, SOCK_STREAM, 0); - GPR_ASSERT(svr_fd >= 0); - GPR_ASSERT(0 == bind(svr_fd, (struct sockaddr*)addr, (socklen_t)resolved_addr->len)); - GPR_ASSERT(0 == listen(svr_fd, 1)); - GPR_ASSERT(getsockname(svr_fd, (struct sockaddr*)addr, (socklen_t*)&resolved_addr->len) == 0); + CHECK(svr_fd >= 0); + CHECK(0 == bind(svr_fd, (struct sockaddr*)addr, (socklen_t)resolved_addr->len)); + CHECK(0 == listen(svr_fd, 1)); + CHECK(getsockname(svr_fd, (struct sockaddr*)addr, (socklen_t*)&resolved_addr->len) == 0); close(svr_fd); gpr_mu_lock(&g_mu); diff --git a/src/objective-c/tests/CronetTests/CronetUnitTests.mm b/src/objective-c/tests/CronetTests/CronetUnitTests.mm index 5d9f8d41123..e09a06e821a 100644 --- a/src/objective-c/tests/CronetTests/CronetUnitTests.mm +++ b/src/objective-c/tests/CronetTests/CronetUnitTests.mm @@ -32,10 +32,10 @@ #import #import "src/core/lib/channel/channel_args.h" -#import "src/core/lib/gpr/string.h" -#import "src/core/lib/gpr/tmpfile.h" #import "src/core/lib/gprpp/env.h" #import "src/core/lib/gprpp/host_port.h" +#import "src/core/util/string.h" +#import "src/core/util/tmpfile.h" #import "test/core/end2end/data/ssl_test_data.h" #import "test/core/test_util/test_config.h" @@ -154,7 +154,7 @@ unsigned int parse_h2_length(const char *field) { c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, cq, grpc_slice_from_static_string("/foo"), NULL, deadline, NULL); - GPR_ASSERT(c); + CHECK(c); grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); @@ -162,7 +162,7 @@ unsigned int parse_h2_length(const char *field) { grpc_call_details_init(&call_details); int sl = socket(AF_INET, SOCK_STREAM, 0); - GPR_ASSERT(sl >= 0); + CHECK(sl >= 0); // Make an TCP endpoint to accept the connection struct sockaddr_in s_addr; @@ -170,8 +170,8 @@ unsigned int parse_h2_length(const char *field) { s_addr.sin_family = AF_INET; s_addr.sin_addr.s_addr = htonl(INADDR_ANY); s_addr.sin_port = htons(port); - GPR_ASSERT(0 == bind(sl, (struct sockaddr *)&s_addr, sizeof(s_addr))); - GPR_ASSERT(0 == listen(sl, 5)); + CHECK(0 == bind(sl, (struct sockaddr *)&s_addr, sizeof(s_addr))); + CHECK(0 == listen(sl, 5)); memset(ops, 0, sizeof(ops)); op = ops; @@ -208,11 +208,11 @@ unsigned int parse_h2_length(const char *field) { op->reserved = NULL; op++; error = grpc_call_start_batch(c, ops, (size_t)(op - ops), (void *)1, NULL); - GPR_ASSERT(GRPC_CALL_OK == error); + CHECK(GRPC_CALL_OK == error); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ int s = accept(sl, NULL, NULL); - GPR_ASSERT(s >= 0); + CHECK(s >= 0); // Close the connection after 1 second to trigger Cronet's on_failed() sleep(1); @@ -223,7 +223,7 @@ unsigned int parse_h2_length(const char *field) { cqv.Expect((void *)1, true); cqv.Verify(); - GPR_ASSERT(status == GRPC_STATUS_UNAVAILABLE); + CHECK(status == GRPC_STATUS_UNAVAILABLE); grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); @@ -282,7 +282,7 @@ unsigned int parse_h2_length(const char *field) { c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, cq, grpc_slice_from_static_string("/foo"), NULL, deadline, NULL); - GPR_ASSERT(c); + CHECK(c); grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); @@ -292,18 +292,18 @@ unsigned int parse_h2_length(const char *field) { __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Coalescing"]; int sl = socket(AF_INET, SOCK_STREAM, 0); - GPR_ASSERT(sl >= 0); + CHECK(sl >= 0); struct sockaddr_in s_addr; memset(&s_addr, 0, sizeof(s_addr)); s_addr.sin_family = AF_INET; s_addr.sin_addr.s_addr = htonl(INADDR_ANY); s_addr.sin_port = htons(port); - GPR_ASSERT(0 == bind(sl, (struct sockaddr *)&s_addr, sizeof(s_addr))); - GPR_ASSERT(0 == listen(sl, 5)); + CHECK(0 == bind(sl, (struct sockaddr *)&s_addr, sizeof(s_addr))); + CHECK(0 == listen(sl, 5)); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ int s = accept(sl, NULL, NULL); - GPR_ASSERT(s >= 0); + CHECK(s >= 0); struct timeval tv; tv.tv_sec = 2; tv.tv_usec = 0; @@ -391,7 +391,7 @@ unsigned int parse_h2_length(const char *field) { op->reserved = NULL; op++; error = grpc_call_start_batch(c, ops, (size_t)(op - ops), (void *)1, NULL); - GPR_ASSERT(GRPC_CALL_OK == error); + CHECK(GRPC_CALL_OK == error); cqv.Expect((void *)1, true); cqv.Verify(); diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi index d663b1c676f..8332c5a0d5b 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi @@ -780,6 +780,16 @@ async def _schedule_rpc_coro(object rpc_coro, ), name="HandleExceptions[%s]" % _decode(rpc_state.method())) _add_callback_handler(rpc_task, rpc_state) await _handle_cancellation_from_core(rpc_task, rpc_state, loop) + try: + # Propagate any errors not handled by _handle_exceptions. If not awaited + # there will be logs of the form "Task exception was never retrieved". + # Catching it here we can provide traceback and debugging logs. + await rpc_task + except: + _LOGGER.exception('Exception not handled by _handle_exceptions in servicer method [%s]' % ( + _decode(rpc_state.method()), + )) + traceback.print_exc() async def _handle_rpc(list generic_handlers, tuple interceptors, @@ -954,6 +964,7 @@ cdef class AioServer: self._server.start(backup_queue=False) cdef RPCState rpc_state server_started.set_result(True) + rpc_tasks = set() while True: # When shutdown begins, no more new connections. @@ -985,9 +996,15 @@ cdef class AioServer: rpc_coro, rpc_state, self._loop - ) + ), + name="rpc_task", ) + # loop.create_task only holds a weakref to the task. + # Maintain reference to tasks to avoid garbage collection. + rpc_tasks.add(rpc_task) + rpc_task.add_done_callback(rpc_tasks.discard) + if self._limiter is not None: self._limiter.decrease_once_finished(rpc_task) diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 377dac99484..a6e9be13ead 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -490,32 +490,6 @@ CORE_SOURCE_FILES = [ 'src/core/lib/event_engine/work_queue/basic_work_queue.cc', 'src/core/lib/experiments/config.cc', 'src/core/lib/experiments/experiments.cc', - 'src/core/lib/gpr/alloc.cc', - 'src/core/lib/gpr/android/log.cc', - 'src/core/lib/gpr/atm.cc', - 'src/core/lib/gpr/iphone/cpu.cc', - 'src/core/lib/gpr/linux/cpu.cc', - 'src/core/lib/gpr/linux/log.cc', - 'src/core/lib/gpr/log.cc', - 'src/core/lib/gpr/msys/tmpfile.cc', - 'src/core/lib/gpr/posix/cpu.cc', - 'src/core/lib/gpr/posix/log.cc', - 'src/core/lib/gpr/posix/string.cc', - 'src/core/lib/gpr/posix/sync.cc', - 'src/core/lib/gpr/posix/time.cc', - 'src/core/lib/gpr/posix/tmpfile.cc', - 'src/core/lib/gpr/string.cc', - 'src/core/lib/gpr/sync.cc', - 'src/core/lib/gpr/sync_abseil.cc', - 'src/core/lib/gpr/time.cc', - 'src/core/lib/gpr/time_precise.cc', - 'src/core/lib/gpr/windows/cpu.cc', - 'src/core/lib/gpr/windows/log.cc', - 'src/core/lib/gpr/windows/string.cc', - 'src/core/lib/gpr/windows/string_util.cc', - 'src/core/lib/gpr/windows/sync.cc', - 'src/core/lib/gpr/windows/time.cc', - 'src/core/lib/gpr/windows/tmpfile.cc', 'src/core/lib/gprpp/crash.cc', 'src/core/lib/gprpp/examine_stack.cc', 'src/core/lib/gprpp/fork.cc', @@ -736,6 +710,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/transport/call_spine.cc', 'src/core/lib/transport/connectivity_state.cc', 'src/core/lib/transport/error_utils.cc', + 'src/core/lib/transport/interception_chain.cc', 'src/core/lib/transport/message.cc', 'src/core/lib/transport/metadata.cc', 'src/core/lib/transport/metadata_batch.cc', @@ -833,6 +808,32 @@ CORE_SOURCE_FILES = [ 'src/core/tsi/ssl_transport_security_utils.cc', 'src/core/tsi/transport_security.cc', 'src/core/tsi/transport_security_grpc.cc', + 'src/core/util/alloc.cc', + 'src/core/util/android/log.cc', + 'src/core/util/atm.cc', + 'src/core/util/iphone/cpu.cc', + 'src/core/util/linux/cpu.cc', + 'src/core/util/linux/log.cc', + 'src/core/util/log.cc', + 'src/core/util/msys/tmpfile.cc', + 'src/core/util/posix/cpu.cc', + 'src/core/util/posix/log.cc', + 'src/core/util/posix/string.cc', + 'src/core/util/posix/sync.cc', + 'src/core/util/posix/time.cc', + 'src/core/util/posix/tmpfile.cc', + 'src/core/util/string.cc', + 'src/core/util/sync.cc', + 'src/core/util/sync_abseil.cc', + 'src/core/util/time.cc', + 'src/core/util/time_precise.cc', + 'src/core/util/windows/cpu.cc', + 'src/core/util/windows/log.cc', + 'src/core/util/windows/string.cc', + 'src/core/util/windows/string_util.cc', + 'src/core/util/windows/sync.cc', + 'src/core/util/windows/time.cc', + 'src/core/util/windows/tmpfile.cc', 'src/core/xds/grpc/certificate_provider_store.cc', 'src/core/xds/grpc/file_watcher_certificate_provider_factory.cc', 'src/core/xds/grpc/xds_audit_logger_registry.cc', diff --git a/src/python/grpcio_observability/observability_lib_deps.py b/src/python/grpcio_observability/observability_lib_deps.py index 15bd64b12bc..88eebda6fd2 100644 --- a/src/python/grpcio_observability/observability_lib_deps.py +++ b/src/python/grpcio_observability/observability_lib_deps.py @@ -20,32 +20,6 @@ CC_FILES=[ 'grpc_root/src/core/lib/config/load_config.cc', 'grpc_root/src/core/lib/debug/trace.cc', 'grpc_root/src/core/lib/event_engine/thread_local.cc', - 'grpc_root/src/core/lib/gpr/alloc.cc', - 'grpc_root/src/core/lib/gpr/android/log.cc', - 'grpc_root/src/core/lib/gpr/atm.cc', - 'grpc_root/src/core/lib/gpr/iphone/cpu.cc', - 'grpc_root/src/core/lib/gpr/linux/cpu.cc', - 'grpc_root/src/core/lib/gpr/linux/log.cc', - 'grpc_root/src/core/lib/gpr/log.cc', - 'grpc_root/src/core/lib/gpr/msys/tmpfile.cc', - 'grpc_root/src/core/lib/gpr/posix/cpu.cc', - 'grpc_root/src/core/lib/gpr/posix/log.cc', - 'grpc_root/src/core/lib/gpr/posix/string.cc', - 'grpc_root/src/core/lib/gpr/posix/sync.cc', - 'grpc_root/src/core/lib/gpr/posix/time.cc', - 'grpc_root/src/core/lib/gpr/posix/tmpfile.cc', - 'grpc_root/src/core/lib/gpr/string.cc', - 'grpc_root/src/core/lib/gpr/sync.cc', - 'grpc_root/src/core/lib/gpr/sync_abseil.cc', - 'grpc_root/src/core/lib/gpr/time.cc', - 'grpc_root/src/core/lib/gpr/time_precise.cc', - 'grpc_root/src/core/lib/gpr/windows/cpu.cc', - 'grpc_root/src/core/lib/gpr/windows/log.cc', - 'grpc_root/src/core/lib/gpr/windows/string.cc', - 'grpc_root/src/core/lib/gpr/windows/string_util.cc', - 'grpc_root/src/core/lib/gpr/windows/sync.cc', - 'grpc_root/src/core/lib/gpr/windows/time.cc', - 'grpc_root/src/core/lib/gpr/windows/tmpfile.cc', 'grpc_root/src/core/lib/gprpp/crash.cc', 'grpc_root/src/core/lib/gprpp/examine_stack.cc', 'grpc_root/src/core/lib/gprpp/fork.cc', @@ -64,6 +38,32 @@ CC_FILES=[ 'grpc_root/src/core/lib/slice/slice.cc', 'grpc_root/src/core/lib/slice/slice_refcount.cc', 'grpc_root/src/core/lib/slice/slice_string_helpers.cc', + 'grpc_root/src/core/util/alloc.cc', + 'grpc_root/src/core/util/android/log.cc', + 'grpc_root/src/core/util/atm.cc', + 'grpc_root/src/core/util/iphone/cpu.cc', + 'grpc_root/src/core/util/linux/cpu.cc', + 'grpc_root/src/core/util/linux/log.cc', + 'grpc_root/src/core/util/log.cc', + 'grpc_root/src/core/util/msys/tmpfile.cc', + 'grpc_root/src/core/util/posix/cpu.cc', + 'grpc_root/src/core/util/posix/log.cc', + 'grpc_root/src/core/util/posix/string.cc', + 'grpc_root/src/core/util/posix/sync.cc', + 'grpc_root/src/core/util/posix/time.cc', + 'grpc_root/src/core/util/posix/tmpfile.cc', + 'grpc_root/src/core/util/string.cc', + 'grpc_root/src/core/util/sync.cc', + 'grpc_root/src/core/util/sync_abseil.cc', + 'grpc_root/src/core/util/time.cc', + 'grpc_root/src/core/util/time_precise.cc', + 'grpc_root/src/core/util/windows/cpu.cc', + 'grpc_root/src/core/util/windows/log.cc', + 'grpc_root/src/core/util/windows/string.cc', + 'grpc_root/src/core/util/windows/string_util.cc', + 'grpc_root/src/core/util/windows/sync.cc', + 'grpc_root/src/core/util/windows/time.cc', + 'grpc_root/src/core/util/windows/tmpfile.cc', 'third_party/abseil-cpp/absl/base/internal/cycleclock.cc', 'third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc', 'third_party/abseil-cpp/absl/base/internal/raw_logging.cc', diff --git a/templates/gRPC-Core.podspec.template b/templates/gRPC-Core.podspec.template index 5b7669aaacc..57716758103 100644 --- a/templates/gRPC-Core.podspec.template +++ b/templates/gRPC-Core.podspec.template @@ -158,7 +158,7 @@ ' "$(PODS_TARGET_SRCROOT)/third_party/utf8_range"'${"\\"} ' "$(PODS_TARGET_SRCROOT)/third_party/xxhash"', # If we don't set these two settings, `include/grpc/support/time.h` and - # `src/core/lib/gpr/string.h` shadow the system `` and ``, breaking the + # `src/core/util/string.h` shadow the system `` and ``, breaking the # build. 'USE_HEADERMAP' => 'NO', 'ALWAYS_SEARCH_USER_PATHS' => 'NO', diff --git a/test/core/address_utils/BUILD b/test/core/address_utils/BUILD index 15f41c3f9d5..ceb5a12dbb6 100644 --- a/test/core/address_utils/BUILD +++ b/test/core/address_utils/BUILD @@ -41,6 +41,7 @@ grpc_cc_test( name = "parse_address_test", srcs = ["parse_address_test.cc"], external_deps = [ + "absl/log:log", "absl/strings", "gtest", ], @@ -69,7 +70,10 @@ grpc_fuzzer( grpc_cc_test( name = "parse_address_with_named_scope_id_test", srcs = ["parse_address_with_named_scope_id_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", tags = ["no_windows"], uses_event_engine = False, diff --git a/test/core/address_utils/parse_address_test.cc b/test/core/address_utils/parse_address_test.cc index d94370556e5..41b9df4bd5d 100644 --- a/test/core/address_utils/parse_address_test.cc +++ b/test/core/address_utils/parse_address_test.cc @@ -34,12 +34,12 @@ #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/match.h" #include "gtest/gtest.h" #include -#include #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/port.h" @@ -53,7 +53,7 @@ static void test_grpc_parse_unix(const char* uri_text, const char* pathname) { grpc_core::ExecCtx exec_ctx; absl::StatusOr uri = grpc_core::URI::Parse(uri_text); if (!uri.ok()) { - gpr_log(GPR_ERROR, "%s", uri.status().ToString().c_str()); + LOG(ERROR) << uri.status(); ASSERT_TRUE(uri.ok()); } grpc_resolved_address addr; @@ -70,7 +70,7 @@ static void test_grpc_parse_unix_abstract(const char* uri_text, grpc_core::ExecCtx exec_ctx; absl::StatusOr uri = grpc_core::URI::Parse(uri_text); if (!uri.ok()) { - gpr_log(GPR_ERROR, "%s", uri.status().ToString().c_str()); + LOG(ERROR) << uri.status(); ASSERT_TRUE(uri.ok()); } grpc_resolved_address addr; @@ -98,7 +98,7 @@ static void test_grpc_parse_vsock(const char* uri_text, uint32_t cid, grpc_core::ExecCtx exec_ctx; absl::StatusOr uri = grpc_core::URI::Parse(uri_text); if (!uri.ok()) { - gpr_log(GPR_ERROR, "%s", uri.status().ToString().c_str()); + LOG(ERROR) << uri.status(); ASSERT_TRUE(uri.ok()); } grpc_resolved_address addr; @@ -122,7 +122,7 @@ static void test_grpc_parse_ipv4(const char* uri_text, const char* host, grpc_core::ExecCtx exec_ctx; absl::StatusOr uri = grpc_core::URI::Parse(uri_text); if (!uri.ok()) { - gpr_log(GPR_ERROR, "%s", uri.status().ToString().c_str()); + LOG(ERROR) << uri.status(); ASSERT_TRUE(uri.ok()); } grpc_resolved_address addr; @@ -142,7 +142,7 @@ static void test_grpc_parse_ipv6(const char* uri_text, const char* host, grpc_core::ExecCtx exec_ctx; absl::StatusOr uri = grpc_core::URI::Parse(uri_text); if (!uri.ok()) { - gpr_log(GPR_ERROR, "%s", uri.status().ToString().c_str()); + LOG(ERROR) << uri.status(); ASSERT_TRUE(uri.ok()); } grpc_resolved_address addr; @@ -162,7 +162,7 @@ static void test_grpc_parse_ipv6_invalid(const char* uri_text) { grpc_core::ExecCtx exec_ctx; absl::StatusOr uri = grpc_core::URI::Parse(uri_text); if (!uri.ok()) { - gpr_log(GPR_ERROR, "%s", uri.status().ToString().c_str()); + LOG(ERROR) << uri.status(); ASSERT_TRUE(uri.ok()); } grpc_resolved_address addr; diff --git a/test/core/address_utils/parse_address_with_named_scope_id_test.cc b/test/core/address_utils/parse_address_with_named_scope_id_test.cc index a69fa0072b8..eb76adef43d 100644 --- a/test/core/address_utils/parse_address_with_named_scope_id_test.cc +++ b/test/core/address_utils/parse_address_with_named_scope_id_test.cc @@ -28,13 +28,13 @@ #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" #include "gtest/gtest.h" #include -#include #include "src/core/lib/address_utils/parse_address.h" #include "src/core/lib/gprpp/crash.h" @@ -114,10 +114,8 @@ TEST(ParseAddressWithNamedScopeIdTest, MainTest) { // system recognizes, and then use that for the test. for (size_t i = 1; i < 65536; i++) { if (if_indextoname(i, arbitrary_interface_name) != nullptr) { - gpr_log(GPR_DEBUG, - "Found interface at index %" PRIuPTR - " named %s. Will use this for the test", - i, arbitrary_interface_name); + VLOG(2) << "Found interface at index " << i << " named " + << arbitrary_interface_name << ". Will use this for the test"; break; } } @@ -127,9 +125,8 @@ TEST(ParseAddressWithNamedScopeIdTest, MainTest) { struct sockaddr_in6 result_from_getaddrinfo = resolve_with_gettaddrinfo(target.c_str()); // Run the test - gpr_log(GPR_DEBUG, - "Run test_grpc_parse_ipv6_parity_with_getaddrinfo with target: %s", - target.c_str()); + VLOG(2) << "Run test_grpc_parse_ipv6_parity_with_getaddrinfo with target: " + << target; test_grpc_parse_ipv6_parity_with_getaddrinfo(target.c_str(), result_from_getaddrinfo); // Cleanup diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc index ee7e1ee4d39..f47a79cccc3 100644 --- a/test/core/bad_client/bad_client.cc +++ b/test/core/bad_client/bad_client.cc @@ -22,11 +22,11 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include #include -#include #include #include @@ -35,7 +35,6 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args_preconditioning.h" #include "src/core/lib/config/core_configuration.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/endpoint.h" @@ -45,6 +44,7 @@ #include "src/core/lib/surface/completion_queue.h" #include "src/core/lib/transport/transport.h" #include "src/core/server/server.h" +#include "src/core/util/string.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/test_util/test_config.h" @@ -111,11 +111,11 @@ void grpc_run_client_side_validator(grpc_bad_client_arg* arg, uint32_t flags, hex = gpr_dump(arg->client_payload, arg->client_payload_length, GPR_DUMP_HEX | GPR_DUMP_ASCII); // Add a debug log - gpr_log(GPR_INFO, "TEST: %s", hex); + LOG(INFO) << "TEST: " << hex; gpr_free(hex); } else { - gpr_log(GPR_INFO, "TEST: (%" PRIdPTR " byte long string)", - arg->client_payload_length); + LOG(INFO) << "TEST: (" << arg->client_payload_length + << " byte long string)"; } grpc_slice slice = grpc_slice_from_copied_buffer(arg->client_payload, @@ -171,9 +171,8 @@ void grpc_run_client_side_validator(grpc_bad_client_arg* arg, uint32_t flags, .type == GRPC_QUEUE_TIMEOUT); } while (!gpr_event_get(&read_done_event)); if (arg->client_validator(&incoming, arg->client_validator_arg)) break; - gpr_log(GPR_INFO, - "client validator failed; trying additional read " - "in case we didn't get all the data"); + LOG(INFO) << "client validator failed; trying additional read " + "in case we didn't get all the data"; } grpc_slice_buffer_destroy(&incoming); } @@ -317,7 +316,7 @@ bool rst_stream_client_validator(grpc_slice_buffer* incoming, void* /*arg*/) { *p++ == 0 || *p++ == 0 || *p++ == 0 || *p == 0 || *p == 11; if (!success) { - gpr_log(GPR_INFO, "client expected RST_STREAM frame, not found"); + LOG(INFO) << "client expected RST_STREAM frame, not found"; } grpc_slice_buffer_destroy(&last_frame_buffer); diff --git a/test/core/bad_client/generate_tests.bzl b/test/core/bad_client/generate_tests.bzl index 620fb5a114e..2ae6c1b3c42 100755 --- a/test/core/bad_client/generate_tests.bzl +++ b/test/core/bad_client/generate_tests.bzl @@ -44,6 +44,10 @@ def grpc_bad_client_tests(): hdrs = ["bad_client.h"], language = "C++", testonly = 1, + external_deps = [ + "absl/log:check", + "absl/log:log", + ], deps = [ "//test/core/test_util:grpc_test_util", "//:grpc", @@ -51,9 +55,6 @@ def grpc_bad_client_tests(): "//test/core/end2end:cq_verifier", "//:grpc_http_filters", ], - external_deps = [ - "absl/log:check", - ], ) for t, topt in BAD_CLIENT_TESTS.items(): grpc_cc_test( diff --git a/test/core/bad_connection/BUILD b/test/core/bad_connection/BUILD index d424ba888ac..5c674673037 100644 --- a/test/core/bad_connection/BUILD +++ b/test/core/bad_connection/BUILD @@ -23,7 +23,10 @@ grpc_cc_binary( srcs = [ "close_fd_test.cc", ], - external_deps = ["absl/log:check"], + external_deps = [ + "absl/log:check", + "absl/log:log", + ], language = "C++", tags = ["no_windows"], deps = [ diff --git a/test/core/bad_connection/close_fd_test.cc b/test/core/bad_connection/close_fd_test.cc index a51f141270e..d3d69c8c068 100644 --- a/test/core/bad_connection/close_fd_test.cc +++ b/test/core/bad_connection/close_fd_test.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" @@ -53,7 +54,6 @@ #include #include #include -#include #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/gprpp/crash.h" @@ -225,8 +225,8 @@ static void _test_close_before_server_recv(fd_type fdtype) { grpc_raw_byte_buffer_create(&request_payload_slice, 1); grpc_byte_buffer* response_payload = grpc_raw_byte_buffer_create(&response_payload_slice, 1); - gpr_log(GPR_INFO, "Running test: test_close_%s_before_server_recv", - fd_type_str(fdtype)); + LOG(INFO) << "Running test: test_close_" << fd_type_str(fdtype) + << "_before_server_recv"; test_init(); grpc_op ops[6]; @@ -399,8 +399,8 @@ static void _test_close_before_server_send(fd_type fdtype) { grpc_raw_byte_buffer_create(&request_payload_slice, 1); grpc_byte_buffer* response_payload = grpc_raw_byte_buffer_create(&response_payload_slice, 1); - gpr_log(GPR_INFO, "Running test: test_close_%s_before_server_send", - fd_type_str(fdtype)); + LOG(INFO) << "Running test: test_close_" << fd_type_str(fdtype) + << "_before_server_send"; test_init(); grpc_op ops[6]; @@ -596,8 +596,8 @@ static void _test_close_before_client_send(fd_type fdtype) { grpc_raw_byte_buffer_create(&request_payload_slice, 1); grpc_byte_buffer* response_payload = grpc_raw_byte_buffer_create(&response_payload_slice, 1); - gpr_log(GPR_INFO, "Running test: test_close_%s_before_client_send", - fd_type_str(fdtype)); + LOG(INFO) << "Running test: test_close_" << fd_type_str(fdtype) + << "_before_client_send"; test_init(); grpc_op ops[6]; diff --git a/test/core/bad_ssl/bad_ssl_test.cc b/test/core/bad_ssl/bad_ssl_test.cc index 988cea357a5..ade42a80c68 100644 --- a/test/core/bad_ssl/bad_ssl_test.cc +++ b/test/core/bad_ssl/bad_ssl_test.cc @@ -35,9 +35,9 @@ #include #include -#include "src/core/lib/gpr/subprocess.h" #include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/host_port.h" +#include "src/core/util/subprocess.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/test_util/port.h" #include "test/core/test_util/test_config.h" diff --git a/test/core/bad_ssl/generate_tests.bzl b/test/core/bad_ssl/generate_tests.bzl index 3ce7de49171..ddd3b3c97bf 100755 --- a/test/core/bad_ssl/generate_tests.bzl +++ b/test/core/bad_ssl/generate_tests.bzl @@ -35,6 +35,7 @@ def grpc_bad_ssl_tests(): hdrs = ["server_common.h"], external_deps = [ "absl/log:check", + "absl/log:log", ], deps = [ "//test/core/test_util:grpc_test_util", diff --git a/test/core/bad_ssl/server_common.cc b/test/core/bad_ssl/server_common.cc index 1f9c0a69f5f..e76708b1969 100644 --- a/test/core/bad_ssl/server_common.cc +++ b/test/core/bad_ssl/server_common.cc @@ -21,8 +21,8 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" -#include #include #include "test/core/test_util/cmdline.h" @@ -74,7 +74,7 @@ void bad_ssl_run(grpc_server* server) { signal(SIGINT, sigint_handler); while (!shutdown_finished) { if (got_sigint && !shutdown_started) { - gpr_log(GPR_INFO, "Shutting down due to SIGINT"); + LOG(INFO) << "Shutting down due to SIGINT"; shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); grpc_server_shutdown_and_notify(server, shutdown_cq, nullptr); CHECK(grpc_completion_queue_pluck(shutdown_cq, nullptr, diff --git a/test/core/bad_ssl/servers/alpn.cc b/test/core/bad_ssl/servers/alpn.cc index cc11af5ed42..b3894767b01 100644 --- a/test/core/bad_ssl/servers/alpn.cc +++ b/test/core/bad_ssl/servers/alpn.cc @@ -28,8 +28,8 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/iomgr/error.h" +#include "src/core/util/useful.h" #include "test/core/bad_ssl/server_common.h" #include "test/core/test_util/tls_utils.h" diff --git a/test/core/channel/BUILD b/test/core/channel/BUILD index 10831f5090c..b54cc023fa3 100644 --- a/test/core/channel/BUILD +++ b/test/core/channel/BUILD @@ -37,6 +37,7 @@ grpc_cc_test( srcs = ["channel_args_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], language = "C++", @@ -149,6 +150,7 @@ grpc_cc_test( name = "metrics_test", srcs = ["metrics_test.cc"], external_deps = [ + "absl/log:log", "gtest", ], language = "C++", diff --git a/test/core/channel/channel_args_test.cc b/test/core/channel/channel_args_test.cc index 3e59d01bfa0..09f65577f0e 100644 --- a/test/core/channel/channel_args_test.cc +++ b/test/core/channel/channel_args_test.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "gtest/gtest.h" #include @@ -28,13 +29,12 @@ #include #include #include -#include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/notification.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" namespace grpc_core { @@ -272,7 +272,7 @@ struct fake_class { }; static void* fake_pointer_arg_copy(void* arg) { - gpr_log(GPR_DEBUG, "fake_pointer_arg_copy"); + VLOG(2) << "fake_pointer_arg_copy"; fake_class* fc = static_cast(arg); fake_class* new_fc = static_cast(gpr_malloc(sizeof(fake_class))); new_fc->foo = fc->foo; @@ -280,7 +280,7 @@ static void* fake_pointer_arg_copy(void* arg) { } static void fake_pointer_arg_destroy(void* arg) { - gpr_log(GPR_DEBUG, "fake_pointer_arg_destroy"); + VLOG(2) << "fake_pointer_arg_destroy"; fake_class* fc = static_cast(arg); gpr_free(fc); } diff --git a/test/core/channel/metrics_test.cc b/test/core/channel/metrics_test.cc index d6b4d04d17c..3d57b32d2ab 100644 --- a/test/core/channel/metrics_test.cc +++ b/test/core/channel/metrics_test.cc @@ -16,10 +16,7 @@ #include -#include "absl/container/flat_hash_map.h" -#include "absl/strings/match.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_join.h" +#include "absl/log/log.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -40,15 +37,15 @@ class MetricsTest : public ::testing::Test { }; TEST_F(MetricsTest, UInt64Counter) { - const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; - const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", - "optional_label_key_2"}; - auto uint64_counter_handle = GlobalInstrumentsRegistry::RegisterUInt64Counter( - "uint64_counter", "A simple uint64 counter.", "unit", kLabelKeys, - kOptionalLabelKeys, true); - constexpr absl::string_view kLabelValues[] = {"label_value_1", - "label_value_2"}; - constexpr absl::string_view kOptionalLabelValues[] = { + auto uint64_counter_handle = + GlobalInstrumentsRegistry::RegisterUInt64Counter( + "uint64_counter", "A simple uint64 counter.", "unit", true) + .Labels("label_key_1", "label_key_2") + .OptionalLabels("optional_label_key_1", "optional_label_key_2") + .Build(); + std::array kLabelValues = {"label_value_1", + "label_value_2"}; + std::array kOptionalLabelValues = { "optional_label_value_1", "optional_label_value_2"}; constexpr absl::string_view kDomain1To4 = "domain1.domain2.domain3.domain4"; constexpr absl::string_view kDomain2To4 = "domain2.domain3.domain4"; @@ -58,34 +55,37 @@ TEST_F(MetricsTest, UInt64Counter) { auto plugin3 = MakeStatsPluginForTarget(kDomain3To4); GlobalStatsPluginRegistry::GetStatsPluginsForChannel( StatsPluginChannelScope(kDomain1To4, "")) - .AddCounter(uint64_counter_handle, 1, kLabelValues, kOptionalLabelValues); + .AddCounter(uint64_counter_handle, uint64_t(1), kLabelValues, + kOptionalLabelValues); GlobalStatsPluginRegistry::GetStatsPluginsForChannel( StatsPluginChannelScope(kDomain2To4, "")) - .AddCounter(uint64_counter_handle, 2, kLabelValues, kOptionalLabelValues); + .AddCounter(uint64_counter_handle, uint64_t(2), kLabelValues, + kOptionalLabelValues); GlobalStatsPluginRegistry::GetStatsPluginsForChannel( StatsPluginChannelScope(kDomain3To4, "")) - .AddCounter(uint64_counter_handle, 3, kLabelValues, kOptionalLabelValues); - EXPECT_THAT(plugin1->GetCounterValue(uint64_counter_handle, kLabelValues, - kOptionalLabelValues), + .AddCounter(uint64_counter_handle, uint64_t(3), kLabelValues, + kOptionalLabelValues); + EXPECT_THAT(plugin1->GetUInt64CounterValue( + uint64_counter_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(1)); - EXPECT_THAT(plugin2->GetCounterValue(uint64_counter_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetUInt64CounterValue( + uint64_counter_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(3)); - EXPECT_THAT(plugin3->GetCounterValue(uint64_counter_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin3->GetUInt64CounterValue( + uint64_counter_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(6)); } TEST_F(MetricsTest, DoubleCounter) { - const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; - const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", - "optional_label_key_2"}; - auto double_counter_handle = GlobalInstrumentsRegistry::RegisterDoubleCounter( - "double_counter", "A simple double counter.", "unit", kLabelKeys, - kOptionalLabelKeys, true); - constexpr absl::string_view kLabelValues[] = {"label_value_1", - "label_value_2"}; - constexpr absl::string_view kOptionalLabelValues[] = { + auto double_counter_handle = + GlobalInstrumentsRegistry::RegisterDoubleCounter( + "double_counter", "A simple double counter.", "unit", true) + .Labels("label_key_1", "label_key_2") + .OptionalLabels("optional_label_key_1", "optional_label_key_2") + .Build(); + std::array kLabelValues = {"label_value_1", + "label_value_2"}; + std::array kOptionalLabelValues = { "optional_label_value_1", "optional_label_value_2"}; constexpr absl::string_view kDomain1To4 = "domain1.domain2.domain3.domain4"; constexpr absl::string_view kDomain2To4 = "domain2.domain3.domain4"; @@ -105,28 +105,27 @@ TEST_F(MetricsTest, DoubleCounter) { StatsPluginChannelScope(kDomain3To4, "")) .AddCounter(double_counter_handle, 3.45, kLabelValues, kOptionalLabelValues); - EXPECT_THAT(plugin1->GetCounterValue(double_counter_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetDoubleCounterValue( + double_counter_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(1.23)); - EXPECT_THAT(plugin2->GetCounterValue(double_counter_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetDoubleCounterValue( + double_counter_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(3.57)); - EXPECT_THAT(plugin3->GetCounterValue(double_counter_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin3->GetDoubleCounterValue( + double_counter_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(7.02)); } TEST_F(MetricsTest, UInt64Histogram) { - const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; - const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", - "optional_label_key_2"}; auto uint64_histogram_handle = GlobalInstrumentsRegistry::RegisterUInt64Histogram( - "uint64_histogram", "A simple uint64 histogram.", "unit", kLabelKeys, - kOptionalLabelKeys, true); - constexpr absl::string_view kLabelValues[] = {"label_value_1", - "label_value_2"}; - constexpr absl::string_view kOptionalLabelValues[] = { + "uint64_histogram", "A simple uint64 histogram.", "unit", true) + .Labels("label_key_1", "label_key_2") + .OptionalLabels("optional_label_key_1", "optional_label_key_2") + .Build(); + std::array kLabelValues = {"label_value_1", + "label_value_2"}; + std::array kOptionalLabelValues = { "optional_label_value_1", "optional_label_value_2"}; constexpr absl::string_view kDomain1To4 = "domain1.domain2.domain3.domain4"; constexpr absl::string_view kDomain2To4 = "domain2.domain3.domain4"; @@ -136,38 +135,37 @@ TEST_F(MetricsTest, UInt64Histogram) { auto plugin3 = MakeStatsPluginForTarget(kDomain3To4); GlobalStatsPluginRegistry::GetStatsPluginsForChannel( StatsPluginChannelScope(kDomain1To4, "")) - .RecordHistogram(uint64_histogram_handle, 1, kLabelValues, + .RecordHistogram(uint64_histogram_handle, uint64_t(1), kLabelValues, kOptionalLabelValues); GlobalStatsPluginRegistry::GetStatsPluginsForChannel( StatsPluginChannelScope(kDomain2To4, "")) - .RecordHistogram(uint64_histogram_handle, 2, kLabelValues, + .RecordHistogram(uint64_histogram_handle, uint64_t(2), kLabelValues, kOptionalLabelValues); GlobalStatsPluginRegistry::GetStatsPluginsForChannel( StatsPluginChannelScope(kDomain3To4, "")) - .RecordHistogram(uint64_histogram_handle, 3, kLabelValues, + .RecordHistogram(uint64_histogram_handle, uint64_t(3), kLabelValues, kOptionalLabelValues); - EXPECT_THAT(plugin1->GetHistogramValue(uint64_histogram_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetUInt64HistogramValue( + uint64_histogram_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(::testing::UnorderedElementsAre(1))); - EXPECT_THAT(plugin2->GetHistogramValue(uint64_histogram_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetUInt64HistogramValue( + uint64_histogram_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(::testing::UnorderedElementsAre(1, 2))); - EXPECT_THAT(plugin3->GetHistogramValue(uint64_histogram_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin3->GetUInt64HistogramValue( + uint64_histogram_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(::testing::UnorderedElementsAre(1, 2, 3))); } TEST_F(MetricsTest, DoubleHistogram) { - const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; - const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", - "optional_label_key_2"}; auto double_histogram_handle = GlobalInstrumentsRegistry::RegisterDoubleHistogram( - "double_histogram", "A simple double histogram.", "unit", kLabelKeys, - kOptionalLabelKeys, true); - constexpr absl::string_view kLabelValues[] = {"label_value_1", - "label_value_2"}; - constexpr absl::string_view kOptionalLabelValues[] = { + "double_histogram", "A simple double histogram.", "unit", true) + .Labels("label_key_1", "label_key_2") + .OptionalLabels("optional_label_key_1", "optional_label_key_2") + .Build(); + std::array kLabelValues = {"label_value_1", + "label_value_2"}; + std::array kOptionalLabelValues = { "optional_label_value_1", "optional_label_value_2"}; constexpr absl::string_view kDomain1To4 = "domain1.domain2.domain3.domain4"; constexpr absl::string_view kDomain2To4 = "domain2.domain3.domain4"; @@ -187,31 +185,30 @@ TEST_F(MetricsTest, DoubleHistogram) { StatsPluginChannelScope(kDomain3To4, "")) .RecordHistogram(double_histogram_handle, 3.45, kLabelValues, kOptionalLabelValues); - EXPECT_THAT(plugin1->GetHistogramValue(double_histogram_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetDoubleHistogramValue( + double_histogram_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(::testing::UnorderedElementsAre(1.23))); - EXPECT_THAT(plugin2->GetHistogramValue(double_histogram_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetDoubleHistogramValue( + double_histogram_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(::testing::UnorderedElementsAre(1.23, 2.34))); EXPECT_THAT( - plugin3->GetHistogramValue(double_histogram_handle, kLabelValues, - kOptionalLabelValues), + plugin3->GetDoubleHistogramValue(double_histogram_handle, kLabelValues, + kOptionalLabelValues), ::testing::Optional(::testing::UnorderedElementsAre(1.23, 2.34, 3.45))); } TEST_F(MetricsTest, Int64CallbackGauge) { - const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; - const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", - "optional_label_key_2"}; auto int64_gauge_handle = GlobalInstrumentsRegistry::RegisterCallbackInt64Gauge( - "int64_gauge", "A simple int64 gauge.", "unit", kLabelKeys, - kOptionalLabelKeys, true); - constexpr absl::string_view kLabelValues[] = {"label_value_1", - "label_value_2"}; - constexpr absl::string_view kLabelValues2[] = {"label_value_3", - "label_value_2"}; - constexpr absl::string_view kOptionalLabelValues[] = { + "int64_gauge", "A simple int64 gauge.", "unit", true) + .Labels("label_key_1", "label_key_2") + .OptionalLabels("optional_label_key_1", "optional_label_key_2") + .Build(); + std::array kLabelValues = {"label_value_1", + "label_value_2"}; + std::array kLabelValues2 = {"label_value_3", + "label_value_2"}; + std::array kOptionalLabelValues = { "optional_label_value_1", "optional_label_value_2"}; constexpr absl::string_view kDomain1To4 = "domain1.domain2.domain3.domain4"; constexpr absl::string_view kDomain2To4 = "domain2.domain3.domain4"; @@ -221,184 +218,184 @@ TEST_F(MetricsTest, Int64CallbackGauge) { auto plugin3 = MakeStatsPluginForTarget(kDomain1To4); // Register two callbacks that set the same metric but with different // label values. The callbacks get used only by plugin1. - gpr_log(GPR_INFO, "testing callbacks for: plugin1"); + LOG(INFO) << "testing callbacks for: plugin1"; auto group1 = GlobalStatsPluginRegistry::GetStatsPluginsForChannel( StatsPluginChannelScope(kDomain3To4, "")); auto callback1 = group1.RegisterCallback( [&](CallbackMetricReporter& reporter) { - reporter.Report(int64_gauge_handle, 1, kLabelValues, + reporter.Report(int64_gauge_handle, int64_t(1), kLabelValues, kOptionalLabelValues); }, - {int64_gauge_handle}); + Duration::Seconds(5), int64_gauge_handle); auto callback2 = group1.RegisterCallback( [&](CallbackMetricReporter& reporter) { - reporter.Report(int64_gauge_handle, 2, kLabelValues2, + reporter.Report(int64_gauge_handle, int64_t(2), kLabelValues2, kOptionalLabelValues); }, - {int64_gauge_handle}); + Duration::Seconds(5), int64_gauge_handle); // No plugins have data yet. - EXPECT_EQ(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin1->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin1->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin2->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin2->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); // Now invoke the callbacks. plugin1->TriggerCallbacks(); plugin2->TriggerCallbacks(); plugin3->TriggerCallbacks(); // Now plugin1 should have data, but the others should not. - EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(1)); - EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(2)); - EXPECT_EQ(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin2->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin2->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); // De-register the callbacks. callback1.reset(); callback2.reset(); // Now register callbacks that hit both plugin1 and plugin2. - gpr_log(GPR_INFO, "testing callbacks for: plugin1, plugin2"); + LOG(INFO) << "testing callbacks for: plugin1, plugin2"; auto group2 = GlobalStatsPluginRegistry::GetStatsPluginsForChannel( StatsPluginChannelScope(kDomain2To4, "")); callback1 = group2.RegisterCallback( [&](CallbackMetricReporter& reporter) { - reporter.Report(int64_gauge_handle, 3, kLabelValues, + reporter.Report(int64_gauge_handle, int64_t(3), kLabelValues, kOptionalLabelValues); }, - {int64_gauge_handle}); + Duration::Seconds(5), int64_gauge_handle); callback2 = group2.RegisterCallback( [&](CallbackMetricReporter& reporter) { - reporter.Report(int64_gauge_handle, 4, kLabelValues2, + reporter.Report(int64_gauge_handle, int64_t(4), kLabelValues2, kOptionalLabelValues); }, - {int64_gauge_handle}); + Duration::Seconds(5), int64_gauge_handle); // Plugin1 still has data from before, but the others have none. - EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(1)); - EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(2)); - EXPECT_EQ(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin2->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin2->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); // Now invoke the callbacks. plugin1->TriggerCallbacks(); plugin2->TriggerCallbacks(); plugin3->TriggerCallbacks(); // Now plugin1 and plugin2 should have data, but plugin3 should not. - EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(3)); - EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(4)); - EXPECT_THAT(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(3)); - EXPECT_THAT(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(4)); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); // De-register the callbacks. callback1.reset(); callback2.reset(); // Now register callbacks that hit all three plugins. - gpr_log(GPR_INFO, "testing callbacks for: plugin1, plugin2, plugin3"); + LOG(INFO) << "testing callbacks for: plugin1, plugin2, plugin3"; auto group3 = GlobalStatsPluginRegistry::GetStatsPluginsForChannel( StatsPluginChannelScope(kDomain1To4, "")); callback1 = group3.RegisterCallback( [&](CallbackMetricReporter& reporter) { - reporter.Report(int64_gauge_handle, 5, kLabelValues, + reporter.Report(int64_gauge_handle, int64_t(5), kLabelValues, kOptionalLabelValues); }, - {int64_gauge_handle}); + Duration::Seconds(5), int64_gauge_handle); callback2 = group3.RegisterCallback( [&](CallbackMetricReporter& reporter) { - reporter.Report(int64_gauge_handle, 6, kLabelValues2, + reporter.Report(int64_gauge_handle, int64_t(6), kLabelValues2, kOptionalLabelValues); }, - {int64_gauge_handle}); + Duration::Seconds(5), int64_gauge_handle); // Plugin1 and plugin2 still has data from before, but plugin3 has none. - EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(3)); - EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(4)); - EXPECT_THAT(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(3)); - EXPECT_THAT(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(4)); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); // Now invoke the callbacks. plugin1->TriggerCallbacks(); plugin2->TriggerCallbacks(); plugin3->TriggerCallbacks(); // Now plugin1 and plugin2 should have data, but plugin3 should not. - EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(5)); - EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(6)); - EXPECT_THAT(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(5)); - EXPECT_THAT(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(6)); - EXPECT_THAT(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin3->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(5)); - EXPECT_THAT(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin3->GetInt64CallbackGaugeValue( + int64_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(6)); // Need to destroy callbacks before the plugin group that created them. callback1.reset(); @@ -406,18 +403,17 @@ TEST_F(MetricsTest, Int64CallbackGauge) { } TEST_F(MetricsTest, DoubleCallbackGauge) { - const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; - const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", - "optional_label_key_2"}; auto double_gauge_handle = GlobalInstrumentsRegistry::RegisterCallbackDoubleGauge( - "double_gauge", "A simple double gauge.", "unit", kLabelKeys, - kOptionalLabelKeys, true); - constexpr absl::string_view kLabelValues[] = {"label_value_1", - "label_value_2"}; - constexpr absl::string_view kLabelValues2[] = {"label_value_3", - "label_value_2"}; - constexpr absl::string_view kOptionalLabelValues[] = { + "double_gauge", "A simple double gauge.", "unit", true) + .Labels("label_key_1", "label_key_2") + .OptionalLabels("optional_label_key_1", "optional_label_key_2") + .Build(); + std::array kLabelValues = {"label_value_1", + "label_value_2"}; + std::array kLabelValues2 = {"label_value_3", + "label_value_2"}; + std::array kOptionalLabelValues = { "optional_label_value_1", "optional_label_value_2"}; constexpr absl::string_view kDomain1To4 = "domain1.domain2.domain3.domain4"; constexpr absl::string_view kDomain2To4 = "domain2.domain3.domain4"; @@ -427,7 +423,7 @@ TEST_F(MetricsTest, DoubleCallbackGauge) { auto plugin3 = MakeStatsPluginForTarget(kDomain1To4); // Register two callbacks that set the same metric but with different // label values. The callbacks get used only by plugin1. - gpr_log(GPR_INFO, "testing callbacks for: plugin1"); + LOG(INFO) << "testing callbacks for: plugin1"; auto group1 = GlobalStatsPluginRegistry::GetStatsPluginsForChannel( StatsPluginChannelScope(kDomain3To4, "")); auto callback1 = group1.RegisterCallback( @@ -435,60 +431,60 @@ TEST_F(MetricsTest, DoubleCallbackGauge) { reporter.Report(double_gauge_handle, 1.23, kLabelValues, kOptionalLabelValues); }, - {double_gauge_handle}); + Duration::Seconds(5), double_gauge_handle); auto callback2 = group1.RegisterCallback( [&](CallbackMetricReporter& reporter) { reporter.Report(double_gauge_handle, 2.34, kLabelValues2, kOptionalLabelValues); }, - {double_gauge_handle}); + Duration::Seconds(5), double_gauge_handle); // No plugins have data yet. - EXPECT_EQ(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin1->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin1->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin2->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin2->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); // Now invoke the callbacks. plugin1->TriggerCallbacks(); plugin2->TriggerCallbacks(); plugin3->TriggerCallbacks(); // Now plugin1 should have data, but the others should not. - EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(1.23)); - EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(2.34)); - EXPECT_EQ(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin2->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin2->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); // De-register the callbacks. callback1.reset(); callback2.reset(); // Now register callbacks that hit both plugin1 and plugin2. - gpr_log(GPR_INFO, "testing callbacks for: plugin1, plugin2"); + LOG(INFO) << "testing callbacks for: plugin1, plugin2"; auto group2 = GlobalStatsPluginRegistry::GetStatsPluginsForChannel( StatsPluginChannelScope(kDomain2To4, "")); callback1 = group2.RegisterCallback( @@ -496,60 +492,60 @@ TEST_F(MetricsTest, DoubleCallbackGauge) { reporter.Report(double_gauge_handle, 3.45, kLabelValues, kOptionalLabelValues); }, - {double_gauge_handle}); + Duration::Seconds(5), double_gauge_handle); callback2 = group2.RegisterCallback( [&](CallbackMetricReporter& reporter) { reporter.Report(double_gauge_handle, 4.56, kLabelValues2, kOptionalLabelValues); }, - {double_gauge_handle}); + Duration::Seconds(5), double_gauge_handle); // Plugin1 still has data from before, but the others have none. - EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(1.23)); - EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(2.34)); - EXPECT_EQ(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin2->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin2->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); // Now invoke the callbacks. plugin1->TriggerCallbacks(); plugin2->TriggerCallbacks(); plugin3->TriggerCallbacks(); // Now plugin1 and plugin2 should have data, but plugin3 should not. - EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(3.45)); - EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(4.56)); - EXPECT_THAT(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(3.45)); - EXPECT_THAT(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(4.56)); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); // De-register the callbacks. callback1.reset(); callback2.reset(); // Now register callbacks that hit all three plugins. - gpr_log(GPR_INFO, "testing callbacks for: plugin1, plugin2, plugin3"); + LOG(INFO) << "testing callbacks for: plugin1, plugin2, plugin3"; auto group3 = GlobalStatsPluginRegistry::GetStatsPluginsForChannel( StatsPluginChannelScope(kDomain1To4, "")); callback1 = group3.RegisterCallback( @@ -557,54 +553,54 @@ TEST_F(MetricsTest, DoubleCallbackGauge) { reporter.Report(double_gauge_handle, 5.67, kLabelValues, kOptionalLabelValues); }, - {double_gauge_handle}); + Duration::Seconds(5), double_gauge_handle); callback2 = group3.RegisterCallback( [&](CallbackMetricReporter& reporter) { reporter.Report(double_gauge_handle, 6.78, kLabelValues2, kOptionalLabelValues); }, - {double_gauge_handle}); + Duration::Seconds(5), double_gauge_handle); // Plugin1 and plugin2 still has data from before, but plugin3 has none. - EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(3.45)); - EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(4.56)); - EXPECT_THAT(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(3.45)); - EXPECT_THAT(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(4.56)); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), absl::nullopt); - EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), absl::nullopt); // Now invoke the callbacks. plugin1->TriggerCallbacks(); plugin2->TriggerCallbacks(); plugin3->TriggerCallbacks(); // Now plugin1 and plugin2 should have data, but plugin3 should not. - EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(5.67)); - EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(6.78)); - EXPECT_THAT(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(5.67)); - EXPECT_THAT(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin2->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(6.78)); - EXPECT_THAT(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(plugin3->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues, kOptionalLabelValues), ::testing::Optional(5.67)); - EXPECT_THAT(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, - kOptionalLabelValues), + EXPECT_THAT(plugin3->GetDoubleCallbackGaugeValue( + double_gauge_handle, kLabelValues2, kOptionalLabelValues), ::testing::Optional(6.78)); // Need to destroy callbacks before the plugin group that created them. callback1.reset(); @@ -612,16 +608,15 @@ TEST_F(MetricsTest, DoubleCallbackGauge) { } TEST_F(MetricsTest, DisableByDefaultMetricIsNotRecordedByFakeStatsPlugin) { - const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; - const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", - "optional_label_key_2"}; auto double_histogram_handle = GlobalInstrumentsRegistry::RegisterDoubleHistogram( - "double_histogram", "A simple double histogram.", "unit", kLabelKeys, - kOptionalLabelKeys, /*enable_by_default=*/false); - constexpr absl::string_view kLabelValues[] = {"label_value_1", - "label_value_2"}; - constexpr absl::string_view kOptionalLabelValues[] = { + "double_histogram", "A simple double histogram.", "unit", false) + .Labels("label_key_1", "label_key_2") + .OptionalLabels("optional_label_key_1", "optional_label_key_2") + .Build(); + std::array kLabelValues = {"label_value_1", + "label_value_2"}; + std::array kOptionalLabelValues = { "optional_label_value_1", "optional_label_value_2"}; constexpr absl::string_view kDomain1To4 = "domain1.domain2.domain3.domain4"; auto plugin = MakeStatsPluginForTarget(kDomain1To4); @@ -629,24 +624,26 @@ TEST_F(MetricsTest, DisableByDefaultMetricIsNotRecordedByFakeStatsPlugin) { StatsPluginChannelScope(kDomain1To4, "")) .RecordHistogram(double_histogram_handle, 1.23, kLabelValues, kOptionalLabelValues); - EXPECT_EQ(plugin->GetHistogramValue(double_histogram_handle, kLabelValues, - kOptionalLabelValues), + EXPECT_EQ(plugin->GetDoubleHistogramValue(double_histogram_handle, + kLabelValues, kOptionalLabelValues), absl::nullopt); } using MetricsDeathTest = MetricsTest; TEST_F(MetricsDeathTest, RegisterTheSameMetricNameWouldCrash) { - const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; - const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", - "optional_label_key_2"}; (void)GlobalInstrumentsRegistry::RegisterDoubleHistogram( - "double_histogram", "A simple double histogram.", "unit", kLabelKeys, - kOptionalLabelKeys, true); - EXPECT_DEATH(GlobalInstrumentsRegistry::RegisterDoubleHistogram( - "double_histogram", "A simple double histogram.", "unit", - kLabelKeys, kOptionalLabelKeys, true), - "Metric name double_histogram has already been registered."); + "double_histogram", "A simple double histogram.", "unit", true) + .Labels("label_key_1", "label_key_2") + .OptionalLabels("optional_label_key_1", "optional_label_key_2") + .Build(); + EXPECT_DEATH( + GlobalInstrumentsRegistry::RegisterDoubleHistogram( + "double_histogram", "A simple double histogram.", "unit", true) + .Labels("label_key_1", "label_key_2") + .OptionalLabels("optional_label_key_1", "optional_label_key_2") + .Build(), + "Metric name double_histogram has already been registered."); } } // namespace diff --git a/test/core/channelz/channel_trace_test.cc b/test/core/channelz/channel_trace_test.cc index b46f5730c87..6f99e22b38c 100644 --- a/test/core/channelz/channel_trace_test.cc +++ b/test/core/channelz/channel_trace_test.cc @@ -20,10 +20,12 @@ #include +#include #include #include #include "absl/synchronization/notification.h" +#include "gmock/gmock.h" #include "gtest/gtest.h" #include @@ -43,82 +45,126 @@ namespace grpc_core { namespace channelz { namespace testing { -// testing peer to access channel internals -class ChannelNodePeer { +// Testing peer to access channel internals. +class SubchannelNodePeer { public: - explicit ChannelNodePeer(ChannelNode* node) : node_(node) {} + explicit SubchannelNodePeer(SubchannelNode* node) : node_(node) {} ChannelTrace* trace() const { return &node_->trace_; } private: - ChannelNode* node_; + SubchannelNode* node_; }; size_t GetSizeofTraceEvent() { return sizeof(ChannelTrace::TraceEvent); } namespace { -void ValidateJsonArraySize(const Json& array, size_t expected) { - if (expected == 0) { - ASSERT_EQ(array.type(), Json::Type::kNull); - } else { - ASSERT_EQ(array.type(), Json::Type::kArray); - EXPECT_EQ(array.array().size(), expected); +MATCHER_P(IsJsonString, expected, "is JSON string") { + if (!::testing::ExplainMatchResult(Json::Type::kString, arg.type(), + result_listener)) { + return false; } + return ::testing::ExplainMatchResult(expected, arg.string(), result_listener); } -void ValidateChannelTraceData(const Json& json, - size_t num_events_logged_expected, - size_t actual_num_events_expected) { - ASSERT_EQ(json.type(), Json::Type::kObject); - Json::Object object = json.object(); - Json& num_events_logged_json = object["numEventsLogged"]; - ASSERT_EQ(num_events_logged_json.type(), Json::Type::kString); - size_t num_events_logged = static_cast( - strtol(num_events_logged_json.string().c_str(), nullptr, 0)); - ASSERT_EQ(num_events_logged, num_events_logged_expected); - Json& start_time_json = object["creationTimestamp"]; - ASSERT_EQ(start_time_json.type(), Json::Type::kString); - ValidateJsonArraySize(object["events"], actual_num_events_expected); +MATCHER_P(IsJsonStringNumber, expected, "is JSON string containing number") { + if (!::testing::ExplainMatchResult(Json::Type::kString, arg.type(), + result_listener)) { + return false; + } + int actual; + if (!absl::SimpleAtoi(arg.string(), &actual)) { + *result_listener << "JSON string \"" << arg.string() + << " does not contain numeric value"; + return false; + } + return ::testing::ExplainMatchResult(expected, actual, result_listener); } -void AddSimpleTrace(ChannelTrace* tracer) { - tracer->AddTraceEvent(ChannelTrace::Severity::Info, - grpc_slice_from_static_string("simple trace")); +MATCHER_P(IsJsonObject, matcher, "is JSON object") { + if (!::testing::ExplainMatchResult(Json::Type::kObject, arg.type(), + result_listener)) { + return false; + } + return ::testing::ExplainMatchResult(matcher, arg.object(), result_listener); } -// checks for the existence of all the required members of the tracer. -void ValidateChannelTraceCustom(ChannelTrace* tracer, size_t num_events_logged, - size_t num_events_expected) { - Json json = tracer->RenderJson(); - ASSERT_EQ(json.type(), Json::Type::kObject); - std::string json_str = JsonDump(json); - grpc::testing::ValidateChannelTraceProtoJsonTranslation(json_str.c_str()); - ValidateChannelTraceData(json, num_events_logged, num_events_expected); +MATCHER_P(IsJsonArray, matcher, "is JSON array") { + if (!::testing::ExplainMatchResult(Json::Type::kArray, arg.type(), + result_listener)) { + return false; + } + return ::testing::ExplainMatchResult(matcher, arg.array(), result_listener); } -void ValidateChannelTrace(ChannelTrace* tracer, size_t num_events_logged) { - ValidateChannelTraceCustom(tracer, num_events_logged, num_events_logged); +MATCHER_P2(IsTraceEvent, description, severity, "is trace event") { + return ::testing::ExplainMatchResult( + IsJsonObject(::testing::ElementsAre( + ::testing::Pair("description", IsJsonString(description)), + ::testing::Pair("severity", IsJsonString(severity)), + ::testing::Pair("timestamp", IsJsonString(::testing::_)))), + arg, result_listener); } -class ChannelFixture { - public: - explicit ChannelFixture(int max_tracer_event_memory) { - grpc_arg client_a = grpc_channel_arg_integer_create( - const_cast(GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE), - max_tracer_event_memory); - grpc_channel_args client_args = {1, &client_a}; - grpc_channel_credentials* creds = grpc_insecure_credentials_create(); - channel_ = grpc_channel_create("fake_target", creds, &client_args); - grpc_channel_credentials_release(creds); - } +MATCHER_P3(IsTraceEventWithChannelRef, description, severity, channel_ref, + "is trace event with channel ref") { + return ::testing::ExplainMatchResult( + IsJsonObject(::testing::ElementsAre( + ::testing::Pair("channelRef", + IsJsonObject(::testing::ElementsAre(::testing::Pair( + "channelId", IsJsonStringNumber(channel_ref))))), + ::testing::Pair("description", IsJsonString(description)), + ::testing::Pair("severity", IsJsonString(severity)), + ::testing::Pair("timestamp", IsJsonString(::testing::_)))), + arg, result_listener); +} - ~ChannelFixture() { grpc_channel_destroy(channel_); } +MATCHER_P3(IsTraceEventWithSubchannelRef, description, severity, subchannel_ref, + "is trace event with subchannel ref") { + return ::testing::ExplainMatchResult( + IsJsonObject(::testing::ElementsAre( + ::testing::Pair("description", IsJsonString(description)), + ::testing::Pair("severity", IsJsonString(severity)), + ::testing::Pair( + "subchannelRef", + IsJsonObject(::testing::ElementsAre(::testing::Pair( + "subchannelId", IsJsonStringNumber(subchannel_ref))))), + ::testing::Pair("timestamp", IsJsonString(::testing::_)))), + arg, result_listener); +} - grpc_channel* channel() { return channel_; } +MATCHER(IsEmptyChannelTrace, "is empty channel trace") { + return ::testing::ExplainMatchResult( + IsJsonObject(::testing::ElementsAre( + ::testing::Pair("creationTimestamp", IsJsonString(::testing::_)))), + arg, result_listener); +} - private: - grpc_channel* channel_; -}; +MATCHER_P2(IsChannelTrace, num_events_logged_expected, events_matcher, + "is channel trace") { + return ::testing::ExplainMatchResult( + IsJsonObject(::testing::ElementsAre( + ::testing::Pair("creationTimestamp", IsJsonString(::testing::_)), + ::testing::Pair("events", IsJsonArray(events_matcher)), + ::testing::Pair("numEventsLogged", + IsJsonStringNumber(num_events_logged_expected)))), + arg, result_listener); +} + +MATCHER_P(IsEmptyChannelTrace, num_events_logged_expected, + "is empty channel trace") { + return ::testing::ExplainMatchResult( + IsJsonObject(::testing::ElementsAre( + ::testing::Pair("creationTimestamp", IsJsonString(::testing::_)), + ::testing::Pair("numEventsLogged", + IsJsonStringNumber(num_events_logged_expected)))), + arg, result_listener); +} + +void ValidateJsonProtoTranslation(const Json& json) { + std::string json_str = JsonDump(json); + grpc::testing::ValidateChannelTraceProtoJsonTranslation(json_str); +} } // anonymous namespace @@ -129,21 +175,36 @@ const int kEventListMemoryLimit = 1024 * 1024; TEST(ChannelTracerTest, BasicTest) { ExecCtx exec_ctx; ChannelTrace tracer(kEventListMemoryLimit); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); tracer.AddTraceEvent(ChannelTrace::Severity::Info, - grpc_slice_from_static_string("trace three")); + grpc_slice_from_static_string("one")); + tracer.AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("two")); + tracer.AddTraceEvent(ChannelTrace::Severity::Warning, + grpc_slice_from_static_string("three")); tracer.AddTraceEvent(ChannelTrace::Severity::Error, - grpc_slice_from_static_string("trace four error")); - ValidateChannelTrace(&tracer, 4); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - ValidateChannelTrace(&tracer, 6); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - ValidateChannelTrace(&tracer, 10); + grpc_slice_from_static_string("four")); + Json json = tracer.RenderJson(); + ValidateJsonProtoTranslation(json); + EXPECT_THAT(json, IsChannelTrace(4, ::testing::ElementsAre( + IsTraceEvent("one", "CT_INFO"), + IsTraceEvent("two", "CT_INFO"), + IsTraceEvent("three", "CT_WARNING"), + IsTraceEvent("four", "CT_ERROR")))) + << JsonDump(json); + tracer.AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("five")); + tracer.AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("six")); + json = tracer.RenderJson(); + ValidateJsonProtoTranslation(json); + EXPECT_THAT(json, IsChannelTrace(6, ::testing::ElementsAre( + IsTraceEvent("one", "CT_INFO"), + IsTraceEvent("two", "CT_INFO"), + IsTraceEvent("three", "CT_WARNING"), + IsTraceEvent("four", "CT_ERROR"), + IsTraceEvent("five", "CT_INFO"), + IsTraceEvent("six", "CT_INFO")))) + << JsonDump(json); } // Tests more complex functionality, like a parent channel tracking @@ -152,119 +213,80 @@ TEST(ChannelTracerTest, BasicTest) { TEST(ChannelTracerTest, ComplexTest) { ExecCtx exec_ctx; ChannelTrace tracer(kEventListMemoryLimit); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - ChannelFixture channel1(kEventListMemoryLimit); - RefCountedPtr sc1 = - MakeRefCounted("fake_target", kEventListMemoryLimit, 0); - ChannelNodePeer sc1_peer(sc1.get()); - tracer.AddTraceEventWithReference( - ChannelTrace::Severity::Info, - grpc_slice_from_static_string("subchannel one created"), sc1); - ValidateChannelTrace(&tracer, 3); - AddSimpleTrace(sc1_peer.trace()); - AddSimpleTrace(sc1_peer.trace()); - AddSimpleTrace(sc1_peer.trace()); - ValidateChannelTrace(sc1_peer.trace(), 3); - AddSimpleTrace(sc1_peer.trace()); - AddSimpleTrace(sc1_peer.trace()); - AddSimpleTrace(sc1_peer.trace()); - ValidateChannelTrace(sc1_peer.trace(), 6); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - ValidateChannelTrace(&tracer, 5); - ChannelFixture channel2(kEventListMemoryLimit); - RefCountedPtr sc2 = - MakeRefCounted("fake_target", kEventListMemoryLimit, 0); - tracer.AddTraceEventWithReference( - ChannelTrace::Severity::Info, - grpc_slice_from_static_string("LB channel two created"), sc2); - tracer.AddTraceEventWithReference( - ChannelTrace::Severity::Warning, - grpc_slice_from_static_string("subchannel one inactive"), sc1); - ValidateChannelTrace(&tracer, 7); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - sc1.reset(); - sc2.reset(); -} - -// Test a case in which the parent channel has subchannels and the subchannels -// have connections. Ensures that everything lives as long as it should then -// gets deleted. -TEST(ChannelTracerTest, TestNesting) { - ExecCtx exec_ctx; - ChannelTrace tracer(kEventListMemoryLimit); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - ValidateChannelTrace(&tracer, 2); - ChannelFixture channel1(kEventListMemoryLimit); - RefCountedPtr sc1 = - MakeRefCounted("fake_target", kEventListMemoryLimit, 0); - ChannelNodePeer sc1_peer(sc1.get()); + tracer.AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("one")); + tracer.AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("two")); + auto subchannel_node = MakeRefCounted("ipv4:1.2.3.4:5678", + kEventListMemoryLimit); + auto* subchannel_node_trace = + SubchannelNodePeer(subchannel_node.get()).trace(); tracer.AddTraceEventWithReference( ChannelTrace::Severity::Info, - grpc_slice_from_static_string("subchannel one created"), sc1); - ValidateChannelTrace(&tracer, 3); - AddSimpleTrace(sc1_peer.trace()); - ChannelFixture channel2(kEventListMemoryLimit); - RefCountedPtr conn1 = - MakeRefCounted("fake_target", kEventListMemoryLimit, 0); - ChannelNodePeer conn1_peer(conn1.get()); - // nesting one level deeper. - sc1_peer.trace()->AddTraceEventWithReference( - ChannelTrace::Severity::Info, - grpc_slice_from_static_string("connection one created"), conn1); - ValidateChannelTrace(&tracer, 3); - AddSimpleTrace(conn1_peer.trace()); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - ValidateChannelTrace(&tracer, 5); - ValidateChannelTrace(conn1_peer.trace(), 1); - ChannelFixture channel3(kEventListMemoryLimit); - RefCountedPtr sc2 = + grpc_slice_from_static_string("subchannel one created"), subchannel_node); + Json json = tracer.RenderJson(); + ValidateJsonProtoTranslation(json); + EXPECT_THAT(json, + IsChannelTrace(3, ::testing::ElementsAre( + IsTraceEvent("one", "CT_INFO"), + IsTraceEvent("two", "CT_INFO"), + IsTraceEventWithSubchannelRef( + "subchannel one created", "CT_INFO", + subchannel_node->uuid())))) + << JsonDump(json); + subchannel_node_trace->AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("one")); + json = subchannel_node_trace->RenderJson(); + ValidateJsonProtoTranslation(json); + EXPECT_THAT( + json, + IsChannelTrace(1, ::testing::ElementsAre(IsTraceEvent("one", "CT_INFO")))) + << JsonDump(json); + tracer.AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("three")); + auto channel_node = MakeRefCounted("fake_target", kEventListMemoryLimit, 0); tracer.AddTraceEventWithReference( ChannelTrace::Severity::Info, - grpc_slice_from_static_string("subchannel two created"), sc2); - // this trace should not get added to the parents children since it is already - // present in the tracer. + grpc_slice_from_static_string("LB channel two created"), channel_node); tracer.AddTraceEventWithReference( ChannelTrace::Severity::Warning, - grpc_slice_from_static_string("subchannel one inactive"), sc1); - AddSimpleTrace(&tracer); - ValidateChannelTrace(&tracer, 8); - sc1.reset(); - sc2.reset(); - conn1.reset(); + grpc_slice_from_static_string("subchannel one inactive"), + subchannel_node); + json = tracer.RenderJson(); + ValidateJsonProtoTranslation(json); + EXPECT_THAT( + json, + IsChannelTrace( + 6, + ::testing::ElementsAre( + IsTraceEvent("one", "CT_INFO"), IsTraceEvent("two", "CT_INFO"), + IsTraceEventWithSubchannelRef("subchannel one created", "CT_INFO", + subchannel_node->uuid()), + IsTraceEvent("three", "CT_INFO"), + IsTraceEventWithChannelRef("LB channel two created", "CT_INFO", + channel_node->uuid()), + IsTraceEventWithSubchannelRef("subchannel one inactive", + "CT_WARNING", + subchannel_node->uuid())))) + << JsonDump(json); } TEST(ChannelTracerTest, TestSmallMemoryLimit) { ExecCtx exec_ctx; - // doesn't make sense, but serves a testing purpose for the channel tracing - // bookkeeping. All tracing events added should will get immediately garbage - // collected. + // Doesn't make sense in practice, but serves a testing purpose for the + // channel tracing bookkeeping. All tracing events added should get + // immediately garbage collected. const int kSmallMemoryLimit = 1; ChannelTrace tracer(kSmallMemoryLimit); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - tracer.AddTraceEvent(ChannelTrace::Severity::Info, - grpc_slice_from_static_string("trace three")); - tracer.AddTraceEvent(ChannelTrace::Severity::Error, - grpc_slice_from_static_string("trace four error")); - ValidateChannelTraceCustom(&tracer, 4, 0); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - ValidateChannelTraceCustom(&tracer, 6, 0); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - AddSimpleTrace(&tracer); - ValidateChannelTraceCustom(&tracer, 10, 0); + const size_t kNumEvents = 4; + for (size_t i = 0; i < kNumEvents; ++i) { + tracer.AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("trace")); + } + Json json = tracer.RenderJson(); + ValidateJsonProtoTranslation(json); + EXPECT_THAT(json, IsEmptyChannelTrace(kNumEvents)) << JsonDump(json); } TEST(ChannelTracerTest, TestEviction) { @@ -272,35 +294,60 @@ TEST(ChannelTracerTest, TestEviction) { const int kTraceEventSize = GetSizeofTraceEvent(); const int kNumEvents = 5; ChannelTrace tracer(kTraceEventSize * kNumEvents); + std::list<::testing::Matcher> matchers; for (int i = 1; i <= kNumEvents; ++i) { - AddSimpleTrace(&tracer); - ValidateChannelTrace(&tracer, i); + tracer.AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("trace")); + matchers.push_back(IsTraceEvent("trace", "CT_INFO")); + Json json = tracer.RenderJson(); + ValidateJsonProtoTranslation(json); + EXPECT_THAT(json, IsChannelTrace(i, ::testing::ElementsAreArray(matchers))) + << JsonDump(json); } - // at this point the list is full, and each subsequent enntry will cause an + // At this point the list is full, and each subsequent enntry will cause an // eviction. for (int i = 1; i <= kNumEvents; ++i) { - AddSimpleTrace(&tracer); - ValidateChannelTraceCustom(&tracer, kNumEvents + i, kNumEvents); + tracer.AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("new")); + matchers.pop_front(); + matchers.push_back(IsTraceEvent("new", "CT_INFO")); + Json json = tracer.RenderJson(); + ValidateJsonProtoTranslation(json); + EXPECT_THAT(json, IsChannelTrace(kNumEvents + i, + ::testing::ElementsAreArray(matchers))) + << JsonDump(json); } } TEST(ChannelTracerTest, TestMultipleEviction) { ExecCtx exec_ctx; - const int kTraceEventSize = GetSizeofTraceEvent(); + const size_t kTraceEventSize = GetSizeofTraceEvent(); const int kNumEvents = 5; ChannelTrace tracer(kTraceEventSize * kNumEvents); + std::list<::testing::Matcher> matchers; for (int i = 1; i <= kNumEvents; ++i) { - AddSimpleTrace(&tracer); - ValidateChannelTrace(&tracer, i); + tracer.AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("trace")); + matchers.push_back(IsTraceEvent("trace", "CT_INFO")); + Json json = tracer.RenderJson(); + ValidateJsonProtoTranslation(json); + EXPECT_THAT(json, IsChannelTrace(i, ::testing::ElementsAreArray(matchers))) + << JsonDump(json); } - // at this point the list is full, and each subsequent enntry will cause an + // At this point the list is full, and each subsequent enntry will cause an // eviction. We will now add in a trace event that has a copied string. This - // uses more memory, so it will cause a double eviciction - tracer.AddTraceEvent( - ChannelTrace::Severity::Info, - grpc_slice_from_copied_string( - "long enough string to trigger a multiple eviction")); - ValidateChannelTraceCustom(&tracer, kNumEvents + 1, kNumEvents - 1); + // uses more memory, so it will cause a double eviciction. + std::string msg(GRPC_SLICE_INLINED_SIZE + 1, 'x'); + tracer.AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_cpp_string(msg)); + matchers.pop_front(); + matchers.pop_front(); + matchers.push_back(IsTraceEvent(msg, "CT_INFO")); + Json json = tracer.RenderJson(); + ValidateJsonProtoTranslation(json); + EXPECT_THAT(json, IsChannelTrace(kNumEvents + 1, + ::testing::ElementsAreArray(matchers))) + << JsonDump(json); } TEST(ChannelTracerTest, TestTotalEviction) { @@ -308,15 +355,23 @@ TEST(ChannelTracerTest, TestTotalEviction) { const int kTraceEventSize = GetSizeofTraceEvent(); const int kNumEvents = 5; ChannelTrace tracer(kTraceEventSize * kNumEvents); + std::list<::testing::Matcher> matchers; for (int i = 1; i <= kNumEvents; ++i) { - AddSimpleTrace(&tracer); - ValidateChannelTrace(&tracer, i); + tracer.AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("trace")); + matchers.push_back(IsTraceEvent("trace", "CT_INFO")); + Json json = tracer.RenderJson(); + ValidateJsonProtoTranslation(json); + EXPECT_THAT(json, IsChannelTrace(i, ::testing::ElementsAreArray(matchers))) + << JsonDump(json); } - // at this point the list is full. Now we add such a big slice that + // At this point the list is full. Now we add such a big slice that // everything gets evicted. grpc_slice huge_slice = grpc_slice_malloc(kTraceEventSize * (kNumEvents + 1)); tracer.AddTraceEvent(ChannelTrace::Severity::Info, huge_slice); - ValidateChannelTraceCustom(&tracer, kNumEvents + 1, 0); + Json json = tracer.RenderJson(); + ValidateJsonProtoTranslation(json); + EXPECT_THAT(json, IsEmptyChannelTrace(kNumEvents + 1)) << JsonDump(json); } // Tests that the code is thread-safe. @@ -328,7 +383,8 @@ TEST(ChannelTracerTest, ThreadSafety) { for (size_t i = 0; i < 10; ++i) { threads.push_back(std::make_unique([&]() { do { - AddSimpleTrace(&tracer); + tracer.AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("trace")); } while (!done.HasBeenNotified()); })); } diff --git a/test/core/channelz/channelz_test.cc b/test/core/channelz/channelz_test.cc index bd82d6c50f3..7c591711c6b 100644 --- a/test/core/channelz/channelz_test.cc +++ b/test/core/channelz/channelz_test.cc @@ -42,13 +42,13 @@ #include "src/core/channelz/channelz_registry.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/event_engine/default_event_engine.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/notification.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/json/json.h" #include "src/core/lib/json/json_reader.h" #include "src/core/lib/surface/channel.h" #include "src/core/server/server.h" +#include "src/core/util/useful.h" #include "test/core/event_engine/event_engine_test_utils.h" #include "test/core/test_util/test_config.h" #include "test/cpp/util/channel_trace_proto_helper.h" diff --git a/test/core/compression/BUILD b/test/core/compression/BUILD index d6825f63e41..21746ffd776 100644 --- a/test/core/compression/BUILD +++ b/test/core/compression/BUILD @@ -26,7 +26,10 @@ licenses(["notice"]) grpc_cc_test( name = "compression_test", srcs = ["compression_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", uses_event_engine = False, uses_polling = False, @@ -67,7 +70,10 @@ grpc_fuzzer( grpc_cc_test( name = "message_compress_test", srcs = ["message_compress_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", uses_event_engine = False, uses_polling = False, diff --git a/test/core/compression/compression_test.cc b/test/core/compression/compression_test.cc index 2297e5c8303..9ed5b61b042 100644 --- a/test/core/compression/compression_test.cc +++ b/test/core/compression/compression_test.cc @@ -21,13 +21,13 @@ #include +#include "absl/log/log.h" #include "gtest/gtest.h" #include #include -#include -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" TEST(CompressionTest, CompressionAlgorithmParse) { @@ -40,7 +40,7 @@ TEST(CompressionTest, CompressionAlgorithmParse) { }; const char* invalid_names[] = {"gzip2", "foo", "", "2gzip"}; - gpr_log(GPR_DEBUG, "test_compression_algorithm_parse"); + VLOG(2) << "test_compression_algorithm_parse"; for (i = 0; i < GPR_ARRAY_SIZE(valid_names); i++) { const char* valid_name = valid_names[i]; @@ -73,7 +73,7 @@ TEST(CompressionTest, CompressionAlgorithmName) { GRPC_COMPRESS_DEFLATE, }; - gpr_log(GPR_DEBUG, "test_compression_algorithm_name"); + VLOG(2) << "test_compression_algorithm_name"; for (i = 0; i < GPR_ARRAY_SIZE(valid_algorithms); i++) { success = grpc_compression_algorithm_name(valid_algorithms[i], &name); @@ -88,7 +88,7 @@ TEST(CompressionTest, CompressionAlgorithmName) { } TEST(CompressionTest, CompressionAlgorithmForLevel) { - gpr_log(GPR_DEBUG, "test_compression_algorithm_for_level"); + VLOG(2) << "test_compression_algorithm_for_level"; { // accept only identity (aka none) @@ -211,7 +211,7 @@ TEST(CompressionTest, CompressionEnableDisableAlgorithm) { grpc_compression_options options; grpc_compression_algorithm algorithm; - gpr_log(GPR_DEBUG, "test_compression_enable_disable_algorithm"); + VLOG(2) << "test_compression_enable_disable_algorithm"; grpc_compression_options_init(&options); for (algorithm = GRPC_COMPRESS_NONE; diff --git a/test/core/compression/message_compress_test.cc b/test/core/compression/message_compress_test.cc index b3cf8ba7e47..9110456d054 100644 --- a/test/core/compression/message_compress_test.cc +++ b/test/core/compression/message_compress_test.cc @@ -28,10 +28,9 @@ #include #include -#include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/util/useful.h" #include "test/core/test_util/slice_splitter.h" #include "test/core/test_util/test_config.h" diff --git a/test/core/end2end/BUILD b/test/core/end2end/BUILD index 08c373e425d..597fb7c0c26 100644 --- a/test/core/end2end/BUILD +++ b/test/core/end2end/BUILD @@ -28,6 +28,7 @@ grpc_cc_library( "absl/container:flat_hash_map", "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/strings", "absl/strings:str_format", "absl/types:variant", @@ -64,6 +65,7 @@ grpc_cc_library( hdrs = ["fixtures/http_proxy_fixture.h"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -96,7 +98,10 @@ grpc_cc_library( name = "proxy", srcs = ["fixtures/proxy.cc"], hdrs = ["fixtures/proxy.h"], - external_deps = ["absl/log:check"], + external_deps = [ + "absl/log:check", + "absl/log:log", + ], language = "C++", deps = [ "//:channel_arg_names", @@ -120,6 +125,7 @@ grpc_cc_library( external_deps = [ "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/memory", "absl/meta:type_traits", "absl/random", @@ -500,7 +506,10 @@ grpc_core_end2end_test(name = "write_buffering_at_end") grpc_cc_test( name = "bad_server_response_test", srcs = ["bad_server_response_test.cc"], - external_deps = ["absl/log:check"], + external_deps = [ + "absl/log:check", + "absl/log:log", + ], language = "C++", deps = [ "cq_verifier", @@ -523,7 +532,10 @@ grpc_cc_test( grpc_cc_test( name = "connection_refused_test", srcs = ["connection_refused_test.cc"], - external_deps = ["absl/log:check"], + external_deps = [ + "absl/log:check", + "absl/log:log", + ], language = "C++", deps = [ "cq_verifier", @@ -541,6 +553,7 @@ grpc_cc_test( srcs = ["dualstack_socket_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status:statusor", "absl/strings", "absl/strings:str_format", @@ -565,6 +578,7 @@ grpc_cc_test( srcs = ["goaway_server_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -596,7 +610,10 @@ grpc_cc_test( grpc_cc_test( name = "invalid_call_argument_test", srcs = ["invalid_call_argument_test.cc"], - external_deps = ["absl/log:check"], + external_deps = [ + "absl/log:check", + "absl/log:log", + ], language = "C++", deps = [ "cq_verifier", @@ -623,6 +640,7 @@ grpc_cc_test( srcs = ["no_server_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/time", @@ -652,6 +670,7 @@ grpc_cc_test( external_deps = [ "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/memory", "absl/meta:type_traits", "absl/strings", diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index eb9b0c09a2f..03a7e937a9c 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -25,6 +25,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -35,12 +36,10 @@ #include #include #include -#include #include #include #include "src/core/lib/event_engine/shim.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/notification.h" #include "src/core/lib/gprpp/status_helper.h" @@ -52,6 +51,7 @@ #include "src/core/lib/iomgr/iomgr_fwd.h" #include "src/core/lib/iomgr/tcp_server.h" #include "src/core/lib/slice/slice_string_helpers.h" +#include "src/core/util/string.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/test_util/port.h" #include "test/core/test_util/test_config.h" @@ -135,8 +135,7 @@ static void handle_write() { static void handle_read(void* /*arg*/, grpc_error_handle error) { if (!error.ok()) { - gpr_log(GPR_ERROR, "handle_read error: %s", - grpc_core::StatusToString(error).c_str()); + LOG(ERROR) << "handle_read error: " << grpc_core::StatusToString(error); return; } state.incoming_data_length += state.temp_incoming_buffer.length; @@ -145,15 +144,13 @@ static void handle_read(void* /*arg*/, grpc_error_handle error) { for (i = 0; i < state.temp_incoming_buffer.count; i++) { char* dump = grpc_dump_slice(state.temp_incoming_buffer.slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "Server received: %s", dump); + VLOG(2) << "Server received: " << dump; gpr_free(dump); } - gpr_log(GPR_DEBUG, - "got %" PRIuPTR " bytes, expected %" PRIuPTR - " bytes or a non-HTTP2 response to be sent", - state.incoming_data_length, - SERVER_INCOMING_DATA_LENGTH_LOWER_THRESHOLD); + VLOG(2) << "got " << state.incoming_data_length << " bytes, expected " + << SERVER_INCOMING_DATA_LENGTH_LOWER_THRESHOLD + << " bytes or a non-HTTP2 response to be sent"; if (state.incoming_data_length >= SERVER_INCOMING_DATA_LENGTH_LOWER_THRESHOLD || !state.http2_response) { @@ -299,8 +296,8 @@ static void actually_poll_server(void* arg) { bool done = gpr_atm_acq_load(&state.done_atm) != 0; gpr_timespec time_left = gpr_time_sub(deadline, gpr_now(GPR_CLOCK_REALTIME)); - gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRId64 ".%09d", done, - time_left.tv_sec, time_left.tv_nsec); + VLOG(2) << "done=" << done << ", time_left=" << time_left.tv_sec << "." + << time_left.tv_nsec; if (done || gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) < 0) { break; } diff --git a/test/core/end2end/connection_refused_test.cc b/test/core/end2end/connection_refused_test.cc index 055e115a286..1e3414b8875 100644 --- a/test/core/end2end/connection_refused_test.cc +++ b/test/core/end2end/connection_refused_test.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -29,7 +30,6 @@ #include #include #include -#include #include #include "src/core/lib/channel/channel_args.h" @@ -49,8 +49,8 @@ static void run_test(bool wait_for_ready, bool use_service_config) { grpc_status_code status; grpc_slice details; - gpr_log(GPR_INFO, "TEST: wait_for_ready=%d use_service_config=%d", - wait_for_ready, use_service_config); + LOG(INFO) << "TEST: wait_for_ready=" << wait_for_ready + << " use_service_config=" << use_service_config; grpc_init(); @@ -81,7 +81,7 @@ static void run_test(bool wait_for_ready, bool use_service_config) { // create a call, channel to a port which will refuse connection int port = grpc_pick_unused_port_or_die(); std::string addr = grpc_core::JoinHostPort("127.0.0.1", port); - gpr_log(GPR_INFO, "server: %s", addr.c_str()); + LOG(INFO) << "server: " << addr; grpc_channel_credentials* creds = grpc_insecure_credentials_create(); chan = grpc_channel_create(addr.c_str(), creds, args); grpc_channel_credentials_release(creds); diff --git a/test/core/end2end/cq_verifier.cc b/test/core/end2end/cq_verifier.cc index c318f7fa301..c0bc5b66f97 100644 --- a/test/core/end2end/cq_verifier.cc +++ b/test/core/end2end/cq_verifier.cc @@ -29,6 +29,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -41,7 +42,6 @@ #include #include #include -#include #include #include "src/core/lib/compression/message_compress.h" @@ -126,9 +126,8 @@ int raw_byte_buffer_eq_slice(grpc_byte_buffer* rbb, grpc_slice b) { 0 == memcmp(GRPC_SLICE_START_PTR(a), GRPC_SLICE_START_PTR(b), GRPC_SLICE_LENGTH(a)); if (!ok) { - gpr_log(GPR_ERROR, - "SLICE MISMATCH: left_length=%" PRIuPTR " right_length=%" PRIuPTR, - GRPC_SLICE_LENGTH(a), GRPC_SLICE_LENGTH(b)); + LOG(ERROR) << "SLICE MISMATCH: left_length=" << GRPC_SLICE_LENGTH(a) + << " right_length=" << GRPC_SLICE_LENGTH(b); std::string out; const char* a_str = reinterpret_cast(GRPC_SLICE_START_PTR(a)); const char* b_str = reinterpret_cast(GRPC_SLICE_START_PTR(b)); @@ -151,7 +150,7 @@ int raw_byte_buffer_eq_slice(grpc_byte_buffer* rbb, grpc_slice b) { absl::CEscape(absl::string_view(&b_str[i], 1)), "\u001b[0m"); } - gpr_log(GPR_ERROR, "%s", out.c_str()); + LOG(ERROR) << out; } } grpc_slice_unref(a); @@ -365,8 +364,7 @@ void CqVerifier::Verify(Duration timeout, SourceLocation location) { while (!expectations_.empty()) { must_log = std::exchange(added_expectations_, false) || must_log; if (log_verifications_ && must_log) { - gpr_log(GPR_ERROR, "Verify %s for %s", ToShortString().c_str(), - timeout.ToString().c_str()); + LOG(ERROR) << "Verify " << ToShortString() << " for " << timeout; } must_log = false; grpc_event ev = Step(deadline); @@ -423,8 +421,7 @@ bool CqVerifier::AllMaybes() const { void CqVerifier::VerifyEmpty(Duration timeout, SourceLocation location) { if (log_verifications_) { - gpr_log(GPR_ERROR, "Verify empty completion queue for %s", - timeout.ToString().c_str()); + LOG(ERROR) << "Verify empty completion queue for " << timeout; } const gpr_timespec deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), timeout.as_timespec()); diff --git a/test/core/end2end/dualstack_socket_test.cc b/test/core/end2end/dualstack_socket_test.cc index bf793e97bec..33ab2091c1b 100644 --- a/test/core/end2end/dualstack_socket_test.cc +++ b/test/core/end2end/dualstack_socket_test.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include @@ -47,7 +48,6 @@ #include #include #include -#include #include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/gprpp/host_port.h" @@ -78,7 +78,7 @@ static void log_resolved_addrs(const char* label, const char* hostname) { return; } for (const auto& addr : *addresses_or) { - gpr_log(GPR_INFO, "%s: %s", label, grpc_sockaddr_to_uri(&addr)->c_str()); + LOG(INFO) << label << ": " << grpc_sockaddr_to_uri(&addr)->c_str(); } } @@ -152,9 +152,9 @@ void test_connect(const char* server_host, const char* client_host, int port, client = grpc_channel_create(client_hostport.c_str(), creds, nullptr); grpc_channel_credentials_release(creds); - gpr_log(GPR_INFO, "Testing with server=%s client=%s (expecting %s)", - server_hostport.c_str(), client_hostport.c_str(), - expect_ok ? "success" : "failure"); + LOG(INFO) << "Testing with server=" << server_hostport.c_str() + << " client=" << client_hostport.c_str() << " (expecting " + << (expect_ok ? "success" : "failure") << ")"; log_resolved_addrs("server resolved addr", server_host); log_resolved_addrs("client resolved addr", client_host); @@ -236,7 +236,7 @@ void test_connect(const char* server_host, const char* client_host, int port, cqv.Verify(); peer = grpc_call_get_peer(c); - gpr_log(GPR_DEBUG, "got peer: '%s'", peer); + VLOG(2) << "got peer: '" << peer << "'"; gpr_free(peer); CHECK_EQ(status, GRPC_STATUS_UNIMPLEMENTED); @@ -251,8 +251,8 @@ void test_connect(const char* server_host, const char* client_host, int port, cqv.Expect(grpc_core::CqVerifier::tag(1), true); cqv.Verify(); - gpr_log(GPR_INFO, "status: %d (expected: %d)", status, - GRPC_STATUS_UNAVAILABLE); + LOG(INFO) << "status: " << status + << " (expected: " << GRPC_STATUS_UNAVAILABLE << ")"; CHECK_EQ(status, GRPC_STATUS_UNAVAILABLE); } @@ -301,10 +301,9 @@ int external_dns_works(const char* host) { // dualstack_socket_test from functioning correctly). See b/201064791. if (grpc_sockaddr_to_uri(&addr).value() == "ipv6:%5B64:ff9b::7f00:1%5D:80") { - gpr_log( - GPR_INFO, - "Detected DNS64 server response. Tests that depend on " - "*.unittest.grpc.io. will be skipped as they won't work with DNS64."); + LOG(INFO) << "Detected DNS64 server response. Tests that depend on " + "*.unittest.grpc.io. will be skipped as they won't work " + "with DNS64."; result = 0; break; } @@ -319,7 +318,7 @@ int main(int argc, char** argv) { grpc_init(); if (!grpc_ipv6_loopback_available()) { - gpr_log(GPR_INFO, "Can't bind to ::1. Skipping IPv6 tests."); + LOG(INFO) << "Can't bind to ::1. Skipping IPv6 tests."; do_ipv6 = 0; } @@ -360,7 +359,7 @@ int main(int argc, char** argv) { if (!external_dns_works("loopback4.unittest.grpc.io") || !external_dns_works("loopback46.unittest.grpc.io")) { - gpr_log(GPR_INFO, "Skipping tests that depend on *.unittest.grpc.io."); + LOG(INFO) << "Skipping tests that depend on *.unittest.grpc.io."; } else { test_connect("loopback46.unittest.grpc.io", "loopback4.unittest.grpc.io", 0, 1); diff --git a/test/core/end2end/end2end_tests.cc b/test/core/end2end/end2end_tests.cc index 30615b1698a..51505c91fd5 100644 --- a/test/core/end2end/end2end_tests.cc +++ b/test/core/end2end/end2end_tests.cc @@ -23,6 +23,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/random/random.h" @@ -117,7 +118,7 @@ void CoreEnd2endTest::TearDown() { // This will wait until gRPC shutdown has actually happened to make sure // no gRPC resources (such as thread) are active. (timeout = 10s) if (!grpc_wait_until_shutdown(10)) { - gpr_log(GPR_ERROR, "Timeout in waiting for gRPC shutdown"); + LOG(ERROR) << "Timeout in waiting for gRPC shutdown"; } } CHECK_EQ(client_, nullptr); @@ -153,8 +154,8 @@ std::string CoreEnd2endTest::IncomingMessage::payload() const { grpc_slice_buffer decompressed_buffer; grpc_slice_buffer_init(&decompressed_buffer); CHECK(grpc_msg_decompress(payload_->data.raw.compression, - &payload_->data.raw.slice_buffer, - &decompressed_buffer)); + &payload_->data.raw.slice_buffer, + &decompressed_buffer)); grpc_byte_buffer* rbb = grpc_raw_byte_buffer_create( decompressed_buffer.slices, decompressed_buffer.count); grpc_byte_buffer_reader reader; diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index be2ec412014..3eca777e098 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -27,6 +27,7 @@ #include #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" @@ -37,7 +38,6 @@ #include #include #include -#include #include #include "src/core/lib/address_utils/sockaddr_utils.h" @@ -510,8 +510,8 @@ static bool proxy_auth_header_matches(absl::string_view proxy_auth_header_val, // which will cause the client connection to be dropped. static void on_read_request_done_locked(void* arg, grpc_error_handle error) { proxy_connection* conn = static_cast(arg); - gpr_log(GPR_DEBUG, "on_read_request_done: %p %s", conn, - grpc_core::StatusToString(error).c_str()); + VLOG(2) << "on_read_request_done: " << conn << " " + << grpc_core::StatusToString(error); if (!error.ok()) { proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", error); @@ -670,7 +670,7 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( // Construct proxy address. const int proxy_port = grpc_pick_unused_port_or_die(); proxy->proxy_name = grpc_core::JoinHostPort("localhost", proxy_port); - gpr_log(GPR_INFO, "Proxy address: %s", proxy->proxy_name.c_str()); + LOG(INFO) << "Proxy address: " << proxy->proxy_name; // Create TCP server. auto channel_args = grpc_core::CoreConfiguration::Get() .channel_args_preconditioning() diff --git a/test/core/end2end/fixtures/proxy.cc b/test/core/end2end/fixtures/proxy.cc index cb1a2e04cb2..febdb809838 100644 --- a/test/core/end2end/fixtures/proxy.cc +++ b/test/core/end2end/fixtures/proxy.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -31,7 +32,6 @@ #include #include #include -#include #include #include @@ -106,8 +106,8 @@ grpc_end2end_proxy* grpc_end2end_proxy_create( proxy->proxy_port = grpc_core::JoinHostPort("localhost", proxy_port); proxy->server_port = grpc_core::JoinHostPort("localhost", server_port); - gpr_log(GPR_DEBUG, "PROXY ADDR:%s BACKEND:%s", proxy->proxy_port.c_str(), - proxy->server_port.c_str()); + VLOG(2) << "PROXY ADDR:" << proxy->proxy_port + << " BACKEND:" << proxy->server_port; proxy->cq = grpc_completion_queue_create_for_next(nullptr); proxy->server = def->create_server(proxy->proxy_port.c_str(), server_args); diff --git a/test/core/end2end/fuzzers/BUILD b/test/core/end2end/fuzzers/BUILD index 35f52f6be3b..c3a1f0245c9 100644 --- a/test/core/end2end/fuzzers/BUILD +++ b/test/core/end2end/fuzzers/BUILD @@ -36,6 +36,7 @@ grpc_cc_library( hdrs = ["fuzzing_common.h"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", ], deps = [ @@ -92,6 +93,7 @@ grpc_cc_library( name = "network_input", srcs = ["network_input.cc"], hdrs = ["network_input.h"], + external_deps = ["absl/log:log"], deps = [ "fuzzer_input_proto", "//:chttp2_frame", diff --git a/test/core/end2end/fuzzers/fuzzing_common.cc b/test/core/end2end/fuzzers/fuzzing_common.cc index 4a20a7870fe..2597694bf3b 100644 --- a/test/core/end2end/fuzzers/fuzzing_common.cc +++ b/test/core/end2end/fuzzers/fuzzing_common.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/types/optional.h" @@ -638,7 +639,7 @@ bool BasicFuzzer::Continue() { BasicFuzzer::Result BasicFuzzer::ExecuteAction( const api_fuzzer::Action& action) { - gpr_log(GPR_DEBUG, "EXECUTE_ACTION: %s", action.DebugString().c_str()); + VLOG(2) << "EXECUTE_ACTION: " << action.DebugString(); switch (action.type_case()) { case api_fuzzer::Action::TYPE_NOT_SET: return BasicFuzzer::Result::kFailed; diff --git a/test/core/end2end/fuzzers/network_input.cc b/test/core/end2end/fuzzers/network_input.cc index 855d3185678..31726db2fd8 100644 --- a/test/core/end2end/fuzzers/network_input.cc +++ b/test/core/end2end/fuzzers/network_input.cc @@ -23,6 +23,7 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/string_view.h" #include "absl/types/span.h" @@ -36,10 +37,10 @@ #include "src/core/lib/config/core_configuration.h" #include "src/core/lib/event_engine/channel_args_endpoint_config.h" #include "src/core/lib/event_engine/tcp_socket_utils.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/slice/slice.h" #include "src/core/lib/slice/slice_buffer.h" +#include "src/core/util/useful.h" #include "test/core/end2end/fuzzers/fuzzer_input.pb.h" #include "test/core/test_util/mock_endpoint.h" @@ -520,8 +521,7 @@ Duration ScheduleConnection( endpoint) mutable { ExecCtx exec_ctx; if (!endpoint.ok()) { - gpr_log(GPR_ERROR, "Failed to connect: %s", - endpoint.status().ToString().c_str()); + LOG(ERROR) << "Failed to connect: " << endpoint.status(); return; } std::shared_ptr ep = diff --git a/test/core/end2end/goaway_server_test.cc b/test/core/end2end/goaway_server_test.cc index 3efd3939364..edf58074223 100644 --- a/test/core/end2end/goaway_server_test.cc +++ b/test/core/end2end/goaway_server_test.cc @@ -27,6 +27,7 @@ #include #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" @@ -40,7 +41,6 @@ #include #include #include -#include #include #include @@ -212,9 +212,8 @@ static void my_cancel_ares_request(grpc_ares_request* request) { int main(int argc, char** argv) { // TODO(yijiem): rewrite this test with a custom EventEngine DNS Resolver if (grpc_core::IsEventEngineDnsEnabled()) { - gpr_log( - GPR_ERROR, - "Skipping iomgr-specific DNS test because EventEngine DNS is enabled"); + LOG(ERROR) << "Skipping iomgr-specific DNS test because EventEngine DNS is " + "enabled"; return 0; } grpc_completion_queue* cq; diff --git a/test/core/end2end/grpc_core_end2end_test.bzl b/test/core/end2end/grpc_core_end2end_test.bzl index 78733efcf2b..8b75ae6aac8 100644 --- a/test/core/end2end/grpc_core_end2end_test.bzl +++ b/test/core/end2end/grpc_core_end2end_test.bzl @@ -43,6 +43,9 @@ def grpc_core_end2end_test(name, shard_count = 10, tags = []): srcs = [ "tests/%s.cc" % name, ], + external_deps = [ + "absl/log:log", + ], deps = [ "cq_verifier", "end2end_test_lib", diff --git a/test/core/end2end/h2_ssl_cert_test.cc b/test/core/end2end/h2_ssl_cert_test.cc index d24c6956235..1a674bde544 100644 --- a/test/core/end2end/h2_ssl_cert_test.cc +++ b/test/core/end2end/h2_ssl_cert_test.cc @@ -25,6 +25,7 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/types/optional.h" #include "gtest/gtest.h" @@ -37,12 +38,11 @@ #include #include #include -#include #include #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/config/config_vars.h" -#include "src/core/lib/gpr/tmpfile.h" +#include "src/core/util/tmpfile.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/data/ssl_test_data.h" #include "test/core/end2end/end2end_tests.h" @@ -245,9 +245,7 @@ static void simple_request_body(grpc_core::CoreTestFixture* f, class H2SslCertTest : public ::testing::TestWithParam { protected: - H2SslCertTest() { - gpr_log(GPR_INFO, "SSL_CERT_tests/%s", GetParam().config.name); - } + H2SslCertTest() { LOG(INFO) << "SSL_CERT_tests/" << GetParam().config.name; } void SetUp() override { fixture_ = GetParam().config.create_fixture(grpc_core::ChannelArgs(), grpc_core::ChannelArgs()); diff --git a/test/core/end2end/h2_ssl_session_reuse_test.cc b/test/core/end2end/h2_ssl_session_reuse_test.cc index 99db3ab8594..e419096114d 100644 --- a/test/core/end2end/h2_ssl_session_reuse_test.cc +++ b/test/core/end2end/h2_ssl_session_reuse_test.cc @@ -38,10 +38,10 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/config/config_vars.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/util/useful.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/test_util/port.h" #include "test/core/test_util/test_config.h" diff --git a/test/core/end2end/h2_tls_peer_property_external_verifier_test.cc b/test/core/end2end/h2_tls_peer_property_external_verifier_test.cc index 054038aef19..e3982feaa4f 100644 --- a/test/core/end2end/h2_tls_peer_property_external_verifier_test.cc +++ b/test/core/end2end/h2_tls_peer_property_external_verifier_test.cc @@ -38,10 +38,10 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/config/config_vars.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/util/useful.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/test_util/port.h" #include "test/core/test_util/test_config.h" diff --git a/test/core/end2end/invalid_call_argument_test.cc b/test/core/end2end/invalid_call_argument_test.cc index a297eb61a3b..1f086c3f98a 100644 --- a/test/core/end2end/invalid_call_argument_test.cc +++ b/test/core/end2end/invalid_call_argument_test.cc @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -32,7 +33,6 @@ #include #include #include -#include #include #include @@ -155,7 +155,7 @@ static void cleanup_test() { } static void test_non_null_reserved_on_start_batch() { - gpr_log(GPR_INFO, "test_non_null_reserved_on_start_batch"); + LOG(INFO) << "test_non_null_reserved_on_start_batch"; prepare_test(1); CHECK(GRPC_CALL_ERROR == @@ -165,7 +165,7 @@ static void test_non_null_reserved_on_start_batch() { } static void test_non_null_reserved_on_op() { - gpr_log(GPR_INFO, "test_non_null_reserved_on_op"); + LOG(INFO) << "test_non_null_reserved_on_op"; grpc_op* op; prepare_test(1); @@ -184,7 +184,7 @@ static void test_non_null_reserved_on_op() { } static void test_send_initial_metadata_more_than_once() { - gpr_log(GPR_INFO, "test_send_initial_metadata_more_than_once"); + LOG(INFO) << "test_send_initial_metadata_more_than_once"; grpc_op* op; prepare_test(1); @@ -216,7 +216,7 @@ static void test_send_initial_metadata_more_than_once() { } static void test_too_many_metadata() { - gpr_log(GPR_INFO, "test_too_many_metadata"); + LOG(INFO) << "test_too_many_metadata"; grpc_op* op; prepare_test(1); @@ -235,7 +235,7 @@ static void test_too_many_metadata() { } static void test_send_null_message() { - gpr_log(GPR_INFO, "test_send_null_message"); + LOG(INFO) << "test_send_null_message"; grpc_op* op; prepare_test(1); @@ -259,7 +259,7 @@ static void test_send_null_message() { } static void test_send_messages_at_the_same_time() { - gpr_log(GPR_INFO, "test_send_messages_at_the_same_time"); + LOG(INFO) << "test_send_messages_at_the_same_time"; grpc_op* op; grpc_slice request_payload_slice = @@ -293,7 +293,7 @@ static void test_send_messages_at_the_same_time() { } static void test_send_server_status_from_client() { - gpr_log(GPR_INFO, "test_send_server_status_from_client"); + LOG(INFO) << "test_send_server_status_from_client"; grpc_op* op; prepare_test(1); @@ -315,7 +315,7 @@ static void test_send_server_status_from_client() { } static void test_receive_initial_metadata_twice_at_client() { - gpr_log(GPR_INFO, "test_receive_initial_metadata_twice_at_client"); + LOG(INFO) << "test_receive_initial_metadata_twice_at_client"; grpc_op* op; prepare_test(1); @@ -347,7 +347,7 @@ static void test_receive_initial_metadata_twice_at_client() { } static void test_receive_message_with_invalid_flags() { - gpr_log(GPR_INFO, "test_receive_message_with_invalid_flags"); + LOG(INFO) << "test_receive_message_with_invalid_flags"; grpc_op* op; grpc_byte_buffer* payload = nullptr; @@ -366,7 +366,7 @@ static void test_receive_message_with_invalid_flags() { } static void test_receive_two_messages_at_the_same_time() { - gpr_log(GPR_INFO, "test_receive_two_messages_at_the_same_time"); + LOG(INFO) << "test_receive_two_messages_at_the_same_time"; grpc_op* op; grpc_byte_buffer* payload = nullptr; @@ -390,7 +390,7 @@ static void test_receive_two_messages_at_the_same_time() { } static void test_recv_close_on_server_from_client() { - gpr_log(GPR_INFO, "test_recv_close_on_server_from_client"); + LOG(INFO) << "test_recv_close_on_server_from_client"; grpc_op* op; prepare_test(1); @@ -409,7 +409,7 @@ static void test_recv_close_on_server_from_client() { } static void test_recv_status_on_client_twice() { - gpr_log(GPR_INFO, "test_recv_status_on_client_twice"); + LOG(INFO) << "test_recv_status_on_client_twice"; grpc_op* op; prepare_test(1); @@ -446,7 +446,7 @@ static void test_recv_status_on_client_twice() { } static void test_send_close_from_client_on_server() { - gpr_log(GPR_INFO, "test_send_close_from_client_on_server"); + LOG(INFO) << "test_send_close_from_client_on_server"; grpc_op* op; prepare_test(0); @@ -464,7 +464,7 @@ static void test_send_close_from_client_on_server() { } static void test_recv_status_on_client_from_server() { - gpr_log(GPR_INFO, "test_recv_status_on_client_from_server"); + LOG(INFO) << "test_recv_status_on_client_from_server"; grpc_op* op; prepare_test(0); @@ -486,7 +486,7 @@ static void test_recv_status_on_client_from_server() { } static void test_send_status_from_server_with_invalid_flags() { - gpr_log(GPR_INFO, "test_send_status_from_server_with_invalid_flags"); + LOG(INFO) << "test_send_status_from_server_with_invalid_flags"; grpc_op* op; prepare_test(0); @@ -508,7 +508,7 @@ static void test_send_status_from_server_with_invalid_flags() { } static void test_too_many_trailing_metadata() { - gpr_log(GPR_INFO, "test_too_many_trailing_metadata"); + LOG(INFO) << "test_too_many_trailing_metadata"; grpc_op* op; prepare_test(0); @@ -531,7 +531,7 @@ static void test_too_many_trailing_metadata() { } static void test_send_server_status_twice() { - gpr_log(GPR_INFO, "test_send_server_status_twice"); + LOG(INFO) << "test_send_server_status_twice"; grpc_op* op; prepare_test(0); @@ -560,7 +560,7 @@ static void test_send_server_status_twice() { } static void test_recv_close_on_server_with_invalid_flags() { - gpr_log(GPR_INFO, "test_recv_close_on_server_with_invalid_flags"); + LOG(INFO) << "test_recv_close_on_server_with_invalid_flags"; grpc_op* op; prepare_test(0); @@ -579,7 +579,7 @@ static void test_recv_close_on_server_with_invalid_flags() { } static void test_recv_close_on_server_twice() { - gpr_log(GPR_INFO, "test_recv_close_on_server_twice"); + LOG(INFO) << "test_recv_close_on_server_twice"; grpc_op* op; prepare_test(0); @@ -603,7 +603,7 @@ static void test_recv_close_on_server_twice() { } static void test_invalid_initial_metadata_reserved_key() { - gpr_log(GPR_INFO, "test_invalid_initial_metadata_reserved_key"); + LOG(INFO) << "test_invalid_initial_metadata_reserved_key"; grpc_metadata metadata; metadata.key = grpc_slice_from_static_string(":start_with_colon"); @@ -626,7 +626,7 @@ static void test_invalid_initial_metadata_reserved_key() { } static void test_multiple_ops_in_a_single_batch() { - gpr_log(GPR_INFO, "test_multiple_ops_in_a_single_batch"); + LOG(INFO) << "test_multiple_ops_in_a_single_batch"; grpc_op* op; prepare_test(1); diff --git a/test/core/end2end/no_server_test.cc b/test/core/end2end/no_server_test.cc index dc3db4b37bf..4b14f0a1a72 100644 --- a/test/core/end2end/no_server_test.cc +++ b/test/core/end2end/no_server_test.cc @@ -21,6 +21,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/time/time.h" @@ -31,7 +32,6 @@ #include #include #include -#include #include #include "src/core/lib/channel/channel_args.h" @@ -45,7 +45,7 @@ #include "test/core/test_util/test_config.h" void run_test(bool wait_for_ready) { - gpr_log(GPR_INFO, "TEST: wait_for_ready=%d", wait_for_ready); + LOG(INFO) << "TEST: wait_for_ready=" << wait_for_ready; grpc_init(); @@ -104,7 +104,7 @@ void run_test(bool wait_for_ready) { cqv.Expect(grpc_core::CqVerifier::tag(1), true); cqv.Verify(); - gpr_log(GPR_INFO, "call status: %d", status); + LOG(INFO) << "call status: " << status; if (wait_for_ready) { CHECK_EQ(status, GRPC_STATUS_DEADLINE_EXCEEDED); } else { diff --git a/test/core/end2end/tests/call_creds.cc b/test/core/end2end/tests/call_creds.cc index ce6b949085f..2b078a1152d 100644 --- a/test/core/end2end/tests/call_creds.cc +++ b/test/core/end2end/tests/call_creds.cc @@ -18,6 +18,7 @@ #include +#include "absl/log/log.h" #include "absl/types/optional.h" #include "gtest/gtest.h" @@ -25,7 +26,6 @@ #include #include #include -#include #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/gprpp/time.h" @@ -47,17 +47,17 @@ const char overridden_fake_md_value[] = "overridden_fake_value"; void PrintAuthContext(bool is_client, const grpc_auth_context* ctx) { const grpc_auth_property* p; grpc_auth_property_iterator it; - gpr_log(GPR_INFO, "%s peer:", is_client ? "client" : "server"); - gpr_log(GPR_INFO, "\tauthenticated: %s", - grpc_auth_context_peer_is_authenticated(ctx) ? "YES" : "NO"); + LOG(INFO) << (is_client ? "client" : "server") << " peer:"; + LOG(INFO) << "\tauthenticated: " + << (grpc_auth_context_peer_is_authenticated(ctx) ? "YES" : "NO"); it = grpc_auth_context_peer_identity(ctx); while ((p = grpc_auth_property_iterator_next(&it)) != nullptr) { - gpr_log(GPR_INFO, "\t\t%s: %s", p->name, p->value); + LOG(INFO) << "\t\t" << p->name << ": " << p->value; } - gpr_log(GPR_INFO, "\tall properties:"); + LOG(INFO) << "\tall properties:"; it = grpc_auth_context_property_iterator(ctx); while ((p = grpc_auth_property_iterator_next(&it)) != nullptr) { - gpr_log(GPR_INFO, "\t\t%s: %s", p->name, p->value); + LOG(INFO) << "\t\t" << p->name << ": " << p->value; } } diff --git a/test/core/end2end/tests/disappearing_server.cc b/test/core/end2end/tests/disappearing_server.cc index 81cea5a5ad2..5b65e20eb57 100644 --- a/test/core/end2end/tests/disappearing_server.cc +++ b/test/core/end2end/tests/disappearing_server.cc @@ -18,10 +18,10 @@ #include +#include "absl/log/log.h" #include "gtest/gtest.h" #include -#include #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/gprpp/time.h" @@ -31,13 +31,13 @@ namespace grpc_core { static void OneRequestAndShutdownServer(CoreEnd2endTest& test) { - gpr_log(GPR_ERROR, "Create client side call"); + LOG(ERROR) << "Create client side call"; auto c = test.NewClientCall("/service/method") .Timeout(Duration::Seconds(30)) .Create(); CoreEnd2endTest::IncomingMetadata server_initial_md; CoreEnd2endTest::IncomingStatusOnClient server_status; - gpr_log(GPR_ERROR, "Start initial batch"); + LOG(ERROR) << "Start initial batch"; c.NewBatch(1) .SendInitialMetadata({}) .SendCloseFromClient() diff --git a/test/core/end2end/tests/filter_context.cc b/test/core/end2end/tests/filter_context.cc index b3e2759ef1f..7d53047f971 100644 --- a/test/core/end2end/tests/filter_context.cc +++ b/test/core/end2end/tests/filter_context.cc @@ -20,11 +20,11 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "gtest/gtest.h" #include -#include #include "src/core/lib/channel/channel_fwd.h" #include "src/core/lib/channel/channel_stack.h" @@ -53,7 +53,7 @@ grpc_error_handle init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = static_cast(elem->call_data); calld->context = args->context; - gpr_log(GPR_INFO, "init_call_elem(): context=%p", args->context); + LOG(INFO) << "init_call_elem(): context=" << args->context; return absl::OkStatus(); } @@ -63,8 +63,8 @@ void start_transport_stream_op_batch(grpc_call_element* elem, // If batch payload context is not null (which will happen in some // cancellation cases), make sure we get the same context here that we // saw in init_call_elem(). - gpr_log(GPR_INFO, "start_transport_stream_op_batch(): context=%p", - batch->payload->context); + LOG(INFO) << "start_transport_stream_op_batch(): context=" + << batch->payload->context; if (batch->payload->context != nullptr) { CHECK(calld->context == batch->payload->context); } @@ -103,9 +103,6 @@ CORE_END2END_TEST(CoreEnd2endTest, FilterContext) { CoreConfiguration::RegisterBuilder([](CoreConfiguration::Builder* builder) { for (auto type : {GRPC_CLIENT_CHANNEL, GRPC_CLIENT_SUBCHANNEL, GRPC_CLIENT_DIRECT_CHANNEL, GRPC_SERVER_CHANNEL}) { - if (type == GRPC_SERVER_CHANNEL && IsPromiseBasedServerCallEnabled()) { - continue; - } builder->channel_init()->RegisterFilter(type, &test_filter); } }); diff --git a/test/core/end2end/tests/resource_quota_server.cc b/test/core/end2end/tests/resource_quota_server.cc index acf4c109089..0bc7a69e034 100644 --- a/test/core/end2end/tests/resource_quota_server.cc +++ b/test/core/end2end/tests/resource_quota_server.cc @@ -21,13 +21,13 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include "gtest/gtest.h" #include #include #include -#include #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/experiments/experiments.h" @@ -146,11 +146,11 @@ CORE_END2END_TEST(ResourceQuotaTest, ResourceQuota) { cancelled_calls_on_server++; } } - gpr_log(GPR_INFO, - "Done. %d total calls: %d cancelled at server, %d cancelled at " - "client, %d timed out, %d unavailable.", - kNumCalls, cancelled_calls_on_server, cancelled_calls_on_client, - deadline_exceeded, unavailable); + LOG(INFO) << "Done. " << kNumCalls + << " total calls: " << cancelled_calls_on_server + << " cancelled at server, " << cancelled_calls_on_client + << " cancelled at client, " << deadline_exceeded << " timed out, " + << unavailable << " unavailable."; ShutdownServerAndNotify(0); Expect(0, PerformAction{[this](bool success) { diff --git a/test/core/end2end/tests/server_streaming.cc b/test/core/end2end/tests/server_streaming.cc index 76cd2ae7382..b6fd6f30511 100644 --- a/test/core/end2end/tests/server_streaming.cc +++ b/test/core/end2end/tests/server_streaming.cc @@ -19,10 +19,10 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "gtest/gtest.h" #include -#include #include "src/core/lib/gprpp/time.h" #include "test/core/end2end/cq_verifier.h" @@ -70,7 +70,7 @@ void ServerStreaming(CoreEnd2endTest& test, int num_messages) { test.Expect(104, true); test.Step(); - gpr_log(GPR_DEBUG, "SEEN_STATUS:%d", seen_status); + VLOG(2) << "SEEN_STATUS:" << seen_status; // Client keeps reading messages till it gets the status int num_messages_received = 0; diff --git a/test/core/end2end/tests/simple_delayed_request.cc b/test/core/end2end/tests/simple_delayed_request.cc index e22ea978335..bbdfe4ab790 100644 --- a/test/core/end2end/tests/simple_delayed_request.cc +++ b/test/core/end2end/tests/simple_delayed_request.cc @@ -18,12 +18,12 @@ #include +#include "absl/log/log.h" #include "gtest/gtest.h" #include #include #include -#include #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/gprpp/time.h" @@ -37,17 +37,17 @@ CORE_END2END_TEST(Http2SingleHopTest, SimpleDelayedRequestShort) { .Set(GRPC_ARG_INITIAL_RECONNECT_BACKOFF_MS, 1000) .Set(GRPC_ARG_MAX_RECONNECT_BACKOFF_MS, 1000) .Set(GRPC_ARG_MIN_RECONNECT_BACKOFF_MS, 5000)); - gpr_log(GPR_ERROR, "Create client side call"); + LOG(ERROR) << "Create client side call"; auto c = NewClientCall("/foo").Timeout(Duration::Minutes(1)).Create(); IncomingMetadata server_initial_metadata; IncomingStatusOnClient server_status; - gpr_log(GPR_ERROR, "Start initial batch"); + LOG(ERROR) << "Start initial batch"; c.NewBatch(1) .SendInitialMetadata({}, GRPC_INITIAL_METADATA_WAIT_FOR_READY) .SendCloseFromClient() .RecvInitialMetadata(server_initial_metadata) .RecvStatusOnClient(server_status); - gpr_log(GPR_ERROR, "Start server"); + LOG(ERROR) << "Start server"; InitServer(ChannelArgs()); auto s = RequestCall(101); Expect(101, true); diff --git a/test/core/end2end/tests/simple_request.cc b/test/core/end2end/tests/simple_request.cc index 359489f6c2d..1e39734d327 100644 --- a/test/core/end2end/tests/simple_request.cc +++ b/test/core/end2end/tests/simple_request.cc @@ -22,13 +22,13 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/match.h" #include "absl/types/optional.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include -#include #include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/stats_data.h" @@ -91,7 +91,7 @@ void SimpleRequestBody(CoreEnd2endTest& test) { expected_calls *= 2; } auto after = global_stats().Collect(); - gpr_log(GPR_DEBUG, "%s", StatsAsJson(after.get()).c_str()); + VLOG(2) << StatsAsJson(after.get()); EXPECT_EQ(after->client_calls_created - before->client_calls_created, expected_calls); EXPECT_EQ(after->server_calls_created - before->server_calls_created, diff --git a/test/core/end2end/tests/timeout_before_request_call.cc b/test/core/end2end/tests/timeout_before_request_call.cc index 5ad6a9872a1..bb61acd648e 100644 --- a/test/core/end2end/tests/timeout_before_request_call.cc +++ b/test/core/end2end/tests/timeout_before_request_call.cc @@ -16,6 +16,7 @@ #include +#include "absl/log/log.h" #include "gtest/gtest.h" #include @@ -147,7 +148,7 @@ CORE_END2END_TEST(CoreDeadlineSingleHopTest, bool got_call = false; std::unique_ptr client_close; Expect(2, MaybePerformAction{[this, &s, &got_call, &client_close](bool ok) { - gpr_log(GPR_INFO, "\n***\n*** got call: %d\n***", ok); + LOG(INFO) << "\n***\n*** got call: " << ok << "\n***"; got_call = true; if (ok) { // If we successfully get a call, then we should additionally get a diff --git a/test/core/event_engine/BUILD b/test/core/event_engine/BUILD index 11a9c41ab14..593e912f42c 100644 --- a/test/core/event_engine/BUILD +++ b/test/core/event_engine/BUILD @@ -39,6 +39,7 @@ grpc_cc_test( name = "forkable_test", srcs = ["forkable_test.cc"], external_deps = [ + "absl/log:log", "absl/types:optional", "gtest", ], @@ -221,6 +222,7 @@ grpc_cc_library( hdrs = ["event_engine_test_utils.h"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", diff --git a/test/core/event_engine/event_engine_test_utils.h b/test/core/event_engine/event_engine_test_utils.h index 67bbe42d35d..debef7a0449 100644 --- a/test/core/event_engine/event_engine_test_utils.h +++ b/test/core/event_engine/event_engine_test_utils.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -159,6 +160,70 @@ class NotifyOnDelete { grpc_core::Notification* signal_; }; +// An endpoint implementation that supports Read and Write via std::threads. +// Passing a grpc_core::Notification will allow owners to know when all +// in-flight callbacks have been run, and all endpoint state has been destroyed. +class ThreadedNoopEndpoint : public EventEngine::Endpoint { + public: + explicit ThreadedNoopEndpoint(grpc_core::Notification* destroyed) + : state_(std::make_shared(destroyed)) {} + ~ThreadedNoopEndpoint() override { + std::thread deleter([state = state_]() { + CleanupThread(state->read); + CleanupThread(state->write); + }); + deleter.detach(); + } + + bool Read(absl::AnyInvocable on_read, SliceBuffer* buffer, + const ReadArgs* /* args */) override { + buffer->Clear(); + CleanupThread(state_->read); + state_->read = new std::thread([cb = std::move(on_read)]() mutable { + cb(absl::UnknownError("test")); + }); + return false; + } + + bool Write(absl::AnyInvocable on_writable, + SliceBuffer* data, const WriteArgs* /* args */) override { + data->Clear(); + CleanupThread(state_->write); + state_->write = new std::thread([cb = std::move(on_writable)]() mutable { + cb(absl::UnknownError("test")); + }); + return false; + } + + const EventEngine::ResolvedAddress& GetPeerAddress() const override { + return peer_; + } + + const EventEngine::ResolvedAddress& GetLocalAddress() const override { + return local_; + } + + private: + struct EndpointState { + explicit EndpointState(grpc_core::Notification* deleter) + : delete_notifier_(deleter) {} + std::thread* read = nullptr; + std::thread* write = nullptr; + NotifyOnDelete delete_notifier_; + }; + + static void CleanupThread(std::thread* thd) { + if (thd != nullptr) { + thd->join(); + delete thd; + } + } + + std::shared_ptr state_; + EventEngine::ResolvedAddress peer_; + EventEngine::ResolvedAddress local_; +}; + } // namespace experimental } // namespace grpc_event_engine diff --git a/test/core/event_engine/fuzzing_event_engine/BUILD b/test/core/event_engine/fuzzing_event_engine/BUILD index c46574c292b..8182795faf7 100644 --- a/test/core/event_engine/fuzzing_event_engine/BUILD +++ b/test/core/event_engine/fuzzing_event_engine/BUILD @@ -25,7 +25,10 @@ grpc_cc_library( name = "fuzzing_event_engine", srcs = ["fuzzing_event_engine.cc"], hdrs = ["fuzzing_event_engine.h"], - external_deps = ["absl/log:check"], + external_deps = [ + "absl/log:check", + "absl/log:log", + ], deps = [ ":fuzzing_event_engine_proto", "//:event_engine_base_hdrs", diff --git a/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc b/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc index 371d3972997..bba8a824651 100644 --- a/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc +++ b/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc @@ -33,9 +33,9 @@ #include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/event_engine/tcp_socket_utils.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/iomgr/port.h" +#include "src/core/util/useful.h" #include "test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.h" #include "test/core/test_util/port.h" diff --git a/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h b/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h index 1bc85ee3ce5..f28cdca5251 100644 --- a/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h +++ b/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h @@ -29,6 +29,7 @@ #include "absl/base/thread_annotations.h" #include "absl/functional/any_invocable.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/types/optional.h" @@ -314,8 +315,10 @@ class ThreadedFuzzingEventEngine : public FuzzingEventEngine { fuzzing_event_engine::Actions()), main_([this, max_time]() { while (!done_.load()) { - absl::SleepFor(absl::Milliseconds( - grpc_event_engine::experimental::Milliseconds(max_time))); + if (max_time > Duration::zero()) { + absl::SleepFor(absl::Milliseconds( + grpc_event_engine::experimental::Milliseconds(max_time))); + } Tick(); } }) {} diff --git a/test/core/event_engine/posix/BUILD b/test/core/event_engine/posix/BUILD index d320f428b06..21da357bbef 100644 --- a/test/core/event_engine/posix/BUILD +++ b/test/core/event_engine/posix/BUILD @@ -26,6 +26,7 @@ grpc_cc_library( testonly = True, srcs = ["posix_engine_test_utils.cc"], hdrs = ["posix_engine_test_utils.h"], + external_deps = ["absl/log:log"], tags = [ "no_windows", ], @@ -68,7 +69,10 @@ grpc_cc_test( grpc_cc_test( name = "timer_manager_test", srcs = ["timer_manager_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", uses_event_engine = False, uses_polling = False, @@ -83,7 +87,10 @@ grpc_cc_test( grpc_cc_test( name = "event_poller_posix_test", srcs = ["event_poller_posix_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", tags = [ "no_windows", @@ -184,6 +191,7 @@ grpc_cc_test( srcs = ["posix_endpoint_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], language = "C++", @@ -211,7 +219,10 @@ grpc_cc_test( grpc_cc_test( name = "posix_engine_listener_utils_test", srcs = ["posix_engine_listener_utils_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", tags = [ "no_windows", @@ -232,6 +243,7 @@ grpc_cc_test( srcs = ["posix_event_engine_connect_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], language = "C++", diff --git a/test/core/event_engine/posix/tcp_posix_socket_utils_test.cc b/test/core/event_engine/posix/tcp_posix_socket_utils_test.cc index d958b191cd0..0e1099b57aa 100644 --- a/test/core/event_engine/posix/tcp_posix_socket_utils_test.cc +++ b/test/core/event_engine/posix/tcp_posix_socket_utils_test.cc @@ -35,8 +35,8 @@ #include #include "src/core/lib/event_engine/posix_engine/tcp_socket_utils.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/iomgr/socket_mutator.h" +#include "src/core/util/useful.h" namespace grpc_event_engine { namespace experimental { diff --git a/test/core/event_engine/posix/traced_buffer_list_test.cc b/test/core/event_engine/posix/traced_buffer_list_test.cc index 0d72ebcee80..1ae3a05cb94 100644 --- a/test/core/event_engine/posix/traced_buffer_list_test.cc +++ b/test/core/event_engine/posix/traced_buffer_list_test.cc @@ -25,10 +25,10 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/port.h" +#include "src/core/util/useful.h" #ifdef GRPC_LINUX_ERRQUEUE diff --git a/test/core/event_engine/test_suite/posix/BUILD b/test/core/event_engine/test_suite/posix/BUILD index 7cca1028c39..dc4bbeb799d 100644 --- a/test/core/event_engine/test_suite/posix/BUILD +++ b/test/core/event_engine/test_suite/posix/BUILD @@ -23,7 +23,10 @@ grpc_cc_library( testonly = True, srcs = ["oracle_event_engine_posix.cc"], hdrs = ["oracle_event_engine_posix.h"], - external_deps = ["absl/log:check"], + external_deps = [ + "absl/log:check", + "absl/log:log", + ], tags = [ "cpu:10", "no_windows", diff --git a/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc b/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc index 86e0a6ac033..52eff1798ec 100644 --- a/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc +++ b/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc @@ -24,6 +24,7 @@ #include #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" @@ -32,7 +33,6 @@ #include #include -#include #include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/gprpp/crash.h" @@ -255,7 +255,7 @@ bool PosixOracleEndpoint::Write( } void PosixOracleEndpoint::ProcessReadOperations() { - gpr_log(GPR_INFO, "Starting thread to process read ops ..."); + LOG(INFO) << "Starting thread to process read ops ..."; while (true) { read_op_signal_->WaitForNotification(); read_op_signal_ = std::make_unique(); @@ -273,11 +273,11 @@ void PosixOracleEndpoint::ProcessReadOperations() { grpc_core::StrError(saved_errno))) : absl::OkStatus()); } - gpr_log(GPR_INFO, "Shutting down read ops thread ..."); + LOG(INFO) << "Shutting down read ops thread ..."; } void PosixOracleEndpoint::ProcessWriteOperations() { - gpr_log(GPR_INFO, "Starting thread to process write ops ..."); + LOG(INFO) << "Starting thread to process write ops ..."; while (true) { write_op_signal_->WaitForNotification(); write_op_signal_ = std::make_unique(); @@ -293,7 +293,7 @@ void PosixOracleEndpoint::ProcessWriteOperations() { grpc_core::StrError(saved_errno))) : absl::OkStatus()); } - gpr_log(GPR_INFO, "Shutting down write ops thread ..."); + LOG(INFO) << "Shutting down write ops thread ..."; } PosixOracleListener::PosixOracleListener( @@ -341,7 +341,7 @@ PosixOracleListener::~PosixOracleListener() { } void PosixOracleListener::HandleIncomingConnections() { - gpr_log(GPR_INFO, "Starting accept thread ..."); + LOG(INFO) << "Starting accept thread ..."; CHECK(!listener_fds_.empty()); int nfds = listener_fds_.size(); // Add one extra file descriptor to poll the pipe fd. @@ -371,17 +371,16 @@ void PosixOracleListener::HandleIncomingConnections() { // pfds[i].fd has a readable event. int client_sock_fd = accept(pfds[i].fd, nullptr, nullptr); if (client_sock_fd < 0) { - gpr_log(GPR_ERROR, - "Error accepting new connection: %s. Ignoring connection " - "attempt ...", - grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Error accepting new connection: " + << grpc_core::StrError(errno) + << ". Ignoring connection attempt ..."; continue; } on_accept_(PosixOracleEndpoint::Create(client_sock_fd), memory_allocator_factory_->CreateMemoryAllocator("test")); } } - gpr_log(GPR_INFO, "Shutting down accept thread ..."); + LOG(INFO) << "Shutting down accept thread ..."; gpr_free(pfds); } diff --git a/test/core/event_engine/test_suite/tests/BUILD b/test/core/event_engine/test_suite/tests/BUILD index 2346402a83c..ef0b8112d20 100644 --- a/test/core/event_engine/test_suite/tests/BUILD +++ b/test/core/event_engine/test_suite/tests/BUILD @@ -42,6 +42,9 @@ grpc_cc_library( testonly = True, srcs = ["timer_test.cc"], hdrs = ["timer_test.h"], + external_deps = [ + "absl/log:log", + ], deps = [ "//test/core/event_engine:event_engine_test_utils", "//test/core/event_engine/test_suite:event_engine_test_framework", @@ -62,6 +65,7 @@ grpc_cc_library( "//test/cpp/naming/utils:tcp_connect", ], external_deps = [ + "absl/log:log", "absl/status:statusor", "absl/strings", "absl/strings:str_format", diff --git a/test/core/event_engine/test_suite/tools/BUILD b/test/core/event_engine/test_suite/tools/BUILD index af72545a02b..c591d327e3e 100644 --- a/test/core/event_engine/test_suite/tools/BUILD +++ b/test/core/event_engine/test_suite/tools/BUILD @@ -62,6 +62,7 @@ grpc_cc_library( "absl/flags:flag", "absl/flags:parse", "absl/log:check", + "absl/log:log", ], language = "C++", deps = [ diff --git a/test/core/event_engine/windows/BUILD b/test/core/event_engine/windows/BUILD index e40bc6194fa..5dc34be99dc 100644 --- a/test/core/event_engine/windows/BUILD +++ b/test/core/event_engine/windows/BUILD @@ -21,6 +21,7 @@ grpc_cc_test( timeout = "short", srcs = ["iocp_test.cc"], external_deps = [ + "absl/log:log", "gtest", "absl/types:variant", ], @@ -92,6 +93,7 @@ grpc_cc_library( hdrs = ["create_sockpair.h"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", ], language = "C++", diff --git a/test/core/event_engine/windows/iocp_test.cc b/test/core/event_engine/windows/iocp_test.cc index 787ca180cb0..e96b8d3816d 100644 --- a/test/core/event_engine/windows/iocp_test.cc +++ b/test/core/event_engine/windows/iocp_test.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/time/time.h" #include "absl/types/variant.h" @@ -49,7 +50,7 @@ using ::grpc_event_engine::experimental::WinSocket; // `ASSERT_OK(...) << GetErrorMessage(error, context);` void LogErrorMessage(int messageid, absl::string_view context) { char* utf8_message = gpr_format_message(messageid); - gpr_log(GPR_ERROR, "Error in %s: %s", context, utf8_message); + LOG(ERROR) << "Error in " << context << ": " << utf8_message; gpr_free(utf8_message); } } // namespace @@ -77,7 +78,7 @@ TEST_F(IOCPTest, ClientReceivesNotificationOfServerSend) { DWORD bytes_rcvd; on_read = new AnyInvocableClosure([win_socket = wrapped_client_socket.get(), &read_called, &read_wsabuf]() { - gpr_log(GPR_DEBUG, "Notified on read"); + VLOG(2) << "Notified on read"; EXPECT_GE(win_socket->read_info()->result().bytes_transferred, 10u); EXPECT_STREQ(read_wsabuf.buf, "hello!"); read_called.Notify(); @@ -96,7 +97,7 @@ TEST_F(IOCPTest, ClientReceivesNotificationOfServerSend) { } { on_write = new AnyInvocableClosure([&write_called] { - gpr_log(GPR_DEBUG, "Notified on write"); + VLOG(2) << "Notified on write"; write_called.Notify(); }); wrapped_server_socket->NotifyOnWrite(on_write); @@ -153,7 +154,7 @@ TEST_F(IOCPTest, IocpWorkTimeoutDueToNoNotificationRegistered) { wrapped_client_socket->NotifyOnRead( SelfDeletingClosure::Create([win_socket = wrapped_client_socket.get(), &read_called, &read_wsabuf]() { - gpr_log(GPR_DEBUG, "Notified on read"); + VLOG(2) << "Notified on read"; EXPECT_GE(win_socket->read_info()->result().bytes_transferred, 10u); EXPECT_STREQ(read_wsabuf.buf, "hello!"); read_called.Notify(); diff --git a/test/core/filters/client_auth_filter_test.cc b/test/core/filters/client_auth_filter_test.cc index bc06504b25f..2d842875d5a 100644 --- a/test/core/filters/client_auth_filter_test.cc +++ b/test/core/filters/client_auth_filter_test.cc @@ -28,7 +28,6 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/promise_based_filter.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/promise/arena_promise.h" @@ -40,6 +39,7 @@ #include "src/core/lib/security/transport/auth_filters.h" #include "src/core/lib/transport/metadata_batch.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/useful.h" #include "test/core/filters/filter_test.h" // TODO(roth): Need to add a lot more tests here. I created this file diff --git a/test/core/gprpp/BUILD b/test/core/gprpp/BUILD index b6ca769f46d..4e9f12a8c37 100644 --- a/test/core/gprpp/BUILD +++ b/test/core/gprpp/BUILD @@ -47,6 +47,7 @@ grpc_cc_test( external_deps = [ "absl/debugging:stacktrace", "absl/debugging:symbolize", + "absl/log:log", "gtest", ], language = "C++", @@ -60,6 +61,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", @@ -179,7 +194,10 @@ grpc_cc_test( name = "mpscq_test", srcs = ["mpscq_test.cc"], exec_properties = LARGE_MACHINE, - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", tags = ["no_windows"], # LARGE_MACHINE is not configured for windows RBE uses_event_engine = False, @@ -367,7 +385,10 @@ grpc_cc_test( grpc_cc_test( name = "single_set_ptr_test", srcs = ["single_set_ptr_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "c++", uses_event_engine = False, uses_polling = False, 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/test/core/gprpp/load_file_test.cc b/test/core/gprpp/load_file_test.cc index 76988c354fe..180624c9eb4 100644 --- a/test/core/gprpp/load_file_test.cc +++ b/test/core/gprpp/load_file_test.cc @@ -23,7 +23,7 @@ #include -#include "src/core/lib/gpr/tmpfile.h" +#include "src/core/util/tmpfile.h" #include "test/core/test_util/test_config.h" static const char prefix[] = "file_test"; diff --git a/test/core/gprpp/mpscq_test.cc b/test/core/gprpp/mpscq_test.cc index daa3bb3401e..1bf92acd189 100644 --- a/test/core/gprpp/mpscq_test.cc +++ b/test/core/gprpp/mpscq_test.cc @@ -23,14 +23,14 @@ #include +#include "absl/log/log.h" #include "gtest/gtest.h" -#include #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/thd.h" +#include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" using grpc_core::MultiProducerSingleConsumerQueue; @@ -49,7 +49,7 @@ static test_node* new_node(size_t i, size_t* ctr) { } TEST(MpscqTest, Serial) { - gpr_log(GPR_DEBUG, "test_serial"); + VLOG(2) << "test_serial"; MultiProducerSingleConsumerQueue q; for (size_t i = 0; i < 10000000; i++) { q.Push(&new_node(i, nullptr)->node); @@ -79,7 +79,7 @@ static void test_thread(void* args) { } TEST(MpscqTest, Mt) { - gpr_log(GPR_DEBUG, "test_mt"); + VLOG(2) << "test_mt"; gpr_event start; gpr_event_init(&start); grpc_core::Thread thds[100]; @@ -106,7 +106,7 @@ TEST(MpscqTest, Mt) { if (tn->i == THREAD_ITERATIONS) num_done++; delete tn; } - gpr_log(GPR_DEBUG, "spins: %" PRIdPTR, spins); + VLOG(2) << "spins: " << spins; for (auto& th : thds) { th.Join(); } @@ -146,7 +146,7 @@ static void pull_thread(void* arg) { } TEST(MpscqTest, MtMultipop) { - gpr_log(GPR_DEBUG, "test_mt_multipop"); + VLOG(2) << "test_mt_multipop"; gpr_event start; gpr_event_init(&start); grpc_core::Thread thds[50]; @@ -176,7 +176,7 @@ TEST(MpscqTest, MtMultipop) { for (auto& pth : pull_thds) { pth.Join(); } - gpr_log(GPR_DEBUG, "spins: %" PRIdPTR, pa.spins); + VLOG(2) << "spins: " << pa.spins; for (auto& th : thds) { th.Join(); } diff --git a/test/core/gprpp/single_set_ptr_test.cc b/test/core/gprpp/single_set_ptr_test.cc index 62108e3df59..b93aa14c3e8 100644 --- a/test/core/gprpp/single_set_ptr_test.cc +++ b/test/core/gprpp/single_set_ptr_test.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/log/log.h" #include "gtest/gtest.h" namespace grpc_core { @@ -28,7 +29,7 @@ TEST(SingleSetPtrTest, NoOp) { SingleSetPtr(); } TEST(SingleSetPtrTest, CanSet) { SingleSetPtr p; EXPECT_FALSE(p.is_set()); - EXPECT_DEATH_IF_SUPPORTED(gpr_log(GPR_ERROR, "%d", *p), ""); + EXPECT_DEATH_IF_SUPPORTED({ LOG(ERROR) << *p; }, ""); p.Set(new int(42)); EXPECT_EQ(*p, 42); } diff --git a/test/core/gprpp/stat_test.cc b/test/core/gprpp/stat_test.cc index 1c3a9d0022f..29536b4a0e6 100644 --- a/test/core/gprpp/stat_test.cc +++ b/test/core/gprpp/stat_test.cc @@ -24,7 +24,7 @@ #include -#include "src/core/lib/gpr/tmpfile.h" +#include "src/core/util/tmpfile.h" #include "test/core/test_util/test_config.h" namespace grpc_core { diff --git a/test/core/handshake/BUILD b/test/core/handshake/BUILD index ba12e8f2ed0..27fe79fd9d4 100644 --- a/test/core/handshake/BUILD +++ b/test/core/handshake/BUILD @@ -26,7 +26,10 @@ grpc_cc_test( "//src/core/tsi/test_creds:server1.key", "//src/core/tsi/test_creds:server1.pem", ], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", tags = ["no_windows"], deps = [ @@ -40,7 +43,10 @@ grpc_cc_library( name = "server_ssl_common", srcs = ["server_ssl_common.cc"], hdrs = ["server_ssl_common.h"], - external_deps = ["absl/log:check"], + external_deps = [ + "absl/log:check", + "absl/log:log", + ], tags = ["no_windows"], deps = [ "//:gpr", @@ -100,6 +106,7 @@ grpc_cc_test( # ], # external_deps = [ # "absl/log:check", +# "absl/log:log", # ], # language = "C++", # tags = ["no_mac", no_windows"], diff --git a/test/core/handshake/client_ssl.cc b/test/core/handshake/client_ssl.cc index 5445b7b402e..d59018f3a65 100644 --- a/test/core/handshake/client_ssl.cc +++ b/test/core/handshake/client_ssl.cc @@ -24,6 +24,7 @@ #include #include "absl/base/thread_annotations.h" +#include "absl/strings/str_format.h" #include "gtest/gtest.h" #include @@ -49,12 +50,12 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include #include #include -#include #include "src/core/lib/debug/trace.h" #include "src/core/lib/gprpp/crash.h" @@ -119,7 +120,7 @@ static int create_socket(int* out_port) { if (bind(s, reinterpret_cast(&addr), sizeof(addr)) < 0) { perror("Unable to bind"); - gpr_log(GPR_ERROR, "%s", "Unable to bind to any port"); + LOG(ERROR) << "Unable to bind to any port"; close(s); return -1; } @@ -135,7 +136,7 @@ static int create_socket(int* out_port) { 0 || addr_len > sizeof(addr)) { perror("getsockname"); - gpr_log(GPR_ERROR, "%s", "Unable to get socket local address"); + LOG(ERROR) << "Unable to get socket local address"; close(s); return -1; } @@ -176,14 +177,15 @@ static void ssl_log_where_info(const SSL* ssl, int where, int flag, const char* msg) { if ((where & flag) && GRPC_TRACE_FLAG_ENABLED(client_ssl_tsi_tracing_enabled)) { - gpr_log(GPR_INFO, "%20.20s - %30.30s - %5.10s", msg, - SSL_state_string_long(ssl), SSL_state_string(ssl)); + LOG(INFO) << absl::StrFormat("%20.20s - %30.30s - %5.10s", msg, + SSL_state_string_long(ssl), + SSL_state_string(ssl)); } } static void ssl_server_info_callback(const SSL* ssl, int where, int ret) { if (ret == 0) { - gpr_log(GPR_ERROR, "ssl_server_info_callback: error occurred.\n"); + LOG(ERROR) << "ssl_server_info_callback: error occurred.\n"; return; } @@ -251,7 +253,7 @@ static void server_thread(void* arg) { // bind/listen/accept at TCP layer. const int sock = args->socket; - gpr_log(GPR_INFO, "Server listening"); + LOG(INFO) << "Server listening"; struct sockaddr_in addr; socklen_t len = sizeof(addr); const int client = @@ -268,9 +270,9 @@ static void server_thread(void* arg) { SSL_set_fd(ssl, client); if (SSL_accept(ssl) <= 0) { ERR_print_errors_fp(stderr); - gpr_log(GPR_ERROR, "Handshake failed."); + LOG(ERROR) << "Handshake failed."; } else { - gpr_log(GPR_INFO, "Handshake successful."); + LOG(INFO) << "Handshake successful."; } // Send out the settings frame. diff --git a/test/core/handshake/server_ssl_common.cc b/test/core/handshake/server_ssl_common.cc index aefa17d5223..0bebf83ed2e 100644 --- a/test/core/handshake/server_ssl_common.cc +++ b/test/core/handshake/server_ssl_common.cc @@ -35,6 +35,7 @@ #include "absl/base/thread_annotations.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include @@ -42,7 +43,6 @@ #include #include #include -#include #include #include @@ -152,7 +152,7 @@ void server_thread(void* arg) { CHECK(ev.type == GRPC_QUEUE_TIMEOUT); } - gpr_log(GPR_INFO, "Shutting down server"); + LOG(INFO) << "Shutting down server"; grpc_server_shutdown_and_notify(server, cq, nullptr); grpc_completion_queue_shutdown(cq); @@ -246,7 +246,7 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len, } } CHECK_GT(sock, 0); - gpr_log(GPR_INFO, "Connected to server on port %d", s.port()); + LOG(INFO) << "Connected to server on port " << s.port(); // Establish a SSL* and connect at SSL layer. SSL* ssl = SSL_new(ctx); @@ -254,10 +254,10 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len, SSL_set_fd(ssl, sock); if (SSL_connect(ssl) <= 0) { ERR_print_errors_fp(stderr); - gpr_log(GPR_ERROR, "Handshake failed."); + LOG(ERROR) << "Handshake failed."; success = false; } else { - gpr_log(GPR_INFO, "Handshake successful."); + LOG(INFO) << "Handshake successful."; // Validate ALPN preferred by server matches alpn_expected. const unsigned char* alpn_selected; unsigned int alpn_selected_len; @@ -265,7 +265,7 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len, if (strlen(alpn_expected) != alpn_selected_len || strncmp(reinterpret_cast(alpn_selected), alpn_expected, alpn_selected_len) != 0) { - gpr_log(GPR_ERROR, "Unexpected ALPN protocol preference"); + LOG(ERROR) << "Unexpected ALPN protocol preference"; success = false; } } diff --git a/test/core/handshake/verify_peer_options.cc b/test/core/handshake/verify_peer_options.cc index b7680cc7897..3e5e2b1590d 100644 --- a/test/core/handshake/verify_peer_options.cc +++ b/test/core/handshake/verify_peer_options.cc @@ -33,13 +33,13 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include #include #include #include -#include #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/thd.h" @@ -89,7 +89,7 @@ static void server_thread(void* arg) { CHECK(ev.type == GRPC_QUEUE_TIMEOUT); } - gpr_log(GPR_INFO, "Shutting down server"); + LOG(INFO) << "Shutting down server"; grpc_server_shutdown_and_notify(server, cq, nullptr); grpc_server_cancel_all_calls(server); grpc_completion_queue_shutdown(cq); diff --git a/test/core/http/BUILD b/test/core/http/BUILD index dbcc6ad6537..f13e53fdc7e 100644 --- a/test/core/http/BUILD +++ b/test/core/http/BUILD @@ -66,7 +66,10 @@ grpc_cc_library( testonly = True, srcs = ["httpcli_test_util.cc"], hdrs = ["httpcli_test_util.h"], - external_deps = ["absl/log:check"], + external_deps = [ + "absl/log:check", + "absl/log:log", + ], deps = [ "//:gpr", "//:subprocess", @@ -87,6 +90,7 @@ grpc_cc_test( ], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], language = "C++", @@ -116,6 +120,7 @@ grpc_cc_test( ], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], language = "C++", diff --git a/test/core/http/httpcli_test.cc b/test/core/http/httpcli_test.cc index 7a4eb1bf607..2c7d7ee2aa2 100644 --- a/test/core/http/httpcli_test.cc +++ b/test/core/http/httpcli_test.cc @@ -43,7 +43,6 @@ #include #include -#include "src/core/lib/gpr/subprocess.h" #include "src/core/lib/gprpp/status_helper.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/gprpp/time_util.h" @@ -51,6 +50,7 @@ #include "src/core/lib/iomgr/pollset_set.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/resolver/dns/c_ares/grpc_ares_wrapper.h" +#include "src/core/util/subprocess.h" #include "test/core/http/httpcli_test_util.h" #include "test/core/test_util/fake_udp_and_tcp_server.h" #include "test/core/test_util/port.h" diff --git a/test/core/http/httpcli_test_util.cc b/test/core/http/httpcli_test_util.cc index 760b9d83b2a..f47bb1d61a8 100644 --- a/test/core/http/httpcli_test_util.cc +++ b/test/core/http/httpcli_test_util.cc @@ -23,17 +23,17 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/types/optional.h" #include -#include #include #include #include #include "src/core/lib/config/config_vars.h" -#include "src/core/lib/gpr/subprocess.h" +#include "src/core/util/subprocess.h" #include "test/core/test_util/port.h" namespace grpc_core { @@ -86,10 +86,10 @@ HttpRequestTestServer StartHttpRequestTestServer(int argc, char** argv, absl::StrCat(root, "/src/core/tsi/test_creds/ca.pem"); ConfigVars::SetOverrides(overrides); } - gpr_log(GPR_INFO, "starting HttpRequest test server subprocess:"); + LOG(INFO) << "starting HttpRequest test server subprocess:"; for (size_t i = 0; i < args.size(); i++) { - gpr_log(GPR_INFO, " HttpRequest test server subprocess argv[%ld]: %s", i, - args[i]); + LOG(INFO) << " HttpRequest test server subprocess argv[" << i + << "]: " << args[i]; } gpr_subprocess* server = gpr_subprocess_create(args.size(), const_cast(args.data())); diff --git a/test/core/http/httpcli_test_util.h b/test/core/http/httpcli_test_util.h index 6007a4be203..cd475ebe2d5 100644 --- a/test/core/http/httpcli_test_util.h +++ b/test/core/http/httpcli_test_util.h @@ -19,7 +19,7 @@ #include -#include "src/core/lib/gpr/subprocess.h" +#include "src/core/util/subprocess.h" namespace grpc_core { namespace testing { diff --git a/test/core/http/httpscli_test.cc b/test/core/http/httpscli_test.cc index c273581083f..55a559240b4 100644 --- a/test/core/http/httpscli_test.cc +++ b/test/core/http/httpscli_test.cc @@ -42,7 +42,6 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/subprocess.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/status_helper.h" #include "src/core/lib/gprpp/sync.h" @@ -59,6 +58,7 @@ #include "src/core/lib/iomgr/pollset.h" #include "src/core/lib/security/credentials/credentials.h" // IWYU pragma: keep #include "src/core/lib/uri/uri_parser.h" +#include "src/core/util/subprocess.h" #include "test/core/http/httpcli_test_util.h" #include "test/core/test_util/fake_udp_and_tcp_server.h" #include "test/core/test_util/test_config.h" diff --git a/test/core/http/parser_test.cc b/test/core/http/parser_test.cc index 70b5aaa670d..183dc9eeae3 100644 --- a/test/core/http/parser_test.cc +++ b/test/core/http/parser_test.cc @@ -29,7 +29,7 @@ #include -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" #include "test/core/test_util/slice_splitter.h" #include "test/core/test_util/test_config.h" diff --git a/test/core/iomgr/BUILD b/test/core/iomgr/BUILD index c8cbcc08978..058eccdd2b0 100644 --- a/test/core/iomgr/BUILD +++ b/test/core/iomgr/BUILD @@ -26,7 +26,10 @@ grpc_cc_library( name = "endpoint_tests", srcs = ["endpoint_tests.cc"], hdrs = ["endpoint_tests.h"], - external_deps = ["absl/log:check"], + external_deps = [ + "absl/log:check", + "absl/log:log", + ], language = "C++", visibility = [ "//test:__subpackages__", @@ -62,6 +65,7 @@ grpc_cc_test( srcs = ["endpoint_pair_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], language = "C++", @@ -82,6 +86,7 @@ grpc_cc_test( name = "error_test", srcs = ["error_test.cc"], external_deps = [ + "absl/log:log", "gtest", ], language = "C++", @@ -113,7 +118,10 @@ grpc_cc_test( grpc_cc_test( name = "fd_posix_test", srcs = ["fd_posix_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", tags = ["no_windows"], deps = [ @@ -146,6 +154,7 @@ grpc_cc_test( external_deps = [ "absl/flags:flag", "absl/flags:parse", + "absl/log:log", "absl/strings", "gtest", ], @@ -168,6 +177,7 @@ grpc_cc_test( external_deps = [ "absl/flags:flag", "absl/flags:parse", + "absl/log:log", "absl/strings", "gtest", ], @@ -186,6 +196,7 @@ grpc_cc_test( srcs = ["resolve_address_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", "gtest", ], @@ -205,6 +216,7 @@ grpc_cc_test( srcs = ["resolve_address_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", "gtest", ], @@ -239,7 +251,10 @@ grpc_cc_test( grpc_cc_test( name = "tcp_client_posix_test", srcs = ["tcp_client_posix_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", tags = [ "endpoint_test", @@ -260,6 +275,7 @@ grpc_cc_test( srcs = ["tcp_posix_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], language = "C++", @@ -314,7 +330,10 @@ grpc_cc_test( grpc_cc_test( name = "tcp_server_posix_test", srcs = ["tcp_server_posix_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", tags = [ "event_engine_listener_test", @@ -331,7 +350,10 @@ grpc_cc_test( grpc_cc_test( name = "timer_heap_test", srcs = ["timer_heap_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", uses_event_engine = False, uses_polling = False, @@ -348,6 +370,7 @@ grpc_cc_test( srcs = ["timer_list_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", ], language = "C++", uses_event_engine = False, diff --git a/test/core/iomgr/buffer_list_test.cc b/test/core/iomgr/buffer_list_test.cc index 4afd6d591f7..9994961a727 100644 --- a/test/core/iomgr/buffer_list_test.cc +++ b/test/core/iomgr/buffer_list_test.cc @@ -25,11 +25,11 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/internal_errqueue.h" #include "src/core/lib/iomgr/port.h" +#include "src/core/util/useful.h" #ifdef GRPC_LINUX_ERRQUEUE diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc index 11b3b2d5cae..0a8c0a45066 100644 --- a/test/core/iomgr/combiner_test.cc +++ b/test/core/iomgr/combiner_test.cc @@ -26,10 +26,10 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/notification.h" #include "src/core/lib/gprpp/thd.h" +#include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" TEST(CombinerTest, TestNoOp) { diff --git a/test/core/iomgr/endpoint_pair_test.cc b/test/core/iomgr/endpoint_pair_test.cc index e60013802e8..71b631fb184 100644 --- a/test/core/iomgr/endpoint_pair_test.cc +++ b/test/core/iomgr/endpoint_pair_test.cc @@ -23,11 +23,11 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include #include -#include #include #include "src/core/lib/channel/channel_args.h" @@ -35,10 +35,10 @@ #include "src/core/lib/event_engine/default_event_engine.h" #include "src/core/lib/event_engine/shim.h" #include "src/core/lib/event_engine/tcp_socket_utils.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/notification.h" #include "src/core/lib/iomgr/event_engine_shims/endpoint.h" #include "src/core/lib/resource_quota/memory_quota.h" +#include "src/core/util/useful.h" #include "test/core/iomgr/endpoint_tests.h" #include "test/core/test_util/port.h" #include "test/core/test_util/test_config.h" @@ -146,7 +146,7 @@ static void destroy_pollset(void* p, grpc_error_handle /*error*/) { TEST(EndpointPairTest, MainTest) { #ifdef GPR_WINDOWS if (grpc_event_engine::experimental::UseEventEngineClient()) { - gpr_log(GPR_INFO, "Skipping pathological EventEngine test on Windows"); + LOG(INFO) << "Skipping pathological EventEngine test on Windows"; return; } #endif diff --git a/test/core/iomgr/endpoint_tests.cc b/test/core/iomgr/endpoint_tests.cc index 696f58e0572..bd810dfcc82 100644 --- a/test/core/iomgr/endpoint_tests.cc +++ b/test/core/iomgr/endpoint_tests.cc @@ -23,17 +23,17 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include -#include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" // @@ -74,7 +74,7 @@ size_t count_slices(grpc_slice* slices, size_t nslices, int* current_data) { static grpc_endpoint_test_fixture begin_test(grpc_endpoint_test_config config, const char* test_name, size_t slice_size) { - gpr_log(GPR_INFO, "%s/%s", test_name, config.name); + LOG(INFO) << test_name << "/" << config.name; return config.create_fixture(slice_size); } @@ -134,7 +134,7 @@ static void read_scheduler(void* data, grpc_error_handle /* error */) { static void read_and_write_test_read_handler_read_done( read_and_write_test_state* state, int read_done_state) { - gpr_log(GPR_DEBUG, "Read handler done"); + VLOG(2) << "Read handler done"; gpr_mu_lock(g_mu); state->read_done = read_done_state; GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr)); @@ -197,7 +197,7 @@ static void read_and_write_test_write_handler(void* data, } } - gpr_log(GPR_DEBUG, "Write handler done"); + VLOG(2) << "Write handler done"; gpr_mu_lock(g_mu); state->write_done = 1 + (error.ok()); GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr)); @@ -218,18 +218,14 @@ static void read_and_write_test(grpc_endpoint_test_config config, grpc_core::ExecCtx exec_ctx; auto deadline = grpc_core::Timestamp::FromTimespecRoundUp( grpc_timeout_seconds_to_deadline(300)); - gpr_log(GPR_DEBUG, - "num_bytes=%" PRIuPTR " write_size=%" PRIuPTR " slice_size=%" PRIuPTR - " shutdown=%d", - num_bytes, write_size, slice_size, shutdown); + VLOG(2) << "num_bytes=" << num_bytes << " write_size=" << write_size + << " slice_size=" << slice_size << " shutdown=" << shutdown; if (shutdown) { - gpr_log(GPR_INFO, "Start read and write shutdown test"); + LOG(INFO) << "Start read and write shutdown test"; } else { - gpr_log(GPR_INFO, - "Start read and write test with %" PRIuPTR - " bytes, slice size %" PRIuPTR, - num_bytes, slice_size); + LOG(INFO) << "Start read and write test with " << num_bytes + << " bytes, slice size " << slice_size; } state.read_ep = f.client_ep; @@ -265,9 +261,9 @@ static void read_and_write_test(grpc_endpoint_test_config config, grpc_endpoint_read(state.read_ep, &state.incoming, &state.done_read, /*urgent=*/false, /*min_progress_size=*/1); if (shutdown) { - gpr_log(GPR_DEBUG, "shutdown read"); + VLOG(2) << "shutdown read"; grpc_endpoint_shutdown(state.read_ep, GRPC_ERROR_CREATE("Test Shutdown")); - gpr_log(GPR_DEBUG, "shutdown write"); + VLOG(2) << "shutdown write"; grpc_endpoint_shutdown(state.write_ep, GRPC_ERROR_CREATE("Test Shutdown")); } grpc_core::ExecCtx::Get()->Flush(); diff --git a/test/core/iomgr/ios/CFStreamTests/CFStreamClientTests.mm b/test/core/iomgr/ios/CFStreamTests/CFStreamClientTests.mm index 8e7dd378836..77adb057d24 100644 --- a/test/core/iomgr/ios/CFStreamTests/CFStreamClientTests.mm +++ b/test/core/iomgr/ios/CFStreamTests/CFStreamClientTests.mm @@ -47,8 +47,8 @@ static void finish_connection() { } static void must_succeed(void* arg, grpc_error_handle error) { - GPR_ASSERT(g_connecting != nullptr); - GPR_ASSERT(error.ok()); + CHECK(g_connecting != nullptr); + CHECK(error.ok()); grpc_endpoint_shutdown(g_connecting, GRPC_ERROR_CREATE("must_succeed called")); grpc_endpoint_destroy(g_connecting); g_connecting = nullptr; @@ -56,8 +56,8 @@ static void must_succeed(void* arg, grpc_error_handle error) { } static void must_fail(void* arg, grpc_error_handle error) { - GPR_ASSERT(g_connecting == nullptr); - GPR_ASSERT(!error.ok()); + CHECK(g_connecting == nullptr); + CHECK(!error.ok()); NSLog(@"%s", grpc_core::StatusToString(error).c_str()); finish_connection(); } @@ -87,21 +87,21 @@ static void must_fail(void* arg, grpc_error_handle error) { gpr_log(GPR_DEBUG, "test_succeeds"); auto resolved_addr = grpc_core::StringToSockaddr("127.0.0.1:0"); - GPR_ASSERT(resolved_addr.ok()); + CHECK(resolved_addr.ok()); struct sockaddr_in* addr = reinterpret_cast(resolved_addr->addr); /* create a phony server */ svr_fd = socket(AF_INET, SOCK_STREAM, 0); - GPR_ASSERT(svr_fd >= 0); - GPR_ASSERT(0 == bind(svr_fd, (struct sockaddr*)addr, (socklen_t)resolved_addr->len)); - GPR_ASSERT(0 == listen(svr_fd, 1)); + CHECK(svr_fd >= 0); + CHECK(0 == bind(svr_fd, (struct sockaddr*)addr, (socklen_t)resolved_addr->len)); + CHECK(0 == listen(svr_fd, 1)); gpr_mu_lock(&g_mu); connections_complete_before = g_connections_complete; gpr_mu_unlock(&g_mu); /* connect to it */ - GPR_ASSERT(getsockname(svr_fd, (struct sockaddr*)addr, (socklen_t*)&resolved_addr->len) == 0); + CHECK(getsockname(svr_fd, (struct sockaddr*)addr, (socklen_t*)&resolved_addr->len) == 0); GRPC_CLOSURE_INIT(&done, must_succeed, nullptr, grpc_schedule_on_exec_ctx); auto args = grpc_core::CoreConfiguration::Get().channel_args_preconditioning().PreconditionChannelArgs( @@ -116,7 +116,7 @@ static void must_fail(void* arg, grpc_error_handle error) { r = accept(svr_fd, reinterpret_cast(addr), reinterpret_cast(&resolved_addr->len)); } while (r == -1 && errno == EINTR); - GPR_ASSERT(r >= 0); + CHECK(r >= 0); close(r); grpc_core::ExecCtx::Get()->Flush(); @@ -144,14 +144,14 @@ static void must_fail(void* arg, grpc_error_handle error) { gpr_log(GPR_DEBUG, "test_fails"); auto resolved_addr = grpc_core::StringToSockaddr("127.0.0.1:0"); - GPR_ASSERT(resolved_addr.ok()); + CHECK(resolved_addr.ok()); struct sockaddr_in* addr = reinterpret_cast(resolved_addr->addr); svr_fd = socket(AF_INET, SOCK_STREAM, 0); - GPR_ASSERT(svr_fd >= 0); - GPR_ASSERT(0 == bind(svr_fd, (struct sockaddr*)addr, (socklen_t)resolved_addr->len)); - GPR_ASSERT(0 == listen(svr_fd, 1)); - GPR_ASSERT(getsockname(svr_fd, (struct sockaddr*)addr, (socklen_t*)&resolved_addr->len) == 0); + CHECK(svr_fd >= 0); + CHECK(0 == bind(svr_fd, (struct sockaddr*)addr, (socklen_t)resolved_addr->len)); + CHECK(0 == listen(svr_fd, 1)); + CHECK(getsockname(svr_fd, (struct sockaddr*)addr, (socklen_t*)&resolved_addr->len) == 0); close(svr_fd); gpr_mu_lock(&g_mu); diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc index 5a487cc4d7e..9cebdbfa87e 100644 --- a/test/core/iomgr/resolve_address_posix_test.cc +++ b/test/core/iomgr/resolve_address_posix_test.cc @@ -26,17 +26,15 @@ #include "absl/flags/flag.h" #include "absl/flags/parse.h" +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include #include -#include #include #include #include "src/core/lib/config/config_vars.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/thd.h" @@ -45,6 +43,8 @@ #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/pollset.h" #include "src/core/lib/iomgr/resolve_address.h" +#include "src/core/util/string.h" +#include "src/core/util/useful.h" #include "test/core/test_util/cmdline.h" #include "test/core/test_util/test_config.h" @@ -105,8 +105,7 @@ static void actually_poll(void* argsp) { break; } grpc_core::Duration time_left = deadline - grpc_core::Timestamp::Now(); - gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRId64, args->done, - time_left.millis()); + VLOG(2) << "done=" << args->done << ", time_left=" << time_left.millis(); ASSERT_GE(time_left, grpc_core::Duration::Zero()); grpc_pollset_worker* worker = nullptr; GRPC_LOG_IF_ERROR( @@ -158,23 +157,21 @@ static void test_named_and_numeric_scope_ids(void) { // system recognizes, and then use that for the test. for (size_t i = 1; i < 65536; i++) { if (if_indextoname(i, arbitrary_interface_name) != nullptr) { - gpr_log(GPR_DEBUG, - "Found interface at index %" PRIuPTR - " named %s. Will use this for the test", - i, arbitrary_interface_name); + VLOG(2) << "Found interface at index " << i << " named " + << arbitrary_interface_name << ". Will use this for the test"; interface_index = static_cast(i); break; } } ASSERT_GT(strlen(arbitrary_interface_name), 0); // Test resolution of an ipv6 address with a named scope ID - gpr_log(GPR_DEBUG, "test resolution with a named scope ID"); + VLOG(2) << "test resolution with a named scope ID"; std::string target_with_named_scope_id = absl::StrFormat("fe80::1234%%%s", arbitrary_interface_name); resolve_address_must_succeed(target_with_named_scope_id.c_str()); gpr_free(arbitrary_interface_name); // Test resolution of an ipv6 address with a numeric scope ID - gpr_log(GPR_DEBUG, "test resolution with a numeric scope ID"); + VLOG(2) << "test resolution with a numeric scope ID"; std::string target_with_numeric_scope_id = absl::StrFormat("fe80::1234%%%d", interface_index); resolve_address_must_succeed(target_with_numeric_scope_id.c_str()); @@ -194,7 +191,7 @@ TEST(ResolveAddressUsingAresResolverPosixTest, MainTest) { } else if (resolver_type == "ares") { overrides.dns_resolver = "ares"; } else { - gpr_log(GPR_ERROR, "--resolver was not set to ares or native"); + LOG(ERROR) << "--resolver was not set to ares or native"; ASSERT_TRUE(false); } grpc_core::ConfigVars::SetOverrides(overrides); diff --git a/test/core/iomgr/resolve_address_test.cc b/test/core/iomgr/resolve_address_test.cc index f9e39608674..8dc158ddf9d 100644 --- a/test/core/iomgr/resolve_address_test.cc +++ b/test/core/iomgr/resolve_address_test.cc @@ -35,7 +35,6 @@ #include #include "src/core/lib/config/config_vars.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/sync.h" #include "src/core/lib/gprpp/time.h" @@ -43,6 +42,7 @@ #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/pollset.h" #include "src/core/resolver/dns/c_ares/grpc_ares_wrapper.h" +#include "src/core/util/string.h" #include "test/core/test_util/cmdline.h" #include "test/core/test_util/fake_udp_and_tcp_server.h" #include "test/core/test_util/test_config.h" diff --git a/test/core/iomgr/socket_utils_test.cc b/test/core/iomgr/socket_utils_test.cc index d28bc96adec..edec3943f7c 100644 --- a/test/core/iomgr/socket_utils_test.cc +++ b/test/core/iomgr/socket_utils_test.cc @@ -34,10 +34,10 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/socket_mutator.h" #include "src/core/lib/iomgr/socket_utils_posix.h" +#include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" struct test_socket_mutator { diff --git a/test/core/iomgr/tcp_client_posix_test.cc b/test/core/iomgr/tcp_client_posix_test.cc index b2f37db2de1..f3f24b06303 100644 --- a/test/core/iomgr/tcp_client_posix_test.cc +++ b/test/core/iomgr/tcp_client_posix_test.cc @@ -36,9 +36,10 @@ #include #include +#include "absl/log/log.h" + #include #include -#include #include #include "src/core/lib/event_engine/channel_args_endpoint_config.h" @@ -88,7 +89,7 @@ static void must_fail(void* /*arg*/, grpc_error_handle error) { } void test_succeeds(void) { - gpr_log(GPR_ERROR, "---- starting test_succeeds() ----"); + LOG(ERROR) << "---- starting test_succeeds() ----"; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); @@ -153,11 +154,11 @@ void test_succeeds(void) { // A cancellation attempt should fail because connect already succeeded. ASSERT_EQ(grpc_tcp_client_cancel_connect(connection_handle), false); - gpr_log(GPR_ERROR, "---- finished test_succeeds() ----"); + LOG(ERROR) << "---- finished test_succeeds() ----"; } void test_fails(void) { - gpr_log(GPR_ERROR, "---- starting test_fails() ----"); + LOG(ERROR) << "---- starting test_fails() ----"; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); @@ -207,11 +208,11 @@ void test_fails(void) { // A cancellation attempt should fail because connect already failed. ASSERT_EQ(grpc_tcp_client_cancel_connect(connection_handle), false); - gpr_log(GPR_ERROR, "---- finished test_fails() ----"); + LOG(ERROR) << "---- finished test_fails() ----"; } void test_connect_cancellation_succeeds(void) { - gpr_log(GPR_ERROR, "---- starting test_connect_cancellation_succeeds() ----"); + LOG(ERROR) << "---- starting test_connect_cancellation_succeeds() ----"; auto target_ipv6_addr_uri = *grpc_core::URI::Parse(absl::StrCat( "ipv6:[::1]:", std::to_string(grpc_pick_unused_port_or_die()))); auto target_ipv4_addr_uri = *grpc_core::URI::Parse(absl::StrCat( @@ -242,9 +243,8 @@ void test_connect_cancellation_succeeds(void) { if (svr_fd >= 0) { close(svr_fd); } - gpr_log(GPR_ERROR, - "Skipping test. Failed to create a phony server bound to ipv6 or " - "ipv4 address"); + LOG(ERROR) << "Skipping test. Failed to create a phony server bound to " + "ipv6 or ipv4 address"; return; } } @@ -310,11 +310,11 @@ void test_connect_cancellation_succeeds(void) { close(sock); } close(svr_fd); - gpr_log(GPR_ERROR, "---- finished test_connect_cancellation_succeeds() ----"); + LOG(ERROR) << "---- finished test_connect_cancellation_succeeds() ----"; } void test_fails_bad_addr_no_leak(void) { - gpr_log(GPR_ERROR, "---- starting test_fails_bad_addr_no_leak() ----"); + LOG(ERROR) << "---- starting test_fails_bad_addr_no_leak() ----"; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); @@ -355,7 +355,7 @@ void test_fails_bad_addr_no_leak(void) { gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); - gpr_log(GPR_ERROR, "---- finished test_fails_bad_addr_no_leak() ----"); + LOG(ERROR) << "---- finished test_fails_bad_addr_no_leak() ----"; } static void destroy_pollset(void* p, grpc_error_handle /*error*/) { diff --git a/test/core/iomgr/tcp_posix_test.cc b/test/core/iomgr/tcp_posix_test.cc index e7c246c99bc..9f50defcc42 100644 --- a/test/core/iomgr/tcp_posix_test.cc +++ b/test/core/iomgr/tcp_posix_test.cc @@ -47,7 +47,6 @@ #include "src/core/lib/event_engine/default_event_engine.h" #include "src/core/lib/event_engine/posix.h" #include "src/core/lib/event_engine/shim.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/buffer_list.h" #include "src/core/lib/iomgr/ev_posix.h" @@ -56,6 +55,7 @@ #include "src/core/lib/iomgr/socket_utils_posix.h" #include "src/core/lib/iomgr/tcp_posix.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/util/useful.h" #include "test/core/iomgr/endpoint_tests.h" #include "test/core/test_util/test_config.h" diff --git a/test/core/iomgr/tcp_server_posix_test.cc b/test/core/iomgr/tcp_server_posix_test.cc index e31f6c07ded..469d6990502 100644 --- a/test/core/iomgr/tcp_server_posix_test.cc +++ b/test/core/iomgr/tcp_server_posix_test.cc @@ -41,9 +41,10 @@ #include +#include "absl/log/log.h" + #include #include -#include #include #include @@ -59,7 +60,7 @@ #include "src/core/lib/resource_quota/api.h" #include "test/core/test_util/port.h" -#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", #x) +#define LOG_TEST(x) LOG(INFO) << #x static gpr_mu* g_mu; static grpc_pollset* g_pollset; @@ -272,7 +273,7 @@ static grpc_error_handle tcp_connect(const test_addr* remote, const struct sockaddr* remote_addr = reinterpret_cast(remote->addr.addr); - gpr_log(GPR_INFO, "Connecting to %s", remote->str); + LOG(INFO) << "Connecting to " << remote->str; gpr_mu_lock(g_mu); nconnects_before = g_nconnects; on_connect_result_init(&g_result); @@ -281,14 +282,14 @@ static grpc_error_handle tcp_connect(const test_addr* remote, gpr_mu_unlock(g_mu); return GRPC_OS_ERROR(errno, "Failed to create socket"); } - gpr_log(GPR_DEBUG, "start connect to %s", remote->str); + VLOG(2) << "start connect to " << remote->str; if (connect(clifd, remote_addr, static_cast(remote->addr.len)) != 0) { gpr_mu_unlock(g_mu); close(clifd); return GRPC_OS_ERROR(errno, "connect"); } - gpr_log(GPR_DEBUG, "wait"); + VLOG(2) << "wait"; while (g_nconnects == nconnects_before && deadline > grpc_core::Timestamp::Now()) { grpc_pollset_worker* worker = nullptr; @@ -303,7 +304,7 @@ static grpc_error_handle tcp_connect(const test_addr* remote, gpr_mu_lock(g_mu); } - gpr_log(GPR_DEBUG, "wait done"); + VLOG(2) << "wait done"; if (g_nconnects != nconnects_before + 1) { gpr_mu_unlock(g_mu); close(clifd); @@ -313,8 +314,8 @@ static grpc_error_handle tcp_connect(const test_addr* remote, *result = g_result; gpr_mu_unlock(g_mu); - gpr_log(GPR_INFO, "Result (%d, %d) fd %d", result->port_index, - result->fd_index, result->server_fd); + LOG(INFO) << "Result (" << result->port_index << ", " << result->fd_index + << ") fd " << result->server_fd; grpc_tcp_server_unref(result->server); return absl::OkStatus(); } @@ -356,12 +357,10 @@ static void test_connect(size_t num_connects, server_weak_ref_init(&weak_ref); server_weak_ref_set(&weak_ref, s); LOG_TEST("test_connect"); - gpr_log(GPR_INFO, - "clients=%lu, num chan args=%lu, remote IP=%s, test_dst_addrs=%d", - static_cast(num_connects), - static_cast( - channel_args != nullptr ? channel_args->num_args : 0), - dst_addrs != nullptr ? "" : "::", test_dst_addrs); + LOG(INFO) << "clients=" << num_connects << ", num chan args=" + << (channel_args != nullptr ? channel_args->num_args : 0) + << ", remote IP=" << (dst_addrs != nullptr ? "" : "::") + << ", test_dst_addrs=" << test_dst_addrs; memset(&resolved_addr, 0, sizeof(resolved_addr)); memset(&resolved_addr1, 0, sizeof(resolved_addr1)); resolved_addr.len = static_cast(sizeof(struct sockaddr_storage)); @@ -370,13 +369,13 @@ static void test_connect(size_t num_connects, ASSERT_TRUE(GRPC_LOG_IF_ERROR( "grpc_tcp_server_add_port", grpc_tcp_server_add_port(s, &resolved_addr, &svr_port))); - gpr_log(GPR_INFO, "Allocated port %d", svr_port); + LOG(INFO) << "Allocated port " << svr_port; ASSERT_GT(svr_port, 0); // Cannot use wildcard (port==0), because add_port() will try to reuse the // same port as a previous add_port(). svr1_port = grpc_pick_unused_port_or_die(); ASSERT_GT(svr1_port, 0); - gpr_log(GPR_INFO, "Picked unused port %d", svr1_port); + LOG(INFO) << "Picked unused port " << svr1_port; grpc_sockaddr_set_port(&resolved_addr1, svr1_port); ASSERT_EQ(grpc_tcp_server_add_port(s, &resolved_addr1, &port), absl::OkStatus()); @@ -410,8 +409,7 @@ static void test_connect(size_t num_connects, on_connect_result result; grpc_error_handle err; if (dst.addr.len == 0) { - gpr_log(GPR_DEBUG, "Skipping test of non-functional local IP %s", - dst.str); + VLOG(2) << "Skipping test of non-functional local IP " << dst.str; continue; } ASSERT_TRUE(grpc_sockaddr_set_port(&dst.addr, ports[port_num])); @@ -422,8 +420,8 @@ static void test_connect(size_t num_connects, result.server_fd >= 0 && result.server == s) { continue; } - gpr_log(GPR_ERROR, "Failed to connect to %s: %s", dst.str, - grpc_core::StatusToString(err).c_str()); + LOG(ERROR) << "Failed to connect to " << dst.str << ": " + << grpc_core::StatusToString(err); ASSERT_TRUE(test_dst_addrs); dst_addrs->addrs[dst_idx].addr.len = 0; } @@ -444,8 +442,9 @@ static void test_connect(size_t num_connects, 0); ASSERT_LE(dst.addr.len, sizeof(dst.addr.addr)); test_addr_init_str(&dst); - gpr_log(GPR_INFO, "(%d, %d) fd %d family %s listening on %s", port_num, - fd_num, fd, sock_family_name(addr->ss_family), dst.str); + LOG(INFO) << "(" << port_num << ", " << fd_num << ") fd " << fd + << " family " << sock_family_name(addr->ss_family) + << " listening on " << dst.str; for (connect_num = 0; connect_num < num_connects; ++connect_num) { on_connect_result result; on_connect_result_init(&result); @@ -482,7 +481,7 @@ static int pre_allocate_inet_sock(grpc_tcp_server* s, int family, int port, int pre_fd = socket(address.sin6_family, SOCK_STREAM, 0); if (pre_fd < 0) { - gpr_log(GPR_ERROR, "Unable to create inet socket: %m"); + LOG(ERROR) << "Unable to create inet socket: %m"; return -1; } @@ -492,13 +491,13 @@ static int pre_allocate_inet_sock(grpc_tcp_server* s, int family, int port, int b = bind(pre_fd, reinterpret_cast(&address), sizeof(address)); if (b < 0) { - gpr_log(GPR_ERROR, "Unable to bind inet socket: %m"); + LOG(ERROR) << "Unable to bind inet socket: %m"; return -1; } int l = listen(pre_fd, SOMAXCONN); if (l < 0) { - gpr_log(GPR_ERROR, "Unable to listen on inet socket: %m"); + LOG(ERROR) << "Unable to listen on inet socket: %m"; return -1; } @@ -587,20 +586,20 @@ static int pre_allocate_unix_sock(grpc_tcp_server* s, const char* path, int pre_fd = socket(address.sun_family, SOCK_STREAM, 0); if (pre_fd < 0) { - gpr_log(GPR_ERROR, "Unable to create unix socket: %m"); + LOG(ERROR) << "Unable to create unix socket: %m"; return -1; } int b = bind(pre_fd, reinterpret_cast(&address), sizeof(address)); if (b < 0) { - gpr_log(GPR_ERROR, "Unable to bind unix socket: %m"); + LOG(ERROR) << "Unable to bind unix socket: %m"; return -1; } int l = listen(pre_fd, SOMAXCONN); if (l < 0) { - gpr_log(GPR_ERROR, "Unable to listen on unix socket: %m"); + LOG(ERROR) << "Unable to listen on unix socket: %m"; return -1; } @@ -679,8 +678,8 @@ static void test_pre_allocated_unix_fd() { // If the path no longer exists, errno is 2. This can happen when // runninig the test multiple times in parallel. Do not fail the test if (absl::IsUnknown(res_conn) && res_conn.raw_code() == 2) { - gpr_log(GPR_ERROR, - "Unable to test pre_allocated unix socket: path does not exist"); + LOG(ERROR) + << "Unable to test pre_allocated unix socket: path does not exist"; grpc_tcp_server_unref(s); close(pre_fd); return; diff --git a/test/core/iomgr/timer_heap_test.cc b/test/core/iomgr/timer_heap_test.cc index 3cb7a4c7360..af4571a4031 100644 --- a/test/core/iomgr/timer_heap_test.cc +++ b/test/core/iomgr/timer_heap_test.cc @@ -23,12 +23,13 @@ #include +#include "absl/log/log.h" + #include -#include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/port.h" +#include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" static gpr_atm random_deadline(void) { return rand(); } @@ -77,7 +78,7 @@ static void test1(void) { grpc_timer* test_elements = create_test_elements(num_test_elements); uint8_t* inpq = static_cast(gpr_malloc(num_test_elements)); - gpr_log(GPR_INFO, "test1"); + LOG(INFO) << "test1"; grpc_timer_heap_init(&pq); memset(inpq, 0, num_test_elements); @@ -156,7 +157,7 @@ static elem_struct* search_elems(elem_struct* elems, size_t count, } static void test2(void) { - gpr_log(GPR_INFO, "test2"); + LOG(INFO) << "test2"; grpc_timer_heap pq; @@ -227,7 +228,7 @@ static void test2(void) { } static void shrink_test(void) { - gpr_log(GPR_INFO, "shrink_test"); + LOG(INFO) << "shrink_test"; grpc_timer_heap pq; size_t i; diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index ea48b8b1f5f..aa1d545bea7 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -22,9 +22,9 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include -#include #include "src/core/lib/debug/trace.h" #include "src/core/lib/gprpp/crash.h" @@ -54,7 +54,7 @@ static void add_test(void) { grpc_timer timers[20]; grpc_core::ExecCtx exec_ctx; - gpr_log(GPR_INFO, "add_test"); + LOG(INFO) << "add_test"; grpc_timer_list_init(); grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_trace); @@ -122,7 +122,7 @@ void destruction_test(void) { grpc_timer timers[5]; grpc_core::ExecCtx exec_ctx; - gpr_log(GPR_INFO, "destruction_test"); + LOG(INFO) << "destruction_test"; grpc_core::ExecCtx::Get()->TestOnlySetNow( grpc_core::Timestamp::FromMillisecondsAfterProcessEpoch(0)); @@ -179,7 +179,7 @@ void long_running_service_cleanup_test(void) { grpc_timer timers[4]; grpc_core::ExecCtx exec_ctx; - gpr_log(GPR_INFO, "long_running_service_cleanup_test"); + LOG(INFO) << "long_running_service_cleanup_test"; grpc_core::Timestamp now = grpc_core::Timestamp::Now(); CHECK(now.milliseconds_after_process_epoch() >= k25Days.millis()); diff --git a/test/core/json/BUILD b/test/core/json/BUILD index 1d144b8d326..ceeb2c0670a 100644 --- a/test/core/json/BUILD +++ b/test/core/json/BUILD @@ -37,6 +37,7 @@ grpc_cc_test( name = "json_test", srcs = ["json_test.cc"], external_deps = [ + "absl/log:log", "gtest", ], language = "C++", diff --git a/test/core/load_balancing/BUILD b/test/core/load_balancing/BUILD index 2cf14f5858e..2c98aa6dfc5 100644 --- a/test/core/load_balancing/BUILD +++ b/test/core/load_balancing/BUILD @@ -29,6 +29,7 @@ grpc_cc_library( hdrs = ["lb_policy_test_lib.h"], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], language = "C++", @@ -104,7 +105,10 @@ grpc_cc_test( grpc_cc_test( name = "outlier_detection_test", srcs = ["outlier_detection_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", tags = [ "lb_unit_test", @@ -140,7 +144,10 @@ grpc_cc_test( grpc_cc_test( name = "xds_override_host_test", srcs = ["xds_override_host_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", tags = [ "lb_unit_test", @@ -230,7 +237,10 @@ grpc_cc_test( grpc_cc_test( name = "weighted_round_robin_test", srcs = ["weighted_round_robin_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", tags = [ "lb_unit_test", diff --git a/test/core/load_balancing/lb_policy_test_lib.h b/test/core/load_balancing/lb_policy_test_lib.h index 3c57342e5d4..46e0e7d4fec 100644 --- a/test/core/load_balancing/lb_policy_test_lib.h +++ b/test/core/load_balancing/lb_policy_test_lib.h @@ -36,6 +36,7 @@ #include "absl/base/thread_annotations.h" #include "absl/functional/any_invocable.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_format.h" @@ -51,7 +52,6 @@ #include #include #include -#include #include #include "src/core/client_channel/client_channel_internal.h" @@ -152,8 +152,8 @@ class LoadBalancingPolicyTest : public ::testing::Test { void OnConnectivityStateChange(grpc_connectivity_state new_state, const absl::Status& status) override { - gpr_log(GPR_INFO, "notifying watcher: state=%s status=%s", - ConnectivityStateName(new_state), status.ToString().c_str()); + LOG(INFO) << "notifying watcher: state=" + << ConnectivityStateName(new_state) << " status=" << status; watcher_->OnConnectivityStateChange(new_state, status); } @@ -212,11 +212,10 @@ class LoadBalancingPolicyTest : public ::testing::Test { health_watcher_wrapper_ = watcher_wrapper.get(); state_->state_tracker_.AddWatcher(GRPC_CHANNEL_SHUTDOWN, std::move(watcher_wrapper)); - gpr_log(GPR_INFO, - "AddDataWatcher(): added HealthWatch=%p " - "connectivity_watcher=%p watcher_wrapper=%p", - health_watcher_.get(), connectivity_watcher_ptr, - health_watcher_wrapper_); + LOG(INFO) << "AddDataWatcher(): added HealthWatch=" + << health_watcher_.get() + << " connectivity_watcher=" << connectivity_watcher_ptr + << " watcher_wrapper=" << health_watcher_wrapper_; } } @@ -232,10 +231,9 @@ class LoadBalancingPolicyTest : public ::testing::Test { if (health_watcher_.get() != static_cast(watcher)) { return; } - gpr_log(GPR_INFO, - "CancelDataWatcher(): cancelling HealthWatch=%p " - "watcher_wrapper=%p", - health_watcher_.get(), health_watcher_wrapper_); + LOG(INFO) << "CancelDataWatcher(): cancelling HealthWatch=" + << health_watcher_.get() + << " watcher_wrapper=" << health_watcher_wrapper_; state_->state_tracker_.RemoveWatcher(health_watcher_wrapper_); health_watcher_wrapper_ = nullptr; health_watcher_.reset(); @@ -327,18 +325,16 @@ class LoadBalancingPolicyTest : public ::testing::Test { AssertValidConnectivityStateTransition(state_tracker_.state(), state, location); } - gpr_log(GPR_INFO, "Setting state on tracker"); + LOG(INFO) << "Setting state on tracker"; state_tracker_.SetState(state, status, "set from test"); // SetState() enqueued the connectivity state notifications for // the subchannel, so we add another callback to the queue to be // executed after that state notifications has been delivered. - gpr_log(GPR_INFO, - "Waiting for state notifications to be delivered"); + LOG(INFO) << "Waiting for state notifications to be delivered"; test_->work_serializer_->Run( [&]() { - gpr_log(GPR_INFO, - "State notifications delivered, waiting for health " - "notifications"); + LOG(INFO) << "State notifications delivered, waiting for " + "health notifications"; // Now the connectivity state notifications has been // delivered. If the state reported was READY, then the // pick_first leaf policy will have started a health watch, so @@ -351,7 +347,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { }, DEBUG_LOCATION); notification.WaitForNotification(); - gpr_log(GPR_INFO, "Health notifications delivered"); + LOG(INFO) << "Health notifications delivered"; } // Indicates if any of the associated SubchannelInterface objects @@ -472,8 +468,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { << location.file() << ":" << location.line(); if (update == nullptr) return absl::nullopt; StateUpdate result = std::move(*update); - gpr_log(GPR_INFO, "dequeued next state update: %s", - result.ToString().c_str()); + LOG(INFO) << "dequeued next state update: " << result.ToString(); queue_.pop_front(); return std::move(result); } @@ -506,8 +501,8 @@ class LoadBalancingPolicyTest : public ::testing::Test { PickerWrapper(LoadBalancingPolicyTest* test, RefCountedPtr picker) : test_(test), picker_(std::move(picker)) { - gpr_log(GPR_INFO, "creating wrapper %p for picker %p", this, - picker_.get()); + LOG(INFO) << "creating wrapper " << this << " for picker " + << picker_.get(); } void Orphaned() override { @@ -579,8 +574,8 @@ class LoadBalancingPolicyTest : public ::testing::Test { StateUpdate update{ state, status, MakeRefCounted(test_, std::move(picker))}; - gpr_log(GPR_INFO, "enqueuing state update from LB policy: %s", - update.ToString().c_str()); + LOG(INFO) << "enqueuing state update from LB policy: " + << update.ToString(); queue_.push_back(std::move(update)); } @@ -847,14 +842,12 @@ class LoadBalancingPolicyTest : public ::testing::Test { // notifications for the subchannels, so we add another // callback to the queue to be executed after those initial // state notifications have been delivered. - gpr_log(GPR_INFO, - "Applied update, waiting for initial connectivity state " - "notifications"); + LOG(INFO) << "Applied update, waiting for initial connectivity state " + "notifications"; work_serializer_->Run( [&]() { - gpr_log(GPR_INFO, - "Initial connectivity state notifications delivered; " - "waiting for health notifications"); + LOG(INFO) << "Initial connectivity state notifications " + "delivered; waiting for health notifications"; // Now that the initial state notifications have been // delivered, the queue will contain the health watch // notifications for any subchannels in state READY, @@ -868,7 +861,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { }, DEBUG_LOCATION); notification.WaitForNotification(); - gpr_log(GPR_INFO, "health notifications delivered"); + LOG(INFO) << "health notifications delivered"; return status; } @@ -900,15 +893,15 @@ class LoadBalancingPolicyTest : public ::testing::Test { bool WaitForStateUpdate( std::function continue_predicate, SourceLocation location = SourceLocation()) { - gpr_log(GPR_INFO, "==> WaitForStateUpdate()"); + LOG(INFO) << "==> WaitForStateUpdate()"; while (true) { auto update = helper_->GetNextStateUpdate(location); if (!update.has_value()) { - gpr_log(GPR_INFO, "WaitForStateUpdate() returning false"); + LOG(INFO) << "WaitForStateUpdate() returning false"; return false; } if (!continue_predicate(std::move(*update))) { - gpr_log(GPR_INFO, "WaitForStateUpdate() returning true"); + LOG(INFO) << "WaitForStateUpdate() returning true"; return true; } } @@ -945,7 +938,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { // update for state READY, whose picker is returned. RefCountedPtr WaitForConnected( SourceLocation location = SourceLocation()) { - gpr_log(GPR_INFO, "==> WaitForConnected()"); + LOG(INFO) << "==> WaitForConnected()"; RefCountedPtr final_picker; WaitForStateUpdate( [&](FakeHelper::StateUpdate update) { @@ -1022,7 +1015,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { const CallAttributes& call_attributes = {}, size_t num_iterations = 3, SourceLocation location = SourceLocation()) { - gpr_log(GPR_INFO, "Waiting for expected RR addresses..."); + LOG(INFO) << "Waiting for expected RR addresses..."; RefCountedPtr retval; size_t num_picks = std::max(new_addresses.size(), old_addresses.size()) * num_iterations; @@ -1038,7 +1031,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { EXPECT_TRUE(picks.has_value()) << location.file() << ":" << location.line(); if (!picks.has_value()) return false; - gpr_log(GPR_INFO, "PICKS: %s", absl::StrJoin(*picks, " ").c_str()); + LOG(INFO) << "PICKS: " << absl::StrJoin(*picks, " "); // If the picks still match the old list, then keep going. if (PicksAreRoundRobin(old_addresses, *picks)) return true; // Otherwise, the picks should match the new list. @@ -1053,7 +1046,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { return false; // Stop. }, location); - gpr_log(GPR_INFO, "done waiting for expected RR addresses"); + LOG(INFO) << "done waiting for expected RR addresses"; return retval; } @@ -1307,7 +1300,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { RefCountedPtr DrainRoundRobinPickerUpdates(absl::Span addresses, SourceLocation location = SourceLocation()) { - gpr_log(GPR_INFO, "Draining RR picker updates..."); + LOG(INFO) << "Draining RR picker updates..."; RefCountedPtr picker; while (!helper_->QueueEmpty()) { auto update = helper_->GetNextStateUpdate(location); @@ -1322,17 +1315,17 @@ class LoadBalancingPolicyTest : public ::testing::Test { location); picker = std::move(update->picker); } - gpr_log(GPR_INFO, "Done draining RR picker updates"); + LOG(INFO) << "Done draining RR picker updates"; return picker; } // Expects zero or more CONNECTING updates. void DrainConnectingUpdates(SourceLocation location = SourceLocation()) { - gpr_log(GPR_INFO, "Draining CONNECTING updates..."); + LOG(INFO) << "Draining CONNECTING updates..."; while (!helper_->QueueEmpty()) { ASSERT_TRUE(ExpectConnectingUpdate(location)); } - gpr_log(GPR_INFO, "Done draining CONNECTING updates"); + LOG(INFO) << "Done draining CONNECTING updates"; } // Triggers a connection failure for the current address for an @@ -1341,10 +1334,10 @@ class LoadBalancingPolicyTest : public ::testing::Test { absl::Span addresses, size_t current_index, size_t new_index, absl::AnyInvocable expect_after_disconnect, SourceLocation location = SourceLocation()) { - gpr_log(GPR_INFO, - "Expecting endpoint address change: addresses={%s}, " - "current_index=%" PRIuPTR ", new_index=%" PRIuPTR, - absl::StrJoin(addresses, ", ").c_str(), current_index, new_index); + LOG(INFO) << "Expecting endpoint address change: addresses={" + << absl::StrJoin(addresses, ", ") + << "}, current_index=" << current_index + << ", new_index=" << new_index; ASSERT_LT(current_index, addresses.size()); ASSERT_LT(new_index, addresses.size()); // Find all subchannels. @@ -1385,7 +1378,7 @@ class LoadBalancingPolicyTest : public ::testing::Test { // interacts with it again. subchannel->SetConnectivityState(GRPC_CHANNEL_IDLE); } - gpr_log(GPR_INFO, "Done with endpoint address change"); + LOG(INFO) << "Done with endpoint address change"; } // Requests a picker on picker and expects a Fail result. @@ -1451,19 +1444,18 @@ class LoadBalancingPolicyTest : public ::testing::Test { void WaitForWorkSerializerToFlush() { ExecCtx exec_ctx; - gpr_log(GPR_INFO, "waiting for WorkSerializer to flush..."); + LOG(INFO) << "waiting for WorkSerializer to flush..."; absl::Notification notification; work_serializer_->Run([&]() { notification.Notify(); }, DEBUG_LOCATION); notification.WaitForNotification(); - gpr_log(GPR_INFO, "WorkSerializer flush complete"); + LOG(INFO) << "WorkSerializer flush complete"; } void IncrementTimeBy(Duration duration) { ExecCtx exec_ctx; - gpr_log(GPR_INFO, "Incrementing time by %s...", - duration.ToString().c_str()); + LOG(INFO) << "Incrementing time by " << duration; fuzzing_ee_->TickForDuration(duration); - gpr_log(GPR_INFO, "Done incrementing time"); + LOG(INFO) << "Done incrementing time"; // Flush WorkSerializer, in case the timer callback enqueued anything. WaitForWorkSerializerToFlush(); } diff --git a/test/core/load_balancing/outlier_detection_test.cc b/test/core/load_balancing/outlier_detection_test.cc index ba60dce52eb..db425e666fa 100644 --- a/test/core/load_balancing/outlier_detection_test.cc +++ b/test/core/load_balancing/outlier_detection_test.cc @@ -25,6 +25,7 @@ #include #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" @@ -33,7 +34,6 @@ #include #include -#include #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -215,14 +215,14 @@ TEST_F(OutlierDetectionTest, FailurePercentage) { // Expect normal startup. auto picker = ExpectRoundRobinStartup(kAddresses); ASSERT_NE(picker, nullptr); - gpr_log(GPR_INFO, "### RR startup complete"); + LOG(INFO) << "### RR startup complete"; // Do a pick and report a failed call. auto address = DoPickWithFailedCall(picker.get()); ASSERT_TRUE(address.has_value()); - gpr_log(GPR_INFO, "### failed RPC on %s", address->c_str()); + LOG(INFO) << "### failed RPC on " << *address; // Advance time and run the timer callback to trigger ejection. IncrementTimeBy(Duration::Seconds(10)); - gpr_log(GPR_INFO, "### ejection complete"); + LOG(INFO) << "### ejection complete"; // Expect a picker update. std::vector remaining_addresses; for (const auto& addr : kAddresses) { @@ -231,7 +231,7 @@ TEST_F(OutlierDetectionTest, FailurePercentage) { WaitForRoundRobinListChange(kAddresses, remaining_addresses); // Advance time and run the timer callback to trigger un-ejection. IncrementTimeBy(Duration::Seconds(10)); - gpr_log(GPR_INFO, "### un-ejection complete"); + LOG(INFO) << "### un-ejection complete"; // Expect a picker update. WaitForRoundRobinListChange(remaining_addresses, kAddresses); } @@ -265,11 +265,11 @@ TEST_F(OutlierDetectionTest, MultipleAddressesPerEndpoint) { // Expect normal startup. auto picker = ExpectRoundRobinStartup(kEndpoints); ASSERT_NE(picker, nullptr); - gpr_log(GPR_INFO, "### RR startup complete"); + LOG(INFO) << "### RR startup complete"; // Do a pick and report a failed call. auto address = DoPickWithFailedCall(picker.get()); ASSERT_TRUE(address.has_value()); - gpr_log(GPR_INFO, "### failed RPC on %s", address->c_str()); + LOG(INFO) << "### failed RPC on " << *address; // Based on the address that the failed call went to, we determine // which addresses to use in the subsequent steps. absl::Span ejected_endpoint_addresses; @@ -297,12 +297,12 @@ TEST_F(OutlierDetectionTest, MultipleAddressesPerEndpoint) { } // Advance time and run the timer callback to trigger ejection. IncrementTimeBy(Duration::Seconds(10)); - gpr_log(GPR_INFO, "### ejection complete"); + LOG(INFO) << "### ejection complete"; // Expect a picker that removes the ejected address. WaitForRoundRobinListChange( {kEndpoint1Addresses[0], kEndpoint2Addresses[0], kEndpoint3Addresses[0]}, {sentinel_endpoint_addresses[0], unmodified_endpoint_address}); - gpr_log(GPR_INFO, "### ejected endpoint removed"); + LOG(INFO) << "### ejected endpoint removed"; // Cause the connection to the ejected endpoint to fail, and then // have it reconnect to a different address. The endpoint is still // ejected, so the new address should not be used. @@ -312,7 +312,7 @@ TEST_F(OutlierDetectionTest, MultipleAddressesPerEndpoint) { // re-resolution request in the queue. DrainRoundRobinPickerUpdates( {sentinel_endpoint_addresses[0], unmodified_endpoint_address}); - gpr_log(GPR_INFO, "### done changing address of ejected endpoint"); + LOG(INFO) << "### done changing address of ejected endpoint"; // Do the same thing for the sentinel endpoint, so that we // know that the LB policy has seen the address change for the ejected // endpoint. @@ -324,10 +324,10 @@ TEST_F(OutlierDetectionTest, MultipleAddressesPerEndpoint) { WaitForRoundRobinListChange( {unmodified_endpoint_address}, {sentinel_endpoint_addresses[1], unmodified_endpoint_address}); - gpr_log(GPR_INFO, "### done changing address of ejected endpoint"); + LOG(INFO) << "### done changing address of ejected endpoint"; // Advance time and run the timer callback to trigger un-ejection. IncrementTimeBy(Duration::Seconds(10)); - gpr_log(GPR_INFO, "### un-ejection complete"); + LOG(INFO) << "### un-ejection complete"; // The ejected endpoint should come back using the new address. WaitForRoundRobinListChange( {sentinel_endpoint_addresses[1], unmodified_endpoint_address}, @@ -363,11 +363,11 @@ TEST_F(OutlierDetectionTest, EjectionStateResetsWhenEndpointAddressesChange) { // Expect normal startup. auto picker = ExpectRoundRobinStartup(kEndpoints); ASSERT_NE(picker, nullptr); - gpr_log(GPR_INFO, "### RR startup complete"); + LOG(INFO) << "### RR startup complete"; // Do a pick and report a failed call. auto ejected_address = DoPickWithFailedCall(picker.get()); ASSERT_TRUE(ejected_address.has_value()); - gpr_log(GPR_INFO, "### failed RPC on %s", ejected_address->c_str()); + LOG(INFO) << "### failed RPC on " << *ejected_address; // Based on the address that the failed call went to, we determine // which addresses to use in the subsequent steps. std::vector expected_round_robin_while_ejected; @@ -393,12 +393,12 @@ TEST_F(OutlierDetectionTest, EjectionStateResetsWhenEndpointAddressesChange) { } // Advance time and run the timer callback to trigger ejection. IncrementTimeBy(Duration::Seconds(10)); - gpr_log(GPR_INFO, "### ejection complete"); + LOG(INFO) << "### ejection complete"; // Expect a picker that removes the ejected address. WaitForRoundRobinListChange( {kEndpoint1Addresses[0], kEndpoint2Addresses[0], kEndpoint3Addresses[0]}, expected_round_robin_while_ejected); - gpr_log(GPR_INFO, "### ejected endpoint removed"); + LOG(INFO) << "### ejected endpoint removed"; // Send an update that removes the other address from the ejected endpoint. status = ApplyUpdate(BuildUpdate(new_endpoints, kConfig), lb_policy_.get()); EXPECT_TRUE(status.ok()) << status; @@ -447,14 +447,14 @@ TEST_F(OutlierDetectionTest, DoesNotWorkWithPickFirst) { for (size_t i = 0; i < 3; ++i) { EXPECT_EQ(ExpectPickComplete(picker.get()), kAddresses[0]); } - gpr_log(GPR_INFO, "### PF startup complete"); + LOG(INFO) << "### PF startup complete"; // Now have an RPC to that subchannel fail. auto address = DoPickWithFailedCall(picker.get()); ASSERT_TRUE(address.has_value()); - gpr_log(GPR_INFO, "### failed RPC on %s", address->c_str()); + LOG(INFO) << "### failed RPC on " << *address; // Advance time and run the timer callback to trigger ejection. IncrementTimeBy(Duration::Seconds(10)); - gpr_log(GPR_INFO, "### ejection timer pass complete"); + LOG(INFO) << "### ejection timer pass complete"; // Subchannel should not be ejected. ExpectQueueEmpty(); // Subchannel should not see a reconnection request. diff --git a/test/core/load_balancing/pick_first_test.cc b/test/core/load_balancing/pick_first_test.cc index e3dfd04ffc9..839afa62a3c 100644 --- a/test/core/load_balancing/pick_first_test.cc +++ b/test/core/load_balancing/pick_first_test.cc @@ -1307,8 +1307,8 @@ TEST_F(PickFirstTest, MetricValues) { // The first subchannel's connection attempt fails. subchannel->SetConnectivityState(GRPC_CHANNEL_TRANSIENT_FAILURE, absl::UnavailableError("failed to connect")); - EXPECT_THAT(stats_plugin->GetCounterValue(kConnectionAttemptsFailed, - kLabelValues, {}), + EXPECT_THAT(stats_plugin->GetUInt64CounterValue(kConnectionAttemptsFailed, + kLabelValues, {}), ::testing::Optional(1)); // The LB policy will start a connection attempt on the second subchannel. EXPECT_TRUE(subchannel2->ConnectionRequested()); @@ -1317,8 +1317,8 @@ TEST_F(PickFirstTest, MetricValues) { subchannel2->SetConnectivityState(GRPC_CHANNEL_CONNECTING); // The connection attempt succeeds. subchannel2->SetConnectivityState(GRPC_CHANNEL_READY); - EXPECT_THAT(stats_plugin->GetCounterValue(kConnectionAttemptsSucceeded, - kLabelValues, {}), + EXPECT_THAT(stats_plugin->GetUInt64CounterValue(kConnectionAttemptsSucceeded, + kLabelValues, {}), ::testing::Optional(1)); // The LB policy will report CONNECTING some number of times (doesn't // matter how many) and then report READY. @@ -1332,8 +1332,9 @@ TEST_F(PickFirstTest, MetricValues) { subchannel2->SetConnectivityState(GRPC_CHANNEL_IDLE); ExpectReresolutionRequest(); ExpectState(GRPC_CHANNEL_IDLE); - EXPECT_THAT(stats_plugin->GetCounterValue(kDisconnections, kLabelValues, {}), - ::testing::Optional(1)); + EXPECT_THAT( + stats_plugin->GetUInt64CounterValue(kDisconnections, kLabelValues, {}), + ::testing::Optional(1)); } class PickFirstHealthCheckingEnabledTest : public PickFirstTest { diff --git a/test/core/load_balancing/weighted_round_robin_test.cc b/test/core/load_balancing/weighted_round_robin_test.cc index 9177562e919..58a3be1fa14 100644 --- a/test/core/load_balancing/weighted_round_robin_test.cc +++ b/test/core/load_balancing/weighted_round_robin_test.cc @@ -27,6 +27,7 @@ #include #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" @@ -38,7 +39,6 @@ #include #include -#include #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/orphanable.h" @@ -98,7 +98,7 @@ class WeightedRoundRobinTest : public LoadBalancingPolicyTest { RefCountedPtr Build() { Json config = Json::FromArray({Json::FromObject( {{"weighted_round_robin", Json::FromObject(json_)}})}); - gpr_log(GPR_INFO, "CONFIG: %s", JsonDump(config).c_str()); + LOG(INFO) << "CONFIG: " << JsonDump(config); return MakeConfig(config); } @@ -247,10 +247,10 @@ class WeightedRoundRobinTest : public LoadBalancingPolicyTest { auto picks = GetCompletePicks(picker, NumPicksNeeded(expected), {}, &subchannel_call_trackers, location); ASSERT_TRUE(picks.has_value()) << location.file() << ":" << location.line(); - gpr_log(GPR_INFO, "PICKS: %s", absl::StrJoin(*picks, " ").c_str()); + LOG(INFO) << "PICKS: " << absl::StrJoin(*picks, " "); ReportBackendMetrics(*picks, subchannel_call_trackers, backend_metrics); auto actual = MakePickMap(*picks); - gpr_log(GPR_INFO, "Pick map: %s", PickMapString(actual).c_str()); + LOG(INFO) << "Pick map: " << PickMapString(actual); EXPECT_EQ(expected, actual) << "Expected: " << PickMapString(expected) << "\nActual: " << PickMapString(actual) << "\nat " << location.file() @@ -265,17 +265,17 @@ class WeightedRoundRobinTest : public LoadBalancingPolicyTest { absl::Duration timeout = absl::Seconds(5), bool run_timer_callbacks = true, SourceLocation location = SourceLocation()) { - gpr_log(GPR_INFO, "==> WaitForWeightedRoundRobinPicks(): Expecting %s", - PickMapString(expected).c_str()); + LOG(INFO) << "==> WaitForWeightedRoundRobinPicks(): Expecting " + << PickMapString(expected); size_t num_picks = NumPicksNeeded(expected); absl::Time deadline = absl::Now() + timeout; while (true) { - gpr_log(GPR_INFO, "TOP OF LOOP"); + LOG(INFO) << "TOP OF LOOP"; // We need to see the expected weights for 3 consecutive passes, just // to make sure we're consistently returning the right weights. size_t num_passes = 0; for (; num_passes < 3; ++num_passes) { - gpr_log(GPR_INFO, "PASS %" PRIuPTR ": DOING PICKS", num_passes); + LOG(INFO) << "PASS " << num_passes << ": DOING PICKS"; std::vector> subchannel_call_trackers; @@ -284,13 +284,13 @@ class WeightedRoundRobinTest : public LoadBalancingPolicyTest { EXPECT_TRUE(picks.has_value()) << location.file() << ":" << location.line(); if (!picks.has_value()) return false; - gpr_log(GPR_INFO, "PICKS: %s", absl::StrJoin(*picks, " ").c_str()); + LOG(INFO) << "PICKS: " << absl::StrJoin(*picks, " "); // Report backend metrics to the LB policy. ReportBackendMetrics(*picks, subchannel_call_trackers, backend_metrics); // Check the observed weights. auto actual = MakePickMap(*picks); - gpr_log(GPR_INFO, "Pick map:\nExpected: %s\n Actual: %s", - PickMapString(expected).c_str(), PickMapString(actual).c_str()); + LOG(INFO) << "Pick map:\nExpected: " << PickMapString(expected) + << "\n Actual: " << PickMapString(actual); if (expected != actual) { // Make sure each address is one of the expected addresses, // even if the weights aren't as expected. @@ -321,7 +321,7 @@ class WeightedRoundRobinTest : public LoadBalancingPolicyTest { << location.file() << ":" << location.line(); if (*picker == nullptr) return false; } else if (run_timer_callbacks) { - gpr_log(GPR_INFO, "running timer callback..."); + LOG(INFO) << "running timer callback..."; // Increment time and run any timer callbacks. IncrementTimeBy(Duration::Seconds(1)); } @@ -1113,8 +1113,8 @@ TEST_F(WeightedRoundRobinTest, MetricValues) { /*qps=*/100.0, /*eps=*/0.0)}}, {{kAddresses[0], 1}, {kAddresses[1], 3}, {kAddresses[2], 3}}); // Check endpoint weights. - EXPECT_THAT(stats_plugin->GetHistogramValue(kEndpointWeights, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(stats_plugin->GetDoubleHistogramValue( + kEndpointWeights, kLabelValues, kOptionalLabelValues), ::testing::Optional(::testing::ElementsAre( // Picker created for first endpoint becoming READY. 0, @@ -1135,29 +1135,30 @@ TEST_F(WeightedRoundRobinTest, MetricValues) { ::testing::DoubleNear(333.333344, 0.000001)))); // RR fallback should trigger for the first 5 updates above, because // there are less than two endpoints with valid weights. - EXPECT_THAT(stats_plugin->GetCounterValue(kRrFallback, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(stats_plugin->GetUInt64CounterValue(kRrFallback, kLabelValues, + kOptionalLabelValues), ::testing::Optional(5)); // Endpoint-not-yet-usable will be incremented once for every endpoint // with weight 0 above. - EXPECT_THAT(stats_plugin->GetCounterValue(kEndpointWeightNotYetUsable, - kLabelValues, kOptionalLabelValues), - ::testing::Optional(10)); + EXPECT_THAT( + stats_plugin->GetUInt64CounterValue(kEndpointWeightNotYetUsable, + kLabelValues, kOptionalLabelValues), + ::testing::Optional(10)); // There are no stale endpoint weights so far. - EXPECT_THAT(stats_plugin->GetCounterValue(kEndpointWeightStale, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(stats_plugin->GetUInt64CounterValue( + kEndpointWeightStale, kLabelValues, kOptionalLabelValues), ::testing::Optional(0)); // Advance time to make weights stale and trigger the timer callback // to recompute weights. - gpr_log(GPR_INFO, "advancing time to trigger staleness..."); + LOG(INFO) << "advancing time to trigger staleness..."; IncrementTimeBy(Duration::Seconds(2)); // Picker should now be falling back to round-robin. ExpectWeightedRoundRobinPicks( picker.get(), {}, {{kAddresses[0], 3}, {kAddresses[1], 3}, {kAddresses[2], 3}}); // All three endpoints should now have stale weights. - EXPECT_THAT(stats_plugin->GetCounterValue(kEndpointWeightStale, kLabelValues, - kOptionalLabelValues), + EXPECT_THAT(stats_plugin->GetUInt64CounterValue( + kEndpointWeightStale, kLabelValues, kOptionalLabelValues), ::testing::Optional(3)); } diff --git a/test/core/load_balancing/xds_override_host_test.cc b/test/core/load_balancing/xds_override_host_test.cc index 0e8f11cc46e..e75581f720e 100644 --- a/test/core/load_balancing/xds_override_host_test.cc +++ b/test/core/load_balancing/xds_override_host_test.cc @@ -23,6 +23,7 @@ #include #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_join.h" @@ -35,7 +36,6 @@ #include #include -#include #include "src/core/ext/filters/stateful_session/stateful_session_filter.h" #include "src/core/lib/channel/channel_args.h" @@ -295,21 +295,20 @@ TEST_F(XdsOverrideHostTest, auto* address1_attribute = MakeOverrideHostAttribute(kAddresses[1]); ExpectOverridePicks(picker.get(), address1_attribute, kAddresses[1]); // Subchannel for address 1 becomes disconnected. - gpr_log(GPR_INFO, "### subchannel 1 reporting IDLE"); + LOG(INFO) << "### subchannel 1 reporting IDLE"; auto subchannel = FindSubchannel(kAddresses[1]); ASSERT_NE(subchannel, nullptr); subchannel->SetConnectivityState(GRPC_CHANNEL_IDLE); EXPECT_TRUE(subchannel->ConnectionRequested()); - gpr_log(GPR_INFO, "### expecting re-resolution request"); + LOG(INFO) << "### expecting re-resolution request"; ExpectReresolutionRequest(); - gpr_log(GPR_INFO, - "### expecting RR picks to exclude the disconnected subchannel"); + LOG(INFO) << "### expecting RR picks to exclude the disconnected subchannel"; picker = WaitForRoundRobinListChange(kAddresses, {kAddresses[0], kAddresses[2]}); // Picks with the override will be queued. ExpectPickQueued(picker.get(), {address1_attribute}); // The subchannel starts trying to reconnect. - gpr_log(GPR_INFO, "### subchannel 1 reporting CONNECTING"); + LOG(INFO) << "### subchannel 1 reporting CONNECTING"; subchannel->SetConnectivityState(GRPC_CHANNEL_CONNECTING); picker = ExpectState(GRPC_CHANNEL_READY); ASSERT_NE(picker, nullptr); @@ -317,15 +316,15 @@ TEST_F(XdsOverrideHostTest, // Picks with the override will still be queued. ExpectPickQueued(picker.get(), {address1_attribute}); // The connection attempt fails. - gpr_log(GPR_INFO, "### subchannel 1 reporting TRANSIENT_FAILURE"); + LOG(INFO) << "### subchannel 1 reporting TRANSIENT_FAILURE"; subchannel->SetConnectivityState(GRPC_CHANNEL_TRANSIENT_FAILURE, absl::ResourceExhaustedError("Hmmmm")); - gpr_log(GPR_INFO, "### expecting re-resolution request"); + LOG(INFO) << "### expecting re-resolution request"; ExpectReresolutionRequest(); picker = ExpectState(GRPC_CHANNEL_READY); ExpectRoundRobinPicks(picker.get(), {kAddresses[0], kAddresses[2]}); // The host override is not used. - gpr_log(GPR_INFO, "### checking that host override is not used"); + LOG(INFO) << "### checking that host override is not used"; ExpectRoundRobinPicksWithAttribute(picker.get(), address1_attribute, {kAddresses[0], kAddresses[2]}); } @@ -376,7 +375,7 @@ TEST_F(XdsOverrideHostTest, DrainingSubchannelIsConnecting) { // The picker should use the DRAINING host when a call's override // points to that hose, but the host should not be used if there is no // override pointing to it. - gpr_log(GPR_INFO, "### sending update with DRAINING host"); + LOG(INFO) << "### sending update with DRAINING host"; ApplyUpdateWithHealthStatuses({{kAddresses[0], XdsHealthStatus::kUnknown}, {kAddresses[1], XdsHealthStatus::kDraining}, {kAddresses[2], XdsHealthStatus::kHealthy}}, @@ -391,7 +390,7 @@ TEST_F(XdsOverrideHostTest, DrainingSubchannelIsConnecting) { // Now the connection to the draining host gets dropped. // The picker should queue picks where the override host is IDLE. // All picks without an override host should not use this host. - gpr_log(GPR_INFO, "### closing connection to DRAINING host"); + LOG(INFO) << "### closing connection to DRAINING host"; subchannel->SetConnectivityState(GRPC_CHANNEL_IDLE); picker = ExpectState(GRPC_CHANNEL_READY); ExpectPickQueued(picker.get(), {address1_attribute}); @@ -401,7 +400,7 @@ TEST_F(XdsOverrideHostTest, DrainingSubchannelIsConnecting) { // The pick behavior is the same as above: The picker should queue // picks where the override host is CONNECTING. All picks without an // override host should not use this host. - gpr_log(GPR_INFO, "### subchannel starts reconnecting"); + LOG(INFO) << "### subchannel starts reconnecting"; WaitForWorkSerializerToFlush(); EXPECT_TRUE(subchannel->ConnectionRequested()); ExpectQueueEmpty(); @@ -412,7 +411,7 @@ TEST_F(XdsOverrideHostTest, DrainingSubchannelIsConnecting) { // The subchannel now becomes connected again. // Now picks with this override host can be completed again. // Picks without an override host still don't use the draining host. - gpr_log(GPR_INFO, "### subchannel becomes reconnected"); + LOG(INFO) << "### subchannel becomes reconnected"; subchannel->SetConnectivityState(GRPC_CHANNEL_READY); picker = ExpectState(GRPC_CHANNEL_READY); ExpectOverridePicks(picker.get(), address1_attribute, kAddresses[1]); @@ -644,7 +643,7 @@ TEST_F(XdsOverrideHostTest, IdleTimer) { }); const std::array kAddresses = { "ipv4:127.0.0.1:441", "ipv4:127.0.0.1:442", "ipv4:127.0.0.1:443"}; - gpr_log(GPR_INFO, "### sending initial update"); + LOG(INFO) << "### sending initial update"; EXPECT_EQ(UpdateXdsOverrideHostPolicy(kAddresses, {"UNKNOWN", "HEALTHY"}, Duration::Minutes(1)), absl::OkStatus()); @@ -663,7 +662,7 @@ TEST_F(XdsOverrideHostTest, IdleTimer) { ExpectOverridePicks(picker.get(), address2_attribute, kAddresses[2]); // Increment time by 5 seconds and send an update that moves endpoints 1 // and 2 to state DRAINING. - gpr_log(GPR_INFO, "### moving endpoints 1 and 2 to state DRAINING"); + LOG(INFO) << "### moving endpoints 1 and 2 to state DRAINING"; IncrementTimeBy(Duration::Seconds(5)); ApplyUpdateWithHealthStatuses({{kAddresses[0], XdsHealthStatus::kUnknown}, {kAddresses[1], XdsHealthStatus::kDraining}, diff --git a/test/core/memory_usage/BUILD b/test/core/memory_usage/BUILD index c7048dc172a..202c5a99b11 100644 --- a/test/core/memory_usage/BUILD +++ b/test/core/memory_usage/BUILD @@ -46,6 +46,7 @@ grpc_cc_binary( "absl/flags:flag", "absl/flags:parse", "absl/log:check", + "absl/log:log", ], tags = [ "bazel_only", @@ -69,6 +70,7 @@ grpc_cc_binary( "absl/flags:flag", "absl/flags:parse", "absl/log:check", + "absl/log:log", ], tags = [ "bazel_only", @@ -94,6 +96,7 @@ grpc_cc_binary( "absl/flags:flag", "absl/flags:parse", "absl/log:check", + "absl/log:log", "absl/time", ], tags = [ @@ -118,6 +121,7 @@ grpc_cc_binary( srcs = ["callback_server.cc"], external_deps = [ "absl/flags:flag", + "absl/log:log", "absl/flags:parse", "absl/log:check", ], @@ -159,6 +163,7 @@ grpc_cc_test( "absl/algorithm:container", "absl/flags:flag", "absl/flags:parse", + "absl/log:log", ], language = "C++", tags = MEMORY_USAGE_TAGS, diff --git a/test/core/memory_usage/callback_client.cc b/test/core/memory_usage/callback_client.cc index ad806559f86..9444d090c4a 100644 --- a/test/core/memory_usage/callback_client.cc +++ b/test/core/memory_usage/callback_client.cc @@ -28,11 +28,11 @@ #include "absl/flags/flag.h" #include "absl/flags/parse.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include -#include #include #include #include @@ -55,7 +55,7 @@ std::shared_ptr CreateChannelForTest(int index) { grpc::InsecureChannelCredentials(); if (absl::GetFlag(FLAGS_secure)) { // TODO (chennancy) Add in secure credentials - gpr_log(GPR_INFO, "Supposed to be secure, is not yet"); + LOG(INFO) << "Supposed to be secure, is not yet"; } // Channel args to prevent connection from closing after RPC is done @@ -91,7 +91,7 @@ std::shared_ptr UnaryCall(std::shared_ptr channel) { ¶ms->response, [params](const grpc::Status& status) { if (!status.ok()) { - gpr_log(GPR_ERROR, "UnaryCall RPC failed."); + LOG(ERROR) << "UnaryCall RPC failed."; } params->done.Notify(); }); @@ -111,11 +111,10 @@ std::shared_ptr GetBeforeSnapshot( [params, &before_server_memory](const grpc::Status& status) { if (status.ok()) { before_server_memory = params->snapshot_response.rss(); - gpr_log(GPR_INFO, "Server Before RPC: %ld", - params->snapshot_response.rss()); - gpr_log(GPR_INFO, "GetBeforeSnapshot succeeded."); + LOG(INFO) << "Server Before RPC: " << params->snapshot_response.rss(); + LOG(INFO) << "GetBeforeSnapshot succeeded."; } else { - gpr_log(GPR_ERROR, "GetBeforeSnapshot failed."); + LOG(ERROR) << "GetBeforeSnapshot failed."; } params->done.Notify(); }); @@ -129,11 +128,11 @@ int main(int argc, char** argv) { fake_argv[0] = argv[0]; grpc::testing::TestEnvironment env(&argc, argv); if (absl::GetFlag(FLAGS_target).empty()) { - gpr_log(GPR_ERROR, "Client: No target port entered"); + LOG(ERROR) << "Client: No target port entered"; return 1; } - gpr_log(GPR_INFO, "Client Target: %s", absl::GetFlag(FLAGS_target).c_str()); - gpr_log(GPR_INFO, "Client Size: %d", absl::GetFlag(FLAGS_size)); + LOG(INFO) << "Client Target: " << absl::GetFlag(FLAGS_target); + LOG(INFO) << "Client Size: " << absl::GetFlag(FLAGS_size); // Getting initial memory usage std::shared_ptr get_memory_channel = CreateChannelForTest(0); @@ -182,6 +181,6 @@ int main(int argc, char** argv) { static_cast(peak_server_memory - before_server_memory) / size * 1024); } - gpr_log(GPR_INFO, "Client Done"); + LOG(INFO) << "Client Done"; return 0; } diff --git a/test/core/memory_usage/callback_server.cc b/test/core/memory_usage/callback_server.cc index a00fc9e4125..7fddbba79a6 100644 --- a/test/core/memory_usage/callback_server.cc +++ b/test/core/memory_usage/callback_server.cc @@ -25,8 +25,8 @@ #include "absl/flags/flag.h" #include "absl/flags/parse.h" #include "absl/log/check.h" +#include "absl/log/log.h" -#include #include #include #include @@ -60,7 +60,7 @@ class ServerCallbackImpl final grpc::CallbackServerContext* context, const grpc::testing::SimpleRequest* /* request */, grpc::testing::MemorySize* response) override { - gpr_log(GPR_INFO, "BeforeSnapshot RPC CALL RECEIVED"); + LOG(INFO) << "BeforeSnapshot RPC CALL RECEIVED"; response->set_rss(before_server_create); auto* reactor = context->DefaultReactor(); reactor->Finish(grpc::Status::OK); @@ -85,10 +85,10 @@ int main(int argc, char** argv) { signal(SIGINT, sigint_handler); std::string server_address = absl::GetFlag(FLAGS_bind); if (server_address.empty()) { - gpr_log(GPR_ERROR, "Server: No port entered"); + LOG(ERROR) << "Server: No port entered"; return 1; } - gpr_log(GPR_INFO, "Server port: %s", server_address.c_str()); + LOG(INFO) << "Server port: " << server_address; // Get initial process memory usage before creating server long before_server_create = GetMemUsage(); @@ -103,7 +103,7 @@ int main(int argc, char** argv) { std::shared_ptr creds = grpc::InsecureServerCredentials(); if (absl::GetFlag(FLAGS_secure)) { - gpr_log(GPR_INFO, "Supposed to be secure, is not yet"); + LOG(INFO) << "Supposed to be secure, is not yet"; // TODO (chennancy) Add in secure credentials } builder->AddListeningPort(server_address, creds); @@ -111,7 +111,7 @@ int main(int argc, char** argv) { // Set up the server to start accepting requests. std::shared_ptr server(builder->BuildAndStart()); - gpr_log(GPR_INFO, "Server listening on %s", server_address.c_str()); + LOG(INFO) << "Server listening on " << server_address; // Keep the program running until the server shuts down. server->Wait(); diff --git a/test/core/memory_usage/client.cc b/test/core/memory_usage/client.cc index 150ba4a1bec..3ba5ac650da 100644 --- a/test/core/memory_usage/client.cc +++ b/test/core/memory_usage/client.cc @@ -43,8 +43,8 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/util/useful.h" #include "test/core/memory_usage/memstats.h" #include "test/core/test_util/test_config.h" diff --git a/test/core/memory_usage/memory_usage_test.cc b/test/core/memory_usage/memory_usage_test.cc index 2bc0f7d6128..9ca28321a72 100644 --- a/test/core/memory_usage/memory_usage_test.cc +++ b/test/core/memory_usage/memory_usage_test.cc @@ -32,6 +32,7 @@ #include "absl/algorithm/container.h" #include "absl/flags/flag.h" #include "absl/flags/parse.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" @@ -39,15 +40,14 @@ #include "google/protobuf/wrappers.pb.h" #include -#include #include #include #include #include #include "src/core/lib/config/config_vars.h" -#include "src/core/lib/gpr/subprocess.h" #include "src/core/lib/gprpp/env.h" +#include "src/core/util/subprocess.h" #include "src/proto/grpc/testing/xds/v3/cluster.pb.h" #include "src/proto/grpc/testing/xds/v3/health_check.pb.h" #include "test/core/test_util/port.h" @@ -102,7 +102,7 @@ int RunCallBenchmark(int port, char* root, int status; // start the server - gpr_log(GPR_INFO, "starting server"); + LOG(INFO) << "starting server"; std::vector server_flags = { absl::StrCat(root, "/memory_usage_server", gpr_subprocess_binary_extension()), @@ -113,14 +113,14 @@ int RunCallBenchmark(int port, char* root, // Add scenario-specific server flags to the end of the server_flags absl::c_move(server_scenario_flags, std::back_inserter(server_flags)); Subprocess svr(server_flags); - gpr_log(GPR_INFO, "server started, pid %d", svr.GetPID()); + LOG(INFO) << "server started, pid " << svr.GetPID(); // Wait one second before starting client to give the server a chance // to start up. gpr_sleep_until(grpc_timeout_seconds_to_deadline(1)); // start the client - gpr_log(GPR_INFO, "starting client"); + LOG(INFO) << "starting client"; std::vector client_flags = { absl::StrCat(root, "/memory_usage_client", gpr_subprocess_binary_extension()), @@ -135,7 +135,7 @@ int RunCallBenchmark(int port, char* root, // Add scenario-specific client flags to the end of the client_flags absl::c_move(client_scenario_flags, std::back_inserter(client_flags)); Subprocess cli(client_flags); - gpr_log(GPR_INFO, "client started, pid %d", cli.GetPID()); + LOG(INFO) << "client started, pid " << cli.GetPID(); // wait for completion if ((status = cli.Join()) != 0) { printf("client failed with: %d", status); @@ -154,14 +154,14 @@ int RunChannelBenchmark(const std::vector& server_ports, char* root) { std::vector servers; servers.reserve(server_ports.size()); for (int port : server_ports) { - gpr_log(GPR_INFO, "starting server on port %d", port); + LOG(INFO) << "starting server on port " << port; std::vector server_flags = { absl::StrCat(root, "/memory_usage_callback_server", gpr_subprocess_binary_extension()), "--bind", grpc_core::LocalIpAndPort(port)}; if (absl::GetFlag(FLAGS_use_xds)) server_flags.emplace_back("--use_xds"); servers.emplace_back(server_flags); - gpr_log(GPR_INFO, "server started, pid %d", servers.back().GetPID()); + LOG(INFO) << "server started, pid " << servers.back().GetPID(); } // Wait one second before starting client to avoid possible race condition @@ -169,7 +169,7 @@ int RunChannelBenchmark(const std::vector& server_ports, char* root) { gpr_sleep_until(grpc_timeout_seconds_to_deadline(1)); // start the client - gpr_log(GPR_INFO, "starting client"); + LOG(INFO) << "starting client"; std::vector client_flags = { absl::StrCat(root, "/memory_usage_callback_client", gpr_subprocess_binary_extension()), @@ -183,7 +183,7 @@ int RunChannelBenchmark(const std::vector& server_ports, char* root) { absl::StrCat("--server_pid=", servers[0].GetPID())); } Subprocess cli(client_flags); - gpr_log(GPR_INFO, "client started, pid %d", cli.GetPID()); + LOG(INFO) << "client started, pid " << cli.GetPID(); // wait for completion int retval = cli.Join(); if (retval != 0) { @@ -206,7 +206,7 @@ XdsServer StartXdsServerAndConfigureBootstrap( const std::vector& server_ports) { XdsServer xds_server; int xds_server_port = grpc_pick_unused_port_or_die(); - gpr_log(GPR_INFO, "xDS server port: %d", xds_server_port); + LOG(INFO) << "xDS server port: " << xds_server_port; // Generate xDS bootstrap and set the env var. std::string bootstrap = grpc::testing::XdsBootstrapBuilder() @@ -214,7 +214,7 @@ XdsServer StartXdsServerAndConfigureBootstrap( .SetXdsChannelCredentials("insecure") .Build(); grpc_core::SetEnv("GRPC_XDS_BOOTSTRAP_CONFIG", bootstrap); - gpr_log(GPR_INFO, "xDS bootstrap: %s", bootstrap.c_str()); + LOG(INFO) << "xDS bootstrap: " << bootstrap; // Create ADS service. xds_server.ads_service = std::make_shared(); xds_server.ads_service->Start(); @@ -241,28 +241,27 @@ XdsServer StartXdsServerAndConfigureBootstrap( {XdsResourceUtils::EdsResourceArgs::Locality( "here", std::move(endpoints))}))); // Create and start server. - gpr_log(GPR_INFO, "starting xDS server..."); + LOG(INFO) << "starting xDS server..."; grpc::ServerBuilder builder; builder.RegisterService(xds_server.ads_service.get()); builder.AddListeningPort(absl::StrCat("localhost:", xds_server_port), grpc::InsecureServerCredentials()); xds_server.server = builder.BuildAndStart(); - gpr_log(GPR_INFO, "xDS server started"); + LOG(INFO) << "xDS server started"; return xds_server; } int RunBenchmark(char* root, absl::string_view benchmark, std::vector server_scenario_flags, std::vector client_scenario_flags) { - gpr_log(GPR_INFO, "running benchmark: %s", std::string(benchmark).c_str()); + LOG(INFO) << "running benchmark: " << benchmark; const size_t num_ports = benchmark == "channel_multi_address" ? 10 : 1; std::vector server_ports; server_ports.reserve(num_ports); for (size_t i = 0; i < num_ports; ++i) { server_ports.push_back(grpc_pick_unused_port_or_die()); } - gpr_log(GPR_INFO, "server ports: %s", - absl::StrJoin(server_ports, ",").c_str()); + LOG(INFO) << "server ports: " << absl::StrJoin(server_ports, ","); XdsServer xds_server; if (absl::GetFlag(FLAGS_use_xds)) { xds_server = StartXdsServerAndConfigureBootstrap(server_ports); @@ -274,11 +273,11 @@ int RunBenchmark(char* root, absl::string_view benchmark, } else if (benchmark == "channel" || benchmark == "channel_multi_address") { retval = RunChannelBenchmark(server_ports, root); } else { - gpr_log(GPR_INFO, "Not a valid benchmark name"); + LOG(INFO) << "Not a valid benchmark name"; retval = 4; } if (xds_server.server != nullptr) xds_server.server->Shutdown(); - gpr_log(GPR_INFO, "done running benchmark"); + LOG(INFO) << "done running benchmark"; return retval; } diff --git a/test/core/memory_usage/server.cc b/test/core/memory_usage/server.cc index 60f6ed4cada..b071f62cf38 100644 --- a/test/core/memory_usage/server.cc +++ b/test/core/memory_usage/server.cc @@ -34,6 +34,7 @@ #include "absl/flags/flag.h" #include "absl/flags/parse.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include @@ -44,7 +45,6 @@ #include #include #include -#include #include #include "src/core/lib/channel/channel_args.h" @@ -93,7 +93,7 @@ static fling_call calls[1000006]; static void request_call_unary(int call_idx) { if (call_idx == static_cast(sizeof(calls) / sizeof(fling_call))) { - gpr_log(GPR_INFO, "Used all call slots (10000) on server. Server exit."); + LOG(INFO) << "Used all call slots (10000) on server. Server exit."; _exit(0); } grpc_metadata_array_init(&calls[call_idx].request_metadata_recv); @@ -138,7 +138,7 @@ static void send_snapshot(void* tag, MemStats* snapshot) { op++; op->op = GRPC_OP_SEND_MESSAGE; if (payload_buffer == nullptr) { - gpr_log(GPR_INFO, "NULL payload buffer !!!"); + LOG(INFO) << "NULL payload buffer !!!"; } op->data.send_message.send_message = payload_buffer; op++; @@ -164,8 +164,8 @@ static void OnServingStatusUpdate(void* /*user_data*/, const char* uri, grpc_serving_status_update update) { absl::Status status(static_cast(update.code), update.error_message); - gpr_log(GPR_INFO, "xDS serving status notification: uri=\"%s\", status=%s", - uri, status.ToString().c_str()); + LOG(INFO) << "xDS serving status notification: uri=\"" << uri + << "\", status=" << status; } int main(int argc, char** argv) { @@ -189,7 +189,7 @@ int main(int argc, char** argv) { if (addr.empty()) { addr = grpc_core::JoinHostPort("::", grpc_pick_unused_port_or_die()); } - gpr_log(GPR_INFO, "creating server on: %s", addr.c_str()); + LOG(INFO) << "creating server on: " << addr; cq = grpc_completion_queue_create_for_next(nullptr); @@ -253,7 +253,7 @@ int main(int argc, char** argv) { while (!shutdown_finished) { if (got_sigint && !shutdown_started) { - gpr_log(GPR_INFO, "Shutting down due to SIGINT"); + LOG(INFO) << "Shutting down due to SIGINT"; shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); grpc_server_shutdown_and_notify(server, shutdown_cq, tag(1000)); @@ -301,7 +301,7 @@ int main(int argc, char** argv) { current_snapshot = MemStats::Snapshot(); send_snapshot(s, ¤t_snapshot); } else { - gpr_log(GPR_ERROR, "Wrong call method"); + LOG(ERROR) << "Wrong call method"; } break; case FLING_SERVER_SEND_INIT_METADATA: diff --git a/test/core/network_benchmarks/BUILD b/test/core/network_benchmarks/BUILD index 299d3052f14..b53ea72c8c0 100644 --- a/test/core/network_benchmarks/BUILD +++ b/test/core/network_benchmarks/BUILD @@ -27,7 +27,10 @@ licenses(["notice"]) grpc_cc_binary( name = "low_level_ping_pong", srcs = ["low_level_ping_pong.cc"], - external_deps = ["absl/log:check"], + external_deps = [ + "absl/log:check", + "absl/log:log", + ], language = "C++", tags = ["no_windows"], deps = [ diff --git a/test/core/network_benchmarks/low_level_ping_pong.cc b/test/core/network_benchmarks/low_level_ping_pong.cc index df2c16d3a26..49bd712bb7a 100644 --- a/test/core/network_benchmarks/low_level_ping_pong.cc +++ b/test/core/network_benchmarks/low_level_ping_pong.cc @@ -36,16 +36,16 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include -#include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/strerror.h" #include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/socket_utils_posix.h" +#include "src/core/util/useful.h" #include "test/core/test_util/cmdline.h" #include "test/core/test_util/histogram.h" @@ -84,8 +84,7 @@ static int read_bytes(int fd, char* buf, size_t read_size, int spin) { if (errno == EAGAIN && spin == 1) { continue; } - gpr_log(GPR_ERROR, "Read failed: %s", - grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Read failed: " << grpc_core::StrError(errno); return -1; } } else { @@ -118,8 +117,7 @@ static int poll_read_bytes(int fd, char* buf, size_t read_size, int spin) { if (errno == EINTR) { continue; } else { - gpr_log(GPR_ERROR, "Poll failed: %s", - grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Poll failed: " << grpc_core::StrError(errno); return -1; } } @@ -130,7 +128,7 @@ static int poll_read_bytes(int fd, char* buf, size_t read_size, int spin) { err2 = read(fd, buf + bytes_read, read_size - bytes_read); } while (err2 < 0 && errno == EINTR); if (err2 < 0 && errno != EAGAIN) { - gpr_log(GPR_ERROR, "Read failed: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Read failed: " << grpc_core::StrError(errno); return -1; } bytes_read += static_cast(err2); @@ -159,8 +157,7 @@ static int epoll_read_bytes(struct thread_args* args, char* buf, int spin) { err = epoll_wait(args->epoll_fd, &ev, 1, spin ? 0 : -1); if (err < 0) { if (errno == EINTR) continue; - gpr_log(GPR_ERROR, "epoll_wait failed: %s", - grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "epoll_wait failed: " << grpc_core::StrError(errno); return -1; } if (err == 0 && spin) continue; @@ -206,8 +203,7 @@ static int blocking_write_bytes(struct thread_args* args, char* buf) { if (errno == EINTR) { continue; } else { - gpr_log(GPR_ERROR, "Read failed: %s", - grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Read failed: " << grpc_core::StrError(errno); return -1; } } else { @@ -245,7 +241,7 @@ static int epoll_setup(thread_args* args) { set_socket_nonblocking(args); epoll_fd = epoll_create(1); if (epoll_fd < 0) { - gpr_log(GPR_ERROR, "epoll_create: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "epoll_create: " << grpc_core::StrError(errno); return -1; } @@ -254,7 +250,7 @@ static int epoll_setup(thread_args* args) { ev.events = EPOLLIN | EPOLLET; ev.data.fd = args->fds.read_fd; if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, args->fds.read_fd, &ev) < 0) { - gpr_log(GPR_ERROR, "epoll_ctl: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "epoll_ctl: " << grpc_core::StrError(errno); } return 0; } @@ -263,16 +259,16 @@ static int epoll_setup(thread_args* args) { static void server_thread(thread_args* args) { char* buf = static_cast(gpr_malloc(args->msg_size)); if (args->setup(args) < 0) { - gpr_log(GPR_ERROR, "Setup failed"); + LOG(ERROR) << "Setup failed"; } for (;;) { if (args->read_bytes(args, buf) < 0) { - gpr_log(GPR_ERROR, "Server read failed"); + LOG(ERROR) << "Server read failed"; gpr_free(buf); return; } if (args->write_bytes(args, buf) < 0) { - gpr_log(GPR_ERROR, "Server write failed"); + LOG(ERROR) << "Server write failed"; gpr_free(buf); return; } @@ -287,11 +283,11 @@ static void server_thread_wrap(void* arg) { static void print_histogram(grpc_histogram* histogram) { // TODO(klempner): Print more detailed information, such as detailed histogram // buckets - gpr_log(GPR_INFO, "latency (50/95/99/99.9): %f/%f/%f/%f", - grpc_histogram_percentile(histogram, 50), - grpc_histogram_percentile(histogram, 95), - grpc_histogram_percentile(histogram, 99), - grpc_histogram_percentile(histogram, 99.9)); + LOG(INFO) << "latency (50/95/99/99.9): " + << grpc_histogram_percentile(histogram, 50) << "/" + << grpc_histogram_percentile(histogram, 95) << "/" + << grpc_histogram_percentile(histogram, 99) << "/" + << grpc_histogram_percentile(histogram, 99.9); } static double now(void) { @@ -310,16 +306,16 @@ static void client_thread(thread_args* args) { int i; if (args->setup(args) < 0) { - gpr_log(GPR_ERROR, "Setup failed"); + LOG(ERROR) << "Setup failed"; } for (i = 0; i < kNumIters; ++i) { start_time = now(); if (args->write_bytes(args, buf) < 0) { - gpr_log(GPR_ERROR, "Client write failed"); + LOG(ERROR) << "Client write failed"; goto error; } if (args->read_bytes(args, buf) < 0) { - gpr_log(GPR_ERROR, "Client read failed"); + LOG(ERROR) << "Client read failed"; goto error; } end_time = now(); @@ -338,8 +334,7 @@ error: static int create_listening_socket(struct sockaddr* port, socklen_t len) { int fd = socket(port->sa_family, SOCK_STREAM, 0); if (fd < 0) { - gpr_log(GPR_ERROR, "Unable to create socket: %s", - grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Unable to create socket: " << grpc_core::StrError(errno); goto error; } @@ -357,17 +352,17 @@ static int create_listening_socket(struct sockaddr* port, socklen_t len) { } if (bind(fd, port, len) < 0) { - gpr_log(GPR_ERROR, "bind: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "bind: " << grpc_core::StrError(errno); goto error; } if (listen(fd, 1) < 0) { - gpr_log(GPR_ERROR, "listen: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "listen: " << grpc_core::StrError(errno); goto error; } if (getsockname(fd, port, &len) < 0) { - gpr_log(GPR_ERROR, "getsockname: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "getsockname: " << grpc_core::StrError(errno); goto error; } @@ -384,8 +379,7 @@ static int connect_client(struct sockaddr* addr, socklen_t len) { int fd = socket(addr->sa_family, SOCK_STREAM, 0); int err; if (fd < 0) { - gpr_log(GPR_ERROR, "Unable to create socket: %s", - grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Unable to create socket: " << grpc_core::StrError(errno); goto error; } @@ -403,7 +397,7 @@ static int connect_client(struct sockaddr* addr, socklen_t len) { } while (err < 0 && errno == EINTR); if (err < 0) { - gpr_log(GPR_ERROR, "connect error: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "connect error: " << grpc_core::StrError(errno); goto error; } return fd; @@ -418,7 +412,7 @@ error: static int accept_server(int listen_fd) { int fd = accept(listen_fd, nullptr, nullptr); if (fd < 0) { - gpr_log(GPR_ERROR, "Accept failed: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "Accept failed: " << grpc_core::StrError(errno); return -1; } return fd; @@ -438,19 +432,19 @@ static int create_sockets_tcp(fd_pair* client_fds, fd_pair* server_fds) { listen_fd = create_listening_socket(sa_port, sizeof(port)); if (listen_fd == -1) { - gpr_log(GPR_ERROR, "Listen failed"); + LOG(ERROR) << "Listen failed"; goto error; } client_fd = connect_client(sa_port, sizeof(port)); if (client_fd == -1) { - gpr_log(GPR_ERROR, "Connect failed"); + LOG(ERROR) << "Connect failed"; goto error; } server_fd = accept_server(listen_fd); if (server_fd == -1) { - gpr_log(GPR_ERROR, "Accept failed"); + LOG(ERROR) << "Accept failed"; goto error; } @@ -477,7 +471,7 @@ error: static int create_sockets_socketpair(fd_pair* client_fds, fd_pair* server_fds) { int fds[2]; if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) { - gpr_log(GPR_ERROR, "socketpair: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "socketpair: " << grpc_core::StrError(errno); return -1; } @@ -492,12 +486,12 @@ static int create_sockets_pipe(fd_pair* client_fds, fd_pair* server_fds) { int cfds[2]; int sfds[2]; if (pipe(cfds) < 0) { - gpr_log(GPR_ERROR, "pipe: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "pipe: " << grpc_core::StrError(errno); return -1; } if (pipe(sfds) < 0) { - gpr_log(GPR_ERROR, "pipe: %s", grpc_core::StrError(errno).c_str()); + LOG(ERROR) << "pipe: " << grpc_core::StrError(errno); return -1; } @@ -592,8 +586,8 @@ static int run_benchmark(const char* socket_type, thread_args* client_args, return rv; } - gpr_log(GPR_INFO, "Starting test %s %s %zu", client_args->strategy_name, - socket_type, client_args->msg_size); + LOG(INFO) << "Starting test " << client_args->strategy_name << " " + << socket_type << " " << client_args->msg_size; grpc_core::Thread server("server_thread", server_thread_wrap, server_args); server.Start(); @@ -663,7 +657,7 @@ int main(int argc, char** argv) { } if (read_strategy == nullptr) { - gpr_log(GPR_INFO, "No strategy specified, running all benchmarks"); + LOG(INFO) << "No strategy specified, running all benchmarks"; return run_all_benchmarks(static_cast(msg_size)); } diff --git a/test/core/promise/BUILD b/test/core/promise/BUILD index 2226f16211b..2b2b2cb9943 100644 --- a/test/core/promise/BUILD +++ b/test/core/promise/BUILD @@ -599,7 +599,10 @@ grpc_cc_test( grpc_cc_test( name = "sleep_test", srcs = ["sleep_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "c++", tags = ["promise_test"], uses_event_engine = False, @@ -652,6 +655,7 @@ grpc_cc_test( srcs = ["party_test.cc"], external_deps = [ "absl/base:core_headers", + "absl/log:log", "gtest", ], language = "c++", diff --git a/test/core/promise/party_test.cc b/test/core/promise/party_test.cc index 077fdfa39d1..3afe59b755d 100644 --- a/test/core/promise/party_test.cc +++ b/test/core/promise/party_test.cc @@ -23,6 +23,7 @@ #include #include "absl/base/thread_annotations.h" +#include "absl/log/log.h" #include "gtest/gtest.h" #include @@ -114,8 +115,7 @@ TYPED_TEST(PartySyncTest, AddAndRemoveParticipant) { participants[slot].exchange(nullptr, std::memory_order_acquire); if (participant == done.get()) run_me = true; if (participant == nullptr) { - gpr_log(GPR_ERROR, - "Participant was null (spurious wakeup observed)"); + LOG(ERROR) << "Participant was null (spurious wakeup observed)"; return false; } participant->store(true, std::memory_order_release); @@ -165,8 +165,7 @@ TYPED_TEST(PartySyncTest, AddAndRemoveTwoParticipants) { participants[slot].exchange(nullptr, std::memory_order_acquire); if (participant == done.get()) run_me++; if (participant == nullptr) { - gpr_log(GPR_ERROR, - "Participant was null (spurious wakeup observed)"); + LOG(ERROR) << "Participant was null (spurious wakeup observed)"; return false; } participant->fetch_sub(1, std::memory_order_release); diff --git a/test/core/resolver/BUILD b/test/core/resolver/BUILD index c413ab82dfe..effbbac9dad 100644 --- a/test/core/resolver/BUILD +++ b/test/core/resolver/BUILD @@ -40,6 +40,7 @@ grpc_cc_test( name = "binder_resolver_test", srcs = ["binder_resolver_test.cc"], external_deps = [ + "absl/log:log", "gtest", ], language = "C++", @@ -54,7 +55,10 @@ grpc_cc_test( grpc_cc_test( name = "dns_resolver_test", srcs = ["dns_resolver_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", deps = [ "//:gpr", @@ -66,7 +70,10 @@ grpc_cc_test( grpc_cc_test( name = "dns_resolver_cooldown_test", srcs = ["dns_resolver_cooldown_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", deps = [ "//:gpr", @@ -80,7 +87,10 @@ grpc_cc_test( grpc_cc_test( name = "sockaddr_resolver_test", srcs = ["sockaddr_resolver_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", deps = [ "//:gpr", diff --git a/test/core/resource_quota/BUILD b/test/core/resource_quota/BUILD index 3055925e7dc..74f08344668 100644 --- a/test/core/resource_quota/BUILD +++ b/test/core/resource_quota/BUILD @@ -117,6 +117,7 @@ grpc_cc_test( srcs = ["memory_quota_stress_test.cc"], external_deps = [ "absl/base:core_headers", + "absl/log:log", "absl/strings", "absl/types:optional", "gtest", diff --git a/test/core/resource_quota/memory_quota_fuzzer.cc b/test/core/resource_quota/memory_quota_fuzzer.cc index c94aa28e385..912e3508065 100644 --- a/test/core/resource_quota/memory_quota_fuzzer.cc +++ b/test/core/resource_quota/memory_quota_fuzzer.cc @@ -31,12 +31,12 @@ #include "src/core/lib/debug/trace.h" #include "src/core/lib/experiments/config.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/resource_quota/memory_quota.h" +#include "src/core/util/useful.h" #include "src/libfuzzer/libfuzzer_macro.h" #include "test/core/resource_quota/call_checker.h" #include "test/core/resource_quota/memory_quota_fuzzer.pb.h" diff --git a/test/core/security/BUILD b/test/core/security/BUILD index 8fa90c55d40..4fec75a477c 100644 --- a/test/core/security/BUILD +++ b/test/core/security/BUILD @@ -60,6 +60,7 @@ grpc_cc_library( name = "oauth2_utils", srcs = ["oauth2_utils.cc"], hdrs = ["oauth2_utils.h"], + external_deps = ["absl/log:log"], language = "C++", visibility = ["//test/cpp:__subpackages__"], deps = ["//:grpc"], @@ -68,7 +69,10 @@ grpc_cc_library( grpc_cc_test( name = "auth_context_test", srcs = ["auth_context_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", uses_event_engine = False, uses_polling = False, @@ -99,6 +103,7 @@ grpc_cc_test( srcs = ["credentials_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], language = "C++", @@ -144,7 +149,10 @@ grpc_cc_test( grpc_cc_test( name = "json_token_test", srcs = ["json_token_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", tags = ["credential_token_tests"], uses_event_engine = False, @@ -177,7 +185,10 @@ grpc_cc_test( grpc_cc_test( name = "secure_endpoint_test", srcs = ["secure_endpoint_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], flaky = True, language = "C++", deps = [ @@ -193,7 +204,10 @@ grpc_cc_test( grpc_cc_test( name = "security_connector_test", srcs = ["security_connector_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", deps = [ "//:gpr", @@ -255,7 +269,10 @@ grpc_cc_binary( grpc_cc_binary( name = "fetch_oauth2", srcs = ["fetch_oauth2.cc"], - external_deps = ["absl/log:check"], + external_deps = [ + "absl/log:check", + "absl/log:log", + ], language = "C++", deps = [ ":oauth2_utils", @@ -322,7 +339,10 @@ grpc_cc_test( grpc_cc_test( name = "alts_security_connector_test", srcs = ["alts_security_connector_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", deps = [ "//:gpr", @@ -440,7 +460,10 @@ grpc_cc_test( grpc_cc_test( name = "grpc_tls_certificate_verifier_test", srcs = ["grpc_tls_certificate_verifier_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", deps = [ "//:gpr", diff --git a/test/core/security/auth_context_test.cc b/test/core/security/auth_context_test.cc index 32bf2304720..ea9be077e24 100644 --- a/test/core/security/auth_context_test.cc +++ b/test/core/security/auth_context_test.cc @@ -20,12 +20,12 @@ #include -#include +#include "absl/log/log.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/security/context/security_context.h" +#include "src/core/util/string.h" #include "test/core/test_util/test_config.h" TEST(AuthContextTest, EmptyContext) { @@ -33,7 +33,7 @@ TEST(AuthContextTest, EmptyContext) { grpc_core::MakeRefCounted(nullptr); grpc_auth_property_iterator it; - gpr_log(GPR_INFO, "test_empty_context"); + LOG(INFO) << "test_empty_context"; ASSERT_NE(ctx, nullptr); ASSERT_EQ(grpc_auth_context_peer_identity_property_name(ctx.get()), nullptr); it = grpc_auth_context_peer_identity(ctx.get()); @@ -54,7 +54,7 @@ TEST(AuthContextTest, SimpleContext) { grpc_auth_property_iterator it; size_t i; - gpr_log(GPR_INFO, "test_simple_context"); + LOG(INFO) << "test_simple_context"; ASSERT_NE(ctx, nullptr); grpc_auth_context_add_cstring_property(ctx.get(), "name", "chapi"); grpc_auth_context_add_cstring_property(ctx.get(), "name", "chapo"); @@ -94,7 +94,7 @@ TEST(AuthContextTest, ChainedContext) { grpc_auth_property_iterator it; size_t i; - gpr_log(GPR_INFO, "test_chained_context"); + LOG(INFO) << "test_chained_context"; grpc_auth_context_add_cstring_property(chained_ptr, "name", "padapo"); grpc_auth_context_add_cstring_property(chained_ptr, "foo", "baz"); grpc_auth_context_add_cstring_property(ctx.get(), "name", "chapi"); diff --git a/test/core/security/check_gcp_environment_linux_test.cc b/test/core/security/check_gcp_environment_linux_test.cc index 83f5fc91889..1627aa67b67 100644 --- a/test/core/security/check_gcp_environment_linux_test.cc +++ b/test/core/security/check_gcp_environment_linux_test.cc @@ -25,9 +25,9 @@ #include #include -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/security/credentials/alts/check_gcp_environment.h" +#include "src/core/util/tmpfile.h" #if GPR_LINUX diff --git a/test/core/security/check_gcp_environment_windows_test.cc b/test/core/security/check_gcp_environment_windows_test.cc index 6270bdd913b..d046565d8ab 100644 --- a/test/core/security/check_gcp_environment_windows_test.cc +++ b/test/core/security/check_gcp_environment_windows_test.cc @@ -25,9 +25,9 @@ #include #include -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/security/credentials/alts/check_gcp_environment.h" +#include "src/core/util/tmpfile.h" #ifdef GPR_WINDOWS diff --git a/test/core/security/credentials_test.cc b/test/core/security/credentials_test.cc index 81017be9aa8..d6eb7c74d0f 100644 --- a/test/core/security/credentials_test.cc +++ b/test/core/security/credentials_test.cc @@ -27,6 +27,7 @@ #include #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_format.h" @@ -42,8 +43,6 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/host_port.h" @@ -72,6 +71,8 @@ #include "src/core/lib/security/transport/auth_filters.h" #include "src/core/lib/transport/error_utils.h" #include "src/core/lib/uri/uri_parser.h" +#include "src/core/util/string.h" +#include "src/core/util/tmpfile.h" #include "test/core/test_util/test_config.h" namespace grpc_core { @@ -2011,7 +2012,7 @@ void auth_metadata_context_build(const char* url_scheme, char* service_url = nullptr; grpc_auth_metadata_context_reset(auth_md_context); if (last_slash == nullptr) { - gpr_log(GPR_ERROR, "No '/' found in fully qualified method name"); + LOG(ERROR) << "No '/' found in fully qualified method name"; service[0] = '\0'; method_name = gpr_strdup(""); } else if (last_slash == service) { diff --git a/test/core/security/fetch_oauth2.cc b/test/core/security/fetch_oauth2.cc index 355b368d2ca..8faad222de3 100644 --- a/test/core/security/fetch_oauth2.cc +++ b/test/core/security/fetch_oauth2.cc @@ -20,13 +20,13 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include #include #include #include -#include #include #include @@ -44,7 +44,7 @@ static grpc_call_credentials* create_sts_creds(const char* json_file_path) { if (strlen(json_file_path) == 0) { auto status = grpc::experimental::StsCredentialsOptionsFromEnv(&options); if (!status.ok()) { - gpr_log(GPR_ERROR, "%s", status.error_message().c_str()); + LOG(ERROR) << status.error_message(); return nullptr; } } else { @@ -53,7 +53,7 @@ static grpc_call_credentials* create_sts_creds(const char* json_file_path) { auto status = grpc::experimental::StsCredentialsOptionsFromJson(sts_options, &options); if (!status.ok()) { - gpr_log(GPR_ERROR, "%s", status.error_message().c_str()); + LOG(ERROR) << status.error_message(); return nullptr; } } @@ -97,46 +97,41 @@ int main(int argc, char** argv) { if (json_sts_options_file_path != nullptr && json_refresh_token_file_path != nullptr) { - gpr_log( - GPR_ERROR, - "--json_sts_options and --json_refresh_token are mutually exclusive."); + LOG(ERROR) << "--json_sts_options and --json_refresh_token are mutually " + "exclusive."; exit(1); } if (use_gce) { if (json_sts_options_file_path != nullptr || json_refresh_token_file_path != nullptr) { - gpr_log(GPR_INFO, - "Ignoring json refresh token or sts options to get a token from " - "the GCE metadata server."); + LOG(INFO) + << "Ignoring json refresh token or sts options to get a token from " + "the GCE metadata server."; } creds = grpc_google_compute_engine_credentials_create(nullptr); if (creds == nullptr) { - gpr_log(GPR_ERROR, "Could not create gce credentials."); + LOG(ERROR) << "Could not create gce credentials."; exit(1); } } else if (json_refresh_token_file_path != nullptr) { creds = create_refresh_token_creds(json_refresh_token_file_path); if (creds == nullptr) { - gpr_log(GPR_ERROR, - "Could not create refresh token creds. %s does probably not " - "contain a valid json refresh token.", - json_refresh_token_file_path); + LOG(ERROR) << "Could not create refresh token creds. " + << json_refresh_token_file_path + << " does probably not contain a valid json refresh token."; exit(1); } } else if (json_sts_options_file_path != nullptr) { creds = create_sts_creds(json_sts_options_file_path); if (creds == nullptr) { - gpr_log(GPR_ERROR, - "Could not create sts creds. %s does probably not contain a " - "valid json for sts options.", - json_sts_options_file_path); + LOG(ERROR) << "Could not create sts creds. " << json_sts_options_file_path + << " does probably not contain a valid json for sts options."; exit(1); } } else { - gpr_log( - GPR_ERROR, - "Missing --gce, --json_sts_options, or --json_refresh_token option."); + LOG(ERROR) + << "Missing --gce, --json_sts_options, or --json_refresh_token option."; exit(1); } CHECK_NE(creds, nullptr); diff --git a/test/core/security/grpc_tls_certificate_provider_test.cc b/test/core/security/grpc_tls_certificate_provider_test.cc index 696f329e692..ed0621fef74 100644 --- a/test/core/security/grpc_tls_certificate_provider_test.cc +++ b/test/core/security/grpc_tls_certificate_provider_test.cc @@ -28,9 +28,9 @@ #include #include -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/util/tmpfile.h" #include "test/core/test_util/test_config.h" #include "test/core/test_util/tls_utils.h" diff --git a/test/core/security/grpc_tls_certificate_verifier_test.cc b/test/core/security/grpc_tls_certificate_verifier_test.cc index 3a74c6453e1..e775fe7a847 100644 --- a/test/core/security/grpc_tls_certificate_verifier_test.cc +++ b/test/core/security/grpc_tls_certificate_verifier_test.cc @@ -22,14 +22,15 @@ #include #include +#include "absl/log/log.h" + #include -#include #include -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/security/security_connector/tls/tls_security_connector.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/util/tmpfile.h" #include "test/core/test_util/test_config.h" #include "test/core/test_util/tls_utils.h" @@ -107,7 +108,7 @@ TEST_F(GrpcTlsCertificateVerifierTest, AsyncExternalVerifierFails) { EXPECT_FALSE(core_external_verifier.Verify( &request_, [&callback_completed_event](absl::Status async_status) { - gpr_log(GPR_INFO, "Callback is invoked."); + LOG(INFO) << "Callback is invoked."; EXPECT_EQ(async_status.code(), absl::StatusCode::kUnauthenticated); EXPECT_EQ(async_status.ToString(), "UNAUTHENTICATED: AsyncExternalVerifier failed"); diff --git a/test/core/security/grpc_tls_credentials_options_test.cc b/test/core/security/grpc_tls_credentials_options_test.cc index 172def442ea..4dde2e18b97 100644 --- a/test/core/security/grpc_tls_credentials_options_test.cc +++ b/test/core/security/grpc_tls_credentials_options_test.cc @@ -28,10 +28,10 @@ #include #include "src/core/lib/config/config_vars.h" -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/security/credentials/tls/tls_credentials.h" #include "src/core/lib/security/security_connector/tls/tls_security_connector.h" +#include "src/core/util/tmpfile.h" #include "test/core/test_util/test_config.h" #include "test/core/test_util/tls_utils.h" diff --git a/test/core/security/print_google_default_creds_token.cc b/test/core/security/print_google_default_creds_token.cc index 44bdc9cfd66..b1636f0b5d5 100644 --- a/test/core/security/print_google_default_creds_token.cc +++ b/test/core/security/print_google_default_creds_token.cc @@ -29,11 +29,11 @@ #include #include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/security/credentials/composite/composite_credentials.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/slice/slice_string_helpers.h" +#include "src/core/util/string.h" #include "test/core/test_util/cmdline.h" typedef struct { diff --git a/test/core/security/secure_endpoint_test.cc b/test/core/security/secure_endpoint_test.cc index b05e6a63094..80168ebdfb1 100644 --- a/test/core/security/secure_endpoint_test.cc +++ b/test/core/security/secure_endpoint_test.cc @@ -23,16 +23,17 @@ #include +#include "absl/log/log.h" + #include #include -#include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/endpoint_pair.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/tsi/fake_transport_security.h" +#include "src/core/util/useful.h" #include "test/core/iomgr/endpoint_tests.h" #include "test/core/test_util/test_config.h" @@ -281,7 +282,7 @@ static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) { grpc_core::ExecCtx exec_ctx; int n = 0; grpc_closure done_closure; - gpr_log(GPR_INFO, "Start test left over"); + LOG(INFO) << "Start test left over"; grpc_slice_buffer_init(&incoming); GRPC_CLOSURE_INIT(&done_closure, inc_call_ctr, &n, grpc_schedule_on_exec_ctx); diff --git a/test/core/security/security_connector_test.cc b/test/core/security/security_connector_test.cc index 0ea79680154..63d14a065fc 100644 --- a/test/core/security/security_connector_test.cc +++ b/test/core/security/security_connector_test.cc @@ -23,15 +23,14 @@ #include +#include "absl/log/log.h" + #include #include #include -#include #include #include "src/core/lib/config/config_vars.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/security/context/security_context.h" @@ -39,6 +38,8 @@ #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/tsi/ssl_transport_security.h" #include "src/core/tsi/transport_security.h" +#include "src/core/util/string.h" +#include "src/core/util/tmpfile.h" #include "test/core/test_util/test_config.h" #ifndef TSI_OPENSSL_ALPN_SUPPORT @@ -83,17 +84,16 @@ static int check_property(const grpc_auth_context* ctx, grpc_auth_context_find_properties_by_name(ctx, expected_property_name); const grpc_auth_property* prop = grpc_auth_property_iterator_next(&it); if (prop == nullptr) { - gpr_log(GPR_ERROR, "Expected value %s not found.", expected_property_value); + LOG(ERROR) << "Expected value " << expected_property_value << " not found."; return 0; } if (strncmp(prop->value, expected_property_value, prop->value_length) != 0) { - gpr_log(GPR_ERROR, "Expected value %s and got %s for property %s.", - expected_property_value, prop->value, expected_property_name); + LOG(ERROR) << "Expected value " << expected_property_value << " and got " + << prop->value << " for property " << expected_property_name; return 0; } if (grpc_auth_property_iterator_next(&it) != nullptr) { - gpr_log(GPR_ERROR, "Expected only one property for %s.", - expected_property_name); + LOG(ERROR) << "Expected only one property for " << expected_property_name; return 0; } return 1; @@ -107,24 +107,23 @@ static int check_properties( for (const auto& property_value : expected_property_values) { const grpc_auth_property* prop = grpc_auth_property_iterator_next(&it); if (prop == nullptr) { - gpr_log(GPR_ERROR, "Expected value %s not found.", - property_value.c_str()); + LOG(ERROR) << "Expected value " << property_value << " not found."; return 0; } if (strcmp(prop->name, expected_property_name) != 0) { - gpr_log(GPR_ERROR, "Expected peer property name %s and got %s.", - expected_property_name, prop->name); + LOG(ERROR) << "Expected peer property name " << expected_property_name + << " and got " << prop->name; return 0; } if (strncmp(prop->value, property_value.c_str(), prop->value_length) != 0) { - gpr_log(GPR_ERROR, "Expected peer property value %s and got %s.", - property_value.c_str(), prop->value); + LOG(ERROR) << "Expected peer property value " << property_value + << " and got " << prop->value; return 0; } } if (grpc_auth_property_iterator_next(&it) != nullptr) { - gpr_log(GPR_ERROR, "Expected only %zu property values.", - expected_property_values.size()); + LOG(ERROR) << "Expected only " << expected_property_values.size() + << " property values."; return 0; } return 1; @@ -140,20 +139,20 @@ static int check_spiffe_id(const grpc_auth_context* ctx, return 1; } if (prop != nullptr && !expect_spiffe_id) { - gpr_log(GPR_ERROR, "SPIFFE ID not expected, but got %s.", prop->value); + LOG(ERROR) << "SPIFFE ID not expected, but got " << prop->value; return 0; } if (prop == nullptr && expect_spiffe_id) { - gpr_log(GPR_ERROR, "SPIFFE ID expected, but got nullptr."); + LOG(ERROR) << "SPIFFE ID expected, but got nullptr."; return 0; } if (strncmp(prop->value, expected_spiffe_id, prop->value_length) != 0) { - gpr_log(GPR_ERROR, "Expected SPIFFE ID %s but got %s.", expected_spiffe_id, - prop->value); + LOG(ERROR) << "Expected SPIFFE ID " << expected_spiffe_id << " but got " + << prop->value; return 0; } if (grpc_auth_property_iterator_next(&it) != nullptr) { - gpr_log(GPR_ERROR, "Expected only one property for SPIFFE ID."); + LOG(ERROR) << "Expected only one property for SPIFFE ID."; return 0; } return 1; diff --git a/test/core/security/system_roots_test.cc b/test/core/security/system_roots_test.cc index d9b388e7265..7dfaae7b92d 100644 --- a/test/core/security/system_roots_test.cc +++ b/test/core/security/system_roots_test.cc @@ -34,7 +34,6 @@ #include #include -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/load_file.h" @@ -46,6 +45,7 @@ #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/tsi/ssl_transport_security.h" #include "src/core/tsi/transport_security.h" +#include "src/core/util/tmpfile.h" #include "test/core/test_util/test_config.h" namespace grpc { diff --git a/test/core/slice/BUILD b/test/core/slice/BUILD index 45696771c56..1d4660ae56d 100644 --- a/test/core/slice/BUILD +++ b/test/core/slice/BUILD @@ -65,6 +65,7 @@ grpc_cc_test( name = "slice_test", srcs = ["slice_test.cc"], external_deps = [ + "absl/log:log", "gtest", ], language = "C++", @@ -81,7 +82,10 @@ grpc_cc_test( grpc_cc_test( name = "slice_string_helpers_test", srcs = ["slice_string_helpers_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", uses_event_engine = False, uses_polling = False, diff --git a/test/core/slice/percent_encoding_test.cc b/test/core/slice/percent_encoding_test.cc index b68adb6723c..891bfd9cd0d 100644 --- a/test/core/slice/percent_encoding_test.cc +++ b/test/core/slice/percent_encoding_test.cc @@ -28,8 +28,8 @@ #include #include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/slice/slice_string_helpers.h" +#include "src/core/util/string.h" #include "test/core/test_util/test_config.h" #define TEST_VECTOR(raw, encoded, dict) \ diff --git a/test/core/slice/slice_string_helpers_test.cc b/test/core/slice/slice_string_helpers_test.cc index 3b045bccede..587548099f0 100644 --- a/test/core/slice/slice_string_helpers_test.cc +++ b/test/core/slice/slice_string_helpers_test.cc @@ -25,7 +25,7 @@ #include #include -#include "src/core/lib/gpr/string.h" +#include "src/core/util/string.h" #define LOG_TEST_NAME(x) gpr_log(GPR_INFO, "%s", x) diff --git a/test/core/slice/slice_test.cc b/test/core/slice/slice_test.cc index f21781ee48d..44c139d8c07 100644 --- a/test/core/slice/slice_test.cc +++ b/test/core/slice/slice_test.cc @@ -28,6 +28,7 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/string_view.h" #include "gtest/gtest.h" @@ -182,7 +183,7 @@ TEST_P(GrpcSliceSizedTest, SliceSplitHeadWorks) { grpc_slice head, tail; size_t i; - gpr_log(GPR_INFO, "length=%" PRIuPTR, length); + LOG(INFO) << "length=" << length; // Create a slice in which each byte is equal to the distance from it to the // beginning of the slice. @@ -211,7 +212,7 @@ TEST_P(GrpcSliceSizedTest, SliceSplitTailWorks) { grpc_slice head, tail; size_t i; - gpr_log(GPR_INFO, "length=%" PRIuPTR, length); + LOG(INFO) << "length=" << length; // Create a slice in which each byte is equal to the distance from it to the // beginning of the slice. diff --git a/test/core/surface/BUILD b/test/core/surface/BUILD index e5025fcfca6..ea2fa27b24a 100644 --- a/test/core/surface/BUILD +++ b/test/core/surface/BUILD @@ -21,7 +21,10 @@ grpc_package(name = "test/core/surface") grpc_cc_test( name = "grpc_byte_buffer_reader_test", srcs = ["byte_buffer_reader_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", uses_event_engine = False, uses_polling = False, @@ -49,7 +52,10 @@ grpc_cc_test( grpc_cc_test( name = "grpc_completion_queue_test", srcs = ["completion_queue_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", deps = [ "//:gpr", @@ -61,7 +67,10 @@ grpc_cc_test( grpc_cc_test( name = "completion_queue_threading_test", srcs = ["completion_queue_threading_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", deps = [ "//:gpr", @@ -73,7 +82,10 @@ grpc_cc_test( grpc_cc_test( name = "concurrent_connectivity_test", srcs = ["concurrent_connectivity_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", deps = [ "//:gpr", @@ -120,7 +132,10 @@ grpc_cc_test( data = [ "//src/core/tsi/test_creds:ca.pem", ], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", deps = [ "//:gpr", @@ -150,7 +165,10 @@ grpc_cc_test( "//src/core/tsi/test_creds:server1.key", "//src/core/tsi/test_creds:server1.pem", ], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", deps = [ "//:gpr", @@ -178,7 +196,10 @@ grpc_cc_test( grpc_cc_test( name = "server_test", srcs = ["server_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", deps = [ "//:gpr", diff --git a/test/core/surface/channel_init_test.cc b/test/core/surface/channel_init_test.cc index 1b0baeafba0..a548b221eac 100644 --- a/test/core/surface/channel_init_test.cc +++ b/test/core/surface/channel_init_test.cc @@ -23,7 +23,10 @@ #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/channel_stack_builder_impl.h" +#include "src/core/lib/channel/promise_based_filter.h" +#include "src/core/lib/resource_quota/resource_quota.h" #include "src/core/lib/surface/channel_stack_type.h" +#include "src/core/lib/transport/call_arena_allocator.h" #include "test/core/test_util/test_config.h" namespace grpc_core { @@ -208,7 +211,7 @@ class TestFilter1 { explicit TestFilter1(int* p) : p_(p) {} static absl::StatusOr> Create( - const ChannelArgs& args, Empty) { + const ChannelArgs& args, ChannelFilter::Args) { EXPECT_EQ(args.GetInt("foo"), 1); return std::make_unique(args.GetPointer("p")); } @@ -226,6 +229,7 @@ class TestFilter1 { static const NoInterceptor OnServerInitialMetadata; static const NoInterceptor OnServerTrailingMetadata; static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnFinalize; }; @@ -242,6 +246,7 @@ const NoInterceptor TestFilter1::Call::OnClientInitialMetadata; const NoInterceptor TestFilter1::Call::OnServerInitialMetadata; const NoInterceptor TestFilter1::Call::OnServerTrailingMetadata; const NoInterceptor TestFilter1::Call::OnClientToServerMessage; +const NoInterceptor TestFilter1::Call::OnClientToServerHalfClose; const NoInterceptor TestFilter1::Call::OnServerToClientMessage; const NoInterceptor TestFilter1::Call::OnFinalize; @@ -250,19 +255,23 @@ TEST(ChannelInitTest, CanCreateFilterWithCall) { b.RegisterFilter(GRPC_CLIENT_CHANNEL); auto init = b.Build(); int p = 0; - auto segment = init.CreateStackSegment( - GRPC_CLIENT_CHANNEL, - ChannelArgs().Set("foo", 1).Set("p", ChannelArgs::UnownedPointer(&p))); - ASSERT_TRUE(segment.ok()) << segment.status(); - CallFilters::StackBuilder stack_builder; - segment->AddToCallFilterStack(stack_builder); - segment = absl::CancelledError(); // force the segment to be destroyed - auto stack = stack_builder.Build(); - { - CallFilters call_filters(Arena::MakePooled()); - call_filters.SetStack(std::move(stack)); - } + InterceptionChainBuilder chain_builder{ + ChannelArgs().Set("foo", 1).Set("p", ChannelArgs::UnownedPointer(&p))}; + init.AddToInterceptionChainBuilder(GRPC_CLIENT_CHANNEL, chain_builder); + int handled = 0; + auto stack = chain_builder.Build(MakeCallDestinationFromHandlerFunction( + [&handled](CallHandler) { ++handled; })); + ASSERT_TRUE(stack.ok()) << stack.status(); + RefCountedPtr allocator = + MakeRefCounted( + ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator( + "test"), + 1024); + auto call = MakeCallPair(Arena::MakePooled(), nullptr, + allocator->MakeArena(), allocator, nullptr); + (*stack)->StartCall(std::move(call.handler)); EXPECT_EQ(p, 1); + EXPECT_EQ(handled, 1); } } // namespace diff --git a/test/core/surface/completion_queue_test.cc b/test/core/surface/completion_queue_test.cc index 27a1d61c335..82dbaed6dd6 100644 --- a/test/core/surface/completion_queue_test.cc +++ b/test/core/surface/completion_queue_test.cc @@ -22,19 +22,19 @@ #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "gtest/gtest.h" #include -#include #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" -#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x) +#define LOG_TEST(x) LOG(INFO) << x static void* create_test_tag(void) { static intptr_t i = 0; @@ -65,7 +65,7 @@ static void shutdown_and_destroy(grpc_completion_queue* cc) { break; } default: { - gpr_log(GPR_ERROR, "Unknown completion type"); + LOG(ERROR) << "Unknown completion type"; break; } } diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index 4d75ca8da07..ad81f5194f9 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -21,23 +21,23 @@ #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "gtest/gtest.h" #include #include -#include #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/surface/completion_queue.h" +#include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" -#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x) +#define LOG_TEST(x) LOG(INFO) << x static void* create_test_tag(void) { static intptr_t i = 0; @@ -61,7 +61,7 @@ static void shutdown_and_destroy(grpc_completion_queue* cc) { break; } default: { - gpr_log(GPR_ERROR, "Unknown completion type"); + LOG(ERROR) << "Unknown completion type"; break; } } @@ -155,20 +155,20 @@ static void producer_thread(void* arg) { test_thread_options* opt = static_cast(arg); int i; - gpr_log(GPR_INFO, "producer %d started", opt->id); + LOG(INFO) << "producer " << opt->id << " started"; gpr_event_set(&opt->on_started, reinterpret_cast(1)); ASSERT_TRUE(gpr_event_wait(opt->phase1, ten_seconds_time())); - gpr_log(GPR_INFO, "producer %d phase 1", opt->id); + LOG(INFO) << "producer " << opt->id << " phase 1"; for (i = 0; i < TEST_THREAD_EVENTS; i++) { ASSERT_TRUE(grpc_cq_begin_op(opt->cc, (void*)(intptr_t)1)); } - gpr_log(GPR_INFO, "producer %d phase 1 done", opt->id); + LOG(INFO) << "producer " << opt->id << " phase 1 done"; gpr_event_set(&opt->on_phase1_done, reinterpret_cast(1)); ASSERT_TRUE(gpr_event_wait(opt->phase2, ten_seconds_time())); - gpr_log(GPR_INFO, "producer %d phase 2", opt->id); + LOG(INFO) << "producer " << opt->id << " phase 2"; for (i = 0; i < TEST_THREAD_EVENTS; i++) { grpc_core::ExecCtx exec_ctx; grpc_cq_end_op(opt->cc, reinterpret_cast(1), absl::OkStatus(), @@ -178,7 +178,7 @@ static void producer_thread(void* arg) { opt->events_triggered++; } - gpr_log(GPR_INFO, "producer %d phase 2 done", opt->id); + LOG(INFO) << "producer " << opt->id << " phase 2 done"; gpr_event_set(&opt->on_finished, reinterpret_cast(1)); } @@ -186,17 +186,17 @@ static void consumer_thread(void* arg) { test_thread_options* opt = static_cast(arg); grpc_event ev; - gpr_log(GPR_INFO, "consumer %d started", opt->id); + LOG(INFO) << "consumer " << opt->id << " started"; gpr_event_set(&opt->on_started, reinterpret_cast(1)); ASSERT_TRUE(gpr_event_wait(opt->phase1, ten_seconds_time())); - gpr_log(GPR_INFO, "consumer %d phase 1", opt->id); + LOG(INFO) << "consumer " << opt->id << " phase 1"; - gpr_log(GPR_INFO, "consumer %d phase 1 done", opt->id); + LOG(INFO) << "consumer " << opt->id << " phase 1 done"; gpr_event_set(&opt->on_phase1_done, reinterpret_cast(1)); ASSERT_TRUE(gpr_event_wait(opt->phase2, ten_seconds_time())); - gpr_log(GPR_INFO, "consumer %d phase 2", opt->id); + LOG(INFO) << "consumer " << opt->id << " phase 2"; for (;;) { ev = grpc_completion_queue_next( opt->cc, gpr_inf_future(GPR_CLOCK_MONOTONIC), nullptr); @@ -206,7 +206,7 @@ static void consumer_thread(void* arg) { opt->events_triggered++; break; case GRPC_QUEUE_SHUTDOWN: - gpr_log(GPR_INFO, "consumer %d phase 2 done", opt->id); + LOG(INFO) << "consumer " << opt->id << " phase 2 done"; gpr_event_set(&opt->on_finished, reinterpret_cast(1)); return; case GRPC_QUEUE_TIMEOUT: @@ -225,8 +225,8 @@ static void test_threading(size_t producers, size_t consumers) { size_t total_consumed = 0; static int optid = 101; - gpr_log(GPR_INFO, "%s: %" PRIuPTR " producers, %" PRIuPTR " consumers", - "test_threading", producers, consumers); + LOG(INFO) << "test_threading: " << producers << " producers, " << consumers + << " consumers"; // start all threads: they will wait for phase1 grpc_core::Thread* threads = static_cast( @@ -252,17 +252,17 @@ static void test_threading(size_t producers, size_t consumers) { // start phase1: producers will pre-declare all operations they will // complete - gpr_log(GPR_INFO, "start phase 1"); + LOG(INFO) << "start phase 1"; gpr_event_set(&phase1, reinterpret_cast(1)); - gpr_log(GPR_INFO, "wait phase 1"); + LOG(INFO) << "wait phase 1"; for (i = 0; i < producers + consumers; i++) { ASSERT_TRUE(gpr_event_wait(&options[i].on_phase1_done, ten_seconds_time())); } - gpr_log(GPR_INFO, "done phase 1"); + LOG(INFO) << "done phase 1"; // start phase2: operations will complete, and consumers will consume them - gpr_log(GPR_INFO, "start phase 2"); + LOG(INFO) << "start phase 2"; gpr_event_set(&phase2, reinterpret_cast(1)); // in parallel, we shutdown the completion channel - all events should still @@ -270,11 +270,11 @@ static void test_threading(size_t producers, size_t consumers) { grpc_completion_queue_shutdown(cc); // join all threads - gpr_log(GPR_INFO, "wait phase 2"); + LOG(INFO) << "wait phase 2"; for (i = 0; i < producers + consumers; i++) { ASSERT_TRUE(gpr_event_wait(&options[i].on_finished, ten_seconds_time())); } - gpr_log(GPR_INFO, "done phase 2"); + LOG(INFO) << "done phase 2"; // destroy the completion channel grpc_completion_queue_destroy(cc); diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index 090d0ba1f5a..33bc43d2752 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -23,6 +23,7 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "gtest/gtest.h" @@ -30,7 +31,6 @@ #include #include #include -#include #include #include @@ -192,7 +192,7 @@ TEST(ConcurrentConnectivityTest, RunConcurrentConnectivityTest) { // First round, no server { - gpr_log(GPR_DEBUG, "Wave 1"); + VLOG(2) << "Wave 1"; grpc_core::Thread threads[NUM_THREADS]; args.addr = "localhost:54321"; for (auto& th : threads) { @@ -207,7 +207,7 @@ TEST(ConcurrentConnectivityTest, RunConcurrentConnectivityTest) { // Second round, actual grpc server { - gpr_log(GPR_DEBUG, "Wave 2"); + VLOG(2) << "Wave 2"; int port = grpc_pick_unused_port_or_die(); args.addr = absl::StrCat("localhost:", port); args.server = grpc_server_create(nullptr, nullptr); @@ -239,7 +239,7 @@ TEST(ConcurrentConnectivityTest, RunConcurrentConnectivityTest) { // Third round, bogus tcp server { - gpr_log(GPR_DEBUG, "Wave 3"); + VLOG(2) << "Wave 3"; auto* pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(pollset, &args.mu); args.pollset.push_back(pollset); diff --git a/test/core/surface/server_test.cc b/test/core/surface/server_test.cc index d180078b9ef..49777234a63 100644 --- a/test/core/surface/server_test.cc +++ b/test/core/surface/server_test.cc @@ -34,11 +34,11 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/resolved_address.h" #include "src/core/lib/security/credentials/fake/fake_credentials.h" +#include "src/core/util/useful.h" #include "test/core/test_util/port.h" #include "test/core/test_util/test_config.h" diff --git a/test/core/test_util/BUILD b/test/core/test_util/BUILD index 2e795daf3ae..db6a89cf1b9 100644 --- a/test/core/test_util/BUILD +++ b/test/core/test_util/BUILD @@ -81,6 +81,7 @@ grpc_cc_library( ], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status:statusor", "absl/strings", "absl/strings:str_format", @@ -119,6 +120,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/debugging:failure_signal_handler", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -165,6 +167,7 @@ grpc_cc_library( external_deps = [ "absl/debugging:failure_signal_handler", "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -202,7 +205,10 @@ grpc_cc_library( grpc_cc_test( name = "cmdline_test", srcs = ["cmdline_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", uses_event_engine = False, uses_polling = False, @@ -221,6 +227,7 @@ grpc_cc_library( external_deps = [ "absl/flags:flag", "absl/log:check", + "absl/log:log", "gtest", ], linkstatic = True, @@ -238,7 +245,10 @@ grpc_cc_library( grpc_cc_test( name = "histogram_test", srcs = ["histogram_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", tags = ["nofixdeps"], uses_event_engine = False, @@ -280,6 +290,7 @@ grpc_cc_test( "stack_tracer_test.cc", ], external_deps = [ + "absl/log:log", "absl/strings", "gtest", ], @@ -302,6 +313,7 @@ grpc_cc_library( hdrs = ["test_lb_policies.h"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status", "absl/status:statusor", "absl/strings", @@ -341,6 +353,7 @@ grpc_cc_library( hdrs = ["fake_udp_and_tcp_server.h"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/status:statusor", "absl/strings", ], @@ -506,6 +519,7 @@ grpc_cc_library( "absl/container:flat_hash_map", "absl/functional:any_invocable", "absl/log:check", + "absl/log:log", "absl/status", "absl/strings", "absl/types:optional", diff --git a/test/core/test_util/cmdline.h b/test/core/test_util/cmdline.h index 4be2fa6dbad..d118d6a9412 100644 --- a/test/core/test_util/cmdline.h +++ b/test/core/test_util/cmdline.h @@ -21,6 +21,8 @@ #include +#include "absl/log/log.h" + #include /// Simple command line parser. @@ -43,7 +45,7 @@ /// gpr_cmdline_destroy(cl); /// if (verbose) { -/// gpr_log(GPR_INFO, "Goodbye cruel world!"); +/// LOG(INFO) << "Goodbye cruel world!"; /// } /// return 0; diff --git a/test/core/test_util/cmdline_test.cc b/test/core/test_util/cmdline_test.cc index 1170cffce43..049676da1c8 100644 --- a/test/core/test_util/cmdline_test.cc +++ b/test/core/test_util/cmdline_test.cc @@ -24,7 +24,7 @@ #include -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" #define LOG_TEST() gpr_log(GPR_INFO, "test at %s:%d", __FILE__, __LINE__) diff --git a/test/core/test_util/fake_stats_plugin.cc b/test/core/test_util/fake_stats_plugin.cc index 50b86a278cc..abc0a6a82ff 100644 --- a/test/core/test_util/fake_stats_plugin.cc +++ b/test/core/test_util/fake_stats_plugin.cc @@ -125,8 +125,8 @@ void GlobalInstrumentsRegistryTestPeer::ResetGlobalInstrumentsRegistry() { namespace { -template -absl::optional FindInstrument( +absl::optional +FindInstrument( const std::vector& instruments, absl::string_view name, GlobalInstrumentsRegistry::ValueType value_type, @@ -134,7 +134,7 @@ absl::optional FindInstrument( for (const auto& descriptor : instruments) { if (descriptor.name == name && descriptor.value_type == value_type && descriptor.instrument_type == instrument_type) { - HandleType handle; + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle; handle.index = descriptor.index; return handle; } @@ -144,57 +144,51 @@ absl::optional FindInstrument( } // namespace -absl::optional +absl::optional GlobalInstrumentsRegistryTestPeer::FindUInt64CounterHandleByName( absl::string_view name) { - return FindInstrument( - GlobalInstrumentsRegistry::GetInstrumentList(), name, - GlobalInstrumentsRegistry::ValueType::kUInt64, - GlobalInstrumentsRegistry::InstrumentType::kCounter); + return FindInstrument(GlobalInstrumentsRegistry::GetInstrumentList(), name, + GlobalInstrumentsRegistry::ValueType::kUInt64, + GlobalInstrumentsRegistry::InstrumentType::kCounter); } -absl::optional +absl::optional GlobalInstrumentsRegistryTestPeer::FindDoubleCounterHandleByName( absl::string_view name) { - return FindInstrument( - GlobalInstrumentsRegistry::GetInstrumentList(), name, - GlobalInstrumentsRegistry::ValueType::kDouble, - GlobalInstrumentsRegistry::InstrumentType::kCounter); + return FindInstrument(GlobalInstrumentsRegistry::GetInstrumentList(), name, + GlobalInstrumentsRegistry::ValueType::kDouble, + GlobalInstrumentsRegistry::InstrumentType::kCounter); } -absl::optional +absl::optional GlobalInstrumentsRegistryTestPeer::FindUInt64HistogramHandleByName( absl::string_view name) { - return FindInstrument( - GlobalInstrumentsRegistry::GetInstrumentList(), name, - GlobalInstrumentsRegistry::ValueType::kUInt64, - GlobalInstrumentsRegistry::InstrumentType::kHistogram); + return FindInstrument(GlobalInstrumentsRegistry::GetInstrumentList(), name, + GlobalInstrumentsRegistry::ValueType::kUInt64, + GlobalInstrumentsRegistry::InstrumentType::kHistogram); } -absl::optional +absl::optional GlobalInstrumentsRegistryTestPeer::FindDoubleHistogramHandleByName( absl::string_view name) { - return FindInstrument( - GlobalInstrumentsRegistry::GetInstrumentList(), name, - GlobalInstrumentsRegistry::ValueType::kDouble, - GlobalInstrumentsRegistry::InstrumentType::kHistogram); + return FindInstrument(GlobalInstrumentsRegistry::GetInstrumentList(), name, + GlobalInstrumentsRegistry::ValueType::kDouble, + GlobalInstrumentsRegistry::InstrumentType::kHistogram); } -absl::optional +absl::optional GlobalInstrumentsRegistryTestPeer::FindCallbackInt64GaugeHandleByName( absl::string_view name) { - return FindInstrument< - GlobalInstrumentsRegistry::GlobalCallbackInt64GaugeHandle>( + return FindInstrument( GlobalInstrumentsRegistry::GetInstrumentList(), name, GlobalInstrumentsRegistry::ValueType::kInt64, GlobalInstrumentsRegistry::InstrumentType::kCallbackGauge); } -absl::optional +absl::optional GlobalInstrumentsRegistryTestPeer::FindCallbackDoubleGaugeHandleByName( absl::string_view name) { - return FindInstrument< - GlobalInstrumentsRegistry::GlobalCallbackDoubleGaugeHandle>( + return FindInstrument( GlobalInstrumentsRegistry::GetInstrumentList(), name, GlobalInstrumentsRegistry::ValueType::kDouble, GlobalInstrumentsRegistry::InstrumentType::kCallbackGauge); diff --git a/test/core/test_util/fake_stats_plugin.h b/test/core/test_util/fake_stats_plugin.h index 29a793dc5c3..655dfe0002c 100644 --- a/test/core/test_util/fake_stats_plugin.h +++ b/test/core/test_util/fake_stats_plugin.h @@ -17,6 +17,7 @@ #include #include +#include #include #include "absl/container/flat_hash_map.h" @@ -270,8 +271,8 @@ class FakeStatsPlugin : public StatsPlugin { } void AddCounter( - GlobalInstrumentsRegistry::GlobalUInt64CounterHandle handle, - uint64_t value, absl::Span label_values, + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, uint64_t value, + absl::Span label_values, absl::Span optional_values) override { // The problem with this approach is that we initialize uint64_counters_ in // BuildAndRegister by querying the GlobalInstrumentsRegistry at the time. @@ -283,7 +284,8 @@ class FakeStatsPlugin : public StatsPlugin { // GlobalInstrumentsRegistry everytime a metric is recorded. But this is not // a concern for now. gpr_log(GPR_INFO, - "FakeStatsPlugin[%p]::AddCounter(index=%u, value=(uint64)%lu, " + "FakeStatsPlugin[%p]::AddCounter(index=%u, value=(uint64)%" PRIu64 + ", " "label_values={%s}, optional_label_values={%s}", this, handle.index, value, absl::StrJoin(label_values, ", ").c_str(), @@ -294,7 +296,7 @@ class FakeStatsPlugin : public StatsPlugin { iter->second.Add(value, label_values, optional_values); } void AddCounter( - GlobalInstrumentsRegistry::GlobalDoubleCounterHandle handle, double value, + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, double value, absl::Span label_values, absl::Span optional_values) override { gpr_log(GPR_INFO, @@ -309,23 +311,24 @@ class FakeStatsPlugin : public StatsPlugin { iter->second.Add(value, label_values, optional_values); } void RecordHistogram( - GlobalInstrumentsRegistry::GlobalUInt64HistogramHandle handle, - uint64_t value, absl::Span label_values, + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, uint64_t value, + absl::Span label_values, absl::Span optional_values) override { - gpr_log(GPR_INFO, - "FakeStatsPlugin[%p]::RecordHistogram(index=%u, value=(uint64)%lu, " - "label_values={%s}, optional_label_values={%s}", - this, handle.index, value, - absl::StrJoin(label_values, ", ").c_str(), - absl::StrJoin(optional_values, ", ").c_str()); + gpr_log( + GPR_INFO, + "FakeStatsPlugin[%p]::RecordHistogram(index=%u, value=(uint64)%" PRIu64 + ", " + "label_values={%s}, optional_label_values={%s}", + this, handle.index, value, absl::StrJoin(label_values, ", ").c_str(), + absl::StrJoin(optional_values, ", ").c_str()); MutexLock lock(&mu_); auto iter = uint64_histograms_.find(handle.index); if (iter == uint64_histograms_.end()) return; iter->second.Record(value, label_values, optional_values); } void RecordHistogram( - GlobalInstrumentsRegistry::GlobalDoubleHistogramHandle handle, - double value, absl::Span label_values, + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, double value, + absl::Span label_values, absl::Span optional_values) override { gpr_log(GPR_INFO, "FakeStatsPlugin[%p]::RecordHistogram(index=%u, value=(double)%f, " @@ -358,8 +361,8 @@ class FakeStatsPlugin : public StatsPlugin { return nullptr; } - absl::optional GetCounterValue( - GlobalInstrumentsRegistry::GlobalUInt64CounterHandle handle, + absl::optional GetUInt64CounterValue( + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, absl::Span label_values, absl::Span optional_values) { MutexLock lock(&mu_); @@ -369,8 +372,8 @@ class FakeStatsPlugin : public StatsPlugin { } return iter->second.GetValue(label_values, optional_values); } - absl::optional GetCounterValue( - GlobalInstrumentsRegistry::GlobalDoubleCounterHandle handle, + absl::optional GetDoubleCounterValue( + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, absl::Span label_values, absl::Span optional_values) { MutexLock lock(&mu_); @@ -380,8 +383,8 @@ class FakeStatsPlugin : public StatsPlugin { } return iter->second.GetValue(label_values, optional_values); } - absl::optional> GetHistogramValue( - GlobalInstrumentsRegistry::GlobalUInt64HistogramHandle handle, + absl::optional> GetUInt64HistogramValue( + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, absl::Span label_values, absl::Span optional_values) { MutexLock lock(&mu_); @@ -391,8 +394,8 @@ class FakeStatsPlugin : public StatsPlugin { } return iter->second.GetValues(label_values, optional_values); } - absl::optional> GetHistogramValue( - GlobalInstrumentsRegistry::GlobalDoubleHistogramHandle handle, + absl::optional> GetDoubleHistogramValue( + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, absl::Span label_values, absl::Span optional_values) { MutexLock lock(&mu_); @@ -410,8 +413,8 @@ class FakeStatsPlugin : public StatsPlugin { } gpr_log(GPR_INFO, "FakeStatsPlugin[%p]::TriggerCallbacks(): END", this); } - absl::optional GetCallbackGaugeValue( - GlobalInstrumentsRegistry::GlobalCallbackInt64GaugeHandle handle, + absl::optional GetInt64CallbackGaugeValue( + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, absl::Span label_values, absl::Span optional_values) { MutexLock lock(&callback_mu_); @@ -421,8 +424,8 @@ class FakeStatsPlugin : public StatsPlugin { } return iter->second.GetValue(label_values, optional_values); } - absl::optional GetCallbackGaugeValue( - GlobalInstrumentsRegistry::GlobalCallbackDoubleGaugeHandle handle, + absl::optional GetDoubleCallbackGaugeValue( + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, absl::Span label_values, absl::Span optional_values) { MutexLock lock(&callback_mu_); @@ -438,13 +441,14 @@ class FakeStatsPlugin : public StatsPlugin { public: explicit Reporter(FakeStatsPlugin& plugin) : plugin_(plugin) {} - void Report( - GlobalInstrumentsRegistry::GlobalCallbackInt64GaugeHandle handle, - int64_t value, absl::Span label_values, + void ReportInt64( + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, int64_t value, + absl::Span label_values, absl::Span optional_values) override { gpr_log(GPR_INFO, "FakeStatsPlugin[%p]::Reporter::Report(index=%u, " - "value=(uint64)%ld, label_values={%s}, " + "value=(int64_t)%" PRId64 + ", label_values={%s}, " "optional_label_values={%s}", this, handle.index, value, absl::StrJoin(label_values, ", ").c_str(), @@ -455,9 +459,9 @@ class FakeStatsPlugin : public StatsPlugin { iter->second.Set(value, label_values, optional_values); } - void Report( - GlobalInstrumentsRegistry::GlobalCallbackDoubleGaugeHandle handle, - double value, absl::Span label_values, + void ReportDouble( + GlobalInstrumentsRegistry::GlobalInstrumentHandle handle, double value, + absl::Span label_values, absl::Span optional_values) override { gpr_log(GPR_INFO, "FakeStatsPlugin[%p]::Reporter::Report(index=%u, " @@ -654,19 +658,17 @@ class GlobalInstrumentsRegistryTestPeer { public: static void ResetGlobalInstrumentsRegistry(); - static absl::optional + static absl::optional FindUInt64CounterHandleByName(absl::string_view name); - static absl::optional + static absl::optional FindDoubleCounterHandleByName(absl::string_view name); - static absl::optional + static absl::optional FindUInt64HistogramHandleByName(absl::string_view name); - static absl::optional + static absl::optional FindDoubleHistogramHandleByName(absl::string_view name); - static absl::optional< - GlobalInstrumentsRegistry::GlobalCallbackInt64GaugeHandle> + static absl::optional FindCallbackInt64GaugeHandleByName(absl::string_view name); - static absl::optional< - GlobalInstrumentsRegistry::GlobalCallbackDoubleGaugeHandle> + static absl::optional FindCallbackDoubleGaugeHandleByName(absl::string_view name); static GlobalInstrumentsRegistry::GlobalInstrumentDescriptor* diff --git a/test/core/test_util/histogram.cc b/test/core/test_util/histogram.cc index 8c8887d3e78..fae3d993347 100644 --- a/test/core/test_util/histogram.cc +++ b/test/core/test_util/histogram.cc @@ -27,7 +27,7 @@ #include #include -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" // Histograms are stored with exponentially increasing bucket sizes. // The first bucket is [0, m) where m = 1 + resolution diff --git a/test/core/test_util/reconnect_server.cc b/test/core/test_util/reconnect_server.cc index 036ee3d1e52..68031263f52 100644 --- a/test/core/test_util/reconnect_server.cc +++ b/test/core/test_util/reconnect_server.cc @@ -20,10 +20,10 @@ #include +#include "absl/log/log.h" #include "absl/strings/string_view.h" #include -#include #include #include "src/core/lib/iomgr/endpoint.h" @@ -37,14 +37,14 @@ static void pretty_print_backoffs(reconnect_server* server) { int i = 1; double expected_backoff = 1000.0, backoff; timestamp_list* head = server->head; - gpr_log(GPR_INFO, "reconnect server: new connection"); + LOG(INFO) << "reconnect server: new connection"; for (head = server->head; head && head->next; head = head->next, i++) { diff = gpr_time_sub(head->next->timestamp, head->timestamp); backoff = gpr_time_to_millis(diff); - gpr_log(GPR_INFO, - "retry %2d:backoff %6.2fs,expected backoff %6.2fs, jitter %4.2f%%", - i, backoff / 1000.0, expected_backoff / 1000.0, - (backoff - expected_backoff) * 100.0 / expected_backoff); + LOG(INFO) << absl::StrFormat( + "retry %2d:backoff %6.2fs,expected backoff %6.2fs, jitter %4.2f%%", i, + backoff / 1000.0, expected_backoff / 1000.0, + (backoff - expected_backoff) * 100.0 / expected_backoff); expected_backoff *= 1.6; int max_reconnect_backoff_ms = 120 * 1000; if (server->max_reconnect_backoff_ms > 0) { @@ -73,11 +73,10 @@ static void on_connect(void* arg, grpc_endpoint* tcp, server->peer = new std::string(peer); } else { if (last_colon == std::string::npos) { - gpr_log(GPR_ERROR, "peer does not contain a ':'"); + LOG(ERROR) << "peer does not contain a ':'"; } else if (peer.compare(0, static_cast(last_colon), *server->peer) != 0) { - gpr_log(GPR_ERROR, "mismatched peer! %s vs %s", server->peer->c_str(), - std::string(peer).c_str()); + LOG(ERROR) << "mismatched peer! " << *server->peer << " vs " << peer; } } new_tail = static_cast(gpr_malloc(sizeof(timestamp_list))); diff --git a/test/core/test_util/test_config.cc b/test/core/test_util/test_config.cc index 11c74d2a36c..b816f5f1b10 100644 --- a/test/core/test_util/test_config.cc +++ b/test/core/test_util/test_config.cc @@ -22,6 +22,7 @@ #include #include "absl/debugging/failure_signal_handler.h" +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/str_format.h" @@ -126,11 +127,11 @@ void grpc_test_init(int* argc, char** argv) { grpc_core::testing::InitializeStackTracer(argv[0]); absl::FailureSignalHandlerOptions options; absl::InstallFailureSignalHandler(options); - gpr_log(GPR_DEBUG, - "test slowdown factor: sanitizer=%" PRId64 ", fixture=%" PRId64 - ", poller=%" PRId64 ", total=%" PRId64, - grpc_test_sanitizer_slowdown_factor(), g_fixture_slowdown_factor, - g_poller_slowdown_factor, grpc_test_slowdown_factor()); + VLOG(2) << "test slowdown factor: sanitizer=" + << grpc_test_sanitizer_slowdown_factor() + << ", fixture=" << g_fixture_slowdown_factor + << ", poller=" << g_poller_slowdown_factor + << ", total=" << grpc_test_slowdown_factor(); // seed rng with pid, so we don't end up with the same random numbers as a // concurrently running test binary srand(seed()); @@ -160,7 +161,7 @@ TestEnvironment::~TestEnvironment() { // This will wait until gRPC shutdown has actually happened to make sure // no gRPC resources (such as thread) are active. (timeout = 10s) if (!grpc_wait_until_shutdown(10)) { - gpr_log(GPR_ERROR, "Timeout in waiting for gRPC shutdown"); + LOG(ERROR) << "Timeout in waiting for gRPC shutdown"; } if (BuiltUnderMsan()) { // This is a workaround for MSAN. MSAN doesn't like having shutdown thread @@ -171,7 +172,7 @@ TestEnvironment::~TestEnvironment() { gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(500, GPR_TIMESPAN))); } - gpr_log(GPR_INFO, "TestEnvironment ends"); + LOG(INFO) << "TestEnvironment ends"; } TestGrpcScope::TestGrpcScope() { grpc_init(); } @@ -179,7 +180,7 @@ TestGrpcScope::TestGrpcScope() { grpc_init(); } TestGrpcScope::~TestGrpcScope() { grpc_shutdown(); if (!grpc_wait_until_shutdown(10)) { - gpr_log(GPR_ERROR, "Timeout in waiting for gRPC shutdown"); + LOG(ERROR) << "Timeout in waiting for gRPC shutdown"; } } diff --git a/test/core/test_util/tls_utils.cc b/test/core/test_util/tls_utils.cc index 56d4a344381..376ce9615ec 100644 --- a/test/core/test_util/tls_utils.cc +++ b/test/core/test_util/tls_utils.cc @@ -26,10 +26,10 @@ #include #include -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/load_file.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/util/tmpfile.h" #include "test/core/test_util/test_config.h" namespace grpc_core { diff --git a/test/core/transport/BUILD b/test/core/transport/BUILD index 38710157b9e..f9bb417b1d0 100644 --- a/test/core/transport/BUILD +++ b/test/core/transport/BUILD @@ -39,6 +39,7 @@ grpc_cc_test( name = "interception_chain_test", srcs = ["interception_chain_test.cc"], external_deps = [ + "absl/log:log", "gtest", ], language = "C++", diff --git a/test/core/transport/binder/end2end/BUILD b/test/core/transport/binder/end2end/BUILD index 0785198d8c8..4e9ee2fe2d2 100644 --- a/test/core/transport/binder/end2end/BUILD +++ b/test/core/transport/binder/end2end/BUILD @@ -27,6 +27,7 @@ grpc_cc_library( srcs = ["fake_binder.cc"], hdrs = ["fake_binder.h"], external_deps = [ + "absl/log:log", "absl/memory", "absl/random", "absl/strings", diff --git a/test/core/transport/binder/end2end/fake_binder.cc b/test/core/transport/binder/end2end/fake_binder.cc index 5dc25e842c5..bc132e8fe07 100644 --- a/test/core/transport/binder/end2end/fake_binder.cc +++ b/test/core/transport/binder/end2end/fake_binder.cc @@ -17,7 +17,7 @@ #include #include -#include +#include "absl/log/log.h" #include "src/core/lib/gprpp/crash.h" @@ -173,10 +173,10 @@ void TransactionProcessor::SetDelay(absl::Duration delay) { void TransactionProcessor::Terminate() { if (!terminated_.load(std::memory_order_seq_cst)) { - gpr_log(GPR_INFO, "Terminating the processor"); + LOG(INFO) << "Terminating the processor"; terminated_.store(true, std::memory_order_seq_cst); tx_thread_.Join(); - gpr_log(GPR_INFO, "Processor terminated"); + LOG(INFO) << "Processor terminated"; } } diff --git a/test/core/transport/binder/end2end/fuzzers/BUILD b/test/core/transport/binder/end2end/fuzzers/BUILD index 91d4fd4ade8..a0184afd3cb 100644 --- a/test/core/transport/binder/end2end/fuzzers/BUILD +++ b/test/core/transport/binder/end2end/fuzzers/BUILD @@ -35,7 +35,10 @@ grpc_proto_library( grpc_cc_library( name = "fuzzer_utils", srcs = ["fuzzer_utils.cc"], - external_deps = ["absl/log:check"], + external_deps = [ + "absl/log:check", + "absl/log:log", + ], language = "c++", public_hdrs = ["fuzzer_utils.h"], deps = [ diff --git a/test/core/transport/binder/end2end/fuzzers/fuzzer_utils.cc b/test/core/transport/binder/end2end/fuzzers/fuzzer_utils.cc index 74d9f65665e..11609ac92f8 100644 --- a/test/core/transport/binder/end2end/fuzzers/fuzzer_utils.cc +++ b/test/core/transport/binder/end2end/fuzzers/fuzzer_utils.cc @@ -15,6 +15,7 @@ #include "test/core/transport/binder/end2end/fuzzers/fuzzer_utils.h" #include "absl/log/check.h" +#include "absl/log/log.h" namespace grpc_binder { namespace fuzzing { @@ -139,7 +140,7 @@ TransactionReceiverForFuzzing::TransactionReceiverForFuzzing( binder_transport_fuzzer::IncomingParcels incoming_parcels, grpc_core::RefCountedPtr wire_reader_ref, TransactionReceiver::OnTransactCb cb) { - gpr_log(GPR_INFO, "Construct TransactionReceiverForFuzzing"); + LOG(INFO) << "Construct TransactionReceiverForFuzzing"; CreateFuzzingThread(FuzzingLoop, std::move(incoming_parcels), std::move(wire_reader_ref), std::move(cb)); } diff --git a/test/core/transport/call_filters_test.cc b/test/core/transport/call_filters_test.cc index 8044aa85610..750f16b2ec1 100644 --- a/test/core/transport/call_filters_test.cc +++ b/test/core/transport/call_filters_test.cc @@ -1331,6 +1331,7 @@ TEST(CallFiltersTest, CanBuildStack) { void OnClientInitialMetadata(ClientMetadata&) {} void OnServerInitialMetadata(ServerMetadata&) {} void OnClientToServerMessage(Message&) {} + void OnClientToServerHalfClose() {} void OnServerToClientMessage(Message&) {} void OnServerTrailingMetadata(ServerMetadata&) {} void OnFinalize(const grpc_call_final_info*) {} @@ -1355,6 +1356,10 @@ TEST(CallFiltersTest, UnaryCall) { void OnClientToServerMessage(Message&, Filter* f) { f->steps.push_back(absl::StrCat(f->label, ":OnClientToServerMessage")); } + void OnClientToServerHalfClose(Filter* f) { + f->steps.push_back( + absl::StrCat(f->label, ":OnClientToServerHalfClose")); + } void OnServerToClientMessage(Message&, Filter* f) { f->steps.push_back(absl::StrCat(f->label, ":OnServerToClientMessage")); } diff --git a/test/core/transport/chaotic_good/BUILD b/test/core/transport/chaotic_good/BUILD index b1efe92a580..2b22ea94c4c 100644 --- a/test/core/transport/chaotic_good/BUILD +++ b/test/core/transport/chaotic_good/BUILD @@ -95,6 +95,7 @@ grpc_proto_fuzzer( corpus = "frame_fuzzer_corpus", external_deps = [ "absl/log:check", + "absl/log:log", "absl/random:bit_gen_ref", "absl/status:statusor", ], @@ -224,6 +225,7 @@ grpc_cc_test( srcs = ["chaotic_good_server_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", "absl/time", "gtest", diff --git a/test/core/transport/chaotic_good/chaotic_good_server_test.cc b/test/core/transport/chaotic_good/chaotic_good_server_test.cc index b5b058b43ee..40de0b35cbe 100644 --- a/test/core/transport/chaotic_good/chaotic_good_server_test.cc +++ b/test/core/transport/chaotic_good/chaotic_good_server_test.cc @@ -39,6 +39,7 @@ #include "src/core/lib/uri/uri_parser.h" #include "src/core/server/server.h" #include "test/core/event_engine/event_engine_test_utils.h" +#include "test/core/test_util/build.h" #include "test/core/test_util/port.h" #include "test/core/test_util/test_config.h" @@ -67,7 +68,10 @@ class ChaoticGoodServerTest : public ::testing::Test { auto ev = grpc_completion_queue_pluck( shutdown_cq, nullptr, grpc_timeout_milliseconds_to_deadline(15000), nullptr); - CHECK(ev.type == GRPC_OP_COMPLETE); + if (ev.type == GRPC_QUEUE_TIMEOUT) { + AsanAssertNoLeaks(); + } + CHECK_EQ(ev.type, GRPC_OP_COMPLETE); CHECK_EQ(ev.tag, nullptr); grpc_completion_queue_destroy(shutdown_cq); grpc_server_destroy(server_); diff --git a/test/core/transport/chaotic_good/server_transport_test.cc b/test/core/transport/chaotic_good/server_transport_test.cc index a5dd0008b9a..da80f94781f 100644 --- a/test/core/transport/chaotic_good/server_transport_test.cc +++ b/test/core/transport/chaotic_good/server_transport_test.cc @@ -82,19 +82,19 @@ ServerMetadataHandle TestTrailingMetadata() { return md; } -class MockAcceptor : public ServerTransport::Acceptor { +class MockCallDestination : public UnstartedCallDestination { public: - virtual ~MockAcceptor() = default; - MOCK_METHOD(Arena*, CreateArena, (), (override)); - MOCK_METHOD(absl::StatusOr, CreateCall, - (ClientMetadataHandle client_initial_metadata, Arena* arena), + ~MockCallDestination() override = default; + MOCK_METHOD(void, Orphaned, (), (override)); + MOCK_METHOD(void, StartCall, (UnstartedCallHandler unstarted_call_handler), (override)); }; TEST_F(TransportTest, ReadAndWriteOneMessage) { MockPromiseEndpoint control_endpoint; MockPromiseEndpoint data_endpoint; - StrictMock acceptor; + auto call_destination = MakeRefCounted>(); + EXPECT_CALL(*call_destination, Orphaned()).Times(1); auto transport = MakeOrphanable( CoreConfiguration::Get() .channel_args_preconditioning() @@ -112,19 +112,21 @@ TEST_F(TransportTest, ReadAndWriteOneMessage) { data_endpoint.ExpectRead( {EventEngineSlice::FromCopiedString("12345678"), Zeros(56)}, nullptr); // Once that's read we'll create a new call - auto* call_arena = MakeArena(); - EXPECT_CALL(acceptor, CreateArena).WillOnce(Return(call_arena)); StrictMock> on_done; - EXPECT_CALL(acceptor, CreateCall(_, call_arena)) - .WillOnce(WithArgs<0>([this, call_arena, &on_done]( - ClientMetadataHandle client_initial_metadata) { - EXPECT_EQ(client_initial_metadata->get_pointer(HttpPathMetadata()) + auto control_address = + grpc_event_engine::experimental::URIToResolvedAddress("ipv4:1.2.3.4:5678") + .value(); + EXPECT_CALL(*control_endpoint.endpoint, GetPeerAddress) + .WillRepeatedly([&control_address]() { return control_address; }); + EXPECT_CALL(*call_destination, StartCall(_)) + .WillOnce(WithArgs<0>([&on_done]( + UnstartedCallHandler unstarted_call_handler) { + EXPECT_EQ(unstarted_call_handler.UnprocessedClientInitialMetadata() + .get_pointer(HttpPathMetadata()) ->as_string_view(), "/demo.Service/Step"); - CallInitiatorAndHandler call = MakeCallPair( - std::move(client_initial_metadata), event_engine().get(), - call_arena, call_arena_allocator(), nullptr); - auto handler = call.handler.V2HackToStartCallWithoutACallFilterStack(); + auto handler = + unstarted_call_handler.V2HackToStartCallWithoutACallFilterStack(); handler.SpawnInfallible("test-io", [&on_done, handler]() mutable { return Seq( handler.PullClientInitialMetadata(), @@ -163,9 +165,8 @@ TEST_F(TransportTest, ReadAndWriteOneMessage) { return Empty{}; }); }); - return std::move(call.initiator); })); - transport->SetAcceptor(&acceptor); + transport->SetCallDestination(call_destination); EXPECT_CALL(on_done, Call()); EXPECT_CALL(*control_endpoint.endpoint, Read) .InSequence(control_endpoint.read_sequence) diff --git a/test/core/transport/chttp2/BUILD b/test/core/transport/chttp2/BUILD index d4be66252e8..54e1b521b77 100644 --- a/test/core/transport/chttp2/BUILD +++ b/test/core/transport/chttp2/BUILD @@ -141,7 +141,10 @@ grpc_cc_test( grpc_cc_test( name = "bin_decoder_test", srcs = ["bin_decoder_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", uses_event_engine = False, uses_polling = False, @@ -169,7 +172,10 @@ grpc_cc_test( grpc_cc_test( name = "bin_encoder_test", srcs = ["bin_encoder_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", uses_event_engine = False, uses_polling = False, @@ -292,7 +298,10 @@ grpc_cc_test( grpc_cc_test( name = "hpack_encoder_test", srcs = ["hpack_encoder_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", tags = ["hpack_test"], uses_event_engine = False, @@ -373,6 +382,7 @@ grpc_cc_test( srcs = ["settings_timeout_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], language = "C++", @@ -391,6 +401,7 @@ grpc_cc_test( srcs = ["too_many_pings_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], flaky = True, @@ -410,7 +421,10 @@ grpc_cc_test( grpc_cc_test( name = "varint_test", srcs = ["varint_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", uses_event_engine = False, uses_polling = False, @@ -434,6 +448,7 @@ grpc_cc_test( exec_properties = LARGE_MACHINE, external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], language = "C++", @@ -454,6 +469,7 @@ grpc_cc_test( srcs = ["stream_leak_with_queued_flow_control_update_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], language = "C++", diff --git a/test/core/transport/chttp2/bin_decoder_test.cc b/test/core/transport/chttp2/bin_decoder_test.cc index 7a0b6b479ff..71f758cf6aa 100644 --- a/test/core/transport/chttp2/bin_decoder_test.cc +++ b/test/core/transport/chttp2/bin_decoder_test.cc @@ -28,9 +28,9 @@ #include #include "src/core/ext/transport/chttp2/transport/bin_encoder.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/slice/slice_string_helpers.h" +#include "src/core/util/string.h" #include "test/core/test_util/test_config.h" static int all_ok = 1; diff --git a/test/core/transport/chttp2/bin_encoder_test.cc b/test/core/transport/chttp2/bin_encoder_test.cc index 20247b7c45d..47e59745f9f 100644 --- a/test/core/transport/chttp2/bin_encoder_test.cc +++ b/test/core/transport/chttp2/bin_encoder_test.cc @@ -28,8 +28,8 @@ #include #include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/slice/slice_string_helpers.h" +#include "src/core/util/string.h" #include "test/core/test_util/test_config.h" static int all_ok = 1; diff --git a/test/core/transport/chttp2/flow_control_fuzzer.cc b/test/core/transport/chttp2/flow_control_fuzzer.cc index 3e8ca29ecbe..de541fed56e 100644 --- a/test/core/transport/chttp2/flow_control_fuzzer.cc +++ b/test/core/transport/chttp2/flow_control_fuzzer.cc @@ -37,11 +37,11 @@ #include "src/core/ext/transport/chttp2/transport/flow_control.h" #include "src/core/lib/experiments/config.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/resource_quota/memory_quota.h" #include "src/core/lib/transport/bdp_estimator.h" +#include "src/core/util/useful.h" #include "src/libfuzzer/libfuzzer_macro.h" #include "test/core/test_util/fuzz_config_vars.h" #include "test/core/transport/chttp2/flow_control_fuzzer.pb.h" diff --git a/test/core/transport/chttp2/flow_control_test.cc b/test/core/transport/chttp2/flow_control_test.cc index 42cab0b8c2d..75652fcfb16 100644 --- a/test/core/transport/chttp2/flow_control_test.cc +++ b/test/core/transport/chttp2/flow_control_test.cc @@ -23,12 +23,12 @@ #include #include "src/core/lib/experiments/experiments.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/resource_quota/resource_quota.h" #include "src/core/lib/transport/bdp_estimator.h" +#include "src/core/util/useful.h" extern gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type); diff --git a/test/core/transport/chttp2/graceful_shutdown_test.cc b/test/core/transport/chttp2/graceful_shutdown_test.cc index 1f2d5642d55..b817a2fccf1 100644 --- a/test/core/transport/chttp2/graceful_shutdown_test.cc +++ b/test/core/transport/chttp2/graceful_shutdown_test.cc @@ -49,7 +49,6 @@ #include "src/core/ext/transport/chttp2/transport/frame_goaway.h" #include "src/core/ext/transport/chttp2/transport/frame_ping.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/notification.h" #include "src/core/lib/gprpp/sync.h" @@ -62,6 +61,7 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/completion_queue.h" #include "src/core/server/server.h" +#include "src/core/util/useful.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/test_util/test_config.h" diff --git a/test/core/transport/chttp2/hpack_encoder_test.cc b/test/core/transport/chttp2/hpack_encoder_test.cc index 2f3127a501d..28668b730da 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.cc +++ b/test/core/transport/chttp2/hpack_encoder_test.cc @@ -24,12 +24,12 @@ #include #include +#include "absl/log/log.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include #include -#include #include "src/core/ext/transport/chttp2/transport/legacy_frame.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -93,37 +93,37 @@ static void verify_frames(grpc_slice_buffer& output, bool header_is_eof) { // Verifications if (first_frame && type != GRPC_CHTTP2_FRAME_HEADER) { - gpr_log(GPR_ERROR, "expected first frame to be of type header"); - gpr_log(GPR_ERROR, "EXPECT: 0x%x", GRPC_CHTTP2_FRAME_HEADER); - gpr_log(GPR_ERROR, "GOT: 0x%x", type); + LOG(ERROR) << "expected first frame to be of type header"; + LOG(ERROR) << "EXPECT: " << GRPC_CHTTP2_FRAME_HEADER; + LOG(ERROR) << "GOT: " << type; EXPECT_TRUE(false); } else if (first_frame && header_is_eof && !(flags & GRPC_CHTTP2_DATA_FLAG_END_STREAM)) { - gpr_log(GPR_ERROR, "missing END_STREAM flag in HEADER frame"); + LOG(ERROR) << "missing END_STREAM flag in HEADER frame"; EXPECT_TRUE(false); } if (is_closed && (type == GRPC_CHTTP2_FRAME_DATA || type == GRPC_CHTTP2_FRAME_HEADER)) { - gpr_log(GPR_ERROR, - "stream is closed; new frame headers and data are not allowed"); + LOG(ERROR) + << "stream is closed; new frame headers and data are not allowed"; EXPECT_TRUE(false); } if (end_header && (type == GRPC_CHTTP2_FRAME_HEADER || type == GRPC_CHTTP2_FRAME_CONTINUATION)) { - gpr_log(GPR_ERROR, - "frame header is ended; new headers and continuations are not " - "allowed"); + LOG(ERROR) + << "frame header is ended; new headers and continuations are not " + "allowed"; EXPECT_TRUE(false); } if (in_header && (type == GRPC_CHTTP2_FRAME_DATA || type == GRPC_CHTTP2_FRAME_HEADER)) { - gpr_log(GPR_ERROR, - "parsing frame header; new headers and data are not allowed"); + LOG(ERROR) + << "parsing frame header; new headers and data are not allowed"; EXPECT_TRUE(false); } if (flags & ~(GRPC_CHTTP2_DATA_FLAG_END_STREAM | GRPC_CHTTP2_DATA_FLAG_END_HEADERS)) { - gpr_log(GPR_ERROR, "unexpected frame flags: 0x%x", flags); + LOG(ERROR) << "unexpected frame flags: " << flags; EXPECT_TRUE(false); } @@ -137,7 +137,7 @@ static void verify_frames(grpc_slice_buffer& output, bool header_is_eof) { if (flags & GRPC_CHTTP2_DATA_FLAG_END_STREAM) { is_closed = true; if (type == GRPC_CHTTP2_FRAME_CONTINUATION) { - gpr_log(GPR_ERROR, "unexpected END_STREAM flag in CONTINUATION frame"); + LOG(ERROR) << "unexpected END_STREAM flag in CONTINUATION frame"; EXPECT_TRUE(false); } } diff --git a/test/core/transport/chttp2/remove_stream_from_stalled_lists_test.cc b/test/core/transport/chttp2/remove_stream_from_stalled_lists_test.cc index 0471b7e4d08..56cf4721205 100644 --- a/test/core/transport/chttp2/remove_stream_from_stalled_lists_test.cc +++ b/test/core/transport/chttp2/remove_stream_from_stalled_lists_test.cc @@ -28,6 +28,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/types/optional.h" #include @@ -38,7 +39,6 @@ #include #include #include -#include #include #include @@ -228,11 +228,11 @@ class TestServer { grpc_completion_queue_destroy(call_cq); } } - gpr_log(GPR_INFO, "test server shutdown, joining RPC threads..."); + LOG(INFO) << "test server shutdown, joining RPC threads..."; for (auto& t : rpc_threads) { t.join(); } - gpr_log(GPR_INFO, "test server threads all finished!"); + LOG(INFO) << "test server threads all finished!"; } static void HandleOneRpc(grpc_call* call, grpc_completion_queue* call_cq) { @@ -337,15 +337,15 @@ TEST(Pollers, TestDontCrashWhenTryingToReproIssueFixedBy23984) { for (auto& thread : threads) { thread.join(); } - gpr_log(GPR_DEBUG, "All RPCs completed!"); + VLOG(2) << "All RPCs completed!"; int num_calls_seen_at_server = test_server->ShutdownAndGetNumCallsHandled(); if (num_calls_seen_at_server != kNumCalls) { - gpr_log(GPR_ERROR, - "Expected server to handle %d calls, but instead it only handled " - "%d. This suggests some or all RPCs didn't make it to the server, " - "which means " - "that this test likely isn't doing what it's meant to be doing.", - kNumCalls, num_calls_seen_at_server); + LOG(ERROR) << "Expected server to handle " << kNumCalls + << " calls, but instead it only handled " + << num_calls_seen_at_server + << ". This suggests some or all RPCs didn't make it to the " + "server, which means that this test likely isn't doing what " + "it's meant to be doing."; CHECK(0); } } diff --git a/test/core/transport/chttp2/settings_timeout_test.cc b/test/core/transport/chttp2/settings_timeout_test.cc index 0120a2e7bf6..e884f623fca 100644 --- a/test/core/transport/chttp2/settings_timeout_test.cc +++ b/test/core/transport/chttp2/settings_timeout_test.cc @@ -25,6 +25,7 @@ #include #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" @@ -38,7 +39,6 @@ #include #include #include -#include #include #include @@ -174,7 +174,7 @@ class Client { break; } if (state.error() != absl::OkStatus()) break; - gpr_log(GPR_INFO, "client read %" PRIuPTR " bytes", read_buffer.length); + LOG(INFO) << "client read " << read_buffer.length << " bytes"; grpc_slice_buffer_reset_and_unref(&read_buffer); } grpc_endpoint_shutdown(endpoint_, GRPC_ERROR_CREATE("shutdown")); @@ -210,7 +210,7 @@ class Client { private: static void OnEventDone(void* arg, grpc_error_handle error) { - gpr_log(GPR_INFO, "OnEventDone(): %s", StatusToString(error).c_str()); + LOG(INFO) << "OnEventDone(): " << StatusToString(error); EventState* state = static_cast(arg); state->error_ = error; gpr_atm_rel_store(&state->done_atm_, 1); @@ -255,21 +255,21 @@ TEST(SettingsTimeout, Basic) { const int server_port = grpc_pick_unused_port_or_die(); std::string server_address_string = absl::StrCat("localhost:", server_port); // Start server. - gpr_log(GPR_INFO, "starting server on %s", server_address_string.c_str()); + LOG(INFO) << "starting server on " << server_address_string; ServerThread server_thread(server_address_string.c_str()); server_thread.Start(); // Create client and connect to server. - gpr_log(GPR_INFO, "starting client connect"); + LOG(INFO) << "starting client connect"; Client client(server_address_string.c_str()); client.Connect(); // Client read. Should fail due to server dropping connection. - gpr_log(GPR_INFO, "starting client read"); + LOG(INFO) << "starting client read"; EXPECT_TRUE(client.ReadUntilError()); // Shut down client. - gpr_log(GPR_INFO, "shutting down client"); + LOG(INFO) << "shutting down client"; client.Shutdown(); // Shut down server. - gpr_log(GPR_INFO, "shutting down server"); + LOG(INFO) << "shutting down server"; server_thread.Shutdown(); // Clean up. } diff --git a/test/core/transport/chttp2/streams_not_seen_test.cc b/test/core/transport/chttp2/streams_not_seen_test.cc index 5883ab35f10..dd859111bb9 100644 --- a/test/core/transport/chttp2/streams_not_seen_test.cc +++ b/test/core/transport/chttp2/streams_not_seen_test.cc @@ -56,7 +56,6 @@ #include "src/core/lib/channel/channel_fwd.h" #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/config/core_configuration.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/notification.h" @@ -73,6 +72,7 @@ #include "src/core/lib/surface/channel_stack_type.h" #include "src/core/lib/transport/metadata_batch.h" #include "src/core/lib/transport/transport.h" +#include "src/core/util/useful.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/test_util/port.h" #include "test/core/test_util/test_config.h" diff --git a/test/core/transport/chttp2/too_many_pings_test.cc b/test/core/transport/chttp2/too_many_pings_test.cc index 8c5a13a4c92..0beb9e2d0a8 100644 --- a/test/core/transport/chttp2/too_many_pings_test.cc +++ b/test/core/transport/chttp2/too_many_pings_test.cc @@ -25,6 +25,7 @@ #include #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" @@ -46,7 +47,6 @@ #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/address_utils/parse_address.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" @@ -58,6 +58,7 @@ #include "src/core/resolver/endpoint_addresses.h" #include "src/core/resolver/fake/fake_resolver.h" #include "src/core/resolver/resolver.h" +#include "src/core/util/useful.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/test_util/port.h" #include "test/core/test_util/resolve_localhost_ip46.h" @@ -200,10 +201,10 @@ TEST(TooManyPings, TestLotsOfServerCancelledRpcsDoesntGiveTooManyPings) { std::map statuses_and_counts; const int kNumTotalRpcs = 100; // perform an RPC - gpr_log(GPR_INFO, - "Performing %d total RPCs and expecting them all to receive status " - "PERMISSION_DENIED (%d)", - kNumTotalRpcs, GRPC_STATUS_PERMISSION_DENIED); + LOG(INFO) << "Performing " << kNumTotalRpcs + << " total RPCs and expecting them all to receive status " + "PERMISSION_DENIED (" + << GRPC_STATUS_PERMISSION_DENIED << ")"; for (int i = 0; i < kNumTotalRpcs; i++) { grpc_status_code status = PerformCall(channel, server, cq); statuses_and_counts[status] += 1; @@ -214,14 +215,13 @@ TEST(TooManyPings, TestLotsOfServerCancelledRpcsDoesntGiveTooManyPings) { if (itr->first != GRPC_STATUS_PERMISSION_DENIED) { num_not_cancelled += itr->second; } - gpr_log(GPR_INFO, "%d / %d RPCs received status code: %d", itr->second, - kNumTotalRpcs, itr->first); + LOG(INFO) << itr->second << " / " << kNumTotalRpcs + << " RPCs received status code: " << itr->first; } if (num_not_cancelled > 0) { - gpr_log(GPR_ERROR, - "Expected all RPCs to receive status PERMISSION_DENIED (%d) but %d " - "received other status codes", - GRPC_STATUS_PERMISSION_DENIED, num_not_cancelled); + LOG(ERROR) << "Expected all RPCs to receive status PERMISSION_DENIED (" + << GRPC_STATUS_PERMISSION_DENIED << ") but " << num_not_cancelled + << " received other status codes"; FAIL(); } // shutdown and destroy the client and server @@ -405,20 +405,17 @@ TEST_F(KeepaliveThrottlingTest, KeepaliveThrottlingMultipleChannels) { // We need 3 GOAWAY frames to throttle the keepalive time from 1 second to 8 // seconds (> 5sec). for (int i = 0; i < 3; i++) { - gpr_log(GPR_INFO, "Expected keepalive time : %d", - expected_keepalive_time_sec); + LOG(INFO) << "Expected keepalive time : " << expected_keepalive_time_sec; EXPECT_EQ(PerformWaitingCall(channel, server, cq), GRPC_STATUS_UNAVAILABLE); expected_keepalive_time_sec *= 2; } - gpr_log( - GPR_INFO, - "Client keepalive time %d should now be in sync with the server settings", - expected_keepalive_time_sec); + LOG(INFO) << "Client keepalive time " << expected_keepalive_time_sec + << " should now be in sync with the server settings"; EXPECT_EQ(PerformWaitingCall(channel, server, cq), GRPC_STATUS_DEADLINE_EXCEEDED); // Since the subchannel is shared, the second channel should also have // keepalive settings in sync with the server. - gpr_log(GPR_INFO, "Now testing second channel sharing the same subchannel"); + LOG(INFO) << "Now testing second channel sharing the same subchannel"; EXPECT_EQ(PerformWaitingCall(channel_dup, server, cq), GRPC_STATUS_DEADLINE_EXCEEDED); // shutdown and destroy the client and server @@ -440,8 +437,7 @@ grpc_core::Resolver::Result BuildResolverResult( for (const auto& address_str : addresses) { absl::StatusOr uri = grpc_core::URI::Parse(address_str); if (!uri.ok()) { - gpr_log(GPR_ERROR, "Failed to parse uri. Error: %s", - uri.status().ToString().c_str()); + LOG(ERROR) << "Failed to parse uri. Error: " << uri.status(); CHECK_OK(uri); } grpc_resolved_address address; @@ -487,8 +483,7 @@ TEST_F(KeepaliveThrottlingTest, NewSubchannelsUseUpdatedKeepaliveTime) { // (even those from a different subchannel). int expected_keepalive_time_sec = 1; for (int i = 0; i < 3; i++) { - gpr_log(GPR_INFO, "Expected keepalive time : %d", - expected_keepalive_time_sec); + LOG(INFO) << "Expected keepalive time : " << expected_keepalive_time_sec; response_generator->SetResponseSynchronously( BuildResolverResult({absl::StrCat( "ipv4:", i % 2 == 0 ? server_address1 : server_address2)})); @@ -500,10 +495,8 @@ TEST_F(KeepaliveThrottlingTest, NewSubchannelsUseUpdatedKeepaliveTime) { GRPC_STATUS_UNAVAILABLE); expected_keepalive_time_sec *= 2; } - gpr_log( - GPR_INFO, - "Client keepalive time %d should now be in sync with the server settings", - expected_keepalive_time_sec); + LOG(INFO) << "Client keepalive time " << expected_keepalive_time_sec + << " should now be in sync with the server settings"; response_generator->SetResponseSynchronously( BuildResolverResult({absl::StrCat("ipv4:", server_address2)})); grpc_core::ExecCtx::Get()->Flush(); @@ -557,8 +550,7 @@ TEST_F(KeepaliveThrottlingTest, // (even those from a different subchannel). int expected_keepalive_time_sec = 1; for (int i = 0; i < 3; i++) { - gpr_log(GPR_ERROR, "Expected keepalive time : %d", - expected_keepalive_time_sec); + LOG(ERROR) << "Expected keepalive time : " << expected_keepalive_time_sec; grpc_server* server = ServerStart( i % 2 == 0 ? server_address1.c_str() : server_address2.c_str(), cq); VerifyChannelReady(channel, cq); @@ -567,10 +559,8 @@ TEST_F(KeepaliveThrottlingTest, VerifyChannelDisconnected(channel, cq); expected_keepalive_time_sec *= 2; } - gpr_log( - GPR_INFO, - "Client keepalive time %d should now be in sync with the server settings", - expected_keepalive_time_sec); + LOG(INFO) << "Client keepalive time " << expected_keepalive_time_sec + << " should now be in sync with the server settings"; grpc_server* server = ServerStart(server_address1.c_str(), cq); VerifyChannelReady(channel, cq); EXPECT_EQ(PerformWaitingCall(channel, server, cq), diff --git a/test/core/transport/interception_chain_test.cc b/test/core/transport/interception_chain_test.cc index f72fd59e019..ba0b42d7f99 100644 --- a/test/core/transport/interception_chain_test.cc +++ b/test/core/transport/interception_chain_test.cc @@ -16,11 +16,10 @@ #include +#include "absl/log/log.h" #include "gmock/gmock.h" #include "gtest/gtest.h" -#include - #include "src/core/lib/channel/promise_based_filter.h" #include "src/core/lib/resource_quota/resource_quota.h" #include "test/core/promise/poll_matcher.h" @@ -82,6 +81,7 @@ class TestFilter { } static const NoInterceptor OnServerInitialMetadata; static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnServerTrailingMetadata; static const NoInterceptor OnFinalize; @@ -102,6 +102,8 @@ const NoInterceptor TestFilter::Call::OnServerInitialMetadata; template const NoInterceptor TestFilter::Call::OnClientToServerMessage; template +const NoInterceptor TestFilter::Call::OnClientToServerHalfClose; +template const NoInterceptor TestFilter::Call::OnServerToClientMessage; template const NoInterceptor TestFilter::Call::OnServerTrailingMetadata; @@ -119,6 +121,7 @@ class FailsToInstantiateFilter { static const NoInterceptor OnClientInitialMetadata; static const NoInterceptor OnServerInitialMetadata; static const NoInterceptor OnClientToServerMessage; + static const NoInterceptor OnClientToServerHalfClose; static const NoInterceptor OnServerToClientMessage; static const NoInterceptor OnServerTrailingMetadata; static const NoInterceptor OnFinalize; @@ -138,6 +141,9 @@ const NoInterceptor FailsToInstantiateFilter::Call::OnServerInitialMetadata; template const NoInterceptor FailsToInstantiateFilter::Call::OnClientToServerMessage; template +const NoInterceptor + FailsToInstantiateFilter::Call::OnClientToServerHalfClose; +template const NoInterceptor FailsToInstantiateFilter::Call::OnServerToClientMessage; template const NoInterceptor FailsToInstantiateFilter::Call::OnServerTrailingMetadata; @@ -230,7 +236,7 @@ class InterceptionChainTest : public ::testing::Test { Poll trailing_md; call.initiator.SpawnInfallible( "run_call", [destination, &call, &trailing_md]() mutable { - gpr_log(GPR_INFO, "👊 start call"); + LOG(INFO) << "👊 start call"; destination->StartCall(std::move(call.handler)); return Map(call.initiator.PullServerTrailingMetadata(), [&trailing_md](ServerMetadataHandle md) { @@ -247,10 +253,9 @@ class InterceptionChainTest : public ::testing::Test { class Destination final : public UnstartedCallDestination { public: void StartCall(UnstartedCallHandler unstarted_call_handler) override { - gpr_log(GPR_INFO, "👊 started call: metadata=%s", - unstarted_call_handler.UnprocessedClientInitialMetadata() - .DebugString() - .c_str()); + LOG(INFO) << "👊 started call: metadata=" + << unstarted_call_handler.UnprocessedClientInitialMetadata() + .DebugString(); EXPECT_EQ(metadata_.get(), nullptr); metadata_ = Arena::MakePooled(); *metadata_ = diff --git a/test/core/transport/test_suite/BUILD b/test/core/transport/test_suite/BUILD index 64e704304a4..5f1703fda25 100644 --- a/test/core/transport/test_suite/BUILD +++ b/test/core/transport/test_suite/BUILD @@ -71,6 +71,7 @@ grpc_cc_library( hdrs = ["test.h"], external_deps = [ "absl/functional:any_invocable", + "absl/log:log", "absl/random", "absl/random:bit_gen_ref", "absl/strings", diff --git a/test/core/transport/test_suite/call_content.cc b/test/core/transport/test_suite/call_content.cc index 9e334f24fb6..cfcac0bf91b 100644 --- a/test/core/transport/test_suite/call_content.cc +++ b/test/core/transport/test_suite/call_content.cc @@ -62,7 +62,7 @@ void FillMetadata(const std::vector>& md, } // namespace TRANSPORT_TEST(UnaryWithSomeContent) { - SetServerAcceptor(); + SetServerCallDestination(); const auto client_initial_metadata = RandomMetadata(); const auto server_initial_metadata = RandomMetadata(); const auto server_trailing_metadata = RandomMetadata(); diff --git a/test/core/transport/test_suite/call_shapes.cc b/test/core/transport/test_suite/call_shapes.cc index fdae653119d..89ee26ccd2f 100644 --- a/test/core/transport/test_suite/call_shapes.cc +++ b/test/core/transport/test_suite/call_shapes.cc @@ -17,7 +17,7 @@ namespace grpc_core { TRANSPORT_TEST(MetadataOnlyRequest) { - SetServerAcceptor(); + SetServerCallDestination(); auto md = Arena::MakePooled(); md->Set(HttpPathMetadata(), Slice::FromExternalString("/foo/bar")); auto initiator = CreateCall(std::move(md)); @@ -72,7 +72,7 @@ TRANSPORT_TEST(MetadataOnlyRequestServerAbortsAfterInitialMetadata) { "wrong status code: we don't care for any cases we're " "rolling out soon, so leaving this disabled."; - SetServerAcceptor(); + SetServerCallDestination(); auto md = Arena::MakePooled(); md->Set(HttpPathMetadata(), Slice::FromExternalString("/foo/bar")); auto initiator = CreateCall(std::move(md)); @@ -125,7 +125,7 @@ TRANSPORT_TEST(MetadataOnlyRequestServerAbortsImmediately) { "wrong status code: we don't care for any cases we're " "rolling out soon, so leaving this disabled."; - SetServerAcceptor(); + SetServerCallDestination(); auto md = Arena::MakePooled(); md->Set(HttpPathMetadata(), Slice::FromExternalString("/foo/bar")); auto initiator = CreateCall(std::move(md)); @@ -165,7 +165,7 @@ TRANSPORT_TEST(MetadataOnlyRequestServerAbortsImmediately) { } TRANSPORT_TEST(CanCreateCallThenAbandonIt) { - SetServerAcceptor(); + SetServerCallDestination(); auto md = Arena::MakePooled(); md->Set(HttpPathMetadata(), Slice::FromExternalString("/foo/bar")); auto initiator = CreateCall(std::move(md)); @@ -178,7 +178,7 @@ TRANSPORT_TEST(CanCreateCallThenAbandonIt) { } TRANSPORT_TEST(UnaryRequest) { - SetServerAcceptor(); + SetServerCallDestination(); auto md = Arena::MakePooled(); md->Set(HttpPathMetadata(), Slice::FromExternalString("/foo/bar")); auto initiator = CreateCall(std::move(md)); @@ -257,7 +257,7 @@ TRANSPORT_TEST(UnaryRequest) { } TRANSPORT_TEST(UnaryRequestOmitCheckEndOfStream) { - SetServerAcceptor(); + SetServerCallDestination(); auto md = Arena::MakePooled(); md->Set(HttpPathMetadata(), Slice::FromExternalString("/foo/bar")); auto initiator = CreateCall(std::move(md)); @@ -326,7 +326,7 @@ TRANSPORT_TEST(UnaryRequestOmitCheckEndOfStream) { } TRANSPORT_TEST(UnaryRequestWaitForServerInitialMetadataBeforeSendingPayload) { - SetServerAcceptor(); + SetServerCallDestination(); auto md = Arena::MakePooled(); md->Set(HttpPathMetadata(), Slice::FromExternalString("/foo/bar")); auto initiator = CreateCall(std::move(md)); @@ -404,7 +404,7 @@ TRANSPORT_TEST(UnaryRequestWaitForServerInitialMetadataBeforeSendingPayload) { } TRANSPORT_TEST(ClientStreamingRequest) { - SetServerAcceptor(); + SetServerCallDestination(); auto md = Arena::MakePooled(); md->Set(HttpPathMetadata(), Slice::FromExternalString("/foo/bar")); auto initiator = CreateCall(std::move(md)); @@ -518,7 +518,7 @@ TRANSPORT_TEST(ClientStreamingRequest) { } TRANSPORT_TEST(ServerStreamingRequest) { - SetServerAcceptor(); + SetServerCallDestination(); auto md = Arena::MakePooled(); md->Set(HttpPathMetadata(), Slice::FromExternalString("/foo/bar")); auto initiator = CreateCall(std::move(md)); diff --git a/test/core/transport/test_suite/inproc_fixture.cc b/test/core/transport/test_suite/inproc_fixture.cc index 357bbef66be..65468229341 100644 --- a/test/core/transport/test_suite/inproc_fixture.cc +++ b/test/core/transport/test_suite/inproc_fixture.cc @@ -13,12 +13,16 @@ // limitations under the License. #include "src/core/ext/transport/inproc/inproc_transport.h" +#include "src/core/lib/config/core_configuration.h" #include "test/core/transport/test_suite/fixture.h" namespace grpc_core { TRANSPORT_FIXTURE(Inproc) { - auto transports = MakeInProcessTransportPair(); + auto transports = + MakeInProcessTransportPair(CoreConfiguration::Get() + .channel_args_preconditioning() + .PreconditionChannelArgs(nullptr)); return {std::move(transports.first), std::move(transports.second)}; } diff --git a/test/core/transport/test_suite/no_op.cc b/test/core/transport/test_suite/no_op.cc index 0efd226257d..26e21e44e32 100644 --- a/test/core/transport/test_suite/no_op.cc +++ b/test/core/transport/test_suite/no_op.cc @@ -20,8 +20,8 @@ TRANSPORT_TEST(NoOp) {} TRANSPORT_TEST(WaitForAllPendingWork) { WaitForAllPendingWork(); } -TRANSPORT_TEST(SetServerAcceptorAndFinish) { - SetServerAcceptor(); +TRANSPORT_TEST(SetServerCallDestinationAndFinish) { + SetServerCallDestination(); WaitForAllPendingWork(); } diff --git a/test/core/transport/test_suite/stress.cc b/test/core/transport/test_suite/stress.cc index ca20fb7ff3f..e791bb18b8f 100644 --- a/test/core/transport/test_suite/stress.cc +++ b/test/core/transport/test_suite/stress.cc @@ -19,7 +19,7 @@ namespace grpc_core { TRANSPORT_TEST(ManyUnaryRequests) { - SetServerAcceptor(); + SetServerCallDestination(); const int kNumRequests = absl::LogUniform(rng(), 10, 100); std::list call_names; auto make_call_name = [&call_names](int i, diff --git a/test/core/transport/test_suite/test.cc b/test/core/transport/test_suite/test.cc index e170c9acda6..c228196983e 100644 --- a/test/core/transport/test_suite/test.cc +++ b/test/core/transport/test_suite/test.cc @@ -52,8 +52,9 @@ void TransportTest::RunTest() { event_engine_->UnsetGlobalHooks(); } -void TransportTest::SetServerAcceptor() { - transport_pair_.server->server_transport()->SetAcceptor(&acceptor_); +void TransportTest::SetServerCallDestination() { + transport_pair_.server->server_transport()->SetCallDestination( + server_call_destination_); } CallInitiator TransportTest::CreateCall( @@ -71,8 +72,10 @@ CallInitiator TransportTest::CreateCall( CallHandler TransportTest::TickUntilServerCall() { WatchDog watchdog(this); for (;;) { - auto handler = acceptor_.PopHandler(); - if (handler.has_value()) return std::move(*handler); + auto handler = server_call_destination_->PopHandler(); + if (handler.has_value()) { + return std::move(*handler); + } event_engine_->Tick(); } } @@ -227,22 +230,14 @@ std::string TransportTest::RandomMessage() { } /////////////////////////////////////////////////////////////////////////////// -// TransportTest::Acceptor - -Arena* TransportTest::Acceptor::CreateArena() { - return test_->call_arena_allocator_->MakeArena(); -} +// TransportTest::ServerCallDestination -absl::StatusOr TransportTest::Acceptor::CreateCall( - ClientMetadataHandle client_initial_metadata, Arena* arena) { - auto call = MakeCallPair(std::move(client_initial_metadata), - test_->event_engine_.get(), arena, - test_->call_arena_allocator_, nullptr); - handlers_.push(call.handler.V2HackToStartCallWithoutACallFilterStack()); - return std::move(call.initiator); +void TransportTest::ServerCallDestination::StartCall( + UnstartedCallHandler handler) { + handlers_.push(handler.V2HackToStartCallWithoutACallFilterStack()); } -absl::optional TransportTest::Acceptor::PopHandler() { +absl::optional TransportTest::ServerCallDestination::PopHandler() { if (!handlers_.empty()) { auto handler = std::move(handlers_.front()); handlers_.pop(); diff --git a/test/core/transport/test_suite/test.h b/test/core/transport/test_suite/test.h index 1add21cdd29..841b8cedfc8 100644 --- a/test/core/transport/test_suite/test.h +++ b/test/core/transport/test_suite/test.h @@ -32,6 +32,7 @@ #include "src/core/lib/resource_quota/resource_quota.h" #include "test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h" #include "test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.h" +#include "test/core/test_util/test_config.h" #include "test/core/transport/test_suite/fixture.h" namespace grpc_core { @@ -220,7 +221,7 @@ class TransportTest : public ::testing::Test { fixture_(std::move(fixture)), rng_(rng) {} - void SetServerAcceptor(); + void SetServerCallDestination(); CallInitiator CreateCall(ClientMetadataHandle client_initial_metadata); std::string RandomString(int min_length, int max_length, @@ -270,18 +271,14 @@ class TransportTest : public ::testing::Test { void Timeout(); - class Acceptor final : public ServerTransport::Acceptor { + class ServerCallDestination final : public UnstartedCallDestination { public: - explicit Acceptor(TransportTest* test) : test_(test) {} - - Arena* CreateArena() override; - absl::StatusOr CreateCall( - ClientMetadataHandle client_initial_metadata, Arena* arena) override; + void StartCall(UnstartedCallHandler unstarted_call_handler) override; + void Orphaned() override {} absl::optional PopHandler(); private: std::queue handlers_; - TransportTest* const test_; }; class WatchDog { @@ -296,6 +293,7 @@ class TransportTest : public ::testing::Test { [this]() { test_->Timeout(); })}; }; + grpc::testing::TestGrpcScope grpc_scope_; std::shared_ptr event_engine_{ std::make_shared( @@ -313,7 +311,8 @@ class TransportTest : public ::testing::Test { ->memory_quota() ->CreateMemoryAllocator("test-allocator"), 1024)}; - Acceptor acceptor_{this}; + RefCountedPtr server_call_destination_ = + MakeRefCounted(); TransportFixture::ClientAndServerTransportPair transport_pair_ = fixture_->CreateTransportPair(event_engine_); std::queue> diff --git a/test/core/transport/timeout_encoding_test.cc b/test/core/transport/timeout_encoding_test.cc index 420fd930fee..0f03dfa7b3f 100644 --- a/test/core/transport/timeout_encoding_test.cc +++ b/test/core/transport/timeout_encoding_test.cc @@ -24,8 +24,8 @@ #include "absl/strings/string_view.h" #include "gtest/gtest.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/time.h" +#include "src/core/util/useful.h" namespace grpc_core { namespace { diff --git a/test/core/tsi/BUILD b/test/core/tsi/BUILD index ac8204ced28..378ac22ca4d 100644 --- a/test/core/tsi/BUILD +++ b/test/core/tsi/BUILD @@ -91,7 +91,7 @@ grpc_cc_test( grpc_cc_test( name = "ssl_transport_security_test", - timeout = "long", + timeout = "eternal", srcs = ["ssl_transport_security_test.cc"], data = [ "//src/core/tsi/test_creds:badclient.key", @@ -111,10 +111,12 @@ grpc_cc_test( "//src/core/tsi/test_creds:server1.pem", ], external_deps = [ + "absl/log:log", "absl/strings", "gtest", ], language = "C++", + shard_count = 5, tags = ["no_windows"], deps = [ ":transport_security_test_lib", @@ -166,7 +168,10 @@ grpc_cc_test( grpc_cc_test( name = "transport_security_test", srcs = ["transport_security_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", deps = [ "//:gpr", diff --git a/test/core/tsi/alts/fake_handshaker/BUILD b/test/core/tsi/alts/fake_handshaker/BUILD index 6f90dfb6343..55ee08a1163 100644 --- a/test/core/tsi/alts/fake_handshaker/BUILD +++ b/test/core/tsi/alts/fake_handshaker/BUILD @@ -59,6 +59,7 @@ grpc_cc_binary( external_deps = [ "absl/flags:flag", "absl/log:check", + "absl/log:log", ], language = "C++", deps = [ diff --git a/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc b/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc index a333fd85417..e7f58d93c94 100644 --- a/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc +++ b/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc @@ -22,10 +22,10 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include -#include #include #include #include @@ -69,7 +69,7 @@ class FakeHandshakerService : public HandshakerService::Service { HandshakerContext context; HandshakerReq request; HandshakerResp response; - gpr_log(GPR_DEBUG, "Start a new handshake."); + VLOG(2) << "Start a new handshake."; while (stream->Read(&request)) { status = ProcessRequest(&context, request, &response); if (!status.ok()) return WriteErrorResponse(stream, status); @@ -101,13 +101,13 @@ class FakeHandshakerService : public HandshakerService::Service { CHECK_NE(response, nullptr); response->Clear(); if (request.has_client_start()) { - gpr_log(GPR_DEBUG, "Process client start request."); + VLOG(2) << "Process client start request."; return ProcessClientStart(context, request.client_start(), response); } else if (request.has_server_start()) { - gpr_log(GPR_DEBUG, "Process server start request."); + VLOG(2) << "Process server start request."; return ProcessServerStart(context, request.server_start(), response); } else if (request.has_next()) { - gpr_log(GPR_DEBUG, "Process next request."); + VLOG(2) << "Process next request."; return ProcessNext(context, request.next(), response); } return Status(StatusCode::INVALID_ARGUMENT, "Request is empty."); diff --git a/test/core/tsi/alts/frame_protector/frame_handler_test.cc b/test/core/tsi/alts/frame_protector/frame_handler_test.cc index 7563d5542e4..b5ddb31b9b6 100644 --- a/test/core/tsi/alts/frame_protector/frame_handler_test.cc +++ b/test/core/tsi/alts/frame_protector/frame_handler_test.cc @@ -29,8 +29,8 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" +#include "src/core/util/useful.h" #include "test/core/tsi/alts/crypt/gsec_test_util.h" const size_t kFrameHandlerTestBufferSize = 1024; diff --git a/test/core/tsi/alts/handshaker/BUILD b/test/core/tsi/alts/handshaker/BUILD index 1eb4ef6ed4c..953d03fcd9b 100644 --- a/test/core/tsi/alts/handshaker/BUILD +++ b/test/core/tsi/alts/handshaker/BUILD @@ -22,6 +22,7 @@ grpc_cc_library( name = "alts_handshaker_service_api_test_lib", srcs = ["alts_handshaker_service_api_test_lib.cc"], hdrs = ["alts_handshaker_service_api_test_lib.h"], + external_deps = ["absl/log:log"], deps = [ "//:grpc", ], @@ -83,6 +84,7 @@ grpc_cc_test( ], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], flaky = True, diff --git a/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc b/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc index 47e1e115e1e..65a32533d42 100644 --- a/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc +++ b/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc @@ -32,6 +32,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" @@ -40,14 +41,12 @@ #include #include #include -#include #include #include #include #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/thd.h" @@ -56,6 +55,7 @@ #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/security_connector/alts/alts_security_connector.h" #include "src/core/lib/slice/slice_string_helpers.h" +#include "src/core/util/useful.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/test_util/fake_udp_and_tcp_server.h" #include "test/core/test_util/port.h" @@ -113,8 +113,7 @@ class FakeHandshakeServer { // TODO(apolcyn): when removing the global concurrent handshake limiting // queue, set MAX_CONCURRENT_STREAMS on this server. server_ = builder.BuildAndStart(); - gpr_log(GPR_INFO, "Fake handshaker server listening on %s", - address_.c_str()); + LOG(INFO) << "Fake handshaker server listening on " << address_; } ~FakeHandshakeServer() { @@ -148,13 +147,12 @@ class TestServer { server_creds)); grpc_server_credentials_release(server_creds); grpc_server_start(server_); - gpr_log(GPR_DEBUG, "Start TestServer %p. listen on %s", this, - server_addr_.c_str()); + VLOG(2) << "Start TestServer " << this << ". listen on " << server_addr_; server_thd_ = std::make_unique(PollUntilShutdown, this); } ~TestServer() { - gpr_log(GPR_DEBUG, "Begin dtor of TestServer %p", this); + VLOG(2) << "Begin dtor of TestServer " << this; grpc_server_shutdown_and_notify(server_, server_cq_, this); server_thd_->join(); grpc_server_destroy(server_); @@ -170,7 +168,7 @@ class TestServer { self->server_cq_, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); CHECK(ev.type == GRPC_OP_COMPLETE); CHECK(ev.tag == self); - gpr_log(GPR_DEBUG, "TestServer %p stop polling", self); + VLOG(2) << "TestServer " << self << " stop polling"; } private: @@ -210,7 +208,7 @@ class ConnectLoopRunner { static void ConnectLoop(const ConnectLoopRunner* self) { for (size_t i = 0; i < self->loops_; i++) { - gpr_log(GPR_DEBUG, "runner:%p connect_loop begin loop %ld", self, i); + VLOG(2) << "runner:" << self << " connect_loop begin loop " << i; grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); grpc_channel* channel = create_secure_channel_for_test( @@ -259,7 +257,7 @@ class ConnectLoopRunner { grpc_completion_queue_shutdown(cq); drain_cq(cq); grpc_completion_queue_destroy(cq); - gpr_log(GPR_DEBUG, "runner:%p connect_loop finished loop %ld", self, i); + VLOG(2) << "runner:" << self << " connect_loop finished loop " << i; } } @@ -296,8 +294,7 @@ TEST(AltsConcurrentConnectivityTest, TestConcurrentClientServerHandshakes) { TestServer test_server; size_t num_concurrent_connects = 50; std::vector> connect_loop_runners; - gpr_log(GPR_DEBUG, - "start performing concurrent expected-to-succeed connects"); + VLOG(2) << "start performing concurrent expected-to-succeed connects"; for (size_t i = 0; i < num_concurrent_connects; i++) { connect_loop_runners.push_back(std::make_unique( test_server.address(), fake_handshake_server.address(), @@ -306,8 +303,7 @@ TEST(AltsConcurrentConnectivityTest, TestConcurrentClientServerHandshakes) { 0 /* reconnect_backoff_ms unset */)); } connect_loop_runners.clear(); - gpr_log(GPR_DEBUG, - "done performing concurrent expected-to-succeed connects"); + VLOG(2) << "done performing concurrent expected-to-succeed connects"; } } @@ -336,7 +332,7 @@ TEST(AltsConcurrentConnectivityTest, { std::vector> connect_loop_runners; size_t num_concurrent_connects = 100; - gpr_log(GPR_DEBUG, "start performing concurrent expected-to-fail connects"); + VLOG(2) << "start performing concurrent expected-to-fail connects"; for (size_t i = 0; i < num_concurrent_connects; i++) { connect_loop_runners.push_back(std::make_unique( fake_backend_server.address(), fake_handshake_server.address(), @@ -345,7 +341,7 @@ TEST(AltsConcurrentConnectivityTest, 0 /* reconnect_backoff_ms unset */)); } connect_loop_runners.clear(); - gpr_log(GPR_DEBUG, "done performing concurrent expected-to-fail connects"); + VLOG(2) << "done performing concurrent expected-to-fail connects"; } } @@ -368,7 +364,7 @@ TEST(AltsConcurrentConnectivityTest, { std::vector> connect_loop_runners; size_t num_concurrent_connects = 100; - gpr_log(GPR_DEBUG, "start performing concurrent expected-to-fail connects"); + VLOG(2) << "start performing concurrent expected-to-fail connects"; for (size_t i = 0; i < num_concurrent_connects; i++) { connect_loop_runners.push_back(std::make_unique( fake_backend_server.address(), fake_handshake_server.address(), @@ -377,7 +373,7 @@ TEST(AltsConcurrentConnectivityTest, 0 /* reconnect_backoff_ms unset */)); } connect_loop_runners.clear(); - gpr_log(GPR_DEBUG, "done performing concurrent expected-to-fail connects"); + VLOG(2) << "done performing concurrent expected-to-fail connects"; } } @@ -400,7 +396,7 @@ TEST(AltsConcurrentConnectivityTest, { std::vector> connect_loop_runners; size_t num_concurrent_connects = 100; - gpr_log(GPR_DEBUG, "start performing concurrent expected-to-fail connects"); + VLOG(2) << "start performing concurrent expected-to-fail connects"; for (size_t i = 0; i < num_concurrent_connects; i++) { connect_loop_runners.push_back(std::make_unique( fake_backend_server.address(), fake_handshake_server.address(), @@ -409,7 +405,7 @@ TEST(AltsConcurrentConnectivityTest, 100 /* reconnect_backoff_ms */)); } connect_loop_runners.clear(); - gpr_log(GPR_DEBUG, "done performing concurrent expected-to-fail connects"); + VLOG(2) << "done performing concurrent expected-to-fail connects"; } } diff --git a/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc b/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc index dbf65518e56..1afa79ca951 100644 --- a/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc +++ b/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc @@ -18,13 +18,14 @@ #include "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" +#include "absl/log/log.h" + bool grpc_gcp_handshaker_resp_set_peer_rpc_versions( grpc_gcp_HandshakerResp* resp, upb_Arena* arena, uint32_t max_major, uint32_t max_minor, uint32_t min_major, uint32_t min_minor) { if (resp == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr argument to " - "grpc_gcp_handshaker_resp_set_peer_rpc_versions()."); + LOG(ERROR) << "Invalid nullptr argument to " + "grpc_gcp_handshaker_resp_set_peer_rpc_versions()."; return false; } grpc_gcp_rpc_protocol_versions versions; @@ -50,7 +51,7 @@ grpc_gcp_HandshakerReq* grpc_gcp_handshaker_req_decode(grpc_slice slice, grpc_gcp_HandshakerReq* resp = grpc_gcp_HandshakerReq_parse( reinterpret_cast(buf), buf_size, arena); if (!resp) { - gpr_log(GPR_ERROR, "grpc_gcp_HandshakerReq decode error"); + LOG(ERROR) << "grpc_gcp_HandshakerReq decode error"; return nullptr; } return resp; diff --git a/test/core/tsi/ssl_transport_security_test.cc b/test/core/tsi/ssl_transport_security_test.cc index 0e6a5aa162a..a66720e0ca0 100644 --- a/test/core/tsi/ssl_transport_security_test.cc +++ b/test/core/tsi/ssl_transport_security_test.cc @@ -27,16 +27,14 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include #include -#include #include -#include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/memory.h" -#include "src/core/lib/security/security_connector/security_connector.h" #include "src/core/tsi/transport_security.h" #include "src/core/tsi/transport_security_interface.h" #include "test/core/test_util/build.h" @@ -63,10 +61,6 @@ const size_t kSessionTicketEncryptionKeySize = 80; const size_t kSessionTicketEncryptionKeySize = 48; #endif -// Indicates the TLS version used for the test. -static tsi_tls_version test_tls_version = tsi_tls_version::TSI_TLS1_3; -static bool test_send_client_ca_list = false; - typedef enum AlpnMode { NO_ALPN, ALPN_CLIENT_NO_SERVER, @@ -102,215 +96,9 @@ typedef struct ssl_key_cert_lib { uint16_t leaf_signed_by_intermediate_num_key_cert_pairs; } ssl_key_cert_lib; -typedef struct ssl_tsi_test_fixture { - tsi_test_fixture base; - ssl_key_cert_lib* key_cert_lib; - ssl_alpn_lib* alpn_lib; - bool force_client_auth; - char* server_name_indication; - tsi_ssl_session_cache* session_cache; - bool session_reused; - const char* session_ticket_key; - size_t session_ticket_key_size; - size_t network_bio_buf_size; - size_t ssl_bio_buf_size; - bool verify_root_cert_subject; - tsi_ssl_server_handshaker_factory* server_handshaker_factory; - tsi_ssl_client_handshaker_factory* client_handshaker_factory; -} ssl_tsi_test_fixture; - -static void ssl_test_setup_handshakers(tsi_test_fixture* fixture) { - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ASSERT_NE(ssl_fixture, nullptr); - ASSERT_NE(ssl_fixture->key_cert_lib, nullptr); - ASSERT_NE(ssl_fixture->alpn_lib, nullptr); - ssl_key_cert_lib* key_cert_lib = ssl_fixture->key_cert_lib; - ssl_alpn_lib* alpn_lib = ssl_fixture->alpn_lib; - // Create client handshaker factory. - tsi_ssl_client_handshaker_options client_options; - if (key_cert_lib->use_pem_root_certs) { - client_options.pem_root_certs = key_cert_lib->root_cert; - } - if (ssl_fixture->force_client_auth) { - client_options.pem_key_cert_pair = - key_cert_lib->use_bad_client_cert - ? &key_cert_lib->bad_client_pem_key_cert_pair - : &key_cert_lib->client_pem_key_cert_pair; - } - if (alpn_lib->alpn_mode == ALPN_CLIENT_NO_SERVER || - alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_OK || - alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_MISMATCH) { - client_options.alpn_protocols = alpn_lib->client_alpn_protocols; - client_options.num_alpn_protocols = alpn_lib->num_client_alpn_protocols; - } - client_options.root_store = - key_cert_lib->use_root_store ? key_cert_lib->root_store : nullptr; - if (ssl_fixture->session_cache != nullptr) { - client_options.session_cache = ssl_fixture->session_cache; - } - client_options.min_tls_version = test_tls_version; - client_options.max_tls_version = test_tls_version; - client_options.skip_server_certificate_verification = - key_cert_lib->skip_server_certificate_verification; - ASSERT_EQ(tsi_create_ssl_client_handshaker_factory_with_options( - &client_options, &ssl_fixture->client_handshaker_factory), - TSI_OK); - // Create server handshaker factory. - tsi_ssl_server_handshaker_options server_options; - if (alpn_lib->alpn_mode == ALPN_SERVER_NO_CLIENT || - alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_OK || - alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_MISMATCH) { - server_options.alpn_protocols = alpn_lib->server_alpn_protocols; - server_options.num_alpn_protocols = alpn_lib->num_server_alpn_protocols; - if (alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_MISMATCH) { - server_options.num_alpn_protocols--; - } - } - if (key_cert_lib->use_cert_signed_by_intermediate_ca) { - server_options.pem_key_cert_pairs = - key_cert_lib->leaf_signed_by_intermediate_key_cert_pairs; - server_options.num_key_cert_pairs = - key_cert_lib->leaf_signed_by_intermediate_num_key_cert_pairs; - } else { - server_options.pem_key_cert_pairs = - key_cert_lib->use_bad_server_cert - ? key_cert_lib->bad_server_pem_key_cert_pairs - : key_cert_lib->server_pem_key_cert_pairs; - server_options.num_key_cert_pairs = - key_cert_lib->use_bad_server_cert - ? key_cert_lib->bad_server_num_key_cert_pairs - : key_cert_lib->server_num_key_cert_pairs; - } - server_options.pem_client_root_certs = key_cert_lib->root_cert; - if (ssl_fixture->force_client_auth) { - server_options.client_certificate_request = - TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY; - } else { - server_options.client_certificate_request = - TSI_DONT_REQUEST_CLIENT_CERTIFICATE; - } - server_options.send_client_ca_list = test_send_client_ca_list; - server_options.session_ticket_key = ssl_fixture->session_ticket_key; - server_options.session_ticket_key_size = ssl_fixture->session_ticket_key_size; - server_options.min_tls_version = test_tls_version; - server_options.max_tls_version = test_tls_version; - ASSERT_EQ(tsi_create_ssl_server_handshaker_factory_with_options( - &server_options, &ssl_fixture->server_handshaker_factory), - TSI_OK); - // Create server and client handshakers. - ASSERT_EQ( - tsi_ssl_client_handshaker_factory_create_handshaker( - ssl_fixture->client_handshaker_factory, - ssl_fixture->server_name_indication, - ssl_fixture->network_bio_buf_size, ssl_fixture->ssl_bio_buf_size, - &ssl_fixture->base.client_handshaker), - TSI_OK); - ASSERT_EQ( - tsi_ssl_server_handshaker_factory_create_handshaker( - ssl_fixture->server_handshaker_factory, - ssl_fixture->network_bio_buf_size, ssl_fixture->ssl_bio_buf_size, - &ssl_fixture->base.server_handshaker), - TSI_OK); -} - -static void check_verified_root_cert_subject( - ssl_tsi_test_fixture* /*ssl_fixture*/, const tsi_peer* peer) { - const tsi_peer_property* verified_root_cert_subject = - tsi_peer_get_property_by_name( - peer, TSI_X509_VERIFIED_ROOT_CERT_SUBECT_PEER_PROPERTY); - ASSERT_NE(verified_root_cert_subject, nullptr); - const char* expected_match = - "CN=testca,O=Internet Widgits Pty Ltd,ST=Some-State,C=AU"; - ASSERT_EQ(memcmp(verified_root_cert_subject->value.data, expected_match, - verified_root_cert_subject->value.length), - 0); -} - -static void check_verified_root_cert_subject_unset( - ssl_tsi_test_fixture* /*ssl_fixture*/, const tsi_peer* peer) { - const tsi_peer_property* verified_root_cert_subject = - tsi_peer_get_property_by_name( - peer, TSI_X509_VERIFIED_ROOT_CERT_SUBECT_PEER_PROPERTY); - ASSERT_EQ(verified_root_cert_subject, nullptr); -} - -static void check_alpn(ssl_tsi_test_fixture* ssl_fixture, - const tsi_peer* peer) { - ASSERT_NE(ssl_fixture, nullptr); - ASSERT_NE(ssl_fixture->alpn_lib, nullptr); - ssl_alpn_lib* alpn_lib = ssl_fixture->alpn_lib; - const tsi_peer_property* alpn_property = - tsi_peer_get_property_by_name(peer, TSI_SSL_ALPN_SELECTED_PROTOCOL); - if (alpn_lib->alpn_mode != ALPN_CLIENT_SERVER_OK) { - ASSERT_EQ(alpn_property, nullptr); - } else { - ASSERT_NE(alpn_property, nullptr); - const char* expected_match = "baz"; - ASSERT_EQ(memcmp(alpn_property->value.data, expected_match, - alpn_property->value.length), - 0); - } -} - -static void check_security_level(const tsi_peer* peer) { - const tsi_peer_property* security_level = - tsi_peer_get_property_by_name(peer, TSI_SECURITY_LEVEL_PEER_PROPERTY); - ASSERT_NE(security_level, nullptr); - const char* expected_match = "TSI_PRIVACY_AND_INTEGRITY"; - ASSERT_EQ(memcmp(security_level->value.data, expected_match, - security_level->value.length), - 0); -} - -static const tsi_peer_property* -check_basic_authenticated_peer_and_get_common_name(const tsi_peer* peer) { - const tsi_peer_property* cert_type_property = - tsi_peer_get_property_by_name(peer, TSI_CERTIFICATE_TYPE_PEER_PROPERTY); - EXPECT_NE(cert_type_property, nullptr); - EXPECT_EQ(memcmp(cert_type_property->value.data, TSI_X509_CERTIFICATE_TYPE, - cert_type_property->value.length), - 0); - const tsi_peer_property* property = tsi_peer_get_property_by_name( - peer, TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY); - EXPECT_NE(property, nullptr); - return property; -} - -static void check_session_reusage(ssl_tsi_test_fixture* ssl_fixture, - tsi_peer* peer) { - const tsi_peer_property* session_reused = - tsi_peer_get_property_by_name(peer, TSI_SSL_SESSION_REUSED_PEER_PROPERTY); - ASSERT_NE(session_reused, nullptr); - if (ssl_fixture->session_reused) { - ASSERT_EQ(strncmp(session_reused->value.data, "true", - session_reused->value.length), - 0); - } else { - ASSERT_EQ(strncmp(session_reused->value.data, "false", - session_reused->value.length), - 0); - } -} - -void check_server0_peer(tsi_peer* peer) { - const tsi_peer_property* property = - check_basic_authenticated_peer_and_get_common_name(peer); - const char* expected_match = "*.test.google.com.au"; - ASSERT_EQ( - memcmp(property->value.data, expected_match, property->value.length), 0); - ASSERT_EQ(tsi_peer_get_property_by_name( - peer, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY), - nullptr); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "foo.test.google.com.au"), 1); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "bar.test.google.com.au"), 1); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "BAR.TEST.GOOGLE.COM.AU"), 1); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "Bar.Test.Google.Com.Au"), 1); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "bAr.TeST.gOOgle.cOm.AU"), 1); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "bar.test.google.blah"), 0); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "foo.bar.test.google.com.au"), 0); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "test.google.com.au"), 0); - tsi_peer_destruct(peer); +static void ssl_test_pem_key_cert_pair_destroy(tsi_ssl_pem_key_cert_pair kp) { + gpr_free(const_cast(kp.private_key)); + gpr_free(const_cast(kp.cert_chain)); } static bool check_property(tsi_peer* peer, const char* property_name, @@ -327,183 +115,6 @@ static bool check_property(tsi_peer* peer, const char* property_name, return false; } -void check_server1_peer(tsi_peer* peer) { - const tsi_peer_property* property = - check_basic_authenticated_peer_and_get_common_name(peer); - const char* expected_match = "*.test.google.com"; - ASSERT_EQ( - memcmp(property->value.data, expected_match, property->value.length), 0); - ASSERT_EQ( - check_property(peer, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, - "*.test.google.fr"), - 1); - ASSERT_EQ( - check_property(peer, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, - "waterzooi.test.google.be"), - 1); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "foo.test.google.fr"), 1); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "bar.test.google.fr"), 1); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "waterzooi.test.google.be"), 1); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "foo.test.youtube.com"), 1); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "bar.foo.test.google.com"), 0); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "test.google.fr"), 0); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "tartines.test.google.be"), 0); - ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "tartines.youtube.com"), 0); - tsi_peer_destruct(peer); -} - -static void check_client_peer(ssl_tsi_test_fixture* ssl_fixture, - tsi_peer* peer) { - ASSERT_NE(ssl_fixture, nullptr); - ASSERT_NE(ssl_fixture->alpn_lib, nullptr); - ssl_alpn_lib* alpn_lib = ssl_fixture->alpn_lib; - if (!ssl_fixture->force_client_auth) { - ASSERT_EQ(peer->property_count, - (alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_OK ? 3 : 2)); - } else { - const tsi_peer_property* property = - check_basic_authenticated_peer_and_get_common_name(peer); - const char* expected_match = "testclient"; - ASSERT_EQ( - memcmp(property->value.data, expected_match, property->value.length), - 0); - } - tsi_peer_destruct(peer); -} - -static void ssl_test_check_handshaker_peers(tsi_test_fixture* fixture) { - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ASSERT_NE(ssl_fixture, nullptr); - ASSERT_NE(ssl_fixture->key_cert_lib, nullptr); - ssl_key_cert_lib* key_cert_lib = ssl_fixture->key_cert_lib; - tsi_peer peer; - // In TLS 1.3, the client-side handshake succeeds even if the client sends a - // bad certificate. In such a case, the server would fail the TLS handshake - // and send an alert to the client as the first application data message. In - // TLS 1.2, the client-side handshake will fail if the client sends a bad - // certificate. - // - // For OpenSSL versions < 1.1, TLS 1.3 is not supported, so the client-side - // handshake should succeed precisely when the server-side handshake - // succeeds. - bool expect_server_success = - !(key_cert_lib->use_bad_server_cert || - (key_cert_lib->use_bad_client_cert && ssl_fixture->force_client_auth)); -#if OPENSSL_VERSION_NUMBER >= 0x10100000 - bool expect_client_success = test_tls_version == tsi_tls_version::TSI_TLS1_2 - ? expect_server_success - : !key_cert_lib->use_bad_server_cert; -#else - bool expect_client_success = expect_server_success; -#endif - if (expect_client_success) { - ASSERT_EQ(tsi_handshaker_result_extract_peer( - ssl_fixture->base.client_result, &peer), - TSI_OK); - check_session_reusage(ssl_fixture, &peer); - check_alpn(ssl_fixture, &peer); - check_security_level(&peer); - if (ssl_fixture->verify_root_cert_subject) { - if (!ssl_fixture->session_reused) { - check_verified_root_cert_subject(ssl_fixture, &peer); - } else { - check_verified_root_cert_subject_unset(ssl_fixture, &peer); - } - } - if (ssl_fixture->server_name_indication == nullptr || - strcmp(ssl_fixture->server_name_indication, SSL_TSI_TEST_WRONG_SNI) == - 0 || - strcmp(ssl_fixture->server_name_indication, SSL_TSI_TEST_INVALID_SNI) == - 0) { - // Expect server to use default server0.pem. - check_server0_peer(&peer); - } else { - // Expect server to use server1.pem. - check_server1_peer(&peer); - } - } else { - ASSERT_EQ(ssl_fixture->base.client_result, nullptr); - } - if (expect_server_success) { - ASSERT_EQ(tsi_handshaker_result_extract_peer( - ssl_fixture->base.server_result, &peer), - TSI_OK); - check_session_reusage(ssl_fixture, &peer); - check_alpn(ssl_fixture, &peer); - check_security_level(&peer); - if (ssl_fixture->force_client_auth && !ssl_fixture->session_reused) { - check_verified_root_cert_subject(ssl_fixture, &peer); - } else { - check_verified_root_cert_subject_unset(ssl_fixture, &peer); - } - check_client_peer(ssl_fixture, &peer); - } else { - ASSERT_EQ(ssl_fixture->base.server_result, nullptr); - } -} - -static void ssl_test_pem_key_cert_pair_destroy(tsi_ssl_pem_key_cert_pair kp) { - gpr_free(const_cast(kp.private_key)); - gpr_free(const_cast(kp.cert_chain)); -} - -static void ssl_test_destruct(tsi_test_fixture* fixture) { - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - if (ssl_fixture == nullptr) { - return; - } - // Destroy ssl_alpn_lib. - ssl_alpn_lib* alpn_lib = ssl_fixture->alpn_lib; - for (size_t i = 0; i < alpn_lib->num_server_alpn_protocols; i++) { - gpr_free(const_cast(alpn_lib->server_alpn_protocols[i])); - } - gpr_free(alpn_lib->server_alpn_protocols); - for (size_t i = 0; i < alpn_lib->num_client_alpn_protocols; i++) { - gpr_free(const_cast(alpn_lib->client_alpn_protocols[i])); - } - gpr_free(alpn_lib->client_alpn_protocols); - gpr_free(alpn_lib); - // Destroy ssl_key_cert_lib. - ssl_key_cert_lib* key_cert_lib = ssl_fixture->key_cert_lib; - for (size_t i = 0; i < key_cert_lib->server_num_key_cert_pairs; i++) { - ssl_test_pem_key_cert_pair_destroy( - key_cert_lib->server_pem_key_cert_pairs[i]); - } - gpr_free(key_cert_lib->server_pem_key_cert_pairs); - for (size_t i = 0; i < key_cert_lib->bad_server_num_key_cert_pairs; i++) { - ssl_test_pem_key_cert_pair_destroy( - key_cert_lib->bad_server_pem_key_cert_pairs[i]); - } - gpr_free(key_cert_lib->bad_server_pem_key_cert_pairs); - for (size_t i = 0; - i < key_cert_lib->leaf_signed_by_intermediate_num_key_cert_pairs; i++) { - ssl_test_pem_key_cert_pair_destroy( - key_cert_lib->leaf_signed_by_intermediate_key_cert_pairs[i]); - } - gpr_free(key_cert_lib->leaf_signed_by_intermediate_key_cert_pairs); - ssl_test_pem_key_cert_pair_destroy(key_cert_lib->client_pem_key_cert_pair); - ssl_test_pem_key_cert_pair_destroy( - key_cert_lib->bad_client_pem_key_cert_pair); - gpr_free(key_cert_lib->root_cert); - tsi_ssl_root_certs_store_destroy(key_cert_lib->root_store); - gpr_free(key_cert_lib); - if (ssl_fixture->session_cache != nullptr) { - tsi_ssl_session_cache_unref(ssl_fixture->session_cache); - } - // Unreference others. - tsi_ssl_server_handshaker_factory_unref( - ssl_fixture->server_handshaker_factory); - tsi_ssl_client_handshaker_factory_unref( - ssl_fixture->client_handshaker_factory); - gpr_free(ssl_fixture); -} - -static const struct tsi_test_fixture_vtable vtable = { - ssl_test_setup_handshakers, ssl_test_check_handshaker_peers, - ssl_test_destruct}; - static char* load_file(std::string path) { std::string data = grpc_core::testing::GetFileContents(path); return gpr_strdup(data.c_str()); @@ -535,311 +146,752 @@ static std::string GenerateTrustBundle() { return trust_bundle; } -static tsi_test_fixture* ssl_tsi_test_fixture_create() { - ssl_tsi_test_fixture* ssl_fixture = grpc_core::Zalloc(); - tsi_test_fixture_init(&ssl_fixture->base); - ssl_fixture->verify_root_cert_subject = true; - ssl_fixture->base.test_unused_bytes = true; - ssl_fixture->base.vtable = &vtable; - // Create ssl_key_cert_lib. - ssl_key_cert_lib* key_cert_lib = grpc_core::Zalloc(); - key_cert_lib->use_bad_server_cert = false; - key_cert_lib->use_bad_client_cert = false; - key_cert_lib->use_root_store = false; - key_cert_lib->use_pem_root_certs = true; - key_cert_lib->skip_server_certificate_verification = false; - key_cert_lib->server_num_key_cert_pairs = - SSL_TSI_TEST_SERVER_KEY_CERT_PAIRS_NUM; - key_cert_lib->bad_server_num_key_cert_pairs = - SSL_TSI_TEST_BAD_SERVER_KEY_CERT_PAIRS_NUM; - key_cert_lib->leaf_signed_by_intermediate_num_key_cert_pairs = - SSL_TSI_TEST_LEAF_SIGNED_BY_INTERMEDIATE_KEY_CERT_PAIRS_NUM; - key_cert_lib->server_pem_key_cert_pairs = - static_cast( - gpr_malloc(sizeof(tsi_ssl_pem_key_cert_pair) * - key_cert_lib->server_num_key_cert_pairs)); - key_cert_lib->bad_server_pem_key_cert_pairs = - static_cast( - gpr_malloc(sizeof(tsi_ssl_pem_key_cert_pair) * - key_cert_lib->bad_server_num_key_cert_pairs)); - key_cert_lib->leaf_signed_by_intermediate_key_cert_pairs = - static_cast(gpr_malloc( - sizeof(tsi_ssl_pem_key_cert_pair) * - key_cert_lib->leaf_signed_by_intermediate_num_key_cert_pairs)); - key_cert_lib->server_pem_key_cert_pairs[0].private_key = - load_file(SSL_TSI_TEST_CREDENTIALS_DIR "server0.key"); - key_cert_lib->server_pem_key_cert_pairs[0].cert_chain = - load_file(SSL_TSI_TEST_CREDENTIALS_DIR "server0.pem"); - key_cert_lib->server_pem_key_cert_pairs[1].private_key = - load_file(SSL_TSI_TEST_CREDENTIALS_DIR "server1.key"); - key_cert_lib->server_pem_key_cert_pairs[1].cert_chain = - load_file(SSL_TSI_TEST_CREDENTIALS_DIR "server1.pem"); - key_cert_lib->bad_server_pem_key_cert_pairs[0].private_key = - load_file(SSL_TSI_TEST_CREDENTIALS_DIR "badserver.key"); - key_cert_lib->bad_server_pem_key_cert_pairs[0].cert_chain = - load_file(SSL_TSI_TEST_CREDENTIALS_DIR "badserver.pem"); - key_cert_lib->client_pem_key_cert_pair.private_key = - load_file(SSL_TSI_TEST_CREDENTIALS_DIR "client.key"); - key_cert_lib->client_pem_key_cert_pair.cert_chain = - load_file(SSL_TSI_TEST_CREDENTIALS_DIR "client.pem"); - key_cert_lib->bad_client_pem_key_cert_pair.private_key = - load_file(SSL_TSI_TEST_CREDENTIALS_DIR "badclient.key"); - key_cert_lib->bad_client_pem_key_cert_pair.cert_chain = - load_file(SSL_TSI_TEST_CREDENTIALS_DIR "badclient.pem"); - key_cert_lib->leaf_signed_by_intermediate_key_cert_pairs[0].private_key = - load_file(SSL_TSI_TEST_CREDENTIALS_DIR "leaf_signed_by_intermediate.key"); - key_cert_lib->leaf_signed_by_intermediate_key_cert_pairs[0].cert_chain = - load_file(SSL_TSI_TEST_CREDENTIALS_DIR "leaf_and_intermediate_chain.pem"); - key_cert_lib->root_cert = load_file(SSL_TSI_TEST_CREDENTIALS_DIR "ca.pem"); - key_cert_lib->root_store = - tsi_ssl_root_certs_store_create(key_cert_lib->root_cert); - EXPECT_NE(key_cert_lib->root_store, nullptr); - ssl_fixture->key_cert_lib = key_cert_lib; - // Create ssl_alpn_lib. - ssl_alpn_lib* alpn_lib = grpc_core::Zalloc(); - alpn_lib->server_alpn_protocols = static_cast( - gpr_zalloc(sizeof(char*) * SSL_TSI_TEST_ALPN_NUM)); - alpn_lib->client_alpn_protocols = static_cast( - gpr_zalloc(sizeof(char*) * SSL_TSI_TEST_ALPN_NUM)); - alpn_lib->server_alpn_protocols[0] = gpr_strdup(SSL_TSI_TEST_ALPN1); - alpn_lib->server_alpn_protocols[1] = gpr_strdup(SSL_TSI_TEST_ALPN3); - alpn_lib->client_alpn_protocols[0] = gpr_strdup(SSL_TSI_TEST_ALPN2); - alpn_lib->client_alpn_protocols[1] = gpr_strdup(SSL_TSI_TEST_ALPN3); - alpn_lib->num_server_alpn_protocols = SSL_TSI_TEST_ALPN_NUM; - alpn_lib->num_client_alpn_protocols = SSL_TSI_TEST_ALPN_NUM; - alpn_lib->alpn_mode = NO_ALPN; - ssl_fixture->alpn_lib = alpn_lib; - ssl_fixture->base.vtable = &vtable; - ssl_fixture->server_name_indication = nullptr; - ssl_fixture->session_reused = false; - ssl_fixture->session_ticket_key = nullptr; - ssl_fixture->session_ticket_key_size = 0; - ssl_fixture->force_client_auth = false; - ssl_fixture->network_bio_buf_size = 0; - ssl_fixture->ssl_bio_buf_size = 0; - return &ssl_fixture->base; -} +class SslTransportSecurityTest + : public ::testing::TestWithParam> { + protected: + // A tsi_test_fixture implementation + class SslTsiTestFixture { + public: + SslTsiTestFixture(tsi_tls_version tls_version, bool send_client_ca_list) { + tsi_test_fixture_init(&base_); + verify_root_cert_subject_ = true; + base_.test_unused_bytes = true; + base_.vtable = &kVtable; + // Create ssl_key_cert_lib. + key_cert_lib_ = grpc_core::Zalloc(); + key_cert_lib_->use_bad_server_cert = false; + key_cert_lib_->use_bad_client_cert = false; + key_cert_lib_->use_root_store = false; + key_cert_lib_->use_pem_root_certs = true; + key_cert_lib_->skip_server_certificate_verification = false; + key_cert_lib_->server_num_key_cert_pairs = + SSL_TSI_TEST_SERVER_KEY_CERT_PAIRS_NUM; + key_cert_lib_->bad_server_num_key_cert_pairs = + SSL_TSI_TEST_BAD_SERVER_KEY_CERT_PAIRS_NUM; + key_cert_lib_->leaf_signed_by_intermediate_num_key_cert_pairs = + SSL_TSI_TEST_LEAF_SIGNED_BY_INTERMEDIATE_KEY_CERT_PAIRS_NUM; + key_cert_lib_->server_pem_key_cert_pairs = + static_cast( + gpr_malloc(sizeof(tsi_ssl_pem_key_cert_pair) * + key_cert_lib_->server_num_key_cert_pairs)); + key_cert_lib_->bad_server_pem_key_cert_pairs = + static_cast( + gpr_malloc(sizeof(tsi_ssl_pem_key_cert_pair) * + key_cert_lib_->bad_server_num_key_cert_pairs)); + key_cert_lib_->leaf_signed_by_intermediate_key_cert_pairs = + static_cast(gpr_malloc( + sizeof(tsi_ssl_pem_key_cert_pair) * + key_cert_lib_->leaf_signed_by_intermediate_num_key_cert_pairs)); + key_cert_lib_->server_pem_key_cert_pairs[0].private_key = + load_file(SSL_TSI_TEST_CREDENTIALS_DIR "server0.key"); + key_cert_lib_->server_pem_key_cert_pairs[0].cert_chain = + load_file(SSL_TSI_TEST_CREDENTIALS_DIR "server0.pem"); + key_cert_lib_->server_pem_key_cert_pairs[1].private_key = + load_file(SSL_TSI_TEST_CREDENTIALS_DIR "server1.key"); + key_cert_lib_->server_pem_key_cert_pairs[1].cert_chain = + load_file(SSL_TSI_TEST_CREDENTIALS_DIR "server1.pem"); + key_cert_lib_->bad_server_pem_key_cert_pairs[0].private_key = + load_file(SSL_TSI_TEST_CREDENTIALS_DIR "badserver.key"); + key_cert_lib_->bad_server_pem_key_cert_pairs[0].cert_chain = + load_file(SSL_TSI_TEST_CREDENTIALS_DIR "badserver.pem"); + key_cert_lib_->client_pem_key_cert_pair.private_key = + load_file(SSL_TSI_TEST_CREDENTIALS_DIR "client.key"); + key_cert_lib_->client_pem_key_cert_pair.cert_chain = + load_file(SSL_TSI_TEST_CREDENTIALS_DIR "client.pem"); + key_cert_lib_->bad_client_pem_key_cert_pair.private_key = + load_file(SSL_TSI_TEST_CREDENTIALS_DIR "badclient.key"); + key_cert_lib_->bad_client_pem_key_cert_pair.cert_chain = + load_file(SSL_TSI_TEST_CREDENTIALS_DIR "badclient.pem"); + key_cert_lib_->leaf_signed_by_intermediate_key_cert_pairs[0].private_key = + load_file(SSL_TSI_TEST_CREDENTIALS_DIR + "leaf_signed_by_intermediate.key"); + key_cert_lib_->leaf_signed_by_intermediate_key_cert_pairs[0].cert_chain = + load_file(SSL_TSI_TEST_CREDENTIALS_DIR + "leaf_and_intermediate_chain.pem"); + key_cert_lib_->root_cert = + load_file(SSL_TSI_TEST_CREDENTIALS_DIR "ca.pem"); + key_cert_lib_->root_store = + tsi_ssl_root_certs_store_create(key_cert_lib_->root_cert); + EXPECT_NE(key_cert_lib_->root_store, nullptr); + // Create ssl_alpn_lib. + alpn_lib_ = grpc_core::Zalloc(); + alpn_lib_->server_alpn_protocols = static_cast( + gpr_zalloc(sizeof(char*) * SSL_TSI_TEST_ALPN_NUM)); + alpn_lib_->client_alpn_protocols = static_cast( + gpr_zalloc(sizeof(char*) * SSL_TSI_TEST_ALPN_NUM)); + alpn_lib_->server_alpn_protocols[0] = gpr_strdup(SSL_TSI_TEST_ALPN1); + alpn_lib_->server_alpn_protocols[1] = gpr_strdup(SSL_TSI_TEST_ALPN3); + alpn_lib_->client_alpn_protocols[0] = gpr_strdup(SSL_TSI_TEST_ALPN2); + alpn_lib_->client_alpn_protocols[1] = gpr_strdup(SSL_TSI_TEST_ALPN3); + alpn_lib_->num_server_alpn_protocols = SSL_TSI_TEST_ALPN_NUM; + alpn_lib_->num_client_alpn_protocols = SSL_TSI_TEST_ALPN_NUM; + alpn_lib_->alpn_mode = NO_ALPN; + server_name_indication_ = nullptr; + session_reused_ = false; + session_ticket_key_ = nullptr; + session_ticket_key_size_ = 0; + force_client_auth_ = false; + network_bio_buf_size_ = 0; + ssl_bio_buf_size_ = 0; + send_client_ca_list_ = send_client_ca_list; + tls_version_ = tls_version; + } + + ~SslTsiTestFixture() { + // Destroy ssl_alpn_lib. + for (size_t i = 0; i < alpn_lib_->num_server_alpn_protocols; i++) { + gpr_free(const_cast(alpn_lib_->server_alpn_protocols[i])); + } + gpr_free(alpn_lib_->server_alpn_protocols); + for (size_t i = 0; i < alpn_lib_->num_client_alpn_protocols; i++) { + gpr_free(const_cast(alpn_lib_->client_alpn_protocols[i])); + } + gpr_free(alpn_lib_->client_alpn_protocols); + gpr_free(alpn_lib_); + // Destroy ssl_key_cert_lib. + for (size_t i = 0; i < key_cert_lib_->server_num_key_cert_pairs; i++) { + ssl_test_pem_key_cert_pair_destroy( + key_cert_lib_->server_pem_key_cert_pairs[i]); + } + gpr_free(key_cert_lib_->server_pem_key_cert_pairs); + for (size_t i = 0; i < key_cert_lib_->bad_server_num_key_cert_pairs; + i++) { + ssl_test_pem_key_cert_pair_destroy( + key_cert_lib_->bad_server_pem_key_cert_pairs[i]); + } + gpr_free(key_cert_lib_->bad_server_pem_key_cert_pairs); + for (size_t i = 0; + i < key_cert_lib_->leaf_signed_by_intermediate_num_key_cert_pairs; + i++) { + ssl_test_pem_key_cert_pair_destroy( + key_cert_lib_->leaf_signed_by_intermediate_key_cert_pairs[i]); + } + gpr_free(key_cert_lib_->leaf_signed_by_intermediate_key_cert_pairs); + ssl_test_pem_key_cert_pair_destroy( + key_cert_lib_->client_pem_key_cert_pair); + ssl_test_pem_key_cert_pair_destroy( + key_cert_lib_->bad_client_pem_key_cert_pair); + gpr_free(key_cert_lib_->root_cert); + tsi_ssl_root_certs_store_destroy(key_cert_lib_->root_store); + gpr_free(key_cert_lib_); + if (session_cache_ != nullptr) { + tsi_ssl_session_cache_unref(session_cache_); + } + // Unreference others. + tsi_ssl_server_handshaker_factory_unref(server_handshaker_factory_); + tsi_ssl_client_handshaker_factory_unref(client_handshaker_factory_); + } + + tsi_test_fixture* GetBaseFixture() { return &base_; } + + void SetVerifyRootCertSubject(bool verify_root_cert_subject) { + verify_root_cert_subject_ = verify_root_cert_subject; + } + + ssl_key_cert_lib* MutableKeyCertLib() { return key_cert_lib_; } + + void SetForceClientAuth(bool force_client_auth) { + force_client_auth_ = force_client_auth; + } + + void SetAlpnMode(AlpnMode alpn_mode) { alpn_lib_->alpn_mode = alpn_mode; } + + void SetServerNameIndication(char* server_name_indication) { + server_name_indication_ = server_name_indication; + } + + void SetSessionCache(tsi_ssl_session_cache* cache) { + session_cache_ = cache; + } + + void SetSessionReused(bool session_reused) { + session_reused_ = session_reused; + } + + void SetSessionTicketKey(const char* session_ticket_key, + size_t session_ticket_key_size) { + session_ticket_key_ = session_ticket_key; + session_ticket_key_size_ = session_ticket_key_size; + } + + void SetBioBufSizes(size_t network_bio_buf_size, size_t ssl_bio_buf_size) { + network_bio_buf_size_ = network_bio_buf_size; + ssl_bio_buf_size_ = ssl_bio_buf_size; + } + + private: + static void SetupHandshakers(tsi_test_fixture* fixture) { + SslTsiTestFixture* ssl_fixture = + reinterpret_cast(fixture); + ASSERT_NE(ssl_fixture, nullptr); + ASSERT_NE(ssl_fixture->key_cert_lib_, nullptr); + ASSERT_NE(ssl_fixture->alpn_lib_, nullptr); + ssl_key_cert_lib* key_cert_lib = ssl_fixture->key_cert_lib_; + ssl_alpn_lib* alpn_lib = ssl_fixture->alpn_lib_; + // Create client handshaker factory. + tsi_ssl_client_handshaker_options client_options; + if (key_cert_lib->use_pem_root_certs) { + client_options.pem_root_certs = key_cert_lib->root_cert; + } + if (ssl_fixture->force_client_auth_) { + client_options.pem_key_cert_pair = + key_cert_lib->use_bad_client_cert + ? &key_cert_lib->bad_client_pem_key_cert_pair + : &key_cert_lib->client_pem_key_cert_pair; + } + if (alpn_lib->alpn_mode == ALPN_CLIENT_NO_SERVER || + alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_OK || + alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_MISMATCH) { + client_options.alpn_protocols = alpn_lib->client_alpn_protocols; + client_options.num_alpn_protocols = alpn_lib->num_client_alpn_protocols; + } + client_options.root_store = + key_cert_lib->use_root_store ? key_cert_lib->root_store : nullptr; + if (ssl_fixture->session_cache_ != nullptr) { + client_options.session_cache = ssl_fixture->session_cache_; + } + client_options.min_tls_version = ssl_fixture->tls_version_; + client_options.max_tls_version = ssl_fixture->tls_version_; + client_options.skip_server_certificate_verification = + key_cert_lib->skip_server_certificate_verification; + ASSERT_EQ(tsi_create_ssl_client_handshaker_factory_with_options( + &client_options, &ssl_fixture->client_handshaker_factory_), + TSI_OK); + // Create server handshaker factory. + tsi_ssl_server_handshaker_options server_options; + if (alpn_lib->alpn_mode == ALPN_SERVER_NO_CLIENT || + alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_OK || + alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_MISMATCH) { + server_options.alpn_protocols = alpn_lib->server_alpn_protocols; + server_options.num_alpn_protocols = alpn_lib->num_server_alpn_protocols; + if (alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_MISMATCH) { + server_options.num_alpn_protocols--; + } + } + if (key_cert_lib->use_cert_signed_by_intermediate_ca) { + server_options.pem_key_cert_pairs = + key_cert_lib->leaf_signed_by_intermediate_key_cert_pairs; + server_options.num_key_cert_pairs = + key_cert_lib->leaf_signed_by_intermediate_num_key_cert_pairs; + } else { + server_options.pem_key_cert_pairs = + key_cert_lib->use_bad_server_cert + ? key_cert_lib->bad_server_pem_key_cert_pairs + : key_cert_lib->server_pem_key_cert_pairs; + server_options.num_key_cert_pairs = + key_cert_lib->use_bad_server_cert + ? key_cert_lib->bad_server_num_key_cert_pairs + : key_cert_lib->server_num_key_cert_pairs; + } + server_options.pem_client_root_certs = key_cert_lib->root_cert; + if (ssl_fixture->force_client_auth_) { + server_options.client_certificate_request = + TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY; + } else { + server_options.client_certificate_request = + TSI_DONT_REQUEST_CLIENT_CERTIFICATE; + } + server_options.send_client_ca_list = ssl_fixture->send_client_ca_list_; + server_options.session_ticket_key = ssl_fixture->session_ticket_key_; + server_options.session_ticket_key_size = + ssl_fixture->session_ticket_key_size_; + server_options.min_tls_version = ssl_fixture->tls_version_; + server_options.max_tls_version = ssl_fixture->tls_version_; + ASSERT_EQ(tsi_create_ssl_server_handshaker_factory_with_options( + &server_options, &ssl_fixture->server_handshaker_factory_), + TSI_OK); + // Create server and client handshakers. + ASSERT_EQ(tsi_ssl_client_handshaker_factory_create_handshaker( + ssl_fixture->client_handshaker_factory_, + ssl_fixture->server_name_indication_, + ssl_fixture->network_bio_buf_size_, + ssl_fixture->ssl_bio_buf_size_, + &ssl_fixture->base_.client_handshaker), + TSI_OK); + ASSERT_EQ(tsi_ssl_server_handshaker_factory_create_handshaker( + ssl_fixture->server_handshaker_factory_, + ssl_fixture->network_bio_buf_size_, + ssl_fixture->ssl_bio_buf_size_, + &ssl_fixture->base_.server_handshaker), + TSI_OK); + } + + static void CheckAlpn(SslTsiTestFixture* ssl_fixture, + const tsi_peer* peer) { + ASSERT_NE(ssl_fixture, nullptr); + ASSERT_NE(ssl_fixture->alpn_lib_, nullptr); + ssl_alpn_lib* alpn_lib = ssl_fixture->alpn_lib_; + const tsi_peer_property* alpn_property = + tsi_peer_get_property_by_name(peer, TSI_SSL_ALPN_SELECTED_PROTOCOL); + if (alpn_lib->alpn_mode != ALPN_CLIENT_SERVER_OK) { + ASSERT_EQ(alpn_property, nullptr); + } else { + ASSERT_NE(alpn_property, nullptr); + const char* expected_match = "baz"; + ASSERT_EQ(memcmp(alpn_property->value.data, expected_match, + alpn_property->value.length), + 0); + } + } + + static void CheckSecurityLevel(const tsi_peer* peer) { + const tsi_peer_property* security_level = + tsi_peer_get_property_by_name(peer, TSI_SECURITY_LEVEL_PEER_PROPERTY); + ASSERT_NE(security_level, nullptr); + const char* expected_match = "TSI_PRIVACY_AND_INTEGRITY"; + ASSERT_EQ(memcmp(security_level->value.data, expected_match, + security_level->value.length), + 0); + } + + static const tsi_peer_property* CheckBasicAuthenticatedPeerAndGetCommonName( + const tsi_peer* peer) { + const tsi_peer_property* cert_type_property = + tsi_peer_get_property_by_name(peer, + TSI_CERTIFICATE_TYPE_PEER_PROPERTY); + EXPECT_NE(cert_type_property, nullptr); + EXPECT_EQ( + memcmp(cert_type_property->value.data, TSI_X509_CERTIFICATE_TYPE, + cert_type_property->value.length), + 0); + const tsi_peer_property* property = tsi_peer_get_property_by_name( + peer, TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY); + EXPECT_NE(property, nullptr); + return property; + } + + static void CheckSessionReusage(SslTsiTestFixture* ssl_fixture, + tsi_peer* peer) { + const tsi_peer_property* session_reused = tsi_peer_get_property_by_name( + peer, TSI_SSL_SESSION_REUSED_PEER_PROPERTY); + ASSERT_NE(session_reused, nullptr); + if (ssl_fixture->session_reused_) { + ASSERT_EQ(strncmp(session_reused->value.data, "true", + session_reused->value.length), + 0); + } else { + ASSERT_EQ(strncmp(session_reused->value.data, "false", + session_reused->value.length), + 0); + } + } + + // This is tied specifically to server0.pem loaded by the fixture. + static void CheckServer0Peer(tsi_peer* peer) { + const tsi_peer_property* property = + CheckBasicAuthenticatedPeerAndGetCommonName(peer); + const char* expected_match = "*.test.google.com.au"; + ASSERT_EQ( + memcmp(property->value.data, expected_match, property->value.length), + 0); + ASSERT_EQ(tsi_peer_get_property_by_name( + peer, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY), + nullptr); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "foo.test.google.com.au"), 1); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "bar.test.google.com.au"), 1); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "BAR.TEST.GOOGLE.COM.AU"), 1); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "Bar.Test.Google.Com.Au"), 1); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "bAr.TeST.gOOgle.cOm.AU"), 1); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "bar.test.google.blah"), 0); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "foo.bar.test.google.com.au"), + 0); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "test.google.com.au"), 0); + tsi_peer_destruct(peer); + } + + // This is tied specifically to server1.pem loaded by the fixture. + static void CheckServer1Peer(tsi_peer* peer) { + const tsi_peer_property* property = + CheckBasicAuthenticatedPeerAndGetCommonName(peer); + const char* expected_match = "*.test.google.com"; + ASSERT_EQ( + memcmp(property->value.data, expected_match, property->value.length), + 0); + ASSERT_EQ( + check_property(peer, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, + "*.test.google.fr"), + 1); + ASSERT_EQ( + check_property(peer, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, + "waterzooi.test.google.be"), + 1); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "foo.test.google.fr"), 1); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "bar.test.google.fr"), 1); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "waterzooi.test.google.be"), 1); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "foo.test.youtube.com"), 1); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "bar.foo.test.google.com"), 0); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "test.google.fr"), 0); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "tartines.test.google.be"), 0); + ASSERT_EQ(tsi_ssl_peer_matches_name(peer, "tartines.youtube.com"), 0); + tsi_peer_destruct(peer); + } + + static void CheckClientPeer(SslTsiTestFixture* ssl_fixture, + tsi_peer* peer) { + ASSERT_NE(ssl_fixture, nullptr); + ASSERT_NE(ssl_fixture->alpn_lib_, nullptr); + ssl_alpn_lib* alpn_lib = ssl_fixture->alpn_lib_; + if (!ssl_fixture->force_client_auth_) { + ASSERT_EQ(peer->property_count, + (alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_OK ? 3 : 2)); + } else { + const tsi_peer_property* property = + CheckBasicAuthenticatedPeerAndGetCommonName(peer); + const char* expected_match = "testclient"; + ASSERT_EQ(memcmp(property->value.data, expected_match, + property->value.length), + 0); + } + tsi_peer_destruct(peer); + } + + static void CheckVerifiedRootCertSubject(const tsi_peer* peer) { + const tsi_peer_property* verified_root_cert_subject = + tsi_peer_get_property_by_name( + peer, TSI_X509_VERIFIED_ROOT_CERT_SUBECT_PEER_PROPERTY); + ASSERT_NE(verified_root_cert_subject, nullptr); + const char* expected_match = + "CN=testca,O=Internet Widgits Pty Ltd,ST=Some-State,C=AU"; + ASSERT_EQ(memcmp(verified_root_cert_subject->value.data, expected_match, + verified_root_cert_subject->value.length), + 0); + } + + static void CheckVerifiedRootCertSubjectUnset(const tsi_peer* peer) { + const tsi_peer_property* verified_root_cert_subject = + tsi_peer_get_property_by_name( + peer, TSI_X509_VERIFIED_ROOT_CERT_SUBECT_PEER_PROPERTY); + ASSERT_EQ(verified_root_cert_subject, nullptr); + } + + static void CheckHandshakerPeers(tsi_test_fixture* fixture) { + SslTsiTestFixture* ssl_fixture = + reinterpret_cast(fixture); + ASSERT_NE(ssl_fixture, nullptr); + ASSERT_NE(ssl_fixture->key_cert_lib_, nullptr); + ssl_key_cert_lib* key_cert_lib = ssl_fixture->key_cert_lib_; + tsi_peer peer; + // In TLS 1.3, the client-side handshake succeeds even if the client sends + // a bad certificate. In such a case, the server would fail the TLS + // handshake and send an alert to the client as the first application data + // message. In TLS 1.2, the client-side handshake will fail if the client + // sends a bad certificate. + // + // For OpenSSL versions < 1.1, TLS 1.3 is not supported, so the + // client-side handshake should succeed precisely when the server-side + // handshake succeeds. + bool expect_server_success = !(key_cert_lib->use_bad_server_cert || + (key_cert_lib->use_bad_client_cert && + ssl_fixture->force_client_auth_)); +#if OPENSSL_VERSION_NUMBER >= 0x10100000 + bool expect_client_success = + ssl_fixture->tls_version_ == tsi_tls_version::TSI_TLS1_2 + ? expect_server_success + : !key_cert_lib->use_bad_server_cert; +#else + bool expect_client_success = expect_server_success; +#endif + if (expect_client_success) { + ASSERT_EQ(tsi_handshaker_result_extract_peer( + ssl_fixture->base_.client_result, &peer), + TSI_OK); + CheckSessionReusage(ssl_fixture, &peer); + CheckAlpn(ssl_fixture, &peer); + CheckSecurityLevel(&peer); + if (ssl_fixture->verify_root_cert_subject_) { + if (!ssl_fixture->session_reused_) { + CheckVerifiedRootCertSubject(&peer); + } else { + CheckVerifiedRootCertSubjectUnset(&peer); + } + } + if (ssl_fixture->server_name_indication_ == nullptr || + strcmp(ssl_fixture->server_name_indication_, + SSL_TSI_TEST_WRONG_SNI) == 0 || + strcmp(ssl_fixture->server_name_indication_, + SSL_TSI_TEST_INVALID_SNI) == 0) { + // Expect server to use default server0.pem. + CheckServer0Peer(&peer); + } else { + // Expect server to use server1.pem. + CheckServer1Peer(&peer); + } + } else { + ASSERT_EQ(ssl_fixture->base_.client_result, nullptr); + } + if (expect_server_success) { + ASSERT_EQ(tsi_handshaker_result_extract_peer( + ssl_fixture->base_.server_result, &peer), + TSI_OK); + CheckSessionReusage(ssl_fixture, &peer); + CheckAlpn(ssl_fixture, &peer); + CheckSecurityLevel(&peer); + if (ssl_fixture->force_client_auth_ && !ssl_fixture->session_reused_) { + CheckVerifiedRootCertSubject(&peer); + } else { + CheckVerifiedRootCertSubjectUnset(&peer); + } + CheckClientPeer(ssl_fixture, &peer); + } else { + ASSERT_EQ(ssl_fixture->base_.server_result, nullptr); + } + } + + static void Destruct(tsi_test_fixture* fixture) { + auto* self = reinterpret_cast(fixture); + delete self; + } + + static tsi_test_fixture_vtable kVtable; + + tsi_test_fixture base_; + ssl_key_cert_lib* key_cert_lib_ = nullptr; + ssl_alpn_lib* alpn_lib_; + bool force_client_auth_; + char* server_name_indication_ = nullptr; + tsi_ssl_session_cache* session_cache_ = nullptr; + bool session_reused_; + const char* session_ticket_key_ = nullptr; + size_t session_ticket_key_size_; + size_t network_bio_buf_size_; + size_t ssl_bio_buf_size_; + bool verify_root_cert_subject_; + tsi_tls_version tls_version_; + bool send_client_ca_list_; + tsi_ssl_server_handshaker_factory* server_handshaker_factory_ = nullptr; + tsi_ssl_client_handshaker_factory* client_handshaker_factory_ = nullptr; + }; + + SslTransportSecurityTest() { grpc_init(); } + + ~SslTransportSecurityTest() override { + DestroyFixture(); + grpc_shutdown(); + } + + void SetUpSslFixture(tsi_tls_version tls_version, bool send_client_ca_list) { + ssl_fixture_ = new SslTsiTestFixture(tls_version, send_client_ca_list); + ssl_tsi_test_fixture_ = ssl_fixture_->GetBaseFixture(); + fixture_destroyed = false; + } -void ssl_tsi_test_do_handshake_tiny_handshake_buffer() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_tiny_handshake_buffer"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - fixture->handshake_buffer_size = TSI_TEST_TINY_HANDSHAKE_BUFFER_SIZE; + void DoHandshake() { tsi_test_do_handshake(ssl_tsi_test_fixture_); } + + void DoRoundTrip() { tsi_test_do_round_trip(ssl_tsi_test_fixture_); } + + void DestroyFixture() { + if (fixture_destroyed) { + return; + } + tsi_test_fixture_destroy(ssl_tsi_test_fixture_); + fixture_destroyed = true; + } + + tsi_test_fixture* ssl_tsi_test_fixture_; + SslTsiTestFixture* ssl_fixture_; + bool fixture_destroyed = true; +}; + +tsi_test_fixture_vtable SslTransportSecurityTest::SslTsiTestFixture::kVtable = { + SslTransportSecurityTest::SslTsiTestFixture::SetupHandshakers, + SslTransportSecurityTest::SslTsiTestFixture::CheckHandshakerPeers, + SslTransportSecurityTest::SslTsiTestFixture::Destruct}; + +INSTANTIATE_TEST_SUITE_P( + SslTestGroup, SslTransportSecurityTest, + testing::Combine(testing::Values(TSI_TLS1_2, TSI_TLS1_3), + testing::Values(true, false)), + [](const testing::TestParamInfo& + info) { + return absl::StrCat( + std::get<0>(info.param) == TSI_TLS1_2 ? "tls_12" : "tls_13", "_", + std::get<1>(info.param) ? "send_client_ca_list" + : "no_send_client_ca_list"); + }); + +TEST_P(SslTransportSecurityTest, DoHandshakeTinyHandshakeBuffer) { + LOG(INFO) << "ssl_tsi_test_do_handshake_tiny_handshake_buffer"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + ssl_tsi_test_fixture_->handshake_buffer_size = + TSI_TEST_TINY_HANDSHAKE_BUFFER_SIZE; // Handshake buffer is too small to hold both handshake messages and the // unused bytes. - fixture->test_unused_bytes = false; - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); + ssl_tsi_test_fixture_->test_unused_bytes = false; + DoHandshake(); } -void ssl_tsi_test_do_handshake_small_handshake_buffer() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_small_handshake_buffer"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - fixture->handshake_buffer_size = TSI_TEST_SMALL_HANDSHAKE_BUFFER_SIZE; - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); +TEST_P(SslTransportSecurityTest, DoHandshakeSmallHandshakeBuffer) { + LOG(INFO) << "ssl_tsi_test_do_handshake_small_handshake_buffer"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + ssl_tsi_test_fixture_->handshake_buffer_size = + TSI_TEST_SMALL_HANDSHAKE_BUFFER_SIZE; + DoHandshake(); } -void ssl_tsi_test_do_handshake() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); +TEST_P(SslTransportSecurityTest, DoHandshake) { + LOG(INFO) << "ssl_tsi_test_do_handshake"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + DoHandshake(); } -void ssl_tsi_test_do_handshake_with_root_store() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_with_root_store"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->key_cert_lib->use_root_store = true; - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); +TEST_P(SslTransportSecurityTest, DoHandshakeWithRootStore) { + LOG(INFO) << "ssl_tsi_test_do_handshake_with_root_store"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + ssl_fixture_->MutableKeyCertLib()->use_root_store = true; + DoHandshake(); } -void ssl_tsi_test_do_handshake_skipping_server_certificate_verification() { - gpr_log(GPR_INFO, - "ssl_tsi_test_do_handshake_skipping_server_certificate_verification"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->verify_root_cert_subject = false; - ssl_fixture->key_cert_lib->use_root_store = false; - ssl_fixture->key_cert_lib->use_pem_root_certs = false; - ssl_fixture->key_cert_lib->skip_server_certificate_verification = true; - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); +// TODO(gregorycooke) - failing with OpenSSL1.0.2 +#if OPENSSL_VERSION_NUMBER >= 0x10100000 +TEST_P(SslTransportSecurityTest, + DoHandshakeSkippingServerCertificateVerification) { + LOG(INFO) + << "ssl_tsi_test_do_handshake_skipping_server_certificate_verification"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + ssl_fixture_->SetVerifyRootCertSubject(false); + ssl_key_cert_lib* key_cert_lib = ssl_fixture_->MutableKeyCertLib(); + key_cert_lib->use_root_store = false; + key_cert_lib->use_pem_root_certs = false; + key_cert_lib->skip_server_certificate_verification = true; + DoHandshake(); } +#endif -void ssl_tsi_test_do_handshake_with_large_server_handshake_messages( - const std::string& trust_bundle) { - gpr_log(GPR_INFO, - "ssl_tsi_test_do_handshake_with_large_server_handshake_messages"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); +TEST_P(SslTransportSecurityTest, DoHandshakeWithLargeServerHandshakeMessages) { + LOG(INFO) << "ssl_tsi_test_do_handshake_with_large_server_handshake_messages"; + std::string trust_bundle = GenerateTrustBundle(); + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); // Force the test to read more handshake bytes from the peer than we have room // for in the BIO. The default BIO buffer size is 17kB. - fixture->handshake_buffer_size = 18000; - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); + ssl_tsi_test_fixture_->handshake_buffer_size = 18000; // Make a copy of the root cert and free the original. - std::string root_cert(ssl_fixture->key_cert_lib->root_cert); - gpr_free(ssl_fixture->key_cert_lib->root_cert); - ssl_fixture->key_cert_lib->root_cert = nullptr; + ssl_key_cert_lib* key_cert_lib = ssl_fixture_->MutableKeyCertLib(); + std::string root_cert(key_cert_lib->root_cert); + gpr_free(key_cert_lib->root_cert); + key_cert_lib->root_cert = nullptr; // Create a new root store, consisting of the root cert that is actually // needed and 200 self-signed certs. std::string effective_trust_bundle = absl::StrCat(root_cert, trust_bundle); - tsi_ssl_root_certs_store_destroy(ssl_fixture->key_cert_lib->root_store); - ssl_fixture->key_cert_lib->root_cert = - const_cast(effective_trust_bundle.c_str()); - ssl_fixture->key_cert_lib->root_store = + tsi_ssl_root_certs_store_destroy(key_cert_lib->root_store); + key_cert_lib->root_cert = const_cast(effective_trust_bundle.c_str()); + key_cert_lib->root_store = tsi_ssl_root_certs_store_create(effective_trust_bundle.c_str()); - ssl_fixture->key_cert_lib->use_root_store = true; - ssl_fixture->force_client_auth = true; - tsi_test_do_handshake(fixture); + key_cert_lib->use_root_store = true; + ssl_fixture_->SetForceClientAuth(true); + DoHandshake(); // Overwrite the root_cert pointer so that tsi_test_fixture_destroy does not // try to gpr_free it. - ssl_fixture->key_cert_lib->root_cert = nullptr; - tsi_test_fixture_destroy(fixture); + key_cert_lib->root_cert = nullptr; } -void ssl_tsi_test_do_handshake_with_client_authentication() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_with_client_authentication"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->force_client_auth = true; - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); +TEST_P(SslTransportSecurityTest, DoHandshakeWithClientAuthentication) { + LOG(INFO) << "ssl_tsi_test_do_handshake_with_client_authentication"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + ssl_fixture_->SetForceClientAuth(true); + DoHandshake(); } -void ssl_tsi_test_do_handshake_with_client_authentication_and_root_store() { - gpr_log( - GPR_INFO, - "ssl_tsi_test_do_handshake_with_client_authentication_and_root_store"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->force_client_auth = true; - ssl_fixture->key_cert_lib->use_root_store = true; - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); +TEST_P(SslTransportSecurityTest, + DoHandshakeWithClientAuthenticationAndRootStore) { + LOG(INFO) + << "ssl_tsi_test_do_handshake_with_client_authentication_and_root_store"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + ssl_fixture_->SetForceClientAuth(true); + ssl_fixture_->MutableKeyCertLib()->use_root_store = true; + DoHandshake(); } -void ssl_tsi_test_do_handshake_with_server_name_indication_exact_domain() { - gpr_log(GPR_INFO, - "ssl_tsi_test_do_handshake_with_server_name_indication_exact_domain"); +TEST_P(SslTransportSecurityTest, + DoHandshakeWithServerNameIndicationExactDomain) { + LOG(INFO) + << "ssl_tsi_test_do_handshake_with_server_name_indication_exact_domain"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); // server1 cert contains "waterzooi.test.google.be" in SAN. - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->server_name_indication = - const_cast("waterzooi.test.google.be"); - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); + ssl_fixture_->SetServerNameIndication( + const_cast("waterzooi.test.google.be")); + DoHandshake(); } -void ssl_tsi_test_do_handshake_with_server_name_indication_wild_star_domain() { - gpr_log( - GPR_INFO, - "ssl_tsi_test_do_handshake_with_server_name_indication_wild_star_domain"); +TEST_P(SslTransportSecurityTest, + DoHandshakeWithServerNameIndicationWildStarDomain) { + LOG(INFO) << "ssl_tsi_test_do_handshake_with_server_name_indication_wild_" + "star_domain"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); // server1 cert contains "*.test.google.fr" in SAN. - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->server_name_indication = - const_cast("juju.test.google.fr"); - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); + ssl_fixture_->SetServerNameIndication( + const_cast("juju.test.google.fr")); + DoHandshake(); } -void ssl_tsi_test_do_handshake_with_wrong_server_name_indication() { - gpr_log(GPR_INFO, - "ssl_tsi_test_do_handshake_with_wrong_server_name_indication"); +TEST_P(SslTransportSecurityTest, DoHandshakeWithWrongServerNameIndication) { + LOG(INFO) << "ssl_tsi_test_do_handshake_with_wrong_server_name_indication"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); // server certs do not contain "test.google.cn". - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->server_name_indication = - const_cast(SSL_TSI_TEST_WRONG_SNI); - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); + ssl_fixture_->SetServerNameIndication( + const_cast(SSL_TSI_TEST_WRONG_SNI)); + DoHandshake(); } -void ssl_tsi_test_do_handshake_with_invalid_and_ignored_server_name_indication() { - gpr_log(GPR_INFO, - "ssl_tsi_test_do_handshake_with_wrong_server_name_indication"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); +TEST_P(SslTransportSecurityTest, + DoHandshakeWithInvalidAndIgnoredServerNameIndication) { + LOG(INFO) << "ssl_tsi_test_do_handshake_with_invalid_and_ignored_server_name_" + "indication"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); // SNI that's an IP address will be ignored. - ssl_fixture->server_name_indication = - const_cast(SSL_TSI_TEST_INVALID_SNI); - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); + ssl_fixture_->SetServerNameIndication( + const_cast(SSL_TSI_TEST_INVALID_SNI)); + DoHandshake(); } -void ssl_tsi_test_do_handshake_with_bad_server_cert() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_with_bad_server_cert"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->key_cert_lib->use_bad_server_cert = true; - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); +TEST_P(SslTransportSecurityTest, DoHandshakeWithBadServerCert) { + LOG(INFO) << "ssl_tsi_test_do_handshake_with_bad_server_cert"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + ssl_fixture_->MutableKeyCertLib()->use_bad_server_cert = true; + DoHandshake(); } -void ssl_tsi_test_do_handshake_with_bad_client_cert() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_with_bad_client_cert"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->key_cert_lib->use_bad_client_cert = true; - ssl_fixture->force_client_auth = true; - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); +TEST_P(SslTransportSecurityTest, DoHandshakeWithBadClientCert) { + LOG(INFO) << "ssl_tsi_test_do_handshake_with_bad_client_cert"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + ssl_fixture_->MutableKeyCertLib()->use_bad_client_cert = true; + ssl_fixture_->SetForceClientAuth(true); + DoHandshake(); } -void ssl_tsi_test_do_handshake_alpn_client_no_server() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_alpn_client_no_server"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->alpn_lib->alpn_mode = ALPN_CLIENT_NO_SERVER; - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); -} - -void ssl_tsi_test_do_handshake_alpn_server_no_client() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_alpn_server_no_client"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->alpn_lib->alpn_mode = ALPN_SERVER_NO_CLIENT; - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); -} - -void ssl_tsi_test_do_handshake_alpn_client_server_mismatch() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_alpn_server_no_client"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->alpn_lib->alpn_mode = ALPN_CLIENT_SERVER_MISMATCH; - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); +#ifdef OPENSSL_IS_BORINGSSL +// BoringSSL and OpenSSL have different behaviors on mismatched ALPN. +TEST_P(SslTransportSecurityTest, DoHandshakeAlpnClientNoServer) { + LOG(INFO) << "ssl_tsi_test_do_handshake_alpn_client_no_server"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + ssl_fixture_->SetAlpnMode(ALPN_CLIENT_NO_SERVER); + DoHandshake(); } -void ssl_tsi_test_do_handshake_alpn_client_server_ok() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_alpn_client_server_ok"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->alpn_lib->alpn_mode = ALPN_CLIENT_SERVER_OK; - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); +TEST_P(SslTransportSecurityTest, DoHandshakeAlpnClientServerMismatch) { + LOG(INFO) << "ssl_tsi_test_do_handshake_alpn_client_server_mismatch"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + ssl_fixture_->SetAlpnMode(ALPN_CLIENT_SERVER_MISMATCH); + DoHandshake(); } -void ssl_tsi_test_do_round_trip_for_all_configs() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_round_trip_for_all_configs"); +TEST_P(SslTransportSecurityTest, DoRoundTripForAllConfigs) { + LOG(INFO) << "ssl_tsi_test_do_round_trip_for_all_configs"; unsigned int* bit_array = static_cast( gpr_zalloc(sizeof(unsigned int) * TSI_TEST_NUM_OF_ARGUMENTS)); const unsigned int mask = 1U << (TSI_TEST_NUM_OF_ARGUMENTS - 1); @@ -849,32 +901,31 @@ void ssl_tsi_test_do_round_trip_for_all_configs() { bit_array[ind] = (v & mask) ? 1 : 0; v <<= 1; } - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - tsi_test_frame_protector_config_destroy(ssl_fixture->base.config); - ssl_fixture->base.config = tsi_test_frame_protector_config_create( + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + tsi_test_frame_protector_config_destroy(ssl_tsi_test_fixture_->config); + ssl_tsi_test_fixture_->config = tsi_test_frame_protector_config_create( bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4], bit_array[5], bit_array[6]); - tsi_test_do_round_trip(&ssl_fixture->base); - tsi_test_fixture_destroy(fixture); + DoRoundTrip(); + DestroyFixture(); } gpr_free(bit_array); } -void ssl_tsi_test_do_round_trip_with_error_on_stack() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_round_trip_with_error_on_stack"); +TEST_P(SslTransportSecurityTest, DoRoundTripWithErrorOnStack) { + LOG(INFO) << "ssl_tsi_test_do_round_trip_with_error_on_stack"; // Invoke an SSL function that causes an error, and ensure the error // makes it to the stack. ASSERT_FALSE(EC_KEY_new_by_curve_name(NID_rsa)); ASSERT_NE(ERR_peek_error(), 0); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - tsi_test_do_round_trip(fixture); - tsi_test_fixture_destroy(fixture); + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + DoRoundTrip(); } -void ssl_tsi_test_do_round_trip_odd_buffer_size() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_round_trip_odd_buffer_size"); +TEST_P(SslTransportSecurityTest, DoRoundTripOddBufferSize) { + LOG(INFO) << "ssl_tsi_test_do_round_trip_odd_buffer_size"; const size_t odd_sizes[] = {1025, 2051, 4103, 8207, 16409}; size_t size = sizeof(odd_sizes) / sizeof(size_t); // 1. This test is extremely slow under MSAN and TSAN. @@ -890,14 +941,14 @@ void ssl_tsi_test_do_round_trip_odd_buffer_size() { for (size_t ind3 = 0; ind3 < size; ind3++) { for (size_t ind4 = 0; ind4 < size; ind4++) { for (size_t ind5 = 0; ind5 < size; ind5++) { - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); tsi_test_frame_protector_config_set_buffer_size( - ssl_fixture->base.config, odd_sizes[ind1], odd_sizes[ind2], - odd_sizes[ind3], odd_sizes[ind4], odd_sizes[ind5]); - tsi_test_do_round_trip(&ssl_fixture->base); - tsi_test_fixture_destroy(fixture); + ssl_fixture_->GetBaseFixture()->config, odd_sizes[ind1], + odd_sizes[ind2], odd_sizes[ind3], odd_sizes[ind4], + odd_sizes[ind5]); + DoRoundTrip(); + DestroyFixture(); } } } @@ -905,24 +956,23 @@ void ssl_tsi_test_do_round_trip_odd_buffer_size() { } } -void ssl_tsi_test_do_handshake_session_cache() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_session_cache"); +TEST_P(SslTransportSecurityTest, DoHandshakeSessionCache) { + LOG(INFO) << "ssl_tsi_test_do_handshake_session_cache"; tsi_ssl_session_cache* session_cache = tsi_ssl_session_cache_create_lru(16); char session_ticket_key[kSessionTicketEncryptionKeySize]; - auto do_handshake = [&session_ticket_key, + auto do_handshake = [this, &session_ticket_key, &session_cache](bool session_reused) { - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->server_name_indication = - const_cast("waterzooi.test.google.be"); - ssl_fixture->session_ticket_key = session_ticket_key; - ssl_fixture->session_ticket_key_size = sizeof(session_ticket_key); + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + ssl_fixture_->SetServerNameIndication( + const_cast("waterzooi.test.google.be")); + ssl_fixture_->SetSessionTicketKey(session_ticket_key, + sizeof(session_ticket_key)); tsi_ssl_session_cache_ref(session_cache); - ssl_fixture->session_cache = session_cache; - ssl_fixture->session_reused = session_reused; - tsi_test_do_round_trip(&ssl_fixture->base); - tsi_test_fixture_destroy(fixture); + ssl_fixture_->SetSessionCache(session_cache); + ssl_fixture_->SetSessionReused(session_reused); + DoRoundTrip(); + DestroyFixture(); }; memset(session_ticket_key, 'a', sizeof(session_ticket_key)); do_handshake(false); @@ -937,19 +987,35 @@ void ssl_tsi_test_do_handshake_session_cache() { do_handshake(true); tsi_ssl_session_cache_unref(session_cache); } +#endif // OPENSSL_IS_BORINGSSL + +TEST_P(SslTransportSecurityTest, DoHandshakeAlpnServerNoClient) { + LOG(INFO) << "ssl_tsi_test_do_handshake_alpn_server_no_client"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + ssl_fixture_->SetAlpnMode(ALPN_SERVER_NO_CLIENT); + DoHandshake(); +} -void ssl_tsi_test_do_handshake_with_intermediate_ca() { - gpr_log( - GPR_INFO, - "ssl_tsi_test_do_handshake_with_client_authentication_and_root_store"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); - ssl_fixture->force_client_auth = true; - ssl_fixture->key_cert_lib->use_root_store = true; - ssl_fixture->key_cert_lib->use_cert_signed_by_intermediate_ca = true; - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); +TEST_P(SslTransportSecurityTest, DoHandshakeAlpnClientServerOk) { + LOG(INFO) << "ssl_tsi_test_do_handshake_alpn_client_server_ok"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); + ssl_fixture_->SetAlpnMode(ALPN_CLIENT_SERVER_OK); + DoHandshake(); +} + +TEST_P(SslTransportSecurityTest, DoHandshakeWithCustomBioPair) { + LOG(INFO) << "ssl_tsi_test_do_handshake_with_custom_bio_pair"; + SetUpSslFixture(/*tls_version=*/std::get<0>(GetParam()), + /*send_client_ca_list=*/std::get<1>(GetParam())); +#if OPENSSL_VERSION_NUMBER >= 0x10100000 + ssl_fixture_->SetBioBufSizes( + /*network_bio_buf_size=*/TSI_TEST_DEFAULT_BUFFER_SIZE, + /*ssl_bio_buf_size=*/256); +#endif + ssl_fixture_->SetForceClientAuth(true); + DoHandshake(); } static const tsi_ssl_handshaker_factory_vtable* original_vtable; @@ -967,7 +1033,7 @@ static void ssl_tsi_test_handshaker_factory_destructor( static tsi_ssl_handshaker_factory_vtable test_handshaker_factory_vtable = { ssl_tsi_test_handshaker_factory_destructor}; -void test_tsi_ssl_client_handshaker_factory_refcounting() { +TEST(SslTransportSecurityTest, TestClientHandshakerFactoryRefcounting) { int i; char* cert_chain = load_file(SSL_TSI_TEST_CREDENTIALS_DIR "client.pem"); @@ -1012,7 +1078,7 @@ void test_tsi_ssl_client_handshaker_factory_refcounting() { gpr_free(cert_chain); } -void test_tsi_ssl_server_handshaker_factory_refcounting() { +TEST(SslTransportSecurityTest, TestServerHandshakerFactoryRefcounting) { int i; tsi_ssl_server_handshaker_factory* server_handshaker_factory; tsi_handshaker* handshaker[3]; @@ -1059,7 +1125,7 @@ void test_tsi_ssl_server_handshaker_factory_refcounting() { // Attempting to create a handshaker factory with invalid parameters should fail // but not crash. -void test_tsi_ssl_client_handshaker_factory_bad_params() { +TEST(SslTransportSecurityTest, TestClientHandshakerFactoryBadParams) { const char* cert_chain = "This is not a valid PEM file."; tsi_ssl_client_handshaker_factory* client_handshaker_factory; @@ -1071,15 +1137,8 @@ void test_tsi_ssl_client_handshaker_factory_bad_params() { tsi_ssl_client_handshaker_factory_unref(client_handshaker_factory); } -void ssl_tsi_test_handshaker_factory_internals() { - gpr_log(GPR_INFO, "ssl_tsi_test_handshaker_factory_internals"); - test_tsi_ssl_client_handshaker_factory_refcounting(); - test_tsi_ssl_server_handshaker_factory_refcounting(); - test_tsi_ssl_client_handshaker_factory_bad_params(); -} - -void ssl_tsi_test_duplicate_root_certificates() { - gpr_log(GPR_INFO, "ssl_tsi_test_duplicate_root_certificates"); +TEST(SslTransportSecurityTest, DuplicateRootCertificates) { + LOG(INFO) << "ssl_tsi_test_duplicate_root_certificates"; char* root_cert = load_file(SSL_TSI_TEST_CREDENTIALS_DIR "ca.pem"); char* dup_root_cert = static_cast( gpr_zalloc(sizeof(char) * (strlen(root_cert) * 2 + 1))); @@ -1094,8 +1153,8 @@ void ssl_tsi_test_duplicate_root_certificates() { gpr_free(dup_root_cert); } -void ssl_tsi_test_extract_x509_subject_names() { - gpr_log(GPR_INFO, "ssl_tsi_test_extract_x509_subject_names"); +TEST(SslTransportSecurityTest, ExtractX509SubjectNames) { + LOG(INFO) << "ssl_tsi_test_extract_x509_subject_names"; char* cert = load_file(SSL_TSI_TEST_CREDENTIALS_DIR "multi-domain.pem"); tsi_peer peer; ASSERT_EQ(tsi_ssl_extract_x509_subject_names_from_pem_cert(cert, &peer), @@ -1198,8 +1257,8 @@ void ssl_tsi_test_extract_x509_subject_names() { tsi_peer_destruct(&peer); } -void ssl_tsi_test_extract_cert_chain() { - gpr_log(GPR_INFO, "ssl_tsi_test_extract_cert_chain"); +TEST(SslTransportSecurityTest, ExtractCertChain) { + LOG(INFO) << "ssl_tsi_test_extract_cert_chain"; char* cert = load_file(SSL_TSI_TEST_CREDENTIALS_DIR "server1.pem"); char* ca = load_file(SSL_TSI_TEST_CREDENTIALS_DIR "ca.pem"); char* chain = static_cast( @@ -1238,74 +1297,6 @@ void ssl_tsi_test_extract_cert_chain() { sk_X509_pop_free(cert_chain, X509_free); } -void ssl_tsi_test_do_handshake_with_custom_bio_pair() { - gpr_log(GPR_INFO, "ssl_tsi_test_do_handshake_with_custom_bio_pair"); - tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = - reinterpret_cast(fixture); -#if OPENSSL_VERSION_NUMBER >= 0x10100000 - ssl_fixture->network_bio_buf_size = TSI_TEST_DEFAULT_BUFFER_SIZE; - ssl_fixture->ssl_bio_buf_size = 256; -#endif - ssl_fixture->force_client_auth = true; - tsi_test_do_handshake(fixture); - tsi_test_fixture_destroy(fixture); -} - -TEST(SslTransportSecurityTest, MainTest) { - grpc_init(); - std::string trust_bundle = GenerateTrustBundle(); - const size_t number_tls_versions = 2; - const tsi_tls_version tls_versions[] = {tsi_tls_version::TSI_TLS1_2, - tsi_tls_version::TSI_TLS1_3}; - for (size_t i = 0; i < number_tls_versions; i++) { - // Set the TLS version to be used in the tests. - test_tls_version = tls_versions[i]; - for (bool send_client_ca_list : {true, false}) { - test_send_client_ca_list = send_client_ca_list; - ssl_tsi_test_do_handshake_tiny_handshake_buffer(); - ssl_tsi_test_do_handshake_small_handshake_buffer(); - ssl_tsi_test_do_handshake(); - ssl_tsi_test_do_handshake_with_root_store(); - ssl_tsi_test_do_handshake_with_large_server_handshake_messages( - trust_bundle); - ssl_tsi_test_do_handshake_with_client_authentication(); - ssl_tsi_test_do_handshake_with_client_authentication_and_root_store(); - ssl_tsi_test_do_handshake_with_server_name_indication_exact_domain(); - ssl_tsi_test_do_handshake_with_server_name_indication_wild_star_domain(); - ssl_tsi_test_do_handshake_with_invalid_and_ignored_server_name_indication(); - ssl_tsi_test_do_handshake_with_wrong_server_name_indication(); - ssl_tsi_test_do_handshake_with_bad_server_cert(); - ssl_tsi_test_do_handshake_with_bad_client_cert(); -// TODO(gregorycooke) - failing with OpenSSL1.0.2 -#if OPENSSL_VERSION_NUMBER >= 0x10100000 - ssl_tsi_test_do_handshake_skipping_server_certificate_verification(); -#endif // OPENSSL_VERSION_NUMBER >= 0x10100000 - -#ifdef OPENSSL_IS_BORINGSSL - // BoringSSL and OpenSSL have different behaviors on mismatched ALPN. - ssl_tsi_test_do_handshake_alpn_client_no_server(); - ssl_tsi_test_do_handshake_alpn_client_server_mismatch(); - // These tests fail with openssl3 and openssl111 currently but not - // boringssl - ssl_tsi_test_do_handshake_session_cache(); - ssl_tsi_test_do_round_trip_for_all_configs(); - ssl_tsi_test_do_round_trip_with_error_on_stack(); - ssl_tsi_test_do_round_trip_odd_buffer_size(); -#endif - ssl_tsi_test_do_handshake_alpn_server_no_client(); - ssl_tsi_test_do_handshake_alpn_client_server_ok(); - ssl_tsi_test_handshaker_factory_internals(); - ssl_tsi_test_duplicate_root_certificates(); - ssl_tsi_test_extract_x509_subject_names(); - ssl_tsi_test_extract_cert_chain(); - ssl_tsi_test_do_handshake_with_custom_bio_pair(); - ssl_tsi_test_do_handshake_with_intermediate_ca(); - } - } - grpc_shutdown(); -} - int main(int argc, char** argv) { grpc::testing::TestEnvironment env(&argc, argv); ::testing::InitGoogleTest(&argc, argv); diff --git a/test/core/tsi/transport_security_test.cc b/test/core/tsi/transport_security_test.cc index 277b435c57d..b541ab12f3f 100644 --- a/test/core/tsi/transport_security_test.cc +++ b/test/core/tsi/transport_security_test.cc @@ -31,11 +31,11 @@ #include #include -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/tsi/fake_transport_security.h" #include "src/core/tsi/ssl_transport_security.h" +#include "src/core/util/string.h" +#include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" typedef struct { diff --git a/test/core/gpr/BUILD b/test/core/util/BUILD similarity index 95% rename from test/core/gpr/BUILD rename to test/core/util/BUILD index f6d8b4e7ded..728ef6bd167 100644 --- a/test/core/gpr/BUILD +++ b/test/core/util/BUILD @@ -16,7 +16,7 @@ load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package") licenses(["notice"]) -grpc_package(name = "test/core/gpr") +grpc_package(name = "test/core/util") grpc_cc_test( name = "alloc_test", @@ -47,7 +47,10 @@ grpc_cc_test( grpc_cc_test( name = "env_test", srcs = ["env_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:log", + "gtest", + ], language = "C++", uses_event_engine = False, uses_polling = False, @@ -62,6 +65,7 @@ grpc_cc_test( srcs = ["log_test.cc"], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], language = "C++", diff --git a/test/core/gpr/alloc_test.cc b/test/core/util/alloc_test.cc similarity index 100% rename from test/core/gpr/alloc_test.cc rename to test/core/util/alloc_test.cc diff --git a/test/core/gpr/cpu_test.cc b/test/core/util/cpu_test.cc similarity index 100% rename from test/core/gpr/cpu_test.cc rename to test/core/util/cpu_test.cc diff --git a/test/core/gpr/env_test.cc b/test/core/util/env_test.cc similarity index 100% rename from test/core/gpr/env_test.cc rename to test/core/util/env_test.cc diff --git a/test/core/gpr/log_test.cc b/test/core/util/log_test.cc similarity index 100% rename from test/core/gpr/log_test.cc rename to test/core/util/log_test.cc diff --git a/test/core/gpr/spinlock_test.cc b/test/core/util/spinlock_test.cc similarity index 99% rename from test/core/gpr/spinlock_test.cc rename to test/core/util/spinlock_test.cc index 12de438a26e..6e8be4a853e 100644 --- a/test/core/gpr/spinlock_test.cc +++ b/test/core/util/spinlock_test.cc @@ -18,7 +18,7 @@ // Test of gpr spin-lock support. -#include "src/core/lib/gpr/spinlock.h" +#include "src/core/util/spinlock.h" #include #include diff --git a/test/core/gpr/string_test.cc b/test/core/util/string_test.cc similarity index 99% rename from test/core/gpr/string_test.cc rename to test/core/util/string_test.cc index 1a218c12973..4ca644d8090 100644 --- a/test/core/gpr/string_test.cc +++ b/test/core/util/string_test.cc @@ -16,7 +16,7 @@ // // -#include "src/core/lib/gpr/string.h" +#include "src/core/util/string.h" #include #include diff --git a/test/core/gpr/sync_test.cc b/test/core/util/sync_test.cc similarity index 100% rename from test/core/gpr/sync_test.cc rename to test/core/util/sync_test.cc diff --git a/test/core/gpr/time_test.cc b/test/core/util/time_test.cc similarity index 100% rename from test/core/gpr/time_test.cc rename to test/core/util/time_test.cc diff --git a/test/core/gpr/useful_test.cc b/test/core/util/useful_test.cc similarity index 98% rename from test/core/gpr/useful_test.cc rename to test/core/util/useful_test.cc index b203226dbd4..b9c2f696212 100644 --- a/test/core/gpr/useful_test.cc +++ b/test/core/util/useful_test.cc @@ -16,7 +16,7 @@ // // -#include "src/core/lib/gpr/useful.h" +#include "src/core/util/useful.h" #include diff --git a/test/core/xds/BUILD b/test/core/xds/BUILD index 975cb4d819e..a4e133970e7 100644 --- a/test/core/xds/BUILD +++ b/test/core/xds/BUILD @@ -136,6 +136,7 @@ grpc_cc_library( hdrs = ["xds_transport_fake.h"], external_deps = [ "absl/log:check", + "absl/log:log", "absl/strings", "absl/types:optional", ], @@ -182,6 +183,7 @@ grpc_proto_fuzzer( name = "xds_client_fuzzer", srcs = ["xds_client_fuzzer.cc"], corpus = "xds_client_corpora", + external_deps = ["absl/log:log"], language = "C++", proto = "xds_client_fuzzer.proto", proto_deps = [ diff --git a/test/core/xds/xds_bootstrap_test.cc b/test/core/xds/xds_bootstrap_test.cc index 1145be71343..295da0298fb 100644 --- a/test/core/xds/xds_bootstrap_test.cc +++ b/test/core/xds/xds_bootstrap_test.cc @@ -36,7 +36,6 @@ #include #include "src/core/lib/config/core_configuration.h" -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/validation_errors.h" @@ -47,6 +46,7 @@ #include "src/core/lib/security/certificate_provider/certificate_provider_factory.h" #include "src/core/lib/security/credentials/channel_creds_registry.h" #include "src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h" +#include "src/core/util/tmpfile.h" #include "src/core/xds/grpc/certificate_provider_store.h" #include "src/core/xds/grpc/xds_bootstrap_grpc.h" #include "test/core/test_util/scoped_env_var.h" diff --git a/test/core/xds/xds_certificate_provider_test.cc b/test/core/xds/xds_certificate_provider_test.cc index caf950f74c4..a005b1d0f6c 100644 --- a/test/core/xds/xds_certificate_provider_test.cc +++ b/test/core/xds/xds_certificate_provider_test.cc @@ -25,10 +25,10 @@ #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/status_helper.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/security/security_connector/ssl_utils.h" +#include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" #include "test/core/test_util/tls_utils.h" diff --git a/test/core/xds/xds_client_fuzzer.cc b/test/core/xds/xds_client_fuzzer.cc index 4653d545713..f7b3e2fc48e 100644 --- a/test/core/xds/xds_client_fuzzer.cc +++ b/test/core/xds/xds_client_fuzzer.cc @@ -20,6 +20,7 @@ #include #include +#include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" @@ -28,7 +29,6 @@ #include "absl/types/optional.h" #include -#include #include "src/core/lib/event_engine/default_event_engine.h" #include "src/core/lib/gprpp/orphanable.h" @@ -53,8 +53,7 @@ class Fuzzer { explicit Fuzzer(absl::string_view bootstrap_json) { auto bootstrap = GrpcXdsBootstrap::Create(bootstrap_json); if (!bootstrap.ok()) { - gpr_log(GPR_ERROR, "error creating bootstrap: %s", - bootstrap.status().ToString().c_str()); + LOG(ERROR) << "error creating bootstrap: " << bootstrap.status(); // Leave xds_client_ unset, so Act() will be a no-op. return; } @@ -122,20 +121,18 @@ class Fuzzer { [](const testing::XdsClientTestPeer::ResourceCountLabels& labels, uint64_t count) { - gpr_log(GPR_INFO, - "xds_authority=\"%s\", resource_type=\"%s\", " - "cache_state=\"%s\" count=%" PRIu64, - std::string(labels.xds_authority).c_str(), - std::string(labels.resource_type).c_str(), - std::string(labels.cache_state).c_str(), count); + LOG(INFO) << "xds_authority=\"" << labels.xds_authority + << "\", resource_type=\"" << labels.resource_type + << "\", cache_state=\"" << labels.cache_state + << "\" count=" << count; }); break; case xds_client_fuzzer::Action::kReportServerConnections: testing::XdsClientTestPeer(xds_client_.get()) .TestReportServerConnections( [](absl::string_view xds_server, bool connected) { - gpr_log(GPR_INFO, "xds_server=\"%s\" connected=%d", - std::string(xds_server).c_str(), connected); + LOG(INFO) << "xds_server=\"" << xds_server + << "\" connected=" << connected; }); break; case xds_client_fuzzer::Action::kTriggerConnectionFailure: @@ -174,26 +171,24 @@ class Fuzzer { std::shared_ptr resource, RefCountedPtr /* read_delay_handle */) override { - gpr_log(GPR_INFO, "==> OnResourceChanged(%s %s): %s", - std::string(ResourceType::Get()->type_url()).c_str(), - resource_name_.c_str(), resource->ToString().c_str()); + LOG(INFO) << "==> OnResourceChanged(" << ResourceType::Get()->type_url() + << " " << resource_name_ << "): " << resource->ToString(); } void OnError( absl::Status status, RefCountedPtr /* read_delay_handle */) override { - gpr_log(GPR_INFO, "==> OnError(%s %s): %s", - std::string(ResourceType::Get()->type_url()).c_str(), - resource_name_.c_str(), status.ToString().c_str()); + LOG(INFO) << "==> OnError(" << ResourceType::Get()->type_url() << " " + << resource_name_ << "): " << status; } void OnResourceDoesNotExist( RefCountedPtr /* read_delay_handle */) override { - gpr_log(GPR_INFO, "==> OnResourceDoesNotExist(%s %s)", - std::string(ResourceType::Get()->type_url()).c_str(), - resource_name_.c_str()); + LOG(INFO) << "==> OnResourceDoesNotExist(" + << ResourceType::Get()->type_url() << " " << resource_name_ + << ")"; } private: @@ -208,9 +203,9 @@ class Fuzzer { template void StartWatch(std::map>* watchers, std::string resource_name) { - gpr_log(GPR_INFO, "### StartWatch(%s %s)", - std::string(WatcherType::ResourceType::Get()->type_url()).c_str(), - resource_name.c_str()); + LOG(INFO) << "### StartWatch(" + << WatcherType::ResourceType::Get()->type_url() << " " + << resource_name << ")"; auto watcher = MakeRefCounted(resource_name); (*watchers)[resource_name].insert(watcher.get()); WatcherType::ResourceType::Get()->StartWatch( @@ -220,9 +215,9 @@ class Fuzzer { template void StopWatch(std::map>* watchers, std::string resource_name) { - gpr_log(GPR_INFO, "### StopWatch(%s %s)", - std::string(WatcherType::ResourceType::Get()->type_url()).c_str(), - resource_name.c_str()); + LOG(INFO) << "### StopWatch(" + << WatcherType::ResourceType::Get()->type_url() << " " + << resource_name << ")"; auto& watchers_set = (*watchers)[resource_name]; auto it = watchers_set.begin(); if (it == watchers_set.end()) return; @@ -252,8 +247,8 @@ class Fuzzer { void TriggerConnectionFailure(const std::string& authority, absl::Status status) { - gpr_log(GPR_INFO, "### TriggerConnectionFailure(%s): %s", authority.c_str(), - status.ToString().c_str()); + LOG(INFO) << "### TriggerConnectionFailure(" << authority + << "): " << status; const auto* xds_server = GetServer(authority); if (xds_server == nullptr) return; transport_factory_->TriggerConnectionFailure(*xds_server, @@ -290,14 +285,14 @@ class Fuzzer { void ReadMessageFromClient(const xds_client_fuzzer::StreamId& stream_id, bool ok) { - gpr_log(GPR_INFO, "### ReadMessageFromClient(%s): %s", - StreamIdString(stream_id).c_str(), ok ? "true" : "false"); + LOG(INFO) << "### ReadMessageFromClient(" << StreamIdString(stream_id) + << "): " << (ok ? "true" : "false"); auto stream = GetStream(stream_id); if (stream == nullptr) return; - gpr_log(GPR_INFO, " stream=%p", stream.get()); + LOG(INFO) << " stream=" << stream.get(); auto message = stream->WaitForMessageFromClient(absl::ZeroDuration()); if (message.has_value()) { - gpr_log(GPR_INFO, " completing send_message"); + LOG(INFO) << " completing send_message"; stream->CompleteSendMessageFromClient(ok); } } @@ -305,21 +300,20 @@ class Fuzzer { void SendMessageToClient( const xds_client_fuzzer::StreamId& stream_id, const envoy::service::discovery::v3::DiscoveryResponse& response) { - gpr_log(GPR_INFO, "### SendMessageToClient(%s)", - StreamIdString(stream_id).c_str()); + LOG(INFO) << "### SendMessageToClient(" << StreamIdString(stream_id) << ")"; auto stream = GetStream(stream_id); if (stream == nullptr) return; - gpr_log(GPR_INFO, " stream=%p", stream.get()); + LOG(INFO) << " stream=" << stream.get(); stream->SendMessageToClient(response.SerializeAsString()); } void SendStatusToClient(const xds_client_fuzzer::StreamId& stream_id, absl::Status status) { - gpr_log(GPR_INFO, "### SendStatusToClient(%s): %s", - StreamIdString(stream_id).c_str(), status.ToString().c_str()); + LOG(INFO) << "### SendStatusToClient(" << StreamIdString(stream_id) + << "): " << status; auto stream = GetStream(stream_id); if (stream == nullptr) return; - gpr_log(GPR_INFO, " stream=%p", stream.get()); + LOG(INFO) << " stream=" << stream.get(); stream->MaybeSendStatusToClient(std::move(status)); } diff --git a/test/cpp/client/credentials_test.cc b/test/cpp/client/credentials_test.cc index 87e633d854f..10b0c80e066 100644 --- a/test/cpp/client/credentials_test.cc +++ b/test/cpp/client/credentials_test.cc @@ -31,8 +31,8 @@ #include #include -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/env.h" +#include "src/core/util/tmpfile.h" #include "src/cpp/client/secure_credentials.h" #include "test/cpp/util/tls_test_utils.h" diff --git a/test/cpp/common/channel_arguments_test.cc b/test/cpp/common/channel_arguments_test.cc index e25039829ac..a6c7167d25e 100644 --- a/test/cpp/common/channel_arguments_test.cc +++ b/test/cpp/common/channel_arguments_test.cc @@ -22,9 +22,9 @@ #include #include -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/socket_mutator.h" +#include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" namespace grpc { diff --git a/test/cpp/end2end/cfstream_test.cc b/test/cpp/end2end/cfstream_test.cc index a075d28e6e5..907622e0b62 100644 --- a/test/cpp/end2end/cfstream_test.cc +++ b/test/cpp/end2end/cfstream_test.cc @@ -25,11 +25,11 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include #include -#include #include #include #include @@ -102,13 +102,13 @@ class CFStreamTest : public ::testing::TestWithParam { } void NetworkUp() { - gpr_log(GPR_DEBUG, "Bringing network up"); + VLOG(2) << "Bringing network up"; InterfaceUp(); DNSUp(); } void NetworkDown() { - gpr_log(GPR_DEBUG, "Bringing network down"); + VLOG(2) << "Bringing network down"; InterfaceDown(); DNSDown(); } @@ -156,10 +156,10 @@ class CFStreamTest : public ::testing::TestWithParam { ClientContext context; Status status = stub->Echo(&context, request, response.get()); if (status.ok()) { - gpr_log(GPR_DEBUG, "RPC with succeeded"); + VLOG(2) << "RPC with succeeded"; EXPECT_EQ(msg, response->message()); } else { - gpr_log(GPR_DEBUG, "RPC failed: %s", status.error_message().c_str()); + VLOG(2) << "RPC failed: " << status.error_message(); } if (expect_success) { EXPECT_TRUE(status.ok()); @@ -241,7 +241,7 @@ class CFStreamTest : public ::testing::TestWithParam { : port_(port), creds_(creds) {} void Start(const std::string& server_host) { - gpr_log(GPR_INFO, "starting server on port %d", port_); + LOG(INFO) << "starting server on port " << port_; std::mutex mu; std::unique_lock lock(mu); std::condition_variable cond; @@ -249,7 +249,7 @@ class CFStreamTest : public ::testing::TestWithParam { std::bind(&ServerData::Serve, this, server_host, &mu, &cond))); cond.wait(lock, [this] { return server_ready_; }); server_ready_ = false; - gpr_log(GPR_INFO, "server startup complete"); + LOG(INFO) << "server startup complete"; } void Serve(const std::string& server_host, std::mutex* mu, @@ -380,15 +380,14 @@ TEST_P(CFStreamTest, NetworkFlapRpcsInFlight) { CHECK(ok); AsyncClientCall* call = static_cast(got_tag); if (!call->status.ok()) { - gpr_log(GPR_DEBUG, "RPC failed with error: %s", - call->status.error_message().c_str()); + VLOG(2) << "RPC failed with error: " << call->status.error_message(); // Bring network up when RPCs start failing if (network_down) { NetworkUp(); network_down = false; } } else { - gpr_log(GPR_DEBUG, "RPC succeeded"); + VLOG(2) << "RPC succeeded"; } delete call; } @@ -427,11 +426,10 @@ TEST_P(CFStreamTest, ConcurrentRpc) { CHECK(ok); AsyncClientCall* call = static_cast(got_tag); if (!call->status.ok()) { - gpr_log(GPR_DEBUG, "RPC failed with error: %s", - call->status.error_message().c_str()); + VLOG(2) << "RPC failed with error: " << call->status.error_message(); // Bring network up when RPCs start failing } else { - gpr_log(GPR_DEBUG, "RPC succeeded"); + VLOG(2) << "RPC succeeded"; } delete call; } diff --git a/test/cpp/end2end/client_fork_test.cc b/test/cpp/end2end/client_fork_test.cc index 34050872f77..2388e558528 100644 --- a/test/cpp/end2end/client_fork_test.cc +++ b/test/cpp/end2end/client_fork_test.cc @@ -23,11 +23,11 @@ int main(int /* argc */, char** /* argv */) { return 0; } #include +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include #include -#include #include #include #include @@ -53,10 +53,10 @@ class ServiceImpl final : public EchoTestService::Service { EchoRequest request; EchoResponse response; while (stream->Read(&request)) { - gpr_log(GPR_INFO, "recv msg %s", request.message().c_str()); + LOG(INFO) << "recv msg " << request.message(); response.set_message(request.message()); stream->Write(response); - gpr_log(GPR_INFO, "wrote msg %s", response.message().c_str()); + LOG(INFO) << "wrote msg " << response.message(); } return Status::OK; } @@ -114,7 +114,7 @@ TEST(ClientForkTest, ClientCallsBeforeAndAfterForkSucceed) { GTEST_FAIL() << "fork failed"; case 0: // post-fork child { - gpr_log(GPR_DEBUG, "In post-fork child"); + VLOG(2) << "In post-fork child"; EchoRequest request; EchoResponse response; ClientContext context; @@ -131,7 +131,7 @@ TEST(ClientForkTest, ClientCallsBeforeAndAfterForkSucceed) { } default: // post-fork parent { - gpr_log(GPR_DEBUG, "In post-fork parent"); + VLOG(2) << "In post-fork parent"; EchoRequest request; EchoResponse response; ClientContext context; diff --git a/test/cpp/end2end/connection_attempt_injector.cc b/test/cpp/end2end/connection_attempt_injector.cc index bacfd15e1be..ab285203d8b 100644 --- a/test/cpp/end2end/connection_attempt_injector.cc +++ b/test/cpp/end2end/connection_attempt_injector.cc @@ -17,6 +17,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/utility/utility.h" @@ -119,14 +120,14 @@ void ConnectionAttemptInjector::HandleConnection( grpc_pollset_set* interested_parties, const EndpointConfig& config, const grpc_resolved_address* addr, grpc_core::Timestamp deadline) { const int port = grpc_sockaddr_get_port(addr); - gpr_log(GPR_INFO, "==> HandleConnection(): port=%d", port); + LOG(INFO) << "==> HandleConnection(): port=" << port; { grpc_core::MutexLock lock(&mu_); // First, check if there's a hold request for this port. for (auto it = holds_.begin(); it != holds_.end(); ++it) { Hold* hold = *it; if (port == hold->port_) { - gpr_log(GPR_INFO, "*** INTERCEPTING CONNECTION ATTEMPT"); + LOG(INFO) << "*** INTERCEPTING CONNECTION ATTEMPT"; if (hold->intercept_completion_) { hold->original_on_complete_ = closure; closure = GRPC_CLOSURE_INIT(&hold->on_complete_, Hold::OnComplete, @@ -220,16 +221,16 @@ ConnectionAttemptInjector::Hold::Hold(ConnectionAttemptInjector* injector, intercept_completion_(intercept_completion) {} void ConnectionAttemptInjector::Hold::Wait() { - gpr_log(GPR_INFO, "=== WAITING FOR CONNECTION ATTEMPT ON PORT %d ===", port_); + LOG(INFO) << "=== WAITING FOR CONNECTION ATTEMPT ON PORT " << port_ << " ==="; grpc_core::MutexLock lock(&injector_->mu_); while (queued_attempt_ == nullptr) { start_cv_.Wait(&injector_->mu_); } - gpr_log(GPR_INFO, "=== CONNECTION ATTEMPT STARTED ON PORT %d ===", port_); + LOG(INFO) << "=== CONNECTION ATTEMPT STARTED ON PORT " << port_ << " ==="; } void ConnectionAttemptInjector::Hold::Resume() { - gpr_log(GPR_INFO, "=== RESUMING CONNECTION ATTEMPT ON PORT %d ===", port_); + LOG(INFO) << "=== RESUMING CONNECTION ATTEMPT ON PORT " << port_ << " ==="; grpc_core::ExecCtx exec_ctx; std::unique_ptr attempt; { @@ -240,7 +241,7 @@ void ConnectionAttemptInjector::Hold::Resume() { } void ConnectionAttemptInjector::Hold::Fail(grpc_error_handle error) { - gpr_log(GPR_INFO, "=== FAILING CONNECTION ATTEMPT ON PORT %d ===", port_); + LOG(INFO) << "=== FAILING CONNECTION ATTEMPT ON PORT " << port_ << " ==="; grpc_core::ExecCtx exec_ctx; std::unique_ptr attempt; { @@ -251,13 +252,13 @@ void ConnectionAttemptInjector::Hold::Fail(grpc_error_handle error) { } void ConnectionAttemptInjector::Hold::WaitForCompletion() { - gpr_log(GPR_INFO, - "=== WAITING FOR CONNECTION COMPLETION ON PORT %d ===", port_); + LOG(INFO) << "=== WAITING FOR CONNECTION COMPLETION ON PORT " << port_ + << " ==="; grpc_core::MutexLock lock(&injector_->mu_); while (original_on_complete_ != nullptr) { complete_cv_.Wait(&injector_->mu_); } - gpr_log(GPR_INFO, "=== CONNECTION COMPLETED ON PORT %d ===", port_); + LOG(INFO) << "=== CONNECTION COMPLETED ON PORT " << port_ << " ==="; } bool ConnectionAttemptInjector::Hold::IsStarted() { diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 30db76435c3..543be34226f 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -20,6 +20,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/strings/ascii.h" #include "absl/strings/match.h" @@ -27,7 +28,6 @@ #include #include -#include #include #include #include @@ -538,7 +538,7 @@ class End2endServerTryCancelTest : public End2endTest { } num_msgs_sent++; } - gpr_log(GPR_INFO, "Sent %d messages", num_msgs_sent); + LOG(INFO) << "Sent " << num_msgs_sent << " messages"; stream->WritesDone(); Status s = stream->Finish(); @@ -566,8 +566,7 @@ class End2endServerTryCancelTest : public End2endTest { break; default: - gpr_log(GPR_ERROR, "Invalid server_try_cancel value: %d", - server_try_cancel); + LOG(ERROR) << "Invalid server_try_cancel value: " << server_try_cancel; EXPECT_TRUE(server_try_cancel > DO_NOT_CANCEL && server_try_cancel <= CANCEL_AFTER_PROCESSING); break; @@ -618,7 +617,7 @@ class End2endServerTryCancelTest : public End2endTest { request.message() + std::to_string(num_msgs_read)); num_msgs_read++; } - gpr_log(GPR_INFO, "Read %d messages", num_msgs_read); + LOG(INFO) << "Read " << num_msgs_read << " messages"; Status s = stream->Finish(); @@ -647,8 +646,7 @@ class End2endServerTryCancelTest : public End2endTest { break; default: { - gpr_log(GPR_ERROR, "Invalid server_try_cancel value: %d", - server_try_cancel); + LOG(ERROR) << "Invalid server_try_cancel value: " << server_try_cancel; EXPECT_TRUE(server_try_cancel > DO_NOT_CANCEL && server_try_cancel <= CANCEL_AFTER_PROCESSING); break; @@ -705,8 +703,8 @@ class End2endServerTryCancelTest : public End2endTest { EXPECT_EQ(response.message(), request.message()); } - gpr_log(GPR_INFO, "Sent %d messages", num_msgs_sent); - gpr_log(GPR_INFO, "Read %d messages", num_msgs_read); + LOG(INFO) << "Sent " << num_msgs_sent << " messages"; + LOG(INFO) << "Read " << num_msgs_read << " messages"; stream->WritesDone(); Status s = stream->Finish(); @@ -735,8 +733,7 @@ class End2endServerTryCancelTest : public End2endTest { break; default: - gpr_log(GPR_ERROR, "Invalid server_try_cancel value: %d", - server_try_cancel); + LOG(ERROR) << "Invalid server_try_cancel value: " << server_try_cancel; EXPECT_TRUE(server_try_cancel > DO_NOT_CANCEL && server_try_cancel <= CANCEL_AFTER_PROCESSING); break; @@ -1353,7 +1350,7 @@ void ReaderThreadFunc(ClientReaderWriter* stream, EchoResponse resp; gpr_event_set(ev, reinterpret_cast(1)); while (stream->Read(&resp)) { - gpr_log(GPR_INFO, "Read message"); + LOG(INFO) << "Read message"; } } diff --git a/test/cpp/end2end/flaky_network_test.cc b/test/cpp/end2end/flaky_network_test.cc index 4211cba13cf..add00a63cca 100644 --- a/test/cpp/end2end/flaky_network_test.cc +++ b/test/cpp/end2end/flaky_network_test.cc @@ -25,12 +25,12 @@ #include +#include "absl/log/log.h" #include "absl/memory/memory.h" #include #include #include -#include #include #include #include @@ -226,9 +226,9 @@ class FlakyNetworkTest : public ::testing::TestWithParam { Status status = stub->Echo(&context, request, response.get()); auto ok = status.ok(); if (ok) { - gpr_log(GPR_DEBUG, "RPC succeeded"); + VLOG(2) << "RPC succeeded"; } else { - gpr_log(GPR_DEBUG, "RPC failed: %s", status.error_message().c_str()); + VLOG(2) << "RPC failed: " << status.error_message(); } return ok; } @@ -245,7 +245,7 @@ class FlakyNetworkTest : public ::testing::TestWithParam { : port_(port), creds_(creds) {} void Start(const std::string& server_host) { - gpr_log(GPR_INFO, "starting server on port %d", port_); + LOG(INFO) << "starting server on port " << port_; std::mutex mu; std::unique_lock lock(mu); std::condition_variable cond; @@ -253,7 +253,7 @@ class FlakyNetworkTest : public ::testing::TestWithParam { std::bind(&ServerData::Serve, this, server_host, &mu, &cond)); cond.wait(lock, [this] { return server_ready_; }); server_ready_ = false; - gpr_log(GPR_INFO, "server startup complete"); + LOG(INFO) << "server startup complete"; } void Serve(const std::string& server_host, std::mutex* mu, @@ -399,7 +399,7 @@ TEST_P(FlakyNetworkTest, ServerUnreachableWithKeepalive) { // max time between reconnect attempts args.SetInt(GRPC_ARG_MAX_RECONNECT_BACKOFF_MS, kReconnectBackoffMs); - gpr_log(GPR_DEBUG, "FlakyNetworkTest.ServerUnreachableWithKeepalive start"); + VLOG(2) << "FlakyNetworkTest.ServerUnreachableWithKeepalive start"; auto channel = BuildChannel("pick_first", args); auto stub = BuildStub(channel); // Channel should be in READY state after we send an RPC @@ -418,18 +418,18 @@ TEST_P(FlakyNetworkTest, ServerUnreachableWithKeepalive) { }); // break network connectivity - gpr_log(GPR_DEBUG, "Adding iptables rule to drop packets"); + VLOG(2) << "Adding iptables rule to drop packets"; DropPackets(); std::this_thread::sleep_for(std::chrono::milliseconds(10000)); EXPECT_TRUE(WaitForChannelNotReady(channel.get())); // bring network interface back up RestoreNetwork(); - gpr_log(GPR_DEBUG, "Removed iptables rule to drop packets"); + VLOG(2) << "Removed iptables rule to drop packets"; EXPECT_TRUE(WaitForChannelReady(channel.get())); EXPECT_EQ(channel->GetState(false), GRPC_CHANNEL_READY); shutdown.store(true); sender.join(); - gpr_log(GPR_DEBUG, "FlakyNetworkTest.ServerUnreachableWithKeepalive end"); + VLOG(2) << "FlakyNetworkTest.ServerUnreachableWithKeepalive end"; } // diff --git a/test/cpp/end2end/orca_service_end2end_test.cc b/test/cpp/end2end/orca_service_end2end_test.cc index 691a3a3448f..bf67dd0bc36 100644 --- a/test/cpp/end2end/orca_service_end2end_test.cc +++ b/test/cpp/end2end/orca_service_end2end_test.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/types/optional.h" @@ -104,7 +105,7 @@ class OrcaServiceEnd2endTest : public ::testing::Test { builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); builder.RegisterService(&orca_service_); server_ = builder.BuildAndStart(); - gpr_log(GPR_INFO, "server started on %s", server_address_.c_str()); + LOG(INFO) << "server started on " << server_address_; auto channel = CreateChannel(server_address, InsecureChannelCredentials()); stub_ = OpenRcaService::NewStub(channel); } @@ -129,13 +130,13 @@ TEST_F(OrcaServiceEnd2endTest, Basic) { Stream stream1(stub_.get(), grpc_core::Duration::Milliseconds(5000)); Stream stream2(stub_.get(), grpc_core::Duration::Milliseconds(2500)); auto ReadResponses = [&](std::function checker) { - gpr_log(GPR_INFO, "reading response from stream1"); + LOG(INFO) << "reading response from stream1"; OrcaLoadReport response = stream1.ReadResponse(); checker(response); - gpr_log(GPR_INFO, "reading response from stream2"); + LOG(INFO) << "reading response from stream2"; response = stream2.ReadResponse(); checker(response); - gpr_log(GPR_INFO, "reading response from stream2"); + LOG(INFO) << "reading response from stream2"; response = stream2.ReadResponse(); checker(response); }; diff --git a/test/cpp/end2end/rls_end2end_test.cc b/test/cpp/end2end/rls_end2end_test.cc index 189c4c2d34c..ca6616fe6b7 100644 --- a/test/cpp/end2end/rls_end2end_test.cc +++ b/test/cpp/end2end/rls_end2end_test.cc @@ -1535,24 +1535,24 @@ TEST_F(RlsMetricsEnd2endTest, MetricValues) { EXPECT_EQ(backends_[1]->service_.request_count(), 0); // Check exported metrics. EXPECT_THAT( - stats_plugin_->GetCounterValue( + stats_plugin_->GetUInt64CounterValue( kMetricTargetPicks, {target_uri_, rls_server_target_, rls_target0, "complete"}, {}), ::testing::Optional(1)); EXPECT_THAT( - stats_plugin_->GetCounterValue( + stats_plugin_->GetUInt64CounterValue( kMetricTargetPicks, {target_uri_, rls_server_target_, rls_target1, "complete"}, {}), absl::nullopt); - EXPECT_EQ(stats_plugin_->GetCounterValue( + EXPECT_EQ(stats_plugin_->GetUInt64CounterValue( kMetricFailedPicks, {target_uri_, rls_server_target_}, {}), absl::nullopt); stats_plugin_->TriggerCallbacks(); - EXPECT_THAT(stats_plugin_->GetCallbackGaugeValue( + EXPECT_THAT(stats_plugin_->GetInt64CallbackGaugeValue( kMetricCacheEntries, {target_uri_, rls_server_target_, kRlsInstanceUuid}, {}), ::testing::Optional(1)); - auto cache_size = stats_plugin_->GetCallbackGaugeValue( + auto cache_size = stats_plugin_->GetInt64CallbackGaugeValue( kMetricCacheSize, {target_uri_, rls_server_target_, kRlsInstanceUuid}, {}); EXPECT_THAT(cache_size, ::testing::Optional(::testing::Ge(1))); @@ -1567,24 +1567,24 @@ TEST_F(RlsMetricsEnd2endTest, MetricValues) { EXPECT_EQ(backends_[1]->service_.request_count(), 1); // Check exported metrics. EXPECT_THAT( - stats_plugin_->GetCounterValue( + stats_plugin_->GetUInt64CounterValue( kMetricTargetPicks, {target_uri_, rls_server_target_, rls_target0, "complete"}, {}), ::testing::Optional(1)); EXPECT_THAT( - stats_plugin_->GetCounterValue( + stats_plugin_->GetUInt64CounterValue( kMetricTargetPicks, {target_uri_, rls_server_target_, rls_target1, "complete"}, {}), ::testing::Optional(1)); - EXPECT_EQ(stats_plugin_->GetCounterValue( + EXPECT_EQ(stats_plugin_->GetUInt64CounterValue( kMetricFailedPicks, {target_uri_, rls_server_target_}, {}), absl::nullopt); stats_plugin_->TriggerCallbacks(); - EXPECT_THAT(stats_plugin_->GetCallbackGaugeValue( + EXPECT_THAT(stats_plugin_->GetInt64CallbackGaugeValue( kMetricCacheEntries, {target_uri_, rls_server_target_, kRlsInstanceUuid}, {}), ::testing::Optional(2)); - auto cache_size2 = stats_plugin_->GetCallbackGaugeValue( + auto cache_size2 = stats_plugin_->GetInt64CallbackGaugeValue( kMetricCacheSize, {target_uri_, rls_server_target_, kRlsInstanceUuid}, {}); EXPECT_THAT(cache_size2, ::testing::Optional(::testing::Ge(2))); @@ -1611,24 +1611,24 @@ TEST_F(RlsMetricsEnd2endTest, MetricValues) { EXPECT_EQ(backends_[1]->service_.request_count(), 1); // Check exported metrics. EXPECT_THAT( - stats_plugin_->GetCounterValue( + stats_plugin_->GetUInt64CounterValue( kMetricTargetPicks, {target_uri_, rls_server_target_, rls_target0, "complete"}, {}), ::testing::Optional(1)); EXPECT_THAT( - stats_plugin_->GetCounterValue( + stats_plugin_->GetUInt64CounterValue( kMetricTargetPicks, {target_uri_, rls_server_target_, rls_target1, "complete"}, {}), ::testing::Optional(1)); - EXPECT_THAT(stats_plugin_->GetCounterValue( + EXPECT_THAT(stats_plugin_->GetUInt64CounterValue( kMetricFailedPicks, {target_uri_, rls_server_target_}, {}), ::testing::Optional(1)); stats_plugin_->TriggerCallbacks(); - EXPECT_THAT(stats_plugin_->GetCallbackGaugeValue( + EXPECT_THAT(stats_plugin_->GetInt64CallbackGaugeValue( kMetricCacheEntries, {target_uri_, rls_server_target_, kRlsInstanceUuid}, {}), ::testing::Optional(3)); - auto cache_size3 = stats_plugin_->GetCallbackGaugeValue( + auto cache_size3 = stats_plugin_->GetInt64CallbackGaugeValue( kMetricCacheSize, {target_uri_, rls_server_target_, kRlsInstanceUuid}, {}); EXPECT_THAT(cache_size3, ::testing::Optional(::testing::Ge(3))); @@ -1678,7 +1678,7 @@ TEST_F(RlsMetricsEnd2endTest, MetricValuesDefaultTargetRpcs) { EXPECT_EQ(backends_[0]->service_.request_count(), 1); // Check expected metrics. EXPECT_THAT( - stats_plugin_->GetCounterValue( + stats_plugin_->GetUInt64CounterValue( kMetricDefaultTargetPicks, {target_uri_, rls_server_target_, default_target, "complete"}, {}), ::testing::Optional(1)); diff --git a/test/cpp/end2end/rls_server.cc b/test/cpp/end2end/rls_server.cc index 98928bedc8c..f0b520fe9d6 100644 --- a/test/cpp/end2end/rls_server.cc +++ b/test/cpp/end2end/rls_server.cc @@ -18,6 +18,8 @@ #include +#include "absl/log/log.h" + #include "src/proto/grpc/lookup/v1/rls.grpc.pb.h" #include "src/proto/grpc/lookup/v1/rls.pb.h" #include "test/core/test_util/test_config.h" @@ -31,8 +33,7 @@ namespace testing { ::grpc::Status RlsServiceImpl::RouteLookup(grpc::ServerContext* context, const RouteLookupRequest* request, RouteLookupResponse* response) { - gpr_log(GPR_INFO, "RLS: Received request: %s", - request->DebugString().c_str()); + LOG(INFO) << "RLS: Received request: " << request->DebugString(); if (context_proc_ != nullptr) { context_proc_(context); } @@ -44,7 +45,7 @@ namespace testing { grpc::internal::MutexLock lock(&mu_); auto it = responses_.find(*request); if (it == responses_.end()) { - gpr_log(GPR_INFO, "RLS: no matching request, returning INTERNAL"); + LOG(INFO) << "RLS: no matching request, returning INTERNAL"; unmatched_requests_.push_back(*request); return Status(StatusCode::INTERNAL, "no response entry"); } @@ -57,8 +58,8 @@ namespace testing { } IncreaseResponseCount(); *response = res.response; - gpr_log(GPR_INFO, "RLS: returning configured response: %s", - response->DebugString().c_str()); + LOG(INFO) << "RLS: returning configured response: " + << response->DebugString(); return Status::OK; } diff --git a/test/cpp/end2end/server_load_reporting_end2end_test.cc b/test/cpp/end2end/server_load_reporting_end2end_test.cc index acdafe31f5c..d5e057d386a 100644 --- a/test/cpp/end2end/server_load_reporting_end2end_test.cc +++ b/test/cpp/end2end/server_load_reporting_end2end_test.cc @@ -21,9 +21,10 @@ #include #include +#include "absl/log/log.h" + #include #include -#include #include #include #include @@ -138,11 +139,11 @@ TEST_F(ServerLoadReportingEnd2endTest, BasicReport) { ->mutable_load_report_interval() ->set_seconds(5); stream->Write(request); - gpr_log(GPR_INFO, "Initial request sent."); + LOG(INFO) << "Initial request sent."; grpc::lb::v1::LoadReportResponse response; stream->Read(&response); const std::string& lb_id = response.initial_response().load_balancer_id(); - gpr_log(GPR_INFO, "Initial response received (lb_id: %s).", lb_id.c_str()); + LOG(INFO) << "Initial response received (lb_id: " << lb_id << ")."; ClientMakeEchoCalls(lb_id, "LB_TAG", kOkMessage, 1); unsigned load_count = 0; diff --git a/test/cpp/end2end/service_config_end2end_test.cc b/test/cpp/end2end/service_config_end2end_test.cc index 5efb0cd285b..380ebc2e261 100644 --- a/test/cpp/end2end/service_config_end2end_test.cc +++ b/test/cpp/end2end/service_config_end2end_test.cc @@ -28,13 +28,13 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" #include #include #include -#include #include #include #include @@ -311,7 +311,7 @@ class ServiceConfigEnd2endTest : public ::testing::Test { : port_(port > 0 ? port : grpc_pick_unused_port_or_die()) {} void Start(const std::string& server_host) { - gpr_log(GPR_INFO, "starting server on port %d", port_); + LOG(INFO) << "starting server on port " << port_; grpc::internal::MutexLock lock(&mu_); started_ = true; thread_ = std::make_unique( @@ -320,7 +320,7 @@ class ServiceConfigEnd2endTest : public ::testing::Test { cond_.Wait(&mu_); } server_ready_ = false; - gpr_log(GPR_INFO, "server startup complete"); + LOG(INFO) << "server startup complete"; } void Serve(const std::string& server_host) { diff --git a/test/cpp/end2end/test_service_impl.cc b/test/cpp/end2end/test_service_impl.cc index b721ed5382a..0c23abc6c51 100644 --- a/test/cpp/end2end/test_service_impl.cc +++ b/test/cpp/end2end/test_service_impl.cc @@ -24,8 +24,8 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" -#include #include #include #include @@ -96,7 +96,7 @@ int GetIntValueFromMetadataHelper( if (metadata.find(key) != metadata.end()) { std::istringstream iss(ToString(metadata.find(key)->second)); iss >> default_value; - gpr_log(GPR_INFO, "%s : %d", key, default_value); + LOG(INFO) << key << " : " << default_value; } return default_value; @@ -112,7 +112,7 @@ int GetIntValueFromMetadata( void ServerTryCancel(ServerContext* context) { EXPECT_FALSE(context->IsCancelled()); context->TryCancel(); - gpr_log(GPR_INFO, "Server called TryCancel() to cancel the request"); + LOG(INFO) << "Server called TryCancel() to cancel the request"; // Now wait until it's really canceled while (!context->IsCancelled()) { gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), @@ -123,8 +123,7 @@ void ServerTryCancel(ServerContext* context) { void ServerTryCancelNonblocking(CallbackServerContext* context) { EXPECT_FALSE(context->IsCancelled()); context->TryCancel(); - gpr_log(GPR_INFO, - "Server called TryCancelNonblocking() to cancel the request"); + LOG(INFO) << "Server called TryCancelNonblocking() to cancel the request"; } } // namespace internal @@ -211,7 +210,7 @@ ServerUnaryReactor* CallbackTestServiceImpl::Echo( return; } if (req_->has_param() && req_->param().server_die()) { - gpr_log(GPR_ERROR, "The request should not reach application handler."); + LOG(ERROR) << "The request should not reach application handler."; CHECK(0); } if (req_->has_param() && req_->param().has_expected_error()) { @@ -229,7 +228,7 @@ ServerUnaryReactor* CallbackTestServiceImpl::Echo( // RPC as long as server_try_cancel is not DO_NOT_CANCEL EXPECT_FALSE(ctx_->IsCancelled()); ctx_->TryCancel(); - gpr_log(GPR_INFO, "Server called TryCancel() to cancel the request"); + LOG(INFO) << "Server called TryCancel() to cancel the request"; FinishWhenCancelledAsync(); return; } @@ -398,7 +397,7 @@ ServerReadReactor* CallbackTestServiceImpl::RequestStream( num_msgs_read_++; StartRead(&request_); } else { - gpr_log(GPR_INFO, "Read: %d messages", num_msgs_read_); + LOG(INFO) << "Read: " << num_msgs_read_ << " messages"; if (server_try_cancel_ == CANCEL_DURING_PROCESSING) { // Let OnCancel recover this diff --git a/test/cpp/end2end/test_service_impl.h b/test/cpp/end2end/test_service_impl.h index 3fae2456987..05511373302 100644 --- a/test/cpp/end2end/test_service_impl.h +++ b/test/cpp/end2end/test_service_impl.h @@ -28,9 +28,9 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include -#include #include #include #include @@ -98,35 +98,34 @@ class TestServiceSignaller { // is whatever the number of RPCs waiting for server notification is // at that time. int ClientWaitUntilNRpcsStarted(int desired_rpcs, absl::Duration timeout) { - gpr_log(GPR_DEBUG, "*** enter ClientWaitUntilNRpcsStarted ***"); + VLOG(2) << "*** enter ClientWaitUntilNRpcsStarted ***"; absl::Time deadline = absl::Now() + timeout; std::chrono::system_clock::time_point chrono_deadline = absl::ToChronoTime(deadline); std::unique_lock lock(mu_); cv_rpc_started_.wait_until(lock, chrono_deadline, [this, desired_rpcs] { - gpr_log( - GPR_DEBUG, - "*** desired_rpcs: %d rpcs_waiting_for_server_to_continue_: %d ***", - desired_rpcs, rpcs_waiting_for_server_to_continue_); + VLOG(2) << "*** desired_rpcs: " << desired_rpcs + << " rpcs_waiting_for_server_to_continue_: " + << rpcs_waiting_for_server_to_continue_ << " ***"; return rpcs_waiting_for_server_to_continue_ >= desired_rpcs; }); - gpr_log(GPR_DEBUG, "*** leave ClientWaitUntilNRpcsStarted ***"); + VLOG(2) << "*** leave ClientWaitUntilNRpcsStarted ***"; return rpcs_waiting_for_server_to_continue_; } void ServerWaitToContinue() { - gpr_log(GPR_DEBUG, "*** enter ServerWaitToContinue ***"); + VLOG(2) << "*** enter ServerWaitToContinue ***"; std::unique_lock lock(mu_); cv_server_continue_.wait(lock, [this] { return server_should_continue_; }); - gpr_log(GPR_DEBUG, "*** leave ServerWaitToContinue ***"); + VLOG(2) << "*** leave ServerWaitToContinue ***"; } void SignalClientThatRpcStarted() { - gpr_log(GPR_DEBUG, "*** SignalClientThatRpcStarted ***"); + VLOG(2) << "*** SignalClientThatRpcStarted ***"; std::unique_lock lock(mu_); ++rpcs_waiting_for_server_to_continue_; cv_rpc_started_.notify_all(); } void SignalServerToContinue() { - gpr_log(GPR_DEBUG, "*** SignalServerToContinue ***"); + VLOG(2) << "*** SignalServerToContinue ***"; std::unique_lock lock(mu_); server_should_continue_ = true; cv_server_continue_.notify_all(); @@ -170,7 +169,7 @@ class TestMultipleServiceImpl : public RpcService { } if (request->has_param() && request->param().server_die()) { - gpr_log(GPR_ERROR, "The request should not reach application handler."); + LOG(ERROR) << "The request should not reach application handler."; CHECK(0); } if (request->has_param() && request->param().has_expected_error()) { @@ -330,7 +329,7 @@ class TestMultipleServiceImpl : public RpcService { while (reader->Read(&request)) { response->mutable_message()->append(request.message()); } - gpr_log(GPR_INFO, "Read: %d messages", num_msgs_read); + LOG(INFO) << "Read: " << num_msgs_read << " messages"; if (server_try_cancel_thd != nullptr) { server_try_cancel_thd->join(); @@ -441,7 +440,7 @@ class TestMultipleServiceImpl : public RpcService { int read_counts = 0; while (stream->Read(&request)) { read_counts++; - gpr_log(GPR_INFO, "recv msg %s", request.message().c_str()); + LOG(INFO) << "recv msg " << request.message(); response.set_message(request.message()); if (read_counts == server_write_last) { stream->WriteLast(response, WriteOptions()); diff --git a/test/cpp/end2end/tls_key_export_test.cc b/test/cpp/end2end/tls_key_export_test.cc index 09cbed9171b..ad08372f20f 100644 --- a/test/cpp/end2end/tls_key_export_test.cc +++ b/test/cpp/end2end/tls_key_export_test.cc @@ -31,7 +31,7 @@ #include #include -#include "src/core/lib/gpr/tmpfile.h" +#include "src/core/util/tmpfile.h" #include "src/cpp/client/secure_credentials.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/test_util/resolve_localhost_ip46.h" diff --git a/test/cpp/end2end/xds/xds_cluster_end2end_test.cc b/test/cpp/end2end/xds/xds_cluster_end2end_test.cc index 07f3fdaf7e3..a162086b69e 100644 --- a/test/cpp/end2end/xds/xds_cluster_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_cluster_end2end_test.cc @@ -20,6 +20,7 @@ #include #include +#include "absl/log/log.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -898,10 +899,10 @@ TEST_P(EdsTest, LocalityMapUpdateChurn) { balancer_->ads_service()->SetEdsResource(BuildEdsResource(args)); // Wait for the first 3 backends to be ready. WaitForAllBackends(DEBUG_LOCATION, 0, 3); - gpr_log(GPR_INFO, "========= BEFORE FIRST BATCH =========="); + LOG(INFO) << "========= BEFORE FIRST BATCH =========="; // Send kNumRpcs RPCs. CheckRpcSendOk(DEBUG_LOCATION, kNumRpcs); - gpr_log(GPR_INFO, "========= DONE WITH FIRST BATCH =========="); + LOG(INFO) << "========= DONE WITH FIRST BATCH =========="; // The picking rates of the first 3 backends should be roughly equal to the // expectation. std::vector locality_picked_rates; @@ -931,10 +932,10 @@ TEST_P(EdsTest, LocalityMapUpdateChurn) { // Wait until the locality update has been processed, as signaled by backend // 3 receiving a request. WaitForAllBackends(DEBUG_LOCATION, 3, 4); - gpr_log(GPR_INFO, "========= BEFORE SECOND BATCH =========="); + LOG(INFO) << "========= BEFORE SECOND BATCH =========="; // Send kNumRpcs RPCs. CheckRpcSendOk(DEBUG_LOCATION, kNumRpcs); - gpr_log(GPR_INFO, "========= DONE WITH SECOND BATCH =========="); + LOG(INFO) << "========= DONE WITH SECOND BATCH =========="; // Backend 0 no longer receives any request. EXPECT_EQ(0U, backends_[0]->backend_service()->request_count()); // The picking rates of the last 3 backends should be roughly equal to the @@ -1091,11 +1092,11 @@ TEST_P(EdsTest, DropConfigUpdate) { args.drop_categories = {{kLbDropType, kDropPerMillionForLb}}; balancer_->ads_service()->SetEdsResource(BuildEdsResource(args)); // Send kNumRpcsLbOnly RPCs and count the drops. - gpr_log(GPR_INFO, "========= BEFORE FIRST BATCH =========="); + LOG(INFO) << "========= BEFORE FIRST BATCH =========="; size_t num_drops = SendRpcsAndCountFailuresWithMessage( DEBUG_LOCATION, kNumRpcsLbOnly, StatusCode::UNAVAILABLE, kStatusMessageDropPrefix); - gpr_log(GPR_INFO, "========= DONE WITH FIRST BATCH =========="); + LOG(INFO) << "========= DONE WITH FIRST BATCH =========="; // The drop rate should be roughly equal to the expectation. double seen_drop_rate = static_cast(num_drops) / kNumRpcsLbOnly; gpr_log(GPR_INFO, "First batch drop rate %f", seen_drop_rate); @@ -1128,11 +1129,11 @@ TEST_P(EdsTest, DropConfigUpdate) { }, /*timeout_ms=*/40000); // Send kNumRpcsBoth RPCs and count the drops. - gpr_log(GPR_INFO, "========= BEFORE SECOND BATCH =========="); + LOG(INFO) << "========= BEFORE SECOND BATCH =========="; num_drops = SendRpcsAndCountFailuresWithMessage(DEBUG_LOCATION, kNumRpcsBoth, StatusCode::UNAVAILABLE, kStatusMessageDropPrefix); - gpr_log(GPR_INFO, "========= DONE WITH SECOND BATCH =========="); + LOG(INFO) << "========= DONE WITH SECOND BATCH =========="; // The new drop rate should be roughly equal to the expectation. seen_drop_rate = static_cast(num_drops) / kNumRpcsBoth; gpr_log(GPR_INFO, "Second batch drop rate %f", seen_drop_rate); @@ -1268,9 +1269,9 @@ TEST_P(FailoverTest, ReportsConnectingDuringFailover) { // Allow the connection attempt to complete. hold->Resume(); // Now the RPC should complete successfully. - gpr_log(GPR_INFO, "=== WAITING FOR RPC TO FINISH ==="); + LOG(INFO) << "=== WAITING FOR RPC TO FINISH ==="; Status status = rpc.GetStatus(); - gpr_log(GPR_INFO, "=== RPC FINISHED ==="); + LOG(INFO) << "=== RPC FINISHED ==="; EXPECT_TRUE(status.ok()) << "code=" << status.error_code() << " message=" << status.error_message(); } diff --git a/test/cpp/end2end/xds/xds_cluster_type_end2end_test.cc b/test/cpp/end2end/xds/xds_cluster_type_end2end_test.cc index 45dced809bc..b87cf9df016 100644 --- a/test/cpp/end2end/xds/xds_cluster_type_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_cluster_type_end2end_test.cc @@ -19,6 +19,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" @@ -367,9 +368,9 @@ TEST_P(AggregateClusterTest, FallBackWithConnectivityChurn) { // Meanwhile, the channel will also start a second attempt for backend // 0, which we have NOT held, so it will complete normally, and the // RPC will finish on backend 0. - gpr_log(GPR_INFO, "=== WAITING FOR RPC TO FINISH === "); + LOG(INFO) << "=== WAITING FOR RPC TO FINISH === "; Status status = rpc.GetStatus(); - gpr_log(GPR_INFO, "=== RPC FINISHED === "); + LOG(INFO) << "=== RPC FINISHED === "; EXPECT_TRUE(status.ok()) << "code=" << status.error_code() << " message=" << status.error_message(); EXPECT_EQ(1UL, backends_[0]->backend_service()->request_count()); diff --git a/test/cpp/end2end/xds/xds_core_end2end_test.cc b/test/cpp/end2end/xds/xds_core_end2end_test.cc index fd9cc6cac2d..ebc97f4a8e8 100644 --- a/test/cpp/end2end/xds/xds_core_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_core_end2end_test.cc @@ -1217,11 +1217,11 @@ TEST_P(XdsMetricsTest, MetricValues) { CheckRpcSendOk(DEBUG_LOCATION); stats_plugin_->TriggerCallbacks(); // Check client metrics. - EXPECT_THAT(stats_plugin_->GetCallbackGaugeValue(kMetricConnected, - {kTarget, kXdsServer}, {}), + EXPECT_THAT(stats_plugin_->GetInt64CallbackGaugeValue( + kMetricConnected, {kTarget, kXdsServer}, {}), ::testing::Optional(1)); - EXPECT_THAT(stats_plugin_->GetCounterValue(kMetricServerFailure, - {kTarget, kXdsServer}, {}), + EXPECT_THAT(stats_plugin_->GetUInt64CounterValue(kMetricServerFailure, + {kTarget, kXdsServer}, {}), absl::nullopt); for (absl::string_view type_url : {"envoy.config.listener.v3.Listener", @@ -1229,37 +1229,37 @@ TEST_P(XdsMetricsTest, MetricValues) { "envoy.config.cluster.v3.Cluster", "envoy.config.endpoint.v3.ClusterLoadAssignment"}) { EXPECT_THAT( - stats_plugin_->GetCounterValue(kMetricResourceUpdatesValid, - {kTarget, kXdsServer, type_url}, {}), + stats_plugin_->GetUInt64CounterValue( + kMetricResourceUpdatesValid, {kTarget, kXdsServer, type_url}, {}), ::testing::Optional(1)); EXPECT_THAT( - stats_plugin_->GetCounterValue(kMetricResourceUpdatesInvalid, - {kTarget, kXdsServer, type_url}, {}), + stats_plugin_->GetUInt64CounterValue( + kMetricResourceUpdatesInvalid, {kTarget, kXdsServer, type_url}, {}), ::testing::Optional(0)); - EXPECT_THAT(stats_plugin_->GetCallbackGaugeValue( + EXPECT_THAT(stats_plugin_->GetInt64CallbackGaugeValue( kMetricResources, {kTarget, "#old", type_url, "acked"}, {}), ::testing::Optional(1)); } // Check server metrics. - EXPECT_THAT(stats_plugin_->GetCallbackGaugeValue(kMetricConnected, - {"#server", kXdsServer}, {}), + EXPECT_THAT(stats_plugin_->GetInt64CallbackGaugeValue( + kMetricConnected, {"#server", kXdsServer}, {}), ::testing::Optional(1)); - EXPECT_THAT(stats_plugin_->GetCounterValue(kMetricServerFailure, - {"#server", kXdsServer}, {}), + EXPECT_THAT(stats_plugin_->GetUInt64CounterValue(kMetricServerFailure, + {"#server", kXdsServer}, {}), absl::nullopt); for (absl::string_view type_url : {"envoy.config.listener.v3.Listener", "envoy.config.route.v3.RouteConfiguration"}) { EXPECT_THAT( - stats_plugin_->GetCounterValue(kMetricResourceUpdatesValid, - {"#server", kXdsServer, type_url}, {}), + stats_plugin_->GetUInt64CounterValue( + kMetricResourceUpdatesValid, {"#server", kXdsServer, type_url}, {}), ::testing::Optional(1)); + EXPECT_THAT(stats_plugin_->GetUInt64CounterValue( + kMetricResourceUpdatesInvalid, + {"#server", kXdsServer, type_url}, {}), + ::testing::Optional(0)); EXPECT_THAT( - stats_plugin_->GetCounterValue(kMetricResourceUpdatesInvalid, - {"#server", kXdsServer, type_url}, {}), - ::testing::Optional(0)); - EXPECT_THAT( - stats_plugin_->GetCallbackGaugeValue( + stats_plugin_->GetInt64CallbackGaugeValue( kMetricResources, {"#server", "#old", type_url, "acked"}, {}), ::testing::Optional(1)); } @@ -1269,8 +1269,8 @@ TEST_P(XdsMetricsTest, MetricValues) { const absl::Time deadline = absl::Now() + absl::Seconds(5 * grpc_test_slowdown_factor()); while (true) { - auto value = stats_plugin_->GetCounterValue(kMetricServerFailure, - {target, kXdsServer}, {}); + auto value = stats_plugin_->GetUInt64CounterValue( + kMetricServerFailure, {target, kXdsServer}, {}); if (value.has_value()) { EXPECT_EQ(1, *value); break; @@ -1279,8 +1279,8 @@ TEST_P(XdsMetricsTest, MetricValues) { absl::SleepFor(absl::Seconds(1)); } stats_plugin_->TriggerCallbacks(); - EXPECT_THAT(stats_plugin_->GetCallbackGaugeValue(kMetricConnected, - {target, kXdsServer}, {}), + EXPECT_THAT(stats_plugin_->GetInt64CallbackGaugeValue( + kMetricConnected, {target, kXdsServer}, {}), ::testing::Optional(0)); } } diff --git a/test/cpp/end2end/xds/xds_end2end_test.cc b/test/cpp/end2end/xds/xds_end2end_test.cc index 8e2d47e686e..9a8c8a9c52d 100644 --- a/test/cpp/end2end/xds/xds_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_end2end_test.cc @@ -33,6 +33,7 @@ #include "absl/functional/bind_front.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -45,7 +46,6 @@ #include #include #include -#include #include #include #include @@ -63,9 +63,6 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/config/config_vars.h" #include "src/core/lib/config/core_configuration.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/time_precise.h" -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -80,6 +77,9 @@ #include "src/core/load_balancing/xds/xds_channel_args.h" #include "src/core/resolver/endpoint_addresses.h" #include "src/core/resolver/fake/fake_resolver.h" +#include "src/core/util/string.h" +#include "src/core/util/time_precise.h" +#include "src/core/util/tmpfile.h" #include "src/core/xds/grpc/xds_listener.h" #include "src/core/xds/xds_client/xds_api.h" #include "src/core/xds/xds_client/xds_channel_args.h" @@ -398,8 +398,7 @@ class XdsSecurityTest : public XdsEnd2endTest { DEBUG_LOCATION, [&](const RpcResult& result) { if (result.status.ok()) { - gpr_log(GPR_ERROR, - "RPC succeeded. Failure expected. Trying again."); + LOG(ERROR) << "RPC succeeded. Failure expected. Trying again."; return true; } EXPECT_EQ(result.status.error_code(), StatusCode::UNAVAILABLE); @@ -1051,7 +1050,7 @@ class XdsServerSecurityTest : public XdsEnd2endTest { std::vector expected_client_identity, bool test_expects_failure = false, absl::optional expected_status = absl::nullopt) { - gpr_log(GPR_INFO, "Sending RPC"); + LOG(INFO) << "Sending RPC"; int num_tries = 0; constexpr int kRetryCount = 100; auto overall_deadline = absl::Now() + absl::Seconds(5); @@ -1073,7 +1072,7 @@ class XdsServerSecurityTest : public XdsEnd2endTest { Status status = stub->Echo(&context, request, &response); if (test_expects_failure) { if (status.ok()) { - gpr_log(GPR_ERROR, "RPC succeeded. Failure expected. Trying again."); + LOG(ERROR) << "RPC succeeded. Failure expected. Trying again."; continue; } if (expected_status.has_value() && diff --git a/test/cpp/end2end/xds/xds_end2end_test_lib.cc b/test/cpp/end2end/xds/xds_end2end_test_lib.cc index 2301e0d3fd3..efccd9e0fb6 100644 --- a/test/cpp/end2end/xds/xds_end2end_test_lib.cc +++ b/test/cpp/end2end/xds/xds_end2end_test_lib.cc @@ -37,9 +37,9 @@ #include #include "src/core/ext/filters/http/server/http_server_filter.h" -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/env.h" #include "src/core/server/server.h" +#include "src/core/util/tmpfile.h" #include "src/core/xds/grpc/xds_client_grpc.h" #include "src/core/xds/xds_client/xds_channel_args.h" #include "src/proto/grpc/testing/xds/v3/router.grpc.pb.h" diff --git a/test/cpp/end2end/xds/xds_server.cc b/test/cpp/end2end/xds/xds_server.cc index ee96dd3f84a..a4019c7fdfe 100644 --- a/test/cpp/end2end/xds/xds_server.cc +++ b/test/cpp/end2end/xds/xds_server.cc @@ -23,10 +23,9 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/types/optional.h" -#include - #include "src/core/lib/address_utils/parse_address.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/sync.h" @@ -51,10 +50,9 @@ void AdsServiceImpl::SetResource(google::protobuf::Any resource, resource_state.resource_type_version = resource_type_state.resource_type_version; resource_state.resource = std::move(resource); - gpr_log(GPR_INFO, - "ADS[%s]: Updating %s resource %s; resource_type_version now %u", - debug_label_.c_str(), type_url.c_str(), name.c_str(), - resource_type_state.resource_type_version); + LOG(INFO) << "ADS[" << debug_label_ << "]: Updating " << type_url + << " resource " << name << "; resource_type_version now " + << resource_type_state.resource_type_version; for (SubscriptionState* subscription : resource_state.subscriptions) { subscription->update_queue->emplace_back(type_url, name); } @@ -69,10 +67,9 @@ void AdsServiceImpl::UnsetResource(const std::string& type_url, resource_state.resource_type_version = resource_type_state.resource_type_version; resource_state.resource.reset(); - gpr_log(GPR_INFO, - "ADS[%s]: Unsetting %s resource %s; resource_type_version now %u", - debug_label_.c_str(), type_url.c_str(), name.c_str(), - resource_type_state.resource_type_version); + LOG(INFO) << "ADS[" << debug_label_ << "]: Unsetting " << type_url + << " resource " << name << "; resource_type_version now " + << resource_type_state.resource_type_version; for (SubscriptionState* subscription : resource_state.subscriptions) { subscription->update_queue->emplace_back(type_url, name); } @@ -101,9 +98,9 @@ bool AdsServiceImpl::MaybeSubscribe(const std::string& resource_type, if (subscription_state->update_queue != nullptr) return false; subscription_state->update_queue = update_queue; resource_state->subscriptions.emplace(subscription_state); - gpr_log(GPR_INFO, "ADS[%s]: subscribe to resource type %s name %s state %p", - debug_label_.c_str(), resource_type.c_str(), resource_name.c_str(), - &subscription_state); + LOG(INFO) << "ADS[" << debug_label_ << "]: subscribe to resource type " + << resource_type << " name " << resource_name << " state " + << &subscription_state; return true; } @@ -123,9 +120,9 @@ void AdsServiceImpl::ProcessUnsubscriptions( ++it; continue; } - gpr_log(GPR_INFO, "ADS[%s]: Unsubscribe to type=%s name=%s state=%p", - debug_label_.c_str(), resource_type.c_str(), resource_name.c_str(), - &subscription_state); + LOG(INFO) << "ADS[" << debug_label_ + << "]: Unsubscribe to type=" << resource_type + << " name=" << resource_name << " state=" << &subscription_state; auto resource_it = resource_name_map->find(resource_name); CHECK(resource_it != resource_name_map->end()); auto& resource_state = resource_it->second; @@ -152,7 +149,7 @@ void AdsServiceImpl::Shutdown() { } resource_type_response_state_.clear(); } - gpr_log(GPR_INFO, "ADS[%s]: shut down", debug_label_.c_str()); + LOG(INFO) << "ADS[" << debug_label_ << "]: shut down"; } // @@ -233,7 +230,7 @@ void LrsServiceImpl::Shutdown() { lrs_cv_.SignalAll(); } } - gpr_log(GPR_INFO, "LRS[%s]: shut down", debug_label_.c_str()); + LOG(INFO) << "LRS[" << debug_label_ << "]: shut down"; } std::vector LrsServiceImpl::WaitForLoadReport( @@ -245,7 +242,7 @@ std::vector LrsServiceImpl::WaitForLoadReport( load_report_cond_ = &cv; while (result_queue_.empty()) { if (cv.WaitWithTimeout(&load_report_mu_, timeout)) { - gpr_log(GPR_ERROR, "timed out waiting for load report"); + LOG(ERROR) << "timed out waiting for load report"; return {}; } } diff --git a/test/cpp/end2end/xds/xds_utils.cc b/test/cpp/end2end/xds/xds_utils.cc index 897300b230d..f70ca9b9ccd 100644 --- a/test/cpp/end2end/xds/xds_utils.cc +++ b/test/cpp/end2end/xds/xds_utils.cc @@ -34,9 +34,9 @@ #include #include "src/core/ext/filters/http/server/http_server_filter.h" -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/env.h" #include "src/core/server/server.h" +#include "src/core/util/tmpfile.h" #include "src/core/xds/grpc/xds_client_grpc.h" #include "src/core/xds/xds_client/xds_channel_args.h" #include "src/cpp/client/secure_credentials.h" diff --git a/test/cpp/end2end/xds/xds_wrr_end2end_test.cc b/test/cpp/end2end/xds/xds_wrr_end2end_test.cc index 97c5b6ab9a1..9a58443efa0 100644 --- a/test/cpp/end2end/xds/xds_wrr_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_wrr_end2end_test.cc @@ -132,12 +132,12 @@ TEST_P(WrrTest, MetricsHaveLocalityLabel) { WaitForAllBackends(DEBUG_LOCATION); // Make sure we have a metric value for each of the two localities. EXPECT_THAT( - stats_plugin->GetHistogramValue(kEndpointWeights, kLabelValues, - {LocalityNameString("locality0")}), + stats_plugin->GetDoubleHistogramValue(kEndpointWeights, kLabelValues, + {LocalityNameString("locality0")}), ::testing::Optional(::testing::Not(::testing::IsEmpty()))); EXPECT_THAT( - stats_plugin->GetHistogramValue(kEndpointWeights, kLabelValues, - {LocalityNameString("locality1")}), + stats_plugin->GetDoubleHistogramValue(kEndpointWeights, kLabelValues, + {LocalityNameString("locality1")}), ::testing::Optional(::testing::Not(::testing::IsEmpty()))); } diff --git a/test/cpp/ext/csm/mesh_id_test.cc b/test/cpp/ext/csm/mesh_id_test.cc index 437d57c52e6..7d0b8ba8c21 100644 --- a/test/cpp/ext/csm/mesh_id_test.cc +++ b/test/cpp/ext/csm/mesh_id_test.cc @@ -20,8 +20,8 @@ #include -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/env.h" +#include "src/core/util/tmpfile.h" #include "src/cpp/ext/csm/metadata_exchange.h" #include "test/core/test_util/test_config.h" diff --git a/test/cpp/ext/csm/metadata_exchange_test.cc b/test/cpp/ext/csm/metadata_exchange_test.cc index aeaad05117d..3f5d8af74b7 100644 --- a/test/cpp/ext/csm/metadata_exchange_test.cc +++ b/test/cpp/ext/csm/metadata_exchange_test.cc @@ -31,8 +31,8 @@ #include "src/core/lib/channel/call_tracer.h" #include "src/core/lib/config/core_configuration.h" -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/env.h" +#include "src/core/util/tmpfile.h" #include "src/cpp/ext/csm/csm_observability.h" #include "src/cpp/ext/otel/otel_plugin.h" #include "test/core/test_util/test_config.h" diff --git a/test/cpp/ext/filters/logging/BUILD b/test/cpp/ext/filters/logging/BUILD index 11a90473b8f..8767e687423 100644 --- a/test/cpp/ext/filters/logging/BUILD +++ b/test/cpp/ext/filters/logging/BUILD @@ -57,6 +57,7 @@ grpc_cc_test( deps = [ ":logging_test_library", "//:grpc++", + "//src/core:dump_args", "//src/core:logging_filter", "//src/cpp/ext/gcp:observability_logging_sink", "//src/proto/grpc/testing:echo_proto", diff --git a/test/cpp/ext/filters/logging/library.h b/test/cpp/ext/filters/logging/library.h index f1339aa177a..bce76c1a228 100644 --- a/test/cpp/ext/filters/logging/library.h +++ b/test/cpp/ext/filters/logging/library.h @@ -104,7 +104,6 @@ class LoggingTest : public ::testing::Test { protected: static void SetUpTestSuite() { g_test_logging_sink = new TestLoggingSink; - grpc::RegisterOpenCensusPlugin(); grpc_core::RegisterLoggingFilter(g_test_logging_sink); } diff --git a/test/cpp/ext/filters/logging/logging_census_integration_test.cc b/test/cpp/ext/filters/logging/logging_census_integration_test.cc index baff506f59c..b8c196d1c09 100644 --- a/test/cpp/ext/filters/logging/logging_census_integration_test.cc +++ b/test/cpp/ext/filters/logging/logging_census_integration_test.cc @@ -319,5 +319,6 @@ TEST_F(LoggingCensusIntegrationTest, Basic) { int main(int argc, char** argv) { grpc::testing::TestEnvironment env(&argc, argv); ::testing::InitGoogleTest(&argc, argv); + grpc::RegisterOpenCensusPlugin(); return RUN_ALL_TESTS(); } diff --git a/test/cpp/ext/filters/logging/logging_test.cc b/test/cpp/ext/filters/logging/logging_test.cc index 2e40e17efd8..09df6f7f906 100644 --- a/test/cpp/ext/filters/logging/logging_test.cc +++ b/test/cpp/ext/filters/logging/logging_test.cc @@ -29,6 +29,7 @@ #include #include "src/core/ext/filters/logging/logging_filter.h" +#include "src/core/lib/gprpp/dump_args.h" #include "src/core/lib/gprpp/sync.h" #include "src/cpp/ext/gcp/observability_logging_sink.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" @@ -843,7 +844,7 @@ TEST_F(LoggingTest, CancelledRpc) { break; } std::this_thread::sleep_for(std::chrono::milliseconds(10)); - EXPECT_LT(absl::Now() - initial_time, absl::Seconds(10)); + ASSERT_LT(absl::Now() - initial_time, absl::Seconds(10)); } } diff --git a/test/cpp/ext/gcp/observability_config_test.cc b/test/cpp/ext/gcp/observability_config_test.cc index 73ffe386bff..0a1f91abc38 100644 --- a/test/cpp/ext/gcp/observability_config_test.cc +++ b/test/cpp/ext/gcp/observability_config_test.cc @@ -22,9 +22,9 @@ #include #include "src/core/lib/config/core_configuration.h" -#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/env.h" #include "src/core/lib/json/json_reader.h" +#include "src/core/util/tmpfile.h" #include "test/core/test_util/test_config.h" namespace grpc { diff --git a/test/cpp/ext/otel/otel_plugin_test.cc b/test/cpp/ext/otel/otel_plugin_test.cc index af24fcabcac..4cc39847910 100644 --- a/test/cpp/ext/otel/otel_plugin_test.cc +++ b/test/cpp/ext/otel/otel_plugin_test.cc @@ -471,6 +471,28 @@ TEST_F(OpenTelemetryPluginEnd2EndTest, NoMeterProviderRegistered) { SendRPC(); } +// Test that the otel plugin sees the expected channel target and default +// authority. +TEST_F(OpenTelemetryPluginEnd2EndTest, VerifyChannelScopeTargetAndAuthority) { + Init(std::move( + Options() + .set_metric_names({grpc::OpenTelemetryPluginBuilder:: + kClientAttemptStartedInstrumentName}) + .set_channel_scope_filter( + [&](const OpenTelemetryPluginBuilder::ChannelScope& scope) { + return scope.target() == canonical_server_address_ && + scope.default_authority() == server_address_; + }))); + SendRPC(); + const char* kMetricName = "grpc.client.attempt.started"; + auto data = ReadCurrentMetricsData( + [&](const absl::flat_hash_map< + std::string, + std::vector>& + data) { return !data.contains(kMetricName); }); + ASSERT_EQ(data[kMetricName].size(), 1); +} + // Test that a channel scope filter returning true records metrics on the // channel. TEST_F(OpenTelemetryPluginEnd2EndTest, ChannelScopeFilterReturnsTrue) { @@ -1263,7 +1285,7 @@ using OpenTelemetryPluginNPCMetricsTest = OpenTelemetryPluginEnd2EndTest; TEST_F(OpenTelemetryPluginNPCMetricsTest, RecordUInt64Counter) { constexpr absl::string_view kMetricName = "uint64_counter"; - constexpr int kCounterValues[] = {1, 2, 3}; + constexpr uint64_t kCounterValues[] = {1, 2, 3}; constexpr int64_t kCounterResult = 6; constexpr std::array kLabelKeys = {"label_key_1", "label_key_2"}; @@ -1273,9 +1295,13 @@ TEST_F(OpenTelemetryPluginNPCMetricsTest, RecordUInt64Counter) { "label_value_2"}; constexpr std::array kOptionalLabelValues = { "optional_label_value_1", "optional_label_value_2"}; - auto handle = grpc_core::GlobalInstrumentsRegistry::RegisterUInt64Counter( - kMetricName, "A simple uint64 counter.", "unit", kLabelKeys, - kOptionalLabelKeys, /*enable_by_default=*/true); + auto handle = + grpc_core::GlobalInstrumentsRegistry::RegisterUInt64Counter( + kMetricName, "A simple uint64 counter.", "unit", + /*enable_by_default=*/true) + .Labels(kLabelKeys[0], kLabelKeys[1]) + .OptionalLabels(kOptionalLabelKeys[0], kOptionalLabelKeys[1]) + .Build(); Init(std::move(Options() .set_metric_names({kMetricName}) .set_channel_scope_filter( @@ -1319,9 +1345,13 @@ TEST_F(OpenTelemetryPluginNPCMetricsTest, RecordDoubleCounter) { "label_value_2"}; constexpr std::array kOptionalLabelValues = { "optional_label_value_1", "optional_label_value_2"}; - auto handle = grpc_core::GlobalInstrumentsRegistry::RegisterDoubleCounter( - kMetricName, "A simple double counter.", "unit", kLabelKeys, - kOptionalLabelKeys, /*enable_by_default=*/false); + auto handle = + grpc_core::GlobalInstrumentsRegistry::RegisterDoubleCounter( + kMetricName, "A simple double counter.", "unit", + /*enable_by_default=*/false) + .Labels(kLabelKeys[0], kLabelKeys[1]) + .OptionalLabels(kOptionalLabelKeys[0], kOptionalLabelKeys[1]) + .Build(); Init(std::move(Options() .set_metric_names({kMetricName}) .set_channel_scope_filter( @@ -1355,7 +1385,7 @@ TEST_F(OpenTelemetryPluginNPCMetricsTest, RecordDoubleCounter) { TEST_F(OpenTelemetryPluginNPCMetricsTest, RecordUInt64Histogram) { constexpr absl::string_view kMetricName = "uint64_histogram"; - constexpr int kHistogramValues[] = {1, 1, 2, 3, 4, 4, 5, 6}; + constexpr uint64_t kHistogramValues[] = {1, 1, 2, 3, 4, 4, 5, 6}; constexpr int64_t kSum = 26; constexpr int64_t kMin = 1; constexpr int64_t kMax = 6; @@ -1368,9 +1398,13 @@ TEST_F(OpenTelemetryPluginNPCMetricsTest, RecordUInt64Histogram) { "label_value_2"}; constexpr std::array kOptionalLabelValues = { "optional_label_value_1", "optional_label_value_2"}; - auto handle = grpc_core::GlobalInstrumentsRegistry::RegisterUInt64Histogram( - kMetricName, "A simple uint64 histogram.", "unit", kLabelKeys, - kOptionalLabelKeys, /*enable_by_default=*/true); + auto handle = + grpc_core::GlobalInstrumentsRegistry::RegisterUInt64Histogram( + kMetricName, "A simple uint64 histogram.", "unit", + /*enable_by_default=*/true) + .Labels(kLabelKeys[0], kLabelKeys[1]) + .OptionalLabels(kOptionalLabelKeys[0], kOptionalLabelKeys[1]) + .Build(); Init(std::move( Options() .set_metric_names({kMetricName}) @@ -1419,9 +1453,13 @@ TEST_F(OpenTelemetryPluginNPCMetricsTest, RecordDoubleHistogram) { "label_value_2"}; constexpr std::array kOptionalLabelValues = { "optional_label_value_1", "optional_label_value_2"}; - auto handle = grpc_core::GlobalInstrumentsRegistry::RegisterDoubleHistogram( - kMetricName, "A simple double histogram.", "unit", kLabelKeys, - kOptionalLabelKeys, /*enable_by_default=*/true); + auto handle = + grpc_core::GlobalInstrumentsRegistry::RegisterDoubleHistogram( + kMetricName, "A simple double histogram.", "unit", + /*enable_by_default=*/true) + .Labels(kLabelKeys[0], kLabelKeys[1]) + .OptionalLabels(kOptionalLabelKeys[0], kOptionalLabelKeys[1]) + .Build(); Init(std::move( Options() .set_metric_names({kMetricName}) @@ -1466,9 +1504,13 @@ TEST_F(OpenTelemetryPluginNPCMetricsTest, "label_value_2"}; constexpr std::array kOptionalLabelValues = { "optional_label_value_1", "optional_label_value_2"}; - auto handle = grpc_core::GlobalInstrumentsRegistry::RegisterDoubleHistogram( - kMetricName, "A simple double histogram.", "unit", kLabelKeys, - kOptionalLabelKeys, /*enable_by_default=*/true); + auto handle = + grpc_core::GlobalInstrumentsRegistry::RegisterDoubleHistogram( + kMetricName, "A simple double histogram.", "unit", + /*enable_by_default=*/true) + .Labels(kLabelKeys[0], kLabelKeys[1]) + .OptionalLabels(kOptionalLabelKeys[0], kOptionalLabelKeys[1]) + .Build(); // Build and register a separate OpenTelemetryPlugin and verify its histogram // recording. grpc::internal::OpenTelemetryPluginBuilderImpl ot_builder; @@ -1592,9 +1634,14 @@ TEST_F(OpenTelemetryPluginNPCMetricsTest, constexpr std::array kActualOptionalLabelValues = { "optional_label_value_1", "optional_label_value_2", "optional_label_value_4"}; - auto handle = grpc_core::GlobalInstrumentsRegistry::RegisterDoubleHistogram( - kMetricName, "A simple double histogram.", "unit", kLabelKeys, - kOptionalLabelKeys, /*enable_by_default=*/true); + auto handle = + grpc_core::GlobalInstrumentsRegistry::RegisterDoubleHistogram( + kMetricName, "A simple double histogram.", "unit", + /*enable_by_default=*/true) + .Labels(kLabelKeys[0], kLabelKeys[1]) + .OptionalLabels(kOptionalLabelKeys[0], kOptionalLabelKeys[1], + kOptionalLabelKeys[2], kOptionalLabelKeys[3]) + .Build(); Init(std::move( Options() .set_metric_names({kMetricName}) @@ -1655,13 +1702,17 @@ TEST_F(OpenTelemetryPluginCallbackMetricsTest, auto integer_gauge_handle = grpc_core::GlobalInstrumentsRegistry::RegisterCallbackInt64Gauge( kInt64CallbackGaugeMetric, "An int64 callback gauge.", "unit", - kLabelKeys, kOptionalLabelKeys, - /*enable_by_default=*/true); + /*enable_by_default=*/true) + .Labels(kLabelKeys[0], kLabelKeys[1]) + .OptionalLabels(kOptionalLabelKeys[0], kOptionalLabelKeys[1]) + .Build(); auto double_gauge_handle = grpc_core::GlobalInstrumentsRegistry::RegisterCallbackDoubleGauge( kDoubleCallbackGaugeMetric, "A double callback gauge.", "unit", - kLabelKeys, kOptionalLabelKeys, - /*enable_by_default=*/true); + /*enable_by_default=*/true) + .Labels(kLabelKeys[0], kLabelKeys[1]) + .OptionalLabels(kOptionalLabelKeys[0], kOptionalLabelKeys[1]) + .Build(); Init(std::move(Options() .set_metric_names({kInt64CallbackGaugeMetric, kDoubleCallbackGaugeMetric}) @@ -1671,8 +1722,8 @@ TEST_F(OpenTelemetryPluginCallbackMetricsTest, grpc_core::GlobalStatsPluginRegistry::GetStatsPluginsForChannel( grpc_core::experimental::StatsPluginChannelScope( "dns:///localhost:8080", "")); - // Multiple callbacks for the same metrics, each reporting different label - // values. + // Multiple callbacks for the same metrics, each reporting different + // label values. int report_count_1 = 0; int64_t int_value_1 = 1; double double_value_1 = 0.5; @@ -1688,8 +1739,8 @@ TEST_F(OpenTelemetryPluginCallbackMetricsTest, reporter.Report(double_gauge_handle, double_value_1++, kLabelValuesSet2, kOptionalLabelValuesSet2); }, - {integer_gauge_handle, double_gauge_handle}, - grpc_core::Duration::Milliseconds(100) * grpc_test_slowdown_factor()); + grpc_core::Duration::Milliseconds(100) * grpc_test_slowdown_factor(), + integer_gauge_handle, double_gauge_handle); int report_count_2 = 0; int64_t int_value_2 = 1; double double_value_2 = 0.5; @@ -1705,8 +1756,8 @@ TEST_F(OpenTelemetryPluginCallbackMetricsTest, reporter.Report(double_gauge_handle, double_value_2++, kLabelValuesSet2, kOptionalLabelValuesSet2); }, - {integer_gauge_handle, double_gauge_handle}, - grpc_core::Duration::Milliseconds(100) * grpc_test_slowdown_factor()); + grpc_core::Duration::Milliseconds(100) * grpc_test_slowdown_factor(), + integer_gauge_handle, double_gauge_handle); constexpr int kIterations = 100; MetricsCollectorThread collector{ this, grpc_core::Duration::Milliseconds(10) * grpc_test_slowdown_factor(), @@ -1786,13 +1837,17 @@ TEST_F(OpenTelemetryPluginCallbackMetricsTest, auto integer_gauge_handle = grpc_core::GlobalInstrumentsRegistry::RegisterCallbackInt64Gauge( kInt64CallbackGaugeMetric, "An int64 callback gauge.", "unit", - kLabelKeys, kOptionalLabelKeys, - /*enable_by_default=*/true); + /*enable_by_default=*/true) + .Labels(kLabelKeys[0], kLabelKeys[1]) + .OptionalLabels(kOptionalLabelKeys[0], kOptionalLabelKeys[1]) + .Build(); auto double_gauge_handle = grpc_core::GlobalInstrumentsRegistry::RegisterCallbackDoubleGauge( kDoubleCallbackGaugeMetric, "A double callback gauge.", "unit", - kLabelKeys, kOptionalLabelKeys, - /*enable_by_default=*/true); + /*enable_by_default=*/true) + .Labels(kLabelKeys[0], kLabelKeys[1]) + .OptionalLabels(kOptionalLabelKeys[0], kOptionalLabelKeys[1]) + .Build(); Init(std::move(Options() .set_metric_names({kInt64CallbackGaugeMetric, kDoubleCallbackGaugeMetric}) @@ -1802,8 +1857,8 @@ TEST_F(OpenTelemetryPluginCallbackMetricsTest, grpc_core::GlobalStatsPluginRegistry::GetStatsPluginsForChannel( grpc_core::experimental::StatsPluginChannelScope( "dns:///localhost:8080", "")); - // Multiple callbacks for the same metrics, each reporting different label - // values. + // Multiple callbacks for the same metrics, each reporting different + // label values. int report_count_1 = 0; int64_t int_value_1 = 1; double double_value_1 = 0.5; @@ -1819,8 +1874,8 @@ TEST_F(OpenTelemetryPluginCallbackMetricsTest, reporter.Report(double_gauge_handle, double_value_1++, kLabelValuesSet2, kOptionalLabelValuesSet2); }, - {integer_gauge_handle, double_gauge_handle}, - grpc_core::Duration::Milliseconds(10) * grpc_test_slowdown_factor()); + grpc_core::Duration::Milliseconds(10) * grpc_test_slowdown_factor(), + integer_gauge_handle, double_gauge_handle); int report_count_2 = 0; int64_t int_value_2 = 1; double double_value_2 = 0.5; @@ -1836,8 +1891,8 @@ TEST_F(OpenTelemetryPluginCallbackMetricsTest, reporter.Report(double_gauge_handle, double_value_2++, kLabelValuesSet2, kOptionalLabelValuesSet2); }, - {integer_gauge_handle, double_gauge_handle}, - grpc_core::Duration::Milliseconds(10) * grpc_test_slowdown_factor()); + grpc_core::Duration::Milliseconds(10) * grpc_test_slowdown_factor(), + integer_gauge_handle, double_gauge_handle); constexpr int kIterations = 100; MetricsCollectorThread collector{ this, @@ -1854,7 +1909,8 @@ TEST_F(OpenTelemetryPluginCallbackMetricsTest, std::string, std::vector> data = collector.Stop(); - // Verify that data is incremental without duplications (cached values). + // Verify that data is incremental without duplications (cached + // values). EXPECT_EQ(report_count_1, kIterations); EXPECT_EQ(report_count_2, kIterations); EXPECT_EQ(data[kInt64CallbackGaugeMetric].size(), diff --git a/test/cpp/interop/BUILD b/test/cpp/interop/BUILD index 76b49f88be9..21d86d04971 100644 --- a/test/cpp/interop/BUILD +++ b/test/cpp/interop/BUILD @@ -46,6 +46,7 @@ grpc_cc_binary( external_deps = [ "absl/flags:flag", "absl/log:check", + "absl/log:log", "absl/time:time", ], language = "C++", @@ -429,6 +430,7 @@ grpc_cc_binary( external_deps = [ "absl/flags:flag", "absl/log:check", + "absl/log:log", ], deps = [ "//:grpc++", diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index 866f4f67129..7d5a9dad71c 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -28,8 +28,8 @@ #include #include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" +#include "src/core/util/string.h" #include "test/core/test_util/test_config.h" #include "test/cpp/interop/client_helper.h" #include "test/cpp/interop/interop_client.h" diff --git a/test/cpp/interop/grpclb_fallback_test.cc b/test/cpp/interop/grpclb_fallback_test.cc index c8e20fdc54e..594c5b6b39b 100644 --- a/test/cpp/interop/grpclb_fallback_test.cc +++ b/test/cpp/interop/grpclb_fallback_test.cc @@ -32,21 +32,21 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include "absl/time/time.h" #include -#include #include #include #include #include #include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/port.h" #include "src/core/lib/iomgr/socket_mutator.h" +#include "src/core/util/string.h" #include "src/proto/grpc/testing/empty.pb.h" #include "src/proto/grpc/testing/messages.pb.h" #include "src/proto/grpc/testing/test.grpc.pb.h" @@ -87,8 +87,8 @@ enum RpcMode { GrpclbRouteType DoRPCAndGetPath(TestService::Stub* stub, int deadline_seconds, RpcMode rpc_mode) { - gpr_log(GPR_INFO, "DoRPCAndGetPath deadline_seconds:%d rpc_mode:%d", - deadline_seconds, rpc_mode); + LOG(INFO) << "DoRPCAndGetPath deadline_seconds:" << deadline_seconds + << " rpc_mode:" << rpc_mode; SimpleRequest request; SimpleResponse response; grpc::ClientContext context; @@ -101,16 +101,16 @@ GrpclbRouteType DoRPCAndGetPath(TestService::Stub* stub, int deadline_seconds, context.set_deadline(deadline); grpc::Status s = stub->UnaryCall(&context, request, &response); if (!s.ok()) { - gpr_log(GPR_INFO, "DoRPCAndGetPath failed. status-message: %s", - s.error_message().c_str()); + LOG(INFO) << "DoRPCAndGetPath failed. status-message: " + << s.error_message(); return GrpclbRouteType::GRPCLB_ROUTE_TYPE_UNKNOWN; } CHECK(response.grpclb_route_type() == GrpclbRouteType::GRPCLB_ROUTE_TYPE_BACKEND || response.grpclb_route_type() == GrpclbRouteType::GRPCLB_ROUTE_TYPE_FALLBACK); - gpr_log(GPR_INFO, "DoRPCAndGetPath done. grpclb_route_type:%d", - response.grpclb_route_type()); + LOG(INFO) << "DoRPCAndGetPath done. grpclb_route_type:" + << response.grpclb_route_type(); return response.grpclb_route_type(); } @@ -120,7 +120,7 @@ GrpclbRouteType DoRPCAndGetPath(TestService::Stub* stub, int deadline_seconds) { bool TcpUserTimeoutMutateFd(int fd, grpc_socket_mutator* /*mutator*/) { int timeout = 20000; // 20 seconds - gpr_log(GPR_INFO, "Setting socket option TCP_USER_TIMEOUT on fd: %d", fd); + LOG(INFO) << "Setting socket option TCP_USER_TIMEOUT on fd: " << fd; if (0 != setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout, sizeof(timeout))) { grpc_core::Crash("Failed to set socket option TCP_USER_TIMEOUT"); @@ -161,7 +161,7 @@ std::unique_ptr CreateFallbackTestStub() { } void RunCommand(const std::string& command) { - gpr_log(GPR_INFO, "RunCommand: |%s|", command.c_str()); + LOG(INFO) << "RunCommand: |" << command << "|"; int out = std::system(command.c_str()); if (WIFEXITED(out)) { int code = WEXITSTATUS(out); @@ -185,25 +185,23 @@ void WaitForFallbackAndDoRPCs(TestService::Stub* stub) { while (absl::Now() < fallback_deadline) { GrpclbRouteType grpclb_route_type = DoRPCAndGetPath(stub, 1); if (grpclb_route_type == GrpclbRouteType::GRPCLB_ROUTE_TYPE_BACKEND) { - gpr_log(GPR_ERROR, - "Got grpclb route type backend. Backends are " - "supposed to be unreachable, so this test is broken"); + LOG(ERROR) << "Got grpclb route type backend. Backends are " + "supposed to be unreachable, so this test is broken"; CHECK(0); } if (grpclb_route_type == GrpclbRouteType::GRPCLB_ROUTE_TYPE_FALLBACK) { - gpr_log(GPR_INFO, - "Made one successful RPC to a fallback. Now expect the same for " - "the rest."); + LOG(INFO) << "Made one successful RPC to a fallback. Now expect the same " + "for the rest."; fallback = true; break; } else { - gpr_log(GPR_ERROR, "Retryable RPC failure on iteration: %d", - fallback_retry_count); + LOG(ERROR) << "Retryable RPC failure on iteration: " + << fallback_retry_count; } fallback_retry_count++; } if (!fallback) { - gpr_log(GPR_ERROR, "Didn't fall back within deadline"); + LOG(ERROR) << "Didn't fall back within deadline"; CHECK(0); } for (int i = 0; i < 30; i++) { @@ -231,13 +229,13 @@ void DoFallbackAfterStartupTest() { int main(int argc, char** argv) { grpc::testing::InitTest(&argc, &argv, true); - gpr_log(GPR_INFO, "Testing: %s", absl::GetFlag(FLAGS_test_case).c_str()); + LOG(INFO) << "Testing: " << absl::GetFlag(FLAGS_test_case); if (absl::GetFlag(FLAGS_test_case) == "fallback_before_startup") { DoFallbackBeforeStartupTest(); - gpr_log(GPR_INFO, "DoFallbackBeforeStartup done!"); + LOG(INFO) << "DoFallbackBeforeStartup done!"; } else if (absl::GetFlag(FLAGS_test_case) == "fallback_after_startup") { DoFallbackAfterStartupTest(); - gpr_log(GPR_INFO, "DoFallbackBeforeStartup done!"); + LOG(INFO) << "DoFallbackBeforeStartup done!"; } else { grpc_core::Crash(absl::StrFormat("Invalid test case: %s", absl::GetFlag(FLAGS_test_case).c_str())); diff --git a/test/cpp/interop/http2_client.cc b/test/cpp/interop/http2_client.cc index eb96a08b715..62c728d4c78 100644 --- a/test/cpp/interop/http2_client.cc +++ b/test/cpp/interop/http2_client.cc @@ -22,16 +22,16 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include -#include #include #include -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" +#include "src/core/util/string.h" +#include "src/core/util/useful.h" #include "src/proto/grpc/testing/messages.pb.h" #include "src/proto/grpc/testing/test.grpc.pb.h" #include "test/cpp/util/create_test_channel.h" @@ -81,40 +81,40 @@ SimpleRequest Http2Client::BuildDefaultRequest() { } bool Http2Client::DoRstAfterHeader() { - gpr_log(GPR_DEBUG, "Sending RPC and expecting reset stream after header"); + VLOG(2) << "Sending RPC and expecting reset stream after header"; SimpleResponse response; AssertStatusCode(SendUnaryCall(&response), grpc::StatusCode::INTERNAL); CHECK(!response.has_payload()); // no data should be received - gpr_log(GPR_DEBUG, "Done testing reset stream after header"); + VLOG(2) << "Done testing reset stream after header"; return true; } bool Http2Client::DoRstAfterData() { - gpr_log(GPR_DEBUG, "Sending RPC and expecting reset stream after data"); + VLOG(2) << "Sending RPC and expecting reset stream after data"; SimpleResponse response; AssertStatusCode(SendUnaryCall(&response), grpc::StatusCode::INTERNAL); // There is no guarantee that data would be received. - gpr_log(GPR_DEBUG, "Done testing reset stream after data"); + VLOG(2) << "Done testing reset stream after data"; return true; } bool Http2Client::DoRstDuringData() { - gpr_log(GPR_DEBUG, "Sending RPC and expecting reset stream during data"); + VLOG(2) << "Sending RPC and expecting reset stream during data"; SimpleResponse response; AssertStatusCode(SendUnaryCall(&response), grpc::StatusCode::INTERNAL); CHECK(!response.has_payload()); // no data should be received - gpr_log(GPR_DEBUG, "Done testing reset stream during data"); + VLOG(2) << "Done testing reset stream during data"; return true; } bool Http2Client::DoGoaway() { - gpr_log(GPR_DEBUG, "Sending two RPCs and expecting goaway"); + VLOG(2) << "Sending two RPCs and expecting goaway"; SimpleResponse response; AssertStatusCode(SendUnaryCall(&response), grpc::StatusCode::OK); CHECK(response.payload().body() == std::string(kLargeResponseSize, '\0')); @@ -127,16 +127,16 @@ bool Http2Client::DoGoaway() { response.Clear(); AssertStatusCode(SendUnaryCall(&response), grpc::StatusCode::OK); CHECK(response.payload().body() == std::string(kLargeResponseSize, '\0')); - gpr_log(GPR_DEBUG, "Done testing goaway"); + VLOG(2) << "Done testing goaway"; return true; } bool Http2Client::DoPing() { - gpr_log(GPR_DEBUG, "Sending RPC and expecting ping"); + VLOG(2) << "Sending RPC and expecting ping"; SimpleResponse response; AssertStatusCode(SendUnaryCall(&response), grpc::StatusCode::OK); CHECK(response.payload().body() == std::string(kLargeResponseSize, '\0')); - gpr_log(GPR_DEBUG, "Done testing ping"); + VLOG(2) << "Done testing ping"; return true; } @@ -148,7 +148,7 @@ void Http2Client::MaxStreamsWorker( } bool Http2Client::DoMaxStreams() { - gpr_log(GPR_DEBUG, "Testing max streams"); + VLOG(2) << "Testing max streams"; // Make an initial call on the channel to ensure the server's max streams // setting is received @@ -167,7 +167,7 @@ bool Http2Client::DoMaxStreams() { it->join(); } - gpr_log(GPR_DEBUG, "Done testing max streams"); + VLOG(2) << "Done testing max streams"; return true; } @@ -198,7 +198,7 @@ int main(int argc, char** argv) { CHECK(channel->WaitForConnected(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(300, GPR_TIMESPAN)))); grpc::testing::Http2Client client(channel); - gpr_log(GPR_INFO, "Testing case: %s", absl::GetFlag(FLAGS_test_case).c_str()); + LOG(INFO) << "Testing case: " << absl::GetFlag(FLAGS_test_case); int ret = 0; if (absl::GetFlag(FLAGS_test_case) == "rst_after_header") { client.DoRstAfterHeader(); @@ -219,8 +219,9 @@ int main(int argc, char** argv) { char* joined_testcases = gpr_strjoin_sep(testcases, GPR_ARRAY_SIZE(testcases), "\n", nullptr); - gpr_log(GPR_ERROR, "Unsupported test case %s. Valid options are\n%s", - absl::GetFlag(FLAGS_test_case).c_str(), joined_testcases); + LOG(ERROR) << "Unsupported test case " << absl::GetFlag(FLAGS_test_case) + << ". Valid options are\n" + << joined_testcases; gpr_free(joined_testcases); ret = 1; } diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index 26c51b9869a..fb7d3430107 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -23,9 +23,9 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include -#include #include #include #include @@ -35,9 +35,9 @@ #include #include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/sync.h" +#include "src/core/util/string.h" #include "src/proto/grpc/testing/empty.pb.h" #include "src/proto/grpc/testing/messages.pb.h" #include "src/proto/grpc/testing/test.grpc.pb.h" @@ -119,22 +119,20 @@ bool CheckExpectedCompression(const ServerContext& context, if (compression_expected) { if (received_compression == GRPC_COMPRESS_NONE) { // Expected some compression, got NONE. This is an error. - gpr_log(GPR_ERROR, - "Expected compression but got uncompressed request from client."); + LOG(ERROR) + << "Expected compression but got uncompressed request from client."; return false; } if (!(inspector.WasCompressed())) { - gpr_log(GPR_ERROR, - "Failure: Requested compression in a compressable request, but " - "compression bit in message flags not set."); + LOG(ERROR) << "Failure: Requested compression in a compressable request, " + "but compression bit in message flags not set."; return false; } } else { // Didn't expect compression -> make sure the request is uncompressed if (inspector.WasCompressed()) { - gpr_log(GPR_ERROR, - "Failure: Didn't requested compression, but compression bit in " - "message flags set."); + LOG(ERROR) << "Failure: Didn't requested compression, but compression " + "bit in message flags set."; return false; } } @@ -197,8 +195,9 @@ class TestServiceImpl : public TestService::Service { MaybeEchoMetadata(context); if (request->has_response_compressed()) { const bool compression_requested = request->response_compressed().value(); - gpr_log(GPR_DEBUG, "Request for compression (%s) present for %s", - compression_requested ? "enabled" : "disabled", __func__); + VLOG(2) << "Request for compression (" + << (compression_requested ? "enabled" : "disabled") + << ") present for " << __func__; if (compression_requested) { // Any level would do, let's go for HIGH because we are overachievers. context->set_compression_level(GRPC_COMPRESS_LEVEL_HIGH); @@ -247,8 +246,9 @@ class TestServiceImpl : public TestService::Service { context->set_compression_level(GRPC_COMPRESS_LEVEL_HIGH); const bool compression_requested = request->response_parameters(i).compressed().value(); - gpr_log(GPR_DEBUG, "Request for compression (%s) present for %s", - compression_requested ? "enabled" : "disabled", __func__); + VLOG(2) << "Request for compression (" + << (compression_requested ? "enabled" : "disabled") + << ") present for " << __func__; if (!compression_requested) { wopts.set_no_compression(); } // else, compression is already enabled via the context. @@ -445,7 +445,7 @@ void grpc::testing::interop::RunServer( grpc::ServerBuilder::experimental_type(&builder).EnableCallMetricRecording( nullptr); std::unique_ptr server(builder.BuildAndStart()); - gpr_log(GPR_INFO, "Server listening on %s", server_address.str().c_str()); + LOG(INFO) << "Server listening on " << server_address.str(); // Signal that the server has started. if (server_started_condition) { diff --git a/test/cpp/interop/interop_test.cc b/test/cpp/interop/interop_test.cc index b1e9deaf78e..d46e2a531cd 100644 --- a/test/cpp/interop/interop_test.cc +++ b/test/cpp/interop/interop_test.cc @@ -29,14 +29,14 @@ #include #include "absl/flags/flag.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include -#include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/socket_utils_posix.h" +#include "src/core/util/string.h" #include "test/core/test_util/port.h" #include "test/cpp/util/test_config.h" @@ -65,7 +65,7 @@ int test_client(const char* root, const char* host, int port) { return 1; } // wait for client - gpr_log(GPR_INFO, "Waiting for client: %s", host); + LOG(INFO) << "Waiting for client: " << host; if (waitpid(cli, &status, 0) == -1) return 2; if (!WIFEXITED(status)) return 4; if (WEXITSTATUS(status)) return WEXITSTATUS(status); @@ -86,7 +86,7 @@ int main(int argc, char** argv) { // concurrently running test binary srand(getpid()); if (!grpc_ipv6_loopback_available()) { - gpr_log(GPR_INFO, "Can't bind to ::1. Skipping IPv6 tests."); + LOG(INFO) << "Can't bind to ::1. Skipping IPv6 tests."; do_ipv6 = 0; } // figure out where we are @@ -126,7 +126,7 @@ int main(int argc, char** argv) { if (ret != 0) return ret; } // wait for server - gpr_log(GPR_INFO, "Waiting for server"); + LOG(INFO) << "Waiting for server"; kill(svr, SIGINT); if (waitpid(svr, &status, 0) == -1) return 2; if (!WIFEXITED(status)) return 4; diff --git a/test/cpp/interop/observability_client.cc b/test/cpp/interop/observability_client.cc index 0fe08d242dc..247ab1d1738 100644 --- a/test/cpp/interop/observability_client.cc +++ b/test/cpp/interop/observability_client.cc @@ -20,20 +20,20 @@ #include #include "absl/flags/flag.h" +#include "absl/log/log.h" #include "opentelemetry/exporters/prometheus/exporter_factory.h" #include "opentelemetry/exporters/prometheus/exporter_options.h" #include "opentelemetry/sdk/metrics/meter_provider.h" #include #include -#include #include #include #include #include -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" +#include "src/core/util/string.h" #include "test/core/test_util/test_config.h" #include "test/cpp/interop/client_helper.h" #include "test/cpp/interop/interop_client.h" @@ -160,8 +160,8 @@ bool ParseAdditionalMetadataFlag( while (start_pos < flag.length()) { size_t colon_pos = flag.find(':', start_pos); if (colon_pos == std::string::npos) { - gpr_log(GPR_ERROR, - "Couldn't parse metadata flag: extra characters at end of flag"); + LOG(ERROR) + << "Couldn't parse metadata flag: extra characters at end of flag"; return false; } size_t semicolon_pos = flag.find(';', colon_pos); @@ -175,10 +175,9 @@ bool ParseAdditionalMetadataFlag( "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; if (key.find_first_not_of(alphanum_and_hyphen) != std::string::npos) { - gpr_log(GPR_ERROR, - "Couldn't parse metadata flag: key contains characters other " - "than alphanumeric and hyphens: %s", - key.c_str()); + LOG(ERROR) << "Couldn't parse metadata flag: key contains characters " + "other than alphanumeric and hyphens: " + << key; return false; } @@ -189,8 +188,8 @@ bool ParseAdditionalMetadataFlag( } } - gpr_log(GPR_INFO, "Adding additional metadata with key %s and value %s", - key.c_str(), value.c_str()); + LOG(INFO) << "Adding additional metadata with key " << key << " and value " + << value; additional_metadata->insert({key, value}); if (semicolon_pos == std::string::npos) { @@ -208,15 +207,14 @@ bool ParseAdditionalMetadataFlag( int main(int argc, char** argv) { grpc::testing::TestEnvironment env(&argc, argv); grpc::testing::InitTest(&argc, &argv, true); - gpr_log(GPR_INFO, "Testing these cases: %s", - absl::GetFlag(FLAGS_test_case).c_str()); + LOG(INFO) << "Testing these cases: " << absl::GetFlag(FLAGS_test_case); int ret = 0; if (absl::GetFlag(FLAGS_enable_observability)) { // TODO(someone): remove deprecated usage // NOLINTNEXTLINE(clang-diagnostic-deprecated-declarations) auto status = grpc::experimental::GcpObservabilityInit(); - gpr_log(GPR_DEBUG, "GcpObservabilityInit() status_code: %d", status.code()); + VLOG(2) << "GcpObservabilityInit() status_code: " << status.code(); if (!status.ok()) { return 1; } @@ -225,7 +223,7 @@ int main(int argc, char** argv) { // TODO(stanleycheung): switch to CsmObservabilityBuilder once xds setup is // ready if (absl::GetFlag(FLAGS_enable_otel_plugin)) { - gpr_log(GPR_DEBUG, "Registering Prometheus exporter"); + VLOG(2) << "Registering Prometheus exporter"; opentelemetry::exporter::metrics::PrometheusExporterOptions opts; // default was "localhost:9464" which causes connection issue across GKE // pods @@ -389,8 +387,9 @@ int main(int argc, char** argv) { if (!test_cases.empty()) test_cases += "\n"; test_cases += action.first; } - gpr_log(GPR_ERROR, "Unsupported test case %s. Valid options are\n%s", - absl::GetFlag(FLAGS_test_case).c_str(), test_cases.c_str()); + LOG(ERROR) << "Unsupported test case " << absl::GetFlag(FLAGS_test_case) + << ". Valid options are\n" + << test_cases; ret = 1; } diff --git a/test/cpp/interop/reconnect_interop_client.cc b/test/cpp/interop/reconnect_interop_client.cc index cf658db0414..bdc7b27aa07 100644 --- a/test/cpp/interop/reconnect_interop_client.cc +++ b/test/cpp/interop/reconnect_interop_client.cc @@ -21,9 +21,9 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include -#include #include #include #include @@ -76,7 +76,7 @@ int main(int argc, char** argv) { control_stub->Start(&start_context, reconnect_params, &empty_response); CHECK(start_status.ok()); - gpr_log(GPR_INFO, "Starting connections with retries."); + LOG(INFO) << "Starting connections with retries."; server_address.str(""); server_address << absl::GetFlag(FLAGS_server_host) << ':' << absl::GetFlag(FLAGS_server_retry_port); @@ -100,13 +100,13 @@ int main(int argc, char** argv) { Status retry_status = retry_stub->Start(&retry_context, reconnect_params, &empty_response); CHECK(retry_status.error_code() == grpc::StatusCode::DEADLINE_EXCEEDED); - gpr_log(GPR_INFO, "Done retrying, getting final data from server"); + LOG(INFO) << "Done retrying, getting final data from server"; ClientContext stop_context; ReconnectInfo response; Status stop_status = control_stub->Stop(&stop_context, Empty(), &response); CHECK(stop_status.ok()); CHECK(response.passed() == true); - gpr_log(GPR_INFO, "Passed"); + LOG(INFO) << "Passed"; return 0; } diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc index 1e1b6ffe0bd..b37c608a369 100644 --- a/test/cpp/interop/stress_test.cc +++ b/test/cpp/interop/stress_test.cc @@ -24,8 +24,8 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" -#include #include #include #include @@ -176,7 +176,7 @@ bool ParseTestCasesString(const std::string& test_cases, // Token is in the form : size_t colon_pos = it->find(':'); if (colon_pos == std::string::npos) { - gpr_log(GPR_ERROR, "Error in parsing test case string: %s", it->c_str()); + LOG(ERROR) << "Error in parsing test case string: " << it->c_str(); is_success = false; break; } @@ -185,7 +185,7 @@ bool ParseTestCasesString(const std::string& test_cases, int weight = std::stoi(it->substr(colon_pos + 1)); TestCaseType test_case = GetTestTypeFromName(test_name); if (test_case == UNKNOWN_TEST) { - gpr_log(GPR_ERROR, "Unknown test case: %s", test_name.c_str()); + LOG(ERROR) << "Unknown test case: " << test_name; is_success = false; break; } @@ -199,33 +199,32 @@ bool ParseTestCasesString(const std::string& test_cases, // For debugging purposes void LogParameterInfo(const std::vector& addresses, const std::vector>& tests) { - gpr_log(GPR_INFO, "server_addresses: %s", - absl::GetFlag(FLAGS_server_addresses).c_str()); - gpr_log(GPR_INFO, "test_cases : %s", absl::GetFlag(FLAGS_test_cases).c_str()); - gpr_log(GPR_INFO, "sleep_duration_ms: %d", - absl::GetFlag(FLAGS_sleep_duration_ms)); - gpr_log(GPR_INFO, "test_duration_secs: %d", - absl::GetFlag(FLAGS_test_duration_secs)); - gpr_log(GPR_INFO, "num_channels_per_server: %d", - absl::GetFlag(FLAGS_num_channels_per_server)); - gpr_log(GPR_INFO, "num_stubs_per_channel: %d", - absl::GetFlag(FLAGS_num_stubs_per_channel)); - gpr_log(GPR_INFO, "log_level: %d", absl::GetFlag(FLAGS_log_level)); - gpr_log(GPR_INFO, "do_not_abort_on_transient_failures: %s", - absl::GetFlag(FLAGS_do_not_abort_on_transient_failures) ? "true" - : "false"); + LOG(INFO) << "server_addresses: " << absl::GetFlag(FLAGS_server_addresses); + LOG(INFO) << "test_cases : " << absl::GetFlag(FLAGS_test_cases); + LOG(INFO) << "sleep_duration_ms: " << absl::GetFlag(FLAGS_sleep_duration_ms); + LOG(INFO) << "test_duration_secs: " + << absl::GetFlag(FLAGS_test_duration_secs); + LOG(INFO) << "num_channels_per_server: " + << absl::GetFlag(FLAGS_num_channels_per_server); + LOG(INFO) << "num_stubs_per_channel: " + << absl::GetFlag(FLAGS_num_stubs_per_channel); + LOG(INFO) << "log_level: " << absl::GetFlag(FLAGS_log_level); + LOG(INFO) << "do_not_abort_on_transient_failures: " + << (absl::GetFlag(FLAGS_do_not_abort_on_transient_failures) + ? "true" + : "false"); int num = 0; for (auto it = addresses.begin(); it != addresses.end(); it++) { - gpr_log(GPR_INFO, "%d:%s", ++num, it->c_str()); + LOG(INFO) << ++num << ":" << it->c_str(); } num = 0; for (auto it = tests.begin(); it != tests.end(); it++) { TestCaseType test_case = it->first; int weight = it->second; - gpr_log(GPR_INFO, "%d. TestCaseType: %d, Weight: %d", ++num, test_case, - weight); + LOG(INFO) << ++num << ". TestCaseType: " << test_case + << ", Weight: " << weight; } } @@ -234,8 +233,8 @@ int main(int argc, char** argv) { if (absl::GetFlag(FLAGS_log_level) > GPR_LOG_SEVERITY_ERROR || absl::GetFlag(FLAGS_log_level) < GPR_LOG_SEVERITY_DEBUG) { - gpr_log(GPR_ERROR, "log_level should be an integer between %d and %d", - GPR_LOG_SEVERITY_DEBUG, GPR_LOG_SEVERITY_ERROR); + LOG(ERROR) << "log_level should be an integer between " + << GPR_LOG_SEVERITY_DEBUG << " and " << GPR_LOG_SEVERITY_ERROR; return 1; } @@ -253,14 +252,14 @@ int main(int argc, char** argv) { // Parse test cases and weights if (absl::GetFlag(FLAGS_test_cases).length() == 0) { - gpr_log(GPR_ERROR, "No test cases supplied"); + LOG(ERROR) << "No test cases supplied"; return 1; } std::vector> tests; if (!ParseTestCasesString(absl::GetFlag(FLAGS_test_cases), tests)) { - gpr_log(GPR_ERROR, "Error in parsing test cases string %s ", - absl::GetFlag(FLAGS_test_cases).c_str()); + LOG(ERROR) << "Error in parsing test cases string " + << absl::GetFlag(FLAGS_test_cases); return 1; } @@ -269,7 +268,7 @@ int main(int argc, char** argv) { WeightedRandomTestSelector test_selector(tests); MetricsServiceImpl metrics_service; - gpr_log(GPR_INFO, "Starting test(s).."); + LOG(INFO) << "Starting test(s).."; std::vector test_threads; std::vector> clients; @@ -295,8 +294,8 @@ int main(int argc, char** argv) { for (int channel_idx = 0; channel_idx < absl::GetFlag(FLAGS_num_channels_per_server); channel_idx++) { - gpr_log(GPR_INFO, "Starting test with %s channel_idx=%d..", it->c_str(), - channel_idx); + LOG(INFO) << "Starting test with " << it->c_str() + << " channel_idx=" << channel_idx << ".."; grpc::testing::ChannelCreationFunc channel_creation_func = std::bind(static_cast (*)( const std::string&, const std::string&, diff --git a/test/cpp/interop/xds_federation_client.cc b/test/cpp/interop/xds_federation_client.cc index 3de9b2b5f68..8c8c4ffc6b7 100644 --- a/test/cpp/interop/xds_federation_client.cc +++ b/test/cpp/interop/xds_federation_client.cc @@ -21,13 +21,13 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_split.h" #include #include -#include -#include "src/core/lib/gpr/string.h" +#include "src/core/util/string.h" #include "test/core/test_util/test_config.h" #include "test/cpp/interop/client_helper.h" #include "test/cpp/interop/interop_client.h" @@ -74,8 +74,7 @@ ABSL_FLAG(std::string, test_case, "rpc_soak", int main(int argc, char** argv) { grpc::testing::TestEnvironment env(&argc, argv); grpc::testing::InitTest(&argc, &argv, true); - gpr_log(GPR_INFO, "Testing these cases: %s", - absl::GetFlag(FLAGS_test_case).c_str()); + LOG(INFO) << "Testing these cases: " << absl::GetFlag(FLAGS_test_case); std::string test_case = absl::GetFlag(FLAGS_test_case); // validate flags std::vector uris = @@ -83,14 +82,13 @@ int main(int argc, char** argv) { std::vector creds = absl::StrSplit(absl::GetFlag(FLAGS_credentials_types), ','); if (uris.size() != creds.size()) { - gpr_log(GPR_ERROR, - "Number of entries in --server_uris %ld != number of entries in " - "--credentials_types %ld", - uris.size(), creds.size()); + LOG(ERROR) << "Number of entries in --server_uris " << uris.size() + << " != number of entries in --credentials_types " + << creds.size(); CHECK(0); } if (uris.empty()) { - gpr_log(GPR_ERROR, "--server_uris has zero entries"); + LOG(ERROR) << "--server_uris has zero entries"; CHECK(0); } // construct and start clients @@ -121,8 +119,8 @@ int main(int argc, char** argv) { absl::GetFlag(FLAGS_soak_request_size), absl::GetFlag(FLAGS_soak_response_size)); } else { - gpr_log(GPR_ERROR, - "Invalid test case, must be either rpc_soak or channel_soak"); + LOG(ERROR) + << "Invalid test case, must be either rpc_soak or channel_soak"; CHECK(0); } })); @@ -130,6 +128,6 @@ int main(int argc, char** argv) { for (auto& thd : threads) { thd.join(); } - gpr_log(GPR_INFO, "All clients done!"); + LOG(INFO) << "All clients done!"; return 0; } diff --git a/test/cpp/interop/xds_interop_client.cc b/test/cpp/interop/xds_interop_client.cc index c539a9bdc82..8480c24691d 100644 --- a/test/cpp/interop/xds_interop_client.cc +++ b/test/cpp/interop/xds_interop_client.cc @@ -33,6 +33,7 @@ #include "absl/algorithm/container.h" #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_split.h" #include "opentelemetry/exporters/prometheus/exporter_factory.h" #include "opentelemetry/exporters/prometheus/exporter_options.h" @@ -354,15 +355,11 @@ class XdsUpdateClientConfigureServiceImpl } if (request_payload_size > 0 && config.type == ClientConfigureRequest::EMPTY_CALL) { - gpr_log(GPR_ERROR, - "request_payload_size should not be set " - "for EMPTY_CALL"); + LOG(ERROR) << "request_payload_size should not be set for EMPTY_CALL"; } if (response_payload_size > 0 && config.type == ClientConfigureRequest::EMPTY_CALL) { - gpr_log(GPR_ERROR, - "response_payload_size should not be set " - "for EMPTY_CALL"); + LOG(ERROR) << "response_payload_size should not be set for EMPTY_CALL"; } config.request_payload_size = request_payload_size; std::string payload(config.request_payload_size, '0'); @@ -429,7 +426,7 @@ void RunTestLoop(std::chrono::duration duration_per_query, } grpc::CsmObservability EnableCsmObservability() { - gpr_log(GPR_DEBUG, "Registering Prometheus exporter"); + VLOG(2) << "Registering Prometheus exporter"; opentelemetry::exporter::metrics::PrometheusExporterOptions opts; // default was "localhost:9464" which causes connection issue across GKE // pods @@ -463,7 +460,7 @@ void RunServer(const int port, StatsWatchers* stats_watchers, builder.AddListeningPort(server_address.str(), grpc::InsecureServerCredentials()); std::unique_ptr server(builder.BuildAndStart()); - gpr_log(GPR_DEBUG, "Server listening on %s", server_address.str().c_str()); + VLOG(2) << "Server listening on " << server_address.str(); server->Wait(); } @@ -513,15 +510,11 @@ void BuildRpcConfigsFromFlags(RpcConfigurationsQueue* rpc_configs_queue) { } if (request_payload_size > 0 && config.type == ClientConfigureRequest::EMPTY_CALL) { - gpr_log(GPR_ERROR, - "request_payload_size should not be set " - "for EMPTY_CALL"); + LOG(ERROR) << "request_payload_size should not be set for EMPTY_CALL"; } if (response_payload_size > 0 && config.type == ClientConfigureRequest::EMPTY_CALL) { - gpr_log(GPR_ERROR, - "response_payload_size should not be set " - "for EMPTY_CALL"); + LOG(ERROR) << "response_payload_size should not be set for EMPTY_CALL"; } config.request_payload_size = request_payload_size; std::string payload(config.request_payload_size, '0'); diff --git a/test/cpp/interop/xds_interop_server.cc b/test/cpp/interop/xds_interop_server.cc index 27b6317b4a3..ecb951e64c0 100644 --- a/test/cpp/interop/xds_interop_server.cc +++ b/test/cpp/interop/xds_interop_server.cc @@ -19,6 +19,7 @@ #include #include "absl/flags/flag.h" +#include "absl/log/log.h" #include "opentelemetry/exporters/prometheus/exporter_factory.h" #include "opentelemetry/exporters/prometheus/exporter_options.h" #include "opentelemetry/sdk/metrics/meter_provider.h" @@ -44,7 +45,7 @@ ABSL_FLAG(bool, enable_csm_observability, false, "Whether to enable CSM Observability"); grpc::CsmObservability EnableCsmObservability() { - gpr_log(GPR_DEBUG, "Registering Prometheus exporter"); + VLOG(2) << "Registering Prometheus exporter"; opentelemetry::exporter::metrics::PrometheusExporterOptions opts; // default was "localhost:9464" which causes connection issue across GKE // pods diff --git a/test/cpp/microbenchmarks/bm_closure.cc b/test/cpp/microbenchmarks/bm_closure.cc index 923bdb871ca..1622cc2fc93 100644 --- a/test/cpp/microbenchmarks/bm_closure.cc +++ b/test/cpp/microbenchmarks/bm_closure.cc @@ -24,10 +24,10 @@ #include -#include "src/core/lib/gpr/spinlock.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/combiner.h" #include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/util/spinlock.h" #include "test/core/test_util/test_config.h" #include "test/cpp/microbenchmarks/helpers.h" #include "test/cpp/util/test_config.h" diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc index efcb40a8d94..e0144995e0d 100644 --- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc +++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc @@ -23,10 +23,10 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include #include -#include #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/time.h" @@ -77,7 +77,7 @@ static grpc_error_handle pollset_work(grpc_pollset* ps, grpc_pollset_worker** /*worker*/, grpc_core::Timestamp deadline) { if (deadline == grpc_core::Timestamp::ProcessEpoch()) { - gpr_log(GPR_DEBUG, "no-op"); + VLOG(2) << "no-op"; return absl::OkStatus(); } diff --git a/test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong_chaotic_good.cc b/test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong_chaotic_good.cc index 04a8f010cd5..b79df3ed4d1 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong_chaotic_good.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong_chaotic_good.cc @@ -111,7 +111,6 @@ int main(int argc, char** argv) { grpc_core::ForceEnableExperiment("event_engine_client", true); grpc_core::ForceEnableExperiment("event_engine_listener", true); grpc_core::ForceEnableExperiment("promise_based_client_call", true); - grpc_core::ForceEnableExperiment("promise_based_server_call", true); grpc_core::ForceEnableExperiment("chaotic_good", true); grpc::testing::TestEnvironment env(&argc, argv); LibraryInitializer libInit; diff --git a/test/cpp/microbenchmarks/bm_thread_pool.cc b/test/cpp/microbenchmarks/bm_thread_pool.cc index 0514a948019..323c5267c56 100644 --- a/test/cpp/microbenchmarks/bm_thread_pool.cc +++ b/test/cpp/microbenchmarks/bm_thread_pool.cc @@ -27,9 +27,9 @@ #include "src/core/lib/event_engine/common_closures.h" #include "src/core/lib/event_engine/thread_pool/thread_pool.h" -#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/notification.h" +#include "src/core/util/useful.h" #include "test/core/test_util/test_config.h" #include "test/cpp/microbenchmarks/helpers.h" #include "test/cpp/util/test_config.h" diff --git a/test/cpp/microbenchmarks/callback_streaming_ping_pong.h b/test/cpp/microbenchmarks/callback_streaming_ping_pong.h index 3ac9a30b538..7987200a245 100644 --- a/test/cpp/microbenchmarks/callback_streaming_ping_pong.h +++ b/test/cpp/microbenchmarks/callback_streaming_ping_pong.h @@ -24,6 +24,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/cpp/microbenchmarks/callback_test_service.h" @@ -54,7 +55,7 @@ class BidiClient : public grpc::ClientBidiReactor { void OnReadDone(bool ok) override { if (!ok) { - gpr_log(GPR_ERROR, "Client read failed"); + LOG(ERROR) << "Client read failed"; return; } MaybeWrite(); @@ -62,7 +63,7 @@ class BidiClient : public grpc::ClientBidiReactor { void OnWriteDone(bool ok) override { if (!ok) { - gpr_log(GPR_ERROR, "Client write failed"); + LOG(ERROR) << "Client write failed"; return; } writes_complete_++; diff --git a/test/cpp/microbenchmarks/callback_test_service.cc b/test/cpp/microbenchmarks/callback_test_service.cc index 3b22041d4f3..af732280af4 100644 --- a/test/cpp/microbenchmarks/callback_test_service.cc +++ b/test/cpp/microbenchmarks/callback_test_service.cc @@ -19,6 +19,7 @@ #include "test/cpp/microbenchmarks/callback_test_service.h" #include "absl/log/check.h" +#include "absl/log/log.h" namespace grpc { namespace testing { @@ -93,7 +94,7 @@ CallbackStreamingTestService::BidiStream(CallbackServerContext* context) { } void OnWriteDone(bool ok) override { if (!ok) { - gpr_log(GPR_ERROR, "Server write failed"); + LOG(ERROR) << "Server write failed"; return; } StartRead(&request_); diff --git a/test/cpp/naming/address_sorting_test.cc b/test/cpp/naming/address_sorting_test.cc index b244057215b..0ce5a1d5150 100644 --- a/test/cpp/naming/address_sorting_test.cc +++ b/test/cpp/naming/address_sorting_test.cc @@ -37,7 +37,6 @@ #include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/config/config_vars.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/iomgr/combiner.h" @@ -48,6 +47,7 @@ #include "src/core/resolver/endpoint_addresses.h" #include "src/core/resolver/resolver.h" #include "src/core/resolver/resolver_registry.h" +#include "src/core/util/string.h" #include "test/core/test_util/port.h" #include "test/core/test_util/test_config.h" #include "test/cpp/util/subprocess.h" diff --git a/test/cpp/naming/cancel_ares_query_test.cc b/test/cpp/naming/cancel_ares_query_test.cc index b62cd8b1b71..29b5a19d65c 100644 --- a/test/cpp/naming/cancel_ares_query_test.cc +++ b/test/cpp/naming/cancel_ares_query_test.cc @@ -43,7 +43,6 @@ #include "src/core/lib/event_engine/ares_resolver.h" #include "src/core/lib/event_engine/default_event_engine.h" #include "src/core/lib/experiments/experiments.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/thd.h" @@ -54,6 +53,7 @@ #include "src/core/resolver/dns/c_ares/grpc_ares_wrapper.h" #include "src/core/resolver/resolver.h" #include "src/core/resolver/resolver_registry.h" +#include "src/core/util/string.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/test_util/cmdline.h" #include "test/core/test_util/fake_udp_and_tcp_server.h" diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index 6f0e3678a91..78909d9eb17 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -48,7 +48,6 @@ #include "src/core/lib/event_engine/ares_resolver.h" #include "src/core/lib/event_engine/default_event_engine.h" #include "src/core/lib/experiments/experiments.h" -#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/orphanable.h" @@ -62,6 +61,7 @@ #include "src/core/resolver/endpoint_addresses.h" #include "src/core/resolver/resolver.h" #include "src/core/resolver/resolver_registry.h" +#include "src/core/util/string.h" #include "test/core/test_util/fake_udp_and_tcp_server.h" #include "test/core/test_util/port.h" #include "test/core/test_util/socket_use_after_close_detector.h" diff --git a/test/cpp/performance/writes_per_rpc_test.cc b/test/cpp/performance/writes_per_rpc_test.cc index 7a24ebd917b..9bd8f009334 100644 --- a/test/cpp/performance/writes_per_rpc_test.cc +++ b/test/cpp/performance/writes_per_rpc_test.cc @@ -61,7 +61,7 @@ using grpc_event_engine::experimental::URIToResolvedAddress; void* tag(intptr_t x) { return reinterpret_cast(x); } -constexpr int kIterations = 10000; +constexpr int kIterations = 1000; constexpr int kSnapshotEvery = kIterations / 10; } // namespace @@ -216,17 +216,20 @@ static double UnaryPingPong(ThreadedFuzzingEventEngine* fuzzing_engine, EchoTestService::NewStub(fixture->channel())); auto baseline = grpc_core::global_stats().Collect(); auto snapshot = grpc_core::global_stats().Collect(); + auto last_snapshot = absl::Now(); for (int iteration = 0; iteration < kIterations; iteration++) { - if (iteration % kSnapshotEvery == 0) { + if (iteration > 0 && iteration % kSnapshotEvery == 0) { auto new_snapshot = grpc_core::global_stats().Collect(); auto diff = new_snapshot->Diff(*snapshot); - gpr_log(GPR_DEBUG, - " SNAPSHOT: UnaryPingPong(%d, %d): writes_per_iteration=%0.3f " - "(total=%lu, i=%d) pings=%lu", - request_size, response_size, - static_cast(diff->syscall_write) / - static_cast(kSnapshotEvery), - diff->syscall_write, iteration, diff->http2_pings_sent); + auto now = absl::Now(); + LOG(ERROR) << " SNAPSHOT: UnaryPingPong(" << request_size << ", " + << response_size << "): writes_per_iteration=" + << static_cast(diff->syscall_write) / + static_cast(kSnapshotEvery) + << " (total=" << diff->syscall_write << ", i=" << iteration + << ") pings=" << diff->http2_pings_sent + << "; duration=" << now - last_snapshot; + last_snapshot = now; snapshot = std::move(new_snapshot); } recv_response.Clear(); @@ -238,7 +241,7 @@ static double UnaryPingPong(ThreadedFuzzingEventEngine* fuzzing_engine, response_reader->Finish(&recv_response, &recv_status, tag(4)); CHECK(fixture->cq()->Next(&t, &ok)); CHECK(ok); - CHECK(t == tag(0) || t == tag(1)); + CHECK(t == tag(0) || t == tag(1)) << "Found unexpected tag " << t; intptr_t slot = reinterpret_cast(t); ServerEnv* senv = server_env[slot]; senv->response_writer.Finish(send_response, Status::OK, tag(3)); diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index fa5ceae31b5..792d271242b 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -29,11 +29,11 @@ #include #include +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "absl/strings/match.h" #include "absl/strings/str_format.h" -#include #include #include #include @@ -203,10 +203,10 @@ class Client { if (median_latency_collection_interval_seconds_ > 0) { std::vector medians_per_interval = threads_[0]->GetMedianPerIntervalList(); - gpr_log(GPR_INFO, "Num threads: %zu", threads_.size()); - gpr_log(GPR_INFO, "Number of medians: %zu", medians_per_interval.size()); + LOG(INFO) << "Num threads: " << threads_.size(); + LOG(INFO) << "Number of medians: " << medians_per_interval.size(); for (size_t j = 0; j < medians_per_interval.size(); j++) { - gpr_log(GPR_INFO, "%f", medians_per_interval[j]); + LOG(INFO) << medians_per_interval[j]; } } @@ -318,8 +318,8 @@ class Client { &client_->start_requests_, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(20, GPR_TIMESPAN)))) { - gpr_log(GPR_INFO, "%" PRIdPTR ": Waiting for benchmark to start (%d)", - idx_, wait_loop); + LOG(INFO) << idx_ << ": Waiting for benchmark to start (" << wait_loop + << ")"; wait_loop++; } @@ -463,9 +463,8 @@ class ClientImpl : public Client { !channel_connect_timeout_str->empty()) { connect_deadline_seconds = atoi(channel_connect_timeout_str->c_str()); } - gpr_log(GPR_INFO, - "Waiting for up to %d seconds for all channels to connect", - connect_deadline_seconds); + LOG(INFO) << "Waiting for up to " << connect_deadline_seconds + << " seconds for all channels to connect"; gpr_timespec connect_deadline = gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(connect_deadline_seconds, GPR_TIMESPAN)); @@ -476,7 +475,7 @@ class ClientImpl : public Client { Channel* channel = c.get_channel(); grpc_connectivity_state last_observed = channel->GetState(true); if (last_observed == GRPC_CHANNEL_READY) { - gpr_log(GPR_INFO, "Channel %p connected!", channel); + LOG(INFO) << "Channel " << channel << " connected!"; } else { num_remaining++; channel->NotifyOnStateChange(last_observed, connect_deadline, &cq, @@ -495,7 +494,7 @@ class ClientImpl : public Client { } else { grpc_connectivity_state last_observed = channel->GetState(true); if (last_observed == GRPC_CHANNEL_READY) { - gpr_log(GPR_INFO, "Channel %p connected!", channel); + LOG(INFO) << "Channel " << channel << " connected!"; num_remaining--; } else { channel->NotifyOnStateChange(last_observed, connect_deadline, &cq, @@ -534,7 +533,7 @@ class ClientImpl : public Client { target, type, config.security_params().server_host_override(), !config.security_params().use_test_ca(), std::shared_ptr(), args); - gpr_log(GPR_INFO, "Connecting to %s", target.c_str()); + LOG(INFO) << "Connecting to " << target; is_inproc_ = false; } else { std::string tgt = target; @@ -557,7 +556,7 @@ class ClientImpl : public Client { } else if (channel_arg.value_case() == ChannelArg::kIntValue) { args->SetInt(channel_arg.name(), channel_arg.int_value()); } else { - gpr_log(GPR_ERROR, "Empty channel arg value."); + LOG(ERROR) << "Empty channel arg value."; } } } diff --git a/test/cpp/qps/client_callback.cc b/test/cpp/qps/client_callback.cc index 65ad207de63..51cead4e3ea 100644 --- a/test/cpp/qps/client_callback.cc +++ b/test/cpp/qps/client_callback.cc @@ -25,11 +25,11 @@ #include #include +#include "absl/log/log.h" #include "absl/memory/memory.h" #include #include -#include #include #include #include @@ -126,7 +126,7 @@ class CallbackClient int num_threads = config.async_client_threads(); if (num_threads <= 0) { // Use dynamic sizing num_threads = cores_; - gpr_log(GPR_INFO, "Sizing callback client to %d threads", num_threads); + LOG(INFO) << "Sizing callback client to " << num_threads << " threads"; } return num_threads; } @@ -268,7 +268,7 @@ class CallbackStreamingPingPongReactor final void OnWriteDone(bool ok) override { if (!ok) { - gpr_log(GPR_ERROR, "Error writing RPC"); + LOG(ERROR) << "Error writing RPC"; } if ((!ok || client_->ThreadCompleted()) && !writes_done_started_.test_and_set()) { @@ -284,7 +284,7 @@ class CallbackStreamingPingPongReactor final (client_->messages_per_stream() != 0 && ++messages_issued_ >= client_->messages_per_stream())) { if (!ok) { - gpr_log(GPR_ERROR, "Error reading RPC"); + LOG(ERROR) << "Error reading RPC"; } if (!writes_done_started_.test_and_set()) { StartWritesDone(); diff --git a/test/cpp/qps/inproc_sync_unary_ping_pong_test.cc b/test/cpp/qps/inproc_sync_unary_ping_pong_test.cc index 614891004b3..e876e50cf78 100644 --- a/test/cpp/qps/inproc_sync_unary_ping_pong_test.cc +++ b/test/cpp/qps/inproc_sync_unary_ping_pong_test.cc @@ -18,7 +18,7 @@ #include -#include +#include "absl/log/log.h" #include "src/core/lib/gprpp/crash.h" #include "test/core/test_util/test_config.h" @@ -36,7 +36,7 @@ static const int WARMUP = 1; static const int BENCHMARK = 3; static void RunSynchronousUnaryPingPong() { - gpr_log(GPR_INFO, "Running Synchronous Unary Ping Pong"); + LOG(INFO) << "Running Synchronous Unary Ping Pong"; ClientConfig client_config; client_config.set_client_type(SYNC_CLIENT); diff --git a/test/cpp/qps/qps_json_driver.cc b/test/cpp/qps/qps_json_driver.cc index ee70ec76c0d..50734258b50 100644 --- a/test/cpp/qps/qps_json_driver.cc +++ b/test/cpp/qps/qps_json_driver.cc @@ -23,8 +23,8 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" -#include #include #include "src/core/lib/gprpp/crash.h" @@ -104,10 +104,8 @@ ConstructPerWorkerCredentialTypesMap() { } size_t comma = next_entry.find(','); if (comma == std::string::npos) { - gpr_log(GPR_ERROR, - "Expectd --per_worker_credential_types to be a list " - "of the form: 'addr1,cred_type1;addr2,cred_type2;...' " - "into."); + LOG(ERROR) << "Expectd --per_worker_credential_types to be a list of the " + "form: 'addr1,cred_type1;addr2,cred_type2;...' into."; abort(); } std::string addr = next_entry.substr(0, comma); @@ -185,9 +183,9 @@ static double BinarySearch( double mid = low + (high - low) / 2; double current_cpu_load = GetCpuLoad(scenario, mid, per_worker_credential_types, success); - gpr_log(GPR_DEBUG, "Binary Search: current_offered_load %.0f", mid); + VLOG(2) << absl::StrFormat("Binary Search: current_offered_load %.0f", mid); if (!*success) { - gpr_log(GPR_ERROR, "Client/Server Failure"); + LOG(ERROR) << "Client/Server Failure"; break; } if (targeted_cpu_load <= current_cpu_load) { @@ -209,7 +207,7 @@ static double SearchOfferedLoad( double current_cpu_load = GetCpuLoad(scenario, current_offered_load, per_worker_credential_types, success); if (current_cpu_load > targeted_cpu_load) { - gpr_log(GPR_ERROR, "Initial offered load too high"); + LOG(ERROR) << "Initial offered load too high"; return -1; } @@ -217,8 +215,8 @@ static double SearchOfferedLoad( current_offered_load *= 2; current_cpu_load = GetCpuLoad(scenario, current_offered_load, per_worker_credential_types, success); - gpr_log(GPR_DEBUG, "Binary Search: current_offered_load %.0f", - current_offered_load); + VLOG(2) << absl::StrFormat("Binary Search: current_offered_load %.0f", + current_offered_load); } double targeted_offered_load = @@ -280,11 +278,11 @@ static bool QpsDriver() { SearchOfferedLoad(absl::GetFlag(FLAGS_initial_search_value), absl::GetFlag(FLAGS_targeted_cpu_load), scenario, per_worker_credential_types, &success); - gpr_log(GPR_INFO, "targeted_offered_load %f", targeted_offered_load); + LOG(INFO) << "targeted_offered_load " << targeted_offered_load; GetCpuLoad(scenario, targeted_offered_load, per_worker_credential_types, &success); } else { - gpr_log(GPR_ERROR, "Unimplemented search param"); + LOG(ERROR) << "Unimplemented search param"; } } } diff --git a/test/cpp/qps/qps_openloop_test.cc b/test/cpp/qps/qps_openloop_test.cc index b48798a936d..21c83418427 100644 --- a/test/cpp/qps/qps_openloop_test.cc +++ b/test/cpp/qps/qps_openloop_test.cc @@ -18,7 +18,7 @@ #include -#include +#include "absl/log/log.h" #include "src/core/lib/gprpp/crash.h" #include "test/core/test_util/test_config.h" @@ -36,7 +36,7 @@ static const int WARMUP = 1; static const int BENCHMARK = 3; static void RunQPS() { - gpr_log(GPR_INFO, "Running QPS test, open-loop"); + LOG(INFO) << "Running QPS test, open-loop"; ClientConfig client_config; client_config.set_client_type(ASYNC_CLIENT); diff --git a/test/cpp/qps/qps_worker.cc b/test/cpp/qps/qps_worker.cc index b41cbbc6afc..f2b444fc9c8 100644 --- a/test/cpp/qps/qps_worker.cc +++ b/test/cpp/qps/qps_worker.cc @@ -26,12 +26,12 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include #include #include -#include #include #include #include @@ -52,10 +52,10 @@ namespace grpc { namespace testing { static std::unique_ptr CreateClient(const ClientConfig& config) { - gpr_log(GPR_INFO, "Starting client of type %s %s %d", - ClientType_Name(config.client_type()).c_str(), - RpcType_Name(config.rpc_type()).c_str(), - config.payload_config().has_bytebuf_params()); + LOG(INFO) << "Starting client of type " + << ClientType_Name(config.client_type()) << " " + << RpcType_Name(config.rpc_type()) << " " + << config.payload_config().has_bytebuf_params(); switch (config.client_type()) { case ClientType::SYNC_CLIENT: @@ -72,8 +72,8 @@ static std::unique_ptr CreateClient(const ClientConfig& config) { } static std::unique_ptr CreateServer(const ServerConfig& config) { - gpr_log(GPR_INFO, "Starting server of type %s", - ServerType_Name(config.server_type()).c_str()); + LOG(INFO) << "Starting server of type " + << ServerType_Name(config.server_type()); switch (config.server_type()) { case ServerType::SYNC_SERVER: @@ -110,7 +110,7 @@ class WorkerServiceImpl final : public WorkerService::Service { Status RunClient( ServerContext* ctx, ServerReaderWriter* stream) override { - gpr_log(GPR_INFO, "RunClient: Entering"); + LOG(INFO) << "RunClient: Entering"; InstanceGuard g(this); if (!g.Acquired()) { return Status(StatusCode::RESOURCE_EXHAUSTED, "Client worker busy"); @@ -118,14 +118,14 @@ class WorkerServiceImpl final : public WorkerService::Service { ScopedProfile profile("qps_client.prof", false); Status ret = RunClientBody(ctx, stream); - gpr_log(GPR_INFO, "RunClient: Returning"); + LOG(INFO) << "RunClient: Returning"; return ret; } Status RunServer( ServerContext* ctx, ServerReaderWriter* stream) override { - gpr_log(GPR_INFO, "RunServer: Entering"); + LOG(INFO) << "RunServer: Entering"; InstanceGuard g(this); if (!g.Acquired()) { return Status(StatusCode::RESOURCE_EXHAUSTED, "Server worker busy"); @@ -133,7 +133,7 @@ class WorkerServiceImpl final : public WorkerService::Service { ScopedProfile profile("qps_server.prof", false); Status ret = RunServerBody(ctx, stream); - gpr_log(GPR_INFO, "RunServer: Returning"); + LOG(INFO) << "RunServer: Returning"; return ret; } @@ -194,34 +194,34 @@ class WorkerServiceImpl final : public WorkerService::Service { if (!args.has_setup()) { return Status(StatusCode::INVALID_ARGUMENT, "Invalid setup arg"); } - gpr_log(GPR_INFO, "RunClientBody: about to create client"); + LOG(INFO) << "RunClientBody: about to create client"; std::unique_ptr client = CreateClient(args.setup()); if (!client) { return Status(StatusCode::INVALID_ARGUMENT, "Couldn't create client"); } - gpr_log(GPR_INFO, "RunClientBody: client created"); + LOG(INFO) << "RunClientBody: client created"; ClientStatus status; if (!stream->Write(status)) { return Status(StatusCode::UNKNOWN, "Client couldn't report init status"); } - gpr_log(GPR_INFO, "RunClientBody: creation status reported"); + LOG(INFO) << "RunClientBody: creation status reported"; while (stream->Read(&args)) { - gpr_log(GPR_INFO, "RunClientBody: Message read"); + LOG(INFO) << "RunClientBody: Message read"; if (!args.has_mark()) { - gpr_log(GPR_INFO, "RunClientBody: Message is not a mark!"); + LOG(INFO) << "RunClientBody: Message is not a mark!"; return Status(StatusCode::INVALID_ARGUMENT, "Invalid mark"); } *status.mutable_stats() = client->Mark(args.mark().reset()); if (!stream->Write(status)) { return Status(StatusCode::UNKNOWN, "Client couldn't respond to mark"); } - gpr_log(GPR_INFO, "RunClientBody: Mark response given"); + LOG(INFO) << "RunClientBody: Mark response given"; } - gpr_log(GPR_INFO, "RunClientBody: Awaiting Threads Completion"); + LOG(INFO) << "RunClientBody: Awaiting Threads Completion"; client->AwaitThreadsCompletion(); - gpr_log(GPR_INFO, "RunClientBody: Returning"); + LOG(INFO) << "RunClientBody: Returning"; return Status::OK; } @@ -237,7 +237,7 @@ class WorkerServiceImpl final : public WorkerService::Service { if (server_port_ > 0 && args.setup().port() == 0) { args.mutable_setup()->set_port(server_port_); } - gpr_log(GPR_INFO, "RunServerBody: about to create server"); + LOG(INFO) << "RunServerBody: about to create server"; std::unique_ptr server = CreateServer(args.setup()); if (g_inproc_servers != nullptr) { g_inproc_servers->push_back(server.get()); @@ -245,28 +245,28 @@ class WorkerServiceImpl final : public WorkerService::Service { if (!server) { return Status(StatusCode::INVALID_ARGUMENT, "Couldn't create server"); } - gpr_log(GPR_INFO, "RunServerBody: server created"); + LOG(INFO) << "RunServerBody: server created"; ServerStatus status; status.set_port(server->port()); status.set_cores(server->cores()); if (!stream->Write(status)) { return Status(StatusCode::UNKNOWN, "Server couldn't report init status"); } - gpr_log(GPR_INFO, "RunServerBody: creation status reported"); + LOG(INFO) << "RunServerBody: creation status reported"; while (stream->Read(&args)) { - gpr_log(GPR_INFO, "RunServerBody: Message read"); + LOG(INFO) << "RunServerBody: Message read"; if (!args.has_mark()) { - gpr_log(GPR_INFO, "RunServerBody: Message not a mark!"); + LOG(INFO) << "RunServerBody: Message not a mark!"; return Status(StatusCode::INVALID_ARGUMENT, "Invalid mark"); } *status.mutable_stats() = server->Mark(args.mark().reset()); if (!stream->Write(status)) { return Status(StatusCode::UNKNOWN, "Server couldn't respond to mark"); } - gpr_log(GPR_INFO, "RunServerBody: Mark response given"); + LOG(INFO) << "RunServerBody: Mark response given"; } - gpr_log(GPR_INFO, "RunServerBody: Returning"); + LOG(INFO) << "RunServerBody: Returning"; return Status::OK; } @@ -293,13 +293,11 @@ QpsWorker::QpsWorker(int driver_port, int server_port, server_ = builder->BuildAndStart(); if (server_ == nullptr) { - gpr_log(GPR_ERROR, - "QpsWorker: Fail to BuildAndStart(driver_port=%d, server_port=%d)", - driver_port, server_port); + LOG(ERROR) << "QpsWorker: Fail to BuildAndStart(driver_port=" << driver_port + << ", server_port=" << server_port << ")"; } else { - gpr_log(GPR_INFO, - "QpsWorker: BuildAndStart(driver_port=%d, server_port=%d) done", - driver_port, server_port); + LOG(INFO) << "QpsWorker: BuildAndStart(driver_port=" << driver_port + << ", server_port=" << server_port << ") done"; } } diff --git a/test/cpp/qps/secure_sync_unary_ping_pong_test.cc b/test/cpp/qps/secure_sync_unary_ping_pong_test.cc index a23f9e48802..6829f0dcd29 100644 --- a/test/cpp/qps/secure_sync_unary_ping_pong_test.cc +++ b/test/cpp/qps/secure_sync_unary_ping_pong_test.cc @@ -18,7 +18,7 @@ #include -#include +#include "absl/log/log.h" #include "src/core/lib/gprpp/crash.h" #include "test/core/test_util/test_config.h" @@ -36,7 +36,7 @@ static const int WARMUP = 1; static const int BENCHMARK = 3; static void RunSynchronousUnaryPingPong() { - gpr_log(GPR_INFO, "Running Synchronous Unary Ping Pong"); + LOG(INFO) << "Running Synchronous Unary Ping Pong"; ClientConfig client_config; client_config.set_client_type(SYNC_CLIENT); diff --git a/test/cpp/qps/usage_timer.cc b/test/cpp/qps/usage_timer.cc index ac0584f6bd2..0f717141d25 100644 --- a/test/cpp/qps/usage_timer.cc +++ b/test/cpp/qps/usage_timer.cc @@ -22,7 +22,8 @@ #include #include -#include +#include "absl/log/log.h" + #include #include "src/core/lib/gprpp/crash.h" @@ -74,7 +75,7 @@ static void get_cpu_usage(unsigned long long* total_cpu_time, // Use the parameters to avoid unused-parameter warning (void)total_cpu_time; (void)idle_cpu_time; - gpr_log(GPR_INFO, "get_cpu_usage(): Non-linux platform is not supported."); + LOG(INFO) << "get_cpu_usage(): Non-linux platform is not supported."; #endif } diff --git a/test/cpp/server/BUILD b/test/cpp/server/BUILD index ba2f115ee7a..b65ec5c9e86 100644 --- a/test/cpp/server/BUILD +++ b/test/cpp/server/BUILD @@ -28,6 +28,7 @@ grpc_cc_test( deps = [ "//:grpc++_unsecure", "//src/proto/grpc/testing:echo_proto", + "//test/core/event_engine:event_engine_test_utils", "//test/core/test_util:grpc_test_util_base", "//test/core/test_util:grpc_test_util_unsecure", ], diff --git a/test/cpp/server/load_reporter/load_reporter_test.cc b/test/cpp/server/load_reporter/load_reporter_test.cc index e64356c1389..fd1d4aeef67 100644 --- a/test/cpp/server/load_reporter/load_reporter_test.cc +++ b/test/cpp/server/load_reporter/load_reporter_test.cc @@ -25,6 +25,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/memory/memory.h" #include "opencensus/stats/testing/test_utils.h" @@ -174,9 +175,8 @@ class LbFeedbackTest : public LoadReporterTest { DoubleNear(expected_qps, expected_qps * 0.3)); ASSERT_THAT(static_cast(lb_feedback.errors_per_second()), DoubleNear(expected_eps, expected_eps * 0.3)); - gpr_log(GPR_INFO, - "Verified LB feedback matches the samples of index [%zu, %zu).", - start, start + count); + LOG(INFO) << "Verified LB feedback matches the samples of index [" << start + << ", " << start + count << ")."; } const std::vector> kQpsEpsSamples = { @@ -487,11 +487,11 @@ TEST_F(LoadReportTest, BasicReport) { // First fetch. load_reporter_->FetchAndSample(); load_reporter_->GenerateLoads(kHostname1, kLbId1); - gpr_log(GPR_INFO, "First load generated."); + LOG(INFO) << "First load generated."; // Second fetch. load_reporter_->FetchAndSample(); load_reporter_->GenerateLoads(kHostname2, kLbId2); - gpr_log(GPR_INFO, "Second load generated."); + LOG(INFO) << "Second load generated."; // TODO(juanlishen): Verify the data. } diff --git a/test/cpp/server/server_builder_test.cc b/test/cpp/server/server_builder_test.cc index 1765a1d59bf..089f7c38ecf 100644 --- a/test/cpp/server/server_builder_test.cc +++ b/test/cpp/server/server_builder_test.cc @@ -16,14 +16,19 @@ // // +#include + #include +#include #include #include #include #include +#include "src/core/lib/gprpp/notification.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" +#include "test/core/event_engine/event_engine_test_utils.h" #include "test/core/test_util/port.h" #include "test/core/test_util/test_config.h" @@ -83,6 +88,56 @@ TEST_F(ServerBuilderTest, CreateServerRepeatedPortWithDisallowedReusePort) { nullptr); } +TEST_F(ServerBuilderTest, AddPassiveListener) { + std::unique_ptr passive_listener; + auto server = + ServerBuilder() + .experimental() + .AddPassiveListener(InsecureServerCredentials(), passive_listener) + .BuildAndStart(); + server->Shutdown(); +} + +TEST_F(ServerBuilderTest, PassiveListenerAcceptConnectedFd) { + std::unique_ptr passive_listener; + ServerBuilder builder; + auto cq = builder.AddCompletionQueue(); + // TODO(hork): why is the service necessary? Queue isn't drained otherwise. + auto server = + builder.RegisterService(&g_service) + .experimental() + .AddPassiveListener(InsecureServerCredentials(), passive_listener) + .BuildAndStart(); + ASSERT_NE(server.get(), nullptr); +#ifdef GPR_SUPPORT_CHANNELS_FROM_FD + int fd = socket(AF_INET, SOCK_STREAM, 0); + auto accept_status = passive_listener->AcceptConnectedFd(fd); + ASSERT_TRUE(accept_status.ok()) << accept_status; +#else + int fd = -1; + auto accept_status = passive_listener->AcceptConnectedFd(fd); + ASSERT_FALSE(accept_status.ok()) << accept_status; +#endif + server->Shutdown(); +} + +TEST_F(ServerBuilderTest, PassiveListenerAcceptConnectedEndpoint) { + std::unique_ptr passive_listener; + auto server = + ServerBuilder() + .experimental() + .AddPassiveListener(InsecureServerCredentials(), passive_listener) + .BuildAndStart(); + grpc_core::Notification endpoint_destroyed; + auto success = passive_listener->AcceptConnectedEndpoint( + std::make_unique( + &endpoint_destroyed)); + ASSERT_TRUE(success.ok()) + << "AcceptConnectedEndpoint failure: " << success.ToString(); + endpoint_destroyed.WaitForNotification(); + server->Shutdown(); +} + } // namespace } // namespace grpc diff --git a/test/cpp/server/server_request_call_test.cc b/test/cpp/server/server_request_call_test.cc index 8bb02394179..96bbf15400a 100644 --- a/test/cpp/server/server_request_call_test.cc +++ b/test/cpp/server/server_request_call_test.cc @@ -20,9 +20,9 @@ #include +#include "absl/log/log.h" #include "absl/strings/str_format.h" -#include #include #include #include @@ -90,7 +90,7 @@ TEST(ServerRequestCallTest, ShortDeadlineDoesNotCauseOkayFalse) { // Send a simple response after a small delay that would ensure the client // deadline is exceeded. - gpr_log(GPR_INFO, "Got request %d", n); + LOG(INFO) << "Got request " << n; testing::EchoResponse response; response.set_message("foobar"); // A bit of sleep to make sure the deadline elapses. @@ -99,12 +99,11 @@ TEST(ServerRequestCallTest, ShortDeadlineDoesNotCauseOkayFalse) { { std::lock_guard lock(mu); if (shutting_down) { - gpr_log(GPR_INFO, - "shut down while processing call, not calling Finish()"); + LOG(INFO) << "shut down while processing call, not calling Finish()"; // Continue flushing the CQ. continue; } - gpr_log(GPR_INFO, "Finishing request %d", n); + LOG(INFO) << "Finishing request " << n; responder.Finish(response, grpc::Status::OK, reinterpret_cast(2)); if (!cq->Next(&tag, &ok)) { @@ -119,7 +118,7 @@ TEST(ServerRequestCallTest, ShortDeadlineDoesNotCauseOkayFalse) { grpc::CreateChannel(address, InsecureChannelCredentials())); for (int i = 0; i < 100; i++) { - gpr_log(GPR_INFO, "Sending %d.", i); + LOG(INFO) << "Sending " << i; testing::EchoRequest request; ///////// @@ -138,12 +137,12 @@ TEST(ServerRequestCallTest, ShortDeadlineDoesNotCauseOkayFalse) { std::chrono::milliseconds(1)); grpc::Status status = stub->Echo(&ctx, request, &response); EXPECT_EQ(StatusCode::DEADLINE_EXCEEDED, status.error_code()); - gpr_log(GPR_INFO, "Success."); + LOG(INFO) << "Success."; } - gpr_log(GPR_INFO, "Done sending RPCs."); + LOG(INFO) << "Done sending RPCs."; // Shut down everything properly. - gpr_log(GPR_INFO, "Shutting down."); + LOG(INFO) << "Shutting down."; { std::lock_guard lock(mu); shutting_down = true; @@ -226,7 +225,7 @@ TEST(ServerRequestCallTest, MultithreadedUnimplementedService) { } // Shut down everything properly. - gpr_log(GPR_INFO, "Shutting down."); + LOG(INFO) << "Shutting down."; shutdown.store(true); server->Shutdown(); cq->Shutdown(); diff --git a/test/cpp/util/channel_trace_proto_helper.cc b/test/cpp/util/channel_trace_proto_helper.cc index 9667b1c09b0..37a9898007e 100644 --- a/test/cpp/util/channel_trace_proto_helper.cc +++ b/test/cpp/util/channel_trace_proto_helper.cc @@ -41,7 +41,7 @@ namespace { // then back to json. This ensures that the json string was correctly formatted // according to https://developers.google.com/protocol-buffers/docs/proto3#json template -void VaidateProtoJsonTranslation(const std::string& json_str) { +void VaidateProtoJsonTranslation(absl::string_view json_str) { Message msg; grpc::protobuf::json::JsonParseOptions parse_options; // If the following line is failing, then uncomment the last line of the @@ -73,41 +73,44 @@ void VaidateProtoJsonTranslation(const std::string& json_str) { namespace testing { -void ValidateChannelTraceProtoJsonTranslation(const char* json_c_str) { - VaidateProtoJsonTranslation(json_c_str); +void ValidateChannelTraceProtoJsonTranslation(absl::string_view json_string) { + VaidateProtoJsonTranslation(json_string); } -void ValidateChannelProtoJsonTranslation(const char* json_c_str) { - VaidateProtoJsonTranslation(json_c_str); +void ValidateChannelProtoJsonTranslation(absl::string_view json_string) { + VaidateProtoJsonTranslation(json_string); } void ValidateGetTopChannelsResponseProtoJsonTranslation( - const char* json_c_str) { + absl::string_view json_string) { VaidateProtoJsonTranslation( - json_c_str); + json_string); } -void ValidateGetChannelResponseProtoJsonTranslation(const char* json_c_str) { +void ValidateGetChannelResponseProtoJsonTranslation( + absl::string_view json_string) { VaidateProtoJsonTranslation( - json_c_str); + json_string); } -void ValidateGetServerResponseProtoJsonTranslation(const char* json_c_str) { +void ValidateGetServerResponseProtoJsonTranslation( + absl::string_view json_string) { VaidateProtoJsonTranslation( - json_c_str); + json_string); } -void ValidateSubchannelProtoJsonTranslation(const char* json_c_str) { - VaidateProtoJsonTranslation(json_c_str); +void ValidateSubchannelProtoJsonTranslation(absl::string_view json_string) { + VaidateProtoJsonTranslation(json_string); } -void ValidateServerProtoJsonTranslation(const char* json_c_str) { - VaidateProtoJsonTranslation(json_c_str); +void ValidateServerProtoJsonTranslation(absl::string_view json_string) { + VaidateProtoJsonTranslation(json_string); } -void ValidateGetServersResponseProtoJsonTranslation(const char* json_c_str) { +void ValidateGetServersResponseProtoJsonTranslation( + absl::string_view json_string) { VaidateProtoJsonTranslation( - json_c_str); + json_string); } } // namespace testing diff --git a/test/cpp/util/channel_trace_proto_helper.h b/test/cpp/util/channel_trace_proto_helper.h index 791b8ae698d..0d5cafd4a16 100644 --- a/test/cpp/util/channel_trace_proto_helper.h +++ b/test/cpp/util/channel_trace_proto_helper.h @@ -19,17 +19,23 @@ #ifndef GRPC_TEST_CPP_UTIL_CHANNEL_TRACE_PROTO_HELPER_H #define GRPC_TEST_CPP_UTIL_CHANNEL_TRACE_PROTO_HELPER_H +#include "absl/strings/string_view.h" + namespace grpc { namespace testing { -void ValidateChannelTraceProtoJsonTranslation(const char* json_c_str); -void ValidateChannelProtoJsonTranslation(const char* json_c_str); -void ValidateGetTopChannelsResponseProtoJsonTranslation(const char* json_c_str); -void ValidateGetChannelResponseProtoJsonTranslation(const char* json_c_str); -void ValidateGetServerResponseProtoJsonTranslation(const char* json_c_str); -void ValidateSubchannelProtoJsonTranslation(const char* json_c_str); -void ValidateServerProtoJsonTranslation(const char* json_c_str); -void ValidateGetServersResponseProtoJsonTranslation(const char* json_c_str); +void ValidateChannelTraceProtoJsonTranslation(absl::string_view json_string); +void ValidateChannelProtoJsonTranslation(absl::string_view json_string); +void ValidateGetTopChannelsResponseProtoJsonTranslation( + absl::string_view json_string); +void ValidateGetChannelResponseProtoJsonTranslation( + absl::string_view json_string); +void ValidateGetServerResponseProtoJsonTranslation( + absl::string_view json_string); +void ValidateSubchannelProtoJsonTranslation(absl::string_view json_string); +void ValidateServerProtoJsonTranslation(absl::string_view json_string); +void ValidateGetServersResponseProtoJsonTranslation( + absl::string_view json_string); } // namespace testing } // namespace grpc diff --git a/test/cpp/util/subprocess.cc b/test/cpp/util/subprocess.cc index 2f0c9cd03b2..05017fc1b7d 100644 --- a/test/cpp/util/subprocess.cc +++ b/test/cpp/util/subprocess.cc @@ -20,7 +20,7 @@ #include -#include "src/core/lib/gpr/subprocess.h" +#include "src/core/util/subprocess.h" namespace grpc { diff --git a/tools/distrib/check_namespace_qualification.py b/tools/distrib/check_namespace_qualification.py index 6634d8b8830..51ccb71aeb8 100755 --- a/tools/distrib/check_namespace_qualification.py +++ b/tools/distrib/check_namespace_qualification.py @@ -77,6 +77,10 @@ IGNORED_FILES = [ "src/core/lib/gprpp/global_config_env.h", "src/core/lib/profiling/timers.h", "src/core/lib/gprpp/crash.h", + # The grpc_core::Server redundant namespace qualification is required for + # older gcc versions. + "src/core/ext/transport/chttp2/server/chttp2_server.h", + "src/core/server/server.h", ] # find our home diff --git a/tools/distrib/check_redundant_namespace_qualifiers.py b/tools/distrib/check_redundant_namespace_qualifiers.py index 0322332209b..72a5d8b7a3c 100755 --- a/tools/distrib/check_redundant_namespace_qualifiers.py +++ b/tools/distrib/check_redundant_namespace_qualifiers.py @@ -21,6 +21,13 @@ import os import re import sys +IGNORED_FILES = [ + # note: the grpc_core::Server redundant namespace qualification is required + # for older gcc versions. + "src/core/ext/transport/chttp2/server/chttp2_server.h", + "src/core/server/server.h", +] + def find_closing_mustache(contents, initial_depth): """Find the closing mustache for a given number of open mustaches.""" @@ -166,6 +173,8 @@ for config in _CONFIGURATION: for file in files: if file.endswith(".cc") or file.endswith(".h"): path = os.path.join(root, file) + if path in IGNORED_FILES: + continue try: with open(path) as f: contents = f.read() 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/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index 6a50207e16d..299c480565d 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -928,6 +928,7 @@ include/grpc/impl/grpc_types.h \ include/grpc/impl/propagation_bits.h \ include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ +include/grpc/passive_listener.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ include/grpc/status.h \ @@ -1040,6 +1041,7 @@ include/grpcpp/impl/server_initializer.h \ include/grpcpp/impl/service_type.h \ include/grpcpp/impl/status.h \ include/grpcpp/impl/sync.h \ +include/grpcpp/passive_listener.h \ include/grpcpp/resource_quota.h \ include/grpcpp/security/audit_logging.h \ include/grpcpp/security/auth_context.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 8dd3bb12622..3f4a53208c2 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -928,6 +928,7 @@ include/grpc/impl/grpc_types.h \ include/grpc/impl/propagation_bits.h \ include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ +include/grpc/passive_listener.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ include/grpc/status.h \ @@ -1040,6 +1041,7 @@ include/grpcpp/impl/server_initializer.h \ include/grpcpp/impl/service_type.h \ include/grpcpp/impl/status.h \ include/grpcpp/impl/sync.h \ +include/grpcpp/passive_listener.h \ include/grpcpp/resource_quota.h \ include/grpcpp/security/audit_logging.h \ include/grpcpp/security/auth_context.h \ @@ -2258,38 +2260,6 @@ src/core/lib/experiments/config.cc \ src/core/lib/experiments/config.h \ src/core/lib/experiments/experiments.cc \ src/core/lib/experiments/experiments.h \ -src/core/lib/gpr/alloc.cc \ -src/core/lib/gpr/alloc.h \ -src/core/lib/gpr/android/log.cc \ -src/core/lib/gpr/atm.cc \ -src/core/lib/gpr/iphone/cpu.cc \ -src/core/lib/gpr/linux/cpu.cc \ -src/core/lib/gpr/linux/log.cc \ -src/core/lib/gpr/log.cc \ -src/core/lib/gpr/msys/tmpfile.cc \ -src/core/lib/gpr/posix/cpu.cc \ -src/core/lib/gpr/posix/log.cc \ -src/core/lib/gpr/posix/string.cc \ -src/core/lib/gpr/posix/sync.cc \ -src/core/lib/gpr/posix/time.cc \ -src/core/lib/gpr/posix/tmpfile.cc \ -src/core/lib/gpr/spinlock.h \ -src/core/lib/gpr/string.cc \ -src/core/lib/gpr/string.h \ -src/core/lib/gpr/sync.cc \ -src/core/lib/gpr/sync_abseil.cc \ -src/core/lib/gpr/time.cc \ -src/core/lib/gpr/time_precise.cc \ -src/core/lib/gpr/time_precise.h \ -src/core/lib/gpr/tmpfile.h \ -src/core/lib/gpr/useful.h \ -src/core/lib/gpr/windows/cpu.cc \ -src/core/lib/gpr/windows/log.cc \ -src/core/lib/gpr/windows/string.cc \ -src/core/lib/gpr/windows/string_util.cc \ -src/core/lib/gpr/windows/sync.cc \ -src/core/lib/gpr/windows/time.cc \ -src/core/lib/gpr/windows/tmpfile.cc \ src/core/lib/gprpp/atomic_utils.h \ src/core/lib/gprpp/bitset.h \ src/core/lib/gprpp/chunked_vector.h \ @@ -2748,6 +2718,7 @@ src/core/lib/transport/bdp_estimator.cc \ src/core/lib/transport/bdp_estimator.h \ src/core/lib/transport/call_arena_allocator.cc \ src/core/lib/transport/call_arena_allocator.h \ +src/core/lib/transport/call_destination.h \ src/core/lib/transport/call_filters.cc \ src/core/lib/transport/call_filters.h \ src/core/lib/transport/call_final_info.cc \ @@ -2760,6 +2731,8 @@ src/core/lib/transport/custom_metadata.h \ src/core/lib/transport/error_utils.cc \ src/core/lib/transport/error_utils.h \ src/core/lib/transport/http2_errors.h \ +src/core/lib/transport/interception_chain.cc \ +src/core/lib/transport/interception_chain.h \ src/core/lib/transport/message.cc \ src/core/lib/transport/message.h \ src/core/lib/transport/metadata.cc \ @@ -2952,6 +2925,38 @@ src/core/tsi/transport_security.h \ src/core/tsi/transport_security_grpc.cc \ src/core/tsi/transport_security_grpc.h \ src/core/tsi/transport_security_interface.h \ +src/core/util/alloc.cc \ +src/core/util/alloc.h \ +src/core/util/android/log.cc \ +src/core/util/atm.cc \ +src/core/util/iphone/cpu.cc \ +src/core/util/linux/cpu.cc \ +src/core/util/linux/log.cc \ +src/core/util/log.cc \ +src/core/util/msys/tmpfile.cc \ +src/core/util/posix/cpu.cc \ +src/core/util/posix/log.cc \ +src/core/util/posix/string.cc \ +src/core/util/posix/sync.cc \ +src/core/util/posix/time.cc \ +src/core/util/posix/tmpfile.cc \ +src/core/util/spinlock.h \ +src/core/util/string.cc \ +src/core/util/string.h \ +src/core/util/sync.cc \ +src/core/util/sync_abseil.cc \ +src/core/util/time.cc \ +src/core/util/time_precise.cc \ +src/core/util/time_precise.h \ +src/core/util/tmpfile.h \ +src/core/util/useful.h \ +src/core/util/windows/cpu.cc \ +src/core/util/windows/log.cc \ +src/core/util/windows/string.cc \ +src/core/util/windows/string_util.cc \ +src/core/util/windows/sync.cc \ +src/core/util/windows/time.cc \ +src/core/util/windows/tmpfile.cc \ src/core/xds/grpc/certificate_provider_store.cc \ src/core/xds/grpc/certificate_provider_store.h \ src/core/xds/grpc/file_watcher_certificate_provider_factory.cc \ diff --git a/tools/doxygen/Doxyfile.core b/tools/doxygen/Doxyfile.core index 592e357f54f..20b553dadfe 100644 --- a/tools/doxygen/Doxyfile.core +++ b/tools/doxygen/Doxyfile.core @@ -861,6 +861,7 @@ include/grpc/impl/grpc_types.h \ include/grpc/impl/propagation_bits.h \ include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ +include/grpc/passive_listener.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ include/grpc/status.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 74fd1131517..72b1676eeaf 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -861,6 +861,7 @@ include/grpc/impl/grpc_types.h \ include/grpc/impl/propagation_bits.h \ include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ +include/grpc/passive_listener.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ include/grpc/status.h \ @@ -2031,39 +2032,6 @@ src/core/lib/experiments/config.cc \ src/core/lib/experiments/config.h \ src/core/lib/experiments/experiments.cc \ src/core/lib/experiments/experiments.h \ -src/core/lib/gpr/README.md \ -src/core/lib/gpr/alloc.cc \ -src/core/lib/gpr/alloc.h \ -src/core/lib/gpr/android/log.cc \ -src/core/lib/gpr/atm.cc \ -src/core/lib/gpr/iphone/cpu.cc \ -src/core/lib/gpr/linux/cpu.cc \ -src/core/lib/gpr/linux/log.cc \ -src/core/lib/gpr/log.cc \ -src/core/lib/gpr/msys/tmpfile.cc \ -src/core/lib/gpr/posix/cpu.cc \ -src/core/lib/gpr/posix/log.cc \ -src/core/lib/gpr/posix/string.cc \ -src/core/lib/gpr/posix/sync.cc \ -src/core/lib/gpr/posix/time.cc \ -src/core/lib/gpr/posix/tmpfile.cc \ -src/core/lib/gpr/spinlock.h \ -src/core/lib/gpr/string.cc \ -src/core/lib/gpr/string.h \ -src/core/lib/gpr/sync.cc \ -src/core/lib/gpr/sync_abseil.cc \ -src/core/lib/gpr/time.cc \ -src/core/lib/gpr/time_precise.cc \ -src/core/lib/gpr/time_precise.h \ -src/core/lib/gpr/tmpfile.h \ -src/core/lib/gpr/useful.h \ -src/core/lib/gpr/windows/cpu.cc \ -src/core/lib/gpr/windows/log.cc \ -src/core/lib/gpr/windows/string.cc \ -src/core/lib/gpr/windows/string_util.cc \ -src/core/lib/gpr/windows/sync.cc \ -src/core/lib/gpr/windows/time.cc \ -src/core/lib/gpr/windows/tmpfile.cc \ src/core/lib/gprpp/README.md \ src/core/lib/gprpp/atomic_utils.h \ src/core/lib/gprpp/bitset.h \ @@ -2526,6 +2494,7 @@ src/core/lib/transport/bdp_estimator.cc \ src/core/lib/transport/bdp_estimator.h \ src/core/lib/transport/call_arena_allocator.cc \ src/core/lib/transport/call_arena_allocator.h \ +src/core/lib/transport/call_destination.h \ src/core/lib/transport/call_filters.cc \ src/core/lib/transport/call_filters.h \ src/core/lib/transport/call_final_info.cc \ @@ -2538,6 +2507,8 @@ src/core/lib/transport/custom_metadata.h \ src/core/lib/transport/error_utils.cc \ src/core/lib/transport/error_utils.h \ src/core/lib/transport/http2_errors.h \ +src/core/lib/transport/interception_chain.cc \ +src/core/lib/transport/interception_chain.h \ src/core/lib/transport/message.cc \ src/core/lib/transport/message.h \ src/core/lib/transport/metadata.cc \ @@ -2735,6 +2706,39 @@ src/core/tsi/transport_security.h \ src/core/tsi/transport_security_grpc.cc \ src/core/tsi/transport_security_grpc.h \ src/core/tsi/transport_security_interface.h \ +src/core/util/README.md \ +src/core/util/alloc.cc \ +src/core/util/alloc.h \ +src/core/util/android/log.cc \ +src/core/util/atm.cc \ +src/core/util/iphone/cpu.cc \ +src/core/util/linux/cpu.cc \ +src/core/util/linux/log.cc \ +src/core/util/log.cc \ +src/core/util/msys/tmpfile.cc \ +src/core/util/posix/cpu.cc \ +src/core/util/posix/log.cc \ +src/core/util/posix/string.cc \ +src/core/util/posix/sync.cc \ +src/core/util/posix/time.cc \ +src/core/util/posix/tmpfile.cc \ +src/core/util/spinlock.h \ +src/core/util/string.cc \ +src/core/util/string.h \ +src/core/util/sync.cc \ +src/core/util/sync_abseil.cc \ +src/core/util/time.cc \ +src/core/util/time_precise.cc \ +src/core/util/time_precise.h \ +src/core/util/tmpfile.h \ +src/core/util/useful.h \ +src/core/util/windows/cpu.cc \ +src/core/util/windows/log.cc \ +src/core/util/windows/string.cc \ +src/core/util/windows/string_util.cc \ +src/core/util/windows/sync.cc \ +src/core/util/windows/time.cc \ +src/core/util/windows/tmpfile.cc \ src/core/xds/grpc/certificate_provider_store.cc \ src/core/xds/grpc/certificate_provider_store.h \ src/core/xds/grpc/file_watcher_certificate_provider_factory.cc \ diff --git a/tools/internal_ci/linux/grpc_build_submodule_at_head.sh b/tools/internal_ci/linux/grpc_build_submodule_at_head.sh index 8450499c272..8beedb1c5b3 100755 --- a/tools/internal_ci/linux/grpc_build_submodule_at_head.sh +++ b/tools/internal_ci/linux/grpc_build_submodule_at_head.sh @@ -74,6 +74,8 @@ then # update upb rm -rf third_party/upb/upb cp -r third_party/protobuf/upb third_party/upb + # generate upb gen source codes + export CC=gcc tools/codegen/core/gen_upb_api.sh # update utf8_range rm -rf third_party/utf8_range diff --git a/tools/internal_ci/linux/grpc_xds_bazel_python_test_in_docker.sh b/tools/internal_ci/linux/grpc_xds_bazel_python_test_in_docker.sh index f3eefec5833..9821ede6575 100755 --- a/tools/internal_ci/linux/grpc_xds_bazel_python_test_in_docker.sh +++ b/tools/internal_ci/linux/grpc_xds_bazel_python_test_in_docker.sh @@ -69,7 +69,7 @@ export PYTHONUNBUFFERED=true GRPC_VERBOSITY=debug GRPC_TRACE=xds_client,xds_resolver,xds_cluster_manager_lb,cds_lb,xds_cluster_resolver_lb,priority_lb,xds_cluster_impl_lb,weighted_target_lb "$PYTHON" \ /var/local/git/grpc/tools/run_tests/run_xds_tests.py \ --halt_after_fail \ - --test_case="ping_pong,circuit_breaking" \ + --test_case="ping_pong" \ --project_id=grpc-testing \ --project_num=830293263384 \ --source_image=projects/grpc-testing/global/images/xds-test-server-5 \ diff --git a/tools/internal_ci/linux/grpc_xds_bazel_test_in_docker.sh b/tools/internal_ci/linux/grpc_xds_bazel_test_in_docker.sh index cd820579bdf..bcb69ad113c 100755 --- a/tools/internal_ci/linux/grpc_xds_bazel_test_in_docker.sh +++ b/tools/internal_ci/linux/grpc_xds_bazel_test_in_docker.sh @@ -70,7 +70,7 @@ bazel build test/cpp/interop:xds_interop_client GRPC_VERBOSITY=debug GRPC_TRACE=xds_client,xds_resolver,xds_cluster_manager_lb,cds_lb,xds_cluster_resolver_lb,priority_lb,xds_cluster_impl_lb,weighted_target_lb "$PYTHON" \ /var/local/git/grpc/tools/run_tests/run_xds_tests.py \ --halt_after_fail \ - --test_case="ping_pong,circuit_breaking" \ + --test_case="ping_pong" \ --project_id=grpc-testing \ --project_num=830293263384 \ --source_image=projects/grpc-testing/global/images/xds-test-server-5 \ diff --git a/tools/interop_matrix/client_matrix.py b/tools/interop_matrix/client_matrix.py index ccaf83cc1e6..3e79add7698 100644 --- a/tools/interop_matrix/client_matrix.py +++ b/tools/interop_matrix/client_matrix.py @@ -133,6 +133,7 @@ LANG_RELEASE_MATRIX = { ("v1.61.0", ReleaseInfo()), ("v1.62.0", ReleaseInfo()), ("v1.63.0", ReleaseInfo()), + ("v1.64.0", ReleaseInfo()), ] ), "go": OrderedDict( @@ -441,7 +442,8 @@ LANG_RELEASE_MATRIX = { ("v1.59.1", ReleaseInfo()), ("v1.60.1", ReleaseInfo()), ("v1.61.0", ReleaseInfo()), - ("v1.63.0", ReleaseInfo()), + ("v1.63.1", ReleaseInfo()), + ("v1.64.0", ReleaseInfo()), ] ), "python": OrderedDict( @@ -788,6 +790,12 @@ LANG_RELEASE_MATRIX = { runtimes=["python"], testcases_file="python__master" ), ), + ( + "v1.64.0", + ReleaseInfo( + runtimes=["python"], testcases_file="python__master" + ), + ), ] ), "node": OrderedDict( @@ -885,6 +893,7 @@ LANG_RELEASE_MATRIX = { ("v1.61.0", ReleaseInfo()), ("v1.62.0", ReleaseInfo()), ("v1.63.0", ReleaseInfo()), + ("v1.64.0", ReleaseInfo()), ] ), "php": OrderedDict( @@ -946,6 +955,7 @@ LANG_RELEASE_MATRIX = { ("v1.61.0", ReleaseInfo()), ("v1.62.0", ReleaseInfo()), ("v1.63.0", ReleaseInfo()), + ("v1.64.0", ReleaseInfo()), ] ), "csharp": OrderedDict( diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 61b98ca9bd1..8dc1a7348a1 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, @@ -10382,7 +10406,7 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_gpr_time_test", + "name": "test_core_gprpp_time_test", "platforms": [ "linux", "mac", @@ -10406,7 +10430,7 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_gprpp_time_test", + "name": "test_core_iomgr_timer_heap_test", "platforms": [ "linux", "mac", @@ -10430,14 +10454,14 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_iomgr_timer_heap_test", + "name": "test_core_security_credentials_test", "platforms": [ "linux", "mac", "posix", "windows" ], - "uses_polling": false + "uses_polling": true }, { "args": [], @@ -10454,7 +10478,7 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_security_credentials_test", + "name": "test_core_security_ssl_credentials_test", "platforms": [ "linux", "mac", @@ -10478,14 +10502,14 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_security_ssl_credentials_test", + "name": "test_core_slice_slice_buffer_test", "platforms": [ "linux", "mac", "posix", "windows" ], - "uses_polling": true + "uses_polling": false }, { "args": [], @@ -10502,7 +10526,7 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_slice_slice_buffer_test", + "name": "test_core_slice_slice_test", "platforms": [ "linux", "mac", @@ -10516,9 +10540,7 @@ "benchmark": false, "ci_platforms": [ "linux", - "mac", - "posix", - "windows" + "posix" ], "cpu_cost": 1.0, "exclude_configs": [], @@ -10526,12 +10548,10 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_slice_slice_test", + "name": "test_core_transport_test_suite_chaotic_good_test", "platforms": [ "linux", - "mac", - "posix", - "windows" + "posix" ], "uses_polling": false }, @@ -10540,7 +10560,9 @@ "benchmark": false, "ci_platforms": [ "linux", - "posix" + "mac", + "posix", + "windows" ], "cpu_cost": 1.0, "exclude_configs": [], @@ -10548,10 +10570,12 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "test_core_transport_test_suite_chaotic_good_test", + "name": "test_core_util_time_test", "platforms": [ "linux", - "posix" + "mac", + "posix", + "windows" ], "uses_polling": false }, diff --git a/tools/run_tests/run_xds_tests.py b/tools/run_tests/run_xds_tests.py index 9c33ba10b3e..a72f2aa2e14 100755 --- a/tools/run_tests/run_xds_tests.py +++ b/tools/run_tests/run_xds_tests.py @@ -4066,6 +4066,16 @@ try: client_env["GRPC_XDS_EXPERIMENTAL_ENABLE_TIMEOUT"] = "true" client_env["GRPC_XDS_EXPERIMENTAL_FAULT_INJECTION"] = "true" for test_case in args.test_case: + # Circuit breaking ported to the new framework. + # https://github.com/grpc/psm-interop/blob/main/tests/circuit_breaking_test.py + # To avoid backports, skipping it in the driver. + if test_case == "circuit_breaking": + logger.info( + "Ported to https://github.com/grpc/psm-interop/" + "blob/main/tests/circuit_breaking_test.py" + ) + continue + if test_case in _V3_TEST_CASES and not args.xds_v3_support: logger.info( "skipping test %s due to missing v3 support", test_case diff --git a/tools/run_tests/sanity/check_absl_mutex.sh b/tools/run_tests/sanity/check_absl_mutex.sh index a2f8812e0a8..e4b5cb27d9d 100755 --- a/tools/run_tests/sanity/check_absl_mutex.sh +++ b/tools/run_tests/sanity/check_absl_mutex.sh @@ -29,7 +29,7 @@ find . \( \( -name "*.cc" \) -or \( -name "*.h" \) \) \ -or \( -wholename "./test/*" \) \) \ -a -not -wholename "./include/grpcpp/impl/sync.h" \ -a -not -wholename "./src/core/lib/gprpp/sync.h" \ - -a -not -wholename "./src/core/lib/gpr/sync_abseil.cc" \ + -a -not -wholename "./src/core/util/sync_abseil.cc" \ -print0 |\ xargs -0 grep -n "absl::Mutex" | \ diff - /dev/null