From a5274614c46757fdab360a5bb3d9075d99658e99 Mon Sep 17 00:00:00 2001 From: dennycd Date: Fri, 30 Aug 2024 00:07:26 +0000 Subject: [PATCH] Native source sync at revision @66e013d --- gRPC-C++.podspec | 22 +- gRPC-Core.podspec | 31 +- include/grpc/credentials.h | 2 +- .../grpc/event_engine/internal/slice_cast.h | 2 +- include/grpc/event_engine/slice.h | 1 - include/grpc/event_engine/slice_buffer.h | 1 - include/grpc/grpc_crl_provider.h | 2 +- include/grpc/impl/channel_arg_names.h | 2 +- include/grpc/support/log.h | 37 +- include/grpc/support/sync_generic.h | 6 +- include/grpcpp/client_context.h | 1 - include/grpcpp/completion_queue.h | 1 - include/grpcpp/ext/call_metric_recorder.h | 2 +- include/grpcpp/impl/interceptor_common.h | 1 - include/grpcpp/impl/metadata_map.h | 1 - include/grpcpp/impl/proto_utils.h | 1 - .../grpcpp/impl/server_callback_handlers.h | 1 - include/grpcpp/impl/service_type.h | 1 - include/grpcpp/impl/sync.h | 1 - include/grpcpp/security/credentials.h | 4 +- .../security/tls_certificate_provider.h | 1 - .../security/tls_certificate_verifier.h | 1 - .../grpcpp/security/tls_credentials_options.h | 1 - include/grpcpp/server_builder.h | 2 +- include/grpcpp/server_interface.h | 1 - include/grpcpp/support/async_stream.h | 1 - include/grpcpp/support/async_unary_call.h | 1 - include/grpcpp/support/byte_buffer.h | 3 +- include/grpcpp/support/callback_common.h | 27 +- include/grpcpp/support/client_callback.h | 1 - include/grpcpp/support/client_interceptor.h | 1 - include/grpcpp/support/config.h | 2 +- include/grpcpp/support/global_callback_hook.h | 58 + include/grpcpp/support/interceptor.h | 2 +- include/grpcpp/support/method_handler.h | 1 - include/grpcpp/support/proto_buffer_reader.h | 1 - include/grpcpp/support/proto_buffer_writer.h | 1 - include/grpcpp/support/server_interceptor.h | 1 - include/grpcpp/support/sync_stream.h | 1 - src/core/channelz/channelz.cc | 1 - src/core/channelz/channelz_registry.cc | 1 - .../client_channel/client_channel_internal.h | 2 - src/core/client_channel/config_selector.h | 1 - src/core/client_channel/dynamic_filters.cc | 2 - .../client_channel/local_subchannel_pool.cc | 2 - src/core/client_channel/retry_filter.h | 1 - .../retry_filter_legacy_call_data.cc | 430 ++- src/core/client_channel/subchannel.cc | 43 +- .../backend_metrics/backend_metric_filter.cc | 17 +- .../legacy_channel_idle_filter.cc | 1 - .../fault_injection/fault_injection_filter.cc | 7 +- .../message_compress/compression_filter.cc | 16 +- .../filters/http/server/http_server_filter.cc | 6 +- .../message_size/message_size_filter.cc | 9 +- .../stateful_session_filter.cc | 2 - src/core/ext/transport/chttp2/alpn/alpn.cc | 1 - .../transport/chttp2/transport/bin_encoder.cc | 1 - .../chttp2/transport/chttp2_transport.cc | 551 ++-- .../chttp2/transport/flow_control.cc | 7 +- .../transport/chttp2/transport/flow_control.h | 1 - .../ext/transport/chttp2/transport/frame.cc | 1 - .../transport/chttp2/transport/frame_data.cc | 1 - .../chttp2/transport/frame_goaway.cc | 1 - .../transport/chttp2/transport/frame_ping.cc | 12 +- .../chttp2/transport/frame_rst_stream.cc | 7 +- .../chttp2/transport/frame_settings.cc | 11 +- .../chttp2/transport/frame_window_update.cc | 1 - .../chttp2/transport/hpack_encoder.cc | 5 +- .../chttp2/transport/hpack_encoder_table.cc | 1 - .../chttp2/transport/hpack_parse_result.h | 1 - .../chttp2/transport/hpack_parser.cc | 53 +- .../transport/chttp2/transport/hpack_parser.h | 2 + .../chttp2/transport/hpack_parser_table.cc | 42 +- .../chttp2/transport/hpack_parser_table.h | 33 +- .../ext/transport/chttp2/transport/internal.h | 3 - .../max_concurrent_streams_policy.cc | 45 - .../transport/max_concurrent_streams_policy.h | 67 - .../ext/transport/chttp2/transport/parsing.cc | 51 +- .../chttp2/transport/ping_callbacks.cc | 1 - .../chttp2/transport/stream_lists.cc | 14 +- .../ext/transport/chttp2/transport/varint.h | 1 - .../chttp2/transport/write_size_policy.cc | 1 - .../ext/transport/chttp2/transport/writing.cc | 37 +- .../filters/http/gcp_authn/v3/gcp_authn.upb.h | 431 +++ .../gcp_authn/v3/gcp_authn.upb_minitable.c | 129 + .../gcp_authn/v3/gcp_authn.upb_minitable.h | 33 + .../http/gcp_authn/v3/gcp_authn.upbdefs.c | 86 + .../http/gcp_authn/v3/gcp_authn.upbdefs.h | 47 + src/core/handshaker/handshaker.cc | 50 +- .../handshaker/security/secure_endpoint.cc | 23 +- .../security/security_handshaker.cc | 132 +- .../tcp_connect/tcp_connect_handshaker.cc | 1 - src/core/lib/channel/channel_stack.cc | 1 - src/core/lib/channel/channel_stack.h | 1 - .../lib/channel/channel_stack_builder_impl.cc | 1 - src/core/lib/channel/connected_channel.cc | 1 - src/core/lib/channel/promise_based_filter.cc | 335 +-- .../lib/compression/compression_internal.cc | 1 - src/core/lib/config/config_vars.cc | 12 +- src/core/lib/config/config_vars.h | 8 + src/core/lib/config/core_configuration.cc | 1 - src/core/lib/config/core_configuration.h | 1 - src/core/lib/debug/event_log.cc | 1 - src/core/lib/debug/trace_flags.cc | 22 +- src/core/lib/debug/trace_flags.h | 7 +- src/core/lib/debug/trace_impl.h | 6 + src/core/lib/event_engine/ares_resolver.cc | 132 +- src/core/lib/event_engine/ares_resolver.h | 9 - .../cf_engine/cfstream_endpoint.cc | 15 +- .../cf_engine/cftype_unique_ref.h | 2 +- src/core/lib/event_engine/forkable.cc | 1 - src/core/lib/event_engine/forkable.h | 1 - .../posix_engine/ev_epoll1_linux.cc | 2 +- .../posix_engine/ev_epoll1_linux.h | 8 +- .../posix_engine/ev_poll_posix.cc | 1 - .../posix_engine/lockfree_event.cc | 1 - .../posix_engine/posix_endpoint.cc | 7 +- .../posix_engine/posix_endpoint.h | 1 - .../posix_engine/posix_engine_listener.h | 4 +- .../posix_engine/tcp_socket_utils.h | 3 +- .../posix_engine/timer_manager.cc | 13 +- .../posix_engine/traced_buffer_list.cc | 1 - src/core/lib/event_engine/resolved_address.cc | 1 - src/core/lib/event_engine/slice.cc | 1 - .../event_engine/thread_pool/thread_count.cc | 1 - .../windows/grpc_polled_fd_windows.cc | 214 +- src/core/lib/experiments/config.cc | 25 +- src/core/lib/experiments/experiments.cc | 93 +- src/core/lib/experiments/experiments.h | 38 +- src/core/lib/gprpp/chunked_vector.h | 1 - src/core/lib/gprpp/down_cast.h | 1 - src/core/lib/gprpp/host_port.cc | 1 - src/core/lib/gprpp/load_file.cc | 1 - src/core/lib/gprpp/mpscq.h | 1 - src/core/lib/gprpp/single_set_ptr.h | 1 - src/core/lib/gprpp/status_helper.cc | 1 - src/core/lib/gprpp/sync.h | 1 - src/core/lib/gprpp/table.h | 28 + src/core/lib/gprpp/thd.h | 1 - src/core/lib/gprpp/time.h | 1 - src/core/lib/gprpp/time_util.cc | 1 - .../lib/gprpp/windows/directory_reader.cc | 2 - src/core/lib/gprpp/windows/thd.cc | 1 - src/core/lib/gprpp/work_serializer.cc | 57 +- src/core/lib/iomgr/buffer_list.cc | 1 - src/core/lib/iomgr/call_combiner.h | 14 +- src/core/lib/iomgr/cfstream_handle.cc | 14 +- src/core/lib/iomgr/closure.h | 13 +- src/core/lib/iomgr/combiner.cc | 14 +- src/core/lib/iomgr/endpoint_cfstream.cc | 31 +- src/core/lib/iomgr/endpoint_pair_posix.cc | 1 - src/core/lib/iomgr/error.h | 1 - src/core/lib/iomgr/ev_apple.cc | 31 +- src/core/lib/iomgr/ev_epoll1_linux.cc | 132 +- src/core/lib/iomgr/ev_poll_posix.cc | 41 +- src/core/lib/iomgr/ev_posix.cc | 99 +- src/core/lib/iomgr/ev_posix.h | 5 - .../lib/iomgr/event_engine_shims/closure.cc | 16 +- .../lib/iomgr/event_engine_shims/endpoint.cc | 7 +- src/core/lib/iomgr/exec_ctx.cc | 15 +- src/core/lib/iomgr/exec_ctx.h | 1 - src/core/lib/iomgr/executor.cc | 76 +- src/core/lib/iomgr/fork_windows.cc | 1 - src/core/lib/iomgr/internal_errqueue.cc | 1 - src/core/lib/iomgr/iocp_windows.cc | 1 - src/core/lib/iomgr/iomgr_windows.cc | 2 - src/core/lib/iomgr/lockfree_event.cc | 18 +- src/core/lib/iomgr/polling_entity.cc | 13 +- src/core/lib/iomgr/pollset_windows.cc | 2 - src/core/lib/iomgr/resolve_address.cc | 1 - src/core/lib/iomgr/resolve_address_posix.cc | 1 - src/core/lib/iomgr/resolve_address_windows.cc | 1 - src/core/lib/iomgr/sockaddr_utils_posix.cc | 1 - src/core/lib/iomgr/socket_mutator.cc | 1 - src/core/lib/iomgr/socket_utils_linux.cc | 2 - src/core/lib/iomgr/socket_utils_posix.cc | 1 - src/core/lib/iomgr/socket_utils_windows.cc | 2 - src/core/lib/iomgr/tcp_client_cfstream.cc | 19 +- src/core/lib/iomgr/tcp_client_posix.cc | 20 +- src/core/lib/iomgr/tcp_client_windows.cc | 1 - src/core/lib/iomgr/tcp_posix.cc | 97 +- src/core/lib/iomgr/tcp_server_posix.cc | 18 +- src/core/lib/iomgr/tcp_windows.cc | 16 +- src/core/lib/iomgr/timer_generic.cc | 111 +- src/core/lib/iomgr/timer_manager.cc | 9 +- src/core/lib/iomgr/unix_sockets_posix.cc | 1 - src/core/lib/iomgr/unix_sockets_posix_noop.cc | 2 - src/core/lib/iomgr/vsock.cc | 1 - src/core/lib/iomgr/wakeup_fd_eventfd.cc | 2 - src/core/lib/promise/activity.h | 1 - src/core/lib/promise/context.h | 1 - src/core/lib/promise/detail/join_state.h | 88 +- src/core/lib/promise/detail/seq_state.h | 2457 ++++++++--------- src/core/lib/promise/for_each.h | 23 +- src/core/lib/promise/interceptor_list.h | 44 +- src/core/lib/promise/latch.h | 40 +- src/core/lib/promise/map.h | 2 +- src/core/lib/promise/party.cc | 6 +- src/core/lib/promise/pipe.h | 7 +- src/core/lib/promise/poll.h | 1 - src/core/lib/promise/status_flag.h | 1 - .../lib/resource_quota/connection_quota.cc | 1 - src/core/lib/resource_quota/memory_quota.cc | 30 +- src/core/lib/resource_quota/memory_quota.h | 6 +- src/core/lib/resource_quota/thread_quota.cc | 1 - .../security/authorization/audit_logging.cc | 1 - .../grpc_authorization_engine.cc | 1 - .../grpc_authorization_policy_provider.cc | 9 +- .../authorization/grpc_server_authz_filter.cc | 33 +- .../security/authorization/rbac_translator.cc | 1 - .../security/authorization/stdout_logger.cc | 1 - .../credentials/alts/check_gcp_environment.cc | 1 - .../alts/check_gcp_environment_windows.cc | 1 - .../security/credentials/call_creds_util.cc | 1 - .../composite/composite_credentials.cc | 1 - .../composite/composite_credentials.h | 2 + .../lib/security/credentials/credentials.h | 3 +- .../aws_external_account_credentials.cc | 646 +++-- .../aws_external_account_credentials.h | 95 +- .../external/external_account_credentials.cc | 744 ++--- .../external/external_account_credentials.h | 172 +- .../file_external_account_credentials.cc | 127 +- .../file_external_account_credentials.h | 34 +- .../url_external_account_credentials.cc | 207 +- .../url_external_account_credentials.h | 31 +- .../credentials/fake/fake_credentials.h | 2 + .../google_default_credentials.cc | 68 +- .../credentials/iam/iam_credentials.cc | 1 - .../credentials/iam/iam_credentials.h | 2 + .../credentials/jwt/jwt_credentials.h | 2 + .../credentials/oauth2/oauth2_credentials.cc | 422 ++- .../credentials/oauth2/oauth2_credentials.h | 90 +- .../credentials/plugin/plugin_credentials.cc | 28 +- .../credentials/plugin/plugin_credentials.h | 2 + .../credentials/ssl/ssl_credentials.h | 1 - .../tls/grpc_tls_certificate_distributor.cc | 1 - .../tls/grpc_tls_certificate_provider.h | 1 - .../tls/grpc_tls_certificate_verifier.cc | 1 - .../tls/grpc_tls_certificate_verifier.h | 1 - .../token_fetcher_credentials.cc | 300 ++ .../token_fetcher/token_fetcher_credentials.h | 176 ++ .../credentials/xds/xds_credentials.cc | 1 - .../fake/fake_security_connector.cc | 1 - .../insecure/insecure_security_connector.cc | 1 - .../load_system_roots_windows.cc | 1 - .../security/transport/server_auth_filter.cc | 10 +- src/core/lib/slice/percent_encoding.cc | 1 - src/core/lib/slice/slice.cc | 1 - src/core/lib/slice/slice.h | 1 - src/core/lib/slice/slice_buffer.cc | 1 - src/core/lib/slice/slice_internal.h | 1 - src/core/lib/slice/slice_refcount.h | 14 +- src/core/lib/surface/byte_buffer_reader.cc | 1 - src/core/lib/surface/call.cc | 15 +- src/core/lib/surface/call.h | 19 + src/core/lib/surface/call_utils.h | 1 - src/core/lib/surface/channel.cc | 1 - src/core/lib/surface/channel_create.cc | 1 - src/core/lib/surface/channel_init.h | 1 - src/core/lib/surface/client_call.cc | 1 - src/core/lib/surface/client_call.h | 1 - src/core/lib/surface/completion_queue.cc | 26 +- .../lib/surface/completion_queue_factory.cc | 1 - src/core/lib/surface/filter_stack_call.cc | 16 +- src/core/lib/surface/filter_stack_call.h | 1 - src/core/lib/surface/lame_client.cc | 1 - src/core/lib/surface/server_call.cc | 1 - src/core/lib/surface/server_call.h | 1 - src/core/lib/surface/validate_metadata.h | 1 - src/core/lib/transport/bdp_estimator.cc | 21 +- src/core/lib/transport/bdp_estimator.h | 14 +- src/core/lib/transport/call_filters.cc | 15 +- src/core/lib/transport/call_spine.h | 37 +- src/core/lib/transport/connectivity_state.cc | 76 +- src/core/lib/transport/metadata_batch.h | 42 +- src/core/lib/transport/timeout_encoding.cc | 1 - src/core/lib/transport/transport.h | 14 +- src/core/lib/transport/transport_op_string.cc | 1 - src/core/lib/uri/uri_parser.cc | 1 - src/core/load_balancing/grpclb/grpclb.cc | 118 +- .../load_balancing/health_check_client.cc | 73 +- src/core/load_balancing/oob_backend_metric.cc | 6 +- .../outlier_detection/outlier_detection.cc | 228 +- .../load_balancing/pick_first/pick_first.cc | 396 ++- src/core/load_balancing/priority/priority.cc | 183 +- .../load_balancing/ring_hash/ring_hash.cc | 78 +- src/core/load_balancing/rls/rls.cc | 460 +-- .../load_balancing/round_robin/round_robin.cc | 91 +- .../static_stride_scheduler.cc | 1 - .../weighted_round_robin.cc | 195 +- .../weighted_target/weighted_target.cc | 127 +- src/core/load_balancing/xds/cds.cc | 69 +- .../load_balancing/xds/xds_cluster_impl.cc | 111 +- .../load_balancing/xds/xds_cluster_manager.cc | 86 +- .../load_balancing/xds/xds_override_host.cc | 226 +- .../load_balancing/xds/xds_wrr_locality.cc | 38 +- src/core/resolver/binder/binder_resolver.cc | 2 - .../resolver/dns/c_ares/dns_resolver_ares.cc | 106 +- .../dns/c_ares/grpc_ares_ev_driver_posix.cc | 2 - .../dns/c_ares/grpc_ares_ev_driver_windows.cc | 199 +- .../resolver/dns/c_ares/grpc_ares_wrapper.cc | 228 +- .../resolver/dns/c_ares/grpc_ares_wrapper.h | 7 - src/core/resolver/dns/dns_resolver_plugin.cc | 1 - .../event_engine_client_channel_resolver.cc | 79 +- src/core/resolver/dns/native/dns_resolver.cc | 22 +- src/core/resolver/endpoint_addresses.cc | 1 - src/core/resolver/fake/fake_resolver.cc | 1 - src/core/resolver/xds/xds_config.cc | 96 + src/core/resolver/xds/xds_config.h | 109 + .../resolver/xds/xds_dependency_manager.cc | 213 +- .../resolver/xds/xds_dependency_manager.h | 70 +- src/core/resolver/xds/xds_resolver.cc | 71 +- .../server/server_config_selector_filter.cc | 1 - src/core/server/xds_server_config_fetcher.cc | 8 +- .../service_config_channel_arg_filter.cc | 1 - src/core/service_config/service_config_impl.h | 1 - src/core/telemetry/call_tracer.cc | 1 - src/core/telemetry/metrics.h | 1 - src/core/telemetry/stats_data.cc | 67 + src/core/telemetry/stats_data.h | 48 + .../alts/handshaker/alts_shared_resource.cc | 1 - .../transport_security_common_api.h | 1 - .../alts_iovec_record_protocol.cc | 1 - src/core/tsi/fake_transport_security.cc | 11 +- .../ssl/session_cache/ssl_session_cache.cc | 1 - src/core/util/alloc.cc | 1 - src/core/util/android/log.cc | 51 - src/core/util/gcp_metadata_query.cc | 1 - src/core/util/http_client/httpcli.cc | 16 +- src/core/util/http_client/httpcli.h | 23 +- src/core/util/http_client/parser.cc | 7 +- src/core/util/json/json_reader.cc | 1 - src/core/util/latent_see.cc | 27 +- src/core/util/latent_see.h | 95 +- src/core/util/linux/log.cc | 72 - src/core/util/log.cc | 65 +- src/core/util/msys/tmpfile.cc | 1 - src/core/util/posix/log.cc | 72 - src/core/util/posix/sync.cc | 1 - src/core/util/posix/time.cc | 1 - src/core/util/ring_buffer.h | 123 + src/core/util/spinlock.h | 3 +- src/core/util/string.cc | 1 - src/core/util/sync.cc | 1 - src/core/util/sync_abseil.cc | 1 - src/core/util/time.cc | 1 - src/core/util/unique_ptr_with_bitset.h | 86 + src/core/util/useful.h | 24 - src/core/util/windows/cpu.cc | 1 - src/core/util/windows/log.cc | 76 - src/core/util/windows/sync.cc | 1 - src/core/util/windows/time.cc | 1 - src/core/util/windows/tmpfile.cc | 1 - src/core/xds/grpc/xds_certificate_provider.cc | 1 - src/core/xds/grpc/xds_client_grpc.cc | 27 +- src/core/xds/grpc/xds_cluster.cc | 10 +- src/core/xds/grpc/xds_cluster.h | 8 +- src/core/xds/grpc/xds_cluster_parser.cc | 154 +- .../xds/grpc/xds_cluster_specifier_plugin.cc | 1 - src/core/xds/grpc/xds_common_types_parser.cc | 8 +- src/core/xds/grpc/xds_common_types_parser.h | 17 + src/core/xds/grpc/xds_endpoint_parser.cc | 28 +- src/core/xds/grpc/xds_http_fault_filter.cc | 8 +- src/core/xds/grpc/xds_http_filter_registry.cc | 1 - src/core/xds/grpc/xds_http_rbac_filter.cc | 10 +- src/core/xds/grpc/xds_lb_policy_registry.cc | 30 +- src/core/xds/grpc/xds_listener_parser.cc | 17 +- src/core/xds/grpc/xds_metadata.cc | 62 + src/core/xds/grpc/xds_metadata.h | 127 + src/core/xds/grpc/xds_metadata_parser.cc | 143 + src/core/xds/grpc/xds_metadata_parser.h | 36 + src/core/xds/grpc/xds_route_config_parser.cc | 27 +- src/core/xds/grpc/xds_routing.cc | 1 - src/core/xds/grpc/xds_transport_grpc.cc | 1 - src/core/xds/xds_client/xds_client.cc | 288 +- src/core/xds/xds_client/xds_client_stats.cc | 47 +- src/cpp/client/channel_cc.cc | 1 - src/cpp/client/client_context.cc | 1 - src/cpp/client/global_callback_hook.cc | 36 + src/cpp/client/xds_credentials.cc | 1 - src/cpp/common/alarm.cc | 1 - src/cpp/common/channel_arguments.cc | 1 - src/cpp/common/tls_certificate_provider.cc | 1 - src/cpp/common/tls_certificate_verifier.cc | 1 - src/cpp/common/tls_credentials_options.cc | 1 - src/cpp/server/backend_metric_recorder.cc | 195 +- src/cpp/server/insecure_server_credentials.cc | 1 - src/cpp/server/xds_server_credentials.cc | 1 - .../private/GRPCCore/GRPCChannel.mm | 2 - .../private/GRPCCore/GRPCChannelPool.mm | 2 - 390 files changed, 8758 insertions(+), 7971 deletions(-) create mode 100644 include/grpcpp/support/global_callback_hook.h delete mode 100644 src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.cc delete mode 100644 src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.h create mode 100644 src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb.h create mode 100644 src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.c create mode 100644 src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.h create mode 100644 src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.c create mode 100644 src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.h create mode 100644 src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.cc create mode 100644 src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.h create mode 100644 src/core/resolver/xds/xds_config.cc create mode 100644 src/core/resolver/xds/xds_config.h delete mode 100644 src/core/util/android/log.cc delete mode 100644 src/core/util/linux/log.cc delete mode 100644 src/core/util/posix/log.cc create mode 100644 src/core/util/ring_buffer.h create mode 100644 src/core/util/unique_ptr_with_bitset.h delete mode 100644 src/core/util/windows/log.cc create mode 100644 src/core/xds/grpc/xds_metadata.cc create mode 100644 src/core/xds/grpc/xds_metadata.h create mode 100644 src/core/xds/grpc/xds_metadata_parser.cc create mode 100644 src/core/xds/grpc/xds_metadata_parser.h create mode 100644 src/cpp/client/global_callback_hook.cc diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 37c11517ff..b02f8ac3d0 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -206,6 +206,7 @@ Pod::Spec.new do |s| 'include/grpcpp/support/client_callback.h', 'include/grpcpp/support/client_interceptor.h', 'include/grpcpp/support/config.h', + 'include/grpcpp/support/global_callback_hook.h', 'include/grpcpp/support/interceptor.h', 'include/grpcpp/support/message_allocator.h', 'include/grpcpp/support/method_handler.h', @@ -374,7 +375,6 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/transport/huffsyms.h', 'src/core/ext/transport/chttp2/transport/internal.h', 'src/core/ext/transport/chttp2/transport/legacy_frame.h', - 'src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.h', 'src/core/ext/transport/chttp2/transport/ping_abuse_policy.h', 'src/core/ext/transport/chttp2/transport/ping_callbacks.h', 'src/core/ext/transport/chttp2/transport/ping_rate_policy.h', @@ -518,6 +518,8 @@ Pod::Spec.new do |s| 'src/core/ext/upb-gen/envoy/extensions/filters/common/fault/v3/fault.upb_minitable.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/fault/v3/fault.upb.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/fault/v3/fault.upb_minitable.h', + 'src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb.h', + 'src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/rbac/v3/rbac.upb.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/rbac/v3/rbac.upb_minitable.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/router/v3/router.upb.h', @@ -780,6 +782,7 @@ Pod::Spec.new do |s| 'src/core/ext/upbdefs-gen/envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/common/fault/v3/fault.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/fault/v3/fault.upbdefs.h', + 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/router/v3/router.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upbdefs.h', @@ -1159,6 +1162,7 @@ Pod::Spec.new do |s| 'src/core/lib/security/credentials/tls/grpc_tls_crl_provider.h', 'src/core/lib/security/credentials/tls/tls_credentials.h', 'src/core/lib/security/credentials/tls/tls_utils.h', + 'src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.h', 'src/core/lib/security/credentials/xds/xds_credentials.h', 'src/core/lib/security/security_connector/alts/alts_security_connector.h', 'src/core/lib/security/security_connector/fake/fake_security_connector.h', @@ -1261,6 +1265,7 @@ Pod::Spec.new do |s| 'src/core/resolver/resolver_factory.h', 'src/core/resolver/resolver_registry.h', 'src/core/resolver/server_address.h', + 'src/core/resolver/xds/xds_config.h', 'src/core/resolver/xds/xds_dependency_manager.h', 'src/core/resolver/xds/xds_resolver_attributes.h', 'src/core/server/server.h', @@ -1322,10 +1327,12 @@ Pod::Spec.new do |s| 'src/core/util/json/json_util.h', 'src/core/util/json/json_writer.h', 'src/core/util/latent_see.h', + 'src/core/util/ring_buffer.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/unique_ptr_with_bitset.h', 'src/core/util/upb_utils.h', 'src/core/util/useful.h', 'src/core/xds/grpc/certificate_provider_store.h', @@ -1351,6 +1358,8 @@ Pod::Spec.new do |s| 'src/core/xds/grpc/xds_lb_policy_registry.h', 'src/core/xds/grpc/xds_listener.h', 'src/core/xds/grpc/xds_listener_parser.h', + 'src/core/xds/grpc/xds_metadata.h', + 'src/core/xds/grpc/xds_metadata_parser.h', 'src/core/xds/grpc/xds_route_config.h', 'src/core/xds/grpc/xds_route_config_parser.h', 'src/core/xds/grpc/xds_routing.h', @@ -1377,6 +1386,7 @@ Pod::Spec.new do |s| 'src/cpp/client/create_channel_internal.cc', 'src/cpp/client/create_channel_internal.h', 'src/cpp/client/create_channel_posix.cc', + 'src/cpp/client/global_callback_hook.cc', 'src/cpp/client/insecure_credentials.cc', 'src/cpp/client/secure_credentials.cc', 'src/cpp/client/secure_credentials.h', @@ -1657,7 +1667,6 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/transport/huffsyms.h', 'src/core/ext/transport/chttp2/transport/internal.h', 'src/core/ext/transport/chttp2/transport/legacy_frame.h', - 'src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.h', 'src/core/ext/transport/chttp2/transport/ping_abuse_policy.h', 'src/core/ext/transport/chttp2/transport/ping_callbacks.h', 'src/core/ext/transport/chttp2/transport/ping_rate_policy.h', @@ -1801,6 +1810,8 @@ Pod::Spec.new do |s| 'src/core/ext/upb-gen/envoy/extensions/filters/common/fault/v3/fault.upb_minitable.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/fault/v3/fault.upb.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/fault/v3/fault.upb_minitable.h', + 'src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb.h', + 'src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/rbac/v3/rbac.upb.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/rbac/v3/rbac.upb_minitable.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/router/v3/router.upb.h', @@ -2063,6 +2074,7 @@ Pod::Spec.new do |s| 'src/core/ext/upbdefs-gen/envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/common/fault/v3/fault.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/fault/v3/fault.upbdefs.h', + 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/router/v3/router.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upbdefs.h', @@ -2442,6 +2454,7 @@ Pod::Spec.new do |s| 'src/core/lib/security/credentials/tls/grpc_tls_crl_provider.h', 'src/core/lib/security/credentials/tls/tls_credentials.h', 'src/core/lib/security/credentials/tls/tls_utils.h', + 'src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.h', 'src/core/lib/security/credentials/xds/xds_credentials.h', 'src/core/lib/security/security_connector/alts/alts_security_connector.h', 'src/core/lib/security/security_connector/fake/fake_security_connector.h', @@ -2544,6 +2557,7 @@ Pod::Spec.new do |s| 'src/core/resolver/resolver_factory.h', 'src/core/resolver/resolver_registry.h', 'src/core/resolver/server_address.h', + 'src/core/resolver/xds/xds_config.h', 'src/core/resolver/xds/xds_dependency_manager.h', 'src/core/resolver/xds/xds_resolver_attributes.h', 'src/core/server/server.h', @@ -2605,10 +2619,12 @@ Pod::Spec.new do |s| 'src/core/util/json/json_util.h', 'src/core/util/json/json_writer.h', 'src/core/util/latent_see.h', + 'src/core/util/ring_buffer.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/unique_ptr_with_bitset.h', 'src/core/util/upb_utils.h', 'src/core/util/useful.h', 'src/core/xds/grpc/certificate_provider_store.h', @@ -2634,6 +2650,8 @@ Pod::Spec.new do |s| 'src/core/xds/grpc/xds_lb_policy_registry.h', 'src/core/xds/grpc/xds_listener.h', 'src/core/xds/grpc/xds_listener_parser.h', + 'src/core/xds/grpc/xds_metadata.h', + 'src/core/xds/grpc/xds_metadata_parser.h', 'src/core/xds/grpc/xds_route_config.h', 'src/core/xds/grpc/xds_route_config_parser.h', 'src/core/xds/grpc/xds_routing.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 328c3093d9..4948727543 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -364,8 +364,6 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/transport/huffsyms.h', 'src/core/ext/transport/chttp2/transport/internal.h', 'src/core/ext/transport/chttp2/transport/legacy_frame.h', - 'src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.cc', - 'src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.h', 'src/core/ext/transport/chttp2/transport/parsing.cc', 'src/core/ext/transport/chttp2/transport/ping_abuse_policy.cc', 'src/core/ext/transport/chttp2/transport/ping_abuse_policy.h', @@ -587,6 +585,9 @@ Pod::Spec.new do |s| 'src/core/ext/upb-gen/envoy/extensions/filters/http/fault/v3/fault.upb.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/fault/v3/fault.upb_minitable.c', 'src/core/ext/upb-gen/envoy/extensions/filters/http/fault/v3/fault.upb_minitable.h', + 'src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb.h', + 'src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.c', + 'src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/rbac/v3/rbac.upb.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/rbac/v3/rbac.upb_minitable.c', 'src/core/ext/upb-gen/envoy/extensions/filters/http/rbac/v3/rbac.upb_minitable.h', @@ -1014,6 +1015,8 @@ Pod::Spec.new do |s| 'src/core/ext/upbdefs-gen/envoy/extensions/filters/common/fault/v3/fault.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/fault/v3/fault.upbdefs.c', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/fault/v3/fault.upbdefs.h', + 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.c', + 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.c', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/router/v3/router.upbdefs.c', @@ -1719,6 +1722,8 @@ Pod::Spec.new do |s| 'src/core/lib/security/credentials/tls/tls_credentials.h', 'src/core/lib/security/credentials/tls/tls_utils.cc', 'src/core/lib/security/credentials/tls/tls_utils.h', + 'src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.cc', + 'src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.h', 'src/core/lib/security/credentials/xds/xds_credentials.cc', 'src/core/lib/security/credentials/xds/xds_credentials.h', 'src/core/lib/security/security_connector/alts/alts_security_connector.cc', @@ -1929,6 +1934,8 @@ Pod::Spec.new do |s| 'src/core/resolver/resolver_registry.h', 'src/core/resolver/server_address.h', 'src/core/resolver/sockaddr/sockaddr_resolver.cc', + 'src/core/resolver/xds/xds_config.cc', + 'src/core/resolver/xds/xds_config.h', 'src/core/resolver/xds/xds_dependency_manager.cc', 'src/core/resolver/xds/xds_dependency_manager.h', 'src/core/resolver/xds/xds_resolver.cc', @@ -2022,7 +2029,6 @@ Pod::Spec.new do |s| '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/gcp_metadata_query.cc', 'src/core/util/gcp_metadata_query.h', @@ -2049,15 +2055,14 @@ Pod::Spec.new do |s| 'src/core/util/latent_see.cc', 'src/core/util/latent_see.h', '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/ring_buffer.h', 'src/core/util/spinlock.h', 'src/core/util/string.cc', 'src/core/util/string.h', @@ -2067,10 +2072,10 @@ Pod::Spec.new do |s| 'src/core/util/time_precise.cc', 'src/core/util/time_precise.h', 'src/core/util/tmpfile.h', + 'src/core/util/unique_ptr_with_bitset.h', 'src/core/util/upb_utils.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', @@ -2119,6 +2124,10 @@ Pod::Spec.new do |s| 'src/core/xds/grpc/xds_listener.h', 'src/core/xds/grpc/xds_listener_parser.cc', 'src/core/xds/grpc/xds_listener_parser.h', + 'src/core/xds/grpc/xds_metadata.cc', + 'src/core/xds/grpc/xds_metadata.h', + 'src/core/xds/grpc/xds_metadata_parser.cc', + 'src/core/xds/grpc/xds_metadata_parser.h', 'src/core/xds/grpc/xds_route_config.cc', 'src/core/xds/grpc/xds_route_config.h', 'src/core/xds/grpc/xds_route_config_parser.cc', @@ -2438,7 +2447,6 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/transport/huffsyms.h', 'src/core/ext/transport/chttp2/transport/internal.h', 'src/core/ext/transport/chttp2/transport/legacy_frame.h', - 'src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.h', 'src/core/ext/transport/chttp2/transport/ping_abuse_policy.h', 'src/core/ext/transport/chttp2/transport/ping_callbacks.h', 'src/core/ext/transport/chttp2/transport/ping_rate_policy.h', @@ -2582,6 +2590,8 @@ Pod::Spec.new do |s| 'src/core/ext/upb-gen/envoy/extensions/filters/common/fault/v3/fault.upb_minitable.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/fault/v3/fault.upb.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/fault/v3/fault.upb_minitable.h', + 'src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb.h', + 'src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/rbac/v3/rbac.upb.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/rbac/v3/rbac.upb_minitable.h', 'src/core/ext/upb-gen/envoy/extensions/filters/http/router/v3/router.upb.h', @@ -2844,6 +2854,7 @@ Pod::Spec.new do |s| 'src/core/ext/upbdefs-gen/envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/common/fault/v3/fault.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/fault/v3/fault.upbdefs.h', + 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/router/v3/router.upbdefs.h', 'src/core/ext/upbdefs-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upbdefs.h', @@ -3223,6 +3234,7 @@ Pod::Spec.new do |s| 'src/core/lib/security/credentials/tls/grpc_tls_crl_provider.h', 'src/core/lib/security/credentials/tls/tls_credentials.h', 'src/core/lib/security/credentials/tls/tls_utils.h', + 'src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.h', 'src/core/lib/security/credentials/xds/xds_credentials.h', 'src/core/lib/security/security_connector/alts/alts_security_connector.h', 'src/core/lib/security/security_connector/fake/fake_security_connector.h', @@ -3325,6 +3337,7 @@ Pod::Spec.new do |s| 'src/core/resolver/resolver_factory.h', 'src/core/resolver/resolver_registry.h', 'src/core/resolver/server_address.h', + 'src/core/resolver/xds/xds_config.h', 'src/core/resolver/xds/xds_dependency_manager.h', 'src/core/resolver/xds/xds_resolver_attributes.h', 'src/core/server/server.h', @@ -3386,10 +3399,12 @@ Pod::Spec.new do |s| 'src/core/util/json/json_util.h', 'src/core/util/json/json_writer.h', 'src/core/util/latent_see.h', + 'src/core/util/ring_buffer.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/unique_ptr_with_bitset.h', 'src/core/util/upb_utils.h', 'src/core/util/useful.h', 'src/core/xds/grpc/certificate_provider_store.h', @@ -3414,6 +3429,8 @@ Pod::Spec.new do |s| 'src/core/xds/grpc/xds_lb_policy_registry.h', 'src/core/xds/grpc/xds_listener.h', 'src/core/xds/grpc/xds_listener_parser.h', + 'src/core/xds/grpc/xds_metadata.h', + 'src/core/xds/grpc/xds_metadata_parser.h', 'src/core/xds/grpc/xds_route_config.h', 'src/core/xds/grpc/xds_route_config_parser.h', 'src/core/xds/grpc/xds_routing.h', diff --git a/include/grpc/credentials.h b/include/grpc/credentials.h index c3a076991c..b5814b913c 100644 --- a/include/grpc/credentials.h +++ b/include/grpc/credentials.h @@ -103,7 +103,7 @@ GRPCAPI grpc_call_credentials* grpc_sts_credentials_create( /** Context that can be used by metadata credentials plugin in order to create auth related metadata. */ typedef struct { - /** The fully qualifed service url. */ + /** The fully qualified service url. */ const char* service_url; /** The method name of the RPC being called (not fully qualified). diff --git a/include/grpc/event_engine/internal/slice_cast.h b/include/grpc/event_engine/internal/slice_cast.h index 3f9593464c..b6f3ae6277 100644 --- a/include/grpc/event_engine/internal/slice_cast.h +++ b/include/grpc/event_engine/internal/slice_cast.h @@ -24,7 +24,7 @@ namespace internal { // with `SliceCast`. Both ways need to be declared (i.e. if // SliceCastable exists, you should declare // SliceCastable too). -// The type has no members, it's just the existance of the specialization that +// The type has no members, it's just the existence of the specialization that // unlocks SliceCast usage for a type pair. template struct SliceCastable; diff --git a/include/grpc/event_engine/slice.h b/include/grpc/event_engine/slice.h index 8153f983a4..f4009648dc 100644 --- a/include/grpc/event_engine/slice.h +++ b/include/grpc/event_engine/slice.h @@ -25,7 +25,6 @@ #include #include -#include #include // This public slice definition largely based of the internal grpc_core::Slice diff --git a/include/grpc/event_engine/slice_buffer.h b/include/grpc/event_engine/slice_buffer.h index 0009089a6b..724c3d0729 100644 --- a/include/grpc/event_engine/slice_buffer.h +++ b/include/grpc/event_engine/slice_buffer.h @@ -28,7 +28,6 @@ #include #include #include -#include #include namespace grpc_event_engine { diff --git a/include/grpc/grpc_crl_provider.h b/include/grpc/grpc_crl_provider.h index 35d6df6f93..968d10b060 100644 --- a/include/grpc/grpc_crl_provider.h +++ b/include/grpc/grpc_crl_provider.h @@ -82,7 +82,7 @@ absl::StatusOr> CreateDirectoryReloaderCrlProvider( } // namespace experimental } // namespace grpc_core -// TODO(gtcooke94) - Mark with api macro when all wrapped langauges support C++ +// TODO(gtcooke94) - Mark with api macro when all wrapped languages support C++ // in core APIs /** * EXPERIMENTAL API - Subject to change diff --git a/include/grpc/impl/channel_arg_names.h b/include/grpc/impl/channel_arg_names.h index c47d928d5c..aa973c2197 100644 --- a/include/grpc/impl/channel_arg_names.h +++ b/include/grpc/impl/channel_arg_names.h @@ -259,7 +259,7 @@ issued by the tcp_write(). By default, this is set to 4. */ #define GRPC_ARG_TCP_TX_ZEROCOPY_MAX_SIMULT_SENDS \ "grpc.experimental.tcp_tx_zerocopy_max_simultaneous_sends" -/* Overrides the TCP socket recieve buffer size, SO_RCVBUF. */ +/* Overrides the TCP socket receive buffer size, SO_RCVBUF. */ #define GRPC_ARG_TCP_RECEIVE_BUFFER_SIZE "grpc.tcp_receive_buffer_size" /* Timeout in milliseconds to use for calls to the grpclb load balancer. If 0 or unset, the balancer calls will have no deadline. */ diff --git a/include/grpc/support/log.h b/include/grpc/support/log.h index 88e7628e0c..aa7f133177 100644 --- a/include/grpc/support/log.h +++ b/include/grpc/support/log.h @@ -28,13 +28,8 @@ extern "C" { #endif -/** - * Logging functions in this file are deprecated. - * Please use absl ABSL_LOG instead. - */ - /** The severity of a log message - use the #defines below when calling into - gpr_log to additionally supply file and line data */ + grpc_absl_log to additionally supply file and line data */ typedef enum gpr_log_severity { GPR_LOG_SEVERITY_DEBUG, GPR_LOG_SEVERITY_INFO, @@ -46,12 +41,32 @@ typedef enum gpr_log_severity { #define GPR_INFO __FILE__, __LINE__, GPR_LOG_SEVERITY_INFO #define GPR_ERROR __FILE__, __LINE__, GPR_LOG_SEVERITY_ERROR -/** Log a message. It's advised to use GPR_xxx above to generate the context - * for each message */ -GPRAPI void gpr_log(const char* file, int line, gpr_log_severity severity, - const char* format, ...) GPR_PRINT_FORMAT_CHECK(4, 5); +/** + * EXPERIMENTAL. API stability not guaranteed. + * Should only be used from gRPC PHP and RUBY. + * Equivalent to ABSL_LOG(severity) << message_str; + * **/ +GPRAPI void grpc_absl_log(const char* file, int line, gpr_log_severity severity, + const char* message_str); -GPRAPI int gpr_should_log(gpr_log_severity severity); +/** + * EXPERIMENTAL. API stability not guaranteed. + * Should only be used from gRPC PHP and RUBY. + * Equivalent to ABSL_LOG(severity) << message_str << num; + * **/ +GPRAPI void grpc_absl_log_int(const char* file, int line, + gpr_log_severity severity, + const char* message_str, intptr_t num); + +/** + * EXPERIMENTAL. API stability not guaranteed. + * Should only be used from gRPC PHP and RUBY. + * Equivalent to ABSL_LOG(severity) << message_str1 << message_str2; + * **/ +GPRAPI void grpc_absl_log_str(const char* file, int line, + gpr_log_severity severity, + const char* message_str1, + const char* message_str2); GPRAPI void gpr_log_verbosity_init(void); diff --git a/include/grpc/support/sync_generic.h b/include/grpc/support/sync_generic.h index b3e638ce54..aa0261c2b6 100644 --- a/include/grpc/support/sync_generic.h +++ b/include/grpc/support/sync_generic.h @@ -29,8 +29,7 @@ typedef struct { gpr_atm state; } gpr_event; -#define GPR_EVENT_INIT \ - { 0 } +#define GPR_EVENT_INIT {0} /* gpr_refcount */ typedef struct { @@ -42,7 +41,6 @@ typedef struct { gpr_atm value; } gpr_stats_counter; -#define GPR_STATS_INIT \ - { 0 } +#define GPR_STATS_INIT {0} #endif /* GRPC_SUPPORT_SYNC_GENERIC_H */ diff --git a/include/grpcpp/client_context.h b/include/grpcpp/client_context.h index d0934dd0f5..af3b533ed1 100644 --- a/include/grpcpp/client_context.h +++ b/include/grpcpp/client_context.h @@ -42,7 +42,6 @@ #include #include -#include #include #include #include diff --git a/include/grpcpp/completion_queue.h b/include/grpcpp/completion_queue.h index 63d202b0e2..2bb391fccf 100644 --- a/include/grpcpp/completion_queue.h +++ b/include/grpcpp/completion_queue.h @@ -38,7 +38,6 @@ #include #include -#include #include #include #include diff --git a/include/grpcpp/ext/call_metric_recorder.h b/include/grpcpp/ext/call_metric_recorder.h index 378a4594af..303a35db14 100644 --- a/include/grpcpp/ext/call_metric_recorder.h +++ b/include/grpcpp/ext/call_metric_recorder.h @@ -33,7 +33,7 @@ namespace experimental { /// Records call metrics for the purpose of load balancing. /// During an RPC, call \a ServerContext::ExperimentalGetCallMetricRecorder() -/// method to retrive the recorder for the current call. +/// method to retrieve the recorder for the current call. class CallMetricRecorder { public: virtual ~CallMetricRecorder() = default; diff --git a/include/grpcpp/impl/interceptor_common.h b/include/grpcpp/impl/interceptor_common.h index 7e3a566f6b..2d4c56701d 100644 --- a/include/grpcpp/impl/interceptor_common.h +++ b/include/grpcpp/impl/interceptor_common.h @@ -25,7 +25,6 @@ #include "absl/log/absl_check.h" #include -#include #include #include #include diff --git a/include/grpcpp/impl/metadata_map.h b/include/grpcpp/impl/metadata_map.h index 6ac9ed2984..6241df0c25 100644 --- a/include/grpcpp/impl/metadata_map.h +++ b/include/grpcpp/impl/metadata_map.h @@ -22,7 +22,6 @@ #include #include -#include #include namespace grpc { diff --git a/include/grpcpp/impl/proto_utils.h b/include/grpcpp/impl/proto_utils.h index f2cd8d21b7..d738ff3ab6 100644 --- a/include/grpcpp/impl/proto_utils.h +++ b/include/grpcpp/impl/proto_utils.h @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include diff --git a/include/grpcpp/impl/server_callback_handlers.h b/include/grpcpp/impl/server_callback_handlers.h index c097ab2ace..7a4b6cf9ae 100644 --- a/include/grpcpp/impl/server_callback_handlers.h +++ b/include/grpcpp/impl/server_callback_handlers.h @@ -22,7 +22,6 @@ #include #include -#include #include #include #include diff --git a/include/grpcpp/impl/service_type.h b/include/grpcpp/impl/service_type.h index 3e40e08b29..b6af6e1fc9 100644 --- a/include/grpcpp/impl/service_type.h +++ b/include/grpcpp/impl/service_type.h @@ -21,7 +21,6 @@ #include "absl/log/absl_check.h" -#include #include #include #include diff --git a/include/grpcpp/impl/sync.h b/include/grpcpp/impl/sync.h index 132e376d7a..a7ec965a00 100644 --- a/include/grpcpp/impl/sync.h +++ b/include/grpcpp/impl/sync.h @@ -30,7 +30,6 @@ #include "absl/log/absl_check.h" #include "absl/synchronization/mutex.h" -#include #include #include diff --git a/include/grpcpp/security/credentials.h b/include/grpcpp/security/credentials.h index 402dd9edb2..d1f8c22846 100644 --- a/include/grpcpp/security/credentials.h +++ b/include/grpcpp/security/credentials.h @@ -247,7 +247,7 @@ class MetadataCredentialsPlugin { /// Type of credentials this plugin is implementing. virtual const char* GetType() const { return ""; } - /// Gets the auth metatada produced by this plugin. + /// Gets the auth metadata produced by this plugin. /// The fully qualified method name is: /// service_url + "/" + method_name. /// The channel_auth_context contains (among other things), the identity of @@ -295,7 +295,7 @@ grpc::Status StsCredentialsOptionsFromJson(const std::string& json_string, /// Creates STS credentials options from the $STS_CREDENTIALS environment /// variable. This environment variable points to the path of a JSON file -/// comforming to the schema described above. +/// conforming to the schema described above. grpc::Status StsCredentialsOptionsFromEnv(StsCredentialsOptions* options); std::shared_ptr StsCredentials( diff --git a/include/grpcpp/security/tls_certificate_provider.h b/include/grpcpp/security/tls_certificate_provider.h index 3e7c952315..6b918fec0a 100644 --- a/include/grpcpp/security/tls_certificate_provider.h +++ b/include/grpcpp/security/tls_certificate_provider.h @@ -24,7 +24,6 @@ #include #include #include -#include #include namespace grpc { diff --git a/include/grpcpp/security/tls_certificate_verifier.h b/include/grpcpp/security/tls_certificate_verifier.h index 61c0acb0fb..5b87b1a42c 100644 --- a/include/grpcpp/security/tls_certificate_verifier.h +++ b/include/grpcpp/security/tls_certificate_verifier.h @@ -25,7 +25,6 @@ #include #include -#include #include #include #include diff --git a/include/grpcpp/security/tls_credentials_options.h b/include/grpcpp/security/tls_credentials_options.h index 11c40f0408..c47f348cca 100644 --- a/include/grpcpp/security/tls_credentials_options.h +++ b/include/grpcpp/security/tls_credentials_options.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/include/grpcpp/server_builder.h b/include/grpcpp/server_builder.h index e66ca4301c..787cb20af7 100644 --- a/include/grpcpp/server_builder.h +++ b/include/grpcpp/server_builder.h @@ -297,7 +297,7 @@ class ServerBuilder { // Creates a passive listener for Server Endpoint injection. /// - /// \a PasiveListener lets applications provide pre-established connections + /// \a PassiveListener 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. /// diff --git a/include/grpcpp/server_interface.h b/include/grpcpp/server_interface.h index 266b85313c..9791ee3589 100644 --- a/include/grpcpp/server_interface.h +++ b/include/grpcpp/server_interface.h @@ -23,7 +23,6 @@ #include #include -#include #include #include #include diff --git a/include/grpcpp/support/async_stream.h b/include/grpcpp/support/async_stream.h index ca849fd348..c4cbb9dbb4 100644 --- a/include/grpcpp/support/async_stream.h +++ b/include/grpcpp/support/async_stream.h @@ -22,7 +22,6 @@ #include "absl/log/absl_check.h" #include -#include #include #include #include diff --git a/include/grpcpp/support/async_unary_call.h b/include/grpcpp/support/async_unary_call.h index 715093fa77..a03a9b2838 100644 --- a/include/grpcpp/support/async_unary_call.h +++ b/include/grpcpp/support/async_unary_call.h @@ -22,7 +22,6 @@ #include "absl/log/absl_check.h" #include -#include #include #include #include diff --git a/include/grpcpp/support/byte_buffer.h b/include/grpcpp/support/byte_buffer.h index 5bbfb66496..676d3cfad7 100644 --- a/include/grpcpp/support/byte_buffer.h +++ b/include/grpcpp/support/byte_buffer.h @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -59,7 +58,7 @@ class GrpcByteBufferPeer; /// A sequence of bytes. class ByteBuffer final { public: - /// Constuct an empty buffer. + /// Construct an empty buffer. ByteBuffer() : buffer_(nullptr) {} /// Construct buffer from \a slices, of which there are \a nslices. diff --git a/include/grpcpp/support/callback_common.h b/include/grpcpp/support/callback_common.h index 0de9cbcf05..49eaa56172 100644 --- a/include/grpcpp/support/callback_common.h +++ b/include/grpcpp/support/callback_common.h @@ -25,11 +25,11 @@ #include #include -#include #include #include #include #include +#include #include namespace grpc { @@ -127,7 +127,18 @@ class CallbackWithStatusTag : public grpc_completion_queue_functor { auto status = std::move(status_); func_ = nullptr; // reset to clear this out for sure status_ = Status(); // reset to clear this out for sure - CatchingCallback(std::move(func), std::move(status)); + GetGlobalCallbackHook()->RunCallback( + call_, [func = std::move(func), status = std::move(status)]() { +#if GRPC_ALLOW_EXCEPTIONS + try { + func(status); + } catch (...) { + // nothing to return or change here, just don't crash the library + } +#else // GRPC_ALLOW_EXCEPTIONS + func(status); +#endif // GRPC_ALLOW_EXCEPTIONS + }); grpc_call_unref(call_); } }; @@ -214,7 +225,17 @@ class CallbackWithSuccessTag : public grpc_completion_queue_functor { #endif if (do_callback) { - CatchingCallback(func_, ok); + GetGlobalCallbackHook()->RunCallback(call_, [this, ok]() { +#if GRPC_ALLOW_EXCEPTIONS + try { + func_(ok); + } catch (...) { + // nothing to return or change here, just don't crash the library + } +#else // GRPC_ALLOW_EXCEPTIONS + func_(ok); +#endif // GRPC_ALLOW_EXCEPTIONS + }); } } }; diff --git a/include/grpcpp/support/client_callback.h b/include/grpcpp/support/client_callback.h index f306b26b96..692dff6b8d 100644 --- a/include/grpcpp/support/client_callback.h +++ b/include/grpcpp/support/client_callback.h @@ -26,7 +26,6 @@ #include #include -#include #include #include #include diff --git a/include/grpcpp/support/client_interceptor.h b/include/grpcpp/support/client_interceptor.h index 67aee26ec3..fbf554437b 100644 --- a/include/grpcpp/support/client_interceptor.h +++ b/include/grpcpp/support/client_interceptor.h @@ -24,7 +24,6 @@ #include "absl/log/absl_check.h" -#include #include #include #include diff --git a/include/grpcpp/support/config.h b/include/grpcpp/support/config.h index c846c43c6e..a491328785 100644 --- a/include/grpcpp/support/config.h +++ b/include/grpcpp/support/config.h @@ -35,7 +35,7 @@ namespace grpc { // Using grpc::string and grpc::to_string is discouraged in favor of // std::string and std::to_string. This is only for legacy code using -// them explictly. +// them explicitly. using std::string; // deprecated // NOLINT(misc-unused-using-decls) using std::to_string; // deprecated // NOLINT(misc-unused-using-decls) diff --git a/include/grpcpp/support/global_callback_hook.h b/include/grpcpp/support/global_callback_hook.h new file mode 100644 index 0000000000..c453bc807f --- /dev/null +++ b/include/grpcpp/support/global_callback_hook.h @@ -0,0 +1,58 @@ +// 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_SUPPORT_GLOBAL_CALLBACK_HOOK_H +#define GRPCPP_SUPPORT_GLOBAL_CALLBACK_HOOK_H + +#include "absl/functional/function_ref.h" + +struct grpc_call; + +namespace grpc { + +class GlobalCallbackHook { + public: + virtual ~GlobalCallbackHook() = default; + virtual void RunCallback(grpc_call* call, + absl::FunctionRef callback) = 0; + + protected: + // An exception-safe way of invoking a user-specified callback function. + template + void CatchingCallback(Func&& func, Args&&... args) { +#if GRPC_ALLOW_EXCEPTIONS + try { + func(std::forward(args)...); + } catch (...) { + // nothing to return or change here, just don't crash the library + } +#else // GRPC_ALLOW_EXCEPTIONS + func(std::forward(args)...); +#endif // GRPC_ALLOW_EXCEPTIONS + } +}; + +class DefaultGlobalCallbackHook final : public GlobalCallbackHook { + public: + void RunCallback(grpc_call* call, + absl::FunctionRef callback) override { + CatchingCallback(callback); + } +}; + +std::shared_ptr GetGlobalCallbackHook(); +void SetGlobalCallbackHook(GlobalCallbackHook* hook); +} // namespace grpc + +#endif // GRPCPP_SUPPORT_GLOBAL_CALLBACK_HOOK_H diff --git a/include/grpcpp/support/interceptor.h b/include/grpcpp/support/interceptor.h index 9248fbb28c..1e4d66610f 100644 --- a/include/grpcpp/support/interceptor.h +++ b/include/grpcpp/support/interceptor.h @@ -133,7 +133,7 @@ class InterceptorBatchMethods { /// means that the payload would be available in the serialized form only /// unless an interceptor replaces the payload with ModifySendMessage. - /// Returns a modifable ByteBuffer holding the serialized form of the message + /// Returns a modifiable ByteBuffer holding the serialized form of the message /// that is going to be sent. Valid for PRE_SEND_MESSAGE interceptions. /// A return value of nullptr indicates that this ByteBuffer is not valid. virtual ByteBuffer* GetSerializedSendMessage() = 0; diff --git a/include/grpcpp/support/method_handler.h b/include/grpcpp/support/method_handler.h index 6a2d2b22d2..081401b187 100644 --- a/include/grpcpp/support/method_handler.h +++ b/include/grpcpp/support/method_handler.h @@ -22,7 +22,6 @@ #include "absl/log/absl_check.h" #include -#include #include #include #include diff --git a/include/grpcpp/support/proto_buffer_reader.h b/include/grpcpp/support/proto_buffer_reader.h index e5ede7a09a..7bdf8d13d7 100644 --- a/include/grpcpp/support/proto_buffer_reader.h +++ b/include/grpcpp/support/proto_buffer_reader.h @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/include/grpcpp/support/proto_buffer_writer.h b/include/grpcpp/support/proto_buffer_writer.h index e695f14ae1..1417a61991 100644 --- a/include/grpcpp/support/proto_buffer_writer.h +++ b/include/grpcpp/support/proto_buffer_writer.h @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/include/grpcpp/support/server_interceptor.h b/include/grpcpp/support/server_interceptor.h index 1147235b6b..de875a347f 100644 --- a/include/grpcpp/support/server_interceptor.h +++ b/include/grpcpp/support/server_interceptor.h @@ -24,7 +24,6 @@ #include "absl/log/absl_check.h" -#include #include #include #include diff --git a/include/grpcpp/support/sync_stream.h b/include/grpcpp/support/sync_stream.h index 9b16b07013..7479adb25c 100644 --- a/include/grpcpp/support/sync_stream.h +++ b/include/grpcpp/support/sync_stream.h @@ -21,7 +21,6 @@ #include "absl/log/absl_check.h" -#include #include #include #include diff --git a/src/core/channelz/channelz.cc b/src/core/channelz/channelz.cc index 1baf851ed6..9487b9161e 100644 --- a/src/core/channelz/channelz.cc +++ b/src/core/channelz/channelz.cc @@ -29,7 +29,6 @@ #include "absl/strings/strip.h" #include -#include #include #include diff --git a/src/core/channelz/channelz_registry.cc b/src/core/channelz/channelz_registry.cc index 8089cc273b..63f6e557c7 100644 --- a/src/core/channelz/channelz_registry.cc +++ b/src/core/channelz/channelz_registry.cc @@ -29,7 +29,6 @@ #include #include -#include #include #include diff --git a/src/core/client_channel/client_channel_internal.h b/src/core/client_channel/client_channel_internal.h index f1982b6537..b9acdd883e 100644 --- a/src/core/client_channel/client_channel_internal.h +++ b/src/core/client_channel/client_channel_internal.h @@ -24,8 +24,6 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" -#include - #include "src/core/lib/gprpp/down_cast.h" #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/resource_quota/arena.h" diff --git a/src/core/client_channel/config_selector.h b/src/core/client_channel/config_selector.h index d049ae9583..1fb1ddab78 100644 --- a/src/core/client_channel/config_selector.h +++ b/src/core/client_channel/config_selector.h @@ -29,7 +29,6 @@ #include "absl/strings/string_view.h" #include -#include #include "src/core/client_channel/client_channel_internal.h" #include "src/core/lib/channel/channel_fwd.h" diff --git a/src/core/client_channel/dynamic_filters.cc b/src/core/client_channel/dynamic_filters.cc index 1e33da2105..f6658343e0 100644 --- a/src/core/client_channel/dynamic_filters.cc +++ b/src/core/client_channel/dynamic_filters.cc @@ -27,8 +27,6 @@ #include "absl/log/log.h" #include "absl/status/statusor.h" -#include - #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/channel_stack_builder_impl.h" diff --git a/src/core/client_channel/local_subchannel_pool.cc b/src/core/client_channel/local_subchannel_pool.cc index f3aa73d7bd..878d3547b9 100644 --- a/src/core/client_channel/local_subchannel_pool.cc +++ b/src/core/client_channel/local_subchannel_pool.cc @@ -24,8 +24,6 @@ #include "absl/log/check.h" -#include - #include "src/core/client_channel/subchannel.h" namespace grpc_core { diff --git a/src/core/client_channel/retry_filter.h b/src/core/client_channel/retry_filter.h index 153e2f1f00..8e30d1e7b6 100644 --- a/src/core/client_channel/retry_filter.h +++ b/src/core/client_channel/retry_filter.h @@ -30,7 +30,6 @@ #include #include #include -#include #include "src/core/client_channel/client_channel_filter.h" #include "src/core/client_channel/retry_service_config.h" 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 303b40a304..dd0267d7c5 100644 --- a/src/core/client_channel/retry_filter_legacy_call_data.cc +++ b/src/core/client_channel/retry_filter_legacy_call_data.cc @@ -139,21 +139,18 @@ RetryFilter::LegacyCallData::CallAttempt::CallAttempt( } }, is_transparent_retry); - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld->chand_ << " calld=" << calld - << " attempt=" << this - << ": created attempt, lb_call=" << lb_call_.get(); - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld->chand_ << " calld=" << calld << " attempt=" << this + << ": created attempt, lb_call=" << lb_call_.get(); // If per_attempt_recv_timeout is set, start a timer. if (calld->retry_policy_ != nullptr && calld->retry_policy_->per_attempt_recv_timeout().has_value()) { const Duration per_attempt_recv_timeout = *calld->retry_policy_->per_attempt_recv_timeout(); - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld->chand_ << " calld=" << calld - << " attempt=" << this << ": per-attempt timeout in " - << per_attempt_recv_timeout.millis() << " ms"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld->chand_ << " calld=" << calld + << " attempt=" << this << ": per-attempt timeout in " + << per_attempt_recv_timeout.millis() << " ms"; // Schedule retry after computed delay. GRPC_CALL_STACK_REF(calld->owning_call_, "OnPerAttemptRecvTimer"); Ref(DEBUG_LOCATION, "OnPerAttemptRecvTimer").release(); @@ -167,10 +164,9 @@ RetryFilter::LegacyCallData::CallAttempt::CallAttempt( } RetryFilter::LegacyCallData::CallAttempt::~CallAttempt() { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this << ": destroying call attempt"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld_->chand_ << " calld=" << calld_ + << " attempt=" << this << ": destroying call attempt"; } void RetryFilter::LegacyCallData::CallAttempt:: @@ -234,12 +230,11 @@ void RetryFilter::LegacyCallData::CallAttempt::MaybeSwitchToFastPath() { // yet seen that op from the surface, we can't switch yet. if (recv_trailing_metadata_internal_batch_ != nullptr) return; // Switch to fast path. - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this - << ": retry state no longer needed; " - "moving LB call to parent and unreffing the call attempt"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld_->chand_ << " calld=" << calld_ + << " attempt=" << this + << ": retry state no longer needed; " + "moving LB call to parent and unreffing the call attempt"; calld_->committed_call_ = std::move(lb_call_); calld_->call_attempt_.reset(DEBUG_LOCATION, "MaybeSwitchToFastPath"); } @@ -253,12 +248,10 @@ RetryFilter::LegacyCallData::CallAttempt::MaybeCreateBatchForReplay() { // send_initial_metadata. if (calld_->seen_send_initial_metadata_ && !started_send_initial_metadata_ && !calld_->pending_send_initial_metadata_) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this - << ": replaying previously completed " - "send_initial_metadata op"; - } + GRPC_TRACE_LOG(retry, INFO) << "chand=" << calld_->chand_ + << " calld=" << calld_ << " attempt=" << this + << ": replaying previously completed " + "send_initial_metadata op"; replay_batch_data = CreateBatch(1, true /* set_on_complete */); replay_batch_data->AddRetriableSendInitialMetadataOp(); } @@ -267,12 +260,10 @@ RetryFilter::LegacyCallData::CallAttempt::MaybeCreateBatchForReplay() { if (started_send_message_count_ < calld_->send_messages_.size() && started_send_message_count_ == completed_send_message_count_ && !calld_->pending_send_message_) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this - << ": replaying previously completed " - "send_message op"; - } + GRPC_TRACE_LOG(retry, INFO) << "chand=" << calld_->chand_ + << " calld=" << calld_ << " attempt=" << this + << ": replaying previously completed " + "send_message op"; if (replay_batch_data == nullptr) { replay_batch_data = CreateBatch(1, true /* set_on_complete */); } @@ -286,12 +277,10 @@ RetryFilter::LegacyCallData::CallAttempt::MaybeCreateBatchForReplay() { started_send_message_count_ == calld_->send_messages_.size() && !started_send_trailing_metadata_ && !calld_->pending_send_trailing_metadata_) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this - << ": replaying previously completed " - "send_trailing_metadata op"; - } + GRPC_TRACE_LOG(retry, INFO) << "chand=" << calld_->chand_ + << " calld=" << calld_ << " attempt=" << this + << ": replaying previously completed " + "send_trailing_metadata op"; if (replay_batch_data == nullptr) { replay_batch_data = CreateBatch(1, true /* set_on_complete */); } @@ -317,11 +306,10 @@ void StartBatchInCallCombiner(void* arg, grpc_error_handle /*ignored*/) { void RetryFilter::LegacyCallData::CallAttempt::AddClosureForBatch( grpc_transport_stream_op_batch* batch, const char* reason, CallCombinerClosureList* closures) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this << ": adding batch (" << reason - << "): " << grpc_transport_stream_op_batch_string(batch, false); - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld_->chand_ << " calld=" << calld_ + << " attempt=" << this << ": adding batch (" << reason + << "): " << grpc_transport_stream_op_batch_string(batch, false); batch->handler_private.extra_arg = lb_call_.get(); GRPC_CLOSURE_INIT(&batch->handler_private.closure, StartBatchInCallCombiner, batch, grpc_schedule_on_exec_ctx); @@ -330,12 +318,11 @@ void RetryFilter::LegacyCallData::CallAttempt::AddClosureForBatch( void RetryFilter::LegacyCallData::CallAttempt:: AddBatchForInternalRecvTrailingMetadata(CallCombinerClosureList* closures) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this - << ": call failed but recv_trailing_metadata not started; " - "starting it internally"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld_->chand_ << " calld=" << calld_ + << " attempt=" << this + << ": call failed but recv_trailing_metadata not started; " + "starting it internally"; // Create batch_data with 2 refs, since this batch will be unreffed twice: // once for the recv_trailing_metadata_ready callback when the batch // completes, and again when we actually get a recv_trailing_metadata @@ -520,20 +507,18 @@ void RetryFilter::LegacyCallData::CallAttempt::AddRetriableBatches( } void RetryFilter::LegacyCallData::CallAttempt::StartRetriableBatches() { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this << ": constructing retriable batches"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld_->chand_ << " calld=" << calld_ + << " attempt=" << this << ": constructing retriable batches"; // Construct list of closures to execute, one for each pending batch. CallCombinerClosureList closures; AddRetriableBatches(&closures); // Note: This will yield the call combiner. // Start batches on LB call. - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this << ": starting " << closures.size() - << " retriable batches on lb_call=" << lb_call_.get(); - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld_->chand_ << " calld=" << calld_ + << " attempt=" << this << ": starting " << closures.size() + << " retriable batches on lb_call=" << lb_call_.get(); closures.RunClosures(calld_->call_combiner_); } @@ -556,20 +541,18 @@ bool RetryFilter::LegacyCallData::CallAttempt::ShouldRetry( if (calld_->retry_throttle_data_ != nullptr) { calld_->retry_throttle_data_->RecordSuccess(); } - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this << ": call succeeded"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld_->chand_ << " calld=" << calld_ + << " attempt=" << this << ": call succeeded"; return false; } // Status is not OK. Check whether the status is retryable. if (!calld_->retry_policy_->retryable_status_codes().Contains(*status)) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this << ": status " - << grpc_status_code_to_string(*status) - << " not configured as retryable"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld_->chand_ << " calld=" << calld_ + << " attempt=" << this << ": status " + << grpc_status_code_to_string(*status) + << " not configured as retryable"; return false; } } @@ -582,46 +565,40 @@ bool RetryFilter::LegacyCallData::CallAttempt::ShouldRetry( // checks, so that we don't fail to record failures due to other factors. if (calld_->retry_throttle_data_ != nullptr && !calld_->retry_throttle_data_->RecordFailure()) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this << ": retries throttled"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld_->chand_ << " calld=" << calld_ + << " attempt=" << this << ": retries throttled"; return false; } // Check whether the call is committed. if (calld_->retry_committed_) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this << ": retries already committed"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld_->chand_ << " calld=" << calld_ + << " attempt=" << this << ": retries already committed"; return false; } // Check whether we have retries remaining. ++calld_->num_attempts_completed_; if (calld_->num_attempts_completed_ >= calld_->retry_policy_->max_attempts()) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this << ": exceeded " - << calld_->retry_policy_->max_attempts() << " retry attempts"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld_->chand_ << " calld=" << calld_ + << " attempt=" << this << ": exceeded " + << calld_->retry_policy_->max_attempts() << " retry attempts"; return false; } // Check server push-back. if (server_pushback.has_value()) { if (*server_pushback < Duration::Zero()) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this - << ": not retrying due to server push-back"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld_->chand_ << " calld=" << calld_ + << " attempt=" << this << ": not retrying due to server push-back"; return false; } else { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this << ": server push-back: retry in " - << server_pushback->millis() << " ms"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld_->chand_ << " calld=" << calld_ + << " attempt=" << this << ": server push-back: retry in " + << server_pushback->millis() << " ms"; } } // We should retry. @@ -665,14 +642,12 @@ void RetryFilter::LegacyCallData::CallAttempt::OnPerAttemptRecvTimerLocked( void* arg, grpc_error_handle error) { auto* call_attempt = static_cast(arg); auto* calld = call_attempt->calld_; - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld->chand_ << " calld=" << calld - << " attempt=" << call_attempt - << ": perAttemptRecvTimeout timer fired: error=" - << StatusToString(error) - << ", per_attempt_recv_timer_handle_.has_value()=" - << call_attempt->per_attempt_recv_timer_handle_.has_value(); - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld->chand_ << " calld=" << calld + << " attempt=" << call_attempt + << ": perAttemptRecvTimeout timer fired: error=" << StatusToString(error) + << ", per_attempt_recv_timer_handle_.has_value()=" + << call_attempt->per_attempt_recv_timer_handle_.has_value(); CallCombinerClosureList closures; call_attempt->per_attempt_recv_timer_handle_.reset(); // Cancel this attempt. @@ -705,11 +680,9 @@ void RetryFilter::LegacyCallData::CallAttempt::OnPerAttemptRecvTimerLocked( void RetryFilter::LegacyCallData::CallAttempt:: MaybeCancelPerAttemptRecvTimer() { if (per_attempt_recv_timer_handle_.has_value()) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld_->chand_ << " calld=" << calld_ - << " attempt=" << this - << ": cancelling perAttemptRecvTimeout timer"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld_->chand_ << " calld=" << calld_ + << " attempt=" << this << ": cancelling perAttemptRecvTimeout timer"; if (calld_->chand_->event_engine()->Cancel( *per_attempt_recv_timer_handle_)) { Unref(DEBUG_LOCATION, "OnPerAttemptRecvTimer"); @@ -728,11 +701,10 @@ RetryFilter::LegacyCallData::CallAttempt::BatchData::BatchData( : RefCounted(GRPC_TRACE_FLAG_ENABLED(retry) ? "BatchData" : nullptr, refcount), call_attempt_(attempt.release()) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << call_attempt_->calld_->chand_ - << " calld=" << call_attempt_->calld_ - << " attempt=" << call_attempt_ << ": creating batch " << this; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << call_attempt_->calld_->chand_ + << " calld=" << call_attempt_->calld_ << " attempt=" << call_attempt_ + << ": creating batch " << this; // We hold a ref to the call stack for every batch sent on a call attempt. // This is because some batches on the call attempt may not complete // until after all of the batches are completed at the surface (because @@ -749,11 +721,10 @@ RetryFilter::LegacyCallData::CallAttempt::BatchData::BatchData( } RetryFilter::LegacyCallData::CallAttempt::BatchData::~BatchData() { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << call_attempt_->calld_->chand_ - << " calld=" << call_attempt_->calld_ - << " attempt=" << call_attempt_ << ": destroying batch " << this; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << call_attempt_->calld_->chand_ + << " calld=" << call_attempt_->calld_ << " attempt=" << call_attempt_ + << ": destroying batch " << this; CallAttempt* call_attempt = std::exchange(call_attempt_, nullptr); grpc_call_stack* owning_call = call_attempt->calld_->owning_call_; call_attempt->Unref(DEBUG_LOCATION, "~BatchData"); @@ -822,13 +793,10 @@ void RetryFilter::LegacyCallData::CallAttempt::BatchData:: RefCountedPtr batch_data(static_cast(arg)); CallAttempt* call_attempt = batch_data->call_attempt_; RetryFilter::LegacyCallData* calld = call_attempt->calld_; - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld->chand_ << " calld=" << calld - << " attempt=" << call_attempt - << " batch_data=" << batch_data.get() - << ": got recv_initial_metadata_ready, error=" - << StatusToString(error); - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld->chand_ << " calld=" << calld + << " attempt=" << call_attempt << " batch_data=" << batch_data.get() + << ": got recv_initial_metadata_ready, error=" << StatusToString(error); call_attempt->completed_recv_initial_metadata_ = true; // If this attempt has been abandoned, then we're not going to use the // result of this recv_initial_metadata op, so do nothing. @@ -849,11 +817,10 @@ void RetryFilter::LegacyCallData::CallAttempt::BatchData:: if (GPR_UNLIKELY( (call_attempt->trailing_metadata_available_ || !error.ok()) && !call_attempt->completed_recv_trailing_metadata_)) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld->chand_ << " calld=" << calld - << " attempt=" << call_attempt - << ": deferring recv_initial_metadata_ready (Trailers-Only)"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld->chand_ << " calld=" << calld + << " attempt=" << call_attempt + << ": deferring recv_initial_metadata_ready (Trailers-Only)"; call_attempt->recv_initial_metadata_ready_deferred_batch_ = std::move(batch_data); call_attempt->recv_initial_metadata_error_ = error; @@ -920,12 +887,10 @@ void RetryFilter::LegacyCallData::CallAttempt::BatchData::RecvMessageReady( RefCountedPtr batch_data(static_cast(arg)); CallAttempt* call_attempt = batch_data->call_attempt_; RetryFilter::LegacyCallData* calld = call_attempt->calld_; - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld->chand_ << " calld=" << calld - << " attempt=" << call_attempt - << " batch_data=" << batch_data.get() - << ": got recv_message_ready, error=" << StatusToString(error); - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld->chand_ << " calld=" << calld + << " attempt=" << call_attempt << " batch_data=" << batch_data.get() + << ": got recv_message_ready, error=" << StatusToString(error); ++call_attempt->completed_recv_message_count_; // If this attempt has been abandoned, then we're not going to use the // result of this recv_message op, so do nothing. @@ -949,12 +914,11 @@ void RetryFilter::LegacyCallData::CallAttempt::BatchData::RecvMessageReady( if (GPR_UNLIKELY( (!call_attempt->recv_message_.has_value() || !error.ok()) && !call_attempt->completed_recv_trailing_metadata_)) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld->chand_ << " calld=" << calld - << " attempt=" << call_attempt - << ": deferring recv_message_ready (nullptr message and " - "recv_trailing_metadata pending)"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld->chand_ << " calld=" << calld + << " attempt=" << call_attempt + << ": deferring recv_message_ready (nullptr message and " + "recv_trailing_metadata pending)"; call_attempt->recv_message_ready_deferred_batch_ = std::move(batch_data); call_attempt->recv_message_error_ = error; CallCombinerClosureList closures; @@ -1113,13 +1077,10 @@ void RetryFilter::LegacyCallData::CallAttempt::BatchData:: RefCountedPtr batch_data(static_cast(arg)); CallAttempt* call_attempt = batch_data->call_attempt_; RetryFilter::LegacyCallData* calld = call_attempt->calld_; - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld->chand_ << " calld=" << calld - << " attempt=" << call_attempt - << " batch_data=" << batch_data.get() - << ": got recv_trailing_metadata_ready, error=" - << StatusToString(error); - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld->chand_ << " calld=" << calld + << " attempt=" << call_attempt << " batch_data=" << batch_data.get() + << ": got recv_trailing_metadata_ready, error=" << StatusToString(error); call_attempt->completed_recv_trailing_metadata_ = true; // If this attempt has been abandoned, then we're not going to use the // result of this recv_trailing_metadata op, so do nothing. @@ -1140,17 +1101,15 @@ void RetryFilter::LegacyCallData::CallAttempt::BatchData:: batch_data->batch_.payload->recv_trailing_metadata.recv_trailing_metadata; GetCallStatus(calld->deadline_, md_batch, error, &status, &server_pushback, &is_lb_drop, &stream_network_state); - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld->chand_ << " calld=" << calld - << " attempt=" << call_attempt << ": call finished, status=" - << grpc_status_code_to_string(status) << " server_pushback=" - << (server_pushback.has_value() ? server_pushback->ToString() - : "N/A") - << " is_lb_drop=" << is_lb_drop << " stream_network_state=" - << (stream_network_state.has_value() - ? absl::StrCat(*stream_network_state) - : "N/A"); - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld->chand_ << " calld=" << calld + << " attempt=" << call_attempt + << ": call finished, status=" << grpc_status_code_to_string(status) + << " server_pushback=" + << (server_pushback.has_value() ? server_pushback->ToString() : "N/A") + << " is_lb_drop=" << is_lb_drop << " stream_network_state=" + << (stream_network_state.has_value() ? absl::StrCat(*stream_network_state) + : "N/A"); // Check if we should retry. if (!is_lb_drop) { // Never retry on LB drops. enum { kNoRetry, kTransparentRetry, kConfigurableRetry } retry = kNoRetry; @@ -1259,11 +1218,10 @@ void RetryFilter::LegacyCallData::CallAttempt::BatchData:: } } if (have_pending_send_ops) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld->chand_ << " calld=" << calld - << " attempt=" << call_attempt_ - << ": starting next batch for pending send op(s)"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld->chand_ << " calld=" << calld + << " attempt=" << call_attempt_ + << ": starting next batch for pending send op(s)"; call_attempt_->AddRetriableBatches(closures); } } @@ -1273,15 +1231,11 @@ void RetryFilter::LegacyCallData::CallAttempt::BatchData::OnComplete( RefCountedPtr batch_data(static_cast(arg)); CallAttempt* call_attempt = batch_data->call_attempt_; RetryFilter::LegacyCallData* calld = call_attempt->calld_; - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld->chand_ << " calld=" << calld - << " attempt=" << call_attempt - << " batch_data=" << batch_data.get() - << ": got on_complete, error=" << StatusToString(error) - << ", batch=" - << grpc_transport_stream_op_batch_string(&batch_data->batch_, - false); - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld->chand_ << " calld=" << calld + << " attempt=" << call_attempt << " batch_data=" << batch_data.get() + << ": got on_complete, error=" << StatusToString(error) << ", batch=" + << grpc_transport_stream_op_batch_string(&batch_data->batch_, false); // If this attempt has been abandoned, then we're not going to propagate // the completion of this batch, so do nothing. if (call_attempt->abandoned_) { @@ -1295,10 +1249,9 @@ void RetryFilter::LegacyCallData::CallAttempt::BatchData::OnComplete( // recv_trailing_metadata comes back. if (GPR_UNLIKELY(!calld->retry_committed_ && !error.ok() && !call_attempt->completed_recv_trailing_metadata_)) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld->chand_ << " calld=" << calld - << " attempt=" << call_attempt << ": deferring on_complete"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld->chand_ << " calld=" << calld + << " attempt=" << call_attempt << ": deferring on_complete"; call_attempt->on_complete_deferred_batches_.emplace_back( std::move(batch_data), error); CallCombinerClosureList closures; @@ -1349,15 +1302,12 @@ void RetryFilter::LegacyCallData::CallAttempt::BatchData::OnCompleteForCancelOp( RefCountedPtr batch_data(static_cast(arg)); CallAttempt* call_attempt = batch_data->call_attempt_; RetryFilter::LegacyCallData* calld = call_attempt->calld_; - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld->chand_ << " calld=" << calld - << " attempt=" << call_attempt - << " batch_data=" << batch_data.get() - << ": got on_complete for cancel_stream batch, error=" - << StatusToString(error) << ", batch=" - << grpc_transport_stream_op_batch_string(&batch_data->batch_, - false); - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld->chand_ << " calld=" << calld + << " attempt=" << call_attempt << " batch_data=" << batch_data.get() + << ": got on_complete for cancel_stream batch, error=" + << StatusToString(error) << ", batch=" + << grpc_transport_stream_op_batch_string(&batch_data->batch_, false); GRPC_CALL_COMBINER_STOP( calld->call_combiner_, "on_complete for internally generated cancel_stream op"); @@ -1392,12 +1342,10 @@ void RetryFilter::LegacyCallData::CallAttempt::BatchData:: void RetryFilter::LegacyCallData::CallAttempt::BatchData:: AddRetriableSendMessageOp() { auto* calld = call_attempt_->calld_; - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << calld->chand_ << " calld=" << calld - << " attempt=" << call_attempt_ - << ": starting calld->send_messages[" - << call_attempt_->started_send_message_count_ << "]"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << calld->chand_ << " calld=" << calld + << " attempt=" << call_attempt_ << ": starting calld->send_messages[" + << call_attempt_->started_send_message_count_ << "]"; CachedSendMessage cache = calld->send_messages_[call_attempt_->started_send_message_count_]; ++call_attempt_->started_send_message_count_; @@ -1479,10 +1427,8 @@ grpc_error_handle RetryFilter::LegacyCallData::Init( grpc_call_element* elem, const grpc_call_element_args* args) { auto* chand = static_cast(elem->channel_data); new (elem->call_data) RetryFilter::LegacyCallData(chand, *args); - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand << " calld=" << elem->call_data - << ": created call"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << chand << " calld=" << elem->call_data << ": created call"; return absl::OkStatus(); } @@ -1584,11 +1530,9 @@ void RetryFilter::LegacyCallData::StartTransportStreamOpBatch( if (GPR_UNLIKELY(batch->cancel_stream)) { // Save cancel_error in case subsequent batches are started. cancelled_from_surface_ = batch->payload->cancel_stream.cancel_error; - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this - << ": cancelled from surface: " - << StatusToString(cancelled_from_surface_); - } + GRPC_TRACE_LOG(retry, INFO) << "chand=" << chand_ << " calld=" << this + << ": cancelled from surface: " + << StatusToString(cancelled_from_surface_); // Fail any pending batches. PendingBatchesFail(cancelled_from_surface_); // If we have a current call attempt, commit the call, then send @@ -1608,10 +1552,8 @@ void RetryFilter::LegacyCallData::StartTransportStreamOpBatch( } // Cancel retry timer if needed. if (retry_timer_handle_.has_value()) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this - << ": cancelling retry timer"; - } + GRPC_TRACE_LOG(retry, INFO) << "chand=" << chand_ << " calld=" << this + << ": cancelling retry timer"; if (chand_->event_engine()->Cancel(*retry_timer_handle_)) { GRPC_CALL_STACK_UNREF(owning_call_, "OnRetryTimer"); } @@ -1654,11 +1596,9 @@ void RetryFilter::LegacyCallData::StartTransportStreamOpBatch( if (!retry_codepath_started_ && retry_committed_ && (retry_policy_ == nullptr || !retry_policy_->per_attempt_recv_timeout().has_value())) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this - << ": retry committed before first attempt; " - << "creating LB call"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << chand_ << " calld=" << this + << ": retry committed before first attempt; creating LB call"; PendingBatchClear(pending); auto* service_config_call_data = DownCast( @@ -1672,19 +1612,16 @@ void RetryFilter::LegacyCallData::StartTransportStreamOpBatch( // Otherwise, create a call attempt. // The attempt will automatically start any necessary replays or // pending batches. - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this - << ": creating call attempt"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << chand_ << " calld=" << this << ": creating call attempt"; retry_codepath_started_ = true; CreateCallAttempt(/*is_transparent_retry=*/false); return; } // Send batches to call attempt. - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this - << ": starting batch on attempt=" << call_attempt_.get(); - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << chand_ << " calld=" << this + << ": starting batch on attempt=" << call_attempt_.get(); call_attempt_->StartRetriableBatches(); } @@ -1739,28 +1676,22 @@ void RetryFilter::LegacyCallData::MaybeCacheSendOpsForBatch( } void RetryFilter::LegacyCallData::FreeCachedSendInitialMetadata() { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this - << ": destroying send_initial_metadata"; - } + GRPC_TRACE_LOG(retry, INFO) << "chand=" << chand_ << " calld=" << this + << ": destroying send_initial_metadata"; send_initial_metadata_.Clear(); } void RetryFilter::LegacyCallData::FreeCachedSendMessage(size_t idx) { if (send_messages_[idx].slices != nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this - << ": destroying send_messages[" << idx << "]"; - } + GRPC_TRACE_LOG(retry, INFO) << "chand=" << chand_ << " calld=" << this + << ": destroying send_messages[" << idx << "]"; Destruct(std::exchange(send_messages_[idx].slices, nullptr)); } } void RetryFilter::LegacyCallData::FreeCachedSendTrailingMetadata() { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this - << ": destroying send_trailing_metadata"; - } + GRPC_TRACE_LOG(retry, INFO) << "chand=" << chand_ << " calld=" << this + << ": destroying send_trailing_metadata"; send_trailing_metadata_.Clear(); } @@ -1796,10 +1727,8 @@ RetryFilter::LegacyCallData::PendingBatch* RetryFilter::LegacyCallData::PendingBatchesAdd( grpc_transport_stream_op_batch* batch) { const size_t idx = GetBatchIndex(batch); - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this - << ": adding pending batch at index " << idx; - } + GRPC_TRACE_LOG(retry, INFO) << "chand=" << chand_ << " calld=" << this + << ": adding pending batch at index " << idx; PendingBatch* pending = &pending_batches_[idx]; CHECK_EQ(pending->batch, nullptr); pending->batch = batch; @@ -1826,10 +1755,8 @@ RetryFilter::LegacyCallData::PendingBatchesAdd( // ops have already been sent, and we commit to that attempt. if (GPR_UNLIKELY(bytes_buffered_for_retry_ > chand_->per_rpc_retry_buffer_size())) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this - << ": exceeded retry buffer size, committing"; - } + GRPC_TRACE_LOG(retry, INFO) << "chand=" << chand_ << " calld=" << this + << ": exceeded retry buffer size, committing"; RetryCommit(call_attempt_.get()); } return pending; @@ -1862,10 +1789,8 @@ void RetryFilter::LegacyCallData::MaybeClearPendingBatch( (!batch->recv_trailing_metadata || batch->payload->recv_trailing_metadata.recv_trailing_metadata_ready == nullptr)) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this - << ": clearing pending batch"; - } + GRPC_TRACE_LOG(retry, INFO) << "chand=" << chand_ << " calld=" << this + << ": clearing pending batch"; PendingBatchClear(pending); } } @@ -1918,10 +1843,9 @@ RetryFilter::LegacyCallData::PendingBatchFind(const char* log_message, PendingBatch* pending = &pending_batches_[i]; grpc_transport_stream_op_batch* batch = pending->batch; if (batch != nullptr && predicate(batch)) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this << ": " - << log_message << " pending batch at index " << i; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << chand_ << " calld=" << this << ": " << log_message + << " pending batch at index " << i; return pending; } } @@ -1935,10 +1859,8 @@ RetryFilter::LegacyCallData::PendingBatchFind(const char* log_message, void RetryFilter::LegacyCallData::RetryCommit(CallAttempt* call_attempt) { if (retry_committed_) return; retry_committed_ = true; - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this - << ": committing retries"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << chand_ << " calld=" << this << ": committing retries"; if (call_attempt != nullptr) { // If the call attempt's LB call has been committed, invoke the // call's on_commit callback. @@ -1970,11 +1892,9 @@ void RetryFilter::LegacyCallData::StartRetryTimer( } else { next_attempt_timeout = retry_backoff_.NextAttemptTime() - Timestamp::Now(); } - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this - << ": retrying failed call in " << next_attempt_timeout.millis() - << " ms"; - } + GRPC_TRACE_LOG(retry, INFO) + << "chand=" << chand_ << " calld=" << this << ": retrying failed call in " + << next_attempt_timeout.millis() << " ms"; // Schedule retry after computed delay. GRPC_CALL_STACK_REF(owning_call_, "OnRetryTimer"); retry_timer_handle_ = @@ -2003,10 +1923,8 @@ void RetryFilter::LegacyCallData::OnRetryTimerLocked( void RetryFilter::LegacyCallData::AddClosureToStartTransparentRetry( CallCombinerClosureList* closures) { - if (GRPC_TRACE_FLAG_ENABLED(retry)) { - LOG(INFO) << "chand=" << chand_ << " calld=" << this - << ": scheduling transparent retry"; - } + GRPC_TRACE_LOG(retry, INFO) << "chand=" << chand_ << " calld=" << this + << ": scheduling transparent retry"; GRPC_CALL_STACK_REF(owning_call_, "OnRetryTimer"); GRPC_CLOSURE_INIT(&retry_closure_, StartTransparentRetry, this, nullptr); closures->Add(&retry_closure_, absl::OkStatus(), "start transparent retry"); diff --git a/src/core/client_channel/subchannel.cc b/src/core/client_channel/subchannel.cc index cee164a64a..35ec507c4d 100644 --- a/src/core/client_channel/subchannel.cc +++ b/src/core/client_channel/subchannel.cc @@ -417,12 +417,11 @@ class Subchannel::ConnectedSubchannelStateWatcher final if (c->connected_subchannel_ == nullptr) return; if (new_state == GRPC_CHANNEL_TRANSIENT_FAILURE || new_state == GRPC_CHANNEL_SHUTDOWN) { - if (GRPC_TRACE_FLAG_ENABLED(subchannel)) { - LOG(INFO) << "subchannel " << c << " " << c->key_.ToString() - << ": Connected subchannel " - << c->connected_subchannel_.get() << " reports " - << ConnectivityStateName(new_state) << ": " << status; - } + GRPC_TRACE_LOG(subchannel, INFO) + << "subchannel " << c << " " << c->key_.ToString() + << ": Connected subchannel " << c->connected_subchannel_.get() + << " reports " << ConnectivityStateName(new_state) << ": " + << status; c->connected_subchannel_.reset(); if (c->channelz_node() != nullptr) { c->channelz_node()->SetChildSocket(nullptr); @@ -602,10 +601,9 @@ void Subchannel::ThrottleKeepaliveTime(int new_keepalive_time) { // Only update the value if the new keepalive time is larger. if (new_keepalive_time > keepalive_time_) { keepalive_time_ = new_keepalive_time; - if (GRPC_TRACE_FLAG_ENABLED(subchannel)) { - LOG(INFO) << "subchannel " << this << " " << key_.ToString() - << ": throttling keepalive time to " << new_keepalive_time; - } + GRPC_TRACE_LOG(subchannel, INFO) + << "subchannel " << this << " " << key_.ToString() + << ": throttling keepalive time to " << new_keepalive_time; args_ = args_.Set(GRPC_ARG_KEEPALIVE_TIME_MS, new_keepalive_time); } } @@ -758,10 +756,9 @@ void Subchannel::OnRetryTimer() { void Subchannel::OnRetryTimerLocked() { if (shutdown_) return; - if (GRPC_TRACE_FLAG_ENABLED(subchannel)) { - LOG(INFO) << "subchannel " << this << " " << key_.ToString() - << ": backoff delay elapsed, reporting IDLE"; - } + GRPC_TRACE_LOG(subchannel, INFO) + << "subchannel " << this << " " << key_.ToString() + << ": backoff delay elapsed, reporting IDLE"; SetConnectivityStateLocked(GRPC_CHANNEL_IDLE, absl::OkStatus()); } @@ -805,12 +802,10 @@ void Subchannel::OnConnectingFinishedLocked(grpc_error_handle error) { if (connecting_result_.transport == nullptr || !PublishTransportLocked()) { const Duration time_until_next_attempt = next_attempt_time_ - Timestamp::Now(); - if (GRPC_TRACE_FLAG_ENABLED(subchannel)) { - LOG(INFO) << "subchannel " << this << " " << key_.ToString() - << ": connect failed (" << StatusToString(error) - << "), backing off for " << time_until_next_attempt.millis() - << " ms"; - } + GRPC_TRACE_LOG(subchannel, INFO) + << "subchannel " << this << " " << key_.ToString() + << ": connect failed (" << StatusToString(error) + << "), backing off for " << time_until_next_attempt.millis() << " ms"; SetConnectivityStateLocked(GRPC_CHANNEL_TRANSIENT_FAILURE, grpc_error_to_absl_status(error)); retry_timer_handle_ = event_engine_->RunAfter( @@ -895,11 +890,9 @@ bool Subchannel::PublishTransportLocked() { } connecting_result_.Reset(); // Publish. - if (GRPC_TRACE_FLAG_ENABLED(subchannel)) { - LOG(INFO) << "subchannel " << this << " " << key_.ToString() - << ": new connected subchannel at " - << connected_subchannel_.get(); - } + GRPC_TRACE_LOG(subchannel, INFO) + << "subchannel " << this << " " << key_.ToString() + << ": new connected subchannel at " << connected_subchannel_.get(); if (channelz_node_ != nullptr) { channelz_node_->SetChildSocket(std::move(socket_node)); } 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 24ac03bc38..647ff45c30 100644 --- a/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +++ b/src/core/ext/filters/backend_metrics/backend_metric_filter.cc @@ -128,21 +128,20 @@ void BackendMetricFilter::Call::OnServerTrailingMetadata(ServerMetadata& md) { if (md.get(GrpcCallWasCancelled()).value_or(false)) return; auto* ctx = MaybeGetContext(); if (ctx == nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric_filter)) { - LOG(INFO) << "[" << this << "] No BackendMetricProvider."; - } + GRPC_TRACE_LOG(backend_metric_filter, INFO) + << "[" << this << "] No BackendMetricProvider."; return; } absl::optional serialized = MaybeSerializeBackendMetrics(ctx); if (serialized.has_value() && !serialized->empty()) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric_filter)) { - LOG(INFO) << "[" << this - << "] Backend metrics serialized. size: " << serialized->size(); - } + GRPC_TRACE_LOG(backend_metric_filter, INFO) + << "[" << this + << "] Backend metrics serialized. size: " << serialized->size(); md.Set(EndpointLoadMetricsBinMetadata(), Slice::FromCopiedString(std::move(*serialized))); - } else if (GRPC_TRACE_FLAG_ENABLED(backend_metric_filter)) { - LOG(INFO) << "[" << this << "] No backend metrics."; + } else { + GRPC_TRACE_LOG(backend_metric_filter, INFO) + << "[" << this << "] No backend metrics."; } } diff --git a/src/core/ext/filters/channel_idle/legacy_channel_idle_filter.cc b/src/core/ext/filters/channel_idle/legacy_channel_idle_filter.cc index 6d16ac68b7..b560b92f59 100644 --- a/src/core/ext/filters/channel_idle/legacy_channel_idle_filter.cc +++ b/src/core/ext/filters/channel_idle/legacy_channel_idle_filter.cc @@ -29,7 +29,6 @@ #include "absl/types/optional.h" #include -#include #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/promise_based_filter.h" 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 b4bf623bbb..6576c6df96 100644 --- a/src/core/ext/filters/fault_injection/fault_injection_filter.cc +++ b/src/core/ext/filters/fault_injection/fault_injection_filter.cc @@ -150,10 +150,9 @@ FaultInjectionFilter::FaultInjectionFilter(ChannelFilter::Args filter_args) ArenaPromise FaultInjectionFilter::Call::OnClientInitialMetadata( ClientMetadata& md, FaultInjectionFilter* filter) { auto decision = filter->MakeInjectionDecision(md); - if (GRPC_TRACE_FLAG_ENABLED(fault_injection_filter)) { - LOG(INFO) << "chand=" << this << ": Fault injection triggered " - << decision.ToString(); - } + GRPC_TRACE_LOG(fault_injection_filter, INFO) + << "chand=" << this << ": Fault injection triggered " + << decision.ToString(); auto delay = decision.DelayUntil(); return TrySeq(Sleep(delay), [decision = std::move(decision)]() { return decision.MaybeAbort(); 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 33491f1e6c..dead10bbe1 100644 --- a/src/core/ext/filters/http/message_compress/compression_filter.cc +++ b/src/core/ext/filters/http/message_compress/compression_filter.cc @@ -111,10 +111,9 @@ ChannelCompression::ChannelCompression(const ChannelArgs& args) MessageHandle ChannelCompression::CompressMessage( MessageHandle message, grpc_compression_algorithm algorithm) const { - if (GRPC_TRACE_FLAG_ENABLED(compression)) { - LOG(INFO) << "CompressMessage: len=" << message->payload()->Length() - << " alg=" << algorithm << " flags=" << message->flags(); - } + GRPC_TRACE_LOG(compression, INFO) + << "CompressMessage: len=" << message->payload()->Length() + << " alg=" << algorithm << " flags=" << message->flags(); auto* call_tracer = MaybeGetContext(); if (call_tracer != nullptr) { call_tracer->RecordSendMessage(*message->payload()); @@ -166,11 +165,10 @@ MessageHandle ChannelCompression::CompressMessage( absl::StatusOr ChannelCompression::DecompressMessage( bool is_client, MessageHandle message, DecompressArgs args) const { - if (GRPC_TRACE_FLAG_ENABLED(compression)) { - LOG(INFO) << "DecompressMessage: len=" << message->payload()->Length() - << " max=" << args.max_recv_message_length.value_or(-1) - << " alg=" << args.algorithm; - } + GRPC_TRACE_LOG(compression, INFO) + << "DecompressMessage: len=" << message->payload()->Length() + << " max=" << args.max_recv_message_length.value_or(-1) + << " alg=" << args.algorithm; auto* call_tracer = MaybeGetContext(); if (call_tracer != nullptr) { call_tracer->RecordReceivedMessage(*message->payload()); 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 5cfe96f717..fa6a38ddcc 100644 --- a/src/core/ext/filters/http/server/http_server_filter.cc +++ b/src/core/ext/filters/http/server/http_server_filter.cc @@ -139,10 +139,8 @@ ServerMetadataHandle HttpServerFilter::Call::OnClientInitialMetadata( } void HttpServerFilter::Call::OnServerInitialMetadata(ServerMetadata& md) { - if (GRPC_TRACE_FLAG_ENABLED(call)) { - LOG(INFO) << GetContext()->DebugTag() - << "[http-server] Write metadata"; - } + GRPC_TRACE_LOG(call, INFO) + << GetContext()->DebugTag() << "[http-server] Write metadata"; FilterOutgoingMetadata(&md); md.Set(HttpStatusMetadata(), 200); md.Set(ContentTypeMetadata(), ContentTypeMetadata::kApplicationGrpc); 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 c00d7d8fed..e45a90de09 100644 --- a/src/core/ext/filters/message_size/message_size_filter.cc +++ b/src/core/ext/filters/message_size/message_size_filter.cc @@ -159,11 +159,10 @@ ServerMetadataHandle CheckPayload(const Message& msg, absl::optional max_length, bool is_client, bool is_send) { if (!max_length.has_value()) return nullptr; - if (GRPC_TRACE_FLAG_ENABLED(call)) { - LOG(INFO) << GetContext()->DebugTag() << "[message_size] " - << (is_send ? "send" : "recv") - << " len:" << msg.payload()->Length() << " max:" << *max_length; - } + GRPC_TRACE_LOG(call, INFO) + << GetContext()->DebugTag() << "[message_size] " + << (is_send ? "send" : "recv") << " len:" << msg.payload()->Length() + << " max:" << *max_length; if (msg.payload()->Length() <= *max_length) return nullptr; return ServerMetadataFromStatus( GRPC_STATUS_RESOURCE_EXHAUSTED, 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 c677bd2cc1..cf83e5db1f 100644 --- a/src/core/ext/filters/stateful_session/stateful_session_filter.cc +++ b/src/core/ext/filters/stateful_session/stateful_session_filter.cc @@ -37,8 +37,6 @@ #include "absl/strings/strip.h" #include "absl/types/optional.h" -#include - #include "src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h" #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/config/core_configuration.h" diff --git a/src/core/ext/transport/chttp2/alpn/alpn.cc b/src/core/ext/transport/chttp2/alpn/alpn.cc index cb9c2d6e34..75f1740233 100644 --- a/src/core/ext/transport/chttp2/alpn/alpn.cc +++ b/src/core/ext/transport/chttp2/alpn/alpn.cc @@ -20,7 +20,6 @@ #include "absl/log/check.h" -#include #include #include "src/core/util/useful.h" diff --git a/src/core/ext/transport/chttp2/transport/bin_encoder.cc b/src/core/ext/transport/chttp2/transport/bin_encoder.cc index cf024f03d4..4063d1d549 100644 --- a/src/core/ext/transport/chttp2/transport/bin_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/bin_encoder.cc @@ -23,7 +23,6 @@ #include "absl/log/check.h" -#include #include #include "src/core/ext/transport/chttp2/transport/huffsyms.h" diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index cddcecf1b5..d3c5d994c1 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -65,7 +65,6 @@ #include "src/core/ext/transport/chttp2/transport/http2_settings.h" #include "src/core/ext/transport/chttp2/transport/internal.h" #include "src/core/ext/transport/chttp2/transport/legacy_frame.h" -#include "src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.h" #include "src/core/ext/transport/chttp2/transport/ping_abuse_policy.h" #include "src/core/ext/transport/chttp2/transport/ping_callbacks.h" #include "src/core/ext/transport/chttp2/transport/ping_rate_policy.h" @@ -547,7 +546,6 @@ static void read_channel_args(grpc_chttp2_transport* t, value = channel_args.GetInt(GRPC_ARG_MAX_CONCURRENT_STREAMS).value_or(-1); if (value >= 0) { t->settings.mutable_local().SetMaxConcurrentStreams(value); - t->max_concurrent_streams_policy.SetTarget(value); } } else if (channel_args.Contains(GRPC_ARG_MAX_CONCURRENT_STREAMS)) { VLOG(2) << GRPC_ARG_MAX_CONCURRENT_STREAMS @@ -1310,15 +1308,14 @@ void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t, return; } closure->next_data.scratch -= CLOSURE_BARRIER_FIRST_REF_BIT; - if (GRPC_TRACE_FLAG_ENABLED(http)) { - LOG(INFO) << "complete_closure_step: t=" << t << " " << closure << " refs=" - << (closure->next_data.scratch / CLOSURE_BARRIER_FIRST_REF_BIT) - << " flags=" - << (closure->next_data.scratch % CLOSURE_BARRIER_FIRST_REF_BIT) - << " desc=" << desc << " err=" << grpc_core::StatusToString(error) - << " write_state=" << write_state_name(t->write_state) - << " whence=" << whence.file() << ":" << whence.line(); - } + GRPC_TRACE_LOG(http, INFO) + << "complete_closure_step: t=" << t << " " << closure << " refs=" + << (closure->next_data.scratch / CLOSURE_BARRIER_FIRST_REF_BIT) + << " flags=" + << (closure->next_data.scratch % CLOSURE_BARRIER_FIRST_REF_BIT) + << " desc=" << desc << " err=" << grpc_core::StatusToString(error) + << " write_state=" << write_state_name(t->write_state) + << " whence=" << whence.file() << ":" << whence.line(); if (!error.ok()) { grpc_error_handle cl_err = @@ -1364,6 +1361,241 @@ static void log_metadata(const grpc_metadata_batch* md_batch, uint32_t id, }); } +static void send_initial_metadata_locked( + grpc_transport_stream_op_batch* op, grpc_chttp2_stream* s, + grpc_transport_stream_op_batch_payload* op_payload, + grpc_chttp2_transport* t, grpc_closure* on_complete) { + if (!grpc_core::IsCallTracerInTransportEnabled()) { + if (s->call_tracer != nullptr) { + s->call_tracer->RecordAnnotation( + grpc_core::HttpAnnotation(grpc_core::HttpAnnotation::Type::kStart, + gpr_now(GPR_CLOCK_REALTIME)) + .Add(s->t->flow_control.stats()) + .Add(s->flow_control.stats())); + } + } else if (grpc_core::IsTraceRecordCallopsEnabled()) { + auto* call_tracer = s->arena->GetContext(); + if (call_tracer != nullptr && call_tracer->IsSampled()) { + call_tracer->RecordAnnotation( + grpc_core::HttpAnnotation(grpc_core::HttpAnnotation::Type::kStart, + gpr_now(GPR_CLOCK_REALTIME)) + .Add(s->t->flow_control.stats()) + .Add(s->flow_control.stats())); + } + } + if (t->is_client && t->channelz_socket != nullptr) { + t->channelz_socket->RecordStreamStartedFromLocal(); + } + CHECK_EQ(s->send_initial_metadata_finished, nullptr); + on_complete->next_data.scratch |= t->closure_barrier_may_cover_write; + + s->send_initial_metadata_finished = add_closure_barrier(on_complete); + s->send_initial_metadata = + op_payload->send_initial_metadata.send_initial_metadata; + if (t->is_client) { + s->deadline = + std::min(s->deadline, + s->send_initial_metadata->get(grpc_core::GrpcTimeoutMetadata()) + .value_or(grpc_core::Timestamp::InfFuture())); + } + if (contains_non_ok_status(s->send_initial_metadata)) { + s->seen_error = true; + } + if (!s->write_closed) { + if (t->is_client) { + if (t->closed_with_error.ok()) { + CHECK_EQ(s->id, 0u); + grpc_chttp2_list_add_waiting_for_concurrency(t, s); + maybe_start_some_streams(t); + } else { + s->trailing_metadata_buffer.Set( + grpc_core::GrpcStreamNetworkState(), + grpc_core::GrpcStreamNetworkState::kNotSentOnWire); + grpc_chttp2_cancel_stream( + t, s, + grpc_error_set_int( + GRPC_ERROR_CREATE_REFERENCING("Transport closed", + &t->closed_with_error, 1), + grpc_core::StatusIntProperty::kRpcStatus, + GRPC_STATUS_UNAVAILABLE), + false); + } + } else { + CHECK_NE(s->id, 0u); + grpc_chttp2_mark_stream_writable(t, s); + if (!(op->send_message && + (op->payload->send_message.flags & GRPC_WRITE_BUFFER_HINT))) { + grpc_chttp2_initiate_write( + t, GRPC_CHTTP2_INITIATE_WRITE_SEND_INITIAL_METADATA); + } + } + } else { + s->send_initial_metadata = nullptr; + grpc_chttp2_complete_closure_step( + t, &s->send_initial_metadata_finished, + GRPC_ERROR_CREATE_REFERENCING( + "Attempt to send initial metadata after stream was closed", + &s->write_closed_error, 1), + "send_initial_metadata_finished"); + } +} + +static void send_message_locked( + grpc_transport_stream_op_batch* op, grpc_chttp2_stream* s, + grpc_transport_stream_op_batch_payload* op_payload, + grpc_chttp2_transport* t, grpc_closure* on_complete) { + t->num_messages_in_next_write++; + grpc_core::global_stats().IncrementHttp2SendMessageSize( + op->payload->send_message.send_message->Length()); + on_complete->next_data.scratch |= t->closure_barrier_may_cover_write; + s->send_message_finished = add_closure_barrier(op->on_complete); + const uint32_t flags = op_payload->send_message.flags; + if (s->write_closed) { + op->payload->send_message.stream_write_closed = true; + // We should NOT return an error here, so as to avoid a cancel OP being + // started. The surface layer will notice that the stream has been closed + // for writes and fail the send message op. + grpc_chttp2_complete_closure_step(t, &s->send_message_finished, + absl::OkStatus(), + "fetching_send_message_finished"); + } else { + uint8_t* frame_hdr = grpc_slice_buffer_tiny_add(&s->flow_controlled_buffer, + GRPC_HEADER_SIZE_IN_BYTES); + frame_hdr[0] = (flags & GRPC_WRITE_INTERNAL_COMPRESS) != 0; + size_t len = op_payload->send_message.send_message->Length(); + frame_hdr[1] = static_cast(len >> 24); + frame_hdr[2] = static_cast(len >> 16); + frame_hdr[3] = static_cast(len >> 8); + frame_hdr[4] = static_cast(len); + + s->call_tracer_wrapper.RecordOutgoingBytes( + {GRPC_HEADER_SIZE_IN_BYTES, len, 0}); + s->next_message_end_offset = + s->flow_controlled_bytes_written + + static_cast(s->flow_controlled_buffer.length) + + static_cast(len); + if (flags & GRPC_WRITE_BUFFER_HINT) { + s->next_message_end_offset -= t->write_buffer_size; + s->write_buffering = true; + } else { + s->write_buffering = false; + } + + grpc_slice* const slices = + op_payload->send_message.send_message->c_slice_buffer()->slices; + grpc_slice* const end = + slices + op_payload->send_message.send_message->Count(); + for (grpc_slice* slice = slices; slice != end; slice++) { + grpc_slice_buffer_add(&s->flow_controlled_buffer, + grpc_core::CSliceRef(*slice)); + } + + int64_t notify_offset = s->next_message_end_offset; + if (notify_offset <= s->flow_controlled_bytes_written) { + grpc_chttp2_complete_closure_step(t, &s->send_message_finished, + absl::OkStatus(), + "fetching_send_message_finished"); + } else { + grpc_chttp2_write_cb* cb = t->write_cb_pool; + if (cb == nullptr) { + cb = static_cast(gpr_malloc(sizeof(*cb))); + } else { + t->write_cb_pool = cb->next; + } + cb->call_at_byte = notify_offset; + cb->closure = s->send_message_finished; + s->send_message_finished = nullptr; + grpc_chttp2_write_cb** list = flags & GRPC_WRITE_THROUGH + ? &s->on_write_finished_cbs + : &s->on_flow_controlled_cbs; + cb->next = *list; + *list = cb; + } + + if (s->id != 0 && (!s->write_buffering || s->flow_controlled_buffer.length > + t->write_buffer_size)) { + grpc_chttp2_mark_stream_writable(t, s); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_SEND_MESSAGE); + } + } +} + +static void send_trailing_metadata_locked( + grpc_transport_stream_op_batch* op, grpc_chttp2_stream* s, + grpc_transport_stream_op_batch_payload* op_payload, + grpc_chttp2_transport* t, grpc_closure* on_complete) { + CHECK_EQ(s->send_trailing_metadata_finished, nullptr); + on_complete->next_data.scratch |= t->closure_barrier_may_cover_write; + s->send_trailing_metadata_finished = add_closure_barrier(on_complete); + s->send_trailing_metadata = + op_payload->send_trailing_metadata.send_trailing_metadata; + s->sent_trailing_metadata_op = op_payload->send_trailing_metadata.sent; + s->write_buffering = false; + if (contains_non_ok_status(s->send_trailing_metadata)) { + s->seen_error = true; + } + if (s->write_closed) { + s->send_trailing_metadata = nullptr; + s->sent_trailing_metadata_op = nullptr; + grpc_chttp2_complete_closure_step( + t, &s->send_trailing_metadata_finished, + op->payload->send_trailing_metadata.send_trailing_metadata->empty() + ? absl::OkStatus() + : GRPC_ERROR_CREATE("Attempt to send trailing metadata after " + "stream was closed"), + "send_trailing_metadata_finished"); + } else if (s->id != 0) { + // TODO(ctiller): check if there's flow control for any outstanding + // bytes before going writable + grpc_chttp2_mark_stream_writable(t, s); + grpc_chttp2_initiate_write( + t, GRPC_CHTTP2_INITIATE_WRITE_SEND_TRAILING_METADATA); + } +} + +static void recv_initial_metadata_locked( + grpc_chttp2_stream* s, grpc_transport_stream_op_batch_payload* op_payload, + grpc_chttp2_transport* t) { + CHECK_EQ(s->recv_initial_metadata_ready, nullptr); + s->recv_initial_metadata_ready = + op_payload->recv_initial_metadata.recv_initial_metadata_ready; + s->recv_initial_metadata = + op_payload->recv_initial_metadata.recv_initial_metadata; + s->trailing_metadata_available = + op_payload->recv_initial_metadata.trailing_metadata_available; + if (s->parsed_trailers_only && s->trailing_metadata_available != nullptr) { + *s->trailing_metadata_available = true; + } + grpc_chttp2_maybe_complete_recv_initial_metadata(t, s); +} + +static void recv_message_locked( + grpc_chttp2_stream* s, grpc_transport_stream_op_batch_payload* op_payload, + grpc_chttp2_transport* t) { + CHECK_EQ(s->recv_message_ready, nullptr); + s->recv_message_ready = op_payload->recv_message.recv_message_ready; + s->recv_message = op_payload->recv_message.recv_message; + s->recv_message->emplace(); + s->recv_message_flags = op_payload->recv_message.flags; + s->call_failed_before_recv_message = + op_payload->recv_message.call_failed_before_recv_message; + grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); +} + +static void recv_trailing_metadata_locked( + grpc_chttp2_stream* s, grpc_transport_stream_op_batch_payload* op_payload, + grpc_chttp2_transport* t) { + CHECK_EQ(s->collecting_stats, nullptr); + s->collecting_stats = op_payload->recv_trailing_metadata.collect_stats; + CHECK_EQ(s->recv_trailing_metadata_finished, nullptr); + s->recv_trailing_metadata_finished = + op_payload->recv_trailing_metadata.recv_trailing_metadata_ready; + s->recv_trailing_metadata = + op_payload->recv_trailing_metadata.recv_trailing_metadata; + s->final_metadata_requested = true; + grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); +} + static void perform_stream_op_locked(void* stream_op, grpc_error_handle /*error_ignored*/) { grpc_transport_stream_op_batch* op = @@ -1407,225 +1639,27 @@ static void perform_stream_op_locked(void* stream_op, } if (op->send_initial_metadata) { - if (!grpc_core::IsCallTracerInTransportEnabled()) { - if (s->call_tracer != nullptr) { - s->call_tracer->RecordAnnotation( - grpc_core::HttpAnnotation(grpc_core::HttpAnnotation::Type::kStart, - gpr_now(GPR_CLOCK_REALTIME)) - .Add(s->t->flow_control.stats()) - .Add(s->flow_control.stats())); - } - } else if (grpc_core::IsTraceRecordCallopsEnabled()) { - auto* call_tracer = - s->arena->GetContext(); - if (call_tracer != nullptr && call_tracer->IsSampled()) { - call_tracer->RecordAnnotation( - grpc_core::HttpAnnotation(grpc_core::HttpAnnotation::Type::kStart, - gpr_now(GPR_CLOCK_REALTIME)) - .Add(s->t->flow_control.stats()) - .Add(s->flow_control.stats())); - } - } - if (t->is_client && t->channelz_socket != nullptr) { - t->channelz_socket->RecordStreamStartedFromLocal(); - } - CHECK_EQ(s->send_initial_metadata_finished, nullptr); - on_complete->next_data.scratch |= t->closure_barrier_may_cover_write; - - s->send_initial_metadata_finished = add_closure_barrier(on_complete); - s->send_initial_metadata = - op_payload->send_initial_metadata.send_initial_metadata; - if (t->is_client) { - s->deadline = std::min( - s->deadline, - s->send_initial_metadata->get(grpc_core::GrpcTimeoutMetadata()) - .value_or(grpc_core::Timestamp::InfFuture())); - } - if (contains_non_ok_status(s->send_initial_metadata)) { - s->seen_error = true; - } - if (!s->write_closed) { - if (t->is_client) { - if (t->closed_with_error.ok()) { - CHECK_EQ(s->id, 0u); - grpc_chttp2_list_add_waiting_for_concurrency(t, s); - maybe_start_some_streams(t); - } else { - s->trailing_metadata_buffer.Set( - grpc_core::GrpcStreamNetworkState(), - grpc_core::GrpcStreamNetworkState::kNotSentOnWire); - grpc_chttp2_cancel_stream( - t, s, - grpc_error_set_int( - GRPC_ERROR_CREATE_REFERENCING("Transport closed", - &t->closed_with_error, 1), - grpc_core::StatusIntProperty::kRpcStatus, - GRPC_STATUS_UNAVAILABLE), - false); - } - } else { - CHECK_NE(s->id, 0u); - grpc_chttp2_mark_stream_writable(t, s); - if (!(op->send_message && - (op->payload->send_message.flags & GRPC_WRITE_BUFFER_HINT))) { - grpc_chttp2_initiate_write( - t, GRPC_CHTTP2_INITIATE_WRITE_SEND_INITIAL_METADATA); - } - } - } else { - s->send_initial_metadata = nullptr; - grpc_chttp2_complete_closure_step( - t, &s->send_initial_metadata_finished, - GRPC_ERROR_CREATE_REFERENCING( - "Attempt to send initial metadata after stream was closed", - &s->write_closed_error, 1), - "send_initial_metadata_finished"); - } + send_initial_metadata_locked(op, s, op_payload, t, on_complete); } if (op->send_message) { - t->num_messages_in_next_write++; - grpc_core::global_stats().IncrementHttp2SendMessageSize( - op->payload->send_message.send_message->Length()); - on_complete->next_data.scratch |= t->closure_barrier_may_cover_write; - s->send_message_finished = add_closure_barrier(op->on_complete); - const uint32_t flags = op_payload->send_message.flags; - if (s->write_closed) { - op->payload->send_message.stream_write_closed = true; - // We should NOT return an error here, so as to avoid a cancel OP being - // started. The surface layer will notice that the stream has been closed - // for writes and fail the send message op. - grpc_chttp2_complete_closure_step(t, &s->send_message_finished, - absl::OkStatus(), - "fetching_send_message_finished"); - } else { - uint8_t* frame_hdr = grpc_slice_buffer_tiny_add( - &s->flow_controlled_buffer, GRPC_HEADER_SIZE_IN_BYTES); - frame_hdr[0] = (flags & GRPC_WRITE_INTERNAL_COMPRESS) != 0; - size_t len = op_payload->send_message.send_message->Length(); - frame_hdr[1] = static_cast(len >> 24); - frame_hdr[2] = static_cast(len >> 16); - frame_hdr[3] = static_cast(len >> 8); - frame_hdr[4] = static_cast(len); - - s->call_tracer_wrapper.RecordOutgoingBytes( - {GRPC_HEADER_SIZE_IN_BYTES, len, 0}); - s->next_message_end_offset = - s->flow_controlled_bytes_written + - static_cast(s->flow_controlled_buffer.length) + - static_cast(len); - if (flags & GRPC_WRITE_BUFFER_HINT) { - s->next_message_end_offset -= t->write_buffer_size; - s->write_buffering = true; - } else { - s->write_buffering = false; - } - - grpc_slice* const slices = - op_payload->send_message.send_message->c_slice_buffer()->slices; - grpc_slice* const end = - slices + op_payload->send_message.send_message->Count(); - for (grpc_slice* slice = slices; slice != end; slice++) { - grpc_slice_buffer_add(&s->flow_controlled_buffer, - grpc_core::CSliceRef(*slice)); - } - - int64_t notify_offset = s->next_message_end_offset; - if (notify_offset <= s->flow_controlled_bytes_written) { - grpc_chttp2_complete_closure_step(t, &s->send_message_finished, - absl::OkStatus(), - "fetching_send_message_finished"); - } else { - grpc_chttp2_write_cb* cb = t->write_cb_pool; - if (cb == nullptr) { - cb = static_cast(gpr_malloc(sizeof(*cb))); - } else { - t->write_cb_pool = cb->next; - } - cb->call_at_byte = notify_offset; - cb->closure = s->send_message_finished; - s->send_message_finished = nullptr; - grpc_chttp2_write_cb** list = flags & GRPC_WRITE_THROUGH - ? &s->on_write_finished_cbs - : &s->on_flow_controlled_cbs; - cb->next = *list; - *list = cb; - } - - if (s->id != 0 && - (!s->write_buffering || - s->flow_controlled_buffer.length > t->write_buffer_size)) { - grpc_chttp2_mark_stream_writable(t, s); - grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_SEND_MESSAGE); - } - } + send_message_locked(op, s, op_payload, t, on_complete); } if (op->send_trailing_metadata) { - CHECK_EQ(s->send_trailing_metadata_finished, nullptr); - on_complete->next_data.scratch |= t->closure_barrier_may_cover_write; - s->send_trailing_metadata_finished = add_closure_barrier(on_complete); - s->send_trailing_metadata = - op_payload->send_trailing_metadata.send_trailing_metadata; - s->sent_trailing_metadata_op = op_payload->send_trailing_metadata.sent; - s->write_buffering = false; - if (contains_non_ok_status(s->send_trailing_metadata)) { - s->seen_error = true; - } - if (s->write_closed) { - s->send_trailing_metadata = nullptr; - s->sent_trailing_metadata_op = nullptr; - grpc_chttp2_complete_closure_step( - t, &s->send_trailing_metadata_finished, - op->payload->send_trailing_metadata.send_trailing_metadata->empty() - ? absl::OkStatus() - : GRPC_ERROR_CREATE("Attempt to send trailing metadata after " - "stream was closed"), - "send_trailing_metadata_finished"); - } else if (s->id != 0) { - // TODO(ctiller): check if there's flow control for any outstanding - // bytes before going writable - grpc_chttp2_mark_stream_writable(t, s); - grpc_chttp2_initiate_write( - t, GRPC_CHTTP2_INITIATE_WRITE_SEND_TRAILING_METADATA); - } + send_trailing_metadata_locked(op, s, op_payload, t, on_complete); } if (op->recv_initial_metadata) { - CHECK_EQ(s->recv_initial_metadata_ready, nullptr); - s->recv_initial_metadata_ready = - op_payload->recv_initial_metadata.recv_initial_metadata_ready; - s->recv_initial_metadata = - op_payload->recv_initial_metadata.recv_initial_metadata; - s->trailing_metadata_available = - op_payload->recv_initial_metadata.trailing_metadata_available; - if (s->parsed_trailers_only && s->trailing_metadata_available != nullptr) { - *s->trailing_metadata_available = true; - } - grpc_chttp2_maybe_complete_recv_initial_metadata(t, s); + recv_initial_metadata_locked(s, op_payload, t); } if (op->recv_message) { - CHECK_EQ(s->recv_message_ready, nullptr); - s->recv_message_ready = op_payload->recv_message.recv_message_ready; - s->recv_message = op_payload->recv_message.recv_message; - s->recv_message->emplace(); - s->recv_message_flags = op_payload->recv_message.flags; - s->call_failed_before_recv_message = - op_payload->recv_message.call_failed_before_recv_message; - grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); + recv_message_locked(s, op_payload, t); } if (op->recv_trailing_metadata) { - CHECK_EQ(s->collecting_stats, nullptr); - s->collecting_stats = op_payload->recv_trailing_metadata.collect_stats; - CHECK_EQ(s->recv_trailing_metadata_finished, nullptr); - s->recv_trailing_metadata_finished = - op_payload->recv_trailing_metadata.recv_trailing_metadata_ready; - s->recv_trailing_metadata = - op_payload->recv_trailing_metadata.recv_trailing_metadata; - s->final_metadata_requested = true; - grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); + recv_trailing_metadata_locked(s, op_payload, t); } if (on_complete != nullptr) { @@ -1653,10 +1687,9 @@ void grpc_chttp2_transport::PerformStreamOp( } } - if (GRPC_TRACE_FLAG_ENABLED(http)) { - LOG(INFO) << "perform_stream_op[s=" << s << "; op=" << op - << "]: " << grpc_transport_stream_op_batch_string(op, false); - } + GRPC_TRACE_LOG(http, INFO) + << "perform_stream_op[s=" << s << "; op=" << op + << "]: " << grpc_transport_stream_op_batch_string(op, false); GRPC_CHTTP2_STREAM_REF(s, "perform_stream_op"); op->handler_private.extra_arg = gs; @@ -2000,10 +2033,8 @@ static void perform_transport_op_locked(void* stream_op, } void grpc_chttp2_transport::PerformOp(grpc_transport_op* op) { - if (GRPC_TRACE_FLAG_ENABLED(http)) { - LOG(INFO) << "perform_transport_op[t=" << this - << "]: " << grpc_transport_op_string(op); - } + GRPC_TRACE_LOG(http, INFO) << "perform_transport_op[t=" << this + << "]: " << grpc_transport_op_string(op); op->handler_private.extra_arg = this; Ref().release()->combiner->Run( GRPC_CLOSURE_INIT(&op->handler_private.closure, @@ -2053,11 +2084,10 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_chttp2_transport* t, // Lambda is immediately invoked as a big scoped section that can be // exited out of at any point by returning. [&]() { - if (GRPC_TRACE_FLAG_ENABLED(http)) { - VLOG(2) << "maybe_complete_recv_message " << s - << " final_metadata_requested=" << s->final_metadata_requested - << " seen_error=" << s->seen_error; - } + GRPC_TRACE_VLOG(http, 2) + << "maybe_complete_recv_message " << s + << " final_metadata_requested=" << s->final_metadata_requested + << " seen_error=" << s->seen_error; if (s->final_metadata_requested && s->seen_error) { grpc_slice_buffer_reset_and_unref(&s->frame_storage); s->recv_message->reset(); @@ -2068,11 +2098,10 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_chttp2_transport* t, int64_t min_progress_size; auto r = grpc_deframe_unprocessed_incoming_frames( s, &min_progress_size, &**s->recv_message, s->recv_message_flags); - if (GRPC_TRACE_FLAG_ENABLED(http)) { - VLOG(2) << "Deframe data frame: " - << grpc_core::PollToString( - r, [](absl::Status r) { return r.ToString(); }); - } + GRPC_TRACE_VLOG(http, 2) + << "Deframe data frame: " + << grpc_core::PollToString( + r, [](absl::Status r) { return r.ToString(); }); if (r.pending()) { if (s->read_closed) { grpc_slice_buffer_reset_and_unref(&s->frame_storage); @@ -2123,13 +2152,12 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_chttp2_transport* t, void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t, grpc_chttp2_stream* s) { grpc_chttp2_maybe_complete_recv_message(t, s); - if (GRPC_TRACE_FLAG_ENABLED(http)) { - VLOG(2) << "maybe_complete_recv_trailing_metadata cli=" << t->is_client - << " s=" << s << " closure=" << s->recv_trailing_metadata_finished - << " read_closed=" << s->read_closed - << " write_closed=" << s->write_closed << " " - << s->frame_storage.length; - } + GRPC_TRACE_VLOG(http, 2) << "maybe_complete_recv_trailing_metadata cli=" + << t->is_client << " s=" << s + << " closure=" << s->recv_trailing_metadata_finished + << " read_closed=" << s->read_closed + << " write_closed=" << s->write_closed << " " + << s->frame_storage.length; if (s->recv_trailing_metadata_finished != nullptr && s->read_closed && s->write_closed) { if (s->seen_error || !t->is_client) { @@ -2333,15 +2361,12 @@ grpc_chttp2_transport::RemovedStreamHandle grpc_chttp2_mark_stream_closed( grpc_chttp2_transport* t, grpc_chttp2_stream* s, int close_reads, int close_writes, grpc_error_handle error) { grpc_chttp2_transport::RemovedStreamHandle rsh; - if (GRPC_TRACE_FLAG_ENABLED(http)) { - VLOG(2) << "MARK_STREAM_CLOSED: t=" << t << " s=" << s << "(id=" << s->id - << ") " - << ((close_reads && close_writes) - ? "read+write" - : (close_reads ? "read" - : (close_writes ? "write" : "nothing??"))) - << " [" << grpc_core::StatusToString(error) << "]"; - } + GRPC_TRACE_VLOG(http, 2) + << "MARK_STREAM_CLOSED: t=" << t << " s=" << s << "(id=" << s->id << ") " + << ((close_reads && close_writes) + ? "read+write" + : (close_reads ? "read" : (close_writes ? "write" : "nothing??"))) + << " [" << grpc_core::StatusToString(error) << "]"; if (s->read_closed && s->write_closed) { // already closed, but we should still fake the status if needed. grpc_error_handle overall_error = removal_error(error, s, "Stream removed"); @@ -2818,10 +2843,9 @@ static void start_bdp_ping(grpc_core::RefCountedPtr t, static void start_bdp_ping_locked( grpc_core::RefCountedPtr t, grpc_error_handle error) { - if (GRPC_TRACE_FLAG_ENABLED(http)) { - LOG(INFO) << t->peer_string.as_string_view() - << ": Start BDP ping err=" << grpc_core::StatusToString(error); - } + GRPC_TRACE_LOG(http, INFO) + << t->peer_string.as_string_view() + << ": Start BDP ping err=" << grpc_core::StatusToString(error); if (!error.ok() || !t->closed_with_error.ok()) { return; } @@ -2844,10 +2868,9 @@ static void finish_bdp_ping(grpc_core::RefCountedPtr t, static void finish_bdp_ping_locked( grpc_core::RefCountedPtr t, grpc_error_handle error) { - if (GRPC_TRACE_FLAG_ENABLED(http)) { - LOG(INFO) << t->peer_string.as_string_view() - << ": Complete BDP ping err=" << grpc_core::StatusToString(error); - } + GRPC_TRACE_LOG(http, INFO) + << t->peer_string.as_string_view() + << ": Complete BDP ping err=" << grpc_core::StatusToString(error); if (!error.ok() || !t->closed_with_error.ok()) { return; } @@ -3109,10 +3132,9 @@ static void benign_reclaimer_locked( if (error.ok() && t->stream_map.empty()) { // Channel with no active streams: send a goaway to try and make it // disconnect cleanly - if (GRPC_TRACE_FLAG_ENABLED(resource_quota)) { - LOG(INFO) << "HTTP2: " << t->peer_string.as_string_view() - << " - send goaway to free memory"; - } + GRPC_TRACE_LOG(resource_quota, INFO) + << "HTTP2: " << t->peer_string.as_string_view() + << " - send goaway to free memory"; send_goaway(t.get(), grpc_error_set_int(GRPC_ERROR_CREATE("Buffers full"), grpc_core::StatusIntProperty::kHttp2Error, @@ -3136,10 +3158,9 @@ static void destructive_reclaimer_locked( if (error.ok() && !t->stream_map.empty()) { // As stream_map is a hash map, this selects effectively a random stream. grpc_chttp2_stream* s = t->stream_map.begin()->second; - if (GRPC_TRACE_FLAG_ENABLED(resource_quota)) { - LOG(INFO) << "HTTP2: " << t->peer_string.as_string_view() - << " - abandon stream id " << s->id; - } + GRPC_TRACE_LOG(resource_quota, INFO) + << "HTTP2: " << t->peer_string.as_string_view() + << " - abandon stream id " << s->id; grpc_chttp2_cancel_stream( t.get(), s, grpc_error_set_int(GRPC_ERROR_CREATE("Buffers full"), diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc index 39c0d08299..c80fdd8307 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.cc +++ b/src/core/ext/transport/chttp2/transport/flow_control.cc @@ -233,10 +233,9 @@ void TransportFlowControl::UpdateSetting( FlowControlAction& (FlowControlAction::*set)(FlowControlAction::Urgency, uint32_t)) { if (new_desired_value != *desired_value) { - if (GRPC_TRACE_FLAG_ENABLED(flowctl)) { - LOG(INFO) << "[flowctl] UPDATE SETTING " << name << " from " - << *desired_value << " to " << new_desired_value; - } + GRPC_TRACE_LOG(flowctl, INFO) + << "[flowctl] UPDATE SETTING " << name << " from " << *desired_value + << " to " << new_desired_value; // Reaching zero can only happen for initial window size, and if it occurs // we really want to wake up writes and ensure all the queued stream // window updates are flushed, since stream flow control operates diff --git a/src/core/ext/transport/chttp2/transport/flow_control.h b/src/core/ext/transport/chttp2/transport/flow_control.h index a0bd6323b0..b15e8603c2 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.h +++ b/src/core/ext/transport/chttp2/transport/flow_control.h @@ -32,7 +32,6 @@ #include "absl/strings/string_view.h" #include "absl/types/optional.h" -#include #include #include "src/core/ext/transport/chttp2/transport/http2_settings.h" diff --git a/src/core/ext/transport/chttp2/transport/frame.cc b/src/core/ext/transport/chttp2/transport/frame.cc index 9e05cf6d85..92788903f1 100644 --- a/src/core/ext/transport/chttp2/transport/frame.cc +++ b/src/core/ext/transport/chttp2/transport/frame.cc @@ -23,7 +23,6 @@ #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/ext/transport/chttp2/transport/frame_data.cc b/src/core/ext/transport/chttp2/transport/frame_data.cc index e16965c447..77739c3088 100644 --- a/src/core/ext/transport/chttp2/transport/frame_data.cc +++ b/src/core/ext/transport/chttp2/transport/frame_data.cc @@ -25,7 +25,6 @@ #include "absl/strings/str_format.h" #include -#include #include #include "src/core/ext/transport/chttp2/transport/internal.h" diff --git a/src/core/ext/transport/chttp2/transport/frame_goaway.cc b/src/core/ext/transport/chttp2/transport/frame_goaway.cc index fadce90139..31e7c76ba3 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.cc +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.cc @@ -28,7 +28,6 @@ #include #include -#include #include #include "src/core/ext/transport/chttp2/transport/internal.h" diff --git a/src/core/ext/transport/chttp2/transport/frame_ping.cc b/src/core/ext/transport/chttp2/transport/frame_ping.cc index 764f9842cf..7b7b080e32 100644 --- a/src/core/ext/transport/chttp2/transport/frame_ping.cc +++ b/src/core/ext/transport/chttp2/transport/frame_ping.cc @@ -93,10 +93,9 @@ grpc_error_handle grpc_chttp2_ping_parser_parse(void* parser, if (p->byte == 8) { CHECK(is_last); if (p->is_ack) { - if (GRPC_TRACE_FLAG_ENABLED(http2_ping)) { - LOG(INFO) << (t->is_client ? "CLIENT" : "SERVER") << "[" << t - << "]: received ping ack " << p->opaque_8bytes; - } + GRPC_TRACE_LOG(http2_ping, INFO) + << (t->is_client ? "CLIENT" : "SERVER") << "[" << t + << "]: received ping ack " << p->opaque_8bytes; grpc_chttp2_ack_ping(t, p->opaque_8bytes); } else { if (!t->is_client) { @@ -111,8 +110,9 @@ grpc_error_handle grpc_chttp2_ping_parser_parse(void* parser, if (t->ping_abuse_policy.ReceivedOnePing(transport_idle)) { grpc_chttp2_exceeded_ping_strikes(t); } - } else if (GRPC_TRACE_FLAG_ENABLED(http2_ping)) { - LOG(INFO) << "CLIENT[" << t << "]: received ping " << p->opaque_8bytes; + } else { + GRPC_TRACE_LOG(http2_ping, INFO) + << "CLIENT[" << t << "]: received ping " << p->opaque_8bytes; } if (t->ack_pings) { if (t->ping_ack_count == t->ping_ack_capacity) { diff --git a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc index 540d4faaf2..93e33a14a0 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc @@ -113,10 +113,9 @@ grpc_error_handle grpc_chttp2_rst_stream_parser_parse(void* parser, ((static_cast(p->reason_bytes[1])) << 16) | ((static_cast(p->reason_bytes[2])) << 8) | ((static_cast(p->reason_bytes[3]))); - if (GRPC_TRACE_FLAG_ENABLED(http)) { - LOG(INFO) << "[chttp2 transport=" << t << " stream=" << s - << "] received RST_STREAM(reason=" << reason << ")"; - } + GRPC_TRACE_LOG(http, INFO) + << "[chttp2 transport=" << t << " stream=" << s + << "] received RST_STREAM(reason=" << reason << ")"; grpc_error_handle error; if (reason != GRPC_HTTP2_NO_ERROR || s->trailing_metadata_buffer.empty()) { error = grpc_error_set_int( diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.cc b/src/core/ext/transport/chttp2/transport/frame_settings.cc index ebf74b2114..e0a12218ca 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.cc +++ b/src/core/ext/transport/chttp2/transport/frame_settings.cc @@ -187,12 +187,11 @@ grpc_error_handle grpc_chttp2_settings_parser_parse(void* p, "invalid value %u passed for %s", parser->value, grpc_core::Http2Settings::WireIdToName(parser->id).c_str())); } - if (GRPC_TRACE_FLAG_ENABLED(http)) { - LOG(INFO) << "CHTTP2:" << (t->is_client ? "CLI" : "SVR") << ":" - << t->peer_string.as_string_view() << ": got setting " - << grpc_core::Http2Settings::WireIdToName(parser->id) - << " = " << parser->value; - } + GRPC_TRACE_LOG(http, INFO) + << "CHTTP2:" << (t->is_client ? "CLI" : "SVR") << ":" + << t->peer_string.as_string_view() << ": got setting " + << grpc_core::Http2Settings::WireIdToName(parser->id) << " = " + << parser->value; } break; } } diff --git a/src/core/ext/transport/chttp2/transport/frame_window_update.cc b/src/core/ext/transport/chttp2/transport/frame_window_update.cc index efae1615eb..6dafd5318b 100644 --- a/src/core/ext/transport/chttp2/transport/frame_window_update.cc +++ b/src/core/ext/transport/chttp2/transport/frame_window_update.cc @@ -25,7 +25,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" -#include #include #include "src/core/ext/transport/chttp2/transport/flow_control.h" diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index 54a0865869..9fa6aa7964 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -117,9 +117,8 @@ void HPackCompressor::SetMaxUsableSize(uint32_t max_table_size) { void HPackCompressor::SetMaxTableSize(uint32_t max_table_size) { if (table_.SetMaxSize(std::min(max_usable_size_, max_table_size))) { advertise_table_size_change_ = true; - if (GRPC_TRACE_FLAG_ENABLED(http)) { - LOG(INFO) << "set max table size from encoder to " << max_table_size; - } + GRPC_TRACE_LOG(http, INFO) + << "set max table size from encoder to " << max_table_size; } } diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder_table.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder_table.cc index 3492fd5982..143781dca3 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder_table.cc @@ -18,7 +18,6 @@ #include "absl/log/check.h" -#include #include namespace grpc_core { diff --git a/src/core/ext/transport/chttp2/transport/hpack_parse_result.h b/src/core/ext/transport/chttp2/transport/hpack_parse_result.h index 0d3a57ad3d..b810264a36 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parse_result.h +++ b/src/core/ext/transport/chttp2/transport/hpack_parse_result.h @@ -27,7 +27,6 @@ #include "absl/strings/string_view.h" #include "absl/types/optional.h" -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index 205e16458e..04c64dd5df 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -90,12 +90,14 @@ constexpr Base64InverseTable kBase64InverseTable; class HPackParser::Input { public: Input(grpc_slice_refcount* current_slice_refcount, const uint8_t* begin, - const uint8_t* end, absl::BitGenRef bitsrc, HpackParseResult& error) + const uint8_t* end, absl::BitGenRef bitsrc, + HpackParseResult& frame_error, HpackParseResult& field_error) : current_slice_refcount_(current_slice_refcount), begin_(begin), end_(end), frontier_(begin), - error_(error), + frame_error_(frame_error), + field_error_(field_error), bitsrc_(bitsrc) {} // If input is backed by a slice, retrieve its refcount. If not, return @@ -214,7 +216,13 @@ class HPackParser::Input { // Check if we saw an EOF bool eof_error() const { - return min_progress_size_ != 0 || error_.connection_error(); + return min_progress_size_ != 0 || frame_error_.connection_error(); + } + + // Reset the field error to be ok + void ClearFieldError() { + if (field_error_.ok()) return; + field_error_ = HpackParseResult(); } // Minimum number of bytes to unstuck the current parse @@ -296,13 +304,18 @@ class HPackParser::Input { // Do not use this directly, instead use SetErrorAndContinueParsing or // SetErrorAndStopParsing. void SetError(HpackParseResult error) { - if (!error_.ok() || min_progress_size_ > 0) { - if (error.connection_error() && !error_.connection_error()) { - error_ = std::move(error); // connection errors dominate + SetErrorFor(frame_error_, error); + SetErrorFor(field_error_, std::move(error)); + } + + void SetErrorFor(HpackParseResult& error, HpackParseResult new_error) { + if (!error.ok() || min_progress_size_ > 0) { + if (new_error.connection_error() && !error.connection_error()) { + error = std::move(new_error); // connection errors dominate } return; } - error_ = std::move(error); + error = std::move(new_error); } // Refcount if we are backed by a slice @@ -314,7 +327,8 @@ class HPackParser::Input { // Frontier denotes the first byte past successfully processed input const uint8_t* frontier_; // Current error - HpackParseResult& error_; + HpackParseResult& frame_error_; + HpackParseResult& field_error_; // If the error was EOF, we flag it here by noting how many more bytes would // be needed to make progress size_t min_progress_size_ = 0; @@ -591,6 +605,7 @@ class HPackParser::Parser { bool ParseTop() { DCHECK(state_.parse_state == ParseState::kTop); auto cur = *input_->Next(); + input_->ClearFieldError(); switch (cur >> 4) { // Literal header not indexed - First byte format: 0000xxxx // Literal header never indexed - First byte format: 0001xxxx @@ -698,7 +713,7 @@ class HPackParser::Parser { LOG(INFO) << "HTTP:" << log_info_.stream_id << ":" << type << ":" << (log_info_.is_client ? "CLI" : "SVR") << ": " << memento.md.DebugString() - << (memento.parse_status == nullptr + << (memento.parse_status.get() == nullptr ? "" : absl::StrCat( " (parse error: ", @@ -709,7 +724,7 @@ class HPackParser::Parser { void EmitHeader(const HPackTable::Memento& md) { // Pass up to the transport state_.frame_length += md.md.transport_size(); - if (md.parse_status != nullptr) { + if (md.parse_status.get() != nullptr) { // Reject any requests with invalid metadata. input_->SetErrorAndContinueParsing(*md.parse_status); } @@ -949,7 +964,7 @@ class HPackParser::Parser { absl::string_view key_string; if (auto* s = absl::get_if(&state_.key)) { key_string = s->as_string_view(); - if (state_.frame_error.ok()) { + if (state_.field_error.ok()) { auto r = ValidateKey(key_string); if (r != ValidateMetadataResult::kOk) { input_->SetErrorAndContinueParsing( @@ -959,7 +974,7 @@ class HPackParser::Parser { } else { const auto* memento = absl::get(state_.key); key_string = memento->md.key(); - if (state_.frame_error.ok() && memento->parse_status != nullptr) { + if (state_.field_error.ok() && memento->parse_status.get() != nullptr) { input_->SetErrorAndContinueParsing(*memento->parse_status); } } @@ -987,14 +1002,14 @@ class HPackParser::Parser { auto md = grpc_metadata_batch::Parse( key_string, std::move(value_slice), state_.add_to_table, transport_size, [key_string, this](absl::string_view message, const Slice&) { - if (!state_.frame_error.ok()) return; + if (!state_.field_error.ok()) return; input_->SetErrorAndContinueParsing( HpackParseResult::MetadataParseError(key_string)); LOG(ERROR) << "Error parsing '" << key_string << "' metadata: " << message; }); HPackTable::Memento memento{ - std::move(md), state_.frame_error.PersistentStreamErrorOrNullptr()}; + std::move(md), state_.field_error.PersistentStreamErrorOrNullptr()}; input_->UpdateFrontier(); state_.parse_state = ParseState::kTop; if (state_.add_to_table) { @@ -1107,13 +1122,13 @@ grpc_error_handle HPackParser::Parse( std::vector buffer = std::move(unparsed_bytes_); return ParseInput( Input(nullptr, buffer.data(), buffer.data() + buffer.size(), bitsrc, - state_.frame_error), + state_.frame_error, state_.field_error), is_last, call_tracer); } - return ParseInput( - Input(slice.refcount, GRPC_SLICE_START_PTR(slice), - GRPC_SLICE_END_PTR(slice), bitsrc, state_.frame_error), - is_last, call_tracer); + return ParseInput(Input(slice.refcount, GRPC_SLICE_START_PTR(slice), + GRPC_SLICE_END_PTR(slice), bitsrc, state_.frame_error, + state_.field_error), + is_last, call_tracer); } grpc_error_handle HPackParser::ParseInput( diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.h b/src/core/ext/transport/chttp2/transport/hpack_parser.h index 463e051dc2..9df4487f31 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.h +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.h @@ -235,6 +235,8 @@ class HPackParser { HPackTable hpack_table; // Error so far for this frame (set by class Input) HpackParseResult frame_error; + // Error so far for this field (set by class Input) + HpackParseResult field_error; // Length of frame so far. uint32_t frame_length = 0; // Length of the string being parsed 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 f27f7a1019..7a0b7bd849 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc @@ -37,6 +37,7 @@ #include "src/core/ext/transport/chttp2/transport/hpack_parse_result.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/slice/slice.h" +#include "src/core/telemetry/stats.h" namespace grpc_core { @@ -47,6 +48,10 @@ void HPackTable::MementoRingBuffer::Put(Memento m) { return entries_.push_back(std::move(m)); } size_t index = (first_entry_ + num_entries_) % max_entries_; + if (timestamp_index_ == kNoTimestamp) { + timestamp_index_ = index; + timestamp_ = Timestamp::Now(); + } entries_[index] = std::move(m); ++num_entries_; } @@ -54,12 +59,31 @@ void HPackTable::MementoRingBuffer::Put(Memento m) { auto HPackTable::MementoRingBuffer::PopOne() -> Memento { CHECK_GT(num_entries_, 0u); size_t index = first_entry_ % max_entries_; + if (index == timestamp_index_) { + global_stats().IncrementHttp2HpackEntryLifetime( + (Timestamp::Now() - timestamp_).millis()); + timestamp_index_ = kNoTimestamp; + } ++first_entry_; --num_entries_; - return std::move(entries_[index]); + auto& entry = entries_[index]; + if (!entry.parse_status.TestBit(Memento::kUsedBit)) { + global_stats().IncrementHttp2HpackMisses(); + } + return std::move(entry); } -auto HPackTable::MementoRingBuffer::Lookup(uint32_t index) const +auto HPackTable::MementoRingBuffer::Lookup(uint32_t index) -> const Memento* { + if (index >= num_entries_) return nullptr; + uint32_t offset = (num_entries_ - 1u - index + first_entry_) % max_entries_; + auto& entry = entries_[offset]; + const bool was_used = entry.parse_status.TestBit(Memento::kUsedBit); + entry.parse_status.SetBit(Memento::kUsedBit); + if (!was_used) global_stats().IncrementHttp2HpackHits(); + return &entry; +} + +auto HPackTable::MementoRingBuffer::Peek(uint32_t index) const -> const Memento* { if (index >= num_entries_) return nullptr; uint32_t offset = (num_entries_ - 1u - index + first_entry_) % max_entries_; @@ -79,14 +103,22 @@ void HPackTable::MementoRingBuffer::Rebuild(uint32_t max_entries) { entries_.swap(entries); } -void HPackTable::MementoRingBuffer::ForEach( - absl::FunctionRef f) const { +template +void HPackTable::MementoRingBuffer::ForEach(F f) const { uint32_t index = 0; - while (auto* m = Lookup(index++)) { + while (auto* m = Peek(index++)) { f(index, *m); } } +HPackTable::MementoRingBuffer::~MementoRingBuffer() { + ForEach([](uint32_t, const Memento& m) { + if (!m.parse_status.TestBit(Memento::kUsedBit)) { + global_stats().IncrementHttp2HpackMisses(); + } + }); +} + // Evict one element from the table void HPackTable::EvictOne() { auto first_entry = entries_.PopOne(); diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser_table.h b/src/core/ext/transport/chttp2/transport/hpack_parser_table.h index d126b3eeb4..06e0aeb7f4 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +++ b/src/core/ext/transport/chttp2/transport/hpack_parser_table.h @@ -21,6 +21,8 @@ #include +#include +#include #include #include #include @@ -34,6 +36,7 @@ #include "src/core/lib/gprpp/no_destruct.h" #include "src/core/lib/transport/metadata_batch.h" #include "src/core/lib/transport/parsed_metadata.h" +#include "src/core/util/unique_ptr_with_bitset.h" namespace grpc_core { @@ -54,11 +57,14 @@ class HPackTable { struct Memento { ParsedMetadata md; - std::unique_ptr parse_status; + // Alongside parse_status we store one bit indicating whether this memento + // has been looked up (and therefore consumed) or not. + UniquePtrWithBitset parse_status; + static const int kUsedBit = 0; }; // Lookup, but don't ref. - const Memento* Lookup(uint32_t index) const { + const Memento* Lookup(uint32_t index) { // Static table comes first, just return an entry from it. // NB: This imposes the constraint that the first // GRPC_CHTTP2_LAST_STATIC_ENTRY entries in the core static metadata table @@ -97,6 +103,14 @@ class HPackTable { class MementoRingBuffer { public: + MementoRingBuffer() {} + ~MementoRingBuffer(); + + MementoRingBuffer(const MementoRingBuffer&) = delete; + MementoRingBuffer& operator=(const MementoRingBuffer&) = delete; + MementoRingBuffer(MementoRingBuffer&&) = default; + MementoRingBuffer& operator=(MementoRingBuffer&&) = default; + // Rebuild this buffer with a new max_entries_ size. void Rebuild(uint32_t max_entries); @@ -109,10 +123,11 @@ class HPackTable { Memento PopOne(); // Lookup the entry at index, or return nullptr if none exists. - const Memento* Lookup(uint32_t index) const; + const Memento* Lookup(uint32_t index); + const Memento* Peek(uint32_t index) const; - void ForEach(absl::FunctionRef - f) const; + template + void ForEach(F f) const; uint32_t max_entries() const { return max_entries_; } uint32_t num_entries() const { return num_entries_; } @@ -126,11 +141,17 @@ class HPackTable { // Maximum number of entries we could possibly fit in the table, given // defined overheads. uint32_t max_entries_ = hpack_constants::kInitialTableEntries; + // Which index holds a timestamp (or kNoTimestamp if none do). + static constexpr uint32_t kNoTimestamp = + std::numeric_limits::max(); + uint32_t timestamp_index_ = kNoTimestamp; + // The timestamp associated with timestamp_entry_. + Timestamp timestamp_; std::vector entries_; }; - const Memento* LookupDynamic(uint32_t index) const { + const Memento* LookupDynamic(uint32_t index) { // Not static - find the value in the list of valid entries const uint32_t tbl_index = index - (hpack_constants::kLastStaticEntry + 1); return entries_.Lookup(tbl_index); diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index 5aac16542d..64f398807b 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -52,7 +52,6 @@ #include "src/core/ext/transport/chttp2/transport/hpack_parser.h" #include "src/core/ext/transport/chttp2/transport/http2_settings.h" #include "src/core/ext/transport/chttp2/transport/legacy_frame.h" -#include "src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.h" #include "src/core/ext/transport/chttp2/transport/ping_abuse_policy.h" #include "src/core/ext/transport/chttp2/transport/ping_callbacks.h" #include "src/core/ext/transport/chttp2/transport/ping_rate_policy.h" @@ -383,8 +382,6 @@ struct grpc_chttp2_transport final : public grpc_core::FilterStackTransport, grpc_event_engine::experimental::EventEngine::TaskHandle::kInvalid; grpc_closure retry_initiate_ping_locked; - grpc_core::Chttp2MaxConcurrentStreamsPolicy max_concurrent_streams_policy; - /// ping acks size_t ping_ack_count = 0; size_t ping_ack_capacity = 0; diff --git a/src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.cc b/src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.cc deleted file mode 100644 index 355e40898a..0000000000 --- a/src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.cc +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2023 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/ext/transport/chttp2/transport/max_concurrent_streams_policy.h" - -#include - -#include "absl/log/check.h" - -#include -#include - -namespace grpc_core { - -void Chttp2MaxConcurrentStreamsPolicy::AddDemerit() { - ++new_demerits_; - ++unacked_demerits_; -} - -void Chttp2MaxConcurrentStreamsPolicy::FlushedSettings() { - sent_demerits_ += std::exchange(new_demerits_, 0); -} - -void Chttp2MaxConcurrentStreamsPolicy::AckLastSend() { - CHECK(unacked_demerits_ >= sent_demerits_); - unacked_demerits_ -= std::exchange(sent_demerits_, 0); -} - -uint32_t Chttp2MaxConcurrentStreamsPolicy::AdvertiseValue() const { - if (target_ < unacked_demerits_) return 0; - return target_ - unacked_demerits_; -} - -} // namespace grpc_core diff --git a/src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.h b/src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.h deleted file mode 100644 index a2a56d2bfe..0000000000 --- a/src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.h +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2023 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_EXT_TRANSPORT_CHTTP2_TRANSPORT_MAX_CONCURRENT_STREAMS_POLICY_H -#define GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_MAX_CONCURRENT_STREAMS_POLICY_H - -#include -#include - -#include - -namespace grpc_core { - -class Chttp2MaxConcurrentStreamsPolicy { - public: - // Set the target number of concurrent streams. - // If everything is idle we should advertise this number. - void SetTarget(uint32_t target) { target_ = target; } - - // Add one demerit to the current target. - // We need to do one full settings round trip after this to clear this - // demerit. - // It will reduce our advertised max concurrent streams by one. - void AddDemerit(); - - // Notify the policy that we've sent a settings frame. - // Newly added demerits since the last settings frame was sent will be cleared - // once that settings frame is acknowledged. - void FlushedSettings(); - - // Notify the policy that we've received an acknowledgement for the last - // settings frame we sent. - void AckLastSend(); - - // Returns what we should advertise as max concurrent streams. - uint32_t AdvertiseValue() const; - - private: - uint32_t target_ = std::numeric_limits::max(); - // Demerit flow: - // When we add a demerit, we add to both new & unacked. - // When we flush settings, we move new to sent. - // When we ack settings, we remove what we sent from unacked. - // eg: - // we add 10 demerits - now new=10, sent=0, unacked=10 - // we send settings - now new=0, sent=10, unacked=10 - // we add 5 demerits - now new=5, sent=10, unacked=15 - // we get the settings ack - now new=5, sent=0, unacked=5 - uint32_t new_demerits_ = 0; - uint32_t sent_demerits_ = 0; - uint32_t unacked_demerits_ = 0; -}; - -} // namespace grpc_core - -#endif // GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_MAX_CONCURRENT_STREAMS_POLICY_H diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index 8eefef09ec..d8c1680c3b 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -55,7 +55,6 @@ #include "src/core/ext/transport/chttp2/transport/http2_settings.h" #include "src/core/ext/transport/chttp2/transport/internal.h" #include "src/core/ext/transport/chttp2/transport/legacy_frame.h" -#include "src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.h" #include "src/core/ext/transport/chttp2/transport/ping_rate_policy.h" #include "src/core/lib/backoff/random_early_detection.h" #include "src/core/lib/debug/trace.h" @@ -332,13 +331,11 @@ absl::variant grpc_chttp2_perform_read( case GRPC_DTS_FH_8: DCHECK_LT(cur, end); t->incoming_stream_id |= (static_cast(*cur)); - if (GRPC_TRACE_FLAG_ENABLED(http)) { - LOG(INFO) << "INCOMING[" << t << "]: " - << FrameTypeString(t->incoming_frame_type, - t->incoming_frame_flags) - << " len:" << t->incoming_frame_size - << absl::StrFormat(" id:0x%08x", t->incoming_stream_id); - } + GRPC_TRACE_LOG(http, INFO) + << "INCOMING[" << t << "]: " + << FrameTypeString(t->incoming_frame_type, t->incoming_frame_flags) + << " len:" << t->incoming_frame_size + << absl::StrFormat(" id:0x%08x", t->incoming_stream_id); t->deframe_state = GRPC_DTS_FRAME; err = init_frame_parser(t, requests_started); if (!err.ok()) { @@ -454,10 +451,9 @@ static grpc_error_handle init_frame_parser(grpc_chttp2_transport* t, case GRPC_CHTTP2_FRAME_GOAWAY: return init_goaway_parser(t); default: - if (GRPC_TRACE_FLAG_ENABLED(http)) { - LOG(ERROR) << "Unknown frame type " - << absl::StrFormat("%02x", t->incoming_frame_type); - } + GRPC_TRACE_LOG(http, ERROR) + << "Unknown frame type " + << absl::StrFormat("%02x", t->incoming_frame_type); return init_non_header_skip_frame_parser(t); } } @@ -650,7 +646,7 @@ static grpc_error_handle init_header_frame_parser(grpc_chttp2_transport* t, } else if (GPR_UNLIKELY( t->max_concurrent_streams_overload_protection && t->streams_allocated.load(std::memory_order_relaxed) > - t->max_concurrent_streams_policy.AdvertiseValue())) { + t->settings.local().max_concurrent_streams())) { // We have more streams allocated than we'd like, so apply some pushback // by refusing this stream. ++t->num_pending_induced_frames; @@ -659,13 +655,12 @@ static grpc_error_handle init_header_frame_parser(grpc_chttp2_transport* t, GRPC_HTTP2_REFUSED_STREAM, nullptr)); grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_RST_STREAM); return init_header_skip_frame_parser(t, priority_type, is_eoh); - } else if (GPR_UNLIKELY( - t->stream_map.size() >= - t->max_concurrent_streams_policy.AdvertiseValue() && - grpc_core::RandomEarlyDetection( - t->max_concurrent_streams_policy.AdvertiseValue(), - t->settings.acked().max_concurrent_streams()) - .Reject(t->stream_map.size(), t->bitgen))) { + } else if (GPR_UNLIKELY(t->stream_map.size() >= + t->settings.local().max_concurrent_streams() && + grpc_core::RandomEarlyDetection( + t->settings.local().max_concurrent_streams(), + t->settings.acked().max_concurrent_streams()) + .Reject(t->stream_map.size(), t->bitgen))) { // We are under the limit of max concurrent streams for the current // setting, but are over the next value that will be advertised. // Apply some backpressure by randomly not accepting new streams. @@ -792,10 +787,8 @@ static grpc_error_handle init_window_update_frame_parser( grpc_chttp2_stream* s = t->incoming_stream = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); if (s == nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(http)) { - LOG(ERROR) << "Stream " << t->incoming_stream_id - << " not found, ignoring WINDOW_UPDATE"; - } + GRPC_TRACE_LOG(http, ERROR) << "Stream " << t->incoming_stream_id + << " not found, ignoring WINDOW_UPDATE"; return init_non_header_skip_frame_parser(t); } s->call_tracer_wrapper.RecordIncomingBytes({9, 0, 0}); @@ -827,9 +820,6 @@ static grpc_error_handle init_rst_stream_parser(grpc_chttp2_transport* t) { s->call_tracer_wrapper.RecordIncomingBytes({9, 0, 0}); t->parser = grpc_chttp2_transport::Parser{ "rst_stream", grpc_chttp2_rst_stream_parser_parse, &t->simple.rst_stream}; - if (!t->is_client && grpc_core::IsRstpitEnabled()) { - t->max_concurrent_streams_policy.AddDemerit(); - } return absl::OkStatus(); } @@ -854,7 +844,6 @@ static grpc_error_handle init_settings_frame_parser(grpc_chttp2_transport* t) { return err; } if (t->incoming_frame_flags & GRPC_CHTTP2_FLAG_ACK) { - t->max_concurrent_streams_policy.AckLastSend(); if (!t->settings.AckLastSend()) { return GRPC_ERROR_CREATE("Received unexpected settings ack"); } @@ -894,10 +883,8 @@ static grpc_error_handle parse_frame_slice(grpc_chttp2_transport* t, if (GPR_LIKELY(err.ok())) { return err; } - if (GRPC_TRACE_FLAG_ENABLED(http)) { - LOG(ERROR) << "INCOMING[" << t << ";" << s << "]: Parse failed with " - << err; - } + GRPC_TRACE_LOG(http, ERROR) + << "INCOMING[" << t << ";" << s << "]: Parse failed with " << err; if (grpc_error_get_int(err, grpc_core::StatusIntProperty::kStreamId, &unused)) { grpc_chttp2_parsing_become_skip_parser(t); diff --git a/src/core/ext/transport/chttp2/transport/ping_callbacks.cc b/src/core/ext/transport/chttp2/transport/ping_callbacks.cc index b568ad860a..4bd16e1fbb 100644 --- a/src/core/ext/transport/chttp2/transport/ping_callbacks.cc +++ b/src/core/ext/transport/chttp2/transport/ping_callbacks.cc @@ -20,7 +20,6 @@ #include "absl/meta/type_traits.h" #include "absl/random/distributions.h" -#include #include namespace grpc_core { diff --git a/src/core/ext/transport/chttp2/transport/stream_lists.cc b/src/core/ext/transport/chttp2/transport/stream_lists.cc index 2466f95026..f2ac00e957 100644 --- a/src/core/ext/transport/chttp2/transport/stream_lists.cc +++ b/src/core/ext/transport/chttp2/transport/stream_lists.cc @@ -90,10 +90,9 @@ static void stream_list_remove(grpc_chttp2_transport* t, grpc_chttp2_stream* s, } else { t->lists[id].tail = s->links[id].prev; } - if (GRPC_TRACE_FLAG_ENABLED(http2_stream_state)) { - LOG(INFO) << t << "[" << s->id << "][" << (t->is_client ? "cli" : "svr") - << "]: remove from " << stream_list_id_string(id); - } + GRPC_TRACE_LOG(http2_stream_state, INFO) + << t << "[" << s->id << "][" << (t->is_client ? "cli" : "svr") + << "]: remove from " << stream_list_id_string(id); } static bool stream_list_maybe_remove(grpc_chttp2_transport* t, @@ -122,10 +121,9 @@ static void stream_list_add_tail(grpc_chttp2_transport* t, } t->lists[id].tail = s; s->included.set(id); - if (GRPC_TRACE_FLAG_ENABLED(http2_stream_state)) { - LOG(INFO) << t << "[" << s->id << "][" << (t->is_client ? "cli" : "svr") - << "]: add to " << stream_list_id_string(id); - } + GRPC_TRACE_LOG(http2_stream_state, INFO) + << t << "[" << s->id << "][" << (t->is_client ? "cli" : "svr") + << "]: add to " << stream_list_id_string(id); } static bool stream_list_add(grpc_chttp2_transport* t, grpc_chttp2_stream* s, diff --git a/src/core/ext/transport/chttp2/transport/varint.h b/src/core/ext/transport/chttp2/transport/varint.h index c02d5d1031..3dcf32aa60 100644 --- a/src/core/ext/transport/chttp2/transport/varint.h +++ b/src/core/ext/transport/chttp2/transport/varint.h @@ -24,7 +24,6 @@ #include "absl/log/check.h" -#include #include // Helpers for hpack varint encoding diff --git a/src/core/ext/transport/chttp2/transport/write_size_policy.cc b/src/core/ext/transport/chttp2/transport/write_size_policy.cc index f8ec481d7f..63e8d2b7e2 100644 --- a/src/core/ext/transport/chttp2/transport/write_size_policy.cc +++ b/src/core/ext/transport/chttp2/transport/write_size_policy.cc @@ -18,7 +18,6 @@ #include "absl/log/check.h" -#include #include namespace grpc_core { diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index 1095bfc2c4..29c3b67e82 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -49,7 +49,6 @@ #include "src/core/ext/transport/chttp2/transport/http2_settings.h" #include "src/core/ext/transport/chttp2/transport/internal.h" #include "src/core/ext/transport/chttp2/transport/legacy_frame.h" -#include "src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.h" #include "src/core/ext/transport/chttp2/transport/ping_callbacks.h" #include "src/core/ext/transport/chttp2/transport/ping_rate_policy.h" #include "src/core/ext/transport/chttp2/transport/write_size_policy.h" @@ -205,24 +204,21 @@ static bool update_list(grpc_chttp2_transport* t, int64_t send_bytes, static void report_stall(grpc_chttp2_transport* t, grpc_chttp2_stream* s, const char* staller) { - if (GRPC_TRACE_FLAG_ENABLED(flowctl)) { - VLOG(2) << t->peer_string.as_string_view() << ":" << t << " stream " - << s->id << " moved to stalled list by " << staller - << ". This is FULLY expected to happen in a healthy program that " - "is not seeing flow control stalls. However, if you know that " - "there are unwanted stalls, here is some helpful data: " - "[fc:pending=" - << s->flow_controlled_buffer.length - << ":flowed=" << s->flow_controlled_bytes_flowed - << ":peer_initwin=" << t->settings.acked().initial_window_size() - << ":t_win=" << t->flow_control.remote_window() << ":s_win=" - << static_cast( - std::max(int64_t{0}, - s->flow_control.remote_window_delta() + - static_cast( - t->settings.peer().initial_window_size()))) - << ":s_delta=" << s->flow_control.remote_window_delta() << "]"; - } + GRPC_TRACE_VLOG(flowctl, 2) + << t->peer_string.as_string_view() << ":" << t << " stream " << s->id + << " moved to stalled list by " << staller + << ". This is FULLY expected to happen in a healthy program that is not " + "seeing flow control stalls. However, if you know that there are " + "unwanted stalls, here is some helpful data: [fc:pending=" + << s->flow_controlled_buffer.length + << ":flowed=" << s->flow_controlled_bytes_flowed + << ":peer_initwin=" << t->settings.acked().initial_window_size() + << ":t_win=" << t->flow_control.remote_window() << ":s_win=" + << static_cast(std::max( + int64_t{0}, s->flow_control.remote_window_delta() + + static_cast( + t->settings.peer().initial_window_size()))) + << ":s_delta=" << s->flow_control.remote_window_delta() << "]"; } namespace { @@ -260,8 +256,6 @@ class WriteContext { } void FlushSettings() { - t_->settings.mutable_local().SetMaxConcurrentStreams( - t_->max_concurrent_streams_policy.AdvertiseValue()); auto update = t_->settings.MaybeSendUpdate(); if (update.has_value()) { grpc_core::Http2Frame frame(std::move(*update)); @@ -280,7 +274,6 @@ class WriteContext { }); } t_->flow_control.FlushedSettings(); - t_->max_concurrent_streams_policy.FlushedSettings(); grpc_core::global_stats().IncrementHttp2SettingsWrites(); } } diff --git a/src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb.h b/src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb.h new file mode 100644 index 0000000000..d98d03a9c1 --- /dev/null +++ b/src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb.h @@ -0,0 +1,431 @@ +/* This file was generated by upb_generator from the input file: + * + * envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. */ + +#ifndef ENVOY_EXTENSIONS_FILTERS_HTTP_GCP_AUTHN_V3_GCP_AUTHN_PROTO_UPB_H_ +#define ENVOY_EXTENSIONS_FILTERS_HTTP_GCP_AUTHN_V3_GCP_AUTHN_PROTO_UPB_H_ + +#include "upb/generated_code_support.h" + +#include "envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.h" + +#include "envoy/config/core/v3/base.upb_minitable.h" +#include "envoy/config/core/v3/http_uri.upb_minitable.h" +#include "google/protobuf/duration.upb_minitable.h" +#include "google/protobuf/wrappers.upb_minitable.h" +#include "envoy/annotations/deprecation.upb_minitable.h" +#include "udpa/annotations/status.upb_minitable.h" +#include "validate/validate.upb_minitable.h" + +// Must be last. +#include "upb/port/def.inc" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig { upb_Message UPB_PRIVATE(base); } envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig; +typedef struct envoy_extensions_filters_http_gcp_authn_v3_Audience { upb_Message UPB_PRIVATE(base); } envoy_extensions_filters_http_gcp_authn_v3_Audience; +typedef struct envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig { upb_Message UPB_PRIVATE(base); } envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig; +typedef struct envoy_extensions_filters_http_gcp_authn_v3_TokenHeader { upb_Message UPB_PRIVATE(base); } envoy_extensions_filters_http_gcp_authn_v3_TokenHeader; +struct envoy_config_core_v3_HttpUri; +struct envoy_config_core_v3_RetryPolicy; +struct google_protobuf_Duration; +struct google_protobuf_UInt64Value; + + + +/* envoy.extensions.filters.http.gcp_authn.v3.GcpAuthnFilterConfig */ + +UPB_INLINE envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_new(upb_Arena* arena) { + return (envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig*)_upb_Message_New(&envoy__extensions__filters__http__gcp_0authn__v3__GcpAuthnFilterConfig_msg_init, arena); +} +UPB_INLINE envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_parse(const char* buf, size_t size, upb_Arena* arena) { + envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* ret = envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_new(arena); + if (!ret) return NULL; + if (upb_Decode(buf, size, UPB_UPCAST(ret), &envoy__extensions__filters__http__gcp_0authn__v3__GcpAuthnFilterConfig_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { + return NULL; + } + return ret; +} +UPB_INLINE envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* ret = envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_new(arena); + if (!ret) return NULL; + if (upb_Decode(buf, size, UPB_UPCAST(ret), &envoy__extensions__filters__http__gcp_0authn__v3__GcpAuthnFilterConfig_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } + return ret; +} +UPB_INLINE char* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_serialize(const envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg, upb_Arena* arena, size_t* len) { + char* ptr; + (void)upb_Encode(UPB_UPCAST(msg), &envoy__extensions__filters__http__gcp_0authn__v3__GcpAuthnFilterConfig_msg_init, 0, arena, &ptr, len); + return ptr; +} +UPB_INLINE char* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_serialize_ex(const envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg, int options, + upb_Arena* arena, size_t* len) { + char* ptr; + (void)upb_Encode(UPB_UPCAST(msg), &envoy__extensions__filters__http__gcp_0authn__v3__GcpAuthnFilterConfig_msg_init, options, arena, &ptr, len); + return ptr; +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_clear_http_uri(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); +} +UPB_INLINE const struct envoy_config_core_v3_HttpUri* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_http_uri(const envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const struct envoy_config_core_v3_HttpUri* default_val = NULL; + const struct envoy_config_core_v3_HttpUri* ret; + const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); + return ret; +} +UPB_INLINE bool envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_has_http_uri(const envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_clear_retry_policy(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const upb_MiniTableField field = {2, UPB_SIZE(16, 24), 65, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); +} +UPB_INLINE const struct envoy_config_core_v3_RetryPolicy* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_retry_policy(const envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const struct envoy_config_core_v3_RetryPolicy* default_val = NULL; + const struct envoy_config_core_v3_RetryPolicy* ret; + const upb_MiniTableField field = {2, UPB_SIZE(16, 24), 65, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); + return ret; +} +UPB_INLINE bool envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_has_retry_policy(const envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const upb_MiniTableField field = {2, UPB_SIZE(16, 24), 65, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_clear_cache_config(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 66, 2, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); +} +UPB_INLINE const envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_cache_config(const envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* default_val = NULL; + const envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* ret; + const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 66, 2, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); + return ret; +} +UPB_INLINE bool envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_has_cache_config(const envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 66, 2, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_clear_token_header(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 67, 3, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); +} +UPB_INLINE const envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_token_header(const envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* default_val = NULL; + const envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* ret; + const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 67, 3, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); + return ret; +} +UPB_INLINE bool envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_has_token_header(const envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 67, 3, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_clear_cluster(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const upb_MiniTableField field = {5, UPB_SIZE(32, 48), 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); +} +UPB_INLINE upb_StringView envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_cluster(const envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + upb_StringView default_val = upb_StringView_FromString(""); + upb_StringView ret; + const upb_MiniTableField field = {5, UPB_SIZE(32, 48), 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); + return ret; +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_clear_timeout(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const upb_MiniTableField field = {6, UPB_SIZE(28, 64), 68, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); +} +UPB_INLINE const struct google_protobuf_Duration* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_timeout(const envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const struct google_protobuf_Duration* default_val = NULL; + const struct google_protobuf_Duration* ret; + const upb_MiniTableField field = {6, UPB_SIZE(28, 64), 68, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); + return ret; +} +UPB_INLINE bool envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_has_timeout(const envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg) { + const upb_MiniTableField field = {6, UPB_SIZE(28, 64), 68, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); +} + +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_set_http_uri(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig *msg, struct envoy_config_core_v3_HttpUri* value) { + const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_Message_SetBaseField((upb_Message *)msg, &field, &value); +} +UPB_INLINE struct envoy_config_core_v3_HttpUri* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_mutable_http_uri(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg, upb_Arena* arena) { + struct envoy_config_core_v3_HttpUri* sub = (struct envoy_config_core_v3_HttpUri*)envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_http_uri(msg); + if (sub == NULL) { + sub = (struct envoy_config_core_v3_HttpUri*)_upb_Message_New(&envoy__config__core__v3__HttpUri_msg_init, arena); + if (sub) envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_set_http_uri(msg, sub); + } + return sub; +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_set_retry_policy(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig *msg, struct envoy_config_core_v3_RetryPolicy* value) { + const upb_MiniTableField field = {2, UPB_SIZE(16, 24), 65, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_Message_SetBaseField((upb_Message *)msg, &field, &value); +} +UPB_INLINE struct envoy_config_core_v3_RetryPolicy* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_mutable_retry_policy(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg, upb_Arena* arena) { + struct envoy_config_core_v3_RetryPolicy* sub = (struct envoy_config_core_v3_RetryPolicy*)envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_retry_policy(msg); + if (sub == NULL) { + sub = (struct envoy_config_core_v3_RetryPolicy*)_upb_Message_New(&envoy__config__core__v3__RetryPolicy_msg_init, arena); + if (sub) envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_set_retry_policy(msg, sub); + } + return sub; +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_set_cache_config(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig *msg, envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* value) { + const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 66, 2, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_Message_SetBaseField((upb_Message *)msg, &field, &value); +} +UPB_INLINE struct envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_mutable_cache_config(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg, upb_Arena* arena) { + struct envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* sub = (struct envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig*)envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_cache_config(msg); + if (sub == NULL) { + sub = (struct envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig*)_upb_Message_New(&envoy__extensions__filters__http__gcp_0authn__v3__TokenCacheConfig_msg_init, arena); + if (sub) envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_set_cache_config(msg, sub); + } + return sub; +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_set_token_header(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig *msg, envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* value) { + const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 67, 3, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_Message_SetBaseField((upb_Message *)msg, &field, &value); +} +UPB_INLINE struct envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_mutable_token_header(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg, upb_Arena* arena) { + struct envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* sub = (struct envoy_extensions_filters_http_gcp_authn_v3_TokenHeader*)envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_token_header(msg); + if (sub == NULL) { + sub = (struct envoy_extensions_filters_http_gcp_authn_v3_TokenHeader*)_upb_Message_New(&envoy__extensions__filters__http__gcp_0authn__v3__TokenHeader_msg_init, arena); + if (sub) envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_set_token_header(msg, sub); + } + return sub; +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_set_cluster(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig *msg, upb_StringView value) { + const upb_MiniTableField field = {5, UPB_SIZE(32, 48), 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + upb_Message_SetBaseField((upb_Message *)msg, &field, &value); +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_set_timeout(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig *msg, struct google_protobuf_Duration* value) { + const upb_MiniTableField field = {6, UPB_SIZE(28, 64), 68, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_Message_SetBaseField((upb_Message *)msg, &field, &value); +} +UPB_INLINE struct google_protobuf_Duration* envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_mutable_timeout(envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig* msg, upb_Arena* arena) { + struct google_protobuf_Duration* sub = (struct google_protobuf_Duration*)envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_timeout(msg); + if (sub == NULL) { + sub = (struct google_protobuf_Duration*)_upb_Message_New(&google__protobuf__Duration_msg_init, arena); + if (sub) envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_set_timeout(msg, sub); + } + return sub; +} + +/* envoy.extensions.filters.http.gcp_authn.v3.Audience */ + +UPB_INLINE envoy_extensions_filters_http_gcp_authn_v3_Audience* envoy_extensions_filters_http_gcp_authn_v3_Audience_new(upb_Arena* arena) { + return (envoy_extensions_filters_http_gcp_authn_v3_Audience*)_upb_Message_New(&envoy__extensions__filters__http__gcp_0authn__v3__Audience_msg_init, arena); +} +UPB_INLINE envoy_extensions_filters_http_gcp_authn_v3_Audience* envoy_extensions_filters_http_gcp_authn_v3_Audience_parse(const char* buf, size_t size, upb_Arena* arena) { + envoy_extensions_filters_http_gcp_authn_v3_Audience* ret = envoy_extensions_filters_http_gcp_authn_v3_Audience_new(arena); + if (!ret) return NULL; + if (upb_Decode(buf, size, UPB_UPCAST(ret), &envoy__extensions__filters__http__gcp_0authn__v3__Audience_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { + return NULL; + } + return ret; +} +UPB_INLINE envoy_extensions_filters_http_gcp_authn_v3_Audience* envoy_extensions_filters_http_gcp_authn_v3_Audience_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + envoy_extensions_filters_http_gcp_authn_v3_Audience* ret = envoy_extensions_filters_http_gcp_authn_v3_Audience_new(arena); + if (!ret) return NULL; + if (upb_Decode(buf, size, UPB_UPCAST(ret), &envoy__extensions__filters__http__gcp_0authn__v3__Audience_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } + return ret; +} +UPB_INLINE char* envoy_extensions_filters_http_gcp_authn_v3_Audience_serialize(const envoy_extensions_filters_http_gcp_authn_v3_Audience* msg, upb_Arena* arena, size_t* len) { + char* ptr; + (void)upb_Encode(UPB_UPCAST(msg), &envoy__extensions__filters__http__gcp_0authn__v3__Audience_msg_init, 0, arena, &ptr, len); + return ptr; +} +UPB_INLINE char* envoy_extensions_filters_http_gcp_authn_v3_Audience_serialize_ex(const envoy_extensions_filters_http_gcp_authn_v3_Audience* msg, int options, + upb_Arena* arena, size_t* len) { + char* ptr; + (void)upb_Encode(UPB_UPCAST(msg), &envoy__extensions__filters__http__gcp_0authn__v3__Audience_msg_init, options, arena, &ptr, len); + return ptr; +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_Audience_clear_url(envoy_extensions_filters_http_gcp_authn_v3_Audience* msg) { + const upb_MiniTableField field = {1, 8, 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); +} +UPB_INLINE upb_StringView envoy_extensions_filters_http_gcp_authn_v3_Audience_url(const envoy_extensions_filters_http_gcp_authn_v3_Audience* msg) { + upb_StringView default_val = upb_StringView_FromString(""); + upb_StringView ret; + const upb_MiniTableField field = {1, 8, 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); + return ret; +} + +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_Audience_set_url(envoy_extensions_filters_http_gcp_authn_v3_Audience *msg, upb_StringView value) { + const upb_MiniTableField field = {1, 8, 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + upb_Message_SetBaseField((upb_Message *)msg, &field, &value); +} + +/* envoy.extensions.filters.http.gcp_authn.v3.TokenCacheConfig */ + +UPB_INLINE envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_new(upb_Arena* arena) { + return (envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig*)_upb_Message_New(&envoy__extensions__filters__http__gcp_0authn__v3__TokenCacheConfig_msg_init, arena); +} +UPB_INLINE envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_parse(const char* buf, size_t size, upb_Arena* arena) { + envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* ret = envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_new(arena); + if (!ret) return NULL; + if (upb_Decode(buf, size, UPB_UPCAST(ret), &envoy__extensions__filters__http__gcp_0authn__v3__TokenCacheConfig_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { + return NULL; + } + return ret; +} +UPB_INLINE envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* ret = envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_new(arena); + if (!ret) return NULL; + if (upb_Decode(buf, size, UPB_UPCAST(ret), &envoy__extensions__filters__http__gcp_0authn__v3__TokenCacheConfig_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } + return ret; +} +UPB_INLINE char* envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_serialize(const envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* msg, upb_Arena* arena, size_t* len) { + char* ptr; + (void)upb_Encode(UPB_UPCAST(msg), &envoy__extensions__filters__http__gcp_0authn__v3__TokenCacheConfig_msg_init, 0, arena, &ptr, len); + return ptr; +} +UPB_INLINE char* envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_serialize_ex(const envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* msg, int options, + upb_Arena* arena, size_t* len) { + char* ptr; + (void)upb_Encode(UPB_UPCAST(msg), &envoy__extensions__filters__http__gcp_0authn__v3__TokenCacheConfig_msg_init, options, arena, &ptr, len); + return ptr; +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_clear_cache_size(envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* msg) { + const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); +} +UPB_INLINE const struct google_protobuf_UInt64Value* envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_cache_size(const envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* msg) { + const struct google_protobuf_UInt64Value* default_val = NULL; + const struct google_protobuf_UInt64Value* ret; + const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); + return ret; +} +UPB_INLINE bool envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_has_cache_size(const envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* msg) { + const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); +} + +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_set_cache_size(envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig *msg, struct google_protobuf_UInt64Value* value) { + const upb_MiniTableField field = {1, UPB_SIZE(12, 16), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_Message_SetBaseField((upb_Message *)msg, &field, &value); +} +UPB_INLINE struct google_protobuf_UInt64Value* envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_mutable_cache_size(envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig* msg, upb_Arena* arena) { + struct google_protobuf_UInt64Value* sub = (struct google_protobuf_UInt64Value*)envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_cache_size(msg); + if (sub == NULL) { + sub = (struct google_protobuf_UInt64Value*)_upb_Message_New(&google__protobuf__UInt64Value_msg_init, arena); + if (sub) envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_set_cache_size(msg, sub); + } + return sub; +} + +/* envoy.extensions.filters.http.gcp_authn.v3.TokenHeader */ + +UPB_INLINE envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* envoy_extensions_filters_http_gcp_authn_v3_TokenHeader_new(upb_Arena* arena) { + return (envoy_extensions_filters_http_gcp_authn_v3_TokenHeader*)_upb_Message_New(&envoy__extensions__filters__http__gcp_0authn__v3__TokenHeader_msg_init, arena); +} +UPB_INLINE envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* envoy_extensions_filters_http_gcp_authn_v3_TokenHeader_parse(const char* buf, size_t size, upb_Arena* arena) { + envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* ret = envoy_extensions_filters_http_gcp_authn_v3_TokenHeader_new(arena); + if (!ret) return NULL; + if (upb_Decode(buf, size, UPB_UPCAST(ret), &envoy__extensions__filters__http__gcp_0authn__v3__TokenHeader_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { + return NULL; + } + return ret; +} +UPB_INLINE envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* envoy_extensions_filters_http_gcp_authn_v3_TokenHeader_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* ret = envoy_extensions_filters_http_gcp_authn_v3_TokenHeader_new(arena); + if (!ret) return NULL; + if (upb_Decode(buf, size, UPB_UPCAST(ret), &envoy__extensions__filters__http__gcp_0authn__v3__TokenHeader_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } + return ret; +} +UPB_INLINE char* envoy_extensions_filters_http_gcp_authn_v3_TokenHeader_serialize(const envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* msg, upb_Arena* arena, size_t* len) { + char* ptr; + (void)upb_Encode(UPB_UPCAST(msg), &envoy__extensions__filters__http__gcp_0authn__v3__TokenHeader_msg_init, 0, arena, &ptr, len); + return ptr; +} +UPB_INLINE char* envoy_extensions_filters_http_gcp_authn_v3_TokenHeader_serialize_ex(const envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* msg, int options, + upb_Arena* arena, size_t* len) { + char* ptr; + (void)upb_Encode(UPB_UPCAST(msg), &envoy__extensions__filters__http__gcp_0authn__v3__TokenHeader_msg_init, options, arena, &ptr, len); + return ptr; +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_TokenHeader_clear_name(envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* msg) { + const upb_MiniTableField field = {1, 8, 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); +} +UPB_INLINE upb_StringView envoy_extensions_filters_http_gcp_authn_v3_TokenHeader_name(const envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* msg) { + upb_StringView default_val = upb_StringView_FromString(""); + upb_StringView ret; + const upb_MiniTableField field = {1, 8, 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); + return ret; +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_TokenHeader_clear_value_prefix(envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* msg) { + const upb_MiniTableField field = {2, UPB_SIZE(16, 24), 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); +} +UPB_INLINE upb_StringView envoy_extensions_filters_http_gcp_authn_v3_TokenHeader_value_prefix(const envoy_extensions_filters_http_gcp_authn_v3_TokenHeader* msg) { + upb_StringView default_val = upb_StringView_FromString(""); + upb_StringView ret; + const upb_MiniTableField field = {2, UPB_SIZE(16, 24), 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); + return ret; +} + +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_TokenHeader_set_name(envoy_extensions_filters_http_gcp_authn_v3_TokenHeader *msg, upb_StringView value) { + const upb_MiniTableField field = {1, 8, 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + upb_Message_SetBaseField((upb_Message *)msg, &field, &value); +} +UPB_INLINE void envoy_extensions_filters_http_gcp_authn_v3_TokenHeader_set_value_prefix(envoy_extensions_filters_http_gcp_authn_v3_TokenHeader *msg, upb_StringView value) { + const upb_MiniTableField field = {2, UPB_SIZE(16, 24), 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + upb_Message_SetBaseField((upb_Message *)msg, &field, &value); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#include "upb/port/undef.inc" + +#endif /* ENVOY_EXTENSIONS_FILTERS_HTTP_GCP_AUTHN_V3_GCP_AUTHN_PROTO_UPB_H_ */ diff --git a/src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.c b/src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.c new file mode 100644 index 0000000000..c81951d563 --- /dev/null +++ b/src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.c @@ -0,0 +1,129 @@ +/* This file was generated by upb_generator from the input file: + * + * envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. */ + +#include +#include "upb/generated_code_support.h" +#include "envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.h" +#include "envoy/config/core/v3/base.upb_minitable.h" +#include "envoy/config/core/v3/http_uri.upb_minitable.h" +#include "google/protobuf/duration.upb_minitable.h" +#include "google/protobuf/wrappers.upb_minitable.h" +#include "envoy/annotations/deprecation.upb_minitable.h" +#include "udpa/annotations/status.upb_minitable.h" +#include "validate/validate.upb_minitable.h" + +// Must be last. +#include "upb/port/def.inc" + +static const upb_MiniTableSub envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_submsgs[5] = { + {.UPB_PRIVATE(submsg) = &envoy__config__core__v3__HttpUri_msg_init}, + {.UPB_PRIVATE(submsg) = &envoy__config__core__v3__RetryPolicy_msg_init}, + {.UPB_PRIVATE(submsg) = &envoy__extensions__filters__http__gcp_0authn__v3__TokenCacheConfig_msg_init}, + {.UPB_PRIVATE(submsg) = &envoy__extensions__filters__http__gcp_0authn__v3__TokenHeader_msg_init}, + {.UPB_PRIVATE(submsg) = &google__protobuf__Duration_msg_init}, +}; + +static const upb_MiniTableField envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig__fields[6] = { + {1, UPB_SIZE(12, 16), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(16, 24), 65, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(20, 32), 66, 2, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(24, 40), 67, 3, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {5, UPB_SIZE(32, 48), 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {6, UPB_SIZE(28, 64), 68, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable envoy__extensions__filters__http__gcp_0authn__v3__GcpAuthnFilterConfig_msg_init = { + &envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_submsgs[0], + &envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig__fields[0], + UPB_SIZE(40, 72), 6, kUpb_ExtMode_NonExtendable, 6, UPB_FASTTABLE_MASK(56), 0, +#ifdef UPB_TRACING_ENABLED + "envoy.extensions.filters.http.gcp_authn.v3.GcpAuthnFilterConfig", +#endif + UPB_FASTTABLE_INIT({ + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x003000003f00002a, &upb_pss_1bt}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + }) +}; + +static const upb_MiniTableField envoy_extensions_filters_http_gcp_authn_v3_Audience__fields[1] = { + {1, 8, 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable envoy__extensions__filters__http__gcp_0authn__v3__Audience_msg_init = { + NULL, + &envoy_extensions_filters_http_gcp_authn_v3_Audience__fields[0], + UPB_SIZE(16, 24), 1, kUpb_ExtMode_NonExtendable, 1, UPB_FASTTABLE_MASK(8), 0, +#ifdef UPB_TRACING_ENABLED + "envoy.extensions.filters.http.gcp_authn.v3.Audience", +#endif + UPB_FASTTABLE_INIT({ + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x000800003f00000a, &upb_pss_1bt}, + }) +}; + +static const upb_MiniTableSub envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_submsgs[1] = { + {.UPB_PRIVATE(submsg) = &google__protobuf__UInt64Value_msg_init}, +}; + +static const upb_MiniTableField envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig__fields[1] = { + {1, UPB_SIZE(12, 16), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable envoy__extensions__filters__http__gcp_0authn__v3__TokenCacheConfig_msg_init = { + &envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_submsgs[0], + &envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig__fields[0], + UPB_SIZE(16, 24), 1, kUpb_ExtMode_NonExtendable, 1, UPB_FASTTABLE_MASK(255), 0, +#ifdef UPB_TRACING_ENABLED + "envoy.extensions.filters.http.gcp_authn.v3.TokenCacheConfig", +#endif +}; + +static const upb_MiniTableField envoy_extensions_filters_http_gcp_authn_v3_TokenHeader__fields[2] = { + {1, 8, 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(16, 24), 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable envoy__extensions__filters__http__gcp_0authn__v3__TokenHeader_msg_init = { + NULL, + &envoy_extensions_filters_http_gcp_authn_v3_TokenHeader__fields[0], + UPB_SIZE(24, 40), 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(24), 0, +#ifdef UPB_TRACING_ENABLED + "envoy.extensions.filters.http.gcp_authn.v3.TokenHeader", +#endif + UPB_FASTTABLE_INIT({ + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x000800003f00000a, &upb_pss_1bt}, + {0x001800003f000012, &upb_pss_1bt}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + }) +}; + +static const upb_MiniTable *messages_layout[4] = { + &envoy__extensions__filters__http__gcp_0authn__v3__GcpAuthnFilterConfig_msg_init, + &envoy__extensions__filters__http__gcp_0authn__v3__Audience_msg_init, + &envoy__extensions__filters__http__gcp_0authn__v3__TokenCacheConfig_msg_init, + &envoy__extensions__filters__http__gcp_0authn__v3__TokenHeader_msg_init, +}; + +const upb_MiniTableFile envoy_extensions_filters_http_gcp_authn_v3_gcp_authn_proto_upb_file_layout = { + messages_layout, + NULL, + NULL, + 4, + 0, + 0, +}; + +#include "upb/port/undef.inc" + diff --git a/src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.h b/src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.h new file mode 100644 index 0000000000..ae92576dbb --- /dev/null +++ b/src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.h @@ -0,0 +1,33 @@ +/* This file was generated by upb_generator from the input file: + * + * envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. */ + +#ifndef ENVOY_EXTENSIONS_FILTERS_HTTP_GCP_AUTHN_V3_GCP_AUTHN_PROTO_UPB_MINITABLE_H_ +#define ENVOY_EXTENSIONS_FILTERS_HTTP_GCP_AUTHN_V3_GCP_AUTHN_PROTO_UPB_MINITABLE_H_ + +#include "upb/generated_code_support.h" + +// Must be last. +#include "upb/port/def.inc" + +#ifdef __cplusplus +extern "C" { +#endif + +extern const upb_MiniTable envoy__extensions__filters__http__gcp_0authn__v3__GcpAuthnFilterConfig_msg_init; +extern const upb_MiniTable envoy__extensions__filters__http__gcp_0authn__v3__Audience_msg_init; +extern const upb_MiniTable envoy__extensions__filters__http__gcp_0authn__v3__TokenCacheConfig_msg_init; +extern const upb_MiniTable envoy__extensions__filters__http__gcp_0authn__v3__TokenHeader_msg_init; + +extern const upb_MiniTableFile envoy_extensions_filters_http_gcp_authn_v3_gcp_authn_proto_upb_file_layout; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#include "upb/port/undef.inc" + +#endif /* ENVOY_EXTENSIONS_FILTERS_HTTP_GCP_AUTHN_V3_GCP_AUTHN_PROTO_UPB_MINITABLE_H_ */ diff --git a/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.c b/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.c new file mode 100644 index 0000000000..46edcb75a2 --- /dev/null +++ b/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.c @@ -0,0 +1,86 @@ +/* This file was generated by upb_generator from the input file: + * + * envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. */ + +#include "upb/reflection/def.h" +#include "envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.h" +#include "envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.h" + +extern _upb_DefPool_Init envoy_config_core_v3_base_proto_upbdefinit; +extern _upb_DefPool_Init envoy_config_core_v3_http_uri_proto_upbdefinit; +extern _upb_DefPool_Init google_protobuf_duration_proto_upbdefinit; +extern _upb_DefPool_Init google_protobuf_wrappers_proto_upbdefinit; +extern _upb_DefPool_Init envoy_annotations_deprecation_proto_upbdefinit; +extern _upb_DefPool_Init udpa_annotations_status_proto_upbdefinit; +extern _upb_DefPool_Init validate_validate_proto_upbdefinit; +static const char descriptor[1207] = {'\n', ':', 'e', 'n', 'v', 'o', 'y', '/', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 's', '/', 'f', 'i', 'l', 't', 'e', 'r', +'s', '/', 'h', 't', 't', 'p', '/', 'g', 'c', 'p', '_', 'a', 'u', 't', 'h', 'n', '/', 'v', '3', '/', 'g', 'c', 'p', '_', 'a', +'u', 't', 'h', 'n', '.', 'p', 'r', 'o', 't', 'o', '\022', '*', 'e', 'n', 'v', 'o', 'y', '.', 'e', 'x', 't', 'e', 'n', 's', 'i', +'o', 'n', 's', '.', 'f', 'i', 'l', 't', 'e', 'r', 's', '.', 'h', 't', 't', 'p', '.', 'g', 'c', 'p', '_', 'a', 'u', 't', 'h', +'n', '.', 'v', '3', '\032', '\037', 'e', 'n', 'v', 'o', 'y', '/', 'c', 'o', 'n', 'f', 'i', 'g', '/', 'c', 'o', 'r', 'e', '/', 'v', +'3', '/', 'b', 'a', 's', 'e', '.', 'p', 'r', 'o', 't', 'o', '\032', '#', 'e', 'n', 'v', 'o', 'y', '/', 'c', 'o', 'n', 'f', 'i', +'g', '/', 'c', 'o', 'r', 'e', '/', 'v', '3', '/', 'h', 't', 't', 'p', '_', 'u', 'r', 'i', '.', 'p', 'r', 'o', 't', 'o', '\032', +'\036', 'g', 'o', 'o', 'g', 'l', 'e', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 'd', 'u', 'r', 'a', 't', 'i', 'o', 'n', +'.', 'p', 'r', 'o', 't', 'o', '\032', '\036', 'g', 'o', 'o', 'g', 'l', 'e', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 'w', +'r', 'a', 'p', 'p', 'e', 'r', 's', '.', 'p', 'r', 'o', 't', 'o', '\032', '#', 'e', 'n', 'v', 'o', 'y', '/', 'a', 'n', 'n', 'o', +'t', 'a', 't', 'i', 'o', 'n', 's', '/', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'i', 'o', 'n', '.', 'p', 'r', 'o', 't', 'o', +'\032', '\035', 'u', 'd', 'p', 'a', '/', 'a', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', 's', '/', 's', 't', 'a', 't', 'u', 's', +'.', 'p', 'r', 'o', 't', 'o', '\032', '\027', 'v', 'a', 'l', 'i', 'd', 'a', 't', 'e', '/', 'v', 'a', 'l', 'i', 'd', 'a', 't', 'e', +'.', 'p', 'r', 'o', 't', 'o', '\"', '\301', '\003', '\n', '\024', 'G', 'c', 'p', 'A', 'u', 't', 'h', 'n', 'F', 'i', 'l', 't', 'e', 'r', +'C', 'o', 'n', 'f', 'i', 'g', '\022', 'E', '\n', '\010', 'h', 't', 't', 'p', '_', 'u', 'r', 'i', '\030', '\001', ' ', '\001', '(', '\013', '2', +'\035', '.', 'e', 'n', 'v', 'o', 'y', '.', 'c', 'o', 'n', 'f', 'i', 'g', '.', 'c', 'o', 'r', 'e', '.', 'v', '3', '.', 'H', 't', +'t', 'p', 'U', 'r', 'i', 'B', '\013', '\030', '\001', '\222', '\307', '\206', '\330', '\004', '\003', '3', '.', '0', 'R', '\007', 'h', 't', 't', 'p', 'U', +'r', 'i', '\022', 'D', '\n', '\014', 'r', 'e', 't', 'r', 'y', '_', 'p', 'o', 'l', 'i', 'c', 'y', '\030', '\002', ' ', '\001', '(', '\013', '2', +'!', '.', 'e', 'n', 'v', 'o', 'y', '.', 'c', 'o', 'n', 'f', 'i', 'g', '.', 'c', 'o', 'r', 'e', '.', 'v', '3', '.', 'R', 'e', +'t', 'r', 'y', 'P', 'o', 'l', 'i', 'c', 'y', 'R', '\013', 'r', 'e', 't', 'r', 'y', 'P', 'o', 'l', 'i', 'c', 'y', '\022', '_', '\n', +'\014', 'c', 'a', 'c', 'h', 'e', '_', 'c', 'o', 'n', 'f', 'i', 'g', '\030', '\003', ' ', '\001', '(', '\013', '2', '<', '.', 'e', 'n', 'v', +'o', 'y', '.', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 's', '.', 'f', 'i', 'l', 't', 'e', 'r', 's', '.', 'h', 't', 't', +'p', '.', 'g', 'c', 'p', '_', 'a', 'u', 't', 'h', 'n', '.', 'v', '3', '.', 'T', 'o', 'k', 'e', 'n', 'C', 'a', 'c', 'h', 'e', +'C', 'o', 'n', 'f', 'i', 'g', 'R', '\013', 'c', 'a', 'c', 'h', 'e', 'C', 'o', 'n', 'f', 'i', 'g', '\022', 'Z', '\n', '\014', 't', 'o', +'k', 'e', 'n', '_', 'h', 'e', 'a', 'd', 'e', 'r', '\030', '\004', ' ', '\001', '(', '\013', '2', '7', '.', 'e', 'n', 'v', 'o', 'y', '.', +'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 's', '.', 'f', 'i', 'l', 't', 'e', 'r', 's', '.', 'h', 't', 't', 'p', '.', 'g', +'c', 'p', '_', 'a', 'u', 't', 'h', 'n', '.', 'v', '3', '.', 'T', 'o', 'k', 'e', 'n', 'H', 'e', 'a', 'd', 'e', 'r', 'R', '\013', +'t', 'o', 'k', 'e', 'n', 'H', 'e', 'a', 'd', 'e', 'r', '\022', '\030', '\n', '\007', 'c', 'l', 'u', 's', 't', 'e', 'r', '\030', '\005', ' ', +'\001', '(', '\t', 'R', '\007', 'c', 'l', 'u', 's', 't', 'e', 'r', '\022', 'E', '\n', '\007', 't', 'i', 'm', 'e', 'o', 'u', 't', '\030', '\006', +' ', '\001', '(', '\013', '2', '\031', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'D', 'u', +'r', 'a', 't', 'i', 'o', 'n', 'B', '\020', '\372', 'B', '\r', '\252', '\001', '\n', '\032', '\006', '\010', '\200', '\200', '\200', '\200', '\020', '2', '\000', 'R', +'\007', 't', 'i', 'm', 'e', 'o', 'u', 't', '\"', '%', '\n', '\010', 'A', 'u', 'd', 'i', 'e', 'n', 'c', 'e', '\022', '\031', '\n', '\003', 'u', +'r', 'l', '\030', '\001', ' ', '\001', '(', '\t', 'B', '\007', '\372', 'B', '\004', 'r', '\002', '\020', '\001', 'R', '\003', 'u', 'r', 'l', '\"', '`', '\n', +'\020', 'T', 'o', 'k', 'e', 'n', 'C', 'a', 'c', 'h', 'e', 'C', 'o', 'n', 'f', 'i', 'g', '\022', 'L', '\n', '\n', 'c', 'a', 'c', 'h', +'e', '_', 's', 'i', 'z', 'e', '\030', '\001', ' ', '\001', '(', '\013', '2', '\034', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', +'t', 'o', 'b', 'u', 'f', '.', 'U', 'I', 'n', 't', '6', '4', 'V', 'a', 'l', 'u', 'e', 'B', '\017', '\372', 'B', '\014', '2', '\n', '\030', +'\377', '\377', '\377', '\377', '\377', '\377', '\377', '\377', '\177', 'R', '\t', 'c', 'a', 'c', 'h', 'e', 'S', 'i', 'z', 'e', '\"', '`', '\n', '\013', 'T', +'o', 'k', 'e', 'n', 'H', 'e', 'a', 'd', 'e', 'r', '\022', '!', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'B', +'\r', '\372', 'B', '\n', 'r', '\010', '\020', '\001', '\300', '\001', '\001', '\310', '\001', '\000', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '.', '\n', '\014', 'v', +'a', 'l', 'u', 'e', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', '\002', ' ', '\001', '(', '\t', 'B', '\013', '\372', 'B', '\010', 'r', '\006', '\300', +'\001', '\002', '\310', '\001', '\000', 'R', '\013', 'v', 'a', 'l', 'u', 'e', 'P', 'r', 'e', 'f', 'i', 'x', 'B', '\262', '\001', '\n', '8', 'i', 'o', +'.', 'e', 'n', 'v', 'o', 'y', 'p', 'r', 'o', 'x', 'y', '.', 'e', 'n', 'v', 'o', 'y', '.', 'e', 'x', 't', 'e', 'n', 's', 'i', +'o', 'n', 's', '.', 'f', 'i', 'l', 't', 'e', 'r', 's', '.', 'h', 't', 't', 'p', '.', 'g', 'c', 'p', '_', 'a', 'u', 't', 'h', +'n', '.', 'v', '3', 'B', '\r', 'G', 'c', 'p', 'A', 'u', 't', 'h', 'n', 'P', 'r', 'o', 't', 'o', 'P', '\001', 'Z', ']', 'g', 'i', +'t', 'h', 'u', 'b', '.', 'c', 'o', 'm', '/', 'e', 'n', 'v', 'o', 'y', 'p', 'r', 'o', 'x', 'y', '/', 'g', 'o', '-', 'c', 'o', +'n', 't', 'r', 'o', 'l', '-', 'p', 'l', 'a', 'n', 'e', '/', 'e', 'n', 'v', 'o', 'y', '/', 'e', 'x', 't', 'e', 'n', 's', 'i', +'o', 'n', 's', '/', 'f', 'i', 'l', 't', 'e', 'r', 's', '/', 'h', 't', 't', 'p', '/', 'g', 'c', 'p', '_', 'a', 'u', 't', 'h', +'n', '/', 'v', '3', ';', 'g', 'c', 'p', '_', 'a', 'u', 't', 'h', 'n', 'v', '3', '\272', '\200', '\310', '\321', '\006', '\002', '\020', '\002', 'b', +'\006', 'p', 'r', 'o', 't', 'o', '3', +}; + +static _upb_DefPool_Init *deps[8] = { + &envoy_config_core_v3_base_proto_upbdefinit, + &envoy_config_core_v3_http_uri_proto_upbdefinit, + &google_protobuf_duration_proto_upbdefinit, + &google_protobuf_wrappers_proto_upbdefinit, + &envoy_annotations_deprecation_proto_upbdefinit, + &udpa_annotations_status_proto_upbdefinit, + &validate_validate_proto_upbdefinit, + NULL +}; + +_upb_DefPool_Init envoy_extensions_filters_http_gcp_authn_v3_gcp_authn_proto_upbdefinit = { + deps, + &envoy_extensions_filters_http_gcp_authn_v3_gcp_authn_proto_upb_file_layout, + "envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.proto", + UPB_STRINGVIEW_INIT(descriptor, 1207) +}; diff --git a/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.h b/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.h new file mode 100644 index 0000000000..54b22313e3 --- /dev/null +++ b/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.h @@ -0,0 +1,47 @@ +/* This file was generated by upb_generator from the input file: + * + * envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. */ + +#ifndef ENVOY_EXTENSIONS_FILTERS_HTTP_GCP_AUTHN_V3_GCP_AUTHN_PROTO_UPBDEFS_H_ +#define ENVOY_EXTENSIONS_FILTERS_HTTP_GCP_AUTHN_V3_GCP_AUTHN_PROTO_UPBDEFS_H_ + +#include "upb/reflection/def.h" +#include "upb/reflection/internal/def_pool.h" + +#include "upb/port/def.inc" // Must be last. +#ifdef __cplusplus +extern "C" { +#endif + +extern _upb_DefPool_Init envoy_extensions_filters_http_gcp_authn_v3_gcp_authn_proto_upbdefinit; + +UPB_INLINE const upb_MessageDef *envoy_extensions_filters_http_gcp_authn_v3_GcpAuthnFilterConfig_getmsgdef(upb_DefPool *s) { + _upb_DefPool_LoadDefInit(s, &envoy_extensions_filters_http_gcp_authn_v3_gcp_authn_proto_upbdefinit); + return upb_DefPool_FindMessageByName(s, "envoy.extensions.filters.http.gcp_authn.v3.GcpAuthnFilterConfig"); +} + +UPB_INLINE const upb_MessageDef *envoy_extensions_filters_http_gcp_authn_v3_Audience_getmsgdef(upb_DefPool *s) { + _upb_DefPool_LoadDefInit(s, &envoy_extensions_filters_http_gcp_authn_v3_gcp_authn_proto_upbdefinit); + return upb_DefPool_FindMessageByName(s, "envoy.extensions.filters.http.gcp_authn.v3.Audience"); +} + +UPB_INLINE const upb_MessageDef *envoy_extensions_filters_http_gcp_authn_v3_TokenCacheConfig_getmsgdef(upb_DefPool *s) { + _upb_DefPool_LoadDefInit(s, &envoy_extensions_filters_http_gcp_authn_v3_gcp_authn_proto_upbdefinit); + return upb_DefPool_FindMessageByName(s, "envoy.extensions.filters.http.gcp_authn.v3.TokenCacheConfig"); +} + +UPB_INLINE const upb_MessageDef *envoy_extensions_filters_http_gcp_authn_v3_TokenHeader_getmsgdef(upb_DefPool *s) { + _upb_DefPool_LoadDefInit(s, &envoy_extensions_filters_http_gcp_authn_v3_gcp_authn_proto_upbdefinit); + return upb_DefPool_FindMessageByName(s, "envoy.extensions.filters.http.gcp_authn.v3.TokenHeader"); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#include "upb/port/undef.inc" + +#endif /* ENVOY_EXTENSIONS_FILTERS_HTTP_GCP_AUTHN_V3_GCP_AUTHN_PROTO_UPBDEFS_H_ */ diff --git a/src/core/handshaker/handshaker.cc b/src/core/handshaker/handshaker.cc index 66824008fd..3949dccbe5 100644 --- a/src/core/handshaker/handshaker.cc +++ b/src/core/handshaker/handshaker.cc @@ -81,11 +81,10 @@ HandshakeManager::HandshakeManager() void HandshakeManager::Add(RefCountedPtr handshaker) { MutexLock lock(&mu_); - if (GRPC_TRACE_FLAG_ENABLED(handshaker)) { - LOG(INFO) << "handshake_manager " << this << ": adding handshaker " - << std::string(handshaker->name()) << " [" << handshaker.get() - << "] at index " << handshakers_.size(); - } + GRPC_TRACE_LOG(handshaker, INFO) + << "handshake_manager " << this << ": adding handshaker " + << std::string(handshaker->name()) << " [" << handshaker.get() + << "] at index " << handshakers_.size(); handshakers_.push_back(std::move(handshaker)); } @@ -139,28 +138,24 @@ void HandshakeManager::DoHandshake( void HandshakeManager::Shutdown(absl::Status error) { MutexLock lock(&mu_); if (!is_shutdown_) { - if (GRPC_TRACE_FLAG_ENABLED(handshaker)) { - LOG(INFO) << "handshake_manager " << this - << ": Shutdown() called: " << error; - } + GRPC_TRACE_LOG(handshaker, INFO) + << "handshake_manager " << this << ": Shutdown() called: " << error; is_shutdown_ = true; // Shutdown the handshaker that's currently in progress, if any. if (index_ > 0) { - if (GRPC_TRACE_FLAG_ENABLED(handshaker)) { - LOG(INFO) << "handshake_manager " << this - << ": shutting down handshaker at index " << index_ - 1; - } + GRPC_TRACE_LOG(handshaker, INFO) + << "handshake_manager " << this + << ": shutting down handshaker at index " << index_ - 1; handshakers_[index_ - 1]->Shutdown(std::move(error)); } } } void HandshakeManager::CallNextHandshakerLocked(absl::Status error) { - if (GRPC_TRACE_FLAG_ENABLED(handshaker)) { - LOG(INFO) << "handshake_manager " << this << ": error=" << error - << " shutdown=" << is_shutdown_ << " index=" << index_ - << ", args=" << HandshakerArgsString(&args_); - } + GRPC_TRACE_LOG(handshaker, INFO) + << "handshake_manager " << this << ": error=" << error + << " shutdown=" << is_shutdown_ << " index=" << index_ + << ", args=" << HandshakerArgsString(&args_); CHECK(index_ <= handshakers_.size()); // If we got an error or we've been shut down or we're exiting early or // we've finished the last handshaker, invoke the on_handshake_done @@ -171,12 +166,10 @@ void HandshakeManager::CallNextHandshakerLocked(absl::Status error) { error = GRPC_ERROR_CREATE("handshaker shutdown"); args_.endpoint.reset(); } - if (GRPC_TRACE_FLAG_ENABLED(handshaker)) { - LOG(INFO) << "handshake_manager " << this - << ": handshaking complete -- scheduling " - "on_handshake_done with error=" - << error; - } + GRPC_TRACE_LOG(handshaker, INFO) << "handshake_manager " << this + << ": handshaking complete -- scheduling " + "on_handshake_done with error=" + << error; // Cancel deadline timer, since we're invoking the on_handshake_done // callback now. args_.event_engine->Cancel(deadline_timer_handle_); @@ -195,11 +188,10 @@ void HandshakeManager::CallNextHandshakerLocked(absl::Status error) { } // Call the next handshaker. auto handshaker = handshakers_[index_]; - if (GRPC_TRACE_FLAG_ENABLED(handshaker)) { - LOG(INFO) << "handshake_manager " << this << ": calling handshaker " - << handshaker->name() << " [" << handshaker.get() << "] at index " - << index_; - } + GRPC_TRACE_LOG(handshaker, INFO) + << "handshake_manager " << this << ": calling handshaker " + << handshaker->name() << " [" << handshaker.get() << "] at index " + << index_; ++index_; handshaker->DoHandshake(&args_, [self = Ref()](absl::Status error) mutable { MutexLock lock(&self->mu_); diff --git a/src/core/handshaker/security/secure_endpoint.cc b/src/core/handshaker/security/secure_endpoint.cc index a2eab8153a..cf720f19d2 100644 --- a/src/core/handshaker/security/secure_endpoint.cc +++ b/src/core/handshaker/security/secure_endpoint.cc @@ -108,7 +108,6 @@ struct secure_endpoint : public grpc_endpoint { } ~secure_endpoint() { - memory_owner.Reset(); tsi_frame_protector_destroy(protector); tsi_zero_copy_grpc_protector_destroy(zero_copy_protector); grpc_slice_buffer_destroy(&source_buffer); @@ -196,9 +195,8 @@ static void maybe_post_reclaimer(secure_endpoint* ep) { grpc_core::ReclamationPass::kBenign, [ep](absl::optional sweep) { if (sweep.has_value()) { - if (GRPC_TRACE_FLAG_ENABLED(resource_quota)) { - LOG(INFO) << "secure endpoint: benign reclamation to free memory"; - } + GRPC_TRACE_LOG(resource_quota, INFO) + << "secure endpoint: benign reclamation to free memory"; grpc_slice temp_read_slice; grpc_slice temp_write_slice; @@ -254,6 +252,13 @@ static void on_read(void* user_data, grpc_error_handle error) { { grpc_core::MutexLock l(&ep->read_mu); + + // If we were shut down after this callback was scheduled with OK + // status but before it was invoked, we need to treat that as an error. + if (ep->wrapped_ep == nullptr && error.ok()) { + error = absl::CancelledError("secure endpoint shutdown"); + } + uint8_t* cur = GRPC_SLICE_START_PTR(ep->read_staging_buffer); uint8_t* end = GRPC_SLICE_END_PTR(ep->read_staging_buffer); @@ -380,9 +385,12 @@ static void flush_write_staging_buffer(secure_endpoint* ep, uint8_t** cur, static void on_write(void* user_data, grpc_error_handle error) { secure_endpoint* ep = static_cast(user_data); - grpc_core::ExecCtx::Run(DEBUG_LOCATION, std::exchange(ep->write_cb, nullptr), - std::move(error)); + grpc_closure* cb = ep->write_cb; + ep->write_cb = nullptr; SECURE_ENDPOINT_UNREF(ep, "write"); + grpc_core::EnsureRunInExecCtx([cb, error = std::move(error)]() { + grpc_core::Closure::Run(DEBUG_LOCATION, cb, error); + }); } static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, @@ -504,7 +512,10 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, static void endpoint_destroy(grpc_endpoint* secure_ep) { secure_endpoint* ep = reinterpret_cast(secure_ep); + ep->read_mu.Lock(); ep->wrapped_ep.reset(); + ep->memory_owner.Reset(); + ep->read_mu.Unlock(); SECURE_ENDPOINT_UNREF(ep, "destroy"); } diff --git a/src/core/handshaker/security/security_handshaker.cc b/src/core/handshaker/security/security_handshaker.cc index 58c9a16eae..e54735e53a 100644 --- a/src/core/handshaker/security/security_handshaker.cc +++ b/src/core/handshaker/security/security_handshaker.cc @@ -41,7 +41,6 @@ #include #include #include -#include #include #include "src/core/channelz/channelz.h" @@ -88,27 +87,27 @@ class SecurityHandshaker : public Handshaker { private: grpc_error_handle DoHandshakerNextLocked(const unsigned char* bytes_received, - size_t bytes_received_size); + size_t bytes_received_size) + ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_); grpc_error_handle OnHandshakeNextDoneLocked( tsi_result result, const unsigned char* bytes_to_send, - size_t bytes_to_send_size, tsi_handshaker_result* handshaker_result); - void HandshakeFailedLocked(absl::Status error); + size_t bytes_to_send_size, tsi_handshaker_result* handshaker_result) + ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_); + void HandshakeFailedLocked(absl::Status error) + ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_); void Finish(absl::Status status); void OnHandshakeDataReceivedFromPeerFn(absl::Status error); void OnHandshakeDataSentToPeerFn(absl::Status error); - static void OnHandshakeDataReceivedFromPeerFnScheduler( - void* arg, grpc_error_handle error); - static void OnHandshakeDataSentToPeerFnScheduler(void* arg, - grpc_error_handle error); + void OnHandshakeDataReceivedFromPeerFnScheduler(grpc_error_handle error); + void OnHandshakeDataSentToPeerFnScheduler(grpc_error_handle error); static void OnHandshakeNextDoneGrpcWrapper( tsi_result result, void* user_data, const unsigned char* bytes_to_send, size_t bytes_to_send_size, tsi_handshaker_result* handshaker_result); - static void OnPeerCheckedFn(void* arg, grpc_error_handle error); - void OnPeerCheckedInner(grpc_error_handle error); + void OnPeerCheckedFn(grpc_error_handle error); size_t MoveReadBufferIntoHandshakeBuffer(); - grpc_error_handle CheckPeerLocked(); + grpc_error_handle CheckPeerLocked() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_); // State set at creation time. tsi_handshaker* handshaker_; @@ -125,13 +124,11 @@ class SecurityHandshaker : public Handshaker { size_t handshake_buffer_size_; unsigned char* handshake_buffer_; SliceBuffer outgoing_; - grpc_closure on_handshake_data_sent_to_peer_; - grpc_closure on_handshake_data_received_from_peer_; - grpc_closure on_peer_checked_; RefCountedPtr auth_context_; tsi_handshaker_result* handshaker_result_ = nullptr; size_t max_frame_size_ = 0; std::string tsi_handshake_error_; + grpc_closure* on_peer_checked_ ABSL_GUARDED_BY(mu_) = nullptr; }; SecurityHandshaker::SecurityHandshaker(tsi_handshaker* handshaker, @@ -143,10 +140,7 @@ SecurityHandshaker::SecurityHandshaker(tsi_handshaker* handshaker, handshake_buffer_( static_cast(gpr_malloc(handshake_buffer_size_))), max_frame_size_( - std::max(0, args.GetInt(GRPC_ARG_TSI_MAX_FRAME_SIZE).value_or(0))) { - GRPC_CLOSURE_INIT(&on_peer_checked_, &SecurityHandshaker::OnPeerCheckedFn, - this, grpc_schedule_on_exec_ctx); -} + std::max(0, args.GetInt(GRPC_ARG_TSI_MAX_FRAME_SIZE).value_or(0))) {} SecurityHandshaker::~SecurityHandshaker() { tsi_handshaker_destroy(handshaker_); @@ -220,8 +214,9 @@ MakeChannelzSecurityFromAuthContext(grpc_auth_context* auth_context) { } // namespace -void SecurityHandshaker::OnPeerCheckedInner(grpc_error_handle error) { +void SecurityHandshaker::OnPeerCheckedFn(grpc_error_handle error) { MutexLock lock(&mu_); + on_peer_checked_ = nullptr; if (!error.ok() || is_shutdown_) { HandshakeFailedLocked(error); return; @@ -317,11 +312,6 @@ void SecurityHandshaker::OnPeerCheckedInner(grpc_error_handle error) { Finish(absl::OkStatus()); } -void SecurityHandshaker::OnPeerCheckedFn(void* arg, grpc_error_handle error) { - RefCountedPtr(static_cast(arg)) - ->OnPeerCheckedInner(error); -} - grpc_error_handle SecurityHandshaker::CheckPeerLocked() { tsi_peer peer; tsi_result result = @@ -330,8 +320,12 @@ grpc_error_handle SecurityHandshaker::CheckPeerLocked() { return GRPC_ERROR_CREATE(absl::StrCat("Peer extraction failed (", tsi_result_to_string(result), ")")); } + on_peer_checked_ = NewClosure( + [self = RefAsSubclass()](absl::Status status) { + self->OnPeerCheckedFn(std::move(status)); + }); connector_->check_peer(peer, args_->endpoint.get(), args_->args, - &auth_context_, &on_peer_checked_); + &auth_context_, on_peer_checked_); grpc_auth_property_iterator it = grpc_auth_context_find_properties_by_name( auth_context_.get(), GRPC_TRANSPORT_SECURITY_LEVEL_PROPERTY_NAME); const grpc_auth_property* prop = grpc_auth_property_iterator_next(&it); @@ -356,10 +350,10 @@ grpc_error_handle SecurityHandshaker::OnHandshakeNextDoneLocked( CHECK_EQ(bytes_to_send_size, 0u); grpc_endpoint_read( args_->endpoint.get(), args_->read_buffer.c_slice_buffer(), - GRPC_CLOSURE_INIT( - &on_handshake_data_received_from_peer_, - &SecurityHandshaker::OnHandshakeDataReceivedFromPeerFnScheduler, - this, grpc_schedule_on_exec_ctx), + NewClosure([self = RefAsSubclass()]( + absl::Status status) { + self->OnHandshakeDataReceivedFromPeerFnScheduler(std::move(status)); + }), /*urgent=*/true, /*min_progress_size=*/1); return error; } @@ -387,19 +381,19 @@ grpc_error_handle SecurityHandshaker::OnHandshakeNextDoneLocked( reinterpret_cast(bytes_to_send), bytes_to_send_size)); grpc_endpoint_write( args_->endpoint.get(), outgoing_.c_slice_buffer(), - GRPC_CLOSURE_INIT( - &on_handshake_data_sent_to_peer_, - &SecurityHandshaker::OnHandshakeDataSentToPeerFnScheduler, this, - grpc_schedule_on_exec_ctx), + NewClosure( + [self = RefAsSubclass()](absl::Status status) { + self->OnHandshakeDataSentToPeerFnScheduler(std::move(status)); + }), nullptr, /*max_frame_size=*/INT_MAX); } else if (handshaker_result == nullptr) { // There is nothing to send, but need to read from peer. grpc_endpoint_read( args_->endpoint.get(), args_->read_buffer.c_slice_buffer(), - GRPC_CLOSURE_INIT( - &on_handshake_data_received_from_peer_, - &SecurityHandshaker::OnHandshakeDataReceivedFromPeerFnScheduler, - this, grpc_schedule_on_exec_ctx), + NewClosure([self = RefAsSubclass()]( + absl::Status status) { + self->OnHandshakeDataReceivedFromPeerFnScheduler(std::move(status)); + }), /*urgent=*/true, /*min_progress_size=*/1); } else { // Handshake has finished, check peer and so on. @@ -418,8 +412,6 @@ void SecurityHandshaker::OnHandshakeNextDoneGrpcWrapper( result, bytes_to_send, bytes_to_send_size, handshaker_result); if (!error.ok()) { h->HandshakeFailedLocked(std::move(error)); - } else { - h.release(); // Avoid unref } } @@ -429,13 +421,15 @@ grpc_error_handle SecurityHandshaker::DoHandshakerNextLocked( const unsigned char* bytes_to_send = nullptr; size_t bytes_to_send_size = 0; tsi_handshaker_result* hs_result = nullptr; + auto self = RefAsSubclass(); tsi_result result = tsi_handshaker_next( handshaker_, bytes_received, bytes_received_size, &bytes_to_send, - &bytes_to_send_size, &hs_result, &OnHandshakeNextDoneGrpcWrapper, this, - &tsi_handshake_error_); + &bytes_to_send_size, &hs_result, &OnHandshakeNextDoneGrpcWrapper, + self.get(), &tsi_handshake_error_); if (result == TSI_ASYNC) { - // Handshaker operating asynchronously. Nothing else to do here; - // callback will be invoked in a TSI thread. + // Handshaker operating asynchronously. Callback will be invoked in a TSI + // thread. We no longer own the ref held in self. + self.release(); return absl::OkStatus(); } // Handshaker returned synchronously. Invoke callback directly in @@ -449,18 +443,18 @@ grpc_error_handle SecurityHandshaker::DoHandshakerNextLocked( // TODO(roth): This will no longer be necessary once we migrate to the // EventEngine endpoint API. void SecurityHandshaker::OnHandshakeDataReceivedFromPeerFnScheduler( - void* arg, grpc_error_handle error) { - SecurityHandshaker* handshaker = static_cast(arg); - handshaker->args_->event_engine->Run( - [handshaker, error = std::move(error)]() mutable { - ApplicationCallbackExecCtx callback_exec_ctx; - ExecCtx exec_ctx; - handshaker->OnHandshakeDataReceivedFromPeerFn(std::move(error)); - }); + grpc_error_handle error) { + args_->event_engine->Run([self = RefAsSubclass(), + error = std::move(error)]() mutable { + ApplicationCallbackExecCtx callback_exec_ctx; + ExecCtx exec_ctx; + self->OnHandshakeDataReceivedFromPeerFn(std::move(error)); + // Avoid destruction outside of an ExecCtx (since this is non-cancelable). + self.reset(); + }); } void SecurityHandshaker::OnHandshakeDataReceivedFromPeerFn(absl::Status error) { - RefCountedPtr handshaker(this); MutexLock lock(&mu_); if (!error.ok() || is_shutdown_) { HandshakeFailedLocked( @@ -473,8 +467,6 @@ void SecurityHandshaker::OnHandshakeDataReceivedFromPeerFn(absl::Status error) { error = DoHandshakerNextLocked(handshake_buffer_, bytes_received_size); if (!error.ok()) { HandshakeFailedLocked(std::move(error)); - } else { - handshaker.release(); // Avoid unref } } @@ -483,18 +475,18 @@ void SecurityHandshaker::OnHandshakeDataReceivedFromPeerFn(absl::Status error) { // TODO(roth): This will no longer be necessary once we migrate to the // EventEngine endpoint API. void SecurityHandshaker::OnHandshakeDataSentToPeerFnScheduler( - void* arg, grpc_error_handle error) { - SecurityHandshaker* handshaker = static_cast(arg); - handshaker->args_->event_engine->Run( - [handshaker, error = std::move(error)]() mutable { - ApplicationCallbackExecCtx callback_exec_ctx; - ExecCtx exec_ctx; - handshaker->OnHandshakeDataSentToPeerFn(std::move(error)); - }); + grpc_error_handle error) { + args_->event_engine->Run([self = RefAsSubclass(), + error = std::move(error)]() mutable { + ApplicationCallbackExecCtx callback_exec_ctx; + ExecCtx exec_ctx; + self->OnHandshakeDataSentToPeerFn(std::move(error)); + // Avoid destruction outside of an ExecCtx (since this is non-cancelable). + self.reset(); + }); } void SecurityHandshaker::OnHandshakeDataSentToPeerFn(absl::Status error) { - RefCountedPtr handshaker(this); MutexLock lock(&mu_); if (!error.ok() || is_shutdown_) { HandshakeFailedLocked( @@ -505,10 +497,10 @@ void SecurityHandshaker::OnHandshakeDataSentToPeerFn(absl::Status error) { if (handshaker_result_ == nullptr) { grpc_endpoint_read( args_->endpoint.get(), args_->read_buffer.c_slice_buffer(), - GRPC_CLOSURE_INIT( - &on_handshake_data_received_from_peer_, - &SecurityHandshaker::OnHandshakeDataReceivedFromPeerFnScheduler, - this, grpc_schedule_on_exec_ctx), + NewClosure([self = RefAsSubclass()]( + absl::Status status) { + self->OnHandshakeDataReceivedFromPeerFnScheduler(std::move(status)); + }), /*urgent=*/true, /*min_progress_size=*/1); } else { error = CheckPeerLocked(); @@ -517,7 +509,6 @@ void SecurityHandshaker::OnHandshakeDataSentToPeerFn(absl::Status error) { return; } } - handshaker.release(); // Avoid unref } // @@ -528,7 +519,7 @@ void SecurityHandshaker::Shutdown(grpc_error_handle error) { MutexLock lock(&mu_); if (!is_shutdown_) { is_shutdown_ = true; - connector_->cancel_check_peer(&on_peer_checked_, std::move(error)); + connector_->cancel_check_peer(on_peer_checked_, std::move(error)); tsi_handshaker_shutdown(handshaker_); args_->endpoint.reset(); } @@ -537,7 +528,6 @@ void SecurityHandshaker::Shutdown(grpc_error_handle error) { void SecurityHandshaker::DoHandshake( HandshakerArgs* args, absl::AnyInvocable on_handshake_done) { - auto ref = Ref(); MutexLock lock(&mu_); args_ = args; on_handshake_done_ = std::move(on_handshake_done); @@ -546,8 +536,6 @@ void SecurityHandshaker::DoHandshake( DoHandshakerNextLocked(handshake_buffer_, bytes_received_size); if (!error.ok()) { HandshakeFailedLocked(error); - } else { - ref.release(); // Avoid unref } } diff --git a/src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc b/src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc index 7822a5cebe..77ae19ef7d 100644 --- a/src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc +++ b/src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc @@ -31,7 +31,6 @@ #include #include #include -#include #include #include "src/core/handshaker/handshaker.h" diff --git a/src/core/lib/channel/channel_stack.cc b/src/core/lib/channel/channel_stack.cc index 36e3461700..2590ab4590 100644 --- a/src/core/lib/channel/channel_stack.cc +++ b/src/core/lib/channel/channel_stack.cc @@ -26,7 +26,6 @@ #include "absl/log/check.h" #include "absl/log/log.h" -#include #include #include "src/core/lib/channel/channel_args.h" diff --git a/src/core/lib/channel/channel_stack.h b/src/core/lib/channel/channel_stack.h index f21c1dc0d8..451cba6be9 100644 --- a/src/core/lib/channel/channel_stack.h +++ b/src/core/lib/channel/channel_stack.h @@ -53,7 +53,6 @@ #include #include #include -#include #include #include diff --git a/src/core/lib/channel/channel_stack_builder_impl.cc b/src/core/lib/channel/channel_stack_builder_impl.cc index 7db444474e..a5d93d81ed 100644 --- a/src/core/lib/channel/channel_stack_builder_impl.cc +++ b/src/core/lib/channel/channel_stack_builder_impl.cc @@ -33,7 +33,6 @@ #include "absl/strings/str_cat.h" #include -#include #include #include "src/core/lib/channel/channel_fwd.h" diff --git a/src/core/lib/channel/connected_channel.cc b/src/core/lib/channel/connected_channel.cc index f24304bac8..9977ecdabf 100644 --- a/src/core/lib/channel/connected_channel.cc +++ b/src/core/lib/channel/connected_channel.cc @@ -34,7 +34,6 @@ #include #include #include -#include #include #include "src/core/lib/channel/call_finalization.h" diff --git a/src/core/lib/channel/promise_based_filter.cc b/src/core/lib/channel/promise_based_filter.cc index 3466d939be..5f0879dda2 100644 --- a/src/core/lib/channel/promise_based_filter.cc +++ b/src/core/lib/channel/promise_based_filter.cc @@ -207,10 +207,8 @@ void BaseCallData::CapturedBatch::ResumeWith(Flusher* releaser) { uintptr_t& refcnt = *RefCountField(batch); if (refcnt == 0) { // refcnt==0 ==> cancelled - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << releaser->call()->DebugTag() - << "RESUME BATCH REQUEST CANCELLED"; - } + GRPC_TRACE_LOG(channel, INFO) + << releaser->call()->DebugTag() << "RESUME BATCH REQUEST CANCELLED"; return; } if (--refcnt == 0) { @@ -266,10 +264,9 @@ BaseCallData::Flusher::~Flusher() { auto* batch = static_cast(p); BaseCallData* call = static_cast(batch->handler_private.extra_arg); - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << "FLUSHER:forward batch via closure: " - << grpc_transport_stream_op_batch_string(batch, false); - } + GRPC_TRACE_LOG(channel, INFO) + << "FLUSHER:forward batch via closure: " + << grpc_transport_stream_op_batch_string(batch, false); grpc_call_next_op(call->elem(), batch); GRPC_CALL_STACK_UNREF(call->call_stack(), "flusher_batch"); }; @@ -278,10 +275,9 @@ BaseCallData::Flusher::~Flusher() { if (call_->call() != nullptr && call_->call()->traced()) { batch->is_traced = true; } - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << "FLUSHER:queue batch to forward in closure: " - << grpc_transport_stream_op_batch_string(release_[i], false); - } + GRPC_TRACE_LOG(channel, INFO) + << "FLUSHER:queue batch to forward in closure: " + << grpc_transport_stream_op_batch_string(release_[i], false); batch->handler_private.extra_arg = call_; GRPC_CLOSURE_INIT(&batch->handler_private.closure, call_next_op, batch, nullptr); @@ -290,10 +286,9 @@ BaseCallData::Flusher::~Flusher() { "flusher_batch"); } call_closures_.RunClosuresWithoutYielding(call_->call_combiner()); - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << "FLUSHER:forward batch: " - << grpc_transport_stream_op_batch_string(release_[0], false); - } + GRPC_TRACE_LOG(channel, INFO) + << "FLUSHER:forward batch: " + << grpc_transport_stream_op_batch_string(release_[0], false); if (call_->call() != nullptr && call_->call()->traced()) { release_[0]->is_traced = true; } @@ -331,10 +326,8 @@ const char* BaseCallData::SendMessage::StateString(State state) { } void BaseCallData::SendMessage::StartOp(CapturedBatch batch) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " SendMessage.StartOp st=" << StateString(state_); - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() << " SendMessage.StartOp st=" << StateString(state_); switch (state_) { case State::kInitial: state_ = State::kGotBatchNoPipe; @@ -359,10 +352,8 @@ void BaseCallData::SendMessage::StartOp(CapturedBatch batch) { template void BaseCallData::SendMessage::GotPipe(T* pipe_end) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " SendMessage.GotPipe st=" << StateString(state_); - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() << " SendMessage.GotPipe st=" << StateString(state_); CHECK_NE(pipe_end, nullptr); switch (state_) { case State::kInitial: @@ -407,11 +398,9 @@ bool BaseCallData::SendMessage::IsIdle() const { void BaseCallData::SendMessage::OnComplete(absl::Status status) { Flusher flusher(base_); - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " SendMessage.OnComplete st=" << StateString(state_) - << " status=" << status; - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() << " SendMessage.OnComplete st=" << StateString(state_) + << " status=" << status; switch (state_) { case State::kInitial: case State::kIdle: @@ -438,11 +427,9 @@ void BaseCallData::SendMessage::OnComplete(absl::Status status) { void BaseCallData::SendMessage::Done(const ServerMetadata& metadata, Flusher* flusher) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " SendMessage.Done st=" << StateString(state_) - << " md=" << metadata.DebugString(); - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() << " SendMessage.Done st=" << StateString(state_) + << " md=" << metadata.DebugString(); switch (state_) { case State::kCancelled: case State::kCancelledButNotYetPolled: @@ -481,13 +468,12 @@ void BaseCallData::SendMessage::Done(const ServerMetadata& metadata, void BaseCallData::SendMessage::WakeInsideCombiner(Flusher* flusher, bool allow_push_to_pipe) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " SendMessage.WakeInsideCombiner st=" << StateString(state_) - << (state_ == State::kBatchCompleted - ? absl::StrCat(" status=", completed_status_.ToString()) - : ""); - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() + << " SendMessage.WakeInsideCombiner st=" << StateString(state_) + << (state_ == State::kBatchCompleted + ? absl::StrCat(" status=", completed_status_.ToString()) + : ""); switch (state_) { case State::kInitial: case State::kIdle: @@ -515,12 +501,11 @@ void BaseCallData::SendMessage::WakeInsideCombiner(Flusher* flusher, CHECK(push_.has_value()); auto r_push = (*push_)(); if (auto* p = r_push.value_if_ready()) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " SendMessage.WakeInsideCombiner push complete, " - "result=" - << (*p ? "true" : "false"); - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() + << " SendMessage.WakeInsideCombiner push complete, " + "result=" + << (*p ? "true" : "false"); // We haven't pulled through yet, so this certainly shouldn't succeed. CHECK(!*p); state_ = State::kCancelled; @@ -530,12 +515,11 @@ void BaseCallData::SendMessage::WakeInsideCombiner(Flusher* flusher, CHECK(next_.has_value()); auto r_next = (*next_)(); if (auto* p = r_next.value_if_ready()) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " SendMessage.WakeInsideCombiner next complete, " - "result.has_value=" - << (p->has_value() ? "true" : "false"); - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() + << " SendMessage.WakeInsideCombiner next complete, " + "result.has_value=" + << (p->has_value() ? "true" : "false"); if (p->has_value()) { batch_->payload->send_message.send_message->Swap((**p)->payload()); batch_->payload->send_message.flags = (**p)->flags(); @@ -615,10 +599,9 @@ const char* BaseCallData::ReceiveMessage::StateString(State state) { } void BaseCallData::ReceiveMessage::StartOp(CapturedBatch& batch) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " ReceiveMessage.StartOp st=" << StateString(state_); - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() + << " ReceiveMessage.StartOp st=" << StateString(state_); switch (state_) { case State::kInitial: state_ = State::kForwardedBatchNoPipe; @@ -656,10 +639,9 @@ void BaseCallData::ReceiveMessage::StartOp(CapturedBatch& batch) { template void BaseCallData::ReceiveMessage::GotPipe(T* pipe_end) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " ReceiveMessage.GotPipe st=" << StateString(state_); - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() + << " ReceiveMessage.GotPipe st=" << StateString(state_); switch (state_) { case State::kInitial: state_ = State::kIdle; @@ -692,11 +674,10 @@ void BaseCallData::ReceiveMessage::GotPipe(T* pipe_end) { } void BaseCallData::ReceiveMessage::OnComplete(absl::Status status) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " ReceiveMessage.OnComplete st=" << StateString(state_) - << " status=" << status; - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() + << " ReceiveMessage.OnComplete st=" << StateString(state_) + << " status=" << status; switch (state_) { case State::kInitial: case State::kIdle: @@ -733,11 +714,9 @@ void BaseCallData::ReceiveMessage::OnComplete(absl::Status status) { void BaseCallData::ReceiveMessage::Done(const ServerMetadata& metadata, Flusher* flusher) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " ReceiveMessage.Done st=" << StateString(state_) - << " md=" << metadata.DebugString(); - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() << " ReceiveMessage.Done st=" << StateString(state_) + << " md=" << metadata.DebugString(); switch (state_) { case State::kInitial: state_ = State::kCancelled; @@ -792,13 +771,12 @@ void BaseCallData::ReceiveMessage::Done(const ServerMetadata& metadata, void BaseCallData::ReceiveMessage::WakeInsideCombiner(Flusher* flusher, bool allow_push_to_pipe) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " ReceiveMessage.WakeInsideCombiner st=" << StateString(state_) - << " push?=" << (push_.has_value() ? "yes" : "no") - << " next?=" << (next_.has_value() ? "yes" : "no") - << " allow_push_to_pipe=" << (allow_push_to_pipe ? "yes" : "no"); - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() + << " ReceiveMessage.WakeInsideCombiner st=" << StateString(state_) + << " push?=" << (push_.has_value() ? "yes" : "no") + << " next?=" << (next_.has_value() ? "yes" : "no") + << " allow_push_to_pipe=" << (allow_push_to_pipe ? "yes" : "no"); switch (state_) { case State::kInitial: case State::kIdle: @@ -853,11 +831,10 @@ void BaseCallData::ReceiveMessage::WakeInsideCombiner(Flusher* flusher, CHECK(push_.has_value()); auto r_push = (*push_)(); if (auto* p = r_push.value_if_ready()) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " ReceiveMessage.WakeInsideCombiner push complete: " - << (*p ? "true" : "false"); - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() + << " ReceiveMessage.WakeInsideCombiner push complete: " + << (*p ? "true" : "false"); // We haven't pulled through yet, so this certainly shouldn't succeed. CHECK(!*p); state_ = State::kCancelled; @@ -884,12 +861,11 @@ void BaseCallData::ReceiveMessage::WakeInsideCombiner(Flusher* flusher, p->cancelled() ? absl::CancelledError() : absl::OkStatus(), "recv_message"); } - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " ReceiveMessage.WakeInsideCombiner next complete: " - << (p->has_value() ? "got message" : "end of stream") - << " new_state=" << StateString(state_); - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() + << " ReceiveMessage.WakeInsideCombiner next complete: " + << (p->has_value() ? "got message" : "end of stream") + << " new_state=" << StateString(state_); } if (state_ != State::kPulledFromPipe && state_ != State::kCompletedWhilePulledFromPipe) { @@ -901,10 +877,9 @@ void BaseCallData::ReceiveMessage::WakeInsideCombiner(Flusher* flusher, case State::kPulledFromPipe: { CHECK(push_.has_value()); if ((*push_)().ready()) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << base_->LogTag() - << " ReceiveMessage.WakeInsideCombiner push complete"; - } + GRPC_TRACE_LOG(channel, INFO) + << base_->LogTag() + << " ReceiveMessage.WakeInsideCombiner push complete"; if (state_ == State::kCompletedWhilePulledFromPipe) { interceptor()->Push()->Close(); state_ = State::kCancelled; @@ -1016,10 +991,9 @@ class ClientCallData::PollContext { void Run() { DCHECK(HasContext()); - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << self_->LogTag() << " ClientCallData.PollContext.Run " - << self_->DebugString(); - } + GRPC_TRACE_LOG(channel, INFO) + << self_->LogTag() << " ClientCallData.PollContext.Run " + << self_->DebugString(); CHECK(have_scoped_activity_); repoll_ = false; if (self_->send_message() != nullptr) { @@ -1100,15 +1074,14 @@ class ClientCallData::PollContext { case SendInitialState::kForwarded: { // Poll the promise once since we're waiting for it. Poll poll = self_->promise_(); - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << self_->LogTag() - << " ClientCallData.PollContext.Run: poll=" - << PollToString(poll, - [](const ServerMetadataHandle& h) { - return h->DebugString(); - }) - << "; " << self_->DebugString(); - } + GRPC_TRACE_LOG(channel, INFO) + << self_->LogTag() << " ClientCallData.PollContext.Run: poll=" + << PollToString(poll, + [](const ServerMetadataHandle& h) { + return h->DebugString(); + }) + << "; " << self_->DebugString(); + if (auto* r = poll.value_if_ready()) { auto md = std::move(*r); if (self_->send_message() != nullptr) { @@ -1379,9 +1352,7 @@ void ClientCallData::StartBatch(grpc_transport_stream_op_batch* b) { CapturedBatch batch(b); Flusher flusher(this); - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() << " StartBatch " << DebugString(); - } + GRPC_TRACE_LOG(channel, INFO) << LogTag() << " StartBatch " << DebugString(); // If this is a cancel stream, cancel anything we have pending and propagate // the cancellation. @@ -1502,9 +1473,8 @@ void ClientCallData::StartBatch(grpc_transport_stream_op_batch* b) { // Handle cancellation. void ClientCallData::Cancel(grpc_error_handle error, Flusher* flusher) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() << " Cancel error=" << error.ToString(); - } + GRPC_TRACE_LOG(channel, INFO) + << LogTag() << " Cancel error=" << error.ToString(); // Track the latest reason for cancellation. cancelled_error_ = error; // Stop running the promise. @@ -1581,11 +1551,10 @@ void ClientCallData::StartPromise(Flusher* flusher) { } void ClientCallData::RecvInitialMetadataReady(grpc_error_handle error) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() << " ClientCallData.RecvInitialMetadataReady " - << DebugString() << " error:" << error.ToString() - << " md:" << recv_initial_metadata_->metadata->DebugString(); - } + GRPC_TRACE_LOG(channel, INFO) + << LogTag() << " ClientCallData.RecvInitialMetadataReady " + << DebugString() << " error:" << error.ToString() + << " md:" << recv_initial_metadata_->metadata->DebugString(); ScopedContext context(this); Flusher flusher(this); if (!error.ok()) { @@ -1664,10 +1633,8 @@ void ClientCallData::HookRecvTrailingMetadata(CapturedBatch batch) { // - return a wrapper around PollTrailingMetadata as the promise. ArenaPromise ClientCallData::MakeNextPromise( CallArgs call_args) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() << " ClientCallData.MakeNextPromise " - << DebugString(); - } + GRPC_TRACE_LOG(channel, INFO) + << LogTag() << " ClientCallData.MakeNextPromise " << DebugString(); CHECK_NE(poll_ctx_, nullptr); CHECK(send_initial_state_ == SendInitialState::kQueued); send_initial_metadata_batch_->payload->send_initial_metadata @@ -1727,10 +1694,8 @@ ArenaPromise ClientCallData::MakeNextPromise( // All polls: await receiving the trailing metadata, then return it to the // application. Poll ClientCallData::PollTrailingMetadata() { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() << " ClientCallData.PollTrailingMetadata " - << DebugString(); - } + GRPC_TRACE_LOG(channel, INFO) + << LogTag() << " ClientCallData.PollTrailingMetadata " << DebugString(); CHECK_NE(poll_ctx_, nullptr); if (send_initial_state_ == SendInitialState::kQueued) { // First poll: pass the send_initial_metadata op down the stack. @@ -1778,12 +1743,10 @@ void ClientCallData::RecvTrailingMetadataReadyCallback( void ClientCallData::RecvTrailingMetadataReady(grpc_error_handle error) { Flusher flusher(this); - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() << " ClientCallData.RecvTrailingMetadataReady " - << "recv_trailing_state=" << StateString(recv_trailing_state_) - << " error=" << error - << " md=" << recv_trailing_metadata_->DebugString(); - } + GRPC_TRACE_LOG(channel, INFO) + << LogTag() << " ClientCallData.RecvTrailingMetadataReady " + << "recv_trailing_state=" << StateString(recv_trailing_state_) + << " error=" << error << " md=" << recv_trailing_metadata_->DebugString(); // If we were cancelled prior to receiving this callback, we should simply // forward the callback up with the same error. if (recv_trailing_state_ == RecvTrailingState::kCancelled) { @@ -1991,9 +1954,8 @@ ServerCallData::ServerCallData(grpc_call_element* elem, } ServerCallData::~ServerCallData() { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() << " ~ServerCallData " << DebugString(); - } + GRPC_TRACE_LOG(channel, INFO) + << LogTag() << " ~ServerCallData " << DebugString(); if (send_initial_metadata_ != nullptr) { send_initial_metadata_->~SendInitialMetadata(); } @@ -2018,9 +1980,7 @@ void ServerCallData::StartBatch(grpc_transport_stream_op_batch* b) { Flusher flusher(this); bool wake = false; - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() << " StartBatch: " << DebugString(); - } + GRPC_TRACE_LOG(channel, INFO) << LogTag() << " StartBatch: " << DebugString(); // If this is a cancel stream, cancel anything we have pending and // propagate the cancellation. @@ -2151,15 +2111,13 @@ void ServerCallData::StartBatch(grpc_transport_stream_op_batch* b) { // Handle cancellation. void ServerCallData::Completed(grpc_error_handle error, bool tarpit_cancellation, Flusher* flusher) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - VLOG(2) << LogTag() << "ServerCallData::Completed: send_trailing_state=" - << StateString(send_trailing_state_) << " send_initial_state=" - << (send_initial_metadata_ == nullptr - ? "null" - : SendInitialMetadata::StateString( - send_initial_metadata_->state)) - << " error=" << error; - } + GRPC_TRACE_VLOG(channel, 2) + << LogTag() << "ServerCallData::Completed: send_trailing_state=" + << StateString(send_trailing_state_) << " send_initial_state=" + << (send_initial_metadata_ == nullptr + ? "null" + : SendInitialMetadata::StateString(send_initial_metadata_->state)) + << " error=" << error; // Track the latest reason for cancellation. cancelled_error_ = error; // Stop running the promise. @@ -2275,10 +2233,9 @@ ArenaPromise ServerCallData::MakeNextPromise( // All polls: await sending the trailing metadata, then foward it down the // stack. Poll ServerCallData::PollTrailingMetadata() { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() - << " PollTrailingMetadata: " << StateString(send_trailing_state_); - } + GRPC_TRACE_LOG(channel, INFO) + << LogTag() + << " PollTrailingMetadata: " << StateString(send_trailing_state_); switch (send_trailing_state_) { case SendTrailingState::kInitial: case SendTrailingState::kQueuedBehindSendMessage: @@ -2306,10 +2263,9 @@ void ServerCallData::RecvTrailingMetadataReadyCallback( } void ServerCallData::RecvTrailingMetadataReady(grpc_error_handle error) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() << ": RecvTrailingMetadataReady error=" << error - << " md=" << recv_trailing_metadata_->DebugString(); - } + GRPC_TRACE_LOG(channel, INFO) + << LogTag() << ": RecvTrailingMetadataReady error=" << error + << " md=" << recv_trailing_metadata_->DebugString(); Flusher flusher(this); PollContext poll_ctx(this, &flusher); Completed(error, recv_trailing_metadata_->get(GrpcTarPit()).has_value(), @@ -2325,9 +2281,8 @@ void ServerCallData::RecvInitialMetadataReadyCallback(void* arg, void ServerCallData::RecvInitialMetadataReady(grpc_error_handle error) { Flusher flusher(this); - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() << ": RecvInitialMetadataReady " << error; - } + GRPC_TRACE_LOG(channel, INFO) + << LogTag() << ": RecvInitialMetadataReady " << error; CHECK(recv_initial_state_ == RecvInitialState::kForwarded); // If there was an error we just propagate that through if (!error.ok()) { @@ -2389,9 +2344,8 @@ std::string ServerCallData::DebugString() const { // Wakeup and poll the promise if appropriate. void ServerCallData::WakeInsideCombiner(Flusher* flusher) { PollContext poll_ctx(this, flusher); - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() << ": WakeInsideCombiner " << DebugString(); - } + GRPC_TRACE_LOG(channel, INFO) + << LogTag() << ": WakeInsideCombiner " << DebugString(); poll_ctx.ClearRepoll(); if (send_initial_metadata_ != nullptr) { if (send_initial_metadata_->state == @@ -2411,12 +2365,12 @@ void ServerCallData::WakeInsideCombiner(Flusher* flusher) { } if (send_initial_metadata_->metadata_push_.has_value()) { if ((*send_initial_metadata_->metadata_push_)().ready()) { - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() << ": WakeInsideCombiner: metadata_push done"; - } + GRPC_TRACE_LOG(channel, INFO) + << LogTag() << ": WakeInsideCombiner: metadata_push done"; send_initial_metadata_->metadata_push_.reset(); - } else if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() << ": WakeInsideCombiner: metadata_push pending"; + } else { + GRPC_TRACE_LOG(channel, INFO) + << LogTag() << ": WakeInsideCombiner: metadata_push pending"; } } } @@ -2432,11 +2386,10 @@ void ServerCallData::WakeInsideCombiner(Flusher* flusher) { flusher, send_initial_metadata_ == nullptr || send_initial_metadata_->state == SendInitialMetadata::kForwarded); - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - VLOG(2) << LogTag() << ": After send_message WakeInsideCombiner " - << DebugString() << " is_idle=" << send_message()->IsIdle() - << " is_forwarded=" << send_message()->IsForwarded(); - } + GRPC_TRACE_VLOG(channel, 2) + << LogTag() << ": After send_message WakeInsideCombiner " + << DebugString() << " is_idle=" << send_message()->IsIdle() + << " is_forwarded=" << send_message()->IsForwarded(); if (send_trailing_state_ == SendTrailingState::kQueuedBehindSendMessage && (send_message()->IsIdle() || (send_trailing_metadata_batch_->send_message && @@ -2458,34 +2411,30 @@ void ServerCallData::WakeInsideCombiner(Flusher* flusher) { if (promise_.has_value()) { Poll poll; poll = promise_(); - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() << ": WakeInsideCombiner poll=" - << PollToString(poll, - [](const ServerMetadataHandle& h) { - return h->DebugString(); - }) - .c_str() - << "; send_initial_metadata=" - << (send_initial_metadata_ == nullptr - ? "null" - : SendInitialMetadata::StateString( - send_initial_metadata_->state)) - << " send_trailing_metadata=" - << StateString(send_trailing_state_); - } + GRPC_TRACE_LOG(channel, INFO) + << LogTag() << ": WakeInsideCombiner poll=" + << PollToString( + poll, + [](const ServerMetadataHandle& h) { return h->DebugString(); }) + .c_str() + << "; send_initial_metadata=" + << (send_initial_metadata_ == nullptr + ? "null" + : SendInitialMetadata::StateString( + send_initial_metadata_->state)) + << " send_trailing_metadata=" << StateString(send_trailing_state_); + if (send_initial_metadata_ != nullptr && send_initial_metadata_->state == SendInitialMetadata::kQueuedAndPushedToPipe) { CHECK(send_initial_metadata_->metadata_next_.has_value()); auto p = (*send_initial_metadata_->metadata_next_)(); - if (GRPC_TRACE_FLAG_ENABLED(channel)) { - LOG(INFO) << LogTag() - << ": WakeInsideCombiner send_initial_metadata poll=" - << PollToString( - p, [](const NextResult& h) { - return (*h)->DebugString(); - }); - } + GRPC_TRACE_LOG(channel, INFO) + << LogTag() << ": WakeInsideCombiner send_initial_metadata poll=" + << PollToString(p, [](const NextResult& h) { + return (*h)->DebugString(); + }); + if (auto* nr = p.value_if_ready()) { ServerMetadataHandle md = std::move(nr->value()); if (send_initial_metadata_->batch->payload->send_initial_metadata diff --git a/src/core/lib/compression/compression_internal.cc b/src/core/lib/compression/compression_internal.cc index 6a2883f488..c643b1cd81 100644 --- a/src/core/lib/compression/compression_internal.cc +++ b/src/core/lib/compression/compression_internal.cc @@ -29,7 +29,6 @@ #include "absl/strings/str_split.h" #include -#include #include #include "src/core/lib/channel/channel_args.h" diff --git a/src/core/lib/config/config_vars.cc b/src/core/lib/config/config_vars.cc index c1bba0e4aa..e0db62f5d0 100644 --- a/src/core/lib/config/config_vars.cc +++ b/src/core/lib/config/config_vars.cc @@ -72,6 +72,10 @@ ABSL_FLAG(absl::optional, grpc_not_use_system_ssl_roots, {}, "Disable loading system root certificates."); ABSL_FLAG(absl::optional, grpc_ssl_cipher_suites, {}, "A colon separated list of cipher suites to use with OpenSSL"); +ABSL_FLAG(absl::optional, grpc_cpp_experimental_disable_reflection, {}, + "EXPERIMENTAL. Only respected when there is a dependency on " + ":grpc++_reflection. If true, no reflection server will be " + "automatically added."); namespace grpc_core { @@ -89,6 +93,10 @@ ConfigVars::ConfigVars(const Overrides& overrides) not_use_system_ssl_roots_(LoadConfig( FLAGS_grpc_not_use_system_ssl_roots, "GRPC_NOT_USE_SYSTEM_SSL_ROOTS", overrides.not_use_system_ssl_roots, false)), + cpp_experimental_disable_reflection_( + LoadConfig(FLAGS_grpc_cpp_experimental_disable_reflection, + "GRPC_CPP_EXPERIMENTAL_DISABLE_REFLECTION", + overrides.cpp_experimental_disable_reflection, false)), dns_resolver_(LoadConfig(FLAGS_grpc_dns_resolver, "GRPC_DNS_RESOLVER", overrides.dns_resolver, "")), verbosity_(LoadConfig(FLAGS_grpc_verbosity, "GRPC_VERBOSITY", @@ -136,7 +144,9 @@ std::string ConfigVars::ToString() const { "\"", ", default_ssl_roots_file_path: ", "\"", absl::CEscape(DefaultSslRootsFilePath()), "\"", ", not_use_system_ssl_roots: ", NotUseSystemSslRoots() ? "true" : "false", - ", ssl_cipher_suites: ", "\"", absl::CEscape(SslCipherSuites()), "\""); + ", ssl_cipher_suites: ", "\"", absl::CEscape(SslCipherSuites()), "\"", + ", cpp_experimental_disable_reflection: ", + CppExperimentalDisableReflection() ? "true" : "false"); } } // namespace grpc_core diff --git a/src/core/lib/config/config_vars.h b/src/core/lib/config/config_vars.h index a9410d9b76..32220cd1f1 100644 --- a/src/core/lib/config/config_vars.h +++ b/src/core/lib/config/config_vars.h @@ -38,6 +38,7 @@ class GPR_DLL ConfigVars { absl::optional enable_fork_support; absl::optional abort_on_leaks; absl::optional not_use_system_ssl_roots; + absl::optional cpp_experimental_disable_reflection; absl::optional dns_resolver; absl::optional verbosity; absl::optional poll_strategy; @@ -97,6 +98,12 @@ class GPR_DLL ConfigVars { bool NotUseSystemSslRoots() const { return not_use_system_ssl_roots_; } // A colon separated list of cipher suites to use with OpenSSL absl::string_view SslCipherSuites() const { return ssl_cipher_suites_; } + // EXPERIMENTAL. Only respected when there is a dependency on + // :grpc++_reflection. If true, no reflection server will be automatically + // added. + bool CppExperimentalDisableReflection() const { + return cpp_experimental_disable_reflection_; + } private: explicit ConfigVars(const Overrides& overrides); @@ -106,6 +113,7 @@ class GPR_DLL ConfigVars { bool enable_fork_support_; bool abort_on_leaks_; bool not_use_system_ssl_roots_; + bool cpp_experimental_disable_reflection_; std::string dns_resolver_; std::string verbosity_; std::string poll_strategy_; diff --git a/src/core/lib/config/core_configuration.cc b/src/core/lib/config/core_configuration.cc index 7baa803bb4..474ec3b56c 100644 --- a/src/core/lib/config/core_configuration.cc +++ b/src/core/lib/config/core_configuration.cc @@ -20,7 +20,6 @@ #include "absl/log/check.h" -#include #include namespace grpc_core { diff --git a/src/core/lib/config/core_configuration.h b/src/core/lib/config/core_configuration.h index 0d8b268cdd..400278bd5e 100644 --- a/src/core/lib/config/core_configuration.h +++ b/src/core/lib/config/core_configuration.h @@ -20,7 +20,6 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" -#include #include #include "src/core/handshaker/handshaker_registry.h" diff --git a/src/core/lib/debug/event_log.cc b/src/core/lib/debug/event_log.cc index 76edac8584..48dbb5809a 100644 --- a/src/core/lib/debug/event_log.cc +++ b/src/core/lib/debug/event_log.cc @@ -21,7 +21,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" -#include #include namespace grpc_core { diff --git a/src/core/lib/debug/trace_flags.cc b/src/core/lib/debug/trace_flags.cc index f3fa6c6331..85b5f6f9ee 100644 --- a/src/core/lib/debug/trace_flags.cc +++ b/src/core/lib/debug/trace_flags.cc @@ -114,6 +114,7 @@ TraceFlag subchannel_pool_trace(false, "subchannel_pool"); TraceFlag tcp_trace(false, "tcp"); TraceFlag timer_trace(false, "timer"); TraceFlag timer_check_trace(false, "timer_check"); +TraceFlag token_fetcher_credentials_trace(false, "token_fetcher_credentials"); TraceFlag tsi_trace(false, "tsi"); TraceFlag weighted_round_robin_lb_trace(false, "weighted_round_robin_lb"); TraceFlag weighted_target_lb_trace(false, "weighted_target_lb"); @@ -121,18 +122,10 @@ TraceFlag xds_client_trace(false, "xds_client"); TraceFlag xds_client_refcount_trace(false, "xds_client_refcount"); TraceFlag xds_cluster_impl_lb_trace(false, "xds_cluster_impl_lb"); TraceFlag xds_cluster_manager_lb_trace(false, "xds_cluster_manager_lb"); -TraceFlag xds_cluster_resource_type_test_trace( - true, "xds_cluster_resource_type_test"); -TraceFlag xds_common_types_test_trace(true, "xds_common_types_test"); -TraceFlag xds_endpoint_resource_type_test_trace( - true, "xds_endpoint_resource_type_test"); -TraceFlag xds_listener_resource_type_test_trace( - true, "xds_listener_resource_type_test"); TraceFlag xds_override_host_lb_trace(false, "xds_override_host_lb"); TraceFlag xds_resolver_trace(false, "xds_resolver"); -TraceFlag xds_route_config_resource_type_test_trace( - true, "xds_route_config_resource_type_test"); TraceFlag xds_server_config_fetcher_trace(false, "xds_server_config_fetcher"); +TraceFlag xds_unittest_trace(true, "xds_unittest"); TraceFlag xds_wrr_locality_lb_trace(false, "xds_wrr_locality_lb"); const absl::flat_hash_map& GetAllTraceFlags() { @@ -206,6 +199,7 @@ const absl::flat_hash_map& GetAllTraceFlags() { {"tcp", &tcp_trace}, {"timer", &timer_trace}, {"timer_check", &timer_check_trace}, + {"token_fetcher_credentials", &token_fetcher_credentials_trace}, {"tsi", &tsi_trace}, {"weighted_round_robin_lb", &weighted_round_robin_lb_trace}, {"weighted_target_lb", &weighted_target_lb_trace}, @@ -213,18 +207,10 @@ const absl::flat_hash_map& GetAllTraceFlags() { {"xds_client_refcount", &xds_client_refcount_trace}, {"xds_cluster_impl_lb", &xds_cluster_impl_lb_trace}, {"xds_cluster_manager_lb", &xds_cluster_manager_lb_trace}, - {"xds_cluster_resource_type_test", - &xds_cluster_resource_type_test_trace}, - {"xds_common_types_test", &xds_common_types_test_trace}, - {"xds_endpoint_resource_type_test", - &xds_endpoint_resource_type_test_trace}, - {"xds_listener_resource_type_test", - &xds_listener_resource_type_test_trace}, {"xds_override_host_lb", &xds_override_host_lb_trace}, {"xds_resolver", &xds_resolver_trace}, - {"xds_route_config_resource_type_test", - &xds_route_config_resource_type_test_trace}, {"xds_server_config_fetcher", &xds_server_config_fetcher_trace}, + {"xds_unittest", &xds_unittest_trace}, {"xds_wrr_locality_lb", &xds_wrr_locality_lb_trace}, #ifndef NDEBUG {"auth_context_refcount", &auth_context_refcount_trace}, diff --git a/src/core/lib/debug/trace_flags.h b/src/core/lib/debug/trace_flags.h index 4aaf5e0111..f185adb65e 100644 --- a/src/core/lib/debug/trace_flags.h +++ b/src/core/lib/debug/trace_flags.h @@ -112,6 +112,7 @@ extern TraceFlag subchannel_pool_trace; extern TraceFlag tcp_trace; extern TraceFlag timer_trace; extern TraceFlag timer_check_trace; +extern TraceFlag token_fetcher_credentials_trace; extern TraceFlag tsi_trace; extern TraceFlag weighted_round_robin_lb_trace; extern TraceFlag weighted_target_lb_trace; @@ -119,14 +120,10 @@ extern TraceFlag xds_client_trace; extern TraceFlag xds_client_refcount_trace; extern TraceFlag xds_cluster_impl_lb_trace; extern TraceFlag xds_cluster_manager_lb_trace; -extern TraceFlag xds_cluster_resource_type_test_trace; -extern TraceFlag xds_common_types_test_trace; -extern TraceFlag xds_endpoint_resource_type_test_trace; -extern TraceFlag xds_listener_resource_type_test_trace; extern TraceFlag xds_override_host_lb_trace; extern TraceFlag xds_resolver_trace; -extern TraceFlag xds_route_config_resource_type_test_trace; extern TraceFlag xds_server_config_fetcher_trace; +extern TraceFlag xds_unittest_trace; extern TraceFlag xds_wrr_locality_lb_trace; } // namespace grpc_core diff --git a/src/core/lib/debug/trace_impl.h b/src/core/lib/debug/trace_impl.h index 45d4f8cba4..4d91c374d0 100644 --- a/src/core/lib/debug/trace_impl.h +++ b/src/core/lib/debug/trace_impl.h @@ -81,10 +81,16 @@ class TraceFlag { }; #define GRPC_TRACE_FLAG_ENABLED_OBJ(obj) GPR_UNLIKELY((obj).enabled()) + #define GRPC_TRACE_FLAG_ENABLED(tracer) \ GPR_UNLIKELY((grpc_core::tracer##_trace).enabled()) + #define GRPC_TRACE_LOG(tracer, level) \ LOG_IF(level, GRPC_TRACE_FLAG_ENABLED(tracer)) + +#define GRPC_TRACE_DLOG(tracer, level) \ + DLOG_IF(level, GRPC_TRACE_FLAG_ENABLED(tracer)) + #define GRPC_TRACE_VLOG(tracer, level) \ if (GRPC_TRACE_FLAG_ENABLED(tracer)) VLOG(level) diff --git a/src/core/lib/event_engine/ares_resolver.cc b/src/core/lib/event_engine/ares_resolver.cc index 160933b99e..1cd7c73f54 100644 --- a/src/core/lib/event_engine/ares_resolver.cc +++ b/src/core/lib/event_engine/ares_resolver.cc @@ -61,7 +61,6 @@ #include "absl/types/optional.h" #include -#include #include "src/core/lib/address_utils/parse_address.h" #include "src/core/lib/address_utils/sockaddr_utils.h" @@ -97,6 +96,8 @@ absl::Status AresStatusToAbslStatus(int status, absl::string_view error_msg) { return absl::UnimplementedError(error_msg); case ARES_ENOTFOUND: return absl::NotFoundError(error_msg); + case ARES_ECONNREFUSED: + return absl::UnavailableError(error_msg); default: return absl::UnknownError(error_msg); } @@ -122,7 +123,8 @@ bool IsIpv6LoopbackAvailable() { absl::Status SetRequestDNSServer(absl::string_view dns_server, ares_channel* channel) { - GRPC_ARES_RESOLVER_TRACE_LOG("Using DNS server %s", dns_server.data()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) Using DNS server " << dns_server; grpc_resolved_address addr; struct ares_addr_port_node dns_server_addr = {}; if (grpc_parse_ipv4_hostport(dns_server, &addr, /*log_errors=*/false)) { @@ -249,8 +251,9 @@ void AresResolver::Orphan() { } for (const auto& fd_node : fd_node_list_) { if (!fd_node->already_shutdown) { - GRPC_ARES_RESOLVER_TRACE_LOG("resolver: %p shutdown fd: %s", this, - fd_node->polled_fd->GetName()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver: " << this + << " shutdown fd: " << fd_node->polled_fd->GetName(); CHECK(fd_node->polled_fd->ShutdownLocked( absl::CancelledError("AresResolver::Orphan"))); fd_node->already_shutdown = true; @@ -421,8 +424,9 @@ void AresResolver::CheckSocketsLocked() { fd_node_list_.begin(), fd_node_list_.end(), [sock = socks[i]](const auto& node) { return node->as == sock; }); if (iter == fd_node_list_.end()) { - GRPC_ARES_RESOLVER_TRACE_LOG("resolver:%p new fd: %d", this, - socks[i]); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver:" << this + << " new fd: " << socks[i]; new_list.push_back(std::make_unique( socks[i], polled_fd_factory_->NewGrpcPolledFdLocked(socks[i]))); } else { @@ -438,8 +442,9 @@ void AresResolver::CheckSocketsLocked() { // to cope with the edge-triggered poller not getting an event if no // new data arrives and c-ares hasn't read all the data in the // previous ares_process_fd. - GRPC_ARES_RESOLVER_TRACE_LOG( - "resolver:%p schedule read directly on: %d", this, fd_node->as); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver:" << this + << " schedule read directly on: " << fd_node->as; event_engine_->Run( [self = Ref(DEBUG_LOCATION, "CheckSocketsLocked"), fd_node]() mutable { @@ -448,8 +453,9 @@ void AresResolver::CheckSocketsLocked() { }); } else { // Otherwise register with the poller for readable event. - GRPC_ARES_RESOLVER_TRACE_LOG("resolver:%p notify read on: %d", this, - fd_node->as); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver:" << this + << " notify read on: " << fd_node->as; fd_node->polled_fd->RegisterForOnReadableLocked( [self = Ref(DEBUG_LOCATION, "CheckSocketsLocked"), fd_node](absl::Status status) mutable { @@ -462,8 +468,9 @@ void AresResolver::CheckSocketsLocked() { // has not been registered with this socket. if (ARES_GETSOCK_WRITABLE(socks_bitmask, i) && !fd_node->writable_registered) { - GRPC_ARES_RESOLVER_TRACE_LOG("resolver:%p notify write on: %d", this, - fd_node->as); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver:" << this + << " notify write on: " << fd_node->as; fd_node->writable_registered = true; fd_node->polled_fd->RegisterForOnWriteableLocked( [self = Ref(DEBUG_LOCATION, "CheckSocketsLocked"), @@ -485,14 +492,16 @@ void AresResolver::CheckSocketsLocked() { while (!fd_node_list_.empty()) { FdNode* fd_node = fd_node_list_.front().get(); if (!fd_node->already_shutdown) { - GRPC_ARES_RESOLVER_TRACE_LOG("resolver: %p shutdown fd: %s", this, - fd_node->polled_fd->GetName()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver: " << this + << " shutdown fd: " << fd_node->polled_fd->GetName(); fd_node->already_shutdown = fd_node->polled_fd->ShutdownLocked(absl::OkStatus()); } if (!fd_node->readable_registered && !fd_node->writable_registered) { - GRPC_ARES_RESOLVER_TRACE_LOG("resolver: %p delete fd: %s", this, - fd_node->polled_fd->GetName()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver: " << this + << " delete fd: " << fd_node->polled_fd->GetName(); fd_node_list_.pop_front(); } else { new_list.splice(new_list.end(), fd_node_list_, fd_node_list_.begin()); @@ -506,9 +515,10 @@ void AresResolver::MaybeStartTimerLocked() { return; } // Initialize the backup poll alarm - GRPC_ARES_RESOLVER_TRACE_LOG( - "request:%p MaybeStartTimerLocked next ares process poll time in %zu ms", - this, Milliseconds(kAresBackupPollAlarmDuration)); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) request:" << this + << " MaybeStartTimerLocked next ares process poll time in " + << Milliseconds(kAresBackupPollAlarmDuration) << " ms"; ares_backup_poll_alarm_handle_ = event_engine_->RunAfter( kAresBackupPollAlarmDuration, [self = Ref(DEBUG_LOCATION, "MaybeStartTimerLocked")]() { @@ -520,8 +530,9 @@ void AresResolver::OnReadable(FdNode* fd_node, absl::Status status) { grpc_core::MutexLock lock(&mutex_); CHECK(fd_node->readable_registered); fd_node->readable_registered = false; - GRPC_ARES_RESOLVER_TRACE_LOG("OnReadable: fd: %d; request: %p; status: %s", - fd_node->as, this, status.ToString().c_str()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) OnReadable: fd: " << fd_node->as + << "; request: " << this << "; status: " << status; if (status.ok() && !shutting_down_) { ares_process_fd(channel_, fd_node->as, ARES_SOCKET_BAD); } else { @@ -539,8 +550,9 @@ void AresResolver::OnWritable(FdNode* fd_node, absl::Status status) { grpc_core::MutexLock lock(&mutex_); CHECK(fd_node->writable_registered); fd_node->writable_registered = false; - GRPC_ARES_RESOLVER_TRACE_LOG("OnWritable: fd: %d; request:%p; status: %s", - fd_node->as, this, status.ToString().c_str()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) OnWritable: fd: " << fd_node->as + << "; request:" << this << "; status: " << status; if (status.ok() && !shutting_down_) { ares_process_fd(channel_, ARES_SOCKET_BAD, fd_node->as); } else { @@ -565,15 +577,16 @@ void AresResolver::OnWritable(FdNode* fd_node, absl::Status status) { void AresResolver::OnAresBackupPollAlarm() { grpc_core::MutexLock lock(&mutex_); ares_backup_poll_alarm_handle_.reset(); - GRPC_ARES_RESOLVER_TRACE_LOG( - "request:%p OnAresBackupPollAlarm shutting_down=%d.", this, - shutting_down_); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) request:" << this + << " OnAresBackupPollAlarm shutting_down=" << shutting_down_; if (!shutting_down_) { for (const auto& fd_node : fd_node_list_) { if (!fd_node->already_shutdown) { - GRPC_ARES_RESOLVER_TRACE_LOG( - "request:%p OnAresBackupPollAlarm; ares_process_fd. fd=%s", this, - fd_node->polled_fd->GetName()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) request:" << this + << " OnAresBackupPollAlarm; ares_process_fd. fd=" + << fd_node->polled_fd->GetName(); ares_socket_t as = fd_node->polled_fd->GetWrappedAresSocketLocked(); ares_process_fd(channel_, as, as); } @@ -593,13 +606,15 @@ void AresResolver::OnHostbynameDoneLocked(void* arg, int status, std::string error_msg = absl::StrFormat("address lookup failed for %s: %s", hostname_qa->query_name, ares_strerror(status)); - GRPC_ARES_RESOLVER_TRACE_LOG("resolver:%p OnHostbynameDoneLocked: %s", - ares_resolver, error_msg.c_str()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver:" << ares_resolver + << " OnHostbynameDoneLocked: " << error_msg; hostname_qa->error_status = AresStatusToAbslStatus(status, error_msg); } else { - GRPC_ARES_RESOLVER_TRACE_LOG( - "resolver:%p OnHostbynameDoneLocked name=%s ARES_SUCCESS", - ares_resolver, hostname_qa->query_name.c_str()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver:" << ares_resolver + << " OnHostbynameDoneLocked name=" << hostname_qa->query_name + << " ARES_SUCCESS"; for (size_t i = 0; hostent->h_addr_list[i] != nullptr; i++) { if (hostname_qa->result.size() == kMaxRecordSize) { LOG(ERROR) << "A/AAAA response exceeds maximum record size of 65536"; @@ -618,10 +633,11 @@ void AresResolver::OnHostbynameDoneLocked(void* arg, int status, reinterpret_cast(&addr), addr_len); char output[INET6_ADDRSTRLEN]; ares_inet_ntop(AF_INET6, &addr.sin6_addr, output, INET6_ADDRSTRLEN); - GRPC_ARES_RESOLVER_TRACE_LOG( - "resolver:%p c-ares resolver gets a AF_INET6 result: \n" - " addr: %s\n port: %d\n sin6_scope_id: %d\n", - ares_resolver, output, hostname_qa->port, addr.sin6_scope_id); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver:" << ares_resolver + << " c-ares resolver gets a AF_INET6 result: \n addr: " << output + << "\n port: " << hostname_qa->port + << "\n sin6_scope_id: " << addr.sin6_scope_id; break; } case AF_INET: { @@ -636,10 +652,10 @@ void AresResolver::OnHostbynameDoneLocked(void* arg, int status, reinterpret_cast(&addr), addr_len); char output[INET_ADDRSTRLEN]; ares_inet_ntop(AF_INET, &addr.sin_addr, output, INET_ADDRSTRLEN); - GRPC_ARES_RESOLVER_TRACE_LOG( - "resolver:%p c-ares resolver gets a AF_INET result: \n" - " addr: %s\n port: %d\n", - ares_resolver, output, hostname_qa->port); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver:" << ares_resolver + << " c-ares resolver gets a AF_INET result: \n addr: " << output + << "\n port: " << hostname_qa->port; break; } default: @@ -687,8 +703,9 @@ void AresResolver::OnSRVQueryDoneLocked(void* arg, int status, int /*timeouts*/, auto fail = [&](absl::string_view prefix) { std::string error_message = absl::StrFormat( "%s for %s: %s", prefix, qa->query_name, ares_strerror(status)); - GRPC_ARES_RESOLVER_TRACE_LOG("OnSRVQueryDoneLocked: %s", - error_message.c_str()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) OnSRVQueryDoneLocked: " + << error_message; ares_resolver->event_engine_->Run( [callback = std::move(callback), status = AresStatusToAbslStatus(status, error_message)]() mutable { @@ -699,13 +716,14 @@ void AresResolver::OnSRVQueryDoneLocked(void* arg, int status, int /*timeouts*/, fail("SRV lookup failed"); return; } - GRPC_ARES_RESOLVER_TRACE_LOG( - "resolver:%p OnSRVQueryDoneLocked name=%s ARES_SUCCESS", ares_resolver, - qa->query_name.c_str()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver:" << ares_resolver + << " OnSRVQueryDoneLocked name=" << qa->query_name << " ARES_SUCCESS"; struct ares_srv_reply* reply = nullptr; status = ares_parse_srv_reply(abuf, alen, &reply); - GRPC_ARES_RESOLVER_TRACE_LOG("resolver:%p ares_parse_srv_reply: %d", - ares_resolver, status); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver:" << ares_resolver + << " ares_parse_srv_reply: " << status; if (status != ARES_SUCCESS) { fail("Failed to parse SRV reply"); return; @@ -746,8 +764,9 @@ void AresResolver::OnTXTDoneLocked(void* arg, int status, int /*timeouts*/, auto fail = [&](absl::string_view prefix) { std::string error_message = absl::StrFormat( "%s for %s: %s", prefix, qa->query_name, ares_strerror(status)); - GRPC_ARES_RESOLVER_TRACE_LOG("resolver:%p OnTXTDoneLocked: %s", - ares_resolver, error_message.c_str()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver:" << ares_resolver + << " OnTXTDoneLocked: " << error_message; ares_resolver->event_engine_->Run( [callback = std::move(callback), status = AresStatusToAbslStatus(status, error_message)]() mutable { @@ -758,9 +777,9 @@ void AresResolver::OnTXTDoneLocked(void* arg, int status, int /*timeouts*/, fail("TXT lookup failed"); return; } - GRPC_ARES_RESOLVER_TRACE_LOG( - "resolver:%p OnTXTDoneLocked name=%s ARES_SUCCESS", ares_resolver, - qa->query_name.c_str()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver:" << ares_resolver + << " OnTXTDoneLocked name=" << qa->query_name << " ARES_SUCCESS"; struct ares_txt_ext* reply = nullptr; status = ares_parse_txt_reply_ext(buf, len, &reply); if (status != ARES_SUCCESS) { @@ -777,8 +796,9 @@ void AresResolver::OnTXTDoneLocked(void* arg, int status, int /*timeouts*/, std::string(reinterpret_cast(part->txt), part->length)); } } - GRPC_ARES_RESOLVER_TRACE_LOG("resolver:%p Got %zu TXT records", ares_resolver, - result.size()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) resolver:" << ares_resolver << " Got " + << result.size() << " TXT records"; if (GRPC_TRACE_FLAG_ENABLED(cares_resolver)) { for (const auto& record : result) { LOG(INFO) << record; diff --git a/src/core/lib/event_engine/ares_resolver.h b/src/core/lib/event_engine/ares_resolver.h index 68812e59a4..c36cf49f76 100644 --- a/src/core/lib/event_engine/ares_resolver.h +++ b/src/core/lib/event_engine/ares_resolver.h @@ -37,7 +37,6 @@ #include "absl/types/variant.h" #include -#include #include "src/core/lib/event_engine/grpc_polled_fd.h" #include "src/core/lib/event_engine/ref_counted_dns_resolver_interface.h" @@ -47,14 +46,6 @@ namespace grpc_event_engine { namespace experimental { -#define GRPC_ARES_RESOLVER_TRACE_LOG(format, ...) \ - do { \ - if (GRPC_TRACE_FLAG_ENABLED(cares_resolver)) { \ - LOG(INFO) << "(EventEngine c-ares resolver) " \ - << absl::StrFormat(format, __VA_ARGS__); \ - } \ - } while (0) - class AresResolver : public RefCountedDNSResolverInterface { public: static absl::StatusOr> diff --git a/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc b/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc index 337a5bc5a2..4721437860 100644 --- a/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +++ b/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc @@ -331,9 +331,22 @@ void CFStreamEndpointImpl::DoWrite( size_t total_written_size = 0; for (size_t i = 0; i < data->Count(); i++) { auto slice = data->RefSlice(i); - size_t written_size = + if (slice.size() == 0) { + continue; + } + + CFIndex written_size = CFWriteStreamWrite(cf_write_stream_, slice.begin(), slice.size()); + if (written_size < 0) { + auto status = CFErrorToStatus(CFWriteStreamCopyError(cf_write_stream_)); + GRPC_TRACE_LOG(event_engine_endpoint, INFO) + << "CFStream write error: " << status + << ", written_size: " << written_size; + on_writable(status); + return; + } + total_written_size += written_size; if (written_size < slice.size()) { SliceBuffer written; diff --git a/src/core/lib/event_engine/cf_engine/cftype_unique_ref.h b/src/core/lib/event_engine/cf_engine/cftype_unique_ref.h index 04953cade2..5deb68f327 100644 --- a/src/core/lib/event_engine/cf_engine/cftype_unique_ref.h +++ b/src/core/lib/event_engine/cf_engine/cftype_unique_ref.h @@ -37,7 +37,7 @@ class CFTypeUniqueRef { CFTypeUniqueRef(CFTypeUniqueRef const&) = delete; CFTypeUniqueRef& operator=(CFTypeUniqueRef const&) = delete; - CFTypeUniqueRef(CFTypeUniqueRef&& other) : cf_type_ref_(other.release()){}; + CFTypeUniqueRef(CFTypeUniqueRef&& other) : cf_type_ref_(other.release()) {}; CFTypeUniqueRef& operator=(CFTypeUniqueRef&& other) { reset(other.release()); return *this; diff --git a/src/core/lib/event_engine/forkable.cc b/src/core/lib/event_engine/forkable.cc index c096ceb778..0034cbbd92 100644 --- a/src/core/lib/event_engine/forkable.cc +++ b/src/core/lib/event_engine/forkable.cc @@ -16,7 +16,6 @@ #include "absl/log/check.h" -#include #include #ifdef GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK diff --git a/src/core/lib/event_engine/forkable.h b/src/core/lib/event_engine/forkable.h index cf8edac8e6..414947b751 100644 --- a/src/core/lib/event_engine/forkable.h +++ b/src/core/lib/event_engine/forkable.h @@ -17,7 +17,6 @@ #include #include -#include #include #include "src/core/lib/debug/trace.h" diff --git a/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc b/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc index c990fe4023..402822e27e 100644 --- a/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +++ b/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc @@ -358,7 +358,7 @@ Epoll1Poller::Epoll1Poller(Scheduler* scheduler) CHECK_GE(g_epoll_set_.epfd, 0); GRPC_TRACE_LOG(event_engine_poller, INFO) << "grpc epoll fd: " << g_epoll_set_.epfd; - struct epoll_event ev; + struct epoll_event ev {}; ev.events = static_cast(EPOLLIN | EPOLLET); ev.data.ptr = wakeup_fd_.get(); CHECK(epoll_ctl(g_epoll_set_.epfd, EPOLL_CTL_ADD, wakeup_fd_->ReadFd(), diff --git a/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.h b/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.h index 0bd86a7296..ed6b480bde 100644 --- a/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.h +++ b/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.h @@ -102,17 +102,17 @@ class Epoll1Poller : public PosixEventPoller { friend class Epoll1EventHandle; #ifdef GRPC_LINUX_EPOLL struct EpollSet { - int epfd; + int epfd = -1; // The epoll_events after the last call to epoll_wait() - struct epoll_event events[MAX_EPOLL_EVENTS]; + struct epoll_event events[MAX_EPOLL_EVENTS]{}; // The number of epoll_events after the last call to epoll_wait() - int num_events; + int num_events = 0; // Index of the first event in epoll_events that has to be processed. This // field is only valid if num_events > 0 - int cursor; + int cursor = 0; }; #else struct EpollSet {}; diff --git a/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc b/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc index 3f383e663b..e573be3064 100644 --- a/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +++ b/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc @@ -30,7 +30,6 @@ #include #include -#include #include #include #include diff --git a/src/core/lib/event_engine/posix_engine/lockfree_event.cc b/src/core/lib/event_engine/posix_engine/lockfree_event.cc index f95969bc69..dc7900646a 100644 --- a/src/core/lib/event_engine/posix_engine/lockfree_event.cc +++ b/src/core/lib/event_engine/posix_engine/lockfree_event.cc @@ -20,7 +20,6 @@ #include "absl/status/status.h" #include -#include #include #include "src/core/lib/event_engine/posix_engine/event_poller.h" 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 41fcc89a8b..7634bb1334 100644 --- a/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +++ b/src/core/lib/event_engine/posix_engine/posix_endpoint.cc @@ -348,7 +348,6 @@ bool PosixEndpointImpl::TcpDoRead(absl::Status& status) { // We have read something in previous reads. We need to deliver those bytes // to the upper layer. if (read_bytes <= 0 && total_read_bytes >= 1) { - inq_ = 1; break; } @@ -410,6 +409,12 @@ bool PosixEndpointImpl::TcpDoRead(absl::Status& status) { if (inq_ == 0) { FinishEstimate(); + // If this is using the epoll poller, then it is edge-triggered. + // Since this read did not consume the edge (i.e., did not get EAGAIN), the + // next read on this endpoint must assume there is something to read. + // Otherwise, assuming there is nothing to read and waiting for an epoll + // edge event could cause the next read to wait indefinitely. + inq_ = 1; } DCHECK_GT(total_read_bytes, 0u); 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 0c42a5467c..80964556b0 100644 --- a/src/core/lib/event_engine/posix_engine/posix_endpoint.h +++ b/src/core/lib/event_engine/posix_engine/posix_endpoint.h @@ -38,7 +38,6 @@ #include #include #include -#include #include "src/core/lib/event_engine/extensions/supports_fd.h" #include "src/core/lib/event_engine/posix.h" diff --git a/src/core/lib/event_engine/posix_engine/posix_engine_listener.h b/src/core/lib/event_engine/posix_engine/posix_engine_listener.h index 5a15129ddb..73a921a35e 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine_listener.h +++ b/src/core/lib/event_engine/posix_engine/posix_engine_listener.h @@ -93,7 +93,7 @@ class PosixEngineListenerImpl ResolvedAddressToNormalizedString(socket_.addr), listener_->poller_->CanTrackErrors())), notify_on_accept_(PosixEngineClosure::ToPermanentClosure( - [this](absl::Status status) { NotifyOnAccept(status); })){}; + [this](absl::Status status) { NotifyOnAccept(status); })) {}; // Start listening for incoming connections on the socket. void Start(); // Internal callback invoked when the socket has incoming connections to @@ -129,7 +129,7 @@ class PosixEngineListenerImpl class ListenerAsyncAcceptors : public ListenerSocketsContainer { public: explicit ListenerAsyncAcceptors(PosixEngineListenerImpl* listener) - : listener_(listener){}; + : listener_(listener) {}; void UpdateOnAppendCallback( PosixListenerWithFdSupport::OnPosixBindNewFdCallback on_append) { diff --git a/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h b/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h index 15f6c5d88d..412fafcad3 100644 --- a/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +++ b/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -164,7 +163,7 @@ class PosixSocketWrapper { public: explicit PosixSocketWrapper(int fd) : fd_(fd) { CHECK_GT(fd_, 0); } - PosixSocketWrapper() : fd_(-1){}; + PosixSocketWrapper() : fd_(-1) {}; ~PosixSocketWrapper() = default; diff --git a/src/core/lib/event_engine/posix_engine/timer_manager.cc b/src/core/lib/event_engine/posix_engine/timer_manager.cc index 3ab3eb75f4..8a0373cf86 100644 --- a/src/core/lib/event_engine/posix_engine/timer_manager.cc +++ b/src/core/lib/event_engine/posix_engine/timer_manager.cc @@ -118,17 +118,13 @@ void TimerManager::Shutdown() { { grpc_core::MutexLock lock(&mu_); if (shutdown_) return; - if (GRPC_TRACE_FLAG_ENABLED(timer)) { - VLOG(2) << "TimerManager::" << this << " shutting down"; - } + GRPC_TRACE_VLOG(timer, 2) << "TimerManager::" << this << " shutting down"; shutdown_ = true; // Wait on the main loop to exit. cv_wait_.Signal(); } main_loop_exit_signal_->WaitForNotification(); - if (GRPC_TRACE_FLAG_ENABLED(timer)) { - VLOG(2) << "TimerManager::" << this << " shutdown complete"; - } + GRPC_TRACE_VLOG(timer, 2) << "TimerManager::" << this << " shutdown complete"; } TimerManager::~TimerManager() { Shutdown(); } @@ -144,9 +140,8 @@ void TimerManager::Kick() { void TimerManager::RestartPostFork() { grpc_core::MutexLock lock(&mu_); CHECK(GPR_LIKELY(shutdown_)); - if (GRPC_TRACE_FLAG_ENABLED(timer)) { - VLOG(2) << "TimerManager::" << this << " restarting after shutdown"; - } + GRPC_TRACE_VLOG(timer, 2) + << "TimerManager::" << this << " restarting after shutdown"; shutdown_ = false; main_loop_exit_signal_.emplace(); thread_pool_->Run([this]() { MainLoop(); }); 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 1171cb7662..d4cdfac8b7 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 @@ -24,7 +24,6 @@ #include "absl/functional/any_invocable.h" #include "absl/log/log.h" -#include #include #include diff --git a/src/core/lib/event_engine/resolved_address.cc b/src/core/lib/event_engine/resolved_address.cc index d6e01da006..95c37586ae 100644 --- a/src/core/lib/event_engine/resolved_address.cc +++ b/src/core/lib/event_engine/resolved_address.cc @@ -19,7 +19,6 @@ #include "absl/log/check.h" #include -#include #include #include "src/core/lib/event_engine/resolved_address_internal.h" diff --git a/src/core/lib/event_engine/slice.cc b/src/core/lib/event_engine/slice.cc index 51563f4a0c..7d4a6c4a05 100644 --- a/src/core/lib/event_engine/slice.cc +++ b/src/core/lib/event_engine/slice.cc @@ -23,7 +23,6 @@ #include #include -#include #include #include "src/core/lib/slice/slice_internal.h" diff --git a/src/core/lib/event_engine/thread_pool/thread_count.cc b/src/core/lib/event_engine/thread_pool/thread_count.cc index 9148b1a5d2..6fc6a43c21 100644 --- a/src/core/lib/event_engine/thread_pool/thread_count.cc +++ b/src/core/lib/event_engine/thread_pool/thread_count.cc @@ -23,7 +23,6 @@ #include "absl/time/clock.h" #include "absl/time/time.h" -#include #include #include "src/core/lib/gprpp/time.h" diff --git a/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc b/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc index 37a8f85cc5..b9542b0bb6 100644 --- a/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc +++ b/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc @@ -82,7 +82,7 @@ grpc_slice FlattenIovec(const struct iovec* iov, int iov_count) { // instantiated at the top of the virtual socket function callstack. class WSAErrorContext { public: - explicit WSAErrorContext(){}; + explicit WSAErrorContext() {}; ~WSAErrorContext() { if (error_ != 0) { @@ -128,9 +128,9 @@ class GrpcPolledFdWindows : public GrpcPolledFd { event_engine_(event_engine) {} ~GrpcPolledFdWindows() override { - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| ~GrpcPolledFdWindows shutdown_called_: %d ", GetName(), - shutdown_called_); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:|" << GetName() + << "| ~GrpcPolledFdWindows shutdown_called_: " << shutdown_called_; grpc_core::CSliceUnref(read_buf_); grpc_core::CSliceUnref(write_buf_); CHECK(read_closure_ == nullptr); @@ -158,14 +158,16 @@ class GrpcPolledFdWindows : public GrpcPolledFd { void RegisterForOnWriteableLocked( absl::AnyInvocable write_closure) override { if (socket_type_ == SOCK_DGRAM) { - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| RegisterForOnWriteableLocked called", GetName()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:|" << GetName() + << "| RegisterForOnWriteableLocked called"; } else { CHECK(socket_type_ == SOCK_STREAM); - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| RegisterForOnWriteableLocked called tcp_write_state_: %d " - "connect_done_: %d", - GetName(), tcp_write_state_, connect_done_); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:|" << GetName() + << "| RegisterForOnWriteableLocked called tcp_write_state_: " + << static_cast(tcp_write_state_) + << " connect_done_: " << connect_done_; } CHECK(write_closure_ == nullptr); write_closure_ = std::move(write_closure); @@ -184,7 +186,8 @@ class GrpcPolledFdWindows : public GrpcPolledFd { if (!absl::IsCancelled(error)) { return false; } - GRPC_ARES_RESOLVER_TRACE_LOG("fd:|%s| ShutdownLocked", GetName()); + GRPC_TRACE_LOG(cares_resolver, INFO) << "(EventEngine c-ares resolver) fd:|" + << GetName() << "| ShutdownLocked"; shutdown_called_ = true; // The socket is disconnected and closed here since this is an external // cancel request, e.g. a timeout. c-ares shouldn't do anything on the @@ -203,10 +206,10 @@ class GrpcPolledFdWindows : public GrpcPolledFd { ares_ssize_t RecvFrom(WSAErrorContext* wsa_error_ctx, void* data, ares_socket_t data_len, int /* flags */, struct sockaddr* from, ares_socklen_t* from_len) { - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| RecvFrom called read_buf_has_data:%d Current read buf " - "length:|%d|", - GetName(), read_buf_has_data_, GRPC_SLICE_LENGTH(read_buf_)); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:" << GetName() + << " RecvFrom called read_buf_has_data:" << read_buf_has_data_ + << " Current read buf length:" << GRPC_SLICE_LENGTH(read_buf_); if (!read_buf_has_data_) { wsa_error_ctx->SetWSAError(WSAEWOULDBLOCK); return -1; @@ -233,9 +236,10 @@ class GrpcPolledFdWindows : public GrpcPolledFd { ares_ssize_t SendV(WSAErrorContext* wsa_error_ctx, const struct iovec* iov, int iov_count) { - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| SendV called connect_done_:%d wsa_connect_error_:%d", - GetName(), connect_done_, wsa_connect_error_); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:|" << GetName() + << "| SendV called connect_done_:" << connect_done_ + << " wsa_connect_error_:" << wsa_connect_error_; if (!connect_done_) { wsa_error_ctx->SetWSAError(WSAEWOULDBLOCK); return -1; @@ -288,10 +292,10 @@ class GrpcPolledFdWindows : public GrpcPolledFd { } void ContinueRegisterForOnReadableLocked() { - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| ContinueRegisterForOnReadableLocked " - "wsa_connect_error_:%d", - GetName(), wsa_connect_error_); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:|" << GetName() + << "| ContinueRegisterForOnReadableLocked wsa_connect_error_:" + << wsa_connect_error_; CHECK(connect_done_); if (wsa_connect_error_ != 0) { ScheduleAndNullReadClosure(GRPC_WSA_ERROR(wsa_connect_error_, "connect")); @@ -309,11 +313,11 @@ class GrpcPolledFdWindows : public GrpcPolledFd { winsocket_->read_info()->overlapped(), nullptr) != 0) { int wsa_last_error = WSAGetLastError(); char* msg = gpr_format_message(wsa_last_error); - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| ContinueRegisterForOnReadableLocked WSARecvFrom error " - "code:|%d| " - "msg:|%s|", - GetName(), wsa_last_error, msg); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:" << GetName() + << " ContinueRegisterForOnReadableLocked WSARecvFrom error " + "code:" + << wsa_last_error << " msg:" << msg; gpr_free(msg); if (wsa_last_error != WSA_IO_PENDING) { winsocket_->UnregisterReadCallback(); @@ -325,10 +329,10 @@ class GrpcPolledFdWindows : public GrpcPolledFd { } void ContinueRegisterForOnWriteableLocked() { - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| ContinueRegisterForOnWriteableLocked " - "wsa_connect_error_:%d", - GetName(), wsa_connect_error_); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:|" << GetName() + << "| ContinueRegisterForOnWriteableLocked wsa_connect_error_:" + << wsa_connect_error_; CHECK(connect_done_); if (wsa_connect_error_ != 0) { ScheduleAndNullWriteClosure( @@ -372,12 +376,12 @@ class GrpcPolledFdWindows : public GrpcPolledFd { int out = WSASend(winsocket_->raw_socket(), &buf, 1, bytes_sent_ptr, flags, overlapped, nullptr); *wsa_error_code = WSAGetLastError(); - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| SendWriteBuf WSASend buf.len:%d *bytes_sent_ptr:%d " - "overlapped:%p " - "return:%d *wsa_error_code:%d", - GetName(), buf.len, bytes_sent_ptr != nullptr ? *bytes_sent_ptr : 0, - overlapped, out, *wsa_error_code); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:" << GetName() + << " SendWriteBuf WSASend buf.len:" << buf.len << " *bytes_sent_ptr:" + << (bytes_sent_ptr != nullptr ? *bytes_sent_ptr : 0) + << " overlapped:" << overlapped << " return:" << out + << " *wsa_error_code:" << *wsa_error_code; return out; } @@ -386,7 +390,8 @@ class GrpcPolledFdWindows : public GrpcPolledFd { // c-ares doesn't handle retryable errors on writes of UDP sockets. // Therefore, the sendv handler for UDP sockets must only attempt // to write everything inline. - GRPC_ARES_RESOLVER_TRACE_LOG("fd:|%s| SendVUDP called", GetName()); + GRPC_TRACE_LOG(cares_resolver, INFO) << "(EventEngine c-ares resolver) fd:|" + << GetName() << "| SendVUDP called"; CHECK_EQ(GRPC_SLICE_LENGTH(write_buf_), 0); grpc_core::CSliceUnref(write_buf_); write_buf_ = FlattenIovec(iov, iov_count); @@ -397,9 +402,10 @@ class GrpcPolledFdWindows : public GrpcPolledFd { write_buf_ = grpc_empty_slice(); wsa_error_ctx->SetWSAError(wsa_error_code); char* msg = gpr_format_message(wsa_error_code); - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| SendVUDP SendWriteBuf error code:%d msg:|%s|", GetName(), - wsa_error_code, msg); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:|" << GetName() + << "| SendVUDP SendWriteBuf error code:" << wsa_error_code << " msg:|" + << msg << "|"; gpr_free(msg); return -1; } @@ -415,8 +421,10 @@ class GrpcPolledFdWindows : public GrpcPolledFd { // out in the background, and making further send progress in general, will // happen as long as c-ares continues to show interest in writeability on // this fd. - GRPC_ARES_RESOLVER_TRACE_LOG("fd:|%s| SendVTCP called tcp_write_state_:%d", - GetName(), tcp_write_state_); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:|" << GetName() + << "| SendVTCP called tcp_write_state_:" + << static_cast(tcp_write_state_); switch (tcp_write_state_) { case WRITE_IDLE: tcp_write_state_ = WRITE_REQUESTED; @@ -453,12 +461,12 @@ class GrpcPolledFdWindows : public GrpcPolledFd { void OnTcpConnect() { grpc_core::MutexLock lock(mu_); - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:%s InnerOnTcpConnectLocked " - "pending_register_for_readable:%d" - " pending_register_for_writeable:%d", - GetName(), pending_continue_register_for_on_readable_locked_, - pending_continue_register_for_on_writeable_locked_); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:" << GetName() + << " InnerOnTcpConnectLocked pending_register_for_readable:" + << pending_continue_register_for_on_readable_locked_ + << " pending_register_for_writeable:" + << pending_continue_register_for_on_writeable_locked_; CHECK(!connect_done_); connect_done_ = true; CHECK_EQ(wsa_connect_error_, 0); @@ -474,10 +482,10 @@ class GrpcPolledFdWindows : public GrpcPolledFd { if (!wsa_success) { wsa_connect_error_ = WSAGetLastError(); char* msg = gpr_format_message(wsa_connect_error_); - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:%s InnerOnTcpConnectLocked WSA overlapped result code:%d " - "msg:|%s|", - GetName(), wsa_connect_error_, msg); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:" << GetName() + << " InnerOnTcpConnectLocked WSA overlapped result code:" + << wsa_connect_error_ << " msg:|" << msg << "|"; gpr_free(msg); } } @@ -491,7 +499,8 @@ class GrpcPolledFdWindows : public GrpcPolledFd { int ConnectUDP(WSAErrorContext* wsa_error_ctx, const struct sockaddr* target, ares_socklen_t target_len) { - GRPC_ARES_RESOLVER_TRACE_LOG("fd:%s ConnectUDP", GetName()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:" << GetName() << " ConnectUDP"; CHECK(!connect_done_); CHECK_EQ(wsa_connect_error_, 0); SOCKET s = winsocket_->raw_socket(); @@ -501,8 +510,10 @@ class GrpcPolledFdWindows : public GrpcPolledFd { wsa_error_ctx->SetWSAError(wsa_connect_error_); connect_done_ = true; char* msg = gpr_format_message(wsa_connect_error_); - GRPC_ARES_RESOLVER_TRACE_LOG("fd:%s WSAConnect error code:|%d| msg:|%s|", - GetName(), wsa_connect_error_, msg); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:" << GetName() + << " WSAConnect error code:|" << wsa_connect_error_ << "| msg:|" << msg + << "|"; gpr_free(msg); // c-ares expects a posix-style connect API return out == 0 ? 0 : -1; @@ -510,7 +521,8 @@ class GrpcPolledFdWindows : public GrpcPolledFd { int ConnectTCP(WSAErrorContext* wsa_error_ctx, const struct sockaddr* target, ares_socklen_t target_len) { - GRPC_ARES_RESOLVER_TRACE_LOG("fd:%s ConnectTCP", GetName()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:" << GetName() << " ConnectTCP"; LPFN_CONNECTEX ConnectEx; GUID guid = WSAID_CONNECTEX; DWORD ioctl_num_bytes; @@ -521,10 +533,10 @@ class GrpcPolledFdWindows : public GrpcPolledFd { int wsa_last_error = WSAGetLastError(); wsa_error_ctx->SetWSAError(wsa_last_error); char* msg = gpr_format_message(wsa_last_error); - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:%s WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER) error code:%d " - "msg:|%s|", - GetName(), wsa_last_error, msg); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:" << GetName() + << " WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER) error code:" + << wsa_last_error << " msg:|" << msg << "|"; gpr_free(msg); connect_done_ = true; wsa_connect_error_ = wsa_last_error; @@ -544,8 +556,9 @@ class GrpcPolledFdWindows : public GrpcPolledFd { int wsa_last_error = WSAGetLastError(); wsa_error_ctx->SetWSAError(wsa_last_error); char* msg = gpr_format_message(wsa_last_error); - GRPC_ARES_RESOLVER_TRACE_LOG("fd:%s bind error code:%d msg:|%s|", - GetName(), wsa_last_error, msg); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:" << GetName() + << " bind error code:" << wsa_last_error << " msg:|" << msg << "|"; gpr_free(msg); connect_done_ = true; wsa_connect_error_ = wsa_last_error; @@ -561,8 +574,10 @@ class GrpcPolledFdWindows : public GrpcPolledFd { int wsa_last_error = WSAGetLastError(); wsa_error_ctx->SetWSAError(wsa_last_error); char* msg = gpr_format_message(wsa_last_error); - GRPC_ARES_RESOLVER_TRACE_LOG("fd:%s ConnectEx error code:%d msg:|%s|", - GetName(), wsa_last_error, msg); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:" << GetName() + << " ConnectEx error code:" << wsa_last_error << " msg:|" << msg + << "|"; gpr_free(msg); if (wsa_last_error == WSA_IO_PENDING) { // c-ares only understands WSAEINPROGRESS and EWOULDBLOCK error codes on @@ -597,11 +612,12 @@ class GrpcPolledFdWindows : public GrpcPolledFd { if (winsocket_->read_info()->result().wsa_error != WSAEMSGSIZE) { error = GRPC_WSA_ERROR(winsocket_->read_info()->result().wsa_error, "OnIocpReadableInner"); - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| OnIocpReadableInner winsocket_->read_info.wsa_error " - "code:|%d| msg:|%s|", - GetName(), winsocket_->read_info()->result().wsa_error, - grpc_core::StatusToString(error).c_str()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:|" << GetName() + << "| OnIocpReadableInner winsocket_->read_info.wsa_error " + "code:|" + << winsocket_->read_info()->result().wsa_error << "| msg:|" + << grpc_core::StatusToString(error) << "|"; } } if (error.ok()) { @@ -612,34 +628,40 @@ class GrpcPolledFdWindows : public GrpcPolledFd { grpc_core::CSliceUnref(read_buf_); read_buf_ = grpc_empty_slice(); } - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| OnIocpReadable finishing. read buf length now:|%d|", GetName(), - GRPC_SLICE_LENGTH(read_buf_)); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:|" << GetName() + << "| OnIocpReadable finishing. read buf length now:|" + << GRPC_SLICE_LENGTH(read_buf_) << "|"; ScheduleAndNullReadClosure(error); } void OnIocpWriteable() { grpc_core::MutexLock lock(mu_); - GRPC_ARES_RESOLVER_TRACE_LOG("OnIocpWriteableInner. fd:|%s|", GetName()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) OnIocpWriteableInner. fd:|" + << GetName() << "|"; CHECK(socket_type_ == SOCK_STREAM); absl::Status error; if (winsocket_->write_info()->result().wsa_error != 0) { error = GRPC_WSA_ERROR(winsocket_->write_info()->result().wsa_error, "OnIocpWriteableInner"); - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| OnIocpWriteableInner. winsocket_->write_info.wsa_error " - "code:|%d| msg:|%s|", - GetName(), winsocket_->write_info()->result().wsa_error, - grpc_core::StatusToString(error).c_str()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:|" << GetName() + << "| OnIocpWriteableInner. winsocket_->write_info.wsa_error " + "code:|" + << winsocket_->write_info()->result().wsa_error << "| msg:|" + << grpc_core::StatusToString(error) << "|"; } CHECK(tcp_write_state_ == WRITE_PENDING); if (error.ok()) { tcp_write_state_ = WRITE_WAITING_FOR_VERIFICATION_UPON_RETRY; write_buf_ = grpc_slice_sub_no_ref( write_buf_, 0, winsocket_->write_info()->result().bytes_transferred); - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| OnIocpWriteableInner. bytes transferred:%d", GetName(), - winsocket_->write_info()->result().bytes_transferred); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:|" << GetName() + << "| OnIocpWriteableInner. bytes transferred:" + << winsocket_->write_info()->result().bytes_transferred; + } else { grpc_core::CSliceUnref(write_buf_); write_buf_ = grpc_empty_slice(); @@ -686,8 +708,10 @@ class CustomSockFuncs { public: static ares_socket_t Socket(int af, int type, int protocol, void* user_data) { if (type != SOCK_DGRAM && type != SOCK_STREAM) { - GRPC_ARES_RESOLVER_TRACE_LOG("Socket called with invalid socket type:%d", - type); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) Socket called with invalid socket " + "type:" + << type; return INVALID_SOCKET; } GrpcPolledFdFactoryWindows* self = @@ -695,24 +719,26 @@ class CustomSockFuncs { SOCKET s = WSASocket(af, type, protocol, nullptr, 0, IOCP::GetDefaultSocketFlags()); if (s == INVALID_SOCKET) { - GRPC_ARES_RESOLVER_TRACE_LOG( - "WSASocket failed with params af:%d type:%d protocol:%d", af, type, - protocol); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) WSASocket failed with params af:" + << af << " type:" << type << " protocol:" << protocol; return INVALID_SOCKET; } if (type == SOCK_STREAM) { absl::Status error = PrepareSocket(s); if (!error.ok()) { - GRPC_ARES_RESOLVER_TRACE_LOG("WSAIoctl failed with error: %s", - grpc_core::StatusToString(error).c_str()); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) WSAIoctl failed with error: " + << grpc_core::StatusToString(error); return INVALID_SOCKET; } } auto polled_fd = std::make_unique( self->iocp_->Watch(s), self->mu_, af, type, self->event_engine_); - GRPC_ARES_RESOLVER_TRACE_LOG( - "fd:|%s| created with params af:%d type:%d protocol:%d", - polled_fd->GetName(), af, type, protocol); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) fd:" << polled_fd->GetName() + << " created with params af:" << af << " type:" << type + << " protocol:" << protocol; CHECK(self->sockets_.insert({s, std::move(polled_fd)}).second); return s; } @@ -750,7 +776,9 @@ class CustomSockFuncs { } static int CloseSocket(SOCKET s, void*) { - GRPC_ARES_RESOLVER_TRACE_LOG("c-ares socket: %d CloseSocket", s); + GRPC_TRACE_LOG(cares_resolver, INFO) + << "(EventEngine c-ares resolver) c-ares socket: " << s + << " CloseSocket"; return 0; } }; diff --git a/src/core/lib/experiments/config.cc b/src/core/lib/experiments/config.cc index a9d93f7fe8..ac1cf88386 100644 --- a/src/core/lib/experiments/config.cc +++ b/src/core/lib/experiments/config.cc @@ -220,6 +220,11 @@ bool IsTestExperimentEnabled(size_t experiment_id) { return (*g_test_experiments)[experiment_id]; } +// This is VLOG(2) for Open Source gRPC because of a lot of log noise +// complaints. However, internally we want LOG(INFO) so that it is easier for us +// to debug prod issues. +#define GRPC_EXPERIMENT_LOG VLOG(2) + void PrintExperimentsList() { std::map experiment_status; std::set defaulted_on_experiments; @@ -254,20 +259,20 @@ void PrintExperimentsList() { } if (experiment_status.empty()) { if (!defaulted_on_experiments.empty()) { - VLOG(2) << "gRPC experiments enabled: " - << absl::StrJoin(defaulted_on_experiments, ", "); + GRPC_EXPERIMENT_LOG << "gRPC experiments enabled: " + << absl::StrJoin(defaulted_on_experiments, ", "); } } else { if (defaulted_on_experiments.empty()) { - VLOG(2) << "gRPC experiments: " - << absl::StrJoin(experiment_status, ", ", - absl::PairFormatter(":")); + GRPC_EXPERIMENT_LOG << "gRPC experiments: " + << absl::StrJoin(experiment_status, ", ", + absl::PairFormatter(":")); } else { - VLOG(2) << "gRPC experiments: " - << absl::StrJoin(experiment_status, ", ", - absl::PairFormatter(":")) - << "; default-enabled: " - << absl::StrJoin(defaulted_on_experiments, ", "); + GRPC_EXPERIMENT_LOG << "gRPC experiments: " + << absl::StrJoin(experiment_status, ", ", + absl::PairFormatter(":")) + << "; default-enabled: " + << absl::StrJoin(defaulted_on_experiments, ", "); } } } diff --git a/src/core/lib/experiments/experiments.cc b/src/core/lib/experiments/experiments.cc index 70326c3782..8a8b5a445e 100644 --- a/src/core/lib/experiments/experiments.cc +++ b/src/core/lib/experiments/experiments.cc @@ -22,11 +22,6 @@ #if defined(GRPC_CFSTREAM) namespace { -const char* const description_call_status_override_on_cancellation = - "Avoid overriding call status of successfully finished calls if it races " - "with cancellation."; -const char* const additional_constraints_call_status_override_on_cancellation = - "{}"; const char* const description_call_tracer_in_transport = "Transport directly passes byte counts to CallTracer."; const char* const additional_constraints_call_tracer_in_transport = "{}"; @@ -35,6 +30,11 @@ const char* const description_canary_client_privacy = const char* const additional_constraints_canary_client_privacy = "{}"; const char* const description_client_privacy = "If set, client privacy"; const char* const additional_constraints_client_privacy = "{}"; +const char* const description_event_engine_application_callbacks = + "Run application callbacks in EventEngine threads, instead of on the " + "thread-local ApplicationCallbackExecCtx"; +const char* const additional_constraints_event_engine_application_callbacks = + "{}"; const char* const description_event_engine_client = "Use EventEngine clients instead of iomgr's grpc_tcp_client"; const char* const additional_constraints_event_engine_client = "{}"; @@ -58,21 +58,12 @@ const char* const additional_constraints_monitoring_experiment = "{}"; const char* const description_multiping = "Allow more than one ping to be in flight at a time by default."; const char* const additional_constraints_multiping = "{}"; -const char* const description_peer_state_based_framing = - "If set, the max sizes of frames sent to lower layers is controlled based " - "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_pick_first_new = "New pick_first impl with memory reduction."; const char* const additional_constraints_pick_first_new = "{}"; 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 char* const description_rstpit = - "On RST_STREAM on a server, reduce MAX_CONCURRENT_STREAMS for a short " - "duration"; -const char* const additional_constraints_rstpit = "{}"; const char* const description_schedule_cancellation_over_write = "Allow cancellation op to be scheduled over a write"; const char* const additional_constraints_schedule_cancellation_over_write = @@ -109,16 +100,16 @@ const char* const additional_constraints_work_serializer_dispatch = "{}"; namespace grpc_core { const ExperimentMetadata g_experiment_metadata[] = { - {"call_status_override_on_cancellation", - description_call_status_override_on_cancellation, - additional_constraints_call_status_override_on_cancellation, nullptr, 0, - true, true}, {"call_tracer_in_transport", description_call_tracer_in_transport, additional_constraints_call_tracer_in_transport, nullptr, 0, true, true}, {"canary_client_privacy", description_canary_client_privacy, additional_constraints_canary_client_privacy, nullptr, 0, false, false}, {"client_privacy", description_client_privacy, additional_constraints_client_privacy, nullptr, 0, false, false}, + {"event_engine_application_callbacks", + description_event_engine_application_callbacks, + additional_constraints_event_engine_application_callbacks, nullptr, 0, + true, true}, {"event_engine_client", description_event_engine_client, additional_constraints_event_engine_client, nullptr, 0, false, true}, {"event_engine_dns", description_event_engine_dns, @@ -134,16 +125,12 @@ const ExperimentMetadata g_experiment_metadata[] = { additional_constraints_monitoring_experiment, nullptr, 0, true, true}, {"multiping", description_multiping, additional_constraints_multiping, nullptr, 0, false, true}, - {"peer_state_based_framing", description_peer_state_based_framing, - additional_constraints_peer_state_based_framing, nullptr, 0, false, true}, {"pick_first_new", description_pick_first_new, additional_constraints_pick_first_new, nullptr, 0, true, true}, {"promise_based_inproc_transport", description_promise_based_inproc_transport, additional_constraints_promise_based_inproc_transport, nullptr, 0, false, false}, - {"rstpit", description_rstpit, additional_constraints_rstpit, nullptr, 0, - false, true}, {"schedule_cancellation_over_write", description_schedule_cancellation_over_write, additional_constraints_schedule_cancellation_over_write, nullptr, 0, false, @@ -172,11 +159,6 @@ const ExperimentMetadata g_experiment_metadata[] = { #elif defined(GPR_WINDOWS) namespace { -const char* const description_call_status_override_on_cancellation = - "Avoid overriding call status of successfully finished calls if it races " - "with cancellation."; -const char* const additional_constraints_call_status_override_on_cancellation = - "{}"; const char* const description_call_tracer_in_transport = "Transport directly passes byte counts to CallTracer."; const char* const additional_constraints_call_tracer_in_transport = "{}"; @@ -185,6 +167,11 @@ const char* const description_canary_client_privacy = const char* const additional_constraints_canary_client_privacy = "{}"; const char* const description_client_privacy = "If set, client privacy"; const char* const additional_constraints_client_privacy = "{}"; +const char* const description_event_engine_application_callbacks = + "Run application callbacks in EventEngine threads, instead of on the " + "thread-local ApplicationCallbackExecCtx"; +const char* const additional_constraints_event_engine_application_callbacks = + "{}"; const char* const description_event_engine_client = "Use EventEngine clients instead of iomgr's grpc_tcp_client"; const char* const additional_constraints_event_engine_client = "{}"; @@ -208,21 +195,12 @@ const char* const additional_constraints_monitoring_experiment = "{}"; const char* const description_multiping = "Allow more than one ping to be in flight at a time by default."; const char* const additional_constraints_multiping = "{}"; -const char* const description_peer_state_based_framing = - "If set, the max sizes of frames sent to lower layers is controlled based " - "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_pick_first_new = "New pick_first impl with memory reduction."; const char* const additional_constraints_pick_first_new = "{}"; 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 char* const description_rstpit = - "On RST_STREAM on a server, reduce MAX_CONCURRENT_STREAMS for a short " - "duration"; -const char* const additional_constraints_rstpit = "{}"; const char* const description_schedule_cancellation_over_write = "Allow cancellation op to be scheduled over a write"; const char* const additional_constraints_schedule_cancellation_over_write = @@ -259,16 +237,16 @@ const char* const additional_constraints_work_serializer_dispatch = "{}"; namespace grpc_core { const ExperimentMetadata g_experiment_metadata[] = { - {"call_status_override_on_cancellation", - description_call_status_override_on_cancellation, - additional_constraints_call_status_override_on_cancellation, nullptr, 0, - true, true}, {"call_tracer_in_transport", description_call_tracer_in_transport, additional_constraints_call_tracer_in_transport, nullptr, 0, true, true}, {"canary_client_privacy", description_canary_client_privacy, additional_constraints_canary_client_privacy, nullptr, 0, false, false}, {"client_privacy", description_client_privacy, additional_constraints_client_privacy, nullptr, 0, false, false}, + {"event_engine_application_callbacks", + description_event_engine_application_callbacks, + additional_constraints_event_engine_application_callbacks, nullptr, 0, + true, true}, {"event_engine_client", description_event_engine_client, additional_constraints_event_engine_client, nullptr, 0, true, true}, {"event_engine_dns", description_event_engine_dns, @@ -284,16 +262,12 @@ const ExperimentMetadata g_experiment_metadata[] = { additional_constraints_monitoring_experiment, nullptr, 0, true, true}, {"multiping", description_multiping, additional_constraints_multiping, nullptr, 0, false, true}, - {"peer_state_based_framing", description_peer_state_based_framing, - additional_constraints_peer_state_based_framing, nullptr, 0, false, true}, {"pick_first_new", description_pick_first_new, additional_constraints_pick_first_new, nullptr, 0, true, true}, {"promise_based_inproc_transport", description_promise_based_inproc_transport, additional_constraints_promise_based_inproc_transport, nullptr, 0, false, false}, - {"rstpit", description_rstpit, additional_constraints_rstpit, nullptr, 0, - false, true}, {"schedule_cancellation_over_write", description_schedule_cancellation_over_write, additional_constraints_schedule_cancellation_over_write, nullptr, 0, false, @@ -322,11 +296,6 @@ const ExperimentMetadata g_experiment_metadata[] = { #else namespace { -const char* const description_call_status_override_on_cancellation = - "Avoid overriding call status of successfully finished calls if it races " - "with cancellation."; -const char* const additional_constraints_call_status_override_on_cancellation = - "{}"; const char* const description_call_tracer_in_transport = "Transport directly passes byte counts to CallTracer."; const char* const additional_constraints_call_tracer_in_transport = "{}"; @@ -335,6 +304,11 @@ const char* const description_canary_client_privacy = const char* const additional_constraints_canary_client_privacy = "{}"; const char* const description_client_privacy = "If set, client privacy"; const char* const additional_constraints_client_privacy = "{}"; +const char* const description_event_engine_application_callbacks = + "Run application callbacks in EventEngine threads, instead of on the " + "thread-local ApplicationCallbackExecCtx"; +const char* const additional_constraints_event_engine_application_callbacks = + "{}"; const char* const description_event_engine_client = "Use EventEngine clients instead of iomgr's grpc_tcp_client"; const char* const additional_constraints_event_engine_client = "{}"; @@ -358,21 +332,12 @@ const char* const additional_constraints_monitoring_experiment = "{}"; const char* const description_multiping = "Allow more than one ping to be in flight at a time by default."; const char* const additional_constraints_multiping = "{}"; -const char* const description_peer_state_based_framing = - "If set, the max sizes of frames sent to lower layers is controlled based " - "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_pick_first_new = "New pick_first impl with memory reduction."; const char* const additional_constraints_pick_first_new = "{}"; 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 char* const description_rstpit = - "On RST_STREAM on a server, reduce MAX_CONCURRENT_STREAMS for a short " - "duration"; -const char* const additional_constraints_rstpit = "{}"; const char* const description_schedule_cancellation_over_write = "Allow cancellation op to be scheduled over a write"; const char* const additional_constraints_schedule_cancellation_over_write = @@ -409,16 +374,16 @@ const char* const additional_constraints_work_serializer_dispatch = "{}"; namespace grpc_core { const ExperimentMetadata g_experiment_metadata[] = { - {"call_status_override_on_cancellation", - description_call_status_override_on_cancellation, - additional_constraints_call_status_override_on_cancellation, nullptr, 0, - true, true}, {"call_tracer_in_transport", description_call_tracer_in_transport, additional_constraints_call_tracer_in_transport, nullptr, 0, true, true}, {"canary_client_privacy", description_canary_client_privacy, additional_constraints_canary_client_privacy, nullptr, 0, false, false}, {"client_privacy", description_client_privacy, additional_constraints_client_privacy, nullptr, 0, false, false}, + {"event_engine_application_callbacks", + description_event_engine_application_callbacks, + additional_constraints_event_engine_application_callbacks, nullptr, 0, + true, true}, {"event_engine_client", description_event_engine_client, additional_constraints_event_engine_client, nullptr, 0, false, true}, {"event_engine_dns", description_event_engine_dns, @@ -434,16 +399,12 @@ const ExperimentMetadata g_experiment_metadata[] = { additional_constraints_monitoring_experiment, nullptr, 0, true, true}, {"multiping", description_multiping, additional_constraints_multiping, nullptr, 0, false, true}, - {"peer_state_based_framing", description_peer_state_based_framing, - additional_constraints_peer_state_based_framing, nullptr, 0, false, true}, {"pick_first_new", description_pick_first_new, additional_constraints_pick_first_new, nullptr, 0, true, true}, {"promise_based_inproc_transport", description_promise_based_inproc_transport, additional_constraints_promise_based_inproc_transport, nullptr, 0, false, false}, - {"rstpit", description_rstpit, additional_constraints_rstpit, nullptr, 0, - false, true}, {"schedule_cancellation_over_write", description_schedule_cancellation_over_write, additional_constraints_schedule_cancellation_over_write, nullptr, 0, false, diff --git a/src/core/lib/experiments/experiments.h b/src/core/lib/experiments/experiments.h index 498557c511..0b44aca703 100644 --- a/src/core/lib/experiments/experiments.h +++ b/src/core/lib/experiments/experiments.h @@ -57,12 +57,12 @@ namespace grpc_core { #ifdef GRPC_EXPERIMENTS_ARE_FINAL #if defined(GRPC_CFSTREAM) -#define GRPC_EXPERIMENT_IS_INCLUDED_CALL_STATUS_OVERRIDE_ON_CANCELLATION -inline bool IsCallStatusOverrideOnCancellationEnabled() { return true; } #define GRPC_EXPERIMENT_IS_INCLUDED_CALL_TRACER_IN_TRANSPORT inline bool IsCallTracerInTransportEnabled() { return true; } inline bool IsCanaryClientPrivacyEnabled() { return false; } inline bool IsClientPrivacyEnabled() { return false; } +#define GRPC_EXPERIMENT_IS_INCLUDED_EVENT_ENGINE_APPLICATION_CALLBACKS +inline bool IsEventEngineApplicationCallbacksEnabled() { return true; } inline bool IsEventEngineClientEnabled() { return false; } inline bool IsEventEngineDnsEnabled() { return false; } inline bool IsEventEngineListenerEnabled() { return false; } @@ -71,11 +71,9 @@ inline bool IsMaxPingsWoDataThrottleEnabled() { return false; } #define GRPC_EXPERIMENT_IS_INCLUDED_MONITORING_EXPERIMENT inline bool IsMonitoringExperimentEnabled() { return true; } inline bool IsMultipingEnabled() { return false; } -inline bool IsPeerStateBasedFramingEnabled() { return false; } #define GRPC_EXPERIMENT_IS_INCLUDED_PICK_FIRST_NEW inline bool IsPickFirstNewEnabled() { return true; } inline bool IsPromiseBasedInprocTransportEnabled() { return false; } -inline bool IsRstpitEnabled() { return false; } inline bool IsScheduleCancellationOverWriteEnabled() { return false; } inline bool IsServerPrivacyEnabled() { return false; } inline bool IsTcpFrameSizeTuningEnabled() { return false; } @@ -88,12 +86,12 @@ inline bool IsWorkSerializerClearsTimeCacheEnabled() { return true; } inline bool IsWorkSerializerDispatchEnabled() { return false; } #elif defined(GPR_WINDOWS) -#define GRPC_EXPERIMENT_IS_INCLUDED_CALL_STATUS_OVERRIDE_ON_CANCELLATION -inline bool IsCallStatusOverrideOnCancellationEnabled() { return true; } #define GRPC_EXPERIMENT_IS_INCLUDED_CALL_TRACER_IN_TRANSPORT inline bool IsCallTracerInTransportEnabled() { return true; } inline bool IsCanaryClientPrivacyEnabled() { return false; } inline bool IsClientPrivacyEnabled() { return false; } +#define GRPC_EXPERIMENT_IS_INCLUDED_EVENT_ENGINE_APPLICATION_CALLBACKS +inline bool IsEventEngineApplicationCallbacksEnabled() { return true; } #define GRPC_EXPERIMENT_IS_INCLUDED_EVENT_ENGINE_CLIENT inline bool IsEventEngineClientEnabled() { return true; } #define GRPC_EXPERIMENT_IS_INCLUDED_EVENT_ENGINE_DNS @@ -105,11 +103,9 @@ inline bool IsMaxPingsWoDataThrottleEnabled() { return false; } #define GRPC_EXPERIMENT_IS_INCLUDED_MONITORING_EXPERIMENT inline bool IsMonitoringExperimentEnabled() { return true; } inline bool IsMultipingEnabled() { return false; } -inline bool IsPeerStateBasedFramingEnabled() { return false; } #define GRPC_EXPERIMENT_IS_INCLUDED_PICK_FIRST_NEW inline bool IsPickFirstNewEnabled() { return true; } inline bool IsPromiseBasedInprocTransportEnabled() { return false; } -inline bool IsRstpitEnabled() { return false; } inline bool IsScheduleCancellationOverWriteEnabled() { return false; } inline bool IsServerPrivacyEnabled() { return false; } inline bool IsTcpFrameSizeTuningEnabled() { return false; } @@ -122,12 +118,12 @@ inline bool IsWorkSerializerClearsTimeCacheEnabled() { return true; } inline bool IsWorkSerializerDispatchEnabled() { return false; } #else -#define GRPC_EXPERIMENT_IS_INCLUDED_CALL_STATUS_OVERRIDE_ON_CANCELLATION -inline bool IsCallStatusOverrideOnCancellationEnabled() { return true; } #define GRPC_EXPERIMENT_IS_INCLUDED_CALL_TRACER_IN_TRANSPORT inline bool IsCallTracerInTransportEnabled() { return true; } inline bool IsCanaryClientPrivacyEnabled() { return false; } inline bool IsClientPrivacyEnabled() { return false; } +#define GRPC_EXPERIMENT_IS_INCLUDED_EVENT_ENGINE_APPLICATION_CALLBACKS +inline bool IsEventEngineApplicationCallbacksEnabled() { return true; } inline bool IsEventEngineClientEnabled() { return false; } #define GRPC_EXPERIMENT_IS_INCLUDED_EVENT_ENGINE_DNS inline bool IsEventEngineDnsEnabled() { return true; } @@ -138,11 +134,9 @@ inline bool IsMaxPingsWoDataThrottleEnabled() { return false; } #define GRPC_EXPERIMENT_IS_INCLUDED_MONITORING_EXPERIMENT inline bool IsMonitoringExperimentEnabled() { return true; } inline bool IsMultipingEnabled() { return false; } -inline bool IsPeerStateBasedFramingEnabled() { return false; } #define GRPC_EXPERIMENT_IS_INCLUDED_PICK_FIRST_NEW inline bool IsPickFirstNewEnabled() { return true; } inline bool IsPromiseBasedInprocTransportEnabled() { return false; } -inline bool IsRstpitEnabled() { return false; } inline bool IsScheduleCancellationOverWriteEnabled() { return false; } inline bool IsServerPrivacyEnabled() { return false; } inline bool IsTcpFrameSizeTuningEnabled() { return false; } @@ -157,10 +151,10 @@ inline bool IsWorkSerializerDispatchEnabled() { return false; } #else enum ExperimentIds { - kExperimentIdCallStatusOverrideOnCancellation, kExperimentIdCallTracerInTransport, kExperimentIdCanaryClientPrivacy, kExperimentIdClientPrivacy, + kExperimentIdEventEngineApplicationCallbacks, kExperimentIdEventEngineClient, kExperimentIdEventEngineDns, kExperimentIdEventEngineListener, @@ -168,10 +162,8 @@ enum ExperimentIds { kExperimentIdMaxPingsWoDataThrottle, kExperimentIdMonitoringExperiment, kExperimentIdMultiping, - kExperimentIdPeerStateBasedFraming, kExperimentIdPickFirstNew, kExperimentIdPromiseBasedInprocTransport, - kExperimentIdRstpit, kExperimentIdScheduleCancellationOverWrite, kExperimentIdServerPrivacy, kExperimentIdTcpFrameSizeTuning, @@ -182,10 +174,6 @@ enum ExperimentIds { kExperimentIdWorkSerializerDispatch, kNumExperiments }; -#define GRPC_EXPERIMENT_IS_INCLUDED_CALL_STATUS_OVERRIDE_ON_CANCELLATION -inline bool IsCallStatusOverrideOnCancellationEnabled() { - return IsExperimentEnabled(); -} #define GRPC_EXPERIMENT_IS_INCLUDED_CALL_TRACER_IN_TRANSPORT inline bool IsCallTracerInTransportEnabled() { return IsExperimentEnabled(); @@ -198,6 +186,10 @@ inline bool IsCanaryClientPrivacyEnabled() { inline bool IsClientPrivacyEnabled() { return IsExperimentEnabled(); } +#define GRPC_EXPERIMENT_IS_INCLUDED_EVENT_ENGINE_APPLICATION_CALLBACKS +inline bool IsEventEngineApplicationCallbacksEnabled() { + return IsExperimentEnabled(); +} #define GRPC_EXPERIMENT_IS_INCLUDED_EVENT_ENGINE_CLIENT inline bool IsEventEngineClientEnabled() { return IsExperimentEnabled(); @@ -226,10 +218,6 @@ inline bool IsMonitoringExperimentEnabled() { inline bool IsMultipingEnabled() { return IsExperimentEnabled(); } -#define GRPC_EXPERIMENT_IS_INCLUDED_PEER_STATE_BASED_FRAMING -inline bool IsPeerStateBasedFramingEnabled() { - return IsExperimentEnabled(); -} #define GRPC_EXPERIMENT_IS_INCLUDED_PICK_FIRST_NEW inline bool IsPickFirstNewEnabled() { return IsExperimentEnabled(); @@ -238,10 +226,6 @@ inline bool IsPickFirstNewEnabled() { inline bool IsPromiseBasedInprocTransportEnabled() { return IsExperimentEnabled(); } -#define GRPC_EXPERIMENT_IS_INCLUDED_RSTPIT -inline bool IsRstpitEnabled() { - return IsExperimentEnabled(); -} #define GRPC_EXPERIMENT_IS_INCLUDED_SCHEDULE_CANCELLATION_OVER_WRITE inline bool IsScheduleCancellationOverWriteEnabled() { return IsExperimentEnabled(); diff --git a/src/core/lib/gprpp/chunked_vector.h b/src/core/lib/gprpp/chunked_vector.h index b60bdac65a..a90f455d46 100644 --- a/src/core/lib/gprpp/chunked_vector.h +++ b/src/core/lib/gprpp/chunked_vector.h @@ -21,7 +21,6 @@ #include "absl/log/check.h" -#include #include #include "src/core/lib/gprpp/manual_constructor.h" diff --git a/src/core/lib/gprpp/down_cast.h b/src/core/lib/gprpp/down_cast.h index f9f72509ad..e7c05bf4b7 100644 --- a/src/core/lib/gprpp/down_cast.h +++ b/src/core/lib/gprpp/down_cast.h @@ -20,7 +20,6 @@ #include "absl/base/config.h" #include "absl/log/check.h" -#include #include namespace grpc_core { diff --git a/src/core/lib/gprpp/host_port.cc b/src/core/lib/gprpp/host_port.cc index 7e5ae646ca..fec4315110 100644 --- a/src/core/lib/gprpp/host_port.cc +++ b/src/core/lib/gprpp/host_port.cc @@ -24,7 +24,6 @@ #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" -#include #include namespace grpc_core { diff --git a/src/core/lib/gprpp/load_file.cc b/src/core/lib/gprpp/load_file.cc index 01cb7798de..dd15004570 100644 --- a/src/core/lib/gprpp/load_file.cc +++ b/src/core/lib/gprpp/load_file.cc @@ -24,7 +24,6 @@ #include #include -#include #include namespace grpc_core { diff --git a/src/core/lib/gprpp/mpscq.h b/src/core/lib/gprpp/mpscq.h index c33d34ffa1..f6306d4682 100644 --- a/src/core/lib/gprpp/mpscq.h +++ b/src/core/lib/gprpp/mpscq.h @@ -23,7 +23,6 @@ #include "absl/log/check.h" -#include #include #include "src/core/lib/gprpp/sync.h" diff --git a/src/core/lib/gprpp/single_set_ptr.h b/src/core/lib/gprpp/single_set_ptr.h index a8e1f278ba..016967b5f4 100644 --- a/src/core/lib/gprpp/single_set_ptr.h +++ b/src/core/lib/gprpp/single_set_ptr.h @@ -20,7 +20,6 @@ #include "absl/log/check.h" -#include #include namespace grpc_core { diff --git a/src/core/lib/gprpp/status_helper.cc b/src/core/lib/gprpp/status_helper.cc index a2a5160e2f..b3563592b5 100644 --- a/src/core/lib/gprpp/status_helper.cc +++ b/src/core/lib/gprpp/status_helper.cc @@ -35,7 +35,6 @@ #include "upb/base/string_view.h" #include "upb/mem/arena.hpp" -#include #include #include "src/core/lib/slice/percent_encoding.h" diff --git a/src/core/lib/gprpp/sync.h b/src/core/lib/gprpp/sync.h index 16efe619cd..3b80a7bc91 100644 --- a/src/core/lib/gprpp/sync.h +++ b/src/core/lib/gprpp/sync.h @@ -23,7 +23,6 @@ #include "absl/log/check.h" #include "absl/synchronization/mutex.h" -#include #include #include diff --git a/src/core/lib/gprpp/table.h b/src/core/lib/gprpp/table.h index c0f92888b0..7085bae035 100644 --- a/src/core/lib/gprpp/table.h +++ b/src/core/lib/gprpp/table.h @@ -334,6 +334,15 @@ class Table { absl::index_sequence()...>()); } + // Iterate through each set field in the table if it exists in Vs, in the + // order of Vs. For each existing field, call the filter function. If the + // function returns true, keep the field. Otherwise, remove the field. + template + void FilterIn(F f) { + FilterInImpl(std::move(f), + absl::index_sequence()...>()); + } + // Count the number of set fields in the table size_t count() const { return present_bits_.count(); } @@ -415,6 +424,18 @@ class Table { } } + // Call (*f)(value) if that value is in the table. + // If the value is present in the table and (*f)(value) returns false, remove + // the value from the table. + template + void FilterIf(F* f) { + if (auto* p = get()) { + if (!(*f)(*p)) { + clear(); + } + } + } + // For each field (element I=0, 1, ...) if that field is present, call its // destructor. template @@ -444,6 +465,13 @@ class Table { table_detail::do_these_things({(CallIf(&f), 1)...}); } + // For each field (element I=0, 1, ...) if that field is present, call f. If + // f returns false, remove the field from the table. + template + void FilterInImpl(F f, absl::index_sequence) { + table_detail::do_these_things({(FilterIf(&f), 1)...}); + } + template void ClearAllImpl(absl::index_sequence) { table_detail::do_these_things({(clear(), 1)...}); diff --git a/src/core/lib/gprpp/thd.h b/src/core/lib/gprpp/thd.h index 44ff3b22e3..6662610cd6 100644 --- a/src/core/lib/gprpp/thd.h +++ b/src/core/lib/gprpp/thd.h @@ -29,7 +29,6 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" -#include #include #include diff --git a/src/core/lib/gprpp/time.h b/src/core/lib/gprpp/time.h index 2f1be5fa6f..0e57349b78 100644 --- a/src/core/lib/gprpp/time.h +++ b/src/core/lib/gprpp/time.h @@ -24,7 +24,6 @@ #include "absl/types/optional.h" #include -#include #include #include diff --git a/src/core/lib/gprpp/time_util.cc b/src/core/lib/gprpp/time_util.cc index 3a1cd37637..94ca4e08d8 100644 --- a/src/core/lib/gprpp/time_util.cc +++ b/src/core/lib/gprpp/time_util.cc @@ -21,7 +21,6 @@ #include "absl/log/check.h" -#include #include #include diff --git a/src/core/lib/gprpp/windows/directory_reader.cc b/src/core/lib/gprpp/windows/directory_reader.cc index 3d45ee6532..2deedb8ca5 100644 --- a/src/core/lib/gprpp/windows/directory_reader.cc +++ b/src/core/lib/gprpp/windows/directory_reader.cc @@ -30,8 +30,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include - #include "src/core/lib/gprpp/directory_reader.h" namespace grpc_core { diff --git a/src/core/lib/gprpp/windows/thd.cc b/src/core/lib/gprpp/windows/thd.cc index b5c6368cf4..1e754e916b 100644 --- a/src/core/lib/gprpp/windows/thd.cc +++ b/src/core/lib/gprpp/windows/thd.cc @@ -27,7 +27,6 @@ #include "absl/log/log.h" #include -#include #include #include #include diff --git a/src/core/lib/gprpp/work_serializer.cc b/src/core/lib/gprpp/work_serializer.cc index 105aac28a1..16ed3fd6e6 100644 --- a/src/core/lib/gprpp/work_serializer.cc +++ b/src/core/lib/gprpp/work_serializer.cc @@ -136,10 +136,9 @@ class WorkSerializer::LegacyWorkSerializer final : public WorkSerializerImpl { void WorkSerializer::LegacyWorkSerializer::Run(std::function callback, const DebugLocation& location) { - if (GRPC_TRACE_FLAG_ENABLED(work_serializer)) { - LOG(INFO) << "WorkSerializer::Run() " << this << " Scheduling callback [" - << location.file() << ":" << location.line() << "]"; - } + GRPC_TRACE_LOG(work_serializer, INFO) + << "WorkSerializer::Run() " << this << " Scheduling callback [" + << location.file() << ":" << location.line() << "]"; // Increment queue size for the new callback and owner count to attempt to // take ownership of the WorkSerializer. const uint64_t prev_ref_pair = @@ -162,9 +161,8 @@ void WorkSerializer::LegacyWorkSerializer::Run(std::function callback, refs_.fetch_sub(MakeRefPair(1, 0), std::memory_order_acq_rel); CallbackWrapper* cb_wrapper = new CallbackWrapper(std::move(callback), location); - if (GRPC_TRACE_FLAG_ENABLED(work_serializer)) { - LOG(INFO) << " Scheduling on queue : item " << cb_wrapper; - } + GRPC_TRACE_LOG(work_serializer, INFO) + << " Scheduling on queue : item " << cb_wrapper; queue_.Push(&cb_wrapper->mpscq_node); } } @@ -173,19 +171,15 @@ void WorkSerializer::LegacyWorkSerializer::Schedule( std::function callback, const DebugLocation& location) { CallbackWrapper* cb_wrapper = new CallbackWrapper(std::move(callback), location); - if (GRPC_TRACE_FLAG_ENABLED(work_serializer)) { - LOG(INFO) << "WorkSerializer::Schedule() " << this - << " Scheduling callback " << cb_wrapper << " [" - << location.file() << ":" << location.line() << "]"; - } + GRPC_TRACE_LOG(work_serializer, INFO) + << "WorkSerializer::Schedule() " << this << " Scheduling callback " + << cb_wrapper << " [" << location.file() << ":" << location.line() << "]"; refs_.fetch_add(MakeRefPair(0, 1), std::memory_order_acq_rel); queue_.Push(&cb_wrapper->mpscq_node); } void WorkSerializer::LegacyWorkSerializer::Orphan() { - if (GRPC_TRACE_FLAG_ENABLED(work_serializer)) { - LOG(INFO) << "WorkSerializer::Orphan() " << this; - } + GRPC_TRACE_LOG(work_serializer, INFO) << "WorkSerializer::Orphan() " << this; const uint64_t prev_ref_pair = refs_.fetch_sub(MakeRefPair(0, 1), std::memory_order_acq_rel); if (GetOwners(prev_ref_pair) == 0 && GetSize(prev_ref_pair) == 1) { @@ -197,9 +191,8 @@ void WorkSerializer::LegacyWorkSerializer::Orphan() { // The thread that calls this loans itself to the work serializer so as to // execute all the scheduled callbacks. void WorkSerializer::LegacyWorkSerializer::DrainQueue() { - if (GRPC_TRACE_FLAG_ENABLED(work_serializer)) { - LOG(INFO) << "WorkSerializer::DrainQueue() " << this; - } + GRPC_TRACE_LOG(work_serializer, INFO) + << "WorkSerializer::DrainQueue() " << this; // Attempt to take ownership of the WorkSerializer. Also increment the queue // size as required by `DrainQueueOwned()`. const uint64_t prev_ref_pair = @@ -218,9 +211,8 @@ void WorkSerializer::LegacyWorkSerializer::DrainQueue() { } void WorkSerializer::LegacyWorkSerializer::DrainQueueOwned() { - if (GRPC_TRACE_FLAG_ENABLED(work_serializer)) { - LOG(INFO) << "WorkSerializer::DrainQueueOwned() " << this; - } + GRPC_TRACE_LOG(work_serializer, INFO) + << "WorkSerializer::DrainQueueOwned() " << this; while (true) { auto prev_ref_pair = refs_.fetch_sub(MakeRefPair(0, 1)); // It is possible that while draining the queue, the last callback ended @@ -265,11 +257,10 @@ void WorkSerializer::LegacyWorkSerializer::DrainQueueOwned() { GRPC_TRACE_LOG(work_serializer, INFO) << " Queue returned nullptr, trying again"; } - if (GRPC_TRACE_FLAG_ENABLED(work_serializer)) { - LOG(INFO) << " Running item " << cb_wrapper - << " : callback scheduled at [" << cb_wrapper->location.file() - << ":" << cb_wrapper->location.line() << "]"; - } + GRPC_TRACE_LOG(work_serializer, INFO) + << " Running item " << cb_wrapper << " : callback scheduled at [" + << cb_wrapper->location.file() << ":" << cb_wrapper->location.line() + << "]"; cb_wrapper->callback(); delete cb_wrapper; } @@ -405,10 +396,9 @@ void WorkSerializer::DispatchingWorkSerializer::Orphan() { // Implementation of WorkSerializerImpl::Run void WorkSerializer::DispatchingWorkSerializer::Run( std::function callback, const DebugLocation& location) { - if (GRPC_TRACE_FLAG_ENABLED(work_serializer)) { - LOG(INFO) << "WorkSerializer[" << this << "] Scheduling callback [" - << location.file() << ":" << location.line() << "]"; - } + GRPC_TRACE_LOG(work_serializer, INFO) + << "WorkSerializer[" << this << "] Scheduling callback [" + << location.file() << ":" << location.line() << "]"; global_stats().IncrementWorkSerializerItemsEnqueued(); MutexLock lock(&mu_); if (!running_) { @@ -438,10 +428,9 @@ void WorkSerializer::DispatchingWorkSerializer::Run() { // Grab the last element of processing_ - which is the next item in our // queue since processing_ is stored in reverse order. auto& cb = processing_.back(); - if (GRPC_TRACE_FLAG_ENABLED(work_serializer)) { - LOG(INFO) << "WorkSerializer[" << this << "] Executing callback [" - << cb.location.file() << ":" << cb.location.line() << "]"; - } + GRPC_TRACE_LOG(work_serializer, INFO) + << "WorkSerializer[" << this << "] Executing callback [" + << cb.location.file() << ":" << cb.location.line() << "]"; // Run the work item. const auto start = std::chrono::steady_clock::now(); SetCurrentThread(); diff --git a/src/core/lib/iomgr/buffer_list.cc b/src/core/lib/iomgr/buffer_list.cc index aedb422707..dd59b4e7d4 100644 --- a/src/core/lib/iomgr/buffer_list.cc +++ b/src/core/lib/iomgr/buffer_list.cc @@ -20,7 +20,6 @@ #include "absl/log/log.h" -#include #include #include diff --git a/src/core/lib/iomgr/call_combiner.h b/src/core/lib/iomgr/call_combiner.h index d2c7c0c985..87ad024880 100644 --- a/src/core/lib/iomgr/call_combiner.h +++ b/src/core/lib/iomgr/call_combiner.h @@ -166,14 +166,12 @@ class CallCombinerClosureList { GRPC_CALL_COMBINER_START(call_combiner, closure.closure, closure.error, closure.reason); } - if (GRPC_TRACE_FLAG_ENABLED(call_combiner)) { - LOG(INFO) << "CallCombinerClosureList executing closure while already " - "holding call_combiner " - << call_combiner - << ": closure=" << closures_[0].closure->DebugString() - << " error=" << StatusToString(closures_[0].error) - << " reason=" << closures_[0].reason; - } + GRPC_TRACE_LOG(call_combiner, INFO) + << "CallCombinerClosureList executing closure while already " + "holding call_combiner " + << call_combiner << ": closure=" << closures_[0].closure->DebugString() + << " error=" << StatusToString(closures_[0].error) + << " reason=" << closures_[0].reason; // This will release the call combiner. ExecCtx::Run(DEBUG_LOCATION, closures_[0].closure, closures_[0].error); closures_.clear(); diff --git a/src/core/lib/iomgr/cfstream_handle.cc b/src/core/lib/iomgr/cfstream_handle.cc index de9810ad2c..55604791a7 100644 --- a/src/core/lib/iomgr/cfstream_handle.cc +++ b/src/core/lib/iomgr/cfstream_handle.cc @@ -65,10 +65,9 @@ void CFStreamHandle::ReadCallback(CFReadStreamRef stream, grpc_error_handle error; CFErrorRef stream_error; CFStreamHandle* handle = static_cast(client_callback_info); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - VLOG(2) << "CFStream ReadCallback (" << handle << ", " << stream << ", " - << type << ", " << client_callback_info << ")"; - } + GRPC_TRACE_VLOG(tcp, 2) << "CFStream ReadCallback (" << handle << ", " + << stream << ", " << type << ", " + << client_callback_info << ")"; switch (type) { case kCFStreamEventOpenCompleted: handle->open_event_.SetReady(); @@ -99,10 +98,9 @@ void CFStreamHandle::WriteCallback(CFWriteStreamRef stream, grpc_error_handle error; CFErrorRef stream_error; CFStreamHandle* handle = static_cast(clientCallBackInfo); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - VLOG(2) << "CFStream WriteCallback (" << handle << ", " << stream << ", " - << type << ", " << clientCallBackInfo << ")"; - } + GRPC_TRACE_VLOG(tcp, 2) << "CFStream WriteCallback (" << handle << ", " + << stream << ", " << type << ", " + << clientCallBackInfo << ")"; switch (type) { case kCFStreamEventOpenCompleted: handle->open_event_.SetReady(); diff --git a/src/core/lib/iomgr/closure.h b/src/core/lib/iomgr/closure.h index bebdb41a0a..9f8a22493d 100644 --- a/src/core/lib/iomgr/closure.h +++ b/src/core/lib/iomgr/closure.h @@ -292,18 +292,15 @@ class Closure { return; } #ifndef NDEBUG - if (GRPC_TRACE_FLAG_ENABLED(closure)) { - VLOG(2) << "running closure " << closure << ": created [" - << closure->file_created << ":" << closure->line_created - << "]: run [" << location.file() << ":" << location.line() << "]"; - } + GRPC_TRACE_VLOG(closure, 2) + << "running closure " << closure << ": created [" + << closure->file_created << ":" << closure->line_created << "]: run [" + << location.file() << ":" << location.line() << "]"; CHECK_NE(closure->cb, nullptr); #endif closure->cb(closure->cb_arg, error); #ifndef NDEBUG - if (GRPC_TRACE_FLAG_ENABLED(closure)) { - VLOG(2) << "closure " << closure << " finished"; - } + GRPC_TRACE_VLOG(closure, 2) << "closure " << closure << " finished"; #endif } }; diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc index 7032c40f76..56db07f562 100644 --- a/src/core/lib/iomgr/combiner.cc +++ b/src/core/lib/iomgr/combiner.cc @@ -71,14 +71,12 @@ static void start_destroy(grpc_core::Combiner* lock) { } #ifndef NDEBUG -#define GRPC_COMBINER_DEBUG_SPAM(op, delta) \ - if (GRPC_TRACE_FLAG_ENABLED(combiner)) { \ - VLOG(2).AtLocation(file, line) \ - << "C:" << lock << " " << (op) << " " \ - << gpr_atm_no_barrier_load(&lock->refs.count) << " --> " \ - << gpr_atm_no_barrier_load(&lock->refs.count) + (delta) << " " \ - << reason; \ - } +#define GRPC_COMBINER_DEBUG_SPAM(op, delta) \ + GRPC_TRACE_VLOG(combiner, 2).AtLocation(file, line) \ + << "C:" << lock << " " << (op) << " " \ + << gpr_atm_no_barrier_load(&lock->refs.count) << " --> " \ + << gpr_atm_no_barrier_load(&lock->refs.count) + (delta) << " " \ + << reason; #else #define GRPC_COMBINER_DEBUG_SPAM(op, delta) #endif diff --git a/src/core/lib/iomgr/endpoint_cfstream.cc b/src/core/lib/iomgr/endpoint_cfstream.cc index dbe123a554..c542c6ae6b 100644 --- a/src/core/lib/iomgr/endpoint_cfstream.cc +++ b/src/core/lib/iomgr/endpoint_cfstream.cc @@ -129,11 +129,10 @@ static void CallReadCb(CFStreamEndpoint* ep, grpc_error_handle error) { } static void CallWriteCb(CFStreamEndpoint* ep, grpc_error_handle error) { - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - VLOG(2) << "CFStream endpoint:" << ep << " call_write_cb " << ep->write_cb - << " " << ep->write_cb->cb << ":" << ep->write_cb->cb_arg; - VLOG(2) << "write: error=" << grpc_core::StatusToString(error); - } + GRPC_TRACE_VLOG(tcp, 2) << "CFStream endpoint:" << ep << " call_write_cb " + << ep->write_cb << " " << ep->write_cb->cb << ":" + << ep->write_cb->cb_arg << "write: error=" + << grpc_core::StatusToString(error); grpc_closure* cb = ep->write_cb; ep->write_cb = nullptr; ep->write_slices = nullptr; @@ -233,10 +232,9 @@ static void CFStreamRead(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb, bool /*urgent*/, int /*min_progress_size*/) { CFStreamEndpoint* ep_impl = reinterpret_cast(ep); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - VLOG(2) << "CFStream endpoint:" << ep_impl << " read (" << slices << ", " - << cb << ") length:" << slices->length; - } + GRPC_TRACE_VLOG(tcp, 2) << "CFStream endpoint:" << ep_impl << " read (" + << slices << ", " << cb + << ") length:" << slices->length; CHECK_EQ(ep_impl->read_cb, nullptr); ep_impl->read_cb = cb; ep_impl->read_slices = slices; @@ -251,10 +249,9 @@ static void CFStreamWrite(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb, void* /*arg*/, int /*max_frame_size*/) { CFStreamEndpoint* ep_impl = reinterpret_cast(ep); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - VLOG(2) << "CFStream endpoint:" << ep_impl << " write (" << slices << ", " - << cb << ") length:" << slices->length; - } + GRPC_TRACE_VLOG(tcp, 2) << "CFStream endpoint:" << ep_impl << " write (" + << slices << ", " << cb + << ") length:" << slices->length; CHECK_EQ(ep_impl->write_cb, nullptr); ep_impl->write_cb = cb; ep_impl->write_slices = slices; @@ -308,11 +305,9 @@ grpc_endpoint* grpc_cfstream_endpoint_create(CFReadStreamRef read_stream, const char* peer_string, CFStreamHandle* stream_sync) { CFStreamEndpoint* ep_impl = new CFStreamEndpoint; - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - VLOG(2) << "CFStream endpoint:" << ep_impl - << " create readStream:" << read_stream - << " writeStream: " << write_stream; - } + GRPC_TRACE_VLOG(tcp, 2) << "CFStream endpoint:" << ep_impl + << " create readStream:" << read_stream + << " writeStream: " << write_stream; ep_impl->base.vtable = &vtable; gpr_ref_init(&ep_impl->refcount, 1); ep_impl->read_stream = read_stream; diff --git a/src/core/lib/iomgr/endpoint_pair_posix.cc b/src/core/lib/iomgr/endpoint_pair_posix.cc index 42d0e7acdb..4043f9a812 100644 --- a/src/core/lib/iomgr/endpoint_pair_posix.cc +++ b/src/core/lib/iomgr/endpoint_pair_posix.cc @@ -34,7 +34,6 @@ #include "absl/strings/str_cat.h" #include -#include #include "src/core/lib/event_engine/channel_args_endpoint_config.h" #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index 4d38a90c25..b31173121f 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -27,7 +27,6 @@ #include #include -#include #include #include diff --git a/src/core/lib/iomgr/ev_apple.cc b/src/core/lib/iomgr/ev_apple.cc index 77a9c4ee8e..88f07921f3 100644 --- a/src/core/lib/iomgr/ev_apple.cc +++ b/src/core/lib/iomgr/ev_apple.cc @@ -39,15 +39,6 @@ #include "src/core/lib/gprpp/time_util.h" #include "src/core/lib/iomgr/ev_apple.h" -#ifndef NDEBUG -#define GRPC_POLLING_TRACE(format, ...) \ - if (GRPC_TRACE_FLAG_ENABLED(apple_polling)) { \ - VLOG(2) << "(polling) " << absl::StrFormat(format, __VA_ARGS__); \ - } -#else -#define GRPC_POLLING_TRACE(...) -#endif // NDEBUG - #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker*)1) struct GlobalRunLoopContext { @@ -117,7 +108,8 @@ static void grpc_apple_register_write_stream_queue( /// the global run loop thread gGlobalRunLoopThread. static void grpc_apple_register_read_stream_run_loop( CFReadStreamRef read_stream, dispatch_queue_t /*dispatch_queue*/) { - GRPC_POLLING_TRACE("Register read stream: %p", read_stream); + GRPC_TRACE_VLOG(apple_polling, 2) + << "(polling) Register read stream: " << read_stream; grpc_core::MutexLock lock(&gGlobalRunLoopContext->mu); CFReadStreamScheduleWithRunLoop(read_stream, gGlobalRunLoopContext->run_loop, kCFRunLoopDefaultMode); @@ -130,7 +122,8 @@ static void grpc_apple_register_read_stream_run_loop( /// by the global run loop thread gGlobalRunLoopThread. static void grpc_apple_register_write_stream_run_loop( CFWriteStreamRef write_stream, dispatch_queue_t /*dispatch_queue*/) { - GRPC_POLLING_TRACE("Register write stream: %p", write_stream); + GRPC_TRACE_VLOG(apple_polling, 2) + << "(polling) Register write stream: " << write_stream; grpc_core::MutexLock lock(&gGlobalRunLoopContext->mu); CFWriteStreamScheduleWithRunLoop( write_stream, gGlobalRunLoopContext->run_loop, kCFRunLoopDefaultMode); @@ -220,9 +213,9 @@ static void pollset_global_shutdown(void) { static grpc_error_handle pollset_work(grpc_pollset* pollset, grpc_pollset_worker** worker, grpc_core::Timestamp deadline) { - GRPC_POLLING_TRACE("pollset work: %p, worker: %p, deadline: %" PRIu64, - pollset, worker, - deadline.milliseconds_after_process_epoch()); + GRPC_TRACE_VLOG(apple_polling, 2) + << "(polling) pollset work: " << pollset << ", worker: " << worker + << ", deadline: " << deadline.milliseconds_after_process_epoch(); GrpcApplePollset* apple_pollset = reinterpret_cast(pollset); GrpcAppleWorker actual_worker; @@ -276,7 +269,8 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset, GrpcApplePollset* apple_pollset = reinterpret_cast(pollset); - GRPC_POLLING_TRACE("pollset kick: %p, worker:%p", pollset, specific_worker); + GRPC_TRACE_VLOG(apple_polling, 2) << "(polling) pollset kick: " << pollset + << ", worker:" << specific_worker; if (specific_worker == nullptr) { if (apple_pollset->workers.empty()) { @@ -299,7 +293,7 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset, } static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { - GRPC_POLLING_TRACE("pollset init: %p", pollset); + GRPC_TRACE_VLOG(apple_polling, 2) << "(polling) pollset init: " << pollset; GrpcApplePollset* apple_pollset = new (pollset) GrpcApplePollset(); *mu = grpc_core::GetUnderlyingGprMu(&apple_pollset->mu); } @@ -307,7 +301,8 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { /// The caller must acquire the lock GrpcApplePollset.mu before calling this /// function. static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { - GRPC_POLLING_TRACE("pollset shutdown: %p", pollset); + GRPC_TRACE_VLOG(apple_polling, 2) + << "(polling) pollset shutdown: " << pollset; GrpcApplePollset* apple_pollset = reinterpret_cast(pollset); @@ -323,7 +318,7 @@ static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { } static void pollset_destroy(grpc_pollset* pollset) { - GRPC_POLLING_TRACE("pollset destroy: %p", pollset); + GRPC_TRACE_VLOG(apple_polling, 2) << "(polling) pollset destroy: " << pollset; GrpcApplePollset* apple_pollset = reinterpret_cast(pollset); apple_pollset->~GrpcApplePollset(); diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index 6217ba2666..c2c60e9663 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -360,9 +360,8 @@ static grpc_fd* fd_create(int fd, const char* name, bool track_err) { grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name.c_str()); fork_fd_list_add_grpc_fd(new_fd); #ifndef NDEBUG - if (GRPC_TRACE_FLAG_ENABLED(fd_refcount)) { - VLOG(2) << "FD " << fd << " " << new_fd << " create " << fd_name; - } + GRPC_TRACE_VLOG(fd_refcount, 2) + << "FD " << fd << " " << new_fd << " create " << fd_name; #endif struct epoll_event ev; @@ -727,9 +726,8 @@ static grpc_error_handle do_epoll_wait(grpc_pollset* ps, if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait"); - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << "ps: " << ps << " poll got " << r << " events"; - } + GRPC_TRACE_LOG(polling, INFO) + << "ps: " << ps << " poll got " << r << " events"; gpr_atm_rel_store(&g_epoll_set.num_events, r); gpr_atm_rel_store(&g_epoll_set.cursor, 0); @@ -746,9 +744,8 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, worker->schedule_on_end_work = (grpc_closure_list)GRPC_CLOSURE_LIST_INIT; pollset->begin_refs++; - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << "PS:" << pollset << " BEGIN_STARTS:" << worker; - } + GRPC_TRACE_LOG(polling, INFO) + << "PS:" << pollset << " BEGIN_STARTS:" << worker; if (pollset->seen_inactive) { // pollset has been observed to be inactive, we need to move back to the @@ -765,11 +762,10 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, retry_lock_neighborhood: gpr_mu_lock(&neighborhood->mu); gpr_mu_lock(&pollset->mu); - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << "PS:" << pollset << " BEGIN_REORG:" << worker - << " kick_state=" << kick_state_string(worker->state) - << " is_reassigning=" << is_reassigning; - } + GRPC_TRACE_LOG(polling, INFO) + << "PS:" << pollset << " BEGIN_REORG:" << worker + << " kick_state=" << kick_state_string(worker->state) + << " is_reassigning=" << is_reassigning; if (pollset->seen_inactive) { if (neighborhood != pollset->neighborhood) { gpr_mu_unlock(&neighborhood->mu); @@ -818,11 +814,10 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, worker->initialized_cv = true; gpr_cv_init(&worker->cv); while (worker->state == UNKICKED && !pollset->shutting_down) { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << "PS:" << pollset << " BEGIN_WAIT:" << worker - << " kick_state=" << kick_state_string(worker->state) - << " shutdown=" << pollset->shutting_down; - } + GRPC_TRACE_LOG(polling, INFO) + << "PS:" << pollset << " BEGIN_WAIT:" << worker + << " kick_state=" << kick_state_string(worker->state) + << " shutdown=" << pollset->shutting_down; if (gpr_cv_wait(&worker->cv, &pollset->mu, deadline.as_timespec(GPR_CLOCK_MONOTONIC)) && @@ -835,12 +830,11 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, grpc_core::ExecCtx::Get()->InvalidateNow(); } - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << "PS:" << pollset << " BEGIN_DONE:" << worker - << " kick_state=" << kick_state_string(worker->state) - << " shutdown=" << pollset->shutting_down - << " kicked_without_poller: " << pollset->kicked_without_poller; - } + GRPC_TRACE_LOG(polling, INFO) + << "PS:" << pollset << " BEGIN_DONE:" << worker + << " kick_state=" << kick_state_string(worker->state) + << " shutdown=" << pollset->shutting_down + << " kicked_without_poller: " << pollset->kicked_without_poller; // We release pollset lock in this function at a couple of places: // 1. Briefly when assigning pollset to a neighborhood @@ -877,17 +871,15 @@ static bool check_neighborhood_for_available_poller( if (gpr_atm_no_barrier_cas( &g_active_poller, 0, reinterpret_cast(inspect_worker))) { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. choose next poller to be " << inspect_worker; - } + GRPC_TRACE_LOG(polling, INFO) + << " .. choose next poller to be " << inspect_worker; SET_KICK_STATE(inspect_worker, DESIGNATED_POLLER); if (inspect_worker->initialized_cv) { gpr_cv_signal(&inspect_worker->cv); } } else { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. beaten to choose next poller"; - } + GRPC_TRACE_LOG(polling, INFO) + << " .. beaten to choose next poller"; } // even if we didn't win the cas, there's a worker, we can stop found_worker = true; @@ -903,9 +895,8 @@ static bool check_neighborhood_for_available_poller( } while (!found_worker && inspect_worker != inspect->root_worker); } if (!found_worker) { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. mark pollset " << inspect << " inactive"; - } + GRPC_TRACE_LOG(polling, INFO) + << " .. mark pollset " << inspect << " inactive"; inspect->seen_inactive = true; if (inspect == neighborhood->active_root) { neighborhood->active_root = @@ -922,9 +913,7 @@ static bool check_neighborhood_for_available_poller( static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, grpc_pollset_worker** worker_hdl) { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << "PS:" << pollset << " END_WORKER:" << worker; - } + GRPC_TRACE_LOG(polling, INFO) << "PS:" << pollset << " END_WORKER:" << worker; if (worker_hdl != nullptr) *worker_hdl = nullptr; // Make sure we appear kicked SET_KICK_STATE(worker, KICKED); @@ -933,9 +922,8 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, if (gpr_atm_no_barrier_load(&g_active_poller) == reinterpret_cast(worker)) { if (worker->next != worker && worker->next->state == UNKICKED) { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. choose next poller to be peer " << worker; - } + GRPC_TRACE_LOG(polling, INFO) + << " .. choose next poller to be peer " << worker; CHECK(worker->next->initialized_cv); gpr_atm_no_barrier_store(&g_active_poller, (gpr_atm)worker->next); SET_KICK_STATE(worker->next, DESIGNATED_POLLER); @@ -984,9 +972,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, if (worker->initialized_cv) { gpr_cv_destroy(&worker->cv); } - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. remove worker"; - } + GRPC_TRACE_LOG(polling, INFO) << " .. remove worker"; if (EMPTIED == worker_remove(pollset, worker)) { pollset_maybe_finish_shutdown(pollset); } @@ -1075,22 +1061,16 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset, grpc_pollset_worker* root_worker = pollset->root_worker; if (root_worker == nullptr) { pollset->kicked_without_poller = true; - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. kicked_without_poller"; - } + GRPC_TRACE_LOG(polling, INFO) << " .. kicked_without_poller"; goto done; } grpc_pollset_worker* next_worker = root_worker->next; if (root_worker->state == KICKED) { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. already kicked " << root_worker; - } + GRPC_TRACE_LOG(polling, INFO) << " .. already kicked " << root_worker; SET_KICK_STATE(root_worker, KICKED); goto done; } else if (next_worker->state == KICKED) { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. already kicked " << next_worker; - } + GRPC_TRACE_LOG(polling, INFO) << " .. already kicked " << next_worker; SET_KICK_STATE(next_worker, KICKED); goto done; } else if (root_worker == next_worker && // only try and wake up a poller @@ -1098,37 +1078,30 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset, root_worker == reinterpret_cast( gpr_atm_no_barrier_load(&g_active_poller))) { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. kicked " << root_worker; - } + GRPC_TRACE_LOG(polling, INFO) << " .. kicked " << root_worker; SET_KICK_STATE(root_worker, KICKED); ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd); goto done; } else if (next_worker->state == UNKICKED) { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. kicked " << next_worker; - } + GRPC_TRACE_LOG(polling, INFO) << " .. kicked " << next_worker; CHECK(next_worker->initialized_cv); SET_KICK_STATE(next_worker, KICKED); gpr_cv_signal(&next_worker->cv); goto done; } else if (next_worker->state == DESIGNATED_POLLER) { if (root_worker->state != DESIGNATED_POLLER) { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. kicked root non-poller " << root_worker - << " (initialized_cv=" << root_worker->initialized_cv - << ") (poller=" << next_worker << ")"; - } + GRPC_TRACE_LOG(polling, INFO) + << " .. kicked root non-poller " << root_worker + << " (initialized_cv=" << root_worker->initialized_cv + << ") (poller=" << next_worker << ")"; SET_KICK_STATE(root_worker, KICKED); if (root_worker->initialized_cv) { gpr_cv_signal(&root_worker->cv); } goto done; } else { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. non-root poller " << next_worker - << " (root=" << root_worker << ")"; - } + GRPC_TRACE_LOG(polling, INFO) << " .. non-root poller " << next_worker + << " (root=" << root_worker << ")"; SET_KICK_STATE(next_worker, KICKED); ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd); goto done; @@ -1139,9 +1112,7 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset, goto done; } } else { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. kicked while waking up"; - } + GRPC_TRACE_LOG(polling, INFO) << " .. kicked while waking up"; goto done; } @@ -1149,36 +1120,27 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset, } if (specific_worker->state == KICKED) { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. specific worker already kicked"; - } + GRPC_TRACE_LOG(polling, INFO) << " .. specific worker already kicked"; goto done; } else if (g_current_thread_worker == specific_worker) { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. mark " << specific_worker << " kicked"; - } + GRPC_TRACE_LOG(polling, INFO) + << " .. mark " << specific_worker << " kicked"; SET_KICK_STATE(specific_worker, KICKED); goto done; } else if (specific_worker == reinterpret_cast( gpr_atm_no_barrier_load(&g_active_poller))) { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. kick active poller"; - } + GRPC_TRACE_LOG(polling, 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(polling)) { - LOG(INFO) << " .. kick waiting worker"; - } + GRPC_TRACE_LOG(polling, INFO) << " .. kick waiting worker"; SET_KICK_STATE(specific_worker, KICKED); gpr_cv_signal(&specific_worker->cv); goto done; } else { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << " .. kick non-waiting worker"; - } + GRPC_TRACE_LOG(polling, INFO) << " .. kick non-waiting worker"; SET_KICK_STATE(specific_worker, KICKED); goto done; } diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index b2a3068633..a95adea7c8 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -332,12 +332,11 @@ static void fork_fd_list_add_wakeup_fd(grpc_cached_wakeup_fd* fd) { #define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__) static void ref_by(grpc_fd* fd, int n, const char* reason, const char* file, int line) { - if (GRPC_TRACE_FLAG_ENABLED(fd_refcount)) { - VLOG(2) << "FD " << fd->fd << " " << fd << " ref " << n << " " - << gpr_atm_no_barrier_load(&fd->refst) << " -> " - << gpr_atm_no_barrier_load(&fd->refst) + n << " [" << reason << "; " - << file << ":" << line << "]"; - } + GRPC_TRACE_VLOG(fd_refcount, 2) + << "FD " << fd->fd << " " << fd << " ref " << n << " " + << gpr_atm_no_barrier_load(&fd->refst) << " -> " + << gpr_atm_no_barrier_load(&fd->refst) + n << " [" << reason << "; " + << file << ":" << line << "]"; #else #define REF_BY(fd, n, reason) \ do { \ @@ -357,12 +356,11 @@ static void ref_by(grpc_fd* fd, int n) { #ifndef NDEBUG static void unref_by(grpc_fd* fd, int n, const char* reason, const char* file, int line) { - if (GRPC_TRACE_FLAG_ENABLED(fd_refcount)) { - VLOG(2) << "FD " << fd->fd << " " << fd << " unref " << n << " " - << gpr_atm_no_barrier_load(&fd->refst) << " -> " - << gpr_atm_no_barrier_load(&fd->refst) - n << " [" << reason << "; " - << file << ":" << line << "]"; - } + GRPC_TRACE_VLOG(fd_refcount, 2) + << "FD " << fd->fd << " " << fd << " unref " << n << " " + << gpr_atm_no_barrier_load(&fd->refst) << " -> " + << gpr_atm_no_barrier_load(&fd->refst) - n << " [" << reason << "; " + << file << ":" << line << "]"; #else static void unref_by(grpc_fd* fd, int n) { #endif @@ -1028,9 +1026,7 @@ static grpc_error_handle pollset_work(grpc_pollset* pollset, r = grpc_poll_function(pfds, pfd_count, timeout); GRPC_SCHEDULING_END_BLOCKING_REGION; - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << pollset << " poll=" << r; - } + GRPC_TRACE_LOG(polling, INFO) << pollset << " poll=" << r; if (r < 0) { if (errno != EINTR) { @@ -1052,9 +1048,7 @@ static grpc_error_handle pollset_work(grpc_pollset* pollset, } } else { if (pfds[0].revents & POLLIN_CHECK) { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << pollset << ": got_wakeup"; - } + GRPC_TRACE_LOG(polling, INFO) << pollset << ": got_wakeup"; work_combine_error( &error, grpc_wakeup_fd_consume_wakeup(&worker.wakeup_fd->fd)); } @@ -1066,12 +1060,11 @@ static grpc_error_handle pollset_work(grpc_pollset* pollset, } fd_end_poll(&watchers[i], 0, 0); } else { - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - LOG(INFO) << pollset << " got_event: " << pfds[i].fd - << " r:" << ((pfds[i].revents & POLLIN_CHECK) != 0) - << " w:" << ((pfds[i].revents & POLLOUT_CHECK) != 0) - << " [" << pfds[i].revents << "]"; - } + GRPC_TRACE_LOG(polling, INFO) + << pollset << " got_event: " << pfds[i].fd + << " r:" << ((pfds[i].revents & POLLIN_CHECK) != 0) + << " w:" << ((pfds[i].revents & POLLOUT_CHECK) != 0) << " [" + << pfds[i].revents << "]"; // This is a mitigation to prevent poll() from spinning on a //* POLLHUP https://github.com/grpc/grpc/pull/13665 // diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index d7206d421c..70ee372c4f 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -30,7 +30,6 @@ #include "absl/strings/str_split.h" #include -#include #include #include "src/core/lib/config/config_vars.h" @@ -42,18 +41,6 @@ #include "src/core/lib/iomgr/internal_errqueue.h" #include "src/core/util/useful.h" -// Traces fd create/close operations - -// Polling API trace only enabled in debug builds -#ifndef NDEBUG -#define GRPC_POLLING_API_TRACE(format, ...) \ - if (GRPC_TRACE_FLAG_ENABLED(polling_api)) { \ - LOG(INFO) << "(polling-api) " << absl::StrFormat(format, __VA_ARGS__); \ - } -#else -#define GRPC_POLLING_API_TRACE(...) -#endif // NDEBUG - /// Default poll() function - a pointer so that it can be overridden by some /// tests #ifndef GPR_AIX @@ -165,8 +152,10 @@ bool grpc_event_engine_run_in_background(void) { } grpc_fd* grpc_fd_create(int fd, const char* name, bool track_err) { - GRPC_POLLING_API_TRACE("fd_create(%d, %s, %d)", fd, name, track_err); - GRPC_FD_TRACE("fd_create(%d, %s, %d)", fd, name, track_err); + GRPC_TRACE_DLOG(polling_api, INFO) << "(polling-api) fd_create(" << fd << ", " + << name << ", " << track_err << ")"; + GRPC_TRACE_LOG(fd_trace, INFO) << "(fd-trace) fd_create(" << fd << ", " + << name << ", " << track_err << ")"; return g_event_engine->fd_create( fd, name, track_err && grpc_event_engine_can_track_errors()); } @@ -177,22 +166,29 @@ int grpc_fd_wrapped_fd(grpc_fd* fd) { void grpc_fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, const char* reason) { - GRPC_POLLING_API_TRACE("fd_orphan(%d, %p, %p, %s)", grpc_fd_wrapped_fd(fd), - on_done, release_fd, reason); - GRPC_FD_TRACE("grpc_fd_orphan, fd:%d closed", grpc_fd_wrapped_fd(fd)); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) fd_orphan(" << grpc_fd_wrapped_fd(fd) << ", " << on_done + << ", " << release_fd << ", " << reason << ")"; + GRPC_TRACE_LOG(fd_trace, INFO) + << "(fd-trace) grpc_fd_orphan, fd:" << grpc_fd_wrapped_fd(fd) + << " closed"; g_event_engine->fd_orphan(fd, on_done, release_fd, reason); } void grpc_fd_set_pre_allocated(grpc_fd* fd) { - GRPC_POLLING_API_TRACE("fd_set_pre_allocated(%d)", grpc_fd_wrapped_fd(fd)); - GRPC_FD_TRACE("fd_set_pre_allocated(%d)", grpc_fd_wrapped_fd(fd)); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) fd_set_pre_allocated(" << grpc_fd_wrapped_fd(fd) << ")"; + GRPC_TRACE_LOG(fd_trace, INFO) + << "(fd-trace) fd_set_pre_allocated(" << grpc_fd_wrapped_fd(fd) << ")"; g_event_engine->fd_set_pre_allocated(fd); } void grpc_fd_shutdown(grpc_fd* fd, grpc_error_handle why) { - GRPC_POLLING_API_TRACE("fd_shutdown(%d)", grpc_fd_wrapped_fd(fd)); - GRPC_FD_TRACE("fd_shutdown(%d)", grpc_fd_wrapped_fd(fd)); + GRPC_TRACE_LOG(polling_api, INFO) + << "(polling-api) fd_shutdown(" << grpc_fd_wrapped_fd(fd) << ")"; + GRPC_TRACE_LOG(fd_trace, INFO) + << "(fd-trace) fd_shutdown(" << grpc_fd_wrapped_fd(fd) << ")"; g_event_engine->fd_shutdown(fd, why); } @@ -221,41 +217,48 @@ void grpc_fd_set_error(grpc_fd* fd) { g_event_engine->fd_set_error(fd); } static size_t pollset_size(void) { return g_event_engine->pollset_size; } static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { - GRPC_POLLING_API_TRACE("pollset_init(%p)", pollset); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_init(" << pollset << ")"; g_event_engine->pollset_init(pollset, mu); } static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { - GRPC_POLLING_API_TRACE("pollset_shutdown(%p)", pollset); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_shutdown(" << pollset << ")"; g_event_engine->pollset_shutdown(pollset, closure); } static void pollset_destroy(grpc_pollset* pollset) { - GRPC_POLLING_API_TRACE("pollset_destroy(%p)", pollset); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_destroy(" << pollset << ")"; g_event_engine->pollset_destroy(pollset); } static grpc_error_handle pollset_work(grpc_pollset* pollset, grpc_pollset_worker** worker, grpc_core::Timestamp deadline) { - GRPC_POLLING_API_TRACE("pollset_work(%p, %" PRId64 ") begin", pollset, - deadline.milliseconds_after_process_epoch()); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_work(" << pollset << ", " + << deadline.milliseconds_after_process_epoch() << ") begin"; grpc_error_handle err = g_event_engine->pollset_work(pollset, worker, deadline); - GRPC_POLLING_API_TRACE("pollset_work(%p, %" PRId64 ") end", pollset, - deadline.milliseconds_after_process_epoch()); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_work(" << pollset << ", " + << deadline.milliseconds_after_process_epoch() << ") end"; return err; } static grpc_error_handle pollset_kick(grpc_pollset* pollset, grpc_pollset_worker* specific_worker) { - GRPC_POLLING_API_TRACE("pollset_kick(%p, %p)", pollset, specific_worker); + GRPC_TRACE_DLOG(polling_api, INFO) << "(polling-api) pollset_kick(" << pollset + << ", " << specific_worker << ")"; return g_event_engine->pollset_kick(pollset, specific_worker); } void grpc_pollset_add_fd(grpc_pollset* pollset, struct grpc_fd* fd) { - GRPC_POLLING_API_TRACE("pollset_add_fd(%p, %d)", pollset, - grpc_fd_wrapped_fd(fd)); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_add_fd(" << pollset << ", " + << grpc_fd_wrapped_fd(fd) << ")"; g_event_engine->pollset_add_fd(pollset, fd); } @@ -270,38 +273,44 @@ grpc_pollset_vtable grpc_posix_pollset_vtable = { static grpc_pollset_set* pollset_set_create(void) { grpc_pollset_set* pss = g_event_engine->pollset_set_create(); - GRPC_POLLING_API_TRACE("pollset_set_create(%p)", pss); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_set_create(" << pss << ")"; return pss; } static void pollset_set_destroy(grpc_pollset_set* pollset_set) { - GRPC_POLLING_API_TRACE("pollset_set_destroy(%p)", pollset_set); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_set_destroy(" << pollset_set << ")"; g_event_engine->pollset_set_destroy(pollset_set); } static void pollset_set_add_pollset(grpc_pollset_set* pollset_set, grpc_pollset* pollset) { - GRPC_POLLING_API_TRACE("pollset_set_add_pollset(%p, %p)", pollset_set, - pollset); + GRPC_TRACE_DLOG(polling_api, INFO) << "(polling-api) pollset_set_add_pollset(" + << pollset_set << ", " << pollset << ")"; g_event_engine->pollset_set_add_pollset(pollset_set, pollset); } static void pollset_set_del_pollset(grpc_pollset_set* pollset_set, grpc_pollset* pollset) { - GRPC_POLLING_API_TRACE("pollset_set_del_pollset(%p, %p)", pollset_set, - pollset); + GRPC_TRACE_DLOG(polling_api, INFO) << "(polling-api) pollset_set_del_pollset(" + << pollset_set << ", " << pollset << ")"; g_event_engine->pollset_set_del_pollset(pollset_set, pollset); } static void pollset_set_add_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) { - GRPC_POLLING_API_TRACE("pollset_set_add_pollset_set(%p, %p)", bag, item); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_set_add_pollset_set(" << bag << ", " << item + << ")"; g_event_engine->pollset_set_add_pollset_set(bag, item); } static void pollset_set_del_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) { - GRPC_POLLING_API_TRACE("pollset_set_del_pollset_set(%p, %p)", bag, item); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_set_del_pollset_set(" << bag << ", " << item + << ")"; g_event_engine->pollset_set_del_pollset_set(bag, item); } @@ -311,14 +320,16 @@ grpc_pollset_set_vtable grpc_posix_pollset_set_vtable = { pollset_set_add_pollset_set, pollset_set_del_pollset_set}; void grpc_pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { - GRPC_POLLING_API_TRACE("pollset_set_add_fd(%p, %d)", pollset_set, - grpc_fd_wrapped_fd(fd)); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_set_add_fd(" << pollset_set << ", " + << grpc_fd_wrapped_fd(fd) << ")"; g_event_engine->pollset_set_add_fd(pollset_set, fd); } void grpc_pollset_set_del_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { - GRPC_POLLING_API_TRACE("pollset_set_del_fd(%p, %d)", pollset_set, - grpc_fd_wrapped_fd(fd)); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_set_del_fd(" << pollset_set << ", " + << grpc_fd_wrapped_fd(fd) << ")"; g_event_engine->pollset_set_del_fd(pollset_set, fd); } diff --git a/src/core/lib/iomgr/ev_posix.h b/src/core/lib/iomgr/ev_posix.h index 06d039faf3..8573f0568b 100644 --- a/src/core/lib/iomgr/ev_posix.h +++ b/src/core/lib/iomgr/ev_posix.h @@ -33,11 +33,6 @@ #include "src/core/lib/iomgr/pollset_set.h" #include "src/core/lib/iomgr/wakeup_fd_posix.h" -#define GRPC_FD_TRACE(format, ...) \ - if (GRPC_TRACE_FLAG_ENABLED(fd_trace)) { \ - LOG(INFO) << "(fd-trace) " << absl::StrFormat(format, __VA_ARGS__); \ - } - typedef struct grpc_fd grpc_fd; typedef struct grpc_event_engine_vtable { diff --git a/src/core/lib/iomgr/event_engine_shims/closure.cc b/src/core/lib/iomgr/event_engine_shims/closure.cc index e38b295bba..8a362210b8 100644 --- a/src/core/lib/iomgr/event_engine_shims/closure.cc +++ b/src/core/lib/iomgr/event_engine_shims/closure.cc @@ -35,18 +35,16 @@ void RunEventEngineClosure(grpc_closure* closure, grpc_error_handle error) { grpc_core::ExecCtx exec_ctx; #ifndef NDEBUG closure->scheduled = false; - if (GRPC_TRACE_FLAG_ENABLED(closure)) { - VLOG(2) << "EventEngine: running closure " << closure << ": created [" - << closure->file_created << ":" << closure->line_created - << "]: " << (closure->run ? "run" : "scheduled") << " [" - << closure->file_initiated << ":" << closure->line_initiated << "]"; - } + GRPC_TRACE_VLOG(closure, 2) + << "EventEngine: running closure " << closure << ": created [" + << closure->file_created << ":" << closure->line_created + << "]: " << (closure->run ? "run" : "scheduled") << " [" + << closure->file_initiated << ":" << closure->line_initiated << "]"; #endif closure->cb(closure->cb_arg, error); #ifndef NDEBUG - if (GRPC_TRACE_FLAG_ENABLED(closure)) { - VLOG(2) << "EventEngine: closure " << closure << " finished"; - } + GRPC_TRACE_VLOG(closure, 2) + << "EventEngine: closure " << closure << " finished"; #endif } diff --git a/src/core/lib/iomgr/event_engine_shims/endpoint.cc b/src/core/lib/iomgr/event_engine_shims/endpoint.cc index 5b71ec378f..08fcbc6199 100644 --- a/src/core/lib/iomgr/event_engine_shims/endpoint.cc +++ b/src/core/lib/iomgr/event_engine_shims/endpoint.cc @@ -173,10 +173,9 @@ class EventEngineEndpointWrapper { void FinishPendingWrite(absl::Status status) { auto* write_buffer = reinterpret_cast(&eeep_->write_buffer); write_buffer->~SliceBuffer(); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "TCP: " << this << " WRITE (peer=" << PeerAddress() - << ") error=" << status; - } + GRPC_TRACE_LOG(tcp, INFO) + << "TCP: " << this << " WRITE (peer=" << PeerAddress() + << ") error=" << status; grpc_closure* cb = pending_write_cb_; pending_write_cb_ = nullptr; if (grpc_core::ExecCtx::Get() == nullptr) { diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index 0a3ae056eb..804ae6f649 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -32,21 +32,18 @@ static void exec_ctx_run(grpc_closure* closure) { #ifndef NDEBUG closure->scheduled = false; - if (GRPC_TRACE_FLAG_ENABLED(closure)) { - VLOG(2) << "running closure " << closure << ": created [" - << closure->file_created << ":" << closure->line_created - << "]: " << (closure->run ? "run" : "scheduled") << " [" - << closure->file_initiated << ":" << closure->line_initiated << "]"; - } + GRPC_TRACE_VLOG(closure, 2) + << "running closure " << closure << ": created [" << closure->file_created + << ":" << closure->line_created + << "]: " << (closure->run ? "run" : "scheduled") << " [" + << closure->file_initiated << ":" << closure->line_initiated << "]"; #endif grpc_error_handle error = grpc_core::internal::StatusMoveFromHeapPtr(closure->error_data.error); closure->error_data.error = 0; closure->cb(closure->cb_arg, std::move(error)); #ifndef NDEBUG - if (GRPC_TRACE_FLAG_ENABLED(closure)) { - VLOG(2) << "closure " << closure << " finished"; - } + GRPC_TRACE_VLOG(closure, 2) << "closure " << closure << " finished"; #endif } diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index ef336aa6d5..ce41e5b92b 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -33,7 +33,6 @@ #include #include #include -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index 22f1cb768b..02f21cf796 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -26,7 +26,6 @@ #include #include -#include #include #include @@ -39,13 +38,6 @@ #define MAX_DEPTH 2 -#define EXECUTOR_TRACE(format, ...) \ - do { \ - if (GRPC_TRACE_FLAG_ENABLED(executor)) { \ - LOG(INFO) << "EXECUTOR " << absl::StrFormat(format, __VA_ARGS__); \ - } \ - } while (0) - namespace grpc_core { namespace { @@ -110,11 +102,13 @@ size_t Executor::RunClosures(const char* executor_name, while (c != nullptr) { grpc_closure* next = c->next_data.next; #ifndef NDEBUG - EXECUTOR_TRACE("(%s) run %p [created by %s:%d]", executor_name, c, - c->file_created, c->line_created); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR (" << executor_name << ") run " << c << " [created by " + << c->file_created << ":" << c->line_created << "]"; c->scheduled = false; #else - EXECUTOR_TRACE("(%s) run %p", executor_name, c); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR (" << executor_name << ") run " << c; #endif grpc_error_handle error = internal::StatusMoveFromHeapPtr(c->error_data.error); @@ -134,11 +128,14 @@ bool Executor::IsThreaded() const { void Executor::SetThreading(bool threading) { gpr_atm curr_num_threads = gpr_atm_acq_load(&num_threads_); - EXECUTOR_TRACE("(%s) SetThreading(%d) begin", name_, threading); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR (" << name_ << ") SetThreading(" << threading << ") begin"; if (threading) { if (curr_num_threads > 0) { - EXECUTOR_TRACE("(%s) SetThreading(true). curr_num_threads > 0", name_); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR (" << name_ + << ") SetThreading(true). curr_num_threads > 0"; return; } @@ -160,7 +157,9 @@ void Executor::SetThreading(bool threading) { thd_state_[0].thd.Start(); } else { // !threading if (curr_num_threads == 0) { - EXECUTOR_TRACE("(%s) SetThreading(false). curr_num_threads == 0", name_); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR (" << name_ + << ") SetThreading(false). curr_num_threads == 0"; return; } @@ -179,8 +178,9 @@ void Executor::SetThreading(bool threading) { curr_num_threads = gpr_atm_no_barrier_load(&num_threads_); for (gpr_atm i = 0; i < curr_num_threads; i++) { thd_state_[i].thd.Join(); - EXECUTOR_TRACE("(%s) Thread %" PRIdPTR " of %" PRIdPTR " joined", name_, - i + 1, curr_num_threads); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR (" << name_ << ") Thread " << i + 1 << " of " + << curr_num_threads << " joined"; } gpr_atm_rel_store(&num_threads_, 0); @@ -201,7 +201,8 @@ void Executor::SetThreading(bool threading) { grpc_iomgr_platform_shutdown_background_closure(); } - EXECUTOR_TRACE("(%s) SetThreading(%d) done", name_, threading); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR (" << name_ << ") SetThreading(" << threading << ") done"; } void Executor::Shutdown() { SetThreading(false); } @@ -214,8 +215,9 @@ void Executor::ThreadMain(void* arg) { size_t subtract_depth = 0; for (;;) { - EXECUTOR_TRACE("(%s) [%" PRIdPTR "]: step (sub_depth=%" PRIdPTR ")", - ts->name, ts->id, subtract_depth); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR (" << ts->name << ") [" << ts->id + << "]: step (sub_depth=" << subtract_depth << ")"; gpr_mu_lock(&ts->mu); ts->depth -= subtract_depth; @@ -226,7 +228,8 @@ void Executor::ThreadMain(void* arg) { } if (ts->shutdown) { - EXECUTOR_TRACE("(%s) [%" PRIdPTR "]: shutdown", ts->name, ts->id); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR (" << ts->name << ") [" << ts->id << "]: shutdown"; gpr_mu_unlock(&ts->mu); break; } @@ -235,7 +238,8 @@ void Executor::ThreadMain(void* arg) { ts->elems = GRPC_CLOSURE_LIST_INIT; gpr_mu_unlock(&ts->mu); - EXECUTOR_TRACE("(%s) [%" PRIdPTR "]: execute", ts->name, ts->id); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR (" << ts->name << ") [" << ts->id << "]: execute"; ExecCtx::Get()->InvalidateNow(); subtract_depth = RunClosures(ts->name, closures); @@ -257,10 +261,13 @@ void Executor::Enqueue(grpc_closure* closure, grpc_error_handle error, // or already shutdown), then queue the closure on the exec context itself if (cur_thread_count == 0) { #ifndef NDEBUG - EXECUTOR_TRACE("(%s) schedule %p (created %s:%d) inline", name_, closure, - closure->file_created, closure->line_created); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR (" << name_ << ") schedule " << closure << " (created " + << closure->file_created << ":" << closure->line_created + << ") inline"; #else - EXECUTOR_TRACE("(%s) schedule %p inline", name_, closure); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR (" << name_ << ") schedule " << closure << " inline"; #endif grpc_closure_list_append(ExecCtx::Get()->closure_list(), closure, error); return; @@ -280,14 +287,15 @@ void Executor::Enqueue(grpc_closure* closure, grpc_error_handle error, for (;;) { #ifndef NDEBUG - EXECUTOR_TRACE( - "(%s) try to schedule %p (%s) (created %s:%d) to thread " - "%" PRIdPTR, - name_, closure, is_short ? "short" : "long", closure->file_created, - closure->line_created, ts->id); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR (" << name_ << ") try to schedule " << closure << " (" + << (is_short ? "short" : "long") << ") (created " + << closure->file_created << ":" << closure->line_created + << ") to thread " << ts->id; #else - EXECUTOR_TRACE("(%s) try to schedule %p (%s) to thread %" PRIdPTR, name_, - closure, is_short ? "short" : "long", ts->id); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR (" << name_ << ") try to schedule " << closure << " (" + << (is_short ? "short" : "long") << ") to thread " << ts->id; #endif gpr_mu_lock(&ts->mu); @@ -429,7 +437,8 @@ bool Executor::IsThreadedDefault() { } void Executor::SetThreadingAll(bool enable) { - EXECUTOR_TRACE("Executor::SetThreadingAll(%d) called", enable); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR Executor::SetThreadingAll(" << enable << ") called"; for (size_t i = 0; i < static_cast(ExecutorType::NUM_EXECUTORS); i++) { executors[i]->SetThreading(enable); @@ -437,7 +446,8 @@ void Executor::SetThreadingAll(bool enable) { } void Executor::SetThreadingDefault(bool enable) { - EXECUTOR_TRACE("Executor::SetThreadingDefault(%d) called", enable); + GRPC_TRACE_LOG(executor, INFO) + << "EXECUTOR Executor::SetThreadingDefault(" << enable << ") called"; executors[static_cast(ExecutorType::DEFAULT)]->SetThreading(enable); } diff --git a/src/core/lib/iomgr/fork_windows.cc b/src/core/lib/iomgr/fork_windows.cc index 0e1583173d..84d0609e2a 100644 --- a/src/core/lib/iomgr/fork_windows.cc +++ b/src/core/lib/iomgr/fork_windows.cc @@ -25,7 +25,6 @@ #include "absl/log/log.h" #include -#include // // NOTE: FORKING IS NOT GENERALLY SUPPORTED, THIS IS ONLY INTENDED TO WORK diff --git a/src/core/lib/iomgr/internal_errqueue.cc b/src/core/lib/iomgr/internal_errqueue.cc index 5223687a43..dbf001b4cc 100644 --- a/src/core/lib/iomgr/internal_errqueue.cc +++ b/src/core/lib/iomgr/internal_errqueue.cc @@ -16,7 +16,6 @@ #include "absl/log/log.h" -#include #include #include "src/core/lib/iomgr/port.h" diff --git a/src/core/lib/iomgr/iocp_windows.cc b/src/core/lib/iomgr/iocp_windows.cc index 9d6477aaaa..bc931a4f44 100644 --- a/src/core/lib/iomgr/iocp_windows.cc +++ b/src/core/lib/iomgr/iocp_windows.cc @@ -30,7 +30,6 @@ #include "absl/log/log.h" #include -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/lib/iomgr/iomgr_windows.cc b/src/core/lib/iomgr/iomgr_windows.cc index 21570d9033..ae35534186 100644 --- a/src/core/lib/iomgr/iomgr_windows.cc +++ b/src/core/lib/iomgr/iomgr_windows.cc @@ -24,8 +24,6 @@ #include "absl/log/check.h" -#include - #include "src/core/lib/experiments/experiments.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/iocp_windows.h" diff --git a/src/core/lib/iomgr/lockfree_event.cc b/src/core/lib/iomgr/lockfree_event.cc index ab4f563979..51e46ab976 100644 --- a/src/core/lib/iomgr/lockfree_event.cc +++ b/src/core/lib/iomgr/lockfree_event.cc @@ -95,10 +95,8 @@ void LockfreeEvent::NotifyOn(grpc_closure* closure) { // sure that the shutdown error has been initialized properly before us // referencing it. gpr_atm curr = gpr_atm_acq_load(&state_); - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - VLOG(2) << "LockfreeEvent::NotifyOn: " << this << " curr=" << curr - << " closure=" << closure; - } + GRPC_TRACE_VLOG(polling, 2) << "LockfreeEvent::NotifyOn: " << this + << " curr=" << curr << " closure=" << closure; switch (curr) { case kClosureNotReady: { // kClosureNotReady -> . @@ -163,10 +161,9 @@ bool LockfreeEvent::SetShutdown(grpc_error_handle shutdown_error) { while (true) { gpr_atm curr = gpr_atm_no_barrier_load(&state_); - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - VLOG(2) << "LockfreeEvent::SetShutdown: " << &state_ << " curr=" << curr - << " err=" << StatusToString(shutdown_error); - } + GRPC_TRACE_VLOG(polling, 2) + << "LockfreeEvent::SetShutdown: " << &state_ << " curr=" << curr + << " err=" << StatusToString(shutdown_error); switch (curr) { case kClosureReady: case kClosureNotReady: @@ -212,9 +209,8 @@ void LockfreeEvent::SetReady() { while (true) { gpr_atm curr = gpr_atm_no_barrier_load(&state_); - if (GRPC_TRACE_FLAG_ENABLED(polling)) { - VLOG(2) << "LockfreeEvent::SetReady: " << &state_ << " curr=" << curr; - } + GRPC_TRACE_VLOG(polling, 2) + << "LockfreeEvent::SetReady: " << &state_ << " curr=" << curr; switch (curr) { case kClosureReady: { diff --git a/src/core/lib/iomgr/polling_entity.cc b/src/core/lib/iomgr/polling_entity.cc index 42233112c1..2a3e9c7706 100644 --- a/src/core/lib/iomgr/polling_entity.cc +++ b/src/core/lib/iomgr/polling_entity.cc @@ -22,7 +22,6 @@ #include "absl/strings/str_format.h" #include -#include #include #include "src/core/lib/gprpp/crash.h" @@ -30,8 +29,12 @@ grpc_polling_entity grpc_polling_entity_create_from_pollset_set( grpc_pollset_set* pollset_set) { grpc_polling_entity pollent; - pollent.pollent.pollset_set = pollset_set; - pollent.tag = GRPC_POLLS_POLLSET_SET; + if (pollset_set == nullptr) { + pollent.tag = GRPC_POLLS_NONE; + } else { + pollent.pollent.pollset_set = pollset_set; + pollent.tag = GRPC_POLLS_POLLSET_SET; + } return pollent; } @@ -73,6 +76,8 @@ void grpc_polling_entity_add_to_pollset_set(grpc_polling_entity* pollent, } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) { CHECK_NE(pollent->pollent.pollset_set, nullptr); grpc_pollset_set_add_pollset_set(pss_dst, pollent->pollent.pollset_set); + } else if (pollent->tag == GRPC_POLLS_NONE) { + // Do nothing. } else { grpc_core::Crash( absl::StrFormat("Invalid grpc_polling_entity tag '%d'", pollent->tag)); @@ -93,6 +98,8 @@ void grpc_polling_entity_del_from_pollset_set(grpc_polling_entity* pollent, } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) { CHECK_NE(pollent->pollent.pollset_set, nullptr); grpc_pollset_set_del_pollset_set(pss_dst, pollent->pollent.pollset_set); + } else if (pollent->tag == GRPC_POLLS_NONE) { + // Do nothing. } else { grpc_core::Crash( absl::StrFormat("Invalid grpc_polling_entity tag '%d'", pollent->tag)); diff --git a/src/core/lib/iomgr/pollset_windows.cc b/src/core/lib/iomgr/pollset_windows.cc index c42d83da49..32925c61a9 100644 --- a/src/core/lib/iomgr/pollset_windows.cc +++ b/src/core/lib/iomgr/pollset_windows.cc @@ -22,8 +22,6 @@ #ifdef GRPC_WINSOCK_SOCKET -#include - #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/iocp_windows.h" diff --git a/src/core/lib/iomgr/resolve_address.cc b/src/core/lib/iomgr/resolve_address.cc index 24cdcf1c6d..db7b891bcc 100644 --- a/src/core/lib/iomgr/resolve_address.cc +++ b/src/core/lib/iomgr/resolve_address.cc @@ -21,7 +21,6 @@ #include #include -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/lib/iomgr/resolve_address_posix.cc b/src/core/lib/iomgr/resolve_address_posix.cc index 8cad6517c1..f890a349b9 100644 --- a/src/core/lib/iomgr/resolve_address_posix.cc +++ b/src/core/lib/iomgr/resolve_address_posix.cc @@ -25,7 +25,6 @@ #include #include -#include #include #include diff --git a/src/core/lib/iomgr/resolve_address_windows.cc b/src/core/lib/iomgr/resolve_address_windows.cc index 054f742381..105dcc8574 100644 --- a/src/core/lib/iomgr/resolve_address_windows.cc +++ b/src/core/lib/iomgr/resolve_address_windows.cc @@ -28,7 +28,6 @@ #include "absl/strings/str_format.h" #include -#include #include #include #include diff --git a/src/core/lib/iomgr/sockaddr_utils_posix.cc b/src/core/lib/iomgr/sockaddr_utils_posix.cc index d1981a4319..62d5bcac84 100644 --- a/src/core/lib/iomgr/sockaddr_utils_posix.cc +++ b/src/core/lib/iomgr/sockaddr_utils_posix.cc @@ -40,7 +40,6 @@ #include "absl/log/check.h" #include -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/lib/iomgr/socket_mutator.cc b/src/core/lib/iomgr/socket_mutator.cc index 428cc0bdf3..f77661969c 100644 --- a/src/core/lib/iomgr/socket_mutator.cc +++ b/src/core/lib/iomgr/socket_mutator.cc @@ -19,7 +19,6 @@ #include "src/core/lib/iomgr/socket_mutator.h" #include -#include #include #include diff --git a/src/core/lib/iomgr/socket_utils_linux.cc b/src/core/lib/iomgr/socket_utils_linux.cc index 2e64c21e0b..d699a1d5fe 100644 --- a/src/core/lib/iomgr/socket_utils_linux.cc +++ b/src/core/lib/iomgr/socket_utils_linux.cc @@ -25,8 +25,6 @@ #include #include -#include - #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/socket_utils_posix.h" diff --git a/src/core/lib/iomgr/socket_utils_posix.cc b/src/core/lib/iomgr/socket_utils_posix.cc index b34f3749c7..88b5d9a6bc 100644 --- a/src/core/lib/iomgr/socket_utils_posix.cc +++ b/src/core/lib/iomgr/socket_utils_posix.cc @@ -28,7 +28,6 @@ #include #include -#include #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/sockaddr.h" diff --git a/src/core/lib/iomgr/socket_utils_windows.cc b/src/core/lib/iomgr/socket_utils_windows.cc index 8b0e8f45f7..195a838598 100644 --- a/src/core/lib/iomgr/socket_utils_windows.cc +++ b/src/core/lib/iomgr/socket_utils_windows.cc @@ -22,8 +22,6 @@ #ifdef GRPC_WINDOWS_SOCKETUTILS -#include - #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/socket_utils.h" diff --git a/src/core/lib/iomgr/tcp_client_cfstream.cc b/src/core/lib/iomgr/tcp_client_cfstream.cc index 06c6a6fb48..f3228ad20c 100644 --- a/src/core/lib/iomgr/tcp_client_cfstream.cc +++ b/src/core/lib/iomgr/tcp_client_cfstream.cc @@ -78,10 +78,8 @@ static void CFStreamConnectCleanup(CFStreamConnect* connect) { static void OnAlarm(void* arg, grpc_error_handle error) { CFStreamConnect* connect = static_cast(arg); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - VLOG(2) << "CLIENT_CONNECT :" << connect - << " OnAlarm, error:" << grpc_core::StatusToString(error); - } + GRPC_TRACE_VLOG(tcp, 2) << "CLIENT_CONNECT :" << connect << " OnAlarm, error:" + << grpc_core::StatusToString(error); gpr_mu_lock(&connect->mu); grpc_closure* closure = connect->closure; connect->closure = nil; @@ -99,10 +97,8 @@ static void OnAlarm(void* arg, grpc_error_handle error) { static void OnOpen(void* arg, grpc_error_handle error) { CFStreamConnect* connect = static_cast(arg); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - VLOG(2) << "CLIENT_CONNECT :" << connect - << " OnOpen, error:" << grpc_core::StatusToString(error); - } + GRPC_TRACE_VLOG(tcp, 2) << "CLIENT_CONNECT :" << connect << " OnOpen, error:" + << grpc_core::StatusToString(error); gpr_mu_lock(&connect->mu); grpc_timer_cancel(&connect->alarm); grpc_closure* closure = connect->closure; @@ -173,10 +169,9 @@ static int64_t CFStreamClientConnect( gpr_ref_init(&connect->refcount, 1); gpr_mu_init(&connect->mu); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - VLOG(2) << "CLIENT_CONNECT: " << connect << ", " << connect->addr_name - << ": asynchronously connecting"; - } + GRPC_TRACE_VLOG(tcp, 2) << "CLIENT_CONNECT: " << connect << ", " + << connect->addr_name + << ": asynchronously connecting"; CFReadStreamRef read_stream; CFWriteStreamRef write_stream; diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index eed4b78e36..b0d983df9b 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -141,10 +141,9 @@ static grpc_error_handle prepare_socket( static void tc_on_alarm(void* acp, grpc_error_handle error) { int done; async_connect* ac = static_cast(acp); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "CLIENT_CONNECT: " << ac->addr_str - << ": on_alarm: error=" << grpc_core::StatusToString(error); - } + GRPC_TRACE_LOG(tcp, INFO) + << "CLIENT_CONNECT: " << ac->addr_str + << ": on_alarm: error=" << grpc_core::StatusToString(error); gpr_mu_lock(&ac->mu); if (ac->fd != nullptr) { grpc_fd_shutdown(ac->fd, GRPC_ERROR_CREATE("connect() timed out")); @@ -180,10 +179,9 @@ static void on_writable(void* acp, grpc_error_handle error) { std::string addr_str = ac->addr_str; grpc_fd* fd; - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "CLIENT_CONNECT: " << ac->addr_str - << ": on_writable: error=" << grpc_core::StatusToString(error); - } + GRPC_TRACE_LOG(tcp, INFO) + << "CLIENT_CONNECT: " << ac->addr_str + << ": on_writable: error=" << grpc_core::StatusToString(error); gpr_mu_lock(&ac->mu); CHECK(ac->fd); @@ -381,10 +379,8 @@ int64_t grpc_tcp_client_create_from_prepared_fd( grpc_schedule_on_exec_ctx); ac->options = options; - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "CLIENT_CONNECT: " << ac->addr_str - << ": asynchronously connecting fd " << fdobj; - } + GRPC_TRACE_LOG(tcp, INFO) << "CLIENT_CONNECT: " << ac->addr_str + << ": asynchronously connecting fd " << fdobj; int shard_number = connection_id % (*g_connection_shards).size(); struct ConnectionShard* shard = &(*g_connection_shards)[shard_number]; diff --git a/src/core/lib/iomgr/tcp_client_windows.cc b/src/core/lib/iomgr/tcp_client_windows.cc index bedf1cca5b..4086d45a57 100644 --- a/src/core/lib/iomgr/tcp_client_windows.cc +++ b/src/core/lib/iomgr/tcp_client_windows.cc @@ -29,7 +29,6 @@ #include #include #include -#include #include #include "src/core/lib/address_utils/sockaddr_utils.h" diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index a58361c7f7..37e409d123 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -618,18 +618,14 @@ static void tcp_drop_uncovered_then_handle_write(void* arg /* grpc_tcp */, static void done_poller(void* bp, grpc_error_handle /*error_ignored*/) { backup_poller* p = static_cast(bp); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "BACKUP_POLLER:" << p << " destroy"; - } + GRPC_TRACE_LOG(tcp, INFO) << "BACKUP_POLLER:" << p << " destroy"; grpc_pollset_destroy(BACKUP_POLLER_POLLSET(p)); gpr_free(p); } static void run_poller(void* bp, grpc_error_handle /*error_ignored*/) { backup_poller* p = static_cast(bp); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "BACKUP_POLLER:" << p << " run"; - } + GRPC_TRACE_LOG(tcp, INFO) << "BACKUP_POLLER:" << p << " run"; gpr_mu_lock(p->pollset_mu); grpc_core::Timestamp deadline = grpc_core::Timestamp::Now() + grpc_core::Duration::Seconds(10); @@ -644,17 +640,13 @@ static void run_poller(void* bp, grpc_error_handle /*error_ignored*/) { g_backup_poller = nullptr; g_uncovered_notifications_pending = 0; g_backup_poller_mu->Unlock(); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "BACKUP_POLLER:" << p << " shutdown"; - } + GRPC_TRACE_LOG(tcp, INFO) << "BACKUP_POLLER:" << p << " shutdown"; grpc_pollset_shutdown(BACKUP_POLLER_POLLSET(p), GRPC_CLOSURE_INIT(&p->run_poller, done_poller, p, grpc_schedule_on_exec_ctx)); } else { g_backup_poller_mu->Unlock(); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "BACKUP_POLLER:" << p << " reschedule"; - } + GRPC_TRACE_LOG(tcp, INFO) << "BACKUP_POLLER:" << p << " reschedule"; grpc_core::Executor::Run(&p->run_poller, absl::OkStatus(), grpc_core::ExecutorType::DEFAULT, grpc_core::ExecutorJobType::LONG); @@ -669,10 +661,8 @@ static void drop_uncovered(grpc_tcp* /*tcp*/) { old_count = g_uncovered_notifications_pending--; g_backup_poller_mu->Unlock(); CHECK_GT(old_count, 1); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "BACKUP_POLLER:" << p << " uncover cnt " << old_count << "->" - << old_count - 1; - } + GRPC_TRACE_LOG(tcp, INFO) << "BACKUP_POLLER:" << p << " uncover cnt " + << old_count << "->" << old_count - 1; } // gRPC API considers a Write operation to be done the moment it clears ‘flow @@ -693,9 +683,7 @@ static void cover_self(grpc_tcp* tcp) { g_backup_poller = p; grpc_pollset_init(BACKUP_POLLER_POLLSET(p), &p->pollset_mu); g_backup_poller_mu->Unlock(); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "BACKUP_POLLER:" << p << " create"; - } + GRPC_TRACE_LOG(tcp, INFO) << "BACKUP_POLLER:" << p << " create"; grpc_core::Executor::Run( GRPC_CLOSURE_INIT(&p->run_poller, run_poller, p, nullptr), absl::OkStatus(), grpc_core::ExecutorType::DEFAULT, @@ -705,24 +693,18 @@ static void cover_self(grpc_tcp* tcp) { p = g_backup_poller; g_backup_poller_mu->Unlock(); } - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "BACKUP_POLLER:" << p << " add " << tcp << " cnt " - << old_count - 1 << "->" << old_count; - } + GRPC_TRACE_LOG(tcp, INFO) << "BACKUP_POLLER:" << p << " add " << tcp + << " cnt " << old_count - 1 << "->" << old_count; grpc_pollset_add_fd(BACKUP_POLLER_POLLSET(p), tcp->em_fd); } static void notify_on_read(grpc_tcp* tcp) { - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "TCP:" << tcp << " notify_on_read"; - } + GRPC_TRACE_LOG(tcp, INFO) << "TCP:" << tcp << " notify_on_read"; grpc_fd_notify_on_read(tcp->em_fd, &tcp->read_done_closure); } static void notify_on_write(grpc_tcp* tcp) { - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "TCP:" << tcp << " notify_on_write"; - } + GRPC_TRACE_LOG(tcp, INFO) << "TCP:" << tcp << " notify_on_write"; if (!grpc_event_engine_run_in_background()) { cover_self(tcp); } @@ -731,10 +713,8 @@ static void notify_on_write(grpc_tcp* tcp) { static void tcp_drop_uncovered_then_handle_write(void* arg, grpc_error_handle error) { - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "TCP:" << arg - << " got_write: " << grpc_core::StatusToString(error); - } + GRPC_TRACE_LOG(tcp, INFO) + << "TCP:" << arg << " got_write: " << grpc_core::StatusToString(error); drop_uncovered(static_cast(arg)); tcp_handle_write(arg, error); } @@ -821,9 +801,8 @@ 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(resource_quota)) { - LOG(INFO) << "TCP: benign reclamation to free memory"; - } + GRPC_TRACE_LOG(resource_quota, INFO) + << "TCP: benign reclamation to free memory"; tcp->read_mu.Lock(); if (tcp->incoming_buffer != nullptr) { grpc_slice_buffer_reset_and_unref(tcp->incoming_buffer); @@ -916,9 +895,7 @@ static void update_rcvlowat(grpc_tcp* tcp) static bool tcp_do_read(grpc_tcp* tcp, grpc_error_handle* error) ABSL_EXCLUSIVE_LOCKS_REQUIRED(tcp->read_mu) { GRPC_LATENT_SEE_INNER_SCOPE("tcp_do_read"); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "TCP:" << tcp << " do_read"; - } + GRPC_TRACE_LOG(tcp, INFO) << "TCP:" << tcp << " do_read"; struct msghdr msg; struct iovec iov[MAX_READ_IOVEC]; ssize_t read_bytes; @@ -1129,10 +1106,8 @@ static void maybe_make_read_slices(grpc_tcp* tcp) static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error_handle error) { grpc_tcp* tcp = static_cast(arg); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "TCP:" << tcp - << " got_read: " << grpc_core::StatusToString(error); - } + GRPC_TRACE_LOG(tcp, INFO) + << "TCP:" << tcp << " got_read: " << grpc_core::StatusToString(error); tcp->read_mu.Lock(); grpc_error_handle tcp_read_error; if (GPR_LIKELY(error.ok()) && tcp->memory_owner.is_valid()) { @@ -1280,9 +1255,8 @@ static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg, uint32_t opt = grpc_core::kTimestampingSocketOptions; if (setsockopt(tcp->fd, SOL_SOCKET, SO_TIMESTAMPING, static_cast(&opt), sizeof(opt)) != 0) { - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(ERROR) << "Failed to set timestamping options on the socket."; - } + GRPC_TRACE_LOG(tcp, ERROR) + << "Failed to set timestamping options on the socket."; return false; } tcp->bytes_counter = -1; @@ -1366,9 +1340,7 @@ struct cmsghdr* process_timestamp(grpc_tcp* tcp, msghdr* msg, auto next_cmsg = CMSG_NXTHDR(msg, cmsg); cmsghdr* opt_stats = nullptr; if (next_cmsg == nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(ERROR) << "Received timestamp without extended error"; - } + GRPC_TRACE_LOG(tcp, ERROR) << "Received timestamp without extended error"; return cmsg; } @@ -1378,9 +1350,7 @@ struct cmsghdr* process_timestamp(grpc_tcp* tcp, msghdr* msg, opt_stats = next_cmsg; next_cmsg = CMSG_NXTHDR(msg, opt_stats); if (next_cmsg == nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(ERROR) << "Received timestamp without extended error"; - } + GRPC_TRACE_LOG(tcp, ERROR) << "Received timestamp without extended error"; return opt_stats; } } @@ -1388,9 +1358,7 @@ struct cmsghdr* process_timestamp(grpc_tcp* tcp, msghdr* msg, if (!(next_cmsg->cmsg_level == SOL_IP || next_cmsg->cmsg_level == SOL_IPV6) || !(next_cmsg->cmsg_type == IP_RECVERR || next_cmsg->cmsg_type == IPV6_RECVERR)) { - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(ERROR) << "Unexpected control message"; - } + GRPC_TRACE_LOG(tcp, ERROR) << "Unexpected control message"; return cmsg; } @@ -1472,10 +1440,9 @@ static bool process_errors(grpc_tcp* tcp) { } else { // Got a control message that is not a timestamp or zerocopy. Don't know // how to handle this. - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "unknown control message cmsg_level:" << cmsg->cmsg_level - << " cmsg_type:" << cmsg->cmsg_type; - } + GRPC_TRACE_LOG(tcp, INFO) + << "unknown control message cmsg_level:" << cmsg->cmsg_level + << " cmsg_type:" << cmsg->cmsg_type; return processed_err; } } @@ -1488,9 +1455,7 @@ static bool process_errors(grpc_tcp* tcp) { static void tcp_handle_error(void* arg /* grpc_tcp */, grpc_error_handle error) { grpc_tcp* tcp = static_cast(arg); - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "TCP:" << tcp << " got_error: " << error; - } + GRPC_TRACE_LOG(tcp, INFO) << "TCP:" << tcp << " got_error: " << error; if (!error.ok() || static_cast(gpr_atm_acq_load(&tcp->stop_error_notification))) { @@ -1818,9 +1783,7 @@ static void tcp_handle_write(void* arg /* grpc_tcp */, ? tcp_flush_zerocopy(tcp, tcp->current_zerocopy_send, &error) : tcp_flush(tcp, &error); if (!flush_result) { - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "write: delayed"; - } + GRPC_TRACE_LOG(tcp, INFO) << "write: delayed"; notify_on_write(tcp); // tcp_flush does not populate error if it has returned false. DCHECK(error.ok()); @@ -1889,9 +1852,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, TCP_REF(tcp, "write"); tcp->write_cb = cb; tcp->current_zerocopy_send = zerocopy_send_record; - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "write: delayed"; - } + GRPC_TRACE_LOG(tcp, INFO) << "write: delayed"; notify_on_write(tcp); } else { GRPC_TRACE_LOG(tcp, INFO) << "write: " << grpc_core::StatusToString(error); diff --git a/src/core/lib/iomgr/tcp_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc index 14d5765489..a45a0c8e32 100644 --- a/src/core/lib/iomgr/tcp_server_posix.cc +++ b/src/core/lib/iomgr/tcp_server_posix.cc @@ -177,10 +177,9 @@ static grpc_error_handle CreateEventEngineListener( << addr_uri.status().ToString(); return; } - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "SERVER_CONNECT: incoming external connection: " - << addr_uri->c_str(); - } + GRPC_TRACE_LOG(tcp, INFO) << "SERVER_CONNECT: incoming external " + "connection: " + << addr_uri->c_str(); } read_notifier_pollset = (*(s->pollsets))[static_cast( @@ -460,9 +459,8 @@ static void on_read(void* arg, grpc_error_handle err) { LOG(ERROR) << "Invalid address: " << addr_uri.status(); goto error; } - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "SERVER_CONNECT: incoming connection: " << *addr_uri; - } + GRPC_TRACE_LOG(tcp, INFO) + << "SERVER_CONNECT: incoming connection: " << *addr_uri; std::string name = absl::StrCat("tcp-server-connection:", addr_uri.value()); grpc_fd* fdobj = grpc_fd_create(fd, name.c_str(), true); @@ -916,10 +914,8 @@ class ExternalConnectionHandler : public grpc_core::TcpServerFdHandler { LOG(ERROR) << "Invalid address: " << addr_uri.status(); return; } - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "SERVER_CONNECT: incoming external connection: " - << *addr_uri; - } + GRPC_TRACE_LOG(tcp, INFO) + << "SERVER_CONNECT: incoming external connection: " << *addr_uri; std::string name = absl::StrCat("tcp-server-connection:", addr_uri.value()); grpc_fd* fdobj = grpc_fd_create(fd, name.c_str(), true); read_notifier_pollset = diff --git a/src/core/lib/iomgr/tcp_windows.cc b/src/core/lib/iomgr/tcp_windows.cc index 0888f92ff1..b94ffcfe91 100644 --- a/src/core/lib/iomgr/tcp_windows.cc +++ b/src/core/lib/iomgr/tcp_windows.cc @@ -176,9 +176,7 @@ static void on_read(void* tcpp, grpc_error_handle error) { grpc_winsocket* socket = tcp->socket; grpc_winsocket_callback_info* info = &socket->read_info; - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "TCP:" << tcp << " on_read"; - } + GRPC_TRACE_LOG(tcp, INFO) << "TCP:" << tcp << " on_read"; if (error.ok()) { if (info->wsa_error != 0 && !tcp->shutting_down) { @@ -208,9 +206,7 @@ static void on_read(void* tcpp, grpc_error_handle error) { } } } else { - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "TCP:" << tcp << " unref read_slice"; - } + GRPC_TRACE_LOG(tcp, INFO) << "TCP:" << tcp << " unref read_slice"; grpc_slice_buffer_reset_and_unref(tcp->read_slices); error = grpc_error_set_int( tcp->shutting_down ? GRPC_ERROR_CREATE("TCP stream shutting down") @@ -239,9 +235,7 @@ static void win_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, WSABUF buffers[MAX_WSABUF_COUNT]; size_t i; - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "TCP:" << tcp << " win_read"; - } + GRPC_TRACE_LOG(tcp, INFO) << "TCP:" << tcp << " win_read"; if (tcp->shutting_down) { grpc_core::ExecCtx::Run( @@ -310,9 +304,7 @@ static void on_write(void* tcpp, grpc_error_handle error) { grpc_winsocket_callback_info* info = &handle->write_info; grpc_closure* cb; - if (GRPC_TRACE_FLAG_ENABLED(tcp)) { - LOG(INFO) << "TCP:" << tcp << " on_write"; - } + GRPC_TRACE_LOG(tcp, INFO) << "TCP:" << tcp << " on_write"; gpr_mu_lock(&tcp->mu); cb = tcp->write_cb; diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index f931658c67..7b1c9d205c 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -334,12 +334,11 @@ static void timer_init(grpc_timer* timer, grpc_core::Timestamp deadline, timer->hash_table_next = nullptr; #endif - if (GRPC_TRACE_FLAG_ENABLED(timer)) { - VLOG(2) << "TIMER " << timer << ": SET " - << deadline.milliseconds_after_process_epoch() << " now " - << grpc_core::Timestamp::Now().milliseconds_after_process_epoch() - << " call " << closure << "[" << closure->cb << "]"; - } + GRPC_TRACE_VLOG(timer, 2) + << "TIMER " << timer << ": SET " + << deadline.milliseconds_after_process_epoch() << " now " + << grpc_core::Timestamp::Now().milliseconds_after_process_epoch() + << " call " << closure << "[" << closure->cb << "]"; if (!g_shared_mutables.initialized) { timer->pending = false; @@ -370,12 +369,11 @@ static void timer_init(grpc_timer* timer, grpc_core::Timestamp deadline, timer->heap_index = INVALID_HEAP_INDEX; list_join(&shard->list, timer); } - if (GRPC_TRACE_FLAG_ENABLED(timer)) { - VLOG(2) << " .. add to shard " << (shard - g_shards) - << " with queue_deadline_cap=" - << shard->queue_deadline_cap.milliseconds_after_process_epoch() - << " => is_first_timer=" << (is_first_timer ? "true" : "false"); - } + GRPC_TRACE_VLOG(timer, 2) + << " .. add to shard " << (shard - g_shards) + << " with queue_deadline_cap=" + << shard->queue_deadline_cap.milliseconds_after_process_epoch() + << " => is_first_timer=" << (is_first_timer ? "true" : "false"); gpr_mu_unlock(&shard->mu); // Deadline may have decreased, we need to adjust the main queue. Note @@ -391,10 +389,9 @@ static void timer_init(grpc_timer* timer, grpc_core::Timestamp deadline, // grpc_timer_check. if (is_first_timer) { gpr_mu_lock(&g_shared_mutables.mu); - if (GRPC_TRACE_FLAG_ENABLED(timer)) { - VLOG(2) << " .. old shard min_deadline=" - << shard->min_deadline.milliseconds_after_process_epoch(); - } + GRPC_TRACE_VLOG(timer, 2) + << " .. old shard min_deadline=" + << shard->min_deadline.milliseconds_after_process_epoch(); if (deadline < shard->min_deadline) { grpc_core::Timestamp old_min_deadline = g_shard_queue[0]->min_deadline; shard->min_deadline = deadline; @@ -433,10 +430,9 @@ static void timer_cancel(grpc_timer* timer) { timer_shard* shard = &g_shards[grpc_core::HashPointer(timer, g_num_shards)]; gpr_mu_lock(&shard->mu); - if (GRPC_TRACE_FLAG_ENABLED(timer)) { - VLOG(2) << "TIMER " << timer - << ": CANCEL pending=" << (timer->pending ? "true" : "false"); - } + GRPC_TRACE_VLOG(timer, 2) + << "TIMER " << timer + << ": CANCEL pending=" << (timer->pending ? "true" : "false"); if (timer->pending) { REMOVE_FROM_HASH_TABLE(timer); @@ -474,11 +470,9 @@ static bool refill_heap(timer_shard* shard, grpc_core::Timestamp now) { std::max(now, shard->queue_deadline_cap) + grpc_core::Duration::FromSecondsAsDouble(deadline_delta); - if (GRPC_TRACE_FLAG_ENABLED(timer_check)) { - VLOG(2) << " .. shard[" << (shard - g_shards) - << "]->queue_deadline_cap --> " - << shard->queue_deadline_cap.milliseconds_after_process_epoch(); - } + GRPC_TRACE_VLOG(timer_check, 2) + << " .. shard[" << (shard - g_shards) << "]->queue_deadline_cap --> " + << shard->queue_deadline_cap.milliseconds_after_process_epoch(); for (timer = shard->list.next; timer != &shard->list; timer = next) { next = timer->next; auto timer_deadline = @@ -486,11 +480,9 @@ static bool refill_heap(timer_shard* shard, grpc_core::Timestamp now) { timer->deadline); if (timer_deadline < shard->queue_deadline_cap) { - if (GRPC_TRACE_FLAG_ENABLED(timer_check)) { - VLOG(2) << " .. add timer with deadline " - << timer_deadline.milliseconds_after_process_epoch() - << " to heap"; - } + GRPC_TRACE_VLOG(timer_check, 2) + << " .. add timer with deadline " + << timer_deadline.milliseconds_after_process_epoch() << " to heap"; list_remove(timer); grpc_timer_heap_add(&shard->heap, timer); } @@ -504,10 +496,9 @@ static bool refill_heap(timer_shard* shard, grpc_core::Timestamp now) { static grpc_timer* pop_one(timer_shard* shard, grpc_core::Timestamp now) { grpc_timer* timer; for (;;) { - if (GRPC_TRACE_FLAG_ENABLED(timer_check)) { - VLOG(2) << " .. shard[" << (shard - g_shards) << "]: heap_empty=" - << (grpc_timer_heap_is_empty(&shard->heap) ? "true" : "false"); - } + GRPC_TRACE_VLOG(timer_check, 2) + << " .. shard[" << (shard - g_shards) << "]: heap_empty=" + << (grpc_timer_heap_is_empty(&shard->heap) ? "true" : "false"); if (grpc_timer_heap_is_empty(&shard->heap)) { if (now < shard->queue_deadline_cap) return nullptr; if (!refill_heap(shard, now)) return nullptr; @@ -516,16 +507,13 @@ static grpc_timer* pop_one(timer_shard* shard, grpc_core::Timestamp now) { auto timer_deadline = grpc_core::Timestamp::FromMillisecondsAfterProcessEpoch( timer->deadline); - if (GRPC_TRACE_FLAG_ENABLED(timer_check)) { - VLOG(2) << " .. check top timer deadline=" - << timer_deadline.milliseconds_after_process_epoch() - << " now=" << now.milliseconds_after_process_epoch(); - } + GRPC_TRACE_VLOG(timer_check, 2) + << " .. check top timer deadline=" + << timer_deadline.milliseconds_after_process_epoch() + << " now=" << now.milliseconds_after_process_epoch(); if (timer_deadline > now) return nullptr; - if (GRPC_TRACE_FLAG_ENABLED(timer)) { - VLOG(2) << "TIMER " << timer << ": FIRE " - << (now - timer_deadline).millis() << "ms late"; - } + GRPC_TRACE_VLOG(timer, 2) << "TIMER " << timer << ": FIRE " + << (now - timer_deadline).millis() << "ms late"; timer->pending = false; grpc_timer_heap_pop(&shard->heap); return timer; @@ -546,9 +534,8 @@ static size_t pop_timers(timer_shard* shard, grpc_core::Timestamp now, } *new_min_deadline = compute_min_deadline(shard); gpr_mu_unlock(&shard->mu); - if (GRPC_TRACE_FLAG_ENABLED(timer_check)) { - VLOG(2) << " .. shard[" << (shard - g_shards) << "] popped " << n; - } + GRPC_TRACE_VLOG(timer_check, 2) + << " .. shard[" << (shard - g_shards) << "] popped " << n; return n; } @@ -584,12 +571,10 @@ static grpc_timer_check_result run_some_expired_timers( gpr_mu_lock(&g_shared_mutables.mu); result = GRPC_TIMERS_CHECKED_AND_EMPTY; - if (GRPC_TRACE_FLAG_ENABLED(timer_check)) { - VLOG(2) - << " .. shard[" << (g_shard_queue[0] - g_shards) - << "]->min_deadline = " - << g_shard_queue[0]->min_deadline.milliseconds_after_process_epoch(); - } + GRPC_TRACE_VLOG(timer_check, 2) + << " .. shard[" << (g_shard_queue[0] - g_shards) + << "]->min_deadline = " + << g_shard_queue[0]->min_deadline.milliseconds_after_process_epoch(); while (g_shard_queue[0]->min_deadline < now || (now != grpc_core::Timestamp::InfFuture() && @@ -603,14 +588,12 @@ static grpc_timer_check_result run_some_expired_timers( result = GRPC_TIMERS_FIRED; } - if (GRPC_TRACE_FLAG_ENABLED(timer_check)) { - VLOG(2) - << " .. result --> " << result << ", shard[" - << (g_shard_queue[0] - g_shards) << "]->min_deadline " - << g_shard_queue[0]->min_deadline.milliseconds_after_process_epoch() - << " --> " << new_min_deadline.milliseconds_after_process_epoch() - << ", now=" << now.milliseconds_after_process_epoch(); - } + GRPC_TRACE_VLOG(timer_check, 2) + << " .. result --> " << result << ", shard[" + << (g_shard_queue[0] - g_shards) << "]->min_deadline " + << g_shard_queue[0]->min_deadline.milliseconds_after_process_epoch() + << " --> " << new_min_deadline.milliseconds_after_process_epoch() + << ", now=" << now.milliseconds_after_process_epoch(); // An grpc_timer_init() on the shard could intervene here, adding a new // timer that is earlier than new_min_deadline. However, @@ -660,11 +643,9 @@ static grpc_timer_check_result timer_check(grpc_core::Timestamp* next) { if (next != nullptr) { *next = std::min(*next, min_timer); } - if (GRPC_TRACE_FLAG_ENABLED(timer_check)) { - VLOG(2) << "TIMER CHECK SKIP: now=" - << now.milliseconds_after_process_epoch() - << " min_timer=" << min_timer.milliseconds_after_process_epoch(); - } + GRPC_TRACE_VLOG(timer_check, 2) + << "TIMER CHECK SKIP: now=" << now.milliseconds_after_process_epoch() + << " min_timer=" << min_timer.milliseconds_after_process_epoch(); return GRPC_TIMERS_CHECKED_AND_EMPTY; } diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 5136ad35d1..312ed68a02 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -195,11 +195,10 @@ static bool wait_until(grpc_core::Timestamp next) { gpr_cv_wait(&g_cv_wait, &g_mu, next.as_timespec(GPR_CLOCK_MONOTONIC)); - if (GRPC_TRACE_FLAG_ENABLED(timer_check)) { - LOG(INFO) << "wait ended: was_timed:" - << (my_timed_waiter_generation == g_timed_waiter_generation) - << " kicked:" << g_kicked; - } + GRPC_TRACE_LOG(timer_check, INFO) + << "wait ended: was_timed:" + << (my_timed_waiter_generation == g_timed_waiter_generation) + << " kicked:" << g_kicked; // if this was the timed waiter, then we need to check timers, and flag // that there's now no timed waiter... we'll look for a replacement if // there's work to do after checking timers (code above) diff --git a/src/core/lib/iomgr/unix_sockets_posix.cc b/src/core/lib/iomgr/unix_sockets_posix.cc index 15b2226b68..904cb10faa 100644 --- a/src/core/lib/iomgr/unix_sockets_posix.cc +++ b/src/core/lib/iomgr/unix_sockets_posix.cc @@ -37,7 +37,6 @@ #include "absl/strings/str_cat.h" #include -#include #include "src/core/lib/address_utils/parse_address.h" #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/lib/iomgr/unix_sockets_posix_noop.cc b/src/core/lib/iomgr/unix_sockets_posix_noop.cc index 8e783c8cb7..1f9038e953 100644 --- a/src/core/lib/iomgr/unix_sockets_posix_noop.cc +++ b/src/core/lib/iomgr/unix_sockets_posix_noop.cc @@ -26,8 +26,6 @@ #include "absl/log/check.h" -#include - #include "src/core/lib/gprpp/crash.h" void grpc_create_socketpair_if_unix(int /* sv */[2]) { diff --git a/src/core/lib/iomgr/vsock.cc b/src/core/lib/iomgr/vsock.cc index 847dabe0f1..c6dc71a843 100644 --- a/src/core/lib/iomgr/vsock.cc +++ b/src/core/lib/iomgr/vsock.cc @@ -28,7 +28,6 @@ #include "absl/strings/str_cat.h" #include -#include #include "src/core/lib/address_utils/parse_address.h" #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/lib/iomgr/wakeup_fd_eventfd.cc b/src/core/lib/iomgr/wakeup_fd_eventfd.cc index 38760c2cfb..fcdb63b2e5 100644 --- a/src/core/lib/iomgr/wakeup_fd_eventfd.cc +++ b/src/core/lib/iomgr/wakeup_fd_eventfd.cc @@ -26,8 +26,6 @@ #include #include -#include - #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/strerror.h" #include "src/core/lib/iomgr/wakeup_fd_posix.h" diff --git a/src/core/lib/promise/activity.h b/src/core/lib/promise/activity.h index 715a28c047..55738c0899 100644 --- a/src/core/lib/promise/activity.h +++ b/src/core/lib/promise/activity.h @@ -29,7 +29,6 @@ #include "absl/strings/str_cat.h" #include "absl/types/optional.h" -#include #include #include "src/core/lib/debug/trace.h" diff --git a/src/core/lib/promise/context.h b/src/core/lib/promise/context.h index a2597e324a..61520707d2 100644 --- a/src/core/lib/promise/context.h +++ b/src/core/lib/promise/context.h @@ -20,7 +20,6 @@ #include "absl/log/check.h" #include "absl/meta/type_traits.h" -#include #include #include "src/core/lib/gprpp/down_cast.h" diff --git a/src/core/lib/promise/detail/join_state.h b/src/core/lib/promise/detail/join_state.h index d6ce8782bf..403ec38b06 100644 --- a/src/core/lib/promise/detail/join_state.h +++ b/src/core/lib/promise/detail/join_state.h @@ -103,7 +103,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 1/2 already ready"; } @@ -125,7 +125,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 2/2 already ready"; } @@ -216,7 +216,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 1/3 already ready"; } @@ -238,7 +238,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 2/3 already ready"; } @@ -260,7 +260,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 3/3 already ready"; } @@ -367,7 +367,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 1/4 already ready"; } @@ -389,7 +389,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 2/4 already ready"; } @@ -411,7 +411,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 3/4 already ready"; } @@ -433,7 +433,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 4/4 already ready"; } @@ -555,7 +555,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 1/5 already ready"; } @@ -577,7 +577,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 2/5 already ready"; } @@ -599,7 +599,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 3/5 already ready"; } @@ -621,7 +621,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 4/5 already ready"; } @@ -643,7 +643,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 5/5 already ready"; } @@ -780,7 +780,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 1/6 already ready"; } @@ -802,7 +802,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 2/6 already ready"; } @@ -824,7 +824,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 3/6 already ready"; } @@ -846,7 +846,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 4/6 already ready"; } @@ -868,7 +868,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 5/6 already ready"; } @@ -890,7 +890,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 6/6 already ready"; } @@ -1042,7 +1042,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 1/7 already ready"; } @@ -1064,7 +1064,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 2/7 already ready"; } @@ -1086,7 +1086,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 3/7 already ready"; } @@ -1108,7 +1108,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 4/7 already ready"; } @@ -1130,7 +1130,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 5/7 already ready"; } @@ -1152,7 +1152,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 6/7 already ready"; } @@ -1174,7 +1174,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 7/7 already ready"; } @@ -1341,7 +1341,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 1/8 already ready"; } @@ -1363,7 +1363,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 2/8 already ready"; } @@ -1385,7 +1385,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 3/8 already ready"; } @@ -1407,7 +1407,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 4/8 already ready"; } @@ -1429,7 +1429,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 5/8 already ready"; } @@ -1451,7 +1451,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 6/8 already ready"; } @@ -1473,7 +1473,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 7/8 already ready"; } @@ -1495,7 +1495,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 8/8 already ready"; } @@ -1677,7 +1677,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 1/9 already ready"; } @@ -1699,7 +1699,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 2/9 already ready"; } @@ -1721,7 +1721,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 3/9 already ready"; } @@ -1743,7 +1743,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 4/9 already ready"; } @@ -1765,7 +1765,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 5/9 already ready"; } @@ -1787,7 +1787,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 6/9 already ready"; } @@ -1809,7 +1809,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 7/9 already ready"; } @@ -1831,7 +1831,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 8/9 already ready"; } @@ -1853,7 +1853,7 @@ struct JoinState { return Traits::template EarlyReturn(std::move(*p)); } } - } else if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { + } else { GRPC_TRACE_VLOG(promise_primitives, 2) << "join[" << this << "]: joint 9/9 already ready"; } diff --git a/src/core/lib/promise/detail/seq_state.h b/src/core/lib/promise/detail/seq_state.h index b2b635f98b..245b8ac26f 100644 --- a/src/core/lib/promise/detail/seq_state.h +++ b/src/core/lib/promise/detail/seq_state.h @@ -138,24 +138,21 @@ struct SeqState { GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Poll PollOnce() { switch (state) { case State::kState0: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 1/2"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { return PromiseResultTraits0::template ReturnValue( @@ -171,16 +168,14 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; default: case State::kState1: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 2/2"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 2/2"; auto result = current_promise(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 2/2 gets " - << (result.ready() ? "ready" : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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{}; return Result(std::move(*p)); @@ -271,24 +266,21 @@ struct SeqState { GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Poll PollOnce() { switch (state) { case State::kState0: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 1/3"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { return PromiseResultTraits0::template ReturnValue( @@ -303,24 +295,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState1: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 2/3"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { return PromiseResultTraits1::template ReturnValue( @@ -336,16 +325,14 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; default: case State::kState2: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 3/3"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 3/3"; auto result = current_promise(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 3/3 gets " - << (result.ready() ? "ready" : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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{}; return Result(std::move(*p)); @@ -460,24 +447,21 @@ struct SeqState { GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Poll PollOnce() { switch (state) { case State::kState0: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 1/4"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { return PromiseResultTraits0::template ReturnValue( @@ -492,24 +476,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState1: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 2/4"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { return PromiseResultTraits1::template ReturnValue( @@ -524,24 +505,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState2: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 3/4"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { return PromiseResultTraits2::template ReturnValue( @@ -557,16 +535,14 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; default: case State::kState3: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 4/4"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 4/4"; auto result = current_promise(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 4/4 gets " - << (result.ready() ? "ready" : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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{}; return Result(std::move(*p)); @@ -703,24 +679,21 @@ struct SeqState { GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Poll PollOnce() { switch (state) { case State::kState0: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 1/5"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { return PromiseResultTraits0::template ReturnValue( @@ -735,24 +708,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState1: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 2/5"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { return PromiseResultTraits1::template ReturnValue( @@ -767,24 +737,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState2: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 3/5"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { return PromiseResultTraits2::template ReturnValue( @@ -799,24 +766,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState3: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 4/5"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits3::IsOk(*p)) { return PromiseResultTraits3::template ReturnValue( @@ -832,16 +796,14 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; default: case State::kState4: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 5/5"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 5/5"; auto result = current_promise(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 5/5 gets " - << (result.ready() ? "ready" : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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{}; return Result(std::move(*p)); @@ -1009,24 +971,21 @@ struct SeqState { GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Poll PollOnce() { switch (state) { case State::kState0: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 1/6"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { return PromiseResultTraits0::template ReturnValue( @@ -1042,24 +1001,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState1: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 2/6"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { return PromiseResultTraits1::template ReturnValue( @@ -1074,24 +1030,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState2: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 3/6"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { return PromiseResultTraits2::template ReturnValue( @@ -1106,24 +1059,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState3: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 4/6"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits3::IsOk(*p)) { return PromiseResultTraits3::template ReturnValue( @@ -1138,24 +1088,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState4: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 5/6"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits4::IsOk(*p)) { return PromiseResultTraits4::template ReturnValue( @@ -1171,16 +1118,14 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; default: case State::kState5: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 6/6"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 6/6"; auto result = current_promise(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 6/6 gets " - << (result.ready() ? "ready" : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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{}; return Result(std::move(*p)); @@ -1375,24 +1320,21 @@ struct SeqState { GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Poll PollOnce() { switch (state) { case State::kState0: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 1/7"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { return PromiseResultTraits0::template ReturnValue( @@ -1408,24 +1350,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState1: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 2/7"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { return PromiseResultTraits1::template ReturnValue( @@ -1441,24 +1380,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState2: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 3/7"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { return PromiseResultTraits2::template ReturnValue( @@ -1473,24 +1409,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState3: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 4/7"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits3::IsOk(*p)) { return PromiseResultTraits3::template ReturnValue( @@ -1505,24 +1438,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState4: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 5/7"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits4::IsOk(*p)) { return PromiseResultTraits4::template ReturnValue( @@ -1537,24 +1467,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState5: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 6/7"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits5::IsOk(*p)) { return PromiseResultTraits5::template ReturnValue( @@ -1570,16 +1497,14 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; default: case State::kState6: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 7/7"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 7/7"; auto result = current_promise(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 7/7 gets " - << (result.ready() ? "ready" : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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{}; return Result(std::move(*p)); @@ -1802,25 +1727,22 @@ struct SeqState { GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Poll PollOnce() { switch (state) { case State::kState0: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 1/8"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { return PromiseResultTraits0::template ReturnValue( @@ -1837,24 +1759,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState1: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 2/8"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { return PromiseResultTraits1::template ReturnValue( @@ -1870,24 +1789,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState2: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 3/8"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { return PromiseResultTraits2::template ReturnValue( @@ -1903,24 +1819,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState3: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 4/8"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits3::IsOk(*p)) { return PromiseResultTraits3::template ReturnValue( @@ -1935,24 +1848,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState4: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 5/8"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits4::IsOk(*p)) { return PromiseResultTraits4::template ReturnValue( @@ -1967,24 +1877,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState5: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 6/8"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits5::IsOk(*p)) { return PromiseResultTraits5::template ReturnValue( @@ -1999,24 +1906,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState6: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 7/8"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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_FLAG_ENABLED(promise_primitives)) { - VLOG(2).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)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits6::IsOk(*p)) { return PromiseResultTraits6::template ReturnValue( @@ -2032,16 +1936,14 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; default: case State::kState7: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 8/8"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 8/8"; auto result = current_promise(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 8/8 gets " - << (result.ready() ? "ready" : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .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{}; return Result(std::move(*p)); @@ -2291,25 +2193,22 @@ struct SeqState { GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Poll PollOnce() { switch (state) { case State::kState0: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 1/9"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 1/9"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult0* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 1/9 gets " - << (p != nullptr - ? (PromiseResultTraits0::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits0::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 1/9 gets " + << (p != nullptr + ? (PromiseResultTraits0::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits0::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { return PromiseResultTraits0::template ReturnValue( @@ -2327,25 +2226,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState1: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 2/9"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 2/9"; auto result = prior.prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult1* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 2/9 gets " - << (p != nullptr - ? (PromiseResultTraits1::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits1::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 2/9 gets " + << (p != nullptr + ? (PromiseResultTraits1::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits1::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { return PromiseResultTraits1::template ReturnValue( @@ -2362,24 +2258,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState2: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 3/9"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 3/9"; auto result = prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult2* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 3/9 gets " - << (p != nullptr - ? (PromiseResultTraits2::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits2::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 3/9 gets " + << (p != nullptr + ? (PromiseResultTraits2::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits2::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { return PromiseResultTraits2::template ReturnValue( @@ -2395,24 +2288,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState3: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 4/9"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 4/9"; auto result = prior.prior.prior.prior.prior.current_promise(); PromiseResult3* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 4/9 gets " - << (p != nullptr - ? (PromiseResultTraits3::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits3::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 4/9 gets " + << (p != nullptr + ? (PromiseResultTraits3::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits3::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits3::IsOk(*p)) { return PromiseResultTraits3::template ReturnValue( @@ -2428,24 +2318,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState4: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 5/9"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 5/9"; auto result = prior.prior.prior.prior.current_promise(); PromiseResult4* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 5/9 gets " - << (p != nullptr - ? (PromiseResultTraits4::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits4::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 5/9 gets " + << (p != nullptr + ? (PromiseResultTraits4::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits4::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits4::IsOk(*p)) { return PromiseResultTraits4::template ReturnValue( @@ -2460,24 +2347,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState5: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 6/9"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 6/9"; auto result = prior.prior.prior.current_promise(); PromiseResult5* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 6/9 gets " - << (p != nullptr - ? (PromiseResultTraits5::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits5::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 6/9 gets " + << (p != nullptr + ? (PromiseResultTraits5::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits5::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits5::IsOk(*p)) { return PromiseResultTraits5::template ReturnValue( @@ -2492,24 +2376,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState6: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 7/9"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 7/9"; auto result = prior.prior.current_promise(); PromiseResult6* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 7/9 gets " - << (p != nullptr - ? (PromiseResultTraits6::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits6::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 7/9 gets " + << (p != nullptr + ? (PromiseResultTraits6::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits6::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits6::IsOk(*p)) { return PromiseResultTraits6::template ReturnValue( @@ -2524,24 +2405,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState7: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 8/9"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 8/9"; auto result = prior.current_promise(); PromiseResult7* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 8/9 gets " - << (p != nullptr - ? (PromiseResultTraits7::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits7::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 8/9 gets " + << (p != nullptr + ? (PromiseResultTraits7::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits7::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits7::IsOk(*p)) { return PromiseResultTraits7::template ReturnValue( @@ -2557,16 +2435,14 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; default: case State::kState8: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 9/9"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 9/9"; auto result = current_promise(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 9/9 gets " - << (result.ready() ? "ready" : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 9/9 gets " + << (result.ready() ? "ready" : "pending"); auto* p = result.value_if_ready(); if (p == nullptr) return Pending{}; return Result(std::move(*p)); @@ -2851,25 +2727,22 @@ struct SeqState { GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Poll PollOnce() { switch (state) { case State::kState0: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 1/10"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 1/10"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior .current_promise(); PromiseResult0* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 1/10 gets " - << (p != nullptr - ? (PromiseResultTraits0::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits0::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 1/10 gets " + << (p != nullptr + ? (PromiseResultTraits0::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits0::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { return PromiseResultTraits0::template ReturnValue( @@ -2889,25 +2762,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState1: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 2/10"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 2/10"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult1* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 2/10 gets " - << (p != nullptr - ? (PromiseResultTraits1::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits1::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 2/10 gets " + << (p != nullptr + ? (PromiseResultTraits1::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits1::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { return PromiseResultTraits1::template ReturnValue( @@ -2925,25 +2795,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState2: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 3/10"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 3/10"; auto result = prior.prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult2* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 3/10 gets " - << (p != nullptr - ? (PromiseResultTraits2::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits2::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 3/10 gets " + << (p != nullptr + ? (PromiseResultTraits2::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits2::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { return PromiseResultTraits2::template ReturnValue( @@ -2960,24 +2827,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState3: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 4/10"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 4/10"; auto result = prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult3* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 4/10 gets " - << (p != nullptr - ? (PromiseResultTraits3::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits3::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 4/10 gets " + << (p != nullptr + ? (PromiseResultTraits3::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits3::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits3::IsOk(*p)) { return PromiseResultTraits3::template ReturnValue( @@ -2993,24 +2857,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState4: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 5/10"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 5/10"; auto result = prior.prior.prior.prior.prior.current_promise(); PromiseResult4* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 5/10 gets " - << (p != nullptr - ? (PromiseResultTraits4::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits4::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 5/10 gets " + << (p != nullptr + ? (PromiseResultTraits4::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits4::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits4::IsOk(*p)) { return PromiseResultTraits4::template ReturnValue( @@ -3026,24 +2887,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState5: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 6/10"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 6/10"; auto result = prior.prior.prior.prior.current_promise(); PromiseResult5* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 6/10 gets " - << (p != nullptr - ? (PromiseResultTraits5::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits5::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 6/10 gets " + << (p != nullptr + ? (PromiseResultTraits5::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits5::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits5::IsOk(*p)) { return PromiseResultTraits5::template ReturnValue( @@ -3058,24 +2916,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState6: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 7/10"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 7/10"; auto result = prior.prior.prior.current_promise(); PromiseResult6* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 7/10 gets " - << (p != nullptr - ? (PromiseResultTraits6::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits6::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 7/10 gets " + << (p != nullptr + ? (PromiseResultTraits6::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits6::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits6::IsOk(*p)) { return PromiseResultTraits6::template ReturnValue( @@ -3090,24 +2945,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState7: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 8/10"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 8/10"; auto result = prior.prior.current_promise(); PromiseResult7* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 8/10 gets " - << (p != nullptr - ? (PromiseResultTraits7::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits7::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 8/10 gets " + << (p != nullptr + ? (PromiseResultTraits7::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits7::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits7::IsOk(*p)) { return PromiseResultTraits7::template ReturnValue( @@ -3122,24 +2974,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState8: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 9/10"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 9/10"; auto result = prior.current_promise(); PromiseResult8* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 9/10 gets " - << (p != nullptr - ? (PromiseResultTraits8::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits8::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 9/10 gets " + << (p != nullptr + ? (PromiseResultTraits8::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits8::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits8::IsOk(*p)) { return PromiseResultTraits8::template ReturnValue( @@ -3155,16 +3004,14 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; default: case State::kState9: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 10/10"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 10/10"; auto result = current_promise(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 10/10 gets " - << (result.ready() ? "ready" : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 10/10 gets " + << (result.ready() ? "ready" : "pending"); auto* p = result.value_if_ready(); if (p == nullptr) return Pending{}; return Result(std::move(*p)); @@ -3480,25 +3327,22 @@ struct SeqState { GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Poll PollOnce() { switch (state) { case State::kState0: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 1/11"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 1/11"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior .prior.current_promise(); PromiseResult0* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 1/11 gets " - << (p != nullptr - ? (PromiseResultTraits0::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits0::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 1/11 gets " + << (p != nullptr + ? (PromiseResultTraits0::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits0::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { return PromiseResultTraits0::template ReturnValue( @@ -3519,25 +3363,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState1: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 2/11"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 2/11"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior .current_promise(); PromiseResult1* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 2/11 gets " - << (p != nullptr - ? (PromiseResultTraits1::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits1::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 2/11 gets " + << (p != nullptr + ? (PromiseResultTraits1::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits1::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { return PromiseResultTraits1::template ReturnValue( @@ -3557,25 +3398,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState2: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 3/11"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 3/11"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult2* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 3/11 gets " - << (p != nullptr - ? (PromiseResultTraits2::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits2::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 3/11 gets " + << (p != nullptr + ? (PromiseResultTraits2::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits2::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { return PromiseResultTraits2::template ReturnValue( @@ -3593,25 +3431,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState3: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 4/11"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 4/11"; auto result = prior.prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult3* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 4/11 gets " - << (p != nullptr - ? (PromiseResultTraits3::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits3::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 4/11 gets " + << (p != nullptr + ? (PromiseResultTraits3::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits3::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits3::IsOk(*p)) { return PromiseResultTraits3::template ReturnValue( @@ -3628,24 +3463,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState4: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 5/11"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 5/11"; auto result = prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult4* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 5/11 gets " - << (p != nullptr - ? (PromiseResultTraits4::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits4::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 5/11 gets " + << (p != nullptr + ? (PromiseResultTraits4::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits4::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits4::IsOk(*p)) { return PromiseResultTraits4::template ReturnValue( @@ -3661,24 +3493,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState5: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 6/11"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 6/11"; auto result = prior.prior.prior.prior.prior.current_promise(); PromiseResult5* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 6/11 gets " - << (p != nullptr - ? (PromiseResultTraits5::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits5::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 6/11 gets " + << (p != nullptr + ? (PromiseResultTraits5::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits5::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits5::IsOk(*p)) { return PromiseResultTraits5::template ReturnValue( @@ -3694,24 +3523,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState6: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 7/11"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 7/11"; auto result = prior.prior.prior.prior.current_promise(); PromiseResult6* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 7/11 gets " - << (p != nullptr - ? (PromiseResultTraits6::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits6::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 7/11 gets " + << (p != nullptr + ? (PromiseResultTraits6::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits6::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits6::IsOk(*p)) { return PromiseResultTraits6::template ReturnValue( @@ -3726,24 +3552,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState7: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 8/11"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 8/11"; auto result = prior.prior.prior.current_promise(); PromiseResult7* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 8/11 gets " - << (p != nullptr - ? (PromiseResultTraits7::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits7::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 8/11 gets " + << (p != nullptr + ? (PromiseResultTraits7::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits7::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits7::IsOk(*p)) { return PromiseResultTraits7::template ReturnValue( @@ -3758,24 +3581,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState8: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 9/11"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 9/11"; auto result = prior.prior.current_promise(); PromiseResult8* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 9/11 gets " - << (p != nullptr - ? (PromiseResultTraits8::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits8::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 9/11 gets " + << (p != nullptr + ? (PromiseResultTraits8::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits8::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits8::IsOk(*p)) { return PromiseResultTraits8::template ReturnValue( @@ -3790,24 +3610,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState9: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 10/11"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 10/11"; auto result = prior.current_promise(); PromiseResult9* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 10/11 gets " - << (p != nullptr - ? (PromiseResultTraits9::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits9::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 10/11 gets " + << (p != nullptr + ? (PromiseResultTraits9::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits9::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits9::IsOk(*p)) { return PromiseResultTraits9::template ReturnValue( @@ -3823,16 +3640,14 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; default: case State::kState10: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 11/11"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 11/11"; auto result = current_promise(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 11/11 gets " - << (result.ready() ? "ready" : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 11/11 gets " + << (result.ready() ? "ready" : "pending"); auto* p = result.value_if_ready(); if (p == nullptr) return Pending{}; return Result(std::move(*p)); @@ -4179,25 +3994,22 @@ struct SeqState { GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Poll PollOnce() { switch (state) { case State::kState0: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 1/12"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 1/12"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior .prior.prior.current_promise(); PromiseResult0* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 1/12 gets " - << (p != nullptr - ? (PromiseResultTraits0::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits0::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 1/12 gets " + << (p != nullptr + ? (PromiseResultTraits0::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits0::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { return PromiseResultTraits0::template ReturnValue( @@ -4218,25 +4030,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState1: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 2/12"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 2/12"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior .prior.current_promise(); PromiseResult1* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 2/12 gets " - << (p != nullptr - ? (PromiseResultTraits1::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits1::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 2/12 gets " + << (p != nullptr + ? (PromiseResultTraits1::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits1::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { return PromiseResultTraits1::template ReturnValue( @@ -4257,25 +4066,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState2: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 3/12"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 3/12"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior .current_promise(); PromiseResult2* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 3/12 gets " - << (p != nullptr - ? (PromiseResultTraits2::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits2::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 3/12 gets " + << (p != nullptr + ? (PromiseResultTraits2::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits2::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { return PromiseResultTraits2::template ReturnValue( @@ -4295,25 +4101,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState3: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 4/12"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 4/12"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult3* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 4/12 gets " - << (p != nullptr - ? (PromiseResultTraits3::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits3::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 4/12 gets " + << (p != nullptr + ? (PromiseResultTraits3::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits3::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits3::IsOk(*p)) { return PromiseResultTraits3::template ReturnValue( @@ -4331,25 +4134,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState4: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 5/12"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 5/12"; auto result = prior.prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult4* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 5/12 gets " - << (p != nullptr - ? (PromiseResultTraits4::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits4::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 5/12 gets " + << (p != nullptr + ? (PromiseResultTraits4::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits4::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits4::IsOk(*p)) { return PromiseResultTraits4::template ReturnValue( @@ -4366,24 +4166,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState5: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 6/12"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 6/12"; auto result = prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult5* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 6/12 gets " - << (p != nullptr - ? (PromiseResultTraits5::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits5::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 6/12 gets " + << (p != nullptr + ? (PromiseResultTraits5::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits5::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits5::IsOk(*p)) { return PromiseResultTraits5::template ReturnValue( @@ -4399,24 +4196,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState6: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 7/12"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 7/12"; auto result = prior.prior.prior.prior.prior.current_promise(); PromiseResult6* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 7/12 gets " - << (p != nullptr - ? (PromiseResultTraits6::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits6::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 7/12 gets " + << (p != nullptr + ? (PromiseResultTraits6::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits6::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits6::IsOk(*p)) { return PromiseResultTraits6::template ReturnValue( @@ -4432,24 +4226,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState7: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 8/12"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 8/12"; auto result = prior.prior.prior.prior.current_promise(); PromiseResult7* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 8/12 gets " - << (p != nullptr - ? (PromiseResultTraits7::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits7::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 8/12 gets " + << (p != nullptr + ? (PromiseResultTraits7::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits7::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits7::IsOk(*p)) { return PromiseResultTraits7::template ReturnValue( @@ -4464,24 +4255,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState8: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 9/12"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 9/12"; auto result = prior.prior.prior.current_promise(); PromiseResult8* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 9/12 gets " - << (p != nullptr - ? (PromiseResultTraits8::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits8::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 9/12 gets " + << (p != nullptr + ? (PromiseResultTraits8::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits8::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits8::IsOk(*p)) { return PromiseResultTraits8::template ReturnValue( @@ -4496,24 +4284,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState9: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 10/12"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 10/12"; auto result = prior.prior.current_promise(); PromiseResult9* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 10/12 gets " - << (p != nullptr - ? (PromiseResultTraits9::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits9::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 10/12 gets " + << (p != nullptr + ? (PromiseResultTraits9::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits9::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits9::IsOk(*p)) { return PromiseResultTraits9::template ReturnValue( @@ -4528,24 +4313,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState10: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 11/12"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 11/12"; auto result = prior.current_promise(); PromiseResult10* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 11/12 gets " - << (p != nullptr - ? (PromiseResultTraits10::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits10::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 11/12 gets " + << (p != nullptr + ? (PromiseResultTraits10::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits10::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits10::IsOk(*p)) { return PromiseResultTraits10::template ReturnValue( @@ -4561,16 +4344,14 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; default: case State::kState11: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 12/12"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 12/12"; auto result = current_promise(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 12/12 gets " - << (result.ready() ? "ready" : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 12/12 gets " + << (result.ready() ? "ready" : "pending"); auto* p = result.value_if_ready(); if (p == nullptr) return Pending{}; return Result(std::move(*p)); @@ -4950,25 +4731,22 @@ struct SeqState { GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Poll PollOnce() { switch (state) { case State::kState0: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 1/13"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 1/13"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior .prior.prior.prior.current_promise(); PromiseResult0* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 1/13 gets " - << (p != nullptr - ? (PromiseResultTraits0::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits0::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 1/13 gets " + << (p != nullptr + ? (PromiseResultTraits0::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits0::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits0::IsOk(*p)) { return PromiseResultTraits0::template ReturnValue( @@ -4989,25 +4767,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState1: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 2/13"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 2/13"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior .prior.prior.current_promise(); PromiseResult1* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 2/13 gets " - << (p != nullptr - ? (PromiseResultTraits1::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits1::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 2/13 gets " + << (p != nullptr + ? (PromiseResultTraits1::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits1::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits1::IsOk(*p)) { return PromiseResultTraits1::template ReturnValue( @@ -5028,25 +4803,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState2: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 3/13"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 3/13"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior .prior.current_promise(); PromiseResult2* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 3/13 gets " - << (p != nullptr - ? (PromiseResultTraits2::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits2::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 3/13 gets " + << (p != nullptr + ? (PromiseResultTraits2::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits2::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits2::IsOk(*p)) { return PromiseResultTraits2::template ReturnValue( @@ -5067,25 +4839,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState3: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 4/13"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 4/13"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior .current_promise(); PromiseResult3* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 4/13 gets " - << (p != nullptr - ? (PromiseResultTraits3::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits3::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 4/13 gets " + << (p != nullptr + ? (PromiseResultTraits3::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits3::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits3::IsOk(*p)) { return PromiseResultTraits3::template ReturnValue( @@ -5105,25 +4874,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState4: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 5/13"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 5/13"; auto result = prior.prior.prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult4* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 5/13 gets " - << (p != nullptr - ? (PromiseResultTraits4::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits4::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 5/13 gets " + << (p != nullptr + ? (PromiseResultTraits4::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits4::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits4::IsOk(*p)) { return PromiseResultTraits4::template ReturnValue( @@ -5141,25 +4907,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState5: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 6/13"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 6/13"; auto result = prior.prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult5* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 6/13 gets " - << (p != nullptr - ? (PromiseResultTraits5::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits5::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 6/13 gets " + << (p != nullptr + ? (PromiseResultTraits5::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits5::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits5::IsOk(*p)) { return PromiseResultTraits5::template ReturnValue( @@ -5176,24 +4939,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState6: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 7/13"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 7/13"; auto result = prior.prior.prior.prior.prior.prior.current_promise(); PromiseResult6* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 7/13 gets " - << (p != nullptr - ? (PromiseResultTraits6::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits6::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 7/13 gets " + << (p != nullptr + ? (PromiseResultTraits6::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits6::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits6::IsOk(*p)) { return PromiseResultTraits6::template ReturnValue( @@ -5209,24 +4969,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState7: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 8/13"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 8/13"; auto result = prior.prior.prior.prior.prior.current_promise(); PromiseResult7* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 8/13 gets " - << (p != nullptr - ? (PromiseResultTraits7::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits7::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 8/13 gets " + << (p != nullptr + ? (PromiseResultTraits7::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits7::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits7::IsOk(*p)) { return PromiseResultTraits7::template ReturnValue( @@ -5242,24 +4999,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState8: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 9/13"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 9/13"; auto result = prior.prior.prior.prior.current_promise(); PromiseResult8* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 9/13 gets " - << (p != nullptr - ? (PromiseResultTraits8::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits8::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 9/13 gets " + << (p != nullptr + ? (PromiseResultTraits8::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits8::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits8::IsOk(*p)) { return PromiseResultTraits8::template ReturnValue( @@ -5274,24 +5028,21 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState9: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 10/13"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 10/13"; auto result = prior.prior.prior.current_promise(); PromiseResult9* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 10/13 gets " - << (p != nullptr - ? (PromiseResultTraits9::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits9::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 10/13 gets " + << (p != nullptr + ? (PromiseResultTraits9::IsOk(*p) + ? "ready" + : absl::StrCat("early-error:", + PromiseResultTraits9::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits9::IsOk(*p)) { return PromiseResultTraits9::template ReturnValue( @@ -5306,24 +5057,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState10: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 11/13"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 11/13"; auto result = prior.prior.current_promise(); PromiseResult10* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 11/13 gets " - << (p != nullptr - ? (PromiseResultTraits10::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits10::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 11/13 gets " + << (p != nullptr + ? (PromiseResultTraits10::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits10::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits10::IsOk(*p)) { return PromiseResultTraits10::template ReturnValue( @@ -5338,24 +5087,22 @@ struct SeqState { } ABSL_FALLTHROUGH_INTENDED; case State::kState11: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 12/13"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 12/13"; auto result = prior.current_promise(); PromiseResult11* p = result.value_if_ready(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 12/13 gets " - << (p != nullptr - ? (PromiseResultTraits11::IsOk(*p) - ? "ready" - : absl::StrCat( - "early-error:", - PromiseResultTraits11::ErrorString(*p)) - .c_str()) - : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 12/13 gets " + << (p != nullptr + ? (PromiseResultTraits11::IsOk(*p) + ? "ready" + : absl::StrCat( + "early-error:", + PromiseResultTraits11::ErrorString(*p)) + .c_str()) + : "pending"); if (p == nullptr) return Pending{}; if (!PromiseResultTraits11::IsOk(*p)) { return PromiseResultTraits11::template ReturnValue( @@ -5371,16 +5118,14 @@ struct SeqState { ABSL_FALLTHROUGH_INTENDED; default: case State::kState12: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: begin poll step 13/13"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: begin poll step 13/13"; auto result = current_promise(); - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(whence.file(), whence.line()) - << "seq[" << this << "]: poll step 13/13 gets " - << (result.ready() ? "ready" : "pending"); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(whence.file(), whence.line()) + << "seq[" << this << "]: poll step 13/13 gets " + << (result.ready() ? "ready" : "pending"); auto* p = result.value_if_ready(); if (p == nullptr) return Pending{}; return Result(std::move(*p)); diff --git a/src/core/lib/promise/for_each.h b/src/core/lib/promise/for_each.h index 62a4c8de56..60eb19b713 100644 --- a/src/core/lib/promise/for_each.h +++ b/src/core/lib/promise/for_each.h @@ -172,16 +172,13 @@ class ForEach { } GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Poll PollReaderNext() { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - LOG(INFO) << DebugTag() << " PollReaderNext"; - } + GRPC_TRACE_LOG(promise_primitives, INFO) << DebugTag() << " PollReaderNext"; auto r = reader_next_(); if (auto* p = r.value_if_ready()) { switch (NextValueTraits::Type(*p)) { case NextValueType::kValue: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - LOG(INFO) << DebugTag() << " PollReaderNext: got value"; - } + GRPC_TRACE_LOG(promise_primitives, INFO) + << DebugTag() << " PollReaderNext: got value"; Destruct(&reader_next_); auto action = action_factory_.Make( std::move(NextValueTraits::MutableValue(*p))); @@ -190,15 +187,13 @@ class ForEach { return PollAction(); } case NextValueType::kEndOfStream: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - LOG(INFO) << DebugTag() << " PollReaderNext: got end of stream"; - } + GRPC_TRACE_LOG(promise_primitives, INFO) + << DebugTag() << " PollReaderNext: got end of stream"; return Done::Make(false); } case NextValueType::kError: { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - LOG(INFO) << DebugTag() << " PollReaderNext: got error"; - } + GRPC_TRACE_LOG(promise_primitives, INFO) + << DebugTag() << " PollReaderNext: got error"; return Done::Make(true); } } @@ -207,9 +202,7 @@ class ForEach { } Poll PollAction() { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - LOG(INFO) << DebugTag() << " PollAction"; - } + GRPC_TRACE_LOG(promise_primitives, INFO) << DebugTag() << " PollAction"; auto r = in_action_.promise(); if (auto* p = r.value_if_ready()) { if (IsStatusOk(*p)) { diff --git a/src/core/lib/promise/interceptor_list.h b/src/core/lib/promise/interceptor_list.h index dc36c2ee28..dc9b63d3f8 100644 --- a/src/core/lib/promise/interceptor_list.h +++ b/src/core/lib/promise/interceptor_list.h @@ -87,10 +87,8 @@ class InterceptorList { public: RunPromise(size_t memory_required, Map** factory, absl::optional value) { if (!value.has_value() || *factory == nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2) << "InterceptorList::RunPromise[" << this - << "]: create immediate"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + << "InterceptorList::RunPromise[" << this << "]: create immediate"; is_immediately_resolved_ = true; Construct(&result_, std::move(value)); } else { @@ -100,17 +98,15 @@ class InterceptorList { async_resolution_.space.get()); async_resolution_.current_factory = *factory; async_resolution_.first_factory = factory; - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2) << "InterceptorList::RunPromise[" << this - << "]: create async; mem=" << async_resolution_.space.get(); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + << "InterceptorList::RunPromise[" << this + << "]: create async; mem=" << async_resolution_.space.get(); } } ~RunPromise() { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2) << "InterceptorList::RunPromise[" << this << "]: destroy"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + << "InterceptorList::RunPromise[" << this << "]: destroy"; if (is_immediately_resolved_) { Destruct(&result_); } else { @@ -127,10 +123,9 @@ class InterceptorList { RunPromise(RunPromise&& other) noexcept : is_immediately_resolved_(other.is_immediately_resolved_) { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2) << "InterceptorList::RunPromise[" << this << "]: move from " - << &other; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + << "InterceptorList::RunPromise[" << this << "]: move from " + << &other; if (is_immediately_resolved_) { Construct(&result_, std::move(other.result_)); } else { @@ -141,10 +136,8 @@ class InterceptorList { RunPromise& operator=(RunPromise&& other) noexcept = delete; Poll> operator()() { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2) << "InterceptorList::RunPromise[" << this - << "]: " << DebugString(); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + << "InterceptorList::RunPromise[" << this << "]: " << DebugString(); if (is_immediately_resolved_) return std::move(result_); while (true) { if (*async_resolution_.first_factory == nullptr) { @@ -159,10 +152,9 @@ class InterceptorList { async_resolution_.current_factory = async_resolution_.current_factory->next(); if (!p->has_value()) async_resolution_.current_factory = nullptr; - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2) << "InterceptorList::RunPromise[" << this - << "]: " << DebugString(); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + << "InterceptorList::RunPromise[" << this + << "]: " << DebugString(); if (async_resolution_.current_factory == nullptr) { return std::move(*p); } @@ -225,15 +217,13 @@ class InterceptorList { // Append a new map to the end of the chain. template void AppendMap(Fn fn, DebugLocation from) { - Append(MakeMapToAdd( - std::move(fn), [] {}, from)); + Append(MakeMapToAdd(std::move(fn), [] {}, from)); } // Prepend a new map to the beginning of the chain. template void PrependMap(Fn fn, DebugLocation from) { - Prepend(MakeMapToAdd( - std::move(fn), [] {}, from)); + Prepend(MakeMapToAdd(std::move(fn), [] {}, from)); } // Append a new map to the end of the chain, with a cleanup function to be diff --git a/src/core/lib/promise/latch.h b/src/core/lib/promise/latch.h index e946cd739d..10f4776117 100644 --- a/src/core/lib/promise/latch.h +++ b/src/core/lib/promise/latch.h @@ -67,9 +67,8 @@ class Latch { has_had_waiters_ = true; #endif return [this]() -> Poll { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - LOG(INFO) << DebugTag() << "Wait " << StateString(); - } + GRPC_TRACE_LOG(promise_primitives, INFO) + << DebugTag() << "Wait " << StateString(); if (has_value_) { return std::move(value_); } else { @@ -85,9 +84,8 @@ class Latch { has_had_waiters_ = true; #endif return [this]() -> Poll { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - LOG(INFO) << DebugTag() << "WaitAndCopy " << StateString(); - } + GRPC_TRACE_LOG(promise_primitives, INFO) + << DebugTag() << "WaitAndCopy " << StateString(); if (has_value_) { return value_; } else { @@ -98,9 +96,8 @@ class Latch { // Set the value of the latch. Can only be called once. void Set(T value) { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - LOG(INFO) << DebugTag() << "Set " << StateString(); - } + GRPC_TRACE_LOG(promise_primitives, INFO) + << DebugTag() << "Set " << StateString(); DCHECK(!has_value_); value_ = std::move(value); has_value_ = true; @@ -161,9 +158,8 @@ class Latch { has_had_waiters_ = true; #endif return [this]() -> Poll { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - LOG(INFO) << DebugTag() << "PollWait " << StateString(); - } + GRPC_TRACE_LOG(promise_primitives, INFO) + << DebugTag() << "PollWait " << StateString(); if (is_set_) { return Empty{}; } else { @@ -174,9 +170,8 @@ class Latch { // Set the latch. Can only be called once. void Set() { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - LOG(INFO) << DebugTag() << "Set " << StateString(); - } + GRPC_TRACE_LOG(promise_primitives, INFO) + << DebugTag() << "Set " << StateString(); DCHECK(!is_set_); is_set_ = true; waiter_.Wake(); @@ -223,9 +218,8 @@ class ExternallyObservableLatch { // Produce a promise to wait for this latch. auto Wait() { return [this]() -> Poll { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - LOG(INFO) << DebugTag() << "PollWait " << StateString(); - } + GRPC_TRACE_LOG(promise_primitives, INFO) + << DebugTag() << "PollWait " << StateString(); if (IsSet()) { return Empty{}; } else { @@ -236,9 +230,8 @@ class ExternallyObservableLatch { // Set the latch. void Set() { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - LOG(INFO) << DebugTag() << "Set " << StateString(); - } + GRPC_TRACE_LOG(promise_primitives, INFO) + << DebugTag() << "Set " << StateString(); is_set_.store(true, std::memory_order_relaxed); waiter_.Wake(); } @@ -246,9 +239,8 @@ class ExternallyObservableLatch { bool IsSet() const { return is_set_.load(std::memory_order_relaxed); } void Reset() { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - LOG(INFO) << DebugTag() << "Reset " << StateString(); - } + GRPC_TRACE_LOG(promise_primitives, INFO) + << DebugTag() << "Reset " << StateString(); is_set_.store(false, std::memory_order_relaxed); } diff --git a/src/core/lib/promise/map.h b/src/core/lib/promise/map.h index a2a2a773ee..3ba8c19c2f 100644 --- a/src/core/lib/promise/map.h +++ b/src/core/lib/promise/map.h @@ -86,7 +86,7 @@ GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION auto CheckDelayed(Promise promise) { delayed = true; return Pending{}; } - return std::make_tuple(r.value(), delayed); + return std::make_tuple(std::move(r.value()), delayed); }; } diff --git a/src/core/lib/promise/party.cc b/src/core/lib/promise/party.cc index cdf6dd1029..c8bde2d198 100644 --- a/src/core/lib/promise/party.cc +++ b/src/core/lib/promise/party.cc @@ -276,7 +276,7 @@ void Party::RunPartyAndUnref(uint64_t prev_state) { auto wakeup_mask = std::exchange(wakeup_mask_, 0); while (wakeup_mask != 0) { const uint64_t t = LowestOneBit(wakeup_mask); - const int i = CountTrailingZeros(t); + const int i = absl::countr_zero(t); wakeup_mask ^= t; // If the participant is null, skip. // This allows participants to complete whilst wakers still exist @@ -364,7 +364,7 @@ void Party::AddParticipants(Participant** participants, size_t count) { } wakeup_mask |= new_mask; allocated |= new_mask; - slots[i] = CountTrailingZeros(new_mask); + slots[i] = absl::countr_zero(new_mask); } // Try to allocate this slot and take a ref (atomically). // Ref needs to be taken because once we store the participant it could be @@ -406,7 +406,7 @@ void Party::AddParticipant(Participant* participant) { << "No available slots for new participant; allocated=" << allocated << " state=" << state << " wakeup_mask=" << wakeup_mask; allocated |= wakeup_mask; - slot = CountTrailingZeros(wakeup_mask); + slot = absl::countr_zero(wakeup_mask); // Try to allocate this slot and take a ref (atomically). // Ref needs to be taken because once we store the participant it could be // spuriously woken up and unref the party. diff --git a/src/core/lib/promise/pipe.h b/src/core/lib/promise/pipe.h index 86f0b98d8e..59ec003f47 100644 --- a/src/core/lib/promise/pipe.h +++ b/src/core/lib/promise/pipe.h @@ -634,10 +634,9 @@ class Push { Poll operator()() { if (center_ == nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2) << GetContext()->DebugTag() - << " Pipe push has a null center"; - } + GRPC_TRACE_VLOG(promise_primitives, 2) + << GetContext()->DebugTag() + << " Pipe push has a null center"; return false; } if (auto* p = absl::get_if(&state_)) { diff --git a/src/core/lib/promise/poll.h b/src/core/lib/promise/poll.h index 7e26b7b366..36570a56fb 100644 --- a/src/core/lib/promise/poll.h +++ b/src/core/lib/promise/poll.h @@ -22,7 +22,6 @@ #include "absl/strings/str_format.h" #include "absl/types/optional.h" -#include #include #include "src/core/lib/gprpp/construct_destruct.h" diff --git a/src/core/lib/promise/status_flag.h b/src/core/lib/promise/status_flag.h index 5dbe224955..250dce5050 100644 --- a/src/core/lib/promise/status_flag.h +++ b/src/core/lib/promise/status_flag.h @@ -23,7 +23,6 @@ #include "absl/strings/str_cat.h" #include "absl/types/optional.h" -#include #include #include "src/core/lib/promise/detail/status.h" diff --git a/src/core/lib/resource_quota/connection_quota.cc b/src/core/lib/resource_quota/connection_quota.cc index ab07f5e21b..846883f78c 100644 --- a/src/core/lib/resource_quota/connection_quota.cc +++ b/src/core/lib/resource_quota/connection_quota.cc @@ -19,7 +19,6 @@ #include "absl/log/check.h" -#include #include namespace grpc_core { diff --git a/src/core/lib/resource_quota/memory_quota.cc b/src/core/lib/resource_quota/memory_quota.cc index a4841a2542..29b3a581a9 100644 --- a/src/core/lib/resource_quota/memory_quota.cc +++ b/src/core/lib/resource_quota/memory_quota.cc @@ -355,9 +355,8 @@ void GrpcMemoryAllocatorImpl::MaybeDonateBack() { if (free_bytes_.compare_exchange_weak(free, new_free, std::memory_order_acq_rel, std::memory_order_acquire)) { - if (GRPC_TRACE_FLAG_ENABLED(resource_quota)) { - LOG(INFO) << "[" << this << "] Early return " << ret << " bytes"; - } + GRPC_TRACE_LOG(resource_quota, INFO) + << "[" << this << "] Early return " << ret << " bytes"; CHECK(taken_bytes_.fetch_sub(ret, std::memory_order_relaxed) >= ret); memory_quota_->Return(ret); return; @@ -548,9 +547,7 @@ void BasicMemoryQuota::Return(size_t amount) { } void BasicMemoryQuota::AddNewAllocator(GrpcMemoryAllocatorImpl* allocator) { - if (GRPC_TRACE_FLAG_ENABLED(resource_quota)) { - LOG(INFO) << "Adding allocator " << allocator; - } + GRPC_TRACE_LOG(resource_quota, INFO) << "Adding allocator " << allocator; AllocatorBucket::Shard& shard = small_allocators_.SelectShard(allocator); @@ -561,9 +558,7 @@ void BasicMemoryQuota::AddNewAllocator(GrpcMemoryAllocatorImpl* allocator) { } void BasicMemoryQuota::RemoveAllocator(GrpcMemoryAllocatorImpl* allocator) { - if (GRPC_TRACE_FLAG_ENABLED(resource_quota)) { - LOG(INFO) << "Removing allocator " << allocator; - } + GRPC_TRACE_LOG(resource_quota, INFO) << "Removing allocator " << allocator; AllocatorBucket::Shard& small_shard = small_allocators_.SelectShard(allocator); @@ -608,9 +603,8 @@ void BasicMemoryQuota::MaybeMoveAllocator(GrpcMemoryAllocatorImpl* allocator, void BasicMemoryQuota::MaybeMoveAllocatorBigToSmall( GrpcMemoryAllocatorImpl* allocator) { - if (GRPC_TRACE_FLAG_ENABLED(resource_quota)) { - LOG(INFO) << "Moving allocator " << allocator << " to small"; - } + GRPC_TRACE_LOG(resource_quota, INFO) + << "Moving allocator " << allocator << " to small"; AllocatorBucket::Shard& old_shard = big_allocators_.SelectShard(allocator); @@ -629,9 +623,8 @@ void BasicMemoryQuota::MaybeMoveAllocatorBigToSmall( void BasicMemoryQuota::MaybeMoveAllocatorSmallToBig( GrpcMemoryAllocatorImpl* allocator) { - if (GRPC_TRACE_FLAG_ENABLED(resource_quota)) { - LOG(INFO) << "Moving allocator " << allocator << " to big"; - } + GRPC_TRACE_LOG(resource_quota, INFO) + << "Moving allocator " << allocator << " to big"; AllocatorBucket::Shard& old_shard = small_allocators_.SelectShard(allocator); @@ -766,10 +759,9 @@ double PressureTracker::AddSampleAndGetControlValue(double sample) { } else { report = controller_.Update(current_estimate - kSetPoint); } - if (GRPC_TRACE_FLAG_ENABLED(resource_quota)) { - LOG(INFO) << "RQ: pressure:" << current_estimate << " report:" << report - << " controller:" << controller_.DebugString(); - } + GRPC_TRACE_LOG(resource_quota, INFO) + << "RQ: pressure:" << current_estimate << " report:" << report + << " controller:" << controller_.DebugString(); report_.store(report, std::memory_order_relaxed); }); return report_.load(std::memory_order_relaxed); diff --git a/src/core/lib/resource_quota/memory_quota.h b/src/core/lib/resource_quota/memory_quota.h index ac06ae9eb8..f1281cc5ba 100644 --- a/src/core/lib/resource_quota/memory_quota.h +++ b/src/core/lib/resource_quota/memory_quota.h @@ -425,10 +425,8 @@ class GrpcMemoryAllocatorImpl final : public EventEngineMemoryAllocatorImpl { void ReturnFree() { size_t ret = free_bytes_.exchange(0, std::memory_order_acq_rel); if (ret == 0) return; - if (GRPC_TRACE_FLAG_ENABLED(resource_quota)) { - LOG(INFO) << "Allocator " << this << " returning " << ret - << " bytes to quota"; - } + GRPC_TRACE_LOG(resource_quota, INFO) + << "Allocator " << this << " returning " << ret << " bytes to quota"; taken_bytes_.fetch_sub(ret, std::memory_order_relaxed); memory_quota_->Return(ret); memory_quota_->MaybeMoveAllocator(this, /*old_free_bytes=*/ret, diff --git a/src/core/lib/resource_quota/thread_quota.cc b/src/core/lib/resource_quota/thread_quota.cc index b2aba40210..73e8b22440 100644 --- a/src/core/lib/resource_quota/thread_quota.cc +++ b/src/core/lib/resource_quota/thread_quota.cc @@ -16,7 +16,6 @@ #include "absl/log/check.h" -#include #include namespace grpc_core { diff --git a/src/core/lib/security/authorization/audit_logging.cc b/src/core/lib/security/authorization/audit_logging.cc index d5b9ae3d14..d5c8f95705 100644 --- a/src/core/lib/security/authorization/audit_logging.cc +++ b/src/core/lib/security/authorization/audit_logging.cc @@ -30,7 +30,6 @@ #include #include -#include #include #include "src/core/lib/gprpp/sync.h" diff --git a/src/core/lib/security/authorization/grpc_authorization_engine.cc b/src/core/lib/security/authorization/grpc_authorization_engine.cc index 62595ee70b..4fed6af4fe 100644 --- a/src/core/lib/security/authorization/grpc_authorization_engine.cc +++ b/src/core/lib/security/authorization/grpc_authorization_engine.cc @@ -20,7 +20,6 @@ #include "absl/log/check.h" -#include #include #include "src/core/lib/security/authorization/audit_logging.h" diff --git a/src/core/lib/security/authorization/grpc_authorization_policy_provider.cc b/src/core/lib/security/authorization/grpc_authorization_policy_provider.cc index cefe2d6db3..4380e09086 100644 --- a/src/core/lib/security/authorization/grpc_authorization_policy_provider.cc +++ b/src/core/lib/security/authorization/grpc_authorization_policy_provider.cc @@ -167,11 +167,10 @@ absl::Status FileWatcherAuthorizationPolicyProvider::ForceUpdate() { if (cb_ != nullptr) { cb_(contents_changed, absl::OkStatus()); } - if (GRPC_TRACE_FLAG_ENABLED(grpc_authz_api)) { - LOG(INFO) << "authorization policy reload status: successfully loaded new " - "policy\n" - << file_contents_; - } + GRPC_TRACE_LOG(grpc_authz_api, INFO) + << "authorization policy reload status: successfully loaded new " + "policy\n" + << file_contents_; return absl::OkStatus(); } 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 938bce2f40..672b02a9d9 100644 --- a/src/core/lib/security/authorization/grpc_server_authz_filter.cc +++ b/src/core/lib/security/authorization/grpc_server_authz_filter.cc @@ -64,23 +64,21 @@ GrpcServerAuthzFilter::Create(const ChannelArgs& args, ChannelFilter::Args) { bool GrpcServerAuthzFilter::IsAuthorized(ClientMetadata& initial_metadata) { EvaluateArgs args(&initial_metadata, &per_channel_evaluate_args_); - if (GRPC_TRACE_FLAG_ENABLED(grpc_authz_api)) { - VLOG(2) << "checking request: url_path=" << args.GetPath() - << ", transport_security_type=" << args.GetTransportSecurityType() - << ", uri_sans=[" << absl::StrJoin(args.GetUriSans(), ",") - << "], dns_sans=[" << absl::StrJoin(args.GetDnsSans(), ",") - << "], subject=" << args.GetSubject(); - } + GRPC_TRACE_VLOG(grpc_authz_api, 2) + << "checking request: url_path=" << args.GetPath() + << ", transport_security_type=" << args.GetTransportSecurityType() + << ", uri_sans=[" << absl::StrJoin(args.GetUriSans(), ",") + << "], dns_sans=[" << absl::StrJoin(args.GetDnsSans(), ",") + << "], subject=" << args.GetSubject(); grpc_authorization_policy_provider::AuthorizationEngines engines = provider_->engines(); if (engines.deny_engine != nullptr) { AuthorizationEngine::Decision decision = engines.deny_engine->Evaluate(args); if (decision.type == AuthorizationEngine::Decision::Type::kDeny) { - if (GRPC_TRACE_FLAG_ENABLED(grpc_authz_api)) { - LOG(INFO) << "chand=" << this << ": request denied by policy " - << decision.matching_policy_name; - } + GRPC_TRACE_LOG(grpc_authz_api, INFO) + << "chand=" << this << ": request denied by policy " + << decision.matching_policy_name; return false; } } @@ -88,17 +86,14 @@ bool GrpcServerAuthzFilter::IsAuthorized(ClientMetadata& initial_metadata) { AuthorizationEngine::Decision decision = engines.allow_engine->Evaluate(args); if (decision.type == AuthorizationEngine::Decision::Type::kAllow) { - if (GRPC_TRACE_FLAG_ENABLED(grpc_authz_api)) { - VLOG(2) << "chand=" << this << ": request allowed by policy " - << decision.matching_policy_name; - } + GRPC_TRACE_VLOG(grpc_authz_api, 2) + << "chand=" << this << ": request allowed by policy " + << decision.matching_policy_name; return true; } } - if (GRPC_TRACE_FLAG_ENABLED(grpc_authz_api)) { - LOG(INFO) << "chand=" << this - << ": request denied, no matching policy found."; - } + GRPC_TRACE_LOG(grpc_authz_api, INFO) + << "chand=" << this << ": request denied, no matching policy found."; return false; } diff --git a/src/core/lib/security/authorization/rbac_translator.cc b/src/core/lib/security/authorization/rbac_translator.cc index 1dbbe8bf16..d427ce8ea0 100644 --- a/src/core/lib/security/authorization/rbac_translator.cc +++ b/src/core/lib/security/authorization/rbac_translator.cc @@ -34,7 +34,6 @@ #include #include -#include #include #include "src/core/lib/matchers/matchers.h" diff --git a/src/core/lib/security/authorization/stdout_logger.cc b/src/core/lib/security/authorization/stdout_logger.cc index 8e2adb6dd1..9314d21a0e 100644 --- a/src/core/lib/security/authorization/stdout_logger.cc +++ b/src/core/lib/security/authorization/stdout_logger.cc @@ -27,7 +27,6 @@ #include #include -#include #include namespace grpc_core { 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 50406fb8a5..864620c9a5 100644 --- a/src/core/lib/security/credentials/alts/check_gcp_environment.cc +++ b/src/core/lib/security/credentials/alts/check_gcp_environment.cc @@ -25,7 +25,6 @@ #include "absl/log/log.h" #include -#include #include const size_t kBiosDataBufferSize = 256; diff --git a/src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc b/src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc index b034ccaac7..85639e5184 100644 --- a/src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc +++ b/src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc @@ -26,7 +26,6 @@ #include #include -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/lib/security/credentials/call_creds_util.cc b/src/core/lib/security/credentials/call_creds_util.cc index c49dd918ab..037d60196c 100644 --- a/src/core/lib/security/credentials/call_creds_util.cc +++ b/src/core/lib/security/credentials/call_creds_util.cc @@ -22,7 +22,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include #include #include diff --git a/src/core/lib/security/credentials/composite/composite_credentials.cc b/src/core/lib/security/credentials/composite/composite_credentials.cc index 016565ceaa..db5d3079cb 100644 --- a/src/core/lib/security/credentials/composite/composite_credentials.cc +++ b/src/core/lib/security/credentials/composite/composite_credentials.cc @@ -26,7 +26,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" -#include #include #include "src/core/lib/debug/trace.h" diff --git a/src/core/lib/security/credentials/composite/composite_credentials.h b/src/core/lib/security/credentials/composite/composite_credentials.h index bcf2915aba..6bd13f0dea 100644 --- a/src/core/lib/security/credentials/composite/composite_credentials.h +++ b/src/core/lib/security/credentials/composite/composite_credentials.h @@ -102,6 +102,8 @@ class grpc_composite_call_credentials : public grpc_call_credentials { grpc_core::RefCountedPtr creds2); ~grpc_composite_call_credentials() override = default; + void Orphaned() override { inner_.clear(); } + grpc_core::ArenaPromise> GetRequestMetadata(grpc_core::ClientMetadataHandle initial_metadata, const GetRequestMetadataArgs* args) override; diff --git a/src/core/lib/security/credentials/credentials.h b/src/core/lib/security/credentials/credentials.h index 24e384e8d7..3066cbfeb3 100644 --- a/src/core/lib/security/credentials/credentials.h +++ b/src/core/lib/security/credentials/credentials.h @@ -32,7 +32,6 @@ #include #include #include -#include #include #include "src/core/lib/channel/channel_args.h" @@ -184,7 +183,7 @@ using CredentialsMetadataArray = std::vector>; // class. Otherwise, compiler will complain about type mismatch due to // -Wmismatched-tags. struct grpc_call_credentials - : public grpc_core::RefCounted { + : public grpc_core::DualRefCounted { public: // TODO(roth): Consider whether security connector actually needs to // be part of this interface. Currently, it is here only for the diff --git a/src/core/lib/security/credentials/external/aws_external_account_credentials.cc b/src/core/lib/security/credentials/external/aws_external_account_credentials.cc index 27d1b88ef1..c2e0686101 100644 --- a/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +++ b/src/core/lib/security/credentials/external/aws_external_account_credentials.cc @@ -34,7 +34,6 @@ #include #include #include -#include #include #include @@ -59,6 +58,13 @@ const char* kAccessKeyIdEnvVar = "AWS_ACCESS_KEY_ID"; const char* kSecretAccessKeyEnvVar = "AWS_SECRET_ACCESS_KEY"; const char* kSessionTokenEnvVar = "AWS_SESSION_TOKEN"; +bool ShouldUseMetadataServer() { + return !((GetEnv(kRegionEnvVar).has_value() || + GetEnv(kDefaultRegionEnvVar).has_value()) && + (GetEnv(kAccessKeyIdEnvVar).has_value() && + GetEnv(kSecretAccessKeyEnvVar).has_value())); +} + std::string UrlEncode(const absl::string_view& s) { const char* hex = "0123456789ABCDEF"; std::string result; @@ -79,281 +85,202 @@ std::string UrlEncode(const absl::string_view& s) { } // namespace -RefCountedPtr -AwsExternalAccountCredentials::Create(Options options, - std::vector scopes, - grpc_error_handle* error) { - auto creds = MakeRefCounted( - std::move(options), std::move(scopes), error); - if (error->ok()) { - return creds; - } else { - return nullptr; - } -} +// +// AwsExternalAccountCredentials::AwsFetchBody +// -AwsExternalAccountCredentials::AwsExternalAccountCredentials( - Options options, std::vector scopes, grpc_error_handle* error) - : ExternalAccountCredentials(options, std::move(scopes)) { - audience_ = options.audience; - auto it = options.credential_source.object().find("environment_id"); - if (it == options.credential_source.object().end()) { - *error = GRPC_ERROR_CREATE("environment_id field not present."); - return; - } - if (it->second.type() != Json::Type::kString) { - *error = GRPC_ERROR_CREATE("environment_id field must be a string."); - return; - } - if (it->second.string() != kExpectedEnvironmentId) { - *error = GRPC_ERROR_CREATE("environment_id does not match."); - return; - } - it = options.credential_source.object().find("region_url"); - if (it == options.credential_source.object().end()) { - *error = GRPC_ERROR_CREATE("region_url field not present."); - return; - } - if (it->second.type() != Json::Type::kString) { - *error = GRPC_ERROR_CREATE("region_url field must be a string."); - return; - } - region_url_ = it->second.string(); - it = options.credential_source.object().find("url"); - if (it != options.credential_source.object().end() && - it->second.type() == Json::Type::kString) { - url_ = it->second.string(); - } - it = - options.credential_source.object().find("regional_cred_verification_url"); - if (it == options.credential_source.object().end()) { - *error = - GRPC_ERROR_CREATE("regional_cred_verification_url field not present."); - return; - } - if (it->second.type() != Json::Type::kString) { - *error = GRPC_ERROR_CREATE( - "regional_cred_verification_url field must be a string."); - return; - } - regional_cred_verification_url_ = it->second.string(); - it = options.credential_source.object().find("imdsv2_session_token_url"); - if (it != options.credential_source.object().end() && - it->second.type() == Json::Type::kString) { - imdsv2_session_token_url_ = it->second.string(); - } +AwsExternalAccountCredentials::AwsFetchBody::AwsFetchBody( + absl::AnyInvocable)> on_done, + AwsExternalAccountCredentials* creds, Timestamp deadline) + : FetchBody(std::move(on_done)), creds_(creds), deadline_(deadline) { + MutexLock lock(&mu_); + // Do a quick async hop here, so that we can invoke the callback at + // any time without deadlocking. + fetch_body_ = MakeOrphanable( + creds->event_engine(), + [self = RefAsSubclass()]( + absl::StatusOr /*result*/) { self->Start(); }, + ""); } -bool AwsExternalAccountCredentials::ShouldUseMetadataServer() { - return !((GetEnv(kRegionEnvVar).has_value() || - GetEnv(kDefaultRegionEnvVar).has_value()) && - (GetEnv(kAccessKeyIdEnvVar).has_value() && - GetEnv(kSecretAccessKeyEnvVar).has_value())); +void AwsExternalAccountCredentials::AwsFetchBody::Shutdown() { + MutexLock lock(&mu_); + fetch_body_.reset(); } -void AwsExternalAccountCredentials::RetrieveSubjectToken( - HTTPRequestContext* ctx, const Options& /*options*/, - std::function cb) { - if (ctx == nullptr) { - FinishRetrieveSubjectToken( - "", - GRPC_ERROR_CREATE( - "Missing HTTPRequestContext to start subject token retrieval.")); - return; - } - ctx_ = ctx; - cb_ = cb; - if (!imdsv2_session_token_url_.empty() && ShouldUseMetadataServer()) { - RetrieveImdsV2SessionToken(); - } else if (signer_ != nullptr) { - BuildSubjectToken(); - } else { - RetrieveRegion(); - } +void AwsExternalAccountCredentials::AwsFetchBody::AsyncFinish( + absl::StatusOr result) { + creds_->event_engine().Run( + [this, self = Ref(), result = std::move(result)]() mutable { + ApplicationCallbackExecCtx application_exec_ctx; + ExecCtx exec_ctx; + Finish(std::move(result)); + self.reset(); + }); } -void AwsExternalAccountCredentials::RetrieveImdsV2SessionToken() { - absl::StatusOr uri = URI::Parse(imdsv2_session_token_url_); - if (!uri.ok()) { - return; +bool AwsExternalAccountCredentials::AwsFetchBody::MaybeFail( + absl::Status status) { + if (!status.ok()) { + AsyncFinish(std::move(status)); + return true; } - grpc_http_header* headers = - static_cast(gpr_malloc(sizeof(grpc_http_header))); - headers[0].key = gpr_strdup("x-aws-ec2-metadata-token-ttl-seconds"); - headers[0].value = gpr_strdup("300"); - grpc_http_request request; - memset(&request, 0, sizeof(grpc_http_request)); - request.hdr_count = 1; - request.hdrs = headers; - grpc_http_response_destroy(&ctx_->response); - ctx_->response = {}; - GRPC_CLOSURE_INIT(&ctx_->closure, OnRetrieveImdsV2SessionToken, this, - nullptr); - RefCountedPtr http_request_creds; - if (uri->scheme() == "http") { - http_request_creds = RefCountedPtr( - grpc_insecure_credentials_create()); - } else { - http_request_creds = CreateHttpRequestSSLCredentials(); + if (fetch_body_ == nullptr) { + AsyncFinish( + absl::CancelledError("external account credentials fetch cancelled")); + return true; } - http_request_ = - HttpRequest::Put(std::move(*uri), nullptr /* channel args */, - ctx_->pollent, &request, ctx_->deadline, &ctx_->closure, - &ctx_->response, std::move(http_request_creds)); - http_request_->Start(); - grpc_http_request_destroy(&request); -} - -void AwsExternalAccountCredentials::OnRetrieveImdsV2SessionToken( - void* arg, grpc_error_handle error) { - AwsExternalAccountCredentials* self = - static_cast(arg); - self->OnRetrieveImdsV2SessionTokenInternal(error); + return false; } -void AwsExternalAccountCredentials::OnRetrieveImdsV2SessionTokenInternal( - grpc_error_handle error) { - if (!error.ok()) { - FinishRetrieveSubjectToken("", error); - return; - } - imdsv2_session_token_ = - std::string(ctx_->response.body, ctx_->response.body_length); - if (signer_ != nullptr) { +void AwsExternalAccountCredentials::AwsFetchBody::Start() { + MutexLock lock(&mu_); + if (MaybeFail(absl::OkStatus())) return; + if (!creds_->imdsv2_session_token_url_.empty() && ShouldUseMetadataServer()) { + RetrieveImdsV2SessionToken(); + } else if (creds_->signer_ != nullptr) { BuildSubjectToken(); } else { RetrieveRegion(); } } -void AwsExternalAccountCredentials::AddMetadataRequestHeaders( - grpc_http_request* request) { - if (!imdsv2_session_token_.empty()) { - CHECK_EQ(request->hdr_count, 0u); - CHECK_EQ(request->hdrs, nullptr); - grpc_http_header* headers = - static_cast(gpr_malloc(sizeof(grpc_http_header))); - headers[0].key = gpr_strdup("x-aws-ec2-metadata-token"); - headers[0].value = gpr_strdup(imdsv2_session_token_.c_str()); - request->hdr_count = 1; - request->hdrs = headers; +void AwsExternalAccountCredentials::AwsFetchBody::RetrieveImdsV2SessionToken() { + absl::StatusOr uri = URI::Parse(creds_->imdsv2_session_token_url_); + if (!uri.ok()) { + AsyncFinish(uri.status()); + return; } + fetch_body_ = MakeOrphanable( + [&](grpc_http_response* response, grpc_closure* on_http_response) { + grpc_http_header* headers = static_cast( + gpr_malloc(sizeof(grpc_http_header))); + headers[0].key = gpr_strdup("x-aws-ec2-metadata-token-ttl-seconds"); + headers[0].value = gpr_strdup("300"); + grpc_http_request request; + memset(&request, 0, sizeof(grpc_http_request)); + request.hdr_count = 1; + request.hdrs = headers; + RefCountedPtr http_request_creds; + if (uri->scheme() == "http") { + http_request_creds = RefCountedPtr( + grpc_insecure_credentials_create()); + } else { + http_request_creds = CreateHttpRequestSSLCredentials(); + } + auto http_request = HttpRequest::Put( + std::move(*uri), /*args=*/nullptr, creds_->pollent(), &request, + deadline_, on_http_response, response, + std::move(http_request_creds)); + http_request->Start(); + grpc_http_request_destroy(&request); + return http_request; + }, + [self = + RefAsSubclass()](absl::StatusOr result) { + MutexLock lock(&self->mu_); + if (self->MaybeFail(result.status())) return; + self->imdsv2_session_token_ = std::move(*result); + if (self->creds_->signer_ != nullptr) { + self->BuildSubjectToken(); + } else { + self->RetrieveRegion(); + } + }); } -void AwsExternalAccountCredentials::RetrieveRegion() { +void AwsExternalAccountCredentials::AwsFetchBody::RetrieveRegion() { auto region_from_env = GetEnv(kRegionEnvVar); if (!region_from_env.has_value()) { region_from_env = GetEnv(kDefaultRegionEnvVar); } if (region_from_env.has_value()) { region_ = std::move(*region_from_env); - if (url_.empty()) { + if (creds_->url_.empty()) { RetrieveSigningKeys(); } else { RetrieveRoleName(); } return; } - absl::StatusOr uri = URI::Parse(region_url_); + absl::StatusOr uri = URI::Parse(creds_->region_url_); if (!uri.ok()) { - FinishRetrieveSubjectToken( - "", GRPC_ERROR_CREATE(absl::StrFormat("Invalid region url. %s", - uri.status().ToString()))); - return; - } - grpc_http_request request; - memset(&request, 0, sizeof(grpc_http_request)); - grpc_http_response_destroy(&ctx_->response); - ctx_->response = {}; - AddMetadataRequestHeaders(&request); - GRPC_CLOSURE_INIT(&ctx_->closure, OnRetrieveRegion, this, nullptr); - RefCountedPtr http_request_creds; - if (uri->scheme() == "http") { - http_request_creds = RefCountedPtr( - grpc_insecure_credentials_create()); - } else { - http_request_creds = CreateHttpRequestSSLCredentials(); - } - http_request_ = - HttpRequest::Get(std::move(*uri), nullptr /* channel args */, - ctx_->pollent, &request, ctx_->deadline, &ctx_->closure, - &ctx_->response, std::move(http_request_creds)); - http_request_->Start(); - grpc_http_request_destroy(&request); -} - -void AwsExternalAccountCredentials::OnRetrieveRegion(void* arg, - grpc_error_handle error) { - AwsExternalAccountCredentials* self = - static_cast(arg); - self->OnRetrieveRegionInternal(error); -} - -void AwsExternalAccountCredentials::OnRetrieveRegionInternal( - grpc_error_handle error) { - if (!error.ok()) { - FinishRetrieveSubjectToken("", error); + AsyncFinish(GRPC_ERROR_CREATE( + absl::StrFormat("Invalid region url. %s", uri.status().ToString()))); return; } - // Remove the last letter of availability zone to get pure region - absl::string_view response_body(ctx_->response.body, - ctx_->response.body_length); - region_ = std::string(response_body.substr(0, response_body.size() - 1)); - if (url_.empty()) { - RetrieveSigningKeys(); - } else { - RetrieveRoleName(); - } + fetch_body_ = MakeOrphanable( + [&](grpc_http_response* response, grpc_closure* on_http_response) { + grpc_http_request request; + memset(&request, 0, sizeof(grpc_http_request)); + AddMetadataRequestHeaders(&request); + RefCountedPtr http_request_creds; + if (uri->scheme() == "http") { + http_request_creds = RefCountedPtr( + grpc_insecure_credentials_create()); + } else { + http_request_creds = CreateHttpRequestSSLCredentials(); + } + auto http_request = HttpRequest::Get( + std::move(*uri), /*args=*/nullptr, creds_->pollent(), &request, + deadline_, on_http_response, response, + std::move(http_request_creds)); + http_request->Start(); + grpc_http_request_destroy(&request); + return http_request; + }, + [self = + RefAsSubclass()](absl::StatusOr result) { + MutexLock lock(&self->mu_); + if (self->MaybeFail(result.status())) return; + // Remove the last letter of availability zone to get pure region + self->region_ = result->substr(0, result->size() - 1); + if (self->creds_->url_.empty()) { + self->RetrieveSigningKeys(); + } else { + self->RetrieveRoleName(); + } + }); } -void AwsExternalAccountCredentials::RetrieveRoleName() { - absl::StatusOr uri = URI::Parse(url_); +void AwsExternalAccountCredentials::AwsFetchBody::RetrieveRoleName() { + absl::StatusOr uri = URI::Parse(creds_->url_); if (!uri.ok()) { - FinishRetrieveSubjectToken( - "", GRPC_ERROR_CREATE( - absl::StrFormat("Invalid url: %s.", uri.status().ToString()))); + AsyncFinish(GRPC_ERROR_CREATE( + absl::StrFormat("Invalid url: %s.", uri.status().ToString()))); return; } - grpc_http_request request; - memset(&request, 0, sizeof(grpc_http_request)); - grpc_http_response_destroy(&ctx_->response); - ctx_->response = {}; - AddMetadataRequestHeaders(&request); - GRPC_CLOSURE_INIT(&ctx_->closure, OnRetrieveRoleName, this, nullptr); - // TODO(ctiller): use the caller's resource quota. - RefCountedPtr http_request_creds; - if (uri->scheme() == "http") { - http_request_creds = RefCountedPtr( - grpc_insecure_credentials_create()); - } else { - http_request_creds = CreateHttpRequestSSLCredentials(); - } - http_request_ = - HttpRequest::Get(std::move(*uri), nullptr /* channel args */, - ctx_->pollent, &request, ctx_->deadline, &ctx_->closure, - &ctx_->response, std::move(http_request_creds)); - http_request_->Start(); - grpc_http_request_destroy(&request); -} - -void AwsExternalAccountCredentials::OnRetrieveRoleName( - void* arg, grpc_error_handle error) { - AwsExternalAccountCredentials* self = - static_cast(arg); - self->OnRetrieveRoleNameInternal(error); + fetch_body_ = MakeOrphanable( + [&](grpc_http_response* response, grpc_closure* on_http_response) { + grpc_http_request request; + memset(&request, 0, sizeof(grpc_http_request)); + AddMetadataRequestHeaders(&request); + // TODO(ctiller): use the caller's resource quota. + RefCountedPtr http_request_creds; + if (uri->scheme() == "http") { + http_request_creds = RefCountedPtr( + grpc_insecure_credentials_create()); + } else { + http_request_creds = CreateHttpRequestSSLCredentials(); + } + auto http_request = HttpRequest::Get( + std::move(*uri), /*args=*/nullptr, creds_->pollent(), &request, + deadline_, on_http_response, response, + std::move(http_request_creds)); + http_request->Start(); + grpc_http_request_destroy(&request); + return http_request; + }, + [self = + RefAsSubclass()](absl::StatusOr result) { + MutexLock lock(&self->mu_); + if (self->MaybeFail(result.status())) return; + self->role_name_ = std::move(*result); + self->RetrieveSigningKeys(); + }); } -void AwsExternalAccountCredentials::OnRetrieveRoleNameInternal( - grpc_error_handle error) { - if (!error.ok()) { - FinishRetrieveSubjectToken("", error); - return; - } - role_name_ = std::string(ctx_->response.body, ctx_->response.body_length); - RetrieveSigningKeys(); -} - -void AwsExternalAccountCredentials::RetrieveSigningKeys() { +void AwsExternalAccountCredentials::AwsFetchBody::RetrieveSigningKeys() { auto access_key_id_from_env = GetEnv(kAccessKeyIdEnvVar); auto secret_access_key_from_env = GetEnv(kSecretAccessKeyEnvVar); auto token_from_env = GetEnv(kSessionTokenEnvVar); @@ -368,122 +295,106 @@ void AwsExternalAccountCredentials::RetrieveSigningKeys() { return; } if (role_name_.empty()) { - FinishRetrieveSubjectToken( - "", + AsyncFinish( GRPC_ERROR_CREATE("Missing role name when retrieving signing keys.")); return; } - std::string url_with_role_name = absl::StrCat(url_, "/", role_name_); + std::string url_with_role_name = absl::StrCat(creds_->url_, "/", role_name_); absl::StatusOr uri = URI::Parse(url_with_role_name); if (!uri.ok()) { - FinishRetrieveSubjectToken( - "", GRPC_ERROR_CREATE(absl::StrFormat("Invalid url with role name: %s.", - uri.status().ToString()))); + AsyncFinish(GRPC_ERROR_CREATE(absl::StrFormat( + "Invalid url with role name: %s.", uri.status().ToString()))); return; } - grpc_http_request request; - memset(&request, 0, sizeof(grpc_http_request)); - grpc_http_response_destroy(&ctx_->response); - ctx_->response = {}; - AddMetadataRequestHeaders(&request); - GRPC_CLOSURE_INIT(&ctx_->closure, OnRetrieveSigningKeys, this, nullptr); - // TODO(ctiller): use the caller's resource quota. - RefCountedPtr http_request_creds; - if (uri->scheme() == "http") { - http_request_creds = RefCountedPtr( - grpc_insecure_credentials_create()); - } else { - http_request_creds = CreateHttpRequestSSLCredentials(); - } - http_request_ = - HttpRequest::Get(std::move(*uri), nullptr /* channel args */, - ctx_->pollent, &request, ctx_->deadline, &ctx_->closure, - &ctx_->response, std::move(http_request_creds)); - http_request_->Start(); - grpc_http_request_destroy(&request); -} - -void AwsExternalAccountCredentials::OnRetrieveSigningKeys( - void* arg, grpc_error_handle error) { - AwsExternalAccountCredentials* self = - static_cast(arg); - self->OnRetrieveSigningKeysInternal(error); + fetch_body_ = MakeOrphanable( + [&](grpc_http_response* response, grpc_closure* on_http_response) { + grpc_http_request request; + memset(&request, 0, sizeof(grpc_http_request)); + AddMetadataRequestHeaders(&request); + // TODO(ctiller): use the caller's resource quota. + RefCountedPtr http_request_creds; + if (uri->scheme() == "http") { + http_request_creds = RefCountedPtr( + grpc_insecure_credentials_create()); + } else { + http_request_creds = CreateHttpRequestSSLCredentials(); + } + auto http_request = HttpRequest::Get( + std::move(*uri), /*args=*/nullptr, creds_->pollent(), &request, + deadline_, on_http_response, response, + std::move(http_request_creds)); + http_request->Start(); + grpc_http_request_destroy(&request); + return http_request; + }, + [self = + RefAsSubclass()](absl::StatusOr result) { + MutexLock lock(&self->mu_); + if (self->MaybeFail(result.status())) return; + self->OnRetrieveSigningKeys(std::move(*result)); + }); } -void AwsExternalAccountCredentials::OnRetrieveSigningKeysInternal( - grpc_error_handle error) { - if (!error.ok()) { - FinishRetrieveSubjectToken("", error); - return; - } - absl::string_view response_body(ctx_->response.body, - ctx_->response.body_length); - auto json = JsonParse(response_body); +void AwsExternalAccountCredentials::AwsFetchBody::OnRetrieveSigningKeys( + std::string result) { + auto json = JsonParse(result); if (!json.ok()) { - FinishRetrieveSubjectToken( - "", GRPC_ERROR_CREATE( - absl::StrCat("Invalid retrieve signing keys response: ", - json.status().ToString()))); + AsyncFinish(GRPC_ERROR_CREATE(absl::StrCat( + "Invalid retrieve signing keys response: ", json.status().ToString()))); return; } if (json->type() != Json::Type::kObject) { - FinishRetrieveSubjectToken( - "", GRPC_ERROR_CREATE("Invalid retrieve signing keys response: " - "JSON type is not object")); + AsyncFinish( + GRPC_ERROR_CREATE("Invalid retrieve signing keys response: " + "JSON type is not object")); return; } auto it = json->object().find("AccessKeyId"); if (it != json->object().end() && it->second.type() == Json::Type::kString) { access_key_id_ = it->second.string(); } else { - FinishRetrieveSubjectToken( - "", GRPC_ERROR_CREATE(absl::StrFormat( - "Missing or invalid AccessKeyId in %s.", response_body))); + AsyncFinish(GRPC_ERROR_CREATE( + absl::StrFormat("Missing or invalid AccessKeyId in %s.", result))); return; } it = json->object().find("SecretAccessKey"); if (it != json->object().end() && it->second.type() == Json::Type::kString) { secret_access_key_ = it->second.string(); } else { - FinishRetrieveSubjectToken( - "", GRPC_ERROR_CREATE(absl::StrFormat( - "Missing or invalid SecretAccessKey in %s.", response_body))); + AsyncFinish(GRPC_ERROR_CREATE( + absl::StrFormat("Missing or invalid SecretAccessKey in %s.", result))); return; } it = json->object().find("Token"); if (it != json->object().end() && it->second.type() == Json::Type::kString) { token_ = it->second.string(); } else { - FinishRetrieveSubjectToken( - "", GRPC_ERROR_CREATE(absl::StrFormat("Missing or invalid Token in %s.", - response_body))); + AsyncFinish(GRPC_ERROR_CREATE( + absl::StrFormat("Missing or invalid Token in %s.", result))); return; } BuildSubjectToken(); } -void AwsExternalAccountCredentials::BuildSubjectToken() { +void AwsExternalAccountCredentials::AwsFetchBody::BuildSubjectToken() { grpc_error_handle error; - if (signer_ == nullptr) { - cred_verification_url_ = absl::StrReplaceAll( - regional_cred_verification_url_, {{"{region}", region_}}); - signer_ = std::make_unique( + if (creds_->signer_ == nullptr) { + creds_->cred_verification_url_ = absl::StrReplaceAll( + creds_->regional_cred_verification_url_, {{"{region}", region_}}); + creds_->signer_ = std::make_unique( access_key_id_, secret_access_key_, token_, "POST", - cred_verification_url_, region_, "", + creds_->cred_verification_url_, region_, "", std::map(), &error); if (!error.ok()) { - FinishRetrieveSubjectToken( - "", GRPC_ERROR_CREATE_REFERENCING( - "Creating aws request signer failed.", &error, 1)); + AsyncFinish(GRPC_ERROR_CREATE_REFERENCING( + "Creating aws request signer failed.", &error, 1)); return; } } - auto signed_headers = signer_->GetSignedRequestHeaders(); + auto signed_headers = creds_->signer_->GetSignedRequestHeaders(); if (!error.ok()) { - FinishRetrieveSubjectToken( - "", GRPC_ERROR_CREATE_REFERENCING("Invalid getting signed request" - "headers.", - &error, 1)); + AsyncFinish(GRPC_ERROR_CREATE_REFERENCING( + "Invalid getting signed request headers.", &error, 1)); return; } // Construct subject token @@ -502,30 +413,117 @@ void AwsExternalAccountCredentials::BuildSubjectToken() { {"value", Json::FromString(signed_headers["x-amz-security-token"])}})); headers.push_back(Json::FromObject( {{"key", Json::FromString("x-goog-cloud-target-resource")}, - {"value", Json::FromString(audience_)}})); - Json subject_token_json = - Json::FromObject({{"url", Json::FromString(cred_verification_url_)}, - {"method", Json::FromString("POST")}, - {"headers", Json::FromArray(headers)}}); + {"value", Json::FromString(creds_->audience_)}})); + Json subject_token_json = Json::FromObject( + {{"url", Json::FromString(creds_->cred_verification_url_)}, + {"method", Json::FromString("POST")}, + {"headers", Json::FromArray(headers)}}); std::string subject_token = UrlEncode(JsonDump(subject_token_json)); - FinishRetrieveSubjectToken(subject_token, absl::OkStatus()); + AsyncFinish(std::move(subject_token)); } -void AwsExternalAccountCredentials::FinishRetrieveSubjectToken( - std::string subject_token, grpc_error_handle error) { - // Reset context - ctx_ = nullptr; - // Move object state into local variables. - auto cb = cb_; - cb_ = nullptr; - // Invoke the callback. - if (!error.ok()) { - cb("", error); - } else { - cb(subject_token, absl::OkStatus()); +void AwsExternalAccountCredentials::AwsFetchBody::AddMetadataRequestHeaders( + grpc_http_request* request) { + if (!imdsv2_session_token_.empty()) { + CHECK_EQ(request->hdr_count, 0u); + CHECK_EQ(request->hdrs, nullptr); + grpc_http_header* headers = + static_cast(gpr_malloc(sizeof(grpc_http_header))); + headers[0].key = gpr_strdup("x-aws-ec2-metadata-token"); + headers[0].value = gpr_strdup(imdsv2_session_token_.c_str()); + request->hdr_count = 1; + request->hdrs = headers; } } +// +// AwsExternalAccountCredentials +// + +absl::StatusOr> +AwsExternalAccountCredentials::Create( + Options options, std::vector scopes, + std::shared_ptr + event_engine) { + grpc_error_handle error; + auto creds = MakeRefCounted( + std::move(options), std::move(scopes), std::move(event_engine), &error); + if (!error.ok()) return error; + return creds; +} + +AwsExternalAccountCredentials::AwsExternalAccountCredentials( + Options options, std::vector scopes, + std::shared_ptr event_engine, + grpc_error_handle* error) + : ExternalAccountCredentials(options, std::move(scopes), + std::move(event_engine)) { + audience_ = options.audience; + auto it = options.credential_source.object().find("environment_id"); + if (it == options.credential_source.object().end()) { + *error = GRPC_ERROR_CREATE("environment_id field not present."); + return; + } + if (it->second.type() != Json::Type::kString) { + *error = GRPC_ERROR_CREATE("environment_id field must be a string."); + return; + } + if (it->second.string() != kExpectedEnvironmentId) { + *error = GRPC_ERROR_CREATE("environment_id does not match."); + return; + } + it = options.credential_source.object().find("region_url"); + if (it == options.credential_source.object().end()) { + *error = GRPC_ERROR_CREATE("region_url field not present."); + return; + } + if (it->second.type() != Json::Type::kString) { + *error = GRPC_ERROR_CREATE("region_url field must be a string."); + return; + } + region_url_ = it->second.string(); + it = options.credential_source.object().find("url"); + if (it != options.credential_source.object().end() && + it->second.type() == Json::Type::kString) { + url_ = it->second.string(); + } + it = + options.credential_source.object().find("regional_cred_verification_url"); + if (it == options.credential_source.object().end()) { + *error = + GRPC_ERROR_CREATE("regional_cred_verification_url field not present."); + return; + } + if (it->second.type() != Json::Type::kString) { + *error = GRPC_ERROR_CREATE( + "regional_cred_verification_url field must be a string."); + return; + } + regional_cred_verification_url_ = it->second.string(); + it = options.credential_source.object().find("imdsv2_session_token_url"); + if (it != options.credential_source.object().end() && + it->second.type() == Json::Type::kString) { + imdsv2_session_token_url_ = it->second.string(); + } +} + +std::string AwsExternalAccountCredentials::debug_string() { + return absl::StrCat("AwsExternalAccountCredentials{Audience:", audience(), + ")"); +} + +UniqueTypeName AwsExternalAccountCredentials::type() const { + static UniqueTypeName::Factory kFactory("AwsExternalAccountCredentials"); + return kFactory.Create(); +} + +OrphanablePtr +AwsExternalAccountCredentials::RetrieveSubjectToken( + Timestamp deadline, + absl::AnyInvocable)> on_done) { + return MakeOrphanable(std::move(on_done), this, deadline); +} + absl::string_view AwsExternalAccountCredentials::CredentialSourceType() { return "aws"; } diff --git a/src/core/lib/security/credentials/external/aws_external_account_credentials.h b/src/core/lib/security/credentials/external/aws_external_account_credentials.h index c7dc1f166c..588001e480 100644 --- a/src/core/lib/security/credentials/external/aws_external_account_credentials.h +++ b/src/core/lib/security/credentials/external/aws_external_account_credentials.h @@ -38,46 +38,67 @@ namespace grpc_core { class AwsExternalAccountCredentials final : public ExternalAccountCredentials { public: - static RefCountedPtr Create( + static absl::StatusOr> Create( Options options, std::vector scopes, - grpc_error_handle* error); - - AwsExternalAccountCredentials(Options options, - std::vector scopes, - grpc_error_handle* error); - - private: - bool ShouldUseMetadataServer(); - void RetrieveSubjectToken( - HTTPRequestContext* ctx, const Options& options, - std::function cb) override; - - void RetrieveRegion(); - static void OnRetrieveRegion(void* arg, grpc_error_handle error); - void OnRetrieveRegionInternal(grpc_error_handle error); - - void RetrieveImdsV2SessionToken(); - static void OnRetrieveImdsV2SessionToken(void* arg, grpc_error_handle error); - void OnRetrieveImdsV2SessionTokenInternal(grpc_error_handle error); + std::shared_ptr + event_engine = nullptr); - void RetrieveRoleName(); - static void OnRetrieveRoleName(void* arg, grpc_error_handle error); - void OnRetrieveRoleNameInternal(grpc_error_handle error); + AwsExternalAccountCredentials( + Options options, std::vector scopes, + std::shared_ptr + event_engine, + grpc_error_handle* error); - void RetrieveSigningKeys(); - static void OnRetrieveSigningKeys(void* arg, grpc_error_handle error); - void OnRetrieveSigningKeysInternal(grpc_error_handle error); + std::string debug_string() override; - void BuildSubjectToken(); - void FinishRetrieveSubjectToken(std::string subject_token, - grpc_error_handle error); + UniqueTypeName type() const override; - void AddMetadataRequestHeaders(grpc_http_request* request); + private: + // A FetchBody impl that itself performs a sequence of FetchBody operations. + class AwsFetchBody : public FetchBody { + public: + AwsFetchBody(absl::AnyInvocable)> on_done, + AwsExternalAccountCredentials* creds, Timestamp deadline); + + private: + void Shutdown() override; + + void AsyncFinish(absl::StatusOr result); + bool MaybeFail(absl::Status status) ABSL_EXCLUSIVE_LOCKS_REQUIRED(&mu_); + + void Start(); + void RetrieveImdsV2SessionToken() ABSL_EXCLUSIVE_LOCKS_REQUIRED(&mu_); + void RetrieveRegion() ABSL_EXCLUSIVE_LOCKS_REQUIRED(&mu_); + void RetrieveRoleName() ABSL_EXCLUSIVE_LOCKS_REQUIRED(&mu_); + void RetrieveSigningKeys() ABSL_EXCLUSIVE_LOCKS_REQUIRED(&mu_); + void OnRetrieveSigningKeys(std::string result) + ABSL_EXCLUSIVE_LOCKS_REQUIRED(&mu_); + void BuildSubjectToken() ABSL_EXCLUSIVE_LOCKS_REQUIRED(&mu_); + + void AddMetadataRequestHeaders(grpc_http_request* request); + + AwsExternalAccountCredentials* creds_; + Timestamp deadline_; + + Mutex mu_; + OrphanablePtr fetch_body_ ABSL_GUARDED_BY(&mu_); + + // Information required by request signer + std::string region_; + std::string role_name_; + std::string access_key_id_; + std::string secret_access_key_; + std::string token_; + std::string imdsv2_session_token_; + }; + + OrphanablePtr RetrieveSubjectToken( + Timestamp deadline, + absl::AnyInvocable)> on_done) override; absl::string_view CredentialSourceType() override; std::string audience_; - OrphanablePtr http_request_; // Fields of credential source std::string region_url_; @@ -85,19 +106,9 @@ class AwsExternalAccountCredentials final : public ExternalAccountCredentials { std::string regional_cred_verification_url_; std::string imdsv2_session_token_url_; - // Information required by request signer - std::string region_; - std::string role_name_; - std::string access_key_id_; - std::string secret_access_key_; - std::string token_; - std::string imdsv2_session_token_; - + // These fields are set on the first fetch attempt and cached after that. std::unique_ptr signer_; std::string cred_verification_url_; - - HTTPRequestContext* ctx_ = nullptr; - std::function cb_ = nullptr; }; } // namespace grpc_core diff --git a/src/core/lib/security/credentials/external/external_account_credentials.cc b/src/core/lib/security/credentials/external/external_account_credentials.cc index 7455230613..c83351e67e 100644 --- a/src/core/lib/security/credentials/external/external_account_credentials.cc +++ b/src/core/lib/security/credentials/external/external_account_credentials.cc @@ -69,9 +69,94 @@ namespace grpc_core { +// +// ExternalAccountCredentials::NoOpFetchBody +// + +ExternalAccountCredentials::NoOpFetchBody::NoOpFetchBody( + grpc_event_engine::experimental::EventEngine& event_engine, + absl::AnyInvocable)> on_done, + absl::StatusOr result) + : FetchBody(std::move(on_done)) { + event_engine.Run([self = RefAsSubclass(), + result = std::move(result)]() mutable { + ApplicationCallbackExecCtx application_exec_ctx; + ExecCtx exec_ctx; + self->Finish(std::move(result)); + }); +} + +// +// ExternalAccountCredentials::HttpFetchBody +// + +ExternalAccountCredentials::HttpFetchBody::HttpFetchBody( + absl::FunctionRef(grpc_http_response*, + grpc_closure*)> + start_http_request, + absl::AnyInvocable)> on_done) + : FetchBody(std::move(on_done)) { + GRPC_CLOSURE_INIT(&on_http_response_, OnHttpResponse, this, nullptr); + Ref().release(); // Ref held by HTTP request callback. + http_request_ = start_http_request(&response_, &on_http_response_); +} + +void ExternalAccountCredentials::HttpFetchBody::OnHttpResponse( + void* arg, grpc_error_handle error) { + RefCountedPtr self(static_cast(arg)); + if (!error.ok()) { + self->Finish(std::move(error)); + return; + } + absl::string_view response_body(self->response_.body, + self->response_.body_length); + if (self->response_.status != 200) { + self->Finish(absl::UnavailableError( + absl::StrCat("Call to HTTP server ended with status ", + self->response_.status, " [", response_body, "]"))); + return; + } + self->Finish(std::string(response_body)); +} + +// +// ExternalAccountCredentials::ExternalFetchRequest +// + +// The token fetching flow: +// 1. Retrieve subject token - Subclass's RetrieveSubjectToken() gets called +// and the subject token is received in ExchangeToken(). +// 2. Exchange token - ExchangeToken() gets called with the +// subject token from #1. +// 3. (Optional) Impersonate service account - ImpersonateServiceAccount() gets +// called with the access token of the response from #2. Get an impersonated +// access token in OnImpersonateServiceAccountInternal(). +// 4. Finish token fetch - Return back the response that contains an access +// token in FinishTokenFetch(). +ExternalAccountCredentials::ExternalFetchRequest::ExternalFetchRequest( + ExternalAccountCredentials* creds, Timestamp deadline, + absl::AnyInvocable< + void(absl::StatusOr>)> + on_done) + : creds_(creds), deadline_(deadline), on_done_(std::move(on_done)) { + fetch_body_ = creds_->RetrieveSubjectToken( + deadline, [self = RefAsSubclass()]( + absl::StatusOr result) { + self->ExchangeToken(std::move(result)); + }); +} + +void ExternalAccountCredentials::ExternalFetchRequest::Orphan() { + { + MutexLock lock(&mu_); + fetch_body_.reset(); + } + Unref(); +} + namespace { -std::string UrlEncode(const absl::string_view& s) { +std::string UrlEncode(const absl::string_view s) { const char* hex = "0123456789ABCDEF"; std::string result; result.reserve(s.length()); @@ -89,6 +174,270 @@ std::string UrlEncode(const absl::string_view& s) { return result; } +} // namespace + +void ExternalAccountCredentials::ExternalFetchRequest::ExchangeToken( + absl::StatusOr subject_token) { + MutexLock lock(&mu_); + if (MaybeFailLocked(subject_token.status())) return; + // Parse URI. + absl::StatusOr uri = URI::Parse(options().token_url); + if (!uri.ok()) { + return FinishTokenFetch(GRPC_ERROR_CREATE( + absl::StrFormat("Invalid token url: %s. Error: %s", options().token_url, + uri.status().ToString()))); + } + // Start HTTP request. + fetch_body_ = MakeOrphanable( + [&](grpc_http_response* response, grpc_closure* on_http_response) { + grpc_http_request request; + memset(&request, 0, sizeof(grpc_http_request)); + const bool add_authorization_header = + !options().client_id.empty() && !options().client_secret.empty(); + request.hdr_count = add_authorization_header ? 3 : 2; + auto* headers = static_cast( + gpr_malloc(sizeof(grpc_http_header) * request.hdr_count)); + headers[0].key = gpr_strdup("Content-Type"); + headers[0].value = gpr_strdup("application/x-www-form-urlencoded"); + headers[1].key = gpr_strdup("x-goog-api-client"); + headers[1].value = gpr_strdup(creds_->MetricsHeaderValue().c_str()); + if (add_authorization_header) { + std::string raw_cred = absl::StrFormat("%s:%s", options().client_id, + options().client_secret); + std::string str = + absl::StrFormat("Basic %s", absl::Base64Escape(raw_cred)); + headers[2].key = gpr_strdup("Authorization"); + headers[2].value = gpr_strdup(str.c_str()); + } + request.hdrs = headers; + std::vector body_parts; + body_parts.push_back(absl::StrFormat( + "audience=%s", UrlEncode(options().audience).c_str())); + body_parts.push_back(absl::StrFormat( + "grant_type=%s", + UrlEncode(EXTERNAL_ACCOUNT_CREDENTIALS_GRANT_TYPE).c_str())); + body_parts.push_back(absl::StrFormat( + "requested_token_type=%s", + UrlEncode(EXTERNAL_ACCOUNT_CREDENTIALS_REQUESTED_TOKEN_TYPE) + .c_str())); + body_parts.push_back( + absl::StrFormat("subject_token_type=%s", + UrlEncode(options().subject_token_type).c_str())); + body_parts.push_back(absl::StrFormat( + "subject_token=%s", UrlEncode(*subject_token).c_str())); + std::string scope = GOOGLE_CLOUD_PLATFORM_DEFAULT_SCOPE; + if (options().service_account_impersonation_url.empty()) { + scope = absl::StrJoin(creds_->scopes_, " "); + } + body_parts.push_back( + absl::StrFormat("scope=%s", UrlEncode(scope).c_str())); + Json::Object addtional_options_json_object; + if (options().client_id.empty() && options().client_secret.empty()) { + addtional_options_json_object["userProject"] = + Json::FromString(options().workforce_pool_user_project); + } + Json addtional_options_json = + Json::FromObject(std::move(addtional_options_json_object)); + body_parts.push_back(absl::StrFormat( + "options=%s", UrlEncode(JsonDump(addtional_options_json)).c_str())); + std::string body = absl::StrJoin(body_parts, "&"); + request.body = const_cast(body.c_str()); + request.body_length = body.size(); + RefCountedPtr http_request_creds; + if (uri->scheme() == "http") { + http_request_creds = RefCountedPtr( + grpc_insecure_credentials_create()); + } else { + http_request_creds = CreateHttpRequestSSLCredentials(); + } + auto http_request = HttpRequest::Post( + std::move(*uri), /*args=*/nullptr, pollent(), &request, deadline(), + on_http_response, response, std::move(http_request_creds)); + http_request->Start(); + request.body = nullptr; + grpc_http_request_destroy(&request); + return http_request; + }, + [self = RefAsSubclass()]( + absl::StatusOr result) { + self->MaybeImpersonateServiceAccount(std::move(result)); + }); +} + +void ExternalAccountCredentials::ExternalFetchRequest:: + MaybeImpersonateServiceAccount(absl::StatusOr response_body) { + MutexLock lock(&mu_); + if (MaybeFailLocked(response_body.status())) return; + // If not doing impersonation, response_body contains oauth token. + if (options().service_account_impersonation_url.empty()) { + return FinishTokenFetch(std::move(response_body)); + } + // Do impersonation. + auto json = JsonParse(*response_body); + if (!json.ok()) { + FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrCat( + "Invalid token exchange response: ", json.status().ToString()))); + return; + } + if (json->type() != Json::Type::kObject) { + FinishTokenFetch(GRPC_ERROR_CREATE( + "Invalid token exchange response: JSON type is not object")); + return; + } + auto it = json->object().find("access_token"); + if (it == json->object().end() || it->second.type() != Json::Type::kString) { + FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat( + "Missing or invalid access_token in %s.", *response_body))); + return; + } + absl::string_view access_token = it->second.string(); + absl::StatusOr uri = + URI::Parse(options().service_account_impersonation_url); + if (!uri.ok()) { + FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat( + "Invalid service account impersonation url: %s. Error: %s", + options().service_account_impersonation_url, uri.status().ToString()))); + return; + } + // Start HTTP request. + fetch_body_ = MakeOrphanable( + [&](grpc_http_response* response, grpc_closure* on_http_response) { + grpc_http_request request; + memset(&request, 0, sizeof(grpc_http_request)); + request.hdr_count = 2; + grpc_http_header* headers = static_cast( + gpr_malloc(sizeof(grpc_http_header) * request.hdr_count)); + headers[0].key = gpr_strdup("Content-Type"); + headers[0].value = gpr_strdup("application/x-www-form-urlencoded"); + std::string str = absl::StrFormat("Bearer %s", access_token); + headers[1].key = gpr_strdup("Authorization"); + headers[1].value = gpr_strdup(str.c_str()); + request.hdrs = headers; + std::vector body_members; + std::string scope = absl::StrJoin(creds_->scopes_, " "); + body_members.push_back( + absl::StrFormat("scope=%s", UrlEncode(scope).c_str())); + body_members.push_back(absl::StrFormat( + "lifetime=%ds", + options().service_account_impersonation.token_lifetime_seconds)); + std::string body = absl::StrJoin(body_members, "&"); + request.body = const_cast(body.c_str()); + request.body_length = body.size(); + // TODO(ctiller): Use the callers resource quota. + RefCountedPtr http_request_creds; + if (uri->scheme() == "http") { + http_request_creds = RefCountedPtr( + grpc_insecure_credentials_create()); + } else { + http_request_creds = CreateHttpRequestSSLCredentials(); + } + auto http_request = HttpRequest::Post( + std::move(*uri), nullptr, pollent(), &request, deadline(), + on_http_response, response, std::move(http_request_creds)); + http_request->Start(); + request.body = nullptr; + grpc_http_request_destroy(&request); + return http_request; + }, + [self = RefAsSubclass()]( + absl::StatusOr result) { + self->OnImpersonateServiceAccount(std::move(result)); + }); +} + +void ExternalAccountCredentials::ExternalFetchRequest:: + OnImpersonateServiceAccount(absl::StatusOr response_body) { + MutexLock lock(&mu_); + if (MaybeFailLocked(response_body.status())) return; + auto json = JsonParse(*response_body); + if (!json.ok()) { + FinishTokenFetch(GRPC_ERROR_CREATE( + absl::StrCat("Invalid service account impersonation response: ", + json.status().ToString()))); + return; + } + if (json->type() != Json::Type::kObject) { + FinishTokenFetch( + GRPC_ERROR_CREATE("Invalid service account impersonation response: " + "JSON type is not object")); + return; + } + auto it = json->object().find("accessToken"); + if (it == json->object().end() || it->second.type() != Json::Type::kString) { + FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat( + "Missing or invalid accessToken in %s.", *response_body))); + return; + } + absl::string_view access_token = it->second.string(); + it = json->object().find("expireTime"); + if (it == json->object().end() || it->second.type() != Json::Type::kString) { + FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat( + "Missing or invalid expireTime in %s.", *response_body))); + return; + } + absl::string_view expire_time = it->second.string(); + absl::Time t; + if (!absl::ParseTime(absl::RFC3339_full, expire_time, &t, nullptr)) { + FinishTokenFetch(GRPC_ERROR_CREATE( + "Invalid expire time of service account impersonation response.")); + return; + } + int64_t expire_in = (t - absl::Now()) / absl::Seconds(1); + std::string body = absl::StrFormat( + "{\"access_token\":\"%s\",\"expires_in\":%d,\"token_type\":\"Bearer\"}", + access_token, expire_in); + FinishTokenFetch(std::move(body)); +} + +void ExternalAccountCredentials::ExternalFetchRequest::FinishTokenFetch( + absl::StatusOr response_body) { + absl::StatusOr> result; + if (!response_body.ok()) { + LOG(ERROR) << "Fetch external account credentials access token: " + << response_body.status(); + result = absl::Status(response_body.status().code(), + absl::StrCat("error fetching oauth2 token: ", + response_body.status().message())); + } else { + absl::optional token_value; + Duration token_lifetime; + if (grpc_oauth2_token_fetcher_credentials_parse_server_response_body( + *response_body, &token_value, &token_lifetime) != + GRPC_CREDENTIALS_OK) { + result = GRPC_ERROR_CREATE("Could not parse oauth token"); + } else { + result = MakeRefCounted(std::move(*token_value), + Timestamp::Now() + token_lifetime); + } + } + creds_->event_engine().Run([on_done = std::exchange(on_done_, nullptr), + result = std::move(result)]() mutable { + ApplicationCallbackExecCtx application_exec_ctx; + ExecCtx exec_ctx; + std::exchange(on_done, nullptr)(std::move(result)); + }); +} + +bool ExternalAccountCredentials::ExternalFetchRequest::MaybeFailLocked( + absl::Status status) { + if (!status.ok()) { + FinishTokenFetch(std::move(status)); + return true; + } + if (fetch_body_ == nullptr) { // Will be set by Orphan() on cancellation. + FinishTokenFetch( + absl::CancelledError("external account credentials fetch cancelled")); + return true; + } + return false; +} + +// +// ExternalAccountCredentials +// + +namespace { + // Expression to match: // //iam.googleapis.com/locations/[^/]+/workforcePools/[^/]+/providers/.+ bool MatchWorkforcePoolAudience(absl::string_view audience) { @@ -108,49 +457,41 @@ bool MatchWorkforcePoolAudience(absl::string_view audience) { } // namespace -RefCountedPtr ExternalAccountCredentials::Create( +absl::StatusOr> +ExternalAccountCredentials::Create( const Json& json, std::vector scopes, - grpc_error_handle* error) { - CHECK(error->ok()); + std::shared_ptr + event_engine) { Options options; options.type = GRPC_AUTH_JSON_TYPE_INVALID; if (json.type() != Json::Type::kObject) { - *error = - GRPC_ERROR_CREATE("Invalid json to construct credentials options."); - return nullptr; + return GRPC_ERROR_CREATE("Invalid json to construct credentials options."); } auto it = json.object().find("type"); if (it == json.object().end()) { - *error = GRPC_ERROR_CREATE("type field not present."); - return nullptr; + return GRPC_ERROR_CREATE("type field not present."); } if (it->second.type() != Json::Type::kString) { - *error = GRPC_ERROR_CREATE("type field must be a string."); - return nullptr; + return GRPC_ERROR_CREATE("type field must be a string."); } if (it->second.string() != GRPC_AUTH_JSON_TYPE_EXTERNAL_ACCOUNT) { - *error = GRPC_ERROR_CREATE("Invalid credentials json type."); - return nullptr; + return GRPC_ERROR_CREATE("Invalid credentials json type."); } options.type = GRPC_AUTH_JSON_TYPE_EXTERNAL_ACCOUNT; it = json.object().find("audience"); if (it == json.object().end()) { - *error = GRPC_ERROR_CREATE("audience field not present."); - return nullptr; + return GRPC_ERROR_CREATE("audience field not present."); } if (it->second.type() != Json::Type::kString) { - *error = GRPC_ERROR_CREATE("audience field must be a string."); - return nullptr; + return GRPC_ERROR_CREATE("audience field must be a string."); } options.audience = it->second.string(); it = json.object().find("subject_token_type"); if (it == json.object().end()) { - *error = GRPC_ERROR_CREATE("subject_token_type field not present."); - return nullptr; + return GRPC_ERROR_CREATE("subject_token_type field not present."); } if (it->second.type() != Json::Type::kString) { - *error = GRPC_ERROR_CREATE("subject_token_type field must be a string."); - return nullptr; + return GRPC_ERROR_CREATE("subject_token_type field must be a string."); } options.subject_token_type = it->second.string(); it = json.object().find("service_account_impersonation_url"); @@ -159,12 +500,10 @@ RefCountedPtr ExternalAccountCredentials::Create( } it = json.object().find("token_url"); if (it == json.object().end()) { - *error = GRPC_ERROR_CREATE("token_url field not present."); - return nullptr; + return GRPC_ERROR_CREATE("token_url field not present."); } if (it->second.type() != Json::Type::kString) { - *error = GRPC_ERROR_CREATE("token_url field must be a string."); - return nullptr; + return GRPC_ERROR_CREATE("token_url field must be a string."); } options.token_url = it->second.string(); it = json.object().find("token_info_url"); @@ -173,8 +512,7 @@ RefCountedPtr ExternalAccountCredentials::Create( } it = json.object().find("credential_source"); if (it == json.object().end()) { - *error = GRPC_ERROR_CREATE("credential_source field not present."); - return nullptr; + return GRPC_ERROR_CREATE("credential_source field not present."); } options.credential_source = it->second; it = json.object().find("quota_project_id"); @@ -194,10 +532,9 @@ RefCountedPtr ExternalAccountCredentials::Create( if (MatchWorkforcePoolAudience(options.audience)) { options.workforce_pool_user_project = it->second.string(); } else { - *error = GRPC_ERROR_CREATE( + return GRPC_ERROR_CREATE( "workforce_pool_user_project should not be set for non-workforce " "pool credentials"); - return nullptr; } } it = json.object().find("service_account_impersonation"); @@ -211,53 +548,50 @@ RefCountedPtr ExternalAccountCredentials::Create( if (!absl::SimpleAtoi( service_acc_imp_obj_it->second.string(), &options.service_account_impersonation.token_lifetime_seconds)) { - *error = GRPC_ERROR_CREATE("token_lifetime_seconds must be a number"); - return nullptr; + return GRPC_ERROR_CREATE("token_lifetime_seconds must be a number"); } if (options.service_account_impersonation.token_lifetime_seconds > IMPERSONATED_CRED_MAX_LIFETIME_IN_SECONDS) { - *error = GRPC_ERROR_CREATE( + return GRPC_ERROR_CREATE( absl::StrFormat("token_lifetime_seconds must be less than %ds", IMPERSONATED_CRED_MAX_LIFETIME_IN_SECONDS)); - return nullptr; } if (options.service_account_impersonation.token_lifetime_seconds < IMPERSONATED_CRED_MIN_LIFETIME_IN_SECONDS) { - *error = GRPC_ERROR_CREATE( + return GRPC_ERROR_CREATE( absl::StrFormat("token_lifetime_seconds must be more than %ds", IMPERSONATED_CRED_MIN_LIFETIME_IN_SECONDS)); - return nullptr; } } } RefCountedPtr creds; + grpc_error_handle error; if (options.credential_source.object().find("environment_id") != options.credential_source.object().end()) { creds = MakeRefCounted( - std::move(options), std::move(scopes), error); + std::move(options), std::move(scopes), std::move(event_engine), &error); } else if (options.credential_source.object().find("file") != options.credential_source.object().end()) { creds = MakeRefCounted( - std::move(options), std::move(scopes), error); + std::move(options), std::move(scopes), std::move(event_engine), &error); } else if (options.credential_source.object().find("url") != options.credential_source.object().end()) { creds = MakeRefCounted( - std::move(options), std::move(scopes), error); + std::move(options), std::move(scopes), std::move(event_engine), &error); } else { - *error = GRPC_ERROR_CREATE( + return GRPC_ERROR_CREATE( "Invalid options credential source to create " "ExternalAccountCredentials."); } - if (error->ok()) { - return creds; - } else { - return nullptr; - } + if (!error.ok()) return error; + return creds; } ExternalAccountCredentials::ExternalAccountCredentials( - Options options, std::vector scopes) - : options_(std::move(options)) { + Options options, std::vector scopes, + std::shared_ptr event_engine) + : TokenFetcherCredentials(std::move(event_engine)), + options_(std::move(options)) { if (scopes.empty()) { scopes.push_back(GOOGLE_CLOUD_PLATFORM_DEFAULT_SCOPE); } @@ -266,12 +600,6 @@ ExternalAccountCredentials::ExternalAccountCredentials( ExternalAccountCredentials::~ExternalAccountCredentials() {} -std::string ExternalAccountCredentials::debug_string() { - return absl::StrFormat("ExternalAccountCredentials{Audience:%s,%s}", - options_.audience, - grpc_oauth2_token_fetcher_credentials::debug_string()); -} - std::string ExternalAccountCredentials::MetricsHeaderValue() { return absl::StrFormat( "gl-cpp/unknown auth/%s google-byoid-sdk source/%s sa-impersonation/%v " @@ -286,300 +614,12 @@ absl::string_view ExternalAccountCredentials::CredentialSourceType() { return "unknown"; } -// The token fetching flow: -// 1. Retrieve subject token - Subclass's RetrieveSubjectToken() gets called -// and the subject token is received in OnRetrieveSubjectTokenInternal(). -// 2. Exchange token - ExchangeToken() gets called with the -// subject token from #1. Receive the response in OnExchangeTokenInternal(). -// 3. (Optional) Impersonate service account - ImpersenateServiceAccount() gets -// called with the access token of the response from #2. Get an impersonated -// access token in OnImpersenateServiceAccountInternal(). -// 4. Finish token fetch - Return back the response that contains an access -// token in FinishTokenFetch(). -// TODO(chuanr): Avoid starting the remaining requests if the channel gets shut -// down. -void ExternalAccountCredentials::fetch_oauth2( - grpc_credentials_metadata_request* metadata_req, - grpc_polling_entity* pollent, grpc_iomgr_cb_func response_cb, - Timestamp deadline) { - CHECK_EQ(ctx_, nullptr); - ctx_ = new HTTPRequestContext(pollent, deadline); - metadata_req_ = metadata_req; - response_cb_ = response_cb; - auto cb = [this](std::string token, grpc_error_handle error) { - OnRetrieveSubjectTokenInternal(token, error); - }; - RetrieveSubjectToken(ctx_, options_, cb); -} - -void ExternalAccountCredentials::OnRetrieveSubjectTokenInternal( - absl::string_view subject_token, grpc_error_handle error) { - if (!error.ok()) { - FinishTokenFetch(error); - } else { - ExchangeToken(subject_token); - } -} - -void ExternalAccountCredentials::ExchangeToken( - absl::string_view subject_token) { - absl::StatusOr uri = URI::Parse(options_.token_url); - if (!uri.ok()) { - FinishTokenFetch(GRPC_ERROR_CREATE( - absl::StrFormat("Invalid token url: %s. Error: %s", options_.token_url, - uri.status().ToString()))); - return; - } - grpc_http_request request; - memset(&request, 0, sizeof(grpc_http_request)); - const bool add_authorization_header = - !options_.client_id.empty() && !options_.client_secret.empty(); - request.hdr_count = add_authorization_header ? 3 : 2; - auto* headers = static_cast( - gpr_malloc(sizeof(grpc_http_header) * request.hdr_count)); - headers[0].key = gpr_strdup("Content-Type"); - headers[0].value = gpr_strdup("application/x-www-form-urlencoded"); - headers[1].key = gpr_strdup("x-goog-api-client"); - headers[1].value = gpr_strdup(MetricsHeaderValue().c_str()); - if (add_authorization_header) { - std::string raw_cred = - absl::StrFormat("%s:%s", options_.client_id, options_.client_secret); - std::string str = absl::StrFormat("Basic %s", absl::Base64Escape(raw_cred)); - headers[2].key = gpr_strdup("Authorization"); - headers[2].value = gpr_strdup(str.c_str()); - } - request.hdrs = headers; - std::vector body_parts; - body_parts.push_back( - absl::StrFormat("audience=%s", UrlEncode(options_.audience).c_str())); - body_parts.push_back(absl::StrFormat( - "grant_type=%s", - UrlEncode(EXTERNAL_ACCOUNT_CREDENTIALS_GRANT_TYPE).c_str())); - body_parts.push_back(absl::StrFormat( - "requested_token_type=%s", - UrlEncode(EXTERNAL_ACCOUNT_CREDENTIALS_REQUESTED_TOKEN_TYPE).c_str())); - body_parts.push_back(absl::StrFormat( - "subject_token_type=%s", UrlEncode(options_.subject_token_type).c_str())); - body_parts.push_back( - absl::StrFormat("subject_token=%s", UrlEncode(subject_token).c_str())); - std::string scope = GOOGLE_CLOUD_PLATFORM_DEFAULT_SCOPE; - if (options_.service_account_impersonation_url.empty()) { - scope = absl::StrJoin(scopes_, " "); - } - body_parts.push_back(absl::StrFormat("scope=%s", UrlEncode(scope).c_str())); - Json::Object addtional_options_json_object; - if (options_.client_id.empty() && options_.client_secret.empty()) { - addtional_options_json_object["userProject"] = - Json::FromString(options_.workforce_pool_user_project); - } - Json addtional_options_json = - Json::FromObject(std::move(addtional_options_json_object)); - body_parts.push_back(absl::StrFormat( - "options=%s", UrlEncode(JsonDump(addtional_options_json)).c_str())); - std::string body = absl::StrJoin(body_parts, "&"); - request.body = const_cast(body.c_str()); - request.body_length = body.size(); - grpc_http_response_destroy(&ctx_->response); - ctx_->response = {}; - GRPC_CLOSURE_INIT(&ctx_->closure, OnExchangeToken, this, nullptr); - CHECK(http_request_ == nullptr); - RefCountedPtr http_request_creds; - if (uri->scheme() == "http") { - http_request_creds = RefCountedPtr( - grpc_insecure_credentials_create()); - } else { - http_request_creds = CreateHttpRequestSSLCredentials(); - } - http_request_ = - HttpRequest::Post(std::move(*uri), nullptr /* channel args */, - ctx_->pollent, &request, ctx_->deadline, &ctx_->closure, - &ctx_->response, std::move(http_request_creds)); - http_request_->Start(); - request.body = nullptr; - grpc_http_request_destroy(&request); -} - -void ExternalAccountCredentials::OnExchangeToken(void* arg, - grpc_error_handle error) { - ExternalAccountCredentials* self = - static_cast(arg); - self->OnExchangeTokenInternal(error); -} - -void ExternalAccountCredentials::OnExchangeTokenInternal( - grpc_error_handle error) { - http_request_.reset(); - if (!error.ok()) { - FinishTokenFetch(error); - } else { - if (options_.service_account_impersonation_url.empty()) { - metadata_req_->response = ctx_->response; - metadata_req_->response.body = gpr_strdup( - std::string(ctx_->response.body, ctx_->response.body_length).c_str()); - metadata_req_->response.hdrs = static_cast( - gpr_malloc(sizeof(grpc_http_header) * ctx_->response.hdr_count)); - for (size_t i = 0; i < ctx_->response.hdr_count; i++) { - metadata_req_->response.hdrs[i].key = - gpr_strdup(ctx_->response.hdrs[i].key); - metadata_req_->response.hdrs[i].value = - gpr_strdup(ctx_->response.hdrs[i].value); - } - FinishTokenFetch(absl::OkStatus()); - } else { - ImpersenateServiceAccount(); - } - } -} - -void ExternalAccountCredentials::ImpersenateServiceAccount() { - absl::string_view response_body(ctx_->response.body, - ctx_->response.body_length); - auto json = JsonParse(response_body); - if (!json.ok()) { - FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrCat( - "Invalid token exchange response: ", json.status().ToString()))); - return; - } - if (json->type() != Json::Type::kObject) { - FinishTokenFetch(GRPC_ERROR_CREATE( - "Invalid token exchange response: JSON type is not object")); - return; - } - auto it = json->object().find("access_token"); - if (it == json->object().end() || it->second.type() != Json::Type::kString) { - FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat( - "Missing or invalid access_token in %s.", response_body))); - return; - } - std::string access_token = it->second.string(); - absl::StatusOr uri = - URI::Parse(options_.service_account_impersonation_url); - if (!uri.ok()) { - FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat( - "Invalid service account impersonation url: %s. Error: %s", - options_.service_account_impersonation_url, uri.status().ToString()))); - return; - } - grpc_http_request request; - memset(&request, 0, sizeof(grpc_http_request)); - request.hdr_count = 2; - grpc_http_header* headers = static_cast( - gpr_malloc(sizeof(grpc_http_header) * request.hdr_count)); - headers[0].key = gpr_strdup("Content-Type"); - headers[0].value = gpr_strdup("application/x-www-form-urlencoded"); - std::string str = absl::StrFormat("Bearer %s", access_token); - headers[1].key = gpr_strdup("Authorization"); - headers[1].value = gpr_strdup(str.c_str()); - request.hdrs = headers; - std::vector body_members; - std::string scope = absl::StrJoin(scopes_, " "); - body_members.push_back(absl::StrFormat("scope=%s", UrlEncode(scope).c_str())); - body_members.push_back(absl::StrFormat( - "lifetime=%ds", - options_.service_account_impersonation.token_lifetime_seconds)); - std::string body = absl::StrJoin(body_members, "&"); - request.body = const_cast(body.c_str()); - request.body_length = body.size(); - grpc_http_response_destroy(&ctx_->response); - ctx_->response = {}; - GRPC_CLOSURE_INIT(&ctx_->closure, OnImpersenateServiceAccount, this, nullptr); - // TODO(ctiller): Use the callers resource quota. - CHECK(http_request_ == nullptr); - RefCountedPtr http_request_creds; - if (uri->scheme() == "http") { - http_request_creds = RefCountedPtr( - grpc_insecure_credentials_create()); - } else { - http_request_creds = CreateHttpRequestSSLCredentials(); - } - http_request_ = HttpRequest::Post( - std::move(*uri), nullptr, ctx_->pollent, &request, ctx_->deadline, - &ctx_->closure, &ctx_->response, std::move(http_request_creds)); - http_request_->Start(); - request.body = nullptr; - grpc_http_request_destroy(&request); -} - -void ExternalAccountCredentials::OnImpersenateServiceAccount( - void* arg, grpc_error_handle error) { - ExternalAccountCredentials* self = - static_cast(arg); - self->OnImpersenateServiceAccountInternal(error); -} - -void ExternalAccountCredentials::OnImpersenateServiceAccountInternal( - grpc_error_handle error) { - http_request_.reset(); - if (!error.ok()) { - FinishTokenFetch(error); - return; - } - absl::string_view response_body(ctx_->response.body, - ctx_->response.body_length); - auto json = JsonParse(response_body); - if (!json.ok()) { - FinishTokenFetch(GRPC_ERROR_CREATE( - absl::StrCat("Invalid service account impersonation response: ", - json.status().ToString()))); - return; - } - if (json->type() != Json::Type::kObject) { - FinishTokenFetch( - GRPC_ERROR_CREATE("Invalid service account impersonation response: " - "JSON type is not object")); - return; - } - auto it = json->object().find("accessToken"); - if (it == json->object().end() || it->second.type() != Json::Type::kString) { - FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat( - "Missing or invalid accessToken in %s.", response_body))); - return; - } - std::string access_token = it->second.string(); - it = json->object().find("expireTime"); - if (it == json->object().end() || it->second.type() != Json::Type::kString) { - FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat( - "Missing or invalid expireTime in %s.", response_body))); - return; - } - std::string expire_time = it->second.string(); - absl::Time t; - if (!absl::ParseTime(absl::RFC3339_full, expire_time, &t, nullptr)) { - FinishTokenFetch(GRPC_ERROR_CREATE( - "Invalid expire time of service account impersonation response.")); - return; - } - int64_t expire_in = (t - absl::Now()) / absl::Seconds(1); - std::string body = absl::StrFormat( - "{\"access_token\":\"%s\",\"expires_in\":%d,\"token_type\":\"Bearer\"}", - access_token, expire_in); - metadata_req_->response = ctx_->response; - metadata_req_->response.body = gpr_strdup(body.c_str()); - metadata_req_->response.body_length = body.length(); - metadata_req_->response.hdrs = static_cast( - gpr_malloc(sizeof(grpc_http_header) * ctx_->response.hdr_count)); - for (size_t i = 0; i < ctx_->response.hdr_count; i++) { - metadata_req_->response.hdrs[i].key = - gpr_strdup(ctx_->response.hdrs[i].key); - metadata_req_->response.hdrs[i].value = - gpr_strdup(ctx_->response.hdrs[i].value); - } - FinishTokenFetch(absl::OkStatus()); -} - -void ExternalAccountCredentials::FinishTokenFetch(grpc_error_handle error) { - GRPC_LOG_IF_ERROR("Fetch external account credentials access token", error); - // Move object state into local variables. - auto* cb = response_cb_; - response_cb_ = nullptr; - auto* metadata_req = metadata_req_; - metadata_req_ = nullptr; - auto* ctx = ctx_; - ctx_ = nullptr; - // Invoke the callback. - cb(metadata_req, error); - // Delete context. - delete ctx; +OrphanablePtr +ExternalAccountCredentials::FetchToken( + Timestamp deadline, + absl::AnyInvocable>)> on_done) { + return MakeOrphanable(this, deadline, + std::move(on_done)); } } // namespace grpc_core @@ -593,14 +633,12 @@ grpc_call_credentials* grpc_external_account_credentials_create( return nullptr; } std::vector scopes = absl::StrSplit(scopes_string, ','); - grpc_error_handle error; - auto creds = grpc_core::ExternalAccountCredentials::Create( - *json, std::move(scopes), &error) - .release(); - if (!error.ok()) { + auto creds = + grpc_core::ExternalAccountCredentials::Create(*json, std::move(scopes)); + if (!creds.ok()) { LOG(ERROR) << "External account credentials creation failed. Error: " - << grpc_core::StatusToString(error); + << grpc_core::StatusToString(creds.status()); return nullptr; } - return creds; + return creds->release(); } diff --git a/src/core/lib/security/credentials/external/external_account_credentials.h b/src/core/lib/security/credentials/external/external_account_credentials.h index f0023ab878..5dfbb24a36 100644 --- a/src/core/lib/security/credentials/external/external_account_credentials.h +++ b/src/core/lib/security/credentials/external/external_account_credentials.h @@ -20,11 +20,13 @@ #include #include +#include #include #include #include "absl/strings/string_view.h" +#include #include #include "src/core/lib/gprpp/orphanable.h" @@ -34,6 +36,7 @@ #include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/polling_entity.h" #include "src/core/lib/security/credentials/oauth2/oauth2_credentials.h" +#include "src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.h" #include "src/core/util/http_client/httpcli.h" #include "src/core/util/http_client/parser.h" #include "src/core/util/json/json.h" @@ -44,8 +47,7 @@ namespace grpc_core { // exchanging external account credentials for GCP access token to authorize // requests to GCP APIs. The specific logic of retrieving subject token is // implemented in subclasses. -class ExternalAccountCredentials - : public grpc_oauth2_token_fetcher_credentials { +class ExternalAccountCredentials : public TokenFetcherCredentials { public: struct ServiceAccountImpersonation { int32_t token_lifetime_seconds; @@ -66,72 +68,140 @@ class ExternalAccountCredentials std::string workforce_pool_user_project; }; - static RefCountedPtr Create( + static absl::StatusOr> Create( const Json& json, std::vector scopes, - grpc_error_handle* error); + std::shared_ptr + event_engine = nullptr); - ExternalAccountCredentials(Options options, std::vector scopes); + ExternalAccountCredentials( + Options options, std::vector scopes, + std::shared_ptr + event_engine = nullptr); ~ExternalAccountCredentials() override; - std::string debug_string() override; protected: - // This is a helper struct to pass information between multiple callback based - // asynchronous calls. - struct HTTPRequestContext { - HTTPRequestContext(grpc_polling_entity* pollent, Timestamp deadline) - : pollent(pollent), deadline(deadline) {} - ~HTTPRequestContext() { grpc_http_response_destroy(&response); } - - // Contextual parameters passed from - // grpc_oauth2_token_fetcher_credentials::fetch_oauth2(). - grpc_polling_entity* pollent; - Timestamp deadline; - - // Reusable token fetch http response and closure. - grpc_closure closure; - grpc_http_response response; + // A base class for a cancellable fetch operation. + class FetchBody : public InternallyRefCounted { + public: + explicit FetchBody( + absl::AnyInvocable)> on_done) + : on_done_(std::move(on_done)) {} + + void Orphan() override { + Shutdown(); + Unref(); + } + + protected: + // The subclass must call this when the fetch is complete, even if + // cancelled. + void Finish(absl::StatusOr result) { + std::exchange(on_done_, nullptr)(std::move(result)); + } + + private: + virtual void Shutdown() = 0; + + absl::AnyInvocable)> on_done_; }; - // Subclasses of base external account credentials need to override this - // method to implement the specific subject token retrieval logic. - // Once the subject token is ready, subclasses need to invoke - // the callback function (cb) to pass the subject token (or error) - // back. - virtual void RetrieveSubjectToken( - HTTPRequestContext* ctx, const Options& options, - std::function cb) = 0; + // A simple no-op implementation, used for async execution of the + // on_done callback. + class NoOpFetchBody final : public FetchBody { + public: + NoOpFetchBody(grpc_event_engine::experimental::EventEngine& event_engine, + absl::AnyInvocable)> on_done, + absl::StatusOr result); - virtual absl::string_view CredentialSourceType(); + private: + void Shutdown() override {} + }; - std::string MetricsHeaderValue(); + // An implementation for HTTP requests. + class HttpFetchBody final : public FetchBody { + public: + HttpFetchBody( + absl::FunctionRef(grpc_http_response*, + grpc_closure*)> + start_http_request, + absl::AnyInvocable)> on_done); - private: - // This method implements the common token fetch logic and it will be called - // when grpc_oauth2_token_fetcher_credentials request a new access token. - void fetch_oauth2(grpc_credentials_metadata_request* req, - grpc_polling_entity* pollent, grpc_iomgr_cb_func cb, - Timestamp deadline) override; + ~HttpFetchBody() override { grpc_http_response_destroy(&response_); } + + private: + void Shutdown() override { http_request_.reset(); } + + static void OnHttpResponse(void* arg, grpc_error_handle error); + + OrphanablePtr http_request_; + grpc_http_response response_; + grpc_closure on_http_response_; + }; - void OnRetrieveSubjectTokenInternal(absl::string_view subject_token, - grpc_error_handle error); + // An implementation of TokenFetcherCredentials::FetchRequest that + // executes a series of FetchBody operations to ultimately get to a + // token result. + class ExternalFetchRequest : public FetchRequest { + public: + ExternalFetchRequest( + ExternalAccountCredentials* creds, Timestamp deadline, + absl::AnyInvocable< + void(absl::StatusOr>)> + on_done); + + void Orphan() override; + + protected: + Timestamp deadline() const { return deadline_; } + grpc_polling_entity* pollent() const { return creds_->pollent(); } + const Options& options() const { return creds_->options_; } + + private: + void ExchangeToken(absl::StatusOr subject_token); + void MaybeImpersonateServiceAccount( + absl::StatusOr response_body); + void OnImpersonateServiceAccount(absl::StatusOr response_body); + + void FinishTokenFetch(absl::StatusOr response_body); + + // If status is non-OK or we've been shut down, calls FinishTokenFetch() + // and returns true. + bool MaybeFailLocked(absl::Status status) + ABSL_EXCLUSIVE_LOCKS_REQUIRED(&mu_); + + ExternalAccountCredentials* creds_; + Timestamp deadline_; + absl::AnyInvocable>)> + on_done_; + + Mutex mu_; + OrphanablePtr fetch_body_ ABSL_GUARDED_BY(&mu_); + }; - void ExchangeToken(absl::string_view subject_token); - static void OnExchangeToken(void* arg, grpc_error_handle error); - void OnExchangeTokenInternal(grpc_error_handle error); + virtual absl::string_view CredentialSourceType(); - void ImpersenateServiceAccount(); - static void OnImpersenateServiceAccount(void* arg, grpc_error_handle error); - void OnImpersenateServiceAccountInternal(grpc_error_handle error); + std::string MetricsHeaderValue(); - void FinishTokenFetch(grpc_error_handle error); + absl::string_view audience() const { return options_.audience; } + + private: + OrphanablePtr FetchToken( + Timestamp deadline, + absl::AnyInvocable>)> on_done) + final; + + // Subclasses of ExternalAccountCredentials need to override this + // method to implement the specific-subject token retrieval logic. + // The caller will save the resulting FetchBody object, which will + // be orphaned upon cancellation. The FetchBody object must + // eventually invoke on_done. + virtual OrphanablePtr RetrieveSubjectToken( + Timestamp deadline, + absl::AnyInvocable)> on_done) = 0; Options options_; std::vector scopes_; - - OrphanablePtr http_request_; - HTTPRequestContext* ctx_ = nullptr; - grpc_credentials_metadata_request* metadata_req_ = nullptr; - grpc_iomgr_cb_func response_cb_ = nullptr; }; } // namespace grpc_core diff --git a/src/core/lib/security/credentials/external/file_external_account_credentials.cc b/src/core/lib/security/credentials/external/file_external_account_credentials.cc index 0bbef7b8a0..086af8c79c 100644 --- a/src/core/lib/security/credentials/external/file_external_account_credentials.cc +++ b/src/core/lib/security/credentials/external/file_external_account_credentials.cc @@ -34,22 +34,78 @@ namespace grpc_core { -RefCountedPtr -FileExternalAccountCredentials::Create(Options options, - std::vector scopes, - grpc_error_handle* error) { - auto creds = MakeRefCounted( - std::move(options), std::move(scopes), error); - if (error->ok()) { - return creds; - } else { - return nullptr; +// +// FileExternalAccountCredentials::FileFetchBody +// + +FileExternalAccountCredentials::FileFetchBody::FileFetchBody( + absl::AnyInvocable)> on_done, + FileExternalAccountCredentials* creds) + : FetchBody(std::move(on_done)), creds_(creds) { + // Start work asynchronously, since we can't invoke the callback + // synchronously without causing a deadlock. + creds->event_engine().Run([self = RefAsSubclass()]() mutable { + ApplicationCallbackExecCtx application_exec_ctx; + ExecCtx exec_ctx; + self->ReadFile(); + self.reset(); + }); +} + +void FileExternalAccountCredentials::FileFetchBody::ReadFile() { + // To retrieve the subject token, we read the file every time we make a + // request because it may have changed since the last request. + auto content_slice = LoadFile(creds_->file_, /*add_null_terminator=*/false); + if (!content_slice.ok()) { + Finish(content_slice.status()); + return; } + absl::string_view content = content_slice->as_string_view(); + if (creds_->format_type_ == "json") { + auto content_json = JsonParse(content); + if (!content_json.ok() || content_json->type() != Json::Type::kObject) { + Finish(GRPC_ERROR_CREATE( + "The content of the file is not a valid json object.")); + return; + } + auto content_it = + content_json->object().find(creds_->format_subject_token_field_name_); + if (content_it == content_json->object().end()) { + Finish(GRPC_ERROR_CREATE("Subject token field not present.")); + return; + } + if (content_it->second.type() != Json::Type::kString) { + Finish(GRPC_ERROR_CREATE("Subject token field must be a string.")); + return; + } + Finish(content_it->second.string()); + return; + } + Finish(std::string(content)); +} + +// +// FileExternalAccountCredentials +// + +absl::StatusOr> +FileExternalAccountCredentials::Create( + Options options, std::vector scopes, + std::shared_ptr + event_engine) { + grpc_error_handle error; + auto creds = MakeRefCounted( + std::move(options), std::move(scopes), std::move(event_engine), &error); + if (!error.ok()) return error; + return creds; } FileExternalAccountCredentials::FileExternalAccountCredentials( - Options options, std::vector scopes, grpc_error_handle* error) - : ExternalAccountCredentials(options, std::move(scopes)) { + Options options, std::vector scopes, + std::shared_ptr event_engine, + grpc_error_handle* error) + : ExternalAccountCredentials(options, std::move(scopes), + std::move(event_engine)) { auto it = options.credential_source.object().find("file"); if (it == options.credential_source.object().end()) { *error = GRPC_ERROR_CREATE("file field not present."); @@ -96,38 +152,21 @@ FileExternalAccountCredentials::FileExternalAccountCredentials( } } -void FileExternalAccountCredentials::RetrieveSubjectToken( - HTTPRequestContext* /*ctx*/, const Options& /*options*/, - std::function cb) { - // To retrieve the subject token, we read the file every time we make a - // request because it may have changed since the last request. - auto content_slice = LoadFile(file_, /*add_null_terminator=*/false); - if (!content_slice.ok()) { - cb("", content_slice.status()); - return; - } - absl::string_view content = content_slice->as_string_view(); - if (format_type_ == "json") { - auto content_json = JsonParse(content); - if (!content_json.ok() || content_json->type() != Json::Type::kObject) { - cb("", GRPC_ERROR_CREATE( - "The content of the file is not a valid json object.")); - return; - } - auto content_it = - content_json->object().find(format_subject_token_field_name_); - if (content_it == content_json->object().end()) { - cb("", GRPC_ERROR_CREATE("Subject token field not present.")); - return; - } - if (content_it->second.type() != Json::Type::kString) { - cb("", GRPC_ERROR_CREATE("Subject token field must be a string.")); - return; - } - cb(content_it->second.string(), absl::OkStatus()); - return; - } - cb(std::string(content), absl::OkStatus()); +std::string FileExternalAccountCredentials::debug_string() { + return absl::StrCat("FileExternalAccountCredentials{Audience:", audience(), + ")"); +} + +UniqueTypeName FileExternalAccountCredentials::type() const { + static UniqueTypeName::Factory kFactory("FileExternalAccountCredentials"); + return kFactory.Create(); +} + +OrphanablePtr +FileExternalAccountCredentials::RetrieveSubjectToken( + Timestamp /*deadline*/, + absl::AnyInvocable)> on_done) { + return MakeOrphanable(std::move(on_done), this); } absl::string_view FileExternalAccountCredentials::CredentialSourceType() { diff --git a/src/core/lib/security/credentials/external/file_external_account_credentials.h b/src/core/lib/security/credentials/external/file_external_account_credentials.h index 8436dea8e7..8ed7b14653 100644 --- a/src/core/lib/security/credentials/external/file_external_account_credentials.h +++ b/src/core/lib/security/credentials/external/file_external_account_credentials.h @@ -33,18 +33,38 @@ namespace grpc_core { class FileExternalAccountCredentials final : public ExternalAccountCredentials { public: - static RefCountedPtr Create( + static absl::StatusOr> Create( Options options, std::vector scopes, + std::shared_ptr + event_engine = nullptr); + + FileExternalAccountCredentials( + Options options, std::vector scopes, + std::shared_ptr + event_engine, grpc_error_handle* error); - FileExternalAccountCredentials(Options options, - std::vector scopes, - grpc_error_handle* error); + std::string debug_string() override; + + UniqueTypeName type() const override; private: - void RetrieveSubjectToken( - HTTPRequestContext* ctx, const Options& options, - std::function cb) override; + class FileFetchBody final : public FetchBody { + public: + FileFetchBody(absl::AnyInvocable)> on_done, + FileExternalAccountCredentials* creds); + + private: + void Shutdown() override {} + + void ReadFile(); + + FileExternalAccountCredentials* creds_; + }; + + OrphanablePtr RetrieveSubjectToken( + Timestamp deadline, + absl::AnyInvocable)> on_done) override; absl::string_view CredentialSourceType() override; diff --git a/src/core/lib/security/credentials/external/url_external_account_credentials.cc b/src/core/lib/security/credentials/external/url_external_account_credentials.cc index b2a5359c59..bcea5eadc0 100644 --- a/src/core/lib/security/credentials/external/url_external_account_credentials.cc +++ b/src/core/lib/security/credentials/external/url_external_account_credentials.cc @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -47,22 +46,24 @@ namespace grpc_core { -RefCountedPtr -UrlExternalAccountCredentials::Create(Options options, - std::vector scopes, - grpc_error_handle* error) { +absl::StatusOr> +UrlExternalAccountCredentials::Create( + Options options, std::vector scopes, + std::shared_ptr + event_engine) { + grpc_error_handle error; auto creds = MakeRefCounted( - std::move(options), std::move(scopes), error); - if (error->ok()) { - return creds; - } else { - return nullptr; - } + std::move(options), std::move(scopes), std::move(event_engine), &error); + if (!error.ok()) return error; + return creds; } UrlExternalAccountCredentials::UrlExternalAccountCredentials( - Options options, std::vector scopes, grpc_error_handle* error) - : ExternalAccountCredentials(options, std::move(scopes)) { + Options options, std::vector scopes, + std::shared_ptr event_engine, + grpc_error_handle* error) + : ExternalAccountCredentials(options, std::move(scopes), + std::move(event_engine)) { auto it = options.credential_source.object().find("url"); if (it == options.credential_source.object().end()) { *error = GRPC_ERROR_CREATE("url field not present."); @@ -131,114 +132,88 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials( } } -void UrlExternalAccountCredentials::RetrieveSubjectToken( - HTTPRequestContext* ctx, const Options& /*options*/, - std::function cb) { - if (ctx == nullptr) { - FinishRetrieveSubjectToken( - "", - GRPC_ERROR_CREATE( - "Missing HTTPRequestContext to start subject token retrieval.")); - return; - } - auto url_for_request = - URI::Create(url_.scheme(), url_.authority(), url_full_path_, - {} /* query params */, "" /* fragment */); - if (!url_for_request.ok()) { - FinishRetrieveSubjectToken( - "", absl_status_to_grpc_error(url_for_request.status())); - return; - } - ctx_ = ctx; - cb_ = cb; - grpc_http_request request; - memset(&request, 0, sizeof(grpc_http_request)); - request.path = gpr_strdup(url_full_path_.c_str()); - grpc_http_header* headers = nullptr; - request.hdr_count = headers_.size(); - headers = static_cast( - gpr_malloc(sizeof(grpc_http_header) * request.hdr_count)); - int i = 0; - for (auto const& header : headers_) { - headers[i].key = gpr_strdup(header.first.c_str()); - headers[i].value = gpr_strdup(header.second.c_str()); - ++i; - } - request.hdrs = headers; - grpc_http_response_destroy(&ctx_->response); - ctx_->response = {}; - GRPC_CLOSURE_INIT(&ctx_->closure, OnRetrieveSubjectToken, this, nullptr); - CHECK(http_request_ == nullptr); - RefCountedPtr http_request_creds; - if (url_.scheme() == "http") { - http_request_creds = RefCountedPtr( - grpc_insecure_credentials_create()); - } else { - http_request_creds = CreateHttpRequestSSLCredentials(); - } - http_request_ = - HttpRequest::Get(std::move(*url_for_request), nullptr /* channel args */, - ctx_->pollent, &request, ctx_->deadline, &ctx_->closure, - &ctx_->response, std::move(http_request_creds)); - http_request_->Start(); - grpc_http_request_destroy(&request); +std::string UrlExternalAccountCredentials::debug_string() { + return absl::StrCat("UrlExternalAccountCredentials{Audience:", audience(), + ")"); } -void UrlExternalAccountCredentials::OnRetrieveSubjectToken( - void* arg, grpc_error_handle error) { - UrlExternalAccountCredentials* self = - static_cast(arg); - self->OnRetrieveSubjectTokenInternal(error); +UniqueTypeName UrlExternalAccountCredentials::type() const { + static UniqueTypeName::Factory kFactory("UrlExternalAccountCredentials"); + return kFactory.Create(); } -void UrlExternalAccountCredentials::OnRetrieveSubjectTokenInternal( - grpc_error_handle error) { - http_request_.reset(); - if (!error.ok()) { - FinishRetrieveSubjectToken("", error); - return; - } - absl::string_view response_body(ctx_->response.body, - ctx_->response.body_length); - if (format_type_ == "json") { - auto response_json = JsonParse(response_body); - if (!response_json.ok() || response_json->type() != Json::Type::kObject) { - FinishRetrieveSubjectToken( - "", GRPC_ERROR_CREATE( - "The format of response is not a valid json object.")); - return; - } - auto response_it = - response_json->object().find(format_subject_token_field_name_); - if (response_it == response_json->object().end()) { - FinishRetrieveSubjectToken( - "", GRPC_ERROR_CREATE("Subject token field not present.")); - return; - } - if (response_it->second.type() != Json::Type::kString) { - FinishRetrieveSubjectToken( - "", GRPC_ERROR_CREATE("Subject token field must be a string.")); - return; - } - FinishRetrieveSubjectToken(response_it->second.string(), error); - return; - } - FinishRetrieveSubjectToken(std::string(response_body), absl::OkStatus()); -} - -void UrlExternalAccountCredentials::FinishRetrieveSubjectToken( - std::string subject_token, grpc_error_handle error) { - // Reset context - ctx_ = nullptr; - // Move object state into local variables. - auto cb = cb_; - cb_ = nullptr; - // Invoke the callback. - if (!error.ok()) { - cb("", error); - } else { - cb(subject_token, absl::OkStatus()); +OrphanablePtr +UrlExternalAccountCredentials::RetrieveSubjectToken( + Timestamp deadline, + absl::AnyInvocable)> on_done) { + auto url_for_request = + URI::Create(url_.scheme(), url_.authority(), url_full_path_, + {} /* query params */, "" /* fragment */); + if (!url_for_request.ok()) { + return MakeOrphanable( + event_engine(), std::move(on_done), + absl_status_to_grpc_error(url_for_request.status())); } + return MakeOrphanable( + [&](grpc_http_response* response, grpc_closure* on_http_response) { + grpc_http_request request; + memset(&request, 0, sizeof(grpc_http_request)); + request.path = gpr_strdup(url_full_path_.c_str()); + grpc_http_header* headers = nullptr; + request.hdr_count = headers_.size(); + headers = static_cast( + gpr_malloc(sizeof(grpc_http_header) * request.hdr_count)); + int i = 0; + for (auto const& header : headers_) { + headers[i].key = gpr_strdup(header.first.c_str()); + headers[i].value = gpr_strdup(header.second.c_str()); + ++i; + } + request.hdrs = headers; + RefCountedPtr http_request_creds; + if (url_.scheme() == "http") { + http_request_creds = RefCountedPtr( + grpc_insecure_credentials_create()); + } else { + http_request_creds = CreateHttpRequestSSLCredentials(); + } + auto http_request = + HttpRequest::Get(std::move(*url_for_request), /*args=*/nullptr, + pollent(), &request, deadline, on_http_response, + response, std::move(http_request_creds)); + http_request->Start(); + grpc_http_request_destroy(&request); + return http_request; + }, + [this, on_done = std::move(on_done)]( + absl::StatusOr response_body) mutable { + if (!response_body.ok()) { + on_done(std::move(response_body)); + return; + } + if (format_type_ == "json") { + auto response_json = JsonParse(*response_body); + if (!response_json.ok() || + response_json->type() != Json::Type::kObject) { + on_done(GRPC_ERROR_CREATE( + "The format of response is not a valid json object.")); + return; + } + auto response_it = + response_json->object().find(format_subject_token_field_name_); + if (response_it == response_json->object().end()) { + on_done(GRPC_ERROR_CREATE("Subject token field not present.")); + return; + } + if (response_it->second.type() != Json::Type::kString) { + on_done(GRPC_ERROR_CREATE("Subject token field must be a string.")); + return; + } + on_done(response_it->second.string()); + return; + } + on_done(std::move(response_body)); + }); } absl::string_view UrlExternalAccountCredentials::CredentialSourceType() { diff --git a/src/core/lib/security/credentials/external/url_external_account_credentials.h b/src/core/lib/security/credentials/external/url_external_account_credentials.h index 209e652a15..65dcae9176 100644 --- a/src/core/lib/security/credentials/external/url_external_account_credentials.h +++ b/src/core/lib/security/credentials/external/url_external_account_credentials.h @@ -37,37 +37,34 @@ namespace grpc_core { class UrlExternalAccountCredentials final : public ExternalAccountCredentials { public: - static RefCountedPtr Create( + static absl::StatusOr> Create( Options options, std::vector scopes, + std::shared_ptr + event_engine = nullptr); + + UrlExternalAccountCredentials( + Options options, std::vector scopes, + std::shared_ptr + event_engine, grpc_error_handle* error); - UrlExternalAccountCredentials(Options options, - std::vector scopes, - grpc_error_handle* error); + std::string debug_string() override; + + UniqueTypeName type() const override; private: - void RetrieveSubjectToken( - HTTPRequestContext* ctx, const Options& options, - std::function cb) override; + OrphanablePtr RetrieveSubjectToken( + Timestamp deadline, + absl::AnyInvocable)> on_done) override; absl::string_view CredentialSourceType() override; - static void OnRetrieveSubjectToken(void* arg, grpc_error_handle error); - void OnRetrieveSubjectTokenInternal(grpc_error_handle error); - - void FinishRetrieveSubjectToken(std::string subject_token, - grpc_error_handle error); - // Fields of credential source URI url_; std::string url_full_path_; std::map headers_; std::string format_type_; std::string format_subject_token_field_name_; - - OrphanablePtr http_request_; - HTTPRequestContext* ctx_ = nullptr; - std::function cb_ = nullptr; }; } // namespace grpc_core diff --git a/src/core/lib/security/credentials/fake/fake_credentials.h b/src/core/lib/security/credentials/fake/fake_credentials.h index 214d9b3ac3..d4b00d6eb4 100644 --- a/src/core/lib/security/credentials/fake/fake_credentials.h +++ b/src/core/lib/security/credentials/fake/fake_credentials.h @@ -99,6 +99,8 @@ class grpc_md_only_test_credentials : public grpc_call_credentials { key_(grpc_core::Slice::FromCopiedString(md_key)), value_(grpc_core::Slice::FromCopiedString(md_value)) {} + void Orphaned() override {} + grpc_core::ArenaPromise> GetRequestMetadata(grpc_core::ClientMetadataHandle initial_metadata, const GetRequestMetadataArgs* args) override; 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 3fa306cae5..d649eb5512 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 @@ -258,68 +258,54 @@ static int is_metadata_server_reachable() { static grpc_error_handle create_default_creds_from_path( const std::string& creds_path, grpc_core::RefCountedPtr* creds) { - grpc_auth_json_key key; - grpc_auth_refresh_token token; - grpc_core::RefCountedPtr result; - absl::StatusOr creds_data; - grpc_error_handle error; - Json json; if (creds_path.empty()) { - error = GRPC_ERROR_CREATE("creds_path unset"); - goto end; + return GRPC_ERROR_CREATE("creds_path unset"); } - creds_data = grpc_core::LoadFile(creds_path, /*add_null_terminator=*/false); + auto creds_data = + grpc_core::LoadFile(creds_path, /*add_null_terminator=*/false); if (!creds_data.ok()) { - error = absl_status_to_grpc_error(creds_data.status()); - goto end; + return absl_status_to_grpc_error(creds_data.status()); } - { - auto json_or = grpc_core::JsonParse(creds_data->as_string_view()); - if (!json_or.ok()) { - error = absl_status_to_grpc_error(json_or.status()); - goto end; - } - json = std::move(*json_or); + auto json = grpc_core::JsonParse(creds_data->as_string_view()); + if (!json.ok()) { + return absl_status_to_grpc_error(json.status()); } - if (json.type() != Json::Type::kObject) { - error = GRPC_ERROR_CREATE(absl::StrCat("Failed to parse JSON \"", - creds_data->as_string_view(), "\"")); - goto end; + if (json->type() != Json::Type::kObject) { + return GRPC_ERROR_CREATE(absl::StrCat("Failed to parse JSON \"", + creds_data->as_string_view(), "\"")); } - // First, try an auth json key. - key = grpc_auth_json_key_create_from_json(json); + grpc_auth_json_key key = grpc_auth_json_key_create_from_json(*json); if (grpc_auth_json_key_is_valid(&key)) { - result = + *creds = grpc_service_account_jwt_access_credentials_create_from_auth_json_key( key, grpc_max_auth_token_lifetime()); - if (result == nullptr) { - error = GRPC_ERROR_CREATE( + if (*creds == nullptr) { + return GRPC_ERROR_CREATE( "grpc_service_account_jwt_access_credentials_create_from_auth_json_" "key failed"); } - goto end; + return absl::OkStatus(); } - // Then try a refresh token if the auth json key was invalid. - token = grpc_auth_refresh_token_create_from_json(json); + grpc_auth_refresh_token token = + grpc_auth_refresh_token_create_from_json(*json); if (grpc_auth_refresh_token_is_valid(&token)) { - result = + *creds = grpc_refresh_token_credentials_create_from_auth_refresh_token(token); - if (result == nullptr) { - error = GRPC_ERROR_CREATE( + if (*creds == nullptr) { + return GRPC_ERROR_CREATE( "grpc_refresh_token_credentials_create_from_auth_refresh_token " "failed"); } - goto end; + return absl::OkStatus(); } - - result = grpc_core::ExternalAccountCredentials::Create(json, {}, &error); - -end: - CHECK((result == nullptr) + (error.ok()) == 1); - *creds = result; - return error; + // Use external creds. + auto external_creds = + grpc_core::ExternalAccountCredentials::Create(*json, {}); + if (!external_creds.ok()) return external_creds.status(); + *creds = std::move(*external_creds); + return absl::OkStatus(); } static void update_tenancy() { diff --git a/src/core/lib/security/credentials/iam/iam_credentials.cc b/src/core/lib/security/credentials/iam/iam_credentials.cc index 76e54d3dd8..876851555d 100644 --- a/src/core/lib/security/credentials/iam/iam_credentials.cc +++ b/src/core/lib/security/credentials/iam/iam_credentials.cc @@ -27,7 +27,6 @@ #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" -#include #include #include "src/core/lib/debug/trace.h" diff --git a/src/core/lib/security/credentials/iam/iam_credentials.h b/src/core/lib/security/credentials/iam/iam_credentials.h index 592dffc4eb..8fa67a9048 100644 --- a/src/core/lib/security/credentials/iam/iam_credentials.h +++ b/src/core/lib/security/credentials/iam/iam_credentials.h @@ -40,6 +40,8 @@ class grpc_google_iam_credentials : public grpc_call_credentials { grpc_google_iam_credentials(const char* token, const char* authority_selector); + void Orphaned() override {} + grpc_core::ArenaPromise> GetRequestMetadata(grpc_core::ClientMetadataHandle initial_metadata, const GetRequestMetadataArgs* args) override; diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.h b/src/core/lib/security/credentials/jwt/jwt_credentials.h index 91332098ee..751ff187fc 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.h +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.h @@ -51,6 +51,8 @@ class grpc_service_account_jwt_access_credentials gpr_timespec token_lifetime); ~grpc_service_account_jwt_access_credentials() override; + void Orphaned() override {} + grpc_core::ArenaPromise> GetRequestMetadata(grpc_core::ClientMetadataHandle initial_metadata, const GetRequestMetadataArgs* args) override; diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index 014e53ee3c..4e366d0bb6 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -18,7 +18,6 @@ #include "src/core/lib/security/credentials/oauth2/oauth2_credentials.h" -#include #include #include @@ -30,6 +29,7 @@ #include "absl/log/check.h" #include "absl/log/log.h" #include "absl/status/status.h" +#include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" @@ -141,13 +141,49 @@ void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token) { } // -// Oauth2 Token Fetcher credentials. +// Oauth2 Token parsing. // -grpc_oauth2_token_fetcher_credentials:: - ~grpc_oauth2_token_fetcher_credentials() { - gpr_mu_destroy(&mu_); - grpc_pollset_set_destroy(grpc_polling_entity_pollset_set(&pollent_)); +grpc_credentials_status +grpc_oauth2_token_fetcher_credentials_parse_server_response_body( + absl::string_view body, absl::optional* token_value, + grpc_core::Duration* token_lifetime) { + auto json = grpc_core::JsonParse(body); + if (!json.ok()) { + LOG(ERROR) << "Could not parse JSON from " << body << ": " << json.status(); + return GRPC_CREDENTIALS_ERROR; + } + if (json->type() != Json::Type::kObject) { + LOG(ERROR) << "Response should be a JSON object"; + return GRPC_CREDENTIALS_ERROR; + } + auto it = json->object().find("access_token"); + if (it == json->object().end() || it->second.type() != Json::Type::kString) { + LOG(ERROR) << "Missing or invalid access_token in JSON."; + return GRPC_CREDENTIALS_ERROR; + } + absl::string_view access_token = it->second.string(); + it = json->object().find("token_type"); + if (it == json->object().end() || it->second.type() != Json::Type::kString) { + LOG(ERROR) << "Missing or invalid token_type in JSON."; + return GRPC_CREDENTIALS_ERROR; + } + absl::string_view token_type = it->second.string(); + it = json->object().find("expires_in"); + if (it == json->object().end() || it->second.type() != Json::Type::kNumber) { + LOG(ERROR) << "Missing or invalid expires_in in JSON."; + return GRPC_CREDENTIALS_ERROR; + } + absl::string_view expires_in = it->second.string(); + long seconds; + if (!absl::SimpleAtoi(expires_in, &seconds)) { + LOG(ERROR) << "Invalid expires_in in JSON."; + return GRPC_CREDENTIALS_ERROR; + } + *token_lifetime = grpc_core::Duration::Seconds(seconds); + *token_value = grpc_core::Slice::FromCopiedString( + absl::StrCat(token_type, " ", access_token)); + return GRPC_CREDENTIALS_OK; } grpc_credentials_status @@ -155,217 +191,99 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( const grpc_http_response* response, absl::optional* token_value, grpc_core::Duration* token_lifetime) { - char* null_terminated_body = nullptr; - grpc_credentials_status status = GRPC_CREDENTIALS_OK; - + *token_value = absl::nullopt; if (response == nullptr) { LOG(ERROR) << "Received NULL response."; - status = GRPC_CREDENTIALS_ERROR; - goto end; + return GRPC_CREDENTIALS_ERROR; } - - if (response->body_length > 0) { - null_terminated_body = - static_cast(gpr_malloc(response->body_length + 1)); - null_terminated_body[response->body_length] = '\0'; - memcpy(null_terminated_body, response->body, response->body_length); - } - + absl::string_view body(response->body, response->body_length); if (response->status != 200) { LOG(ERROR) << "Call to http server ended with error " << response->status - << " [" - << (null_terminated_body != nullptr ? null_terminated_body : "") - << "]"; - status = GRPC_CREDENTIALS_ERROR; - goto end; - } else { - const char* access_token = nullptr; - const char* token_type = nullptr; - const char* expires_in = nullptr; - Json::Object::const_iterator it; - auto json = grpc_core::JsonParse( - null_terminated_body != nullptr ? null_terminated_body : ""); - if (!json.ok()) { - LOG(ERROR) << "Could not parse JSON from " << null_terminated_body << ": " - << json.status(); - status = GRPC_CREDENTIALS_ERROR; - goto end; - } - if (json->type() != Json::Type::kObject) { - 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) { - LOG(ERROR) << "Missing or invalid access_token in JSON."; - status = GRPC_CREDENTIALS_ERROR; - goto end; - } - access_token = it->second.string().c_str(); - it = json->object().find("token_type"); - if (it == json->object().end() || - it->second.type() != Json::Type::kString) { - LOG(ERROR) << "Missing or invalid token_type in JSON."; - status = GRPC_CREDENTIALS_ERROR; - goto end; - } - token_type = it->second.string().c_str(); - it = json->object().find("expires_in"); - if (it == json->object().end() || - it->second.type() != Json::Type::kNumber) { - LOG(ERROR) << "Missing or invalid expires_in in JSON."; - status = GRPC_CREDENTIALS_ERROR; - goto end; - } - expires_in = it->second.string().c_str(); - *token_lifetime = - grpc_core::Duration::Seconds(strtol(expires_in, nullptr, 10)); - *token_value = grpc_core::Slice::FromCopiedString( - absl::StrCat(token_type, " ", access_token)); - status = GRPC_CREDENTIALS_OK; + << " [" << body << "]"; + return GRPC_CREDENTIALS_ERROR; } - -end: - if (status != GRPC_CREDENTIALS_OK) *token_value = absl::nullopt; - gpr_free(null_terminated_body); - return status; + return grpc_oauth2_token_fetcher_credentials_parse_server_response_body( + body, token_value, token_lifetime); } -static void on_oauth2_token_fetcher_http_response(void* user_data, - grpc_error_handle error) { - GRPC_LOG_IF_ERROR("oauth_fetch", error); - grpc_credentials_metadata_request* r = - static_cast(user_data); - grpc_oauth2_token_fetcher_credentials* c = - reinterpret_cast(r->creds.get()); - c->on_http_response(r, error); -} +// +// Oauth2TokenFetcherCredentials +// -void grpc_oauth2_token_fetcher_credentials::on_http_response( - grpc_credentials_metadata_request* r, grpc_error_handle error) { - absl::optional access_token_value; - grpc_core::Duration token_lifetime; - grpc_credentials_status status = - error.ok() ? grpc_oauth2_token_fetcher_credentials_parse_server_response( - &r->response, &access_token_value, &token_lifetime) - : GRPC_CREDENTIALS_ERROR; - // Update cache and grab list of pending requests. - gpr_mu_lock(&mu_); - token_fetch_pending_ = false; - if (access_token_value.has_value()) { - access_token_value_ = access_token_value->Ref(); - } else { - access_token_value_ = absl::nullopt; - } - token_expiration_ = status == GRPC_CREDENTIALS_OK - ? gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), - token_lifetime.as_timespec()) - : gpr_inf_past(GPR_CLOCK_MONOTONIC); - grpc_oauth2_pending_get_request_metadata* pending_request = pending_requests_; - pending_requests_ = nullptr; - gpr_mu_unlock(&mu_); - // Invoke callbacks for all pending requests. - while (pending_request != nullptr) { - if (status == GRPC_CREDENTIALS_OK) { - pending_request->result = access_token_value->Ref(); - } else { - auto err = GRPC_ERROR_CREATE_REFERENCING( - "Error occurred when fetching oauth2 token.", &error, 1); - pending_request->result = grpc_error_to_absl_status(err); - } - pending_request->done.store(true, std::memory_order_release); - pending_request->waker.Wakeup(); - grpc_polling_entity_del_from_pollset_set( - pending_request->pollent, grpc_polling_entity_pollset_set(&pollent_)); - grpc_oauth2_pending_get_request_metadata* prev = pending_request; - pending_request = pending_request->next; - prev->Unref(); - } - delete r; -} +namespace grpc_core { -grpc_core::ArenaPromise> -grpc_oauth2_token_fetcher_credentials::GetRequestMetadata( - grpc_core::ClientMetadataHandle initial_metadata, - const grpc_call_credentials::GetRequestMetadataArgs*) { - // Check if we can use the cached token. - absl::optional cached_access_token_value; - gpr_mu_lock(&mu_); - if (access_token_value_.has_value() && - gpr_time_cmp( - gpr_time_sub(token_expiration_, gpr_now(GPR_CLOCK_MONOTONIC)), - gpr_time_from_seconds(GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS, - GPR_TIMESPAN)) > 0) { - cached_access_token_value = access_token_value_->Ref(); - } - if (cached_access_token_value.has_value()) { - gpr_mu_unlock(&mu_); - initial_metadata->Append( - GRPC_AUTHORIZATION_METADATA_KEY, std::move(*cached_access_token_value), - [](absl::string_view, const grpc_core::Slice&) { abort(); }); - return grpc_core::Immediate(std::move(initial_metadata)); +// State held for a pending HTTP request. +class Oauth2TokenFetcherCredentials::HttpFetchRequest final + : public TokenFetcherCredentials::FetchRequest { + public: + HttpFetchRequest( + Oauth2TokenFetcherCredentials* creds, Timestamp deadline, + absl::AnyInvocable< + void(absl::StatusOr>)> + on_done) + : on_done_(std::move(on_done)) { + GRPC_CLOSURE_INIT(&on_http_response_, OnHttpResponse, this, nullptr); + Ref().release(); // Ref held by HTTP request callback. + http_request_ = creds->StartHttpRequest(creds->pollent(), deadline, + &response_, &on_http_response_); } - // Couldn't get the token from the cache. - // Add request to pending_requests_ and start a new fetch if needed. - grpc_core::Duration refresh_threshold = - grpc_core::Duration::Seconds(GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS); - auto pending_request = - grpc_core::MakeRefCounted(); - pending_request->pollent = grpc_core::GetContext(); - pending_request->waker = - grpc_core::GetContext()->MakeNonOwningWaker(); - grpc_polling_entity_add_to_pollset_set( - pending_request->pollent, grpc_polling_entity_pollset_set(&pollent_)); - pending_request->next = pending_requests_; - pending_request->md = std::move(initial_metadata); - pending_requests_ = pending_request->Ref().release(); - bool start_fetch = false; - if (!token_fetch_pending_) { - token_fetch_pending_ = true; - start_fetch = true; + + ~HttpFetchRequest() override { grpc_http_response_destroy(&response_); } + + void Orphan() override { + http_request_.reset(); + Unref(); } - gpr_mu_unlock(&mu_); - if (start_fetch) { - fetch_oauth2(new grpc_credentials_metadata_request(Ref()), &pollent_, - on_oauth2_token_fetcher_http_response, - grpc_core::Timestamp::Now() + refresh_threshold); + + private: + static void OnHttpResponse(void* arg, grpc_error_handle error) { + RefCountedPtr self(static_cast(arg)); + if (!error.ok()) { + self->on_done_(std::move(error)); + return; + } + // Parse oauth2 token. + absl::optional access_token_value; + Duration token_lifetime; + grpc_credentials_status status = + grpc_oauth2_token_fetcher_credentials_parse_server_response( + &self->response_, &access_token_value, &token_lifetime); + if (status != GRPC_CREDENTIALS_OK) { + self->on_done_(absl::UnavailableError("error parsing oauth2 token")); + return; + } + self->on_done_(MakeRefCounted(std::move(*access_token_value), + Timestamp::Now() + token_lifetime)); } - return - [pending_request]() - -> grpc_core::Poll> { - if (!pending_request->done.load(std::memory_order_acquire)) { - return grpc_core::Pending{}; - } - if (pending_request->result.ok()) { - pending_request->md->Append( - GRPC_AUTHORIZATION_METADATA_KEY, - std::move(*pending_request->result), - [](absl::string_view, const grpc_core::Slice&) { abort(); }); - return std::move(pending_request->md); - } else { - return pending_request->result.status(); - } - }; -} -grpc_oauth2_token_fetcher_credentials::grpc_oauth2_token_fetcher_credentials() - : token_expiration_(gpr_inf_past(GPR_CLOCK_MONOTONIC)), - pollent_(grpc_polling_entity_create_from_pollset_set( - grpc_pollset_set_create())) { - gpr_mu_init(&mu_); -} + OrphanablePtr http_request_; + grpc_closure on_http_response_; + grpc_http_response response_; + absl::AnyInvocable>)> + on_done_; +}; -std::string grpc_oauth2_token_fetcher_credentials::debug_string() { +std::string Oauth2TokenFetcherCredentials::debug_string() { return "OAuth2TokenFetcherCredentials"; } -grpc_core::UniqueTypeName grpc_oauth2_token_fetcher_credentials::type() const { - static grpc_core::UniqueTypeName::Factory kFactory("Oauth2"); +UniqueTypeName Oauth2TokenFetcherCredentials::type() const { + static UniqueTypeName::Factory kFactory("Oauth2"); return kFactory.Create(); } +OrphanablePtr +Oauth2TokenFetcherCredentials::FetchToken( + Timestamp deadline, + absl::AnyInvocable< + void(absl::StatusOr>)> + on_done) { + return MakeOrphanable(this, deadline, std::move(on_done)); +} + +} // namespace grpc_core + // // Google Compute Engine credentials. // @@ -373,16 +291,21 @@ grpc_core::UniqueTypeName grpc_oauth2_token_fetcher_credentials::type() const { namespace { class grpc_compute_engine_token_fetcher_credentials - : public grpc_oauth2_token_fetcher_credentials { + : public grpc_core::Oauth2TokenFetcherCredentials { public: grpc_compute_engine_token_fetcher_credentials() = default; ~grpc_compute_engine_token_fetcher_credentials() override = default; - protected: - void fetch_oauth2(grpc_credentials_metadata_request* metadata_req, - grpc_polling_entity* pollent, - grpc_iomgr_cb_func response_cb, - grpc_core::Timestamp deadline) override { + std::string debug_string() override { + return absl::StrFormat( + "GoogleComputeEngineTokenFetcherCredentials{%s}", + grpc_core::Oauth2TokenFetcherCredentials::debug_string()); + } + + private: + grpc_core::OrphanablePtr StartHttpRequest( + grpc_polling_entity* pollent, grpc_core::Timestamp deadline, + grpc_http_response* response, grpc_closure* on_complete) override { grpc_http_header header = {const_cast("Metadata-Flavor"), const_cast("Google")}; grpc_http_request request; @@ -396,26 +319,14 @@ class grpc_compute_engine_token_fetcher_credentials GRPC_COMPUTE_ENGINE_METADATA_TOKEN_PATH, {} /* query params */, "" /* fragment */); CHECK(uri.ok()); // params are hardcoded - http_request_ = grpc_core::HttpRequest::Get( - std::move(*uri), nullptr /* channel args */, pollent, &request, - deadline, - GRPC_CLOSURE_INIT(&http_get_cb_closure_, response_cb, metadata_req, - grpc_schedule_on_exec_ctx), - &metadata_req->response, + auto http_request = grpc_core::HttpRequest::Get( + std::move(*uri), /*args=*/nullptr, pollent, &request, deadline, + on_complete, response, grpc_core::RefCountedPtr( grpc_insecure_credentials_create())); - http_request_->Start(); - } - - std::string debug_string() override { - return absl::StrFormat( - "GoogleComputeEngineTokenFetcherCredentials{%s}", - grpc_oauth2_token_fetcher_credentials::debug_string()); + http_request->Start(); + return http_request; } - - private: - grpc_closure http_get_cb_closure_; - grpc_core::OrphanablePtr http_request_; }; } // namespace @@ -434,22 +345,26 @@ grpc_call_credentials* grpc_google_compute_engine_credentials_create( // Google Refresh Token credentials. // +grpc_google_refresh_token_credentials::grpc_google_refresh_token_credentials( + grpc_auth_refresh_token refresh_token) + : refresh_token_(refresh_token) {} + grpc_google_refresh_token_credentials:: ~grpc_google_refresh_token_credentials() { grpc_auth_refresh_token_destruct(&refresh_token_); } -void grpc_google_refresh_token_credentials::fetch_oauth2( - grpc_credentials_metadata_request* metadata_req, - grpc_polling_entity* pollent, grpc_iomgr_cb_func response_cb, - grpc_core::Timestamp deadline) { +grpc_core::OrphanablePtr +grpc_google_refresh_token_credentials::StartHttpRequest( + grpc_polling_entity* pollent, grpc_core::Timestamp deadline, + grpc_http_response* response, grpc_closure* on_complete) { grpc_http_header header = { const_cast("Content-Type"), const_cast("application/x-www-form-urlencoded")}; - grpc_http_request request; std::string body = absl::StrFormat( GRPC_REFRESH_TOKEN_POST_BODY_FORMAT_STRING, refresh_token_.client_id, refresh_token_.client_secret, refresh_token_.refresh_token); + grpc_http_request request; memset(&request, 0, sizeof(grpc_http_request)); request.hdr_count = 1; request.hdrs = &header; @@ -462,18 +377,13 @@ void grpc_google_refresh_token_credentials::fetch_oauth2( GRPC_GOOGLE_OAUTH2_SERVICE_TOKEN_PATH, {} /* query params */, "" /* fragment */); CHECK(uri.ok()); // params are hardcoded - http_request_ = grpc_core::HttpRequest::Post( - std::move(*uri), nullptr /* channel args */, pollent, &request, deadline, - GRPC_CLOSURE_INIT(&http_post_cb_closure_, response_cb, metadata_req, - grpc_schedule_on_exec_ctx), - &metadata_req->response, grpc_core::CreateHttpRequestSSLCredentials()); - http_request_->Start(); + auto http_request = grpc_core::HttpRequest::Post( + std::move(*uri), /*args=*/nullptr, pollent, &request, deadline, + on_complete, response, grpc_core::CreateHttpRequestSSLCredentials()); + http_request->Start(); + return http_request; } -grpc_google_refresh_token_credentials::grpc_google_refresh_token_credentials( - grpc_auth_refresh_token refresh_token) - : refresh_token_(refresh_token) {} - grpc_core::RefCountedPtr grpc_refresh_token_credentials_create_from_auth_refresh_token( grpc_auth_refresh_token refresh_token) { @@ -486,9 +396,9 @@ grpc_refresh_token_credentials_create_from_auth_refresh_token( } std::string grpc_google_refresh_token_credentials::debug_string() { - return absl::StrFormat("GoogleRefreshToken{ClientID:%s,%s}", - refresh_token_.client_id, - grpc_oauth2_token_fetcher_credentials::debug_string()); + return absl::StrFormat( + "GoogleRefreshToken{ClientID:%s,%s}", refresh_token_.client_id, + grpc_core::Oauth2TokenFetcherCredentials::debug_string()); } grpc_core::UniqueTypeName grpc_google_refresh_token_credentials::type() const { @@ -511,11 +421,10 @@ grpc_call_credentials* grpc_google_refresh_token_credentials_create( const char* json_refresh_token, void* reserved) { grpc_auth_refresh_token token = grpc_auth_refresh_token_create_from_string(json_refresh_token); - if (GRPC_TRACE_FLAG_ENABLED(api)) { - LOG(INFO) << "grpc_refresh_token_credentials_create(json_refresh_token=" - << create_loggable_refresh_token(&token) - << ", reserved=" << reserved << ")"; - } + GRPC_TRACE_LOG(api, INFO) + << "grpc_refresh_token_credentials_create(json_refresh_token=" + << create_loggable_refresh_token(&token) << ", reserved=" << reserved + << ")"; CHECK_EQ(reserved, nullptr); return grpc_refresh_token_credentials_create_from_auth_refresh_token(token) .release(); @@ -546,8 +455,7 @@ grpc_error_handle LoadTokenFile(const char* path, grpc_slice* token) { return absl::OkStatus(); } -class StsTokenFetcherCredentials - : public grpc_oauth2_token_fetcher_credentials { +class StsTokenFetcherCredentials : public Oauth2TokenFetcherCredentials { public: StsTokenFetcherCredentials(URI sts_url, const grpc_sts_credentials_options* options) @@ -564,21 +472,19 @@ class StsTokenFetcherCredentials std::string debug_string() override { return absl::StrFormat( "StsTokenFetcherCredentials{Path:%s,Authority:%s,%s}", sts_url_.path(), - sts_url_.authority(), - grpc_oauth2_token_fetcher_credentials::debug_string()); + sts_url_.authority(), Oauth2TokenFetcherCredentials::debug_string()); } private: - void fetch_oauth2(grpc_credentials_metadata_request* metadata_req, - grpc_polling_entity* pollent, - grpc_iomgr_cb_func response_cb, - Timestamp deadline) override { + OrphanablePtr StartHttpRequest( + grpc_polling_entity* pollent, Timestamp deadline, + grpc_http_response* response, grpc_closure* on_complete) override { grpc_http_request request; memset(&request, 0, sizeof(grpc_http_request)); grpc_error_handle err = FillBody(&request.body, &request.body_length); if (!err.ok()) { - response_cb(metadata_req, err); - return; + ExecCtx::Run(DEBUG_LOCATION, on_complete, std::move(err)); + return nullptr; } grpc_http_header header = { const_cast("Content-Type"), @@ -595,13 +501,12 @@ class StsTokenFetcherCredentials } else { http_request_creds = CreateHttpRequestSSLCredentials(); } - http_request_ = HttpRequest::Post( - sts_url_, nullptr /* channel args */, pollent, &request, deadline, - GRPC_CLOSURE_INIT(&http_post_cb_closure_, response_cb, metadata_req, - grpc_schedule_on_exec_ctx), - &metadata_req->response, std::move(http_request_creds)); - http_request_->Start(); + auto http_request = HttpRequest::Post( + sts_url_, /*args=*/nullptr, pollent, &request, deadline, on_complete, + response, std::move(http_request_creds)); + http_request->Start(); gpr_free(request.body); + return http_request; } grpc_error_handle FillBody(char** body, size_t* body_length) { @@ -647,7 +552,6 @@ class StsTokenFetcherCredentials } URI sts_url_; - grpc_closure http_post_cb_closure_; UniquePtr resource_; UniquePtr audience_; UniquePtr scope_; diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h index 199f35f33c..ea9315ba01 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h @@ -24,6 +24,7 @@ #include #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" #include "absl/types/optional.h" #include @@ -43,6 +44,7 @@ #include "src/core/lib/promise/activity.h" #include "src/core/lib/promise/arena_promise.h" #include "src/core/lib/security/credentials/credentials.h" +#include "src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.h" #include "src/core/lib/slice/slice.h" #include "src/core/lib/transport/transport.h" #include "src/core/lib/uri/uri_parser.h" @@ -80,73 +82,45 @@ grpc_auth_refresh_token grpc_auth_refresh_token_create_from_json( /// Destructs the object. void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token); -// -- Credentials Metadata Request. -- - -struct grpc_credentials_metadata_request { - explicit grpc_credentials_metadata_request( - grpc_core::RefCountedPtr creds) - : creds(std::move(creds)) {} - ~grpc_credentials_metadata_request() { - grpc_http_response_destroy(&response); - } - - grpc_core::RefCountedPtr creds; - grpc_http_response response; -}; - -struct grpc_oauth2_pending_get_request_metadata - : public grpc_core::RefCounted { - std::atomic done{false}; - grpc_core::Waker waker; - grpc_polling_entity* pollent; - grpc_core::ClientMetadataHandle md; - struct grpc_oauth2_pending_get_request_metadata* next; - absl::StatusOr result; -}; - // -- Oauth2 Token Fetcher credentials -- // // This object is a base for credentials that need to acquire an oauth2 token // from an http service. -class grpc_oauth2_token_fetcher_credentials : public grpc_call_credentials { - public: - grpc_oauth2_token_fetcher_credentials(); - ~grpc_oauth2_token_fetcher_credentials() override; - - grpc_core::ArenaPromise> - GetRequestMetadata(grpc_core::ClientMetadataHandle initial_metadata, - const GetRequestMetadataArgs* args) override; +namespace grpc_core { - void on_http_response(grpc_credentials_metadata_request* r, - grpc_error_handle error); +// A base class for oauth2 token fetching credentials. +// Subclasses must implement StartHttpRequest(). +class Oauth2TokenFetcherCredentials : public TokenFetcherCredentials { + public: std::string debug_string() override; - grpc_core::UniqueTypeName type() const override; + UniqueTypeName type() const override; + + OrphanablePtr FetchToken( + Timestamp deadline, + absl::AnyInvocable< + void(absl::StatusOr>)> + on_done) final; - protected: - virtual void fetch_oauth2(grpc_credentials_metadata_request* req, - grpc_polling_entity* pollent, grpc_iomgr_cb_func cb, - grpc_core::Timestamp deadline) = 0; + virtual OrphanablePtr StartHttpRequest( + grpc_polling_entity* pollent, Timestamp deadline, + grpc_http_response* response, grpc_closure* on_complete) = 0; private: + class HttpFetchRequest; + int cmp_impl(const grpc_call_credentials* other) const override { // TODO(yashykt): Check if we can do something better here - return grpc_core::QsortCompare( - static_cast(this), other); + return QsortCompare(static_cast(this), other); } - - gpr_mu mu_; - absl::optional access_token_value_; - gpr_timespec token_expiration_; - bool token_fetch_pending_ = false; - grpc_oauth2_pending_get_request_metadata* pending_requests_ = nullptr; - grpc_polling_entity pollent_; }; +} // namespace grpc_core + // Google refresh token credentials. class grpc_google_refresh_token_credentials final - : public grpc_oauth2_token_fetcher_credentials { + : public grpc_core::Oauth2TokenFetcherCredentials { public: explicit grpc_google_refresh_token_credentials( grpc_auth_refresh_token refresh_token); @@ -160,15 +134,12 @@ class grpc_google_refresh_token_credentials final grpc_core::UniqueTypeName type() const override; - protected: - void fetch_oauth2(grpc_credentials_metadata_request* req, - grpc_polling_entity* pollent, grpc_iomgr_cb_func cb, - grpc_core::Timestamp deadline) override; - private: + grpc_core::OrphanablePtr StartHttpRequest( + grpc_polling_entity* pollent, grpc_core::Timestamp deadline, + grpc_http_response* response, grpc_closure* on_complete) override; + grpc_auth_refresh_token refresh_token_; - grpc_closure http_post_cb_closure_; - grpc_core::OrphanablePtr http_request_; }; // Access token credentials. @@ -176,6 +147,8 @@ class grpc_access_token_credentials final : public grpc_call_credentials { public: explicit grpc_access_token_credentials(const char* access_token); + void Orphaned() override {} + grpc_core::ArenaPromise> GetRequestMetadata(grpc_core::ClientMetadataHandle initial_metadata, const GetRequestMetadataArgs* args) override; @@ -202,6 +175,11 @@ grpc_core::RefCountedPtr grpc_refresh_token_credentials_create_from_auth_refresh_token( grpc_auth_refresh_token token); +grpc_credentials_status +grpc_oauth2_token_fetcher_credentials_parse_server_response_body( + absl::string_view body, absl::optional* token_value, + grpc_core::Duration* token_lifetime); + // Exposed for testing only. grpc_credentials_status grpc_oauth2_token_fetcher_credentials_parse_server_response( diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index 9aed48de8b..8fa2bcc657 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -121,10 +121,9 @@ void grpc_plugin_credentials::PendingRequest::RequestMetadataReady( GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP); grpc_core::RefCountedPtr r( static_cast(request)); - if (GRPC_TRACE_FLAG_ENABLED(plugin_credentials)) { - LOG(INFO) << "plugin_credentials[" << r->creds() << "]: request " << r.get() - << ": plugin returned asynchronously"; - } + GRPC_TRACE_LOG(plugin_credentials, INFO) + << "plugin_credentials[" << r->creds() << "]: request " << r.get() + << ": plugin returned asynchronously"; for (size_t i = 0; i < num_md; ++i) { grpc_metadata p; p.key = grpc_core::CSliceRef(md[i].key); @@ -150,10 +149,9 @@ grpc_plugin_credentials::GetRequestMetadata( RefAsSubclass(), std::move(initial_metadata), args); // Invoke the plugin. The callback holds a ref to us. - if (GRPC_TRACE_FLAG_ENABLED(plugin_credentials)) { - LOG(INFO) << "plugin_credentials[" << this << "]: request " << request.get() - << ": invoking plugin"; - } + GRPC_TRACE_LOG(plugin_credentials, INFO) + << "plugin_credentials[" << this << "]: request " << request.get() + << ": invoking plugin"; grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX]; size_t num_creds_md = 0; grpc_status_code status = GRPC_STATUS_OK; @@ -168,17 +166,15 @@ grpc_plugin_credentials::GetRequestMetadata( child_request.get(), creds_md, &num_creds_md, &status, &error_details)) { child_request.release(); - if (GRPC_TRACE_FLAG_ENABLED(plugin_credentials)) { - LOG(INFO) << "plugin_credentials[" << this << "]: request " - << request.get() << ": plugin will return asynchronously"; - } + GRPC_TRACE_LOG(plugin_credentials, INFO) + << "plugin_credentials[" << this << "]: request " << request.get() + << ": plugin will return asynchronously"; return [request] { return request->PollAsyncResult(); }; } // Synchronous return. - if (GRPC_TRACE_FLAG_ENABLED(plugin_credentials)) { - LOG(INFO) << "plugin_credentials[" << this << "]: request " << request.get() - << ": plugin returned synchronously"; - } + GRPC_TRACE_LOG(plugin_credentials, INFO) + << "plugin_credentials[" << this << "]: request " << request.get() + << ": plugin returned synchronously"; auto result = request->ProcessPluginResult(creds_md, num_creds_md, status, error_details); // Clean up. diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.h b/src/core/lib/security/credentials/plugin/plugin_credentials.h index b1f6710af1..9cffc05b3d 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.h +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.h @@ -57,6 +57,8 @@ struct grpc_plugin_credentials final : public grpc_call_credentials { grpc_security_level min_security_level); ~grpc_plugin_credentials() override; + void Orphaned() override {} + grpc_core::ArenaPromise> GetRequestMetadata(grpc_core::ClientMetadataHandle initial_metadata, const GetRequestMetadataArgs* args) override; diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.h b/src/core/lib/security/credentials/ssl/ssl_credentials.h index 6651e50202..32c450de90 100644 --- a/src/core/lib/security/credentials/ssl/ssl_credentials.h +++ b/src/core/lib/security/credentials/ssl/ssl_credentials.h @@ -26,7 +26,6 @@ #include #include #include -#include #include #include "src/core/lib/channel/channel_args.h" diff --git a/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc b/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc index 8b02a5a444..2472244f2c 100644 --- a/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +++ b/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc @@ -21,7 +21,6 @@ #include #include -#include #include void grpc_tls_certificate_distributor::SetKeyMaterials( 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 d5908d974f..c3703cd56f 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 @@ -29,7 +29,6 @@ #include "absl/types/optional.h" #include -#include #include #include diff --git a/src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.cc b/src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.cc index a3bd89996f..f4c2c75bb4 100644 --- a/src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.cc +++ b/src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.cc @@ -25,7 +25,6 @@ #include "absl/strings/string_view.h" #include -#include #include #include 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 3cb2bba340..0c5c2e7f5a 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 @@ -27,7 +27,6 @@ #include #include #include -#include #include #include "src/core/lib/gprpp/ref_counted.h" diff --git a/src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.cc b/src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.cc new file mode 100644 index 0000000000..596641f0ff --- /dev/null +++ b/src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.cc @@ -0,0 +1,300 @@ +// +// +// Copyright 2015 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/security/credentials/token_fetcher/token_fetcher_credentials.h" + +#include "src/core/lib/debug/trace.h" +#include "src/core/lib/event_engine/default_event_engine.h" +#include "src/core/lib/iomgr/pollset_set.h" +#include "src/core/lib/promise/context.h" +#include "src/core/lib/promise/poll.h" +#include "src/core/lib/promise/promise.h" + +namespace grpc_core { + +namespace { + +// Amount of time before the token's expiration that we consider it +// invalid to account for server processing time and clock skew. +constexpr Duration kTokenExpirationAdjustmentDuration = Duration::Seconds(30); + +// Amount of time before the token's expiration that we pre-fetch a new +// token. Also determines the timeout for the fetch request. +constexpr Duration kTokenRefreshDuration = Duration::Seconds(60); + +} // namespace + +// +// TokenFetcherCredentials::Token +// + +TokenFetcherCredentials::Token::Token(Slice token, Timestamp expiration) + : token_(std::move(token)), + expiration_(expiration - kTokenExpirationAdjustmentDuration) {} + +void TokenFetcherCredentials::Token::AddTokenToClientInitialMetadata( + ClientMetadata& metadata) const { + metadata.Append(GRPC_AUTHORIZATION_METADATA_KEY, token_.Ref(), + [](absl::string_view, const Slice&) { abort(); }); +} + +// +// TokenFetcherCredentials::FetchState::BackoffTimer +// + +TokenFetcherCredentials::FetchState::BackoffTimer::BackoffTimer( + RefCountedPtr fetch_state) + : fetch_state_(std::move(fetch_state)) { + const Timestamp next_attempt_time = fetch_state_->backoff_.NextAttemptTime(); + const Duration duration = next_attempt_time - Timestamp::Now(); + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << fetch_state_->creds_.get() + << "]: fetch_state=" << fetch_state_.get() << " backoff_timer=" << this + << ": starting backoff timer for " << next_attempt_time << " (" + << duration << " from now)"; + timer_handle_ = fetch_state_->creds_->event_engine().RunAfter( + duration, [self = Ref()]() mutable { + ApplicationCallbackExecCtx callback_exec_ctx; + ExecCtx exec_ctx; + self->OnTimer(); + self.reset(); + }); +} + +void TokenFetcherCredentials::FetchState::BackoffTimer::Orphan() { + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << fetch_state_->creds_.get() + << "]: fetch_state=" << fetch_state_.get() << " backoff_timer=" << this + << ": backoff timer shut down"; + if (timer_handle_.has_value()) { + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << fetch_state_->creds_.get() + << "]: fetch_state=" << fetch_state_.get() << " backoff_timer=" << this + << ": cancelling timer"; + fetch_state_->creds_->event_engine().Cancel(*timer_handle_); + timer_handle_.reset(); + fetch_state_->ResumeQueuedCalls( + absl::CancelledError("credentials shutdown")); + } + Unref(); +} + +void TokenFetcherCredentials::FetchState::BackoffTimer::OnTimer() { + MutexLock lock(&fetch_state_->creds_->mu_); + if (!timer_handle_.has_value()) return; + timer_handle_.reset(); + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << fetch_state_->creds_.get() + << "]: fetch_state=" << fetch_state_.get() << " backoff_timer=" << this + << ": backoff timer fired"; + if (fetch_state_->queued_calls_.empty()) { + // If there are no pending calls when the timer fires, then orphan + // the FetchState object. Note that this drops the backoff state, + // but that's probably okay, because if we didn't have any pending + // calls during the backoff period, we probably won't see any + // immediately now either. + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << fetch_state_->creds_.get() + << "]: fetch_state=" << fetch_state_.get() << " backoff_timer=" << this + << ": no pending calls, clearing state"; + fetch_state_->creds_->fetch_state_.reset(); + } else { + // If there are pending calls, then start a new fetch attempt. + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << fetch_state_->creds_.get() + << "]: fetch_state=" << fetch_state_.get() << " backoff_timer=" << this + << ": starting new fetch attempt"; + fetch_state_->StartFetchAttempt(); + } +} + +// +// TokenFetcherCredentials::FetchState +// + +TokenFetcherCredentials::FetchState::FetchState( + WeakRefCountedPtr creds) + : creds_(std::move(creds)), + backoff_(BackOff::Options() + .set_initial_backoff(Duration::Seconds(1)) + .set_multiplier(1.6) + .set_jitter(creds_->test_only_use_backoff_jitter_ ? 0.2 : 0) + .set_max_backoff(Duration::Seconds(120))) { + StartFetchAttempt(); +} + +void TokenFetcherCredentials::FetchState::Orphan() { + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << creds_.get() + << "]: fetch_state=" << this << ": shutting down"; + // Cancels fetch or backoff timer, if any. + state_ = Shutdown{}; + Unref(); +} + +void TokenFetcherCredentials::FetchState::StartFetchAttempt() { + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << creds_.get() + << "]: fetch_state=" << this << ": starting fetch"; + state_ = creds_->FetchToken( + /*deadline=*/Timestamp::Now() + kTokenRefreshDuration, + [self = Ref()](absl::StatusOr> token) mutable { + self->TokenFetchComplete(std::move(token)); + }); +} + +void TokenFetcherCredentials::FetchState::TokenFetchComplete( + absl::StatusOr> token) { + MutexLock lock(&creds_->mu_); + // If we were shut down, clean up. + if (absl::holds_alternative(state_)) { + if (token.ok()) token = absl::CancelledError("credentials shutdown"); + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << creds_.get() + << "]: fetch_state=" << this + << ": shut down before fetch completed: " << token.status(); + ResumeQueuedCalls(std::move(token)); + return; + } + // If succeeded, update cache in creds object. + if (token.ok()) { + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << creds_.get() + << "]: fetch_state=" << this << ": token fetch succeeded"; + creds_->token_ = *token; + creds_->fetch_state_.reset(); // Orphan ourselves. + } else { + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << creds_.get() + << "]: fetch_state=" << this + << ": token fetch failed: " << token.status(); + // If failed, start backoff timer. + state_ = OrphanablePtr(new BackoffTimer(Ref())); + } + ResumeQueuedCalls(std::move(token)); +} + +void TokenFetcherCredentials::FetchState::ResumeQueuedCalls( + absl::StatusOr> token) { + // Invoke callbacks for all pending requests. + for (auto& queued_call : queued_calls_) { + queued_call->result = token; + queued_call->done.store(true, std::memory_order_release); + queued_call->waker.Wakeup(); + grpc_polling_entity_del_from_pollset_set( + queued_call->pollent, + grpc_polling_entity_pollset_set(&creds_->pollent_)); + } + queued_calls_.clear(); +} + +RefCountedPtr +TokenFetcherCredentials::FetchState::QueueCall( + ClientMetadataHandle initial_metadata) { + // Add call to pending list. + auto queued_call = MakeRefCounted(); + queued_call->waker = GetContext()->MakeNonOwningWaker(); + queued_call->pollent = GetContext(); + grpc_polling_entity_add_to_pollset_set( + queued_call->pollent, grpc_polling_entity_pollset_set(&creds_->pollent_)); + queued_call->md = std::move(initial_metadata); + queued_calls_.insert(queued_call); + return queued_call; +} + +// +// TokenFetcherCredentials +// + +TokenFetcherCredentials::TokenFetcherCredentials( + std::shared_ptr event_engine, + bool test_only_use_backoff_jitter) + : event_engine_( + event_engine == nullptr + ? grpc_event_engine::experimental::GetDefaultEventEngine() + : std::move(event_engine)), + test_only_use_backoff_jitter_(test_only_use_backoff_jitter), + pollent_(grpc_polling_entity_create_from_pollset_set( + grpc_pollset_set_create())) {} + +TokenFetcherCredentials::~TokenFetcherCredentials() { + grpc_pollset_set_destroy(grpc_polling_entity_pollset_set(&pollent_)); +} + +void TokenFetcherCredentials::Orphaned() { + MutexLock lock(&mu_); + fetch_state_.reset(); +} + +ArenaPromise> +TokenFetcherCredentials::GetRequestMetadata( + ClientMetadataHandle initial_metadata, const GetRequestMetadataArgs*) { + RefCountedPtr queued_call; + { + MutexLock lock(&mu_); + // If we don't have a cached token or the token is within the + // refresh duration, start a new fetch if there isn't a pending one. + if ((token_ == nullptr || (token_->ExpirationTime() - Timestamp::Now()) <= + kTokenRefreshDuration) && + fetch_state_ == nullptr) { + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << this + << "]: " << GetContext()->DebugTag() + << " triggering new token fetch"; + fetch_state_ = OrphanablePtr( + new FetchState(WeakRefAsSubclass())); + } + // If we have a cached non-expired token, use it. + if (token_ != nullptr && + (token_->ExpirationTime() - Timestamp::Now()) > Duration::Zero()) { + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << this + << "]: " << GetContext()->DebugTag() + << " using cached token"; + token_->AddTokenToClientInitialMetadata(*initial_metadata); + return Immediate(std::move(initial_metadata)); + } + // If we don't have a cached token, this call will need to be queued. + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << this + << "]: " << GetContext()->DebugTag() + << " no cached token; queuing call"; + queued_call = fetch_state_->QueueCall(std::move(initial_metadata)); + } + return [this, queued_call = std::move(queued_call)]() + -> Poll> { + if (!queued_call->done.load(std::memory_order_acquire)) { + return Pending{}; + } + if (!queued_call->result.ok()) { + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << this + << "]: " << GetContext()->DebugTag() + << " token fetch failed; failing call"; + return queued_call->result.status(); + } + GRPC_TRACE_LOG(token_fetcher_credentials, INFO) + << "[TokenFetcherCredentials " << this + << "]: " << GetContext()->DebugTag() + << " token fetch complete; resuming call"; + (*queued_call->result)->AddTokenToClientInitialMetadata(*queued_call->md); + return std::move(queued_call->md); + }; +} + +} // namespace grpc_core diff --git a/src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.h b/src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.h new file mode 100644 index 0000000000..c73d469234 --- /dev/null +++ b/src/core/lib/security/credentials/token_fetcher/token_fetcher_credentials.h @@ -0,0 +1,176 @@ +// +// Copyright 2016 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_SECURITY_CREDENTIALS_TOKEN_FETCHER_TOKEN_FETCHER_CREDENTIALS_H +#define GRPC_SRC_CORE_LIB_SECURITY_CREDENTIALS_TOKEN_FETCHER_TOKEN_FETCHER_CREDENTIALS_H + +#include +#include +#include + +#include "absl/container/flat_hash_set.h" +#include "absl/functional/any_invocable.h" +#include "absl/status/statusor.h" +#include "absl/types/variant.h" + +#include + +#include "src/core/lib/backoff/backoff.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" +#include "src/core/lib/gprpp/sync.h" +#include "src/core/lib/gprpp/time.h" +#include "src/core/lib/iomgr/polling_entity.h" +#include "src/core/lib/promise/arena_promise.h" +#include "src/core/lib/security/credentials/credentials.h" +#include "src/core/lib/transport/metadata.h" +#include "src/core/util/http_client/httpcli.h" +#include "src/core/util/useful.h" + +namespace grpc_core { + +// A base class for credentials that fetch tokens via an HTTP request. +// Subclasses must implement FetchToken(). +class TokenFetcherCredentials : public grpc_call_credentials { + public: + // Represents a token. + class Token : public RefCounted { + public: + Token(Slice token, Timestamp expiration); + + // Returns the token's expiration time. + Timestamp ExpirationTime() const { return expiration_; } + + // Adds the token to the call's client initial metadata. + void AddTokenToClientInitialMetadata(ClientMetadata& metadata) const; + + private: + Slice token_; + Timestamp expiration_; + }; + + ~TokenFetcherCredentials() override; + + void Orphaned() override; + + ArenaPromise> GetRequestMetadata( + ClientMetadataHandle initial_metadata, + const GetRequestMetadataArgs* args) override; + + protected: + // Base class for fetch requests. + class FetchRequest : public InternallyRefCounted {}; + + explicit TokenFetcherCredentials( + std::shared_ptr + event_engine = nullptr, + bool test_only_use_backoff_jitter = true); + + // Fetches a token. The on_done callback will be invoked when complete. + virtual OrphanablePtr FetchToken( + Timestamp deadline, + absl::AnyInvocable>)> + on_done) = 0; + + grpc_event_engine::experimental::EventEngine& event_engine() const { + return *event_engine_; + } + + grpc_polling_entity* pollent() { return &pollent_; } + + private: + // A call that is waiting for a token fetch request to complete. + struct QueuedCall : public RefCounted { + std::atomic done{false}; + Waker waker; + grpc_polling_entity* pollent; + ClientMetadataHandle md; + absl::StatusOr> result; + }; + + class FetchState : public InternallyRefCounted { + public: + explicit FetchState(WeakRefCountedPtr creds) + ABSL_EXCLUSIVE_LOCKS_REQUIRED(&TokenFetcherCredentials::mu_); + + // Disabling thread safety annotations, since Orphan() is called + // by OrpahanablePtr<>, which does not have the right lock + // annotations. + void Orphan() override ABSL_NO_THREAD_SAFETY_ANALYSIS; + + RefCountedPtr QueueCall(ClientMetadataHandle initial_metadata) + ABSL_EXCLUSIVE_LOCKS_REQUIRED(&TokenFetcherCredentials::mu_); + + private: + class BackoffTimer : public InternallyRefCounted { + public: + explicit BackoffTimer(RefCountedPtr fetch_state) + ABSL_EXCLUSIVE_LOCKS_REQUIRED(&TokenFetcherCredentials::mu_); + + // Disabling thread safety annotations, since Orphan() is called + // by OrpahanablePtr<>, which does not have the right lock + // annotations. + void Orphan() override ABSL_NO_THREAD_SAFETY_ANALYSIS; + + private: + void OnTimer(); + + RefCountedPtr fetch_state_; + absl::optional + timer_handle_ ABSL_GUARDED_BY(&TokenFetcherCredentials::mu_); + }; + + struct Shutdown {}; + + void StartFetchAttempt() + ABSL_EXCLUSIVE_LOCKS_REQUIRED(&TokenFetcherCredentials::mu_); + void TokenFetchComplete(absl::StatusOr> token); + void ResumeQueuedCalls(absl::StatusOr> token) + ABSL_EXCLUSIVE_LOCKS_REQUIRED(&TokenFetcherCredentials::mu_); + + WeakRefCountedPtr creds_; + // Pending token-fetch request or backoff timer, if any. + absl::variant, OrphanablePtr, + Shutdown> + state_ ABSL_GUARDED_BY(&TokenFetcherCredentials::mu_); + // Calls that are queued up waiting for the token. + absl::flat_hash_set> queued_calls_ + ABSL_GUARDED_BY(&TokenFetcherCredentials::mu_); + // Backoff state. + BackOff backoff_ ABSL_GUARDED_BY(&TokenFetcherCredentials::mu_); + }; + + int cmp_impl(const grpc_call_credentials* other) const override { + // TODO(yashykt): Check if we can do something better here + return QsortCompare(static_cast(this), other); + } + + std::shared_ptr event_engine_; + const bool test_only_use_backoff_jitter_; + + Mutex mu_; + // Cached token, if any. + RefCountedPtr token_ ABSL_GUARDED_BY(&mu_); + // Fetch state, if any. + OrphanablePtr fetch_state_ ABSL_GUARDED_BY(&mu_); + + grpc_polling_entity pollent_ ABSL_GUARDED_BY(&mu_); +}; + +} // namespace grpc_core + +#endif // GRPC_SRC_CORE_LIB_SECURITY_CREDENTIALS_TOKEN_FETCHER_TOKEN_FETCHER_CREDENTIALS_H diff --git a/src/core/lib/security/credentials/xds/xds_credentials.cc b/src/core/lib/security/credentials/xds/xds_credentials.cc index c2e5b925e6..a0e017498e 100644 --- a/src/core/lib/security/credentials/xds/xds_credentials.cc +++ b/src/core/lib/security/credentials/xds/xds_credentials.cc @@ -23,7 +23,6 @@ #include #include -#include #include #include "src/core/lib/channel/channel_args.h" 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 25f7bf736f..b83eda46ee 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 @@ -35,7 +35,6 @@ #include #include #include -#include #include #include diff --git a/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc b/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc index 97f3fff871..08e897bebc 100644 --- a/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc +++ b/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc @@ -23,7 +23,6 @@ #include "absl/log/check.h" #include -#include #include #include "src/core/handshaker/security/security_handshaker.h" 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 74e5b664c6..118f013c32 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 @@ -30,7 +30,6 @@ #include #include #include -#include #include "src/core/lib/security/security_connector/load_system_roots.h" #include "src/core/lib/slice/slice_internal.h" diff --git a/src/core/lib/security/transport/server_auth_filter.cc b/src/core/lib/security/transport/server_auth_filter.cc index 70fe059c98..5b332aa987 100644 --- a/src/core/lib/security/transport/server_auth_filter.cc +++ b/src/core/lib/security/transport/server_auth_filter.cc @@ -131,12 +131,10 @@ struct ServerAuthFilter::RunApplicationCode::State { ServerAuthFilter::RunApplicationCode::RunApplicationCode( ServerAuthFilter* filter, ClientMetadata& metadata) : state_(GetContext()->ManagedNew(metadata)) { - if (GRPC_TRACE_FLAG_ENABLED(call)) { - LOG(ERROR) << GetContext()->DebugTag() - << "[server-auth]: Delegate to application: filter=" << filter - << " this=" << this - << " auth_ctx=" << filter->auth_context_.get(); - } + GRPC_TRACE_LOG(call, ERROR) + << GetContext()->DebugTag() + << "[server-auth]: Delegate to application: filter=" << filter + << " this=" << this << " auth_ctx=" << filter->auth_context_.get(); filter->server_credentials_->auth_metadata_processor().process( filter->server_credentials_->auth_metadata_processor().state, filter->auth_context_.get(), state_->md.metadata, state_->md.count, diff --git a/src/core/lib/slice/percent_encoding.cc b/src/core/lib/slice/percent_encoding.cc index 8931f1d716..0d73ea3c06 100644 --- a/src/core/lib/slice/percent_encoding.cc +++ b/src/core/lib/slice/percent_encoding.cc @@ -25,7 +25,6 @@ #include "absl/log/check.h" -#include #include #include "src/core/lib/gprpp/bitset.h" diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc index f2d49e0bf4..c0143684df 100644 --- a/src/core/lib/slice/slice.cc +++ b/src/core/lib/slice/slice.cc @@ -26,7 +26,6 @@ #include #include -#include #include #include "src/core/lib/gprpp/memory.h" diff --git a/src/core/lib/slice/slice.h b/src/core/lib/slice/slice.h index 2dc1d4164c..88f9d76bcb 100644 --- a/src/core/lib/slice/slice.h +++ b/src/core/lib/slice/slice.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #include "src/core/lib/gprpp/debug_location.h" diff --git a/src/core/lib/slice/slice_buffer.cc b/src/core/lib/slice/slice_buffer.cc index 6ea05cbc15..3d07c32334 100644 --- a/src/core/lib/slice/slice_buffer.cc +++ b/src/core/lib/slice/slice_buffer.cc @@ -27,7 +27,6 @@ #include #include #include -#include #include #include "src/core/lib/slice/slice_internal.h" diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index 03d8fbe180..e0fe8bd7e9 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -29,7 +29,6 @@ #include "absl/strings/string_view.h" #include -#include #include #include "src/core/lib/gprpp/memory.h" diff --git a/src/core/lib/slice/slice_refcount.h b/src/core/lib/slice/slice_refcount.h index 7a60d8a322..71a6e85abe 100644 --- a/src/core/lib/slice/slice_refcount.h +++ b/src/core/lib/slice/slice_refcount.h @@ -46,17 +46,15 @@ struct grpc_slice_refcount { void Ref(grpc_core::DebugLocation location) { auto prev_refs = ref_.fetch_add(1, std::memory_order_relaxed); - if (GRPC_TRACE_FLAG_ENABLED(slice_refcount)) { - LOG(INFO).AtLocation(location.file(), location.line()) - << "REF " << this << " " << prev_refs << "->" << prev_refs + 1; - } + GRPC_TRACE_LOG(slice_refcount, INFO) + .AtLocation(location.file(), location.line()) + << "REF " << this << " " << prev_refs << "->" << prev_refs + 1; } void Unref(grpc_core::DebugLocation location) { auto prev_refs = ref_.fetch_sub(1, std::memory_order_acq_rel); - if (GRPC_TRACE_FLAG_ENABLED(slice_refcount)) { - LOG(INFO).AtLocation(location.file(), location.line()) - << "UNREF " << this << " " << prev_refs << "->" << prev_refs - 1; - } + GRPC_TRACE_LOG(slice_refcount, INFO) + .AtLocation(location.file(), location.line()) + << "UNREF " << this << " " << prev_refs << "->" << prev_refs - 1; if (prev_refs == 1) { destroyer_fn_(this); } diff --git a/src/core/lib/surface/byte_buffer_reader.cc b/src/core/lib/surface/byte_buffer_reader.cc index 2053bf3f8b..0516b852a9 100644 --- a/src/core/lib/surface/byte_buffer_reader.cc +++ b/src/core/lib/surface/byte_buffer_reader.cc @@ -25,7 +25,6 @@ #include #include #include -#include #include #include "src/core/lib/iomgr/exec_ctx.h" diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index c2db94ee4d..f8ee18a9f0 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -336,11 +336,9 @@ void Call::HandleCompressionAlgorithmDisabled( void Call::UpdateDeadline(Timestamp deadline) { ReleasableMutexLock lock(&deadline_mu_); - if (GRPC_TRACE_FLAG_ENABLED(call)) { - VLOG(2) << "[call " << this - << "] UpdateDeadline from=" << deadline_.ToString() - << " to=" << deadline.ToString(); - } + GRPC_TRACE_LOG(call, INFO) + << "[call " << this << "] UpdateDeadline from=" << deadline_.ToString() + << " to=" << deadline.ToString(); if (deadline >= deadline_) return; if (deadline < Timestamp::Now()) { lock.Release(); @@ -497,6 +495,13 @@ void grpc_call_tracer_set(grpc_call* call, return arena->SetContext(tracer); } +void grpc_call_tracer_set_and_manage(grpc_call* call, + grpc_core::ClientCallTracer* tracer) { + grpc_core::Arena* arena = grpc_call_get_arena(call); + arena->ManagedNew(tracer); + return arena->SetContext(tracer); +} + void* grpc_call_tracer_get(grpc_call* call) { grpc_core::Arena* arena = grpc_call_get_arena(call); auto* call_tracer = diff --git a/src/core/lib/surface/call.h b/src/core/lib/surface/call.h index 6da95634d5..99ab4af5c2 100644 --- a/src/core/lib/surface/call.h +++ b/src/core/lib/surface/call.h @@ -265,6 +265,16 @@ void grpc_call_log_batch(const char* file, int line, const grpc_op* ops, void grpc_call_tracer_set(grpc_call* call, grpc_core::ClientCallTracer* tracer); +// Sets call tracer on the call and manages its life by using the call's arena. +// When using this API, the tracer will be destroyed by grpc_call arena when +// grpc_call is about to be destroyed. The caller of this API SHOULD NOT +// manually destroy the tracer. This API is used by Python as a way of using +// Arena to manage the lifetime of the call tracer. Python needs this API +// because the tracer was created within a separate shared object library which +// doesn't have access to core functions like arena->ManagedNew<>. +void grpc_call_tracer_set_and_manage(grpc_call* call, + grpc_core::ClientCallTracer* tracer); + void* grpc_call_tracer_get(grpc_call* call); #define GRPC_CALL_LOG_BATCH(ops, nops) \ @@ -276,6 +286,15 @@ void* grpc_call_tracer_get(grpc_call* call); uint8_t grpc_call_is_client(grpc_call* call); +class ClientCallTracerWrapper { + public: + explicit ClientCallTracerWrapper(grpc_core::ClientCallTracer* tracer) + : tracer_(tracer) {} + + private: + std::unique_ptr tracer_; +}; + // Return an appropriate compression algorithm for the requested compression \a // level in the context of \a call. grpc_compression_algorithm grpc_call_compression_for_level( diff --git a/src/core/lib/surface/call_utils.h b/src/core/lib/surface/call_utils.h index a68fa4a569..3d5039ab4c 100644 --- a/src/core/lib/surface/call_utils.h +++ b/src/core/lib/surface/call_utils.h @@ -43,7 +43,6 @@ #include #include #include -#include #include #include diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index 3e19723838..577ab734ef 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -22,7 +22,6 @@ #include #include #include -#include #include #include "src/core/channelz/channel_trace.h" diff --git a/src/core/lib/surface/channel_create.cc b/src/core/lib/surface/channel_create.cc index 4f9eb9ad9e..ef0fd5ba2c 100644 --- a/src/core/lib/surface/channel_create.cc +++ b/src/core/lib/surface/channel_create.cc @@ -20,7 +20,6 @@ #include #include -#include #include #include "src/core/channelz/channelz.h" diff --git a/src/core/lib/surface/channel_init.h b/src/core/lib/surface/channel_init.h index 05dbdd9120..435d3cff30 100644 --- a/src/core/lib/surface/channel_init.h +++ b/src/core/lib/surface/channel_init.h @@ -30,7 +30,6 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" -#include #include #include "src/core/lib/channel/channel_args.h" diff --git a/src/core/lib/surface/client_call.cc b/src/core/lib/surface/client_call.cc index 42c40174b4..db329e66ff 100644 --- a/src/core/lib/surface/client_call.cc +++ b/src/core/lib/surface/client_call.cc @@ -41,7 +41,6 @@ #include #include #include -#include #include #include diff --git a/src/core/lib/surface/client_call.h b/src/core/lib/surface/client_call.h index 53c5487eab..484be4d13d 100644 --- a/src/core/lib/surface/client_call.h +++ b/src/core/lib/surface/client_call.h @@ -39,7 +39,6 @@ #include #include #include -#include #include #include diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 253a234265..35e2f29599 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -40,6 +40,7 @@ #include #include +#include "src/core/lib/event_engine/default_event_engine.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" @@ -317,7 +318,9 @@ struct cq_pluck_data { struct cq_callback_data { explicit cq_callback_data(grpc_completion_queue_functor* shutdown_callback) - : shutdown_callback(shutdown_callback) {} + : shutdown_callback(shutdown_callback), + event_engine(grpc_event_engine::experimental::GetDefaultEventEngine()) { + } ~cq_callback_data() { #ifndef NDEBUG @@ -338,6 +341,8 @@ struct cq_callback_data { /// A callback that gets invoked when the CQ completes shutdown grpc_completion_queue_functor* shutdown_callback; + + std::shared_ptr event_engine; }; } // namespace @@ -847,13 +852,22 @@ static void cq_end_op_for_callback( cq_finish_shutdown_callback(cq); } + auto* functor = static_cast(tag); + if (grpc_core::IsEventEngineApplicationCallbacksEnabled()) { + // Run the callback on EventEngine threads. + cqd->event_engine->Run( + [engine = cqd->event_engine, functor, ok = error.ok()]() { + grpc_core::ExecCtx exec_ctx; + (*functor->functor_run)(functor, ok); + }); + return; + } // If possible, schedule the callback onto an existing thread-local // ApplicationCallbackExecCtx, which is a work queue. This is possible for: // 1. The callback is internally-generated and there is an ACEC available // 2. The callback is marked inlineable and there is an ACEC available // 3. We are already running in a background poller thread (which always has // an ACEC available at the base of the stack). - auto* functor = static_cast(tag); if (((internal || functor->inlineable) && grpc_core::ApplicationCallbackExecCtx::Available()) || grpc_iomgr_is_any_background_poller_thread()) { @@ -1334,6 +1348,14 @@ static void cq_finish_shutdown_callback(grpc_completion_queue* cq) { CHECK(cqd->shutdown_called); cq->poller_vtable->shutdown(POLLSET_FROM_CQ(cq), &cq->pollset_shutdown_done); + + if (grpc_core::IsEventEngineApplicationCallbacksEnabled()) { + cqd->event_engine->Run([engine = cqd->event_engine, callback]() { + grpc_core::ExecCtx exec_ctx; + callback->functor_run(callback, /*true=*/1); + }); + return; + } if (grpc_iomgr_is_any_background_poller_thread()) { grpc_core::ApplicationCallbackExecCtx::Enqueue(callback, true); return; diff --git a/src/core/lib/surface/completion_queue_factory.cc b/src/core/lib/surface/completion_queue_factory.cc index 486cc5f00e..dae6695b71 100644 --- a/src/core/lib/surface/completion_queue_factory.cc +++ b/src/core/lib/surface/completion_queue_factory.cc @@ -21,7 +21,6 @@ #include "absl/log/check.h" #include -#include #include #include "src/core/lib/iomgr/exec_ctx.h" diff --git a/src/core/lib/surface/filter_stack_call.cc b/src/core/lib/surface/filter_stack_call.cc index 17d8fe2166..a3a6e3d7b6 100644 --- a/src/core/lib/surface/filter_stack_call.cc +++ b/src/core/lib/surface/filter_stack_call.cc @@ -533,15 +533,13 @@ void FilterStackCall::BatchControl::PostCompletion() { FilterStackCall* call = call_; grpc_error_handle error = batch_error_.get(); - if (IsCallStatusOverrideOnCancellationEnabled()) { - // On the client side, if final call status is already known (i.e if this op - // includes recv_trailing_metadata) and if the call status is known to be - // OK, then disregard the batch error to ensure call->receiving_buffer_ is - // not cleared. - if (op_.recv_trailing_metadata && call->is_client() && - call->status_error_.ok()) { - error = absl::OkStatus(); - } + // On the client side, if final call status is already known (i.e if this op + // includes recv_trailing_metadata) and if the call status is known to be + // OK, then disregard the batch error to ensure call->receiving_buffer_ is + // not cleared. + if (op_.recv_trailing_metadata && call->is_client() && + call->status_error_.ok()) { + error = absl::OkStatus(); } GRPC_TRACE_VLOG(call, 2) << "tag:" << completion_data_.notify_tag.tag diff --git a/src/core/lib/surface/filter_stack_call.h b/src/core/lib/surface/filter_stack_call.h index d3ad7f8b40..aa5d739d7a 100644 --- a/src/core/lib/surface/filter_stack_call.h +++ b/src/core/lib/surface/filter_stack_call.h @@ -41,7 +41,6 @@ #include #include #include -#include #include #include diff --git a/src/core/lib/surface/lame_client.cc b/src/core/lib/surface/lame_client.cc index e431024446..3ac1321b6c 100644 --- a/src/core/lib/surface/lame_client.cc +++ b/src/core/lib/surface/lame_client.cc @@ -27,7 +27,6 @@ #include #include #include -#include #include #include "src/core/lib/channel/channel_args.h" diff --git a/src/core/lib/surface/server_call.cc b/src/core/lib/surface/server_call.cc index 3eeddfca86..0ac9064bed 100644 --- a/src/core/lib/surface/server_call.cc +++ b/src/core/lib/surface/server_call.cc @@ -37,7 +37,6 @@ #include #include #include -#include #include #include diff --git a/src/core/lib/surface/server_call.h b/src/core/lib/surface/server_call.h index a4b27afd41..351ef21a35 100644 --- a/src/core/lib/surface/server_call.h +++ b/src/core/lib/surface/server_call.h @@ -42,7 +42,6 @@ #include #include #include -#include #include #include diff --git a/src/core/lib/surface/validate_metadata.h b/src/core/lib/surface/validate_metadata.h index 0607abd1e0..03d0893989 100644 --- a/src/core/lib/surface/validate_metadata.h +++ b/src/core/lib/surface/validate_metadata.h @@ -27,7 +27,6 @@ #include "absl/strings/string_view.h" #include -#include #include #include "src/core/lib/iomgr/error.h" diff --git a/src/core/lib/transport/bdp_estimator.cc b/src/core/lib/transport/bdp_estimator.cc index 29f9188a24..ed2176bea6 100644 --- a/src/core/lib/transport/bdp_estimator.cc +++ b/src/core/lib/transport/bdp_estimator.cc @@ -47,18 +47,16 @@ Timestamp BdpEstimator::CompletePing() { 1e-9 * static_cast(dt_ts.tv_nsec); double bw = dt > 0 ? (static_cast(accumulator_) / dt) : 0; Duration start_inter_ping_delay = inter_ping_delay_; - if (GRPC_TRACE_FLAG_ENABLED(bdp_estimator)) { - LOG(INFO) << "bdp[" << name_ << "]:complete acc=" << accumulator_ - << " est=" << estimate_ << " dt=" << dt << " bw=" << bw / 125000.0 - << "Mbs bw_est=" << bw_est_ / 125000.0 << "Mbs"; - } + GRPC_TRACE_LOG(bdp_estimator, INFO) + << "bdp[" << name_ << "]:complete acc=" << accumulator_ + << " est=" << estimate_ << " dt=" << dt << " bw=" << bw / 125000.0 + << "Mbs bw_est=" << bw_est_ / 125000.0 << "Mbs"; CHECK(ping_state_ == PingState::STARTED); if (accumulator_ > 2 * estimate_ / 3 && bw > bw_est_) { estimate_ = std::max(accumulator_, estimate_ * 2); bw_est_ = bw; - if (GRPC_TRACE_FLAG_ENABLED(bdp_estimator)) { - LOG(INFO) << "bdp[" << name_ << "]: estimate increased to " << estimate_; - } + GRPC_TRACE_LOG(bdp_estimator, INFO) + << "bdp[" << name_ << "]: estimate increased to " << estimate_; inter_ping_delay_ /= 2; // if the ping estimate changes, // exponentially get faster at probing } else if (inter_ping_delay_ < Duration::Seconds(10)) { @@ -71,10 +69,9 @@ Timestamp BdpEstimator::CompletePing() { } if (start_inter_ping_delay != inter_ping_delay_) { stable_estimate_count_ = 0; - if (GRPC_TRACE_FLAG_ENABLED(bdp_estimator)) { - LOG(INFO) << "bdp[" << name_ << "]:update_inter_time to " - << inter_ping_delay_.millis() << "ms"; - } + GRPC_TRACE_LOG(bdp_estimator, INFO) + << "bdp[" << name_ << "]:update_inter_time to " + << inter_ping_delay_.millis() << "ms"; } ping_state_ = PingState::UNSCHEDULED; accumulator_ = 0; diff --git a/src/core/lib/transport/bdp_estimator.h b/src/core/lib/transport/bdp_estimator.h index d219a90900..e9fb28ccee 100644 --- a/src/core/lib/transport/bdp_estimator.h +++ b/src/core/lib/transport/bdp_estimator.h @@ -49,10 +49,9 @@ class BdpEstimator { // grpc_bdp_estimator_add_incoming_bytes once a ping has been scheduled by a // transport (but not necessarily started) void SchedulePing() { - if (GRPC_TRACE_FLAG_ENABLED(bdp_estimator)) { - LOG(INFO) << "bdp[" << name_ << "]:sched acc=" << accumulator_ - << " est=" << estimate_; - } + GRPC_TRACE_LOG(bdp_estimator, INFO) + << "bdp[" << name_ << "]:sched acc=" << accumulator_ + << " est=" << estimate_; CHECK(ping_state_ == PingState::UNSCHEDULED); ping_state_ = PingState::SCHEDULED; accumulator_ = 0; @@ -62,10 +61,9 @@ class BdpEstimator { // once // the ping is on the wire void StartPing() { - if (GRPC_TRACE_FLAG_ENABLED(bdp_estimator)) { - LOG(INFO) << "bdp[" << name_ << "]:start acc=" << accumulator_ - << " est=" << estimate_; - } + GRPC_TRACE_LOG(bdp_estimator, INFO) + << "bdp[" << name_ << "]:start acc=" << accumulator_ + << " est=" << estimate_; CHECK(ping_state_ == PingState::SCHEDULED); ping_state_ = PingState::STARTED; ping_start_time_ = gpr_now(GPR_CLOCK_MONOTONIC); diff --git a/src/core/lib/transport/call_filters.cc b/src/core/lib/transport/call_filters.cc index 7d0cadf0bc..0e378a86d0 100644 --- a/src/core/lib/transport/call_filters.cc +++ b/src/core/lib/transport/call_filters.cc @@ -188,10 +188,9 @@ void CallFilters::Finalize(const grpc_call_final_info* final_info) { void CallFilters::CancelDueToFailedPipeOperation(SourceLocation but_where) { // We expect something cancelled before now if (push_server_trailing_metadata_ == nullptr) return; - if (GRPC_TRACE_FLAG_ENABLED(promise_primitives)) { - VLOG(2).AtLocation(but_where.file(), but_where.line()) - << "Cancelling due to failed pipe operation: " << DebugString(); - } + GRPC_TRACE_VLOG(promise_primitives, 2) + .AtLocation(but_where.file(), but_where.line()) + << "Cancelling due to failed pipe operation: " << DebugString(); auto status = ServerMetadataFromStatus(GRPC_STATUS_CANCELLED, "Failed pipe operation"); status->Set(GrpcCallWasCancelled(), true); @@ -200,11 +199,9 @@ void CallFilters::CancelDueToFailedPipeOperation(SourceLocation but_where) { void CallFilters::PushServerTrailingMetadata(ServerMetadataHandle md) { CHECK(md != nullptr); - if (GRPC_TRACE_FLAG_ENABLED(call)) { - LOG(INFO) << GetContext()->DebugTag() - << " PushServerTrailingMetadata[" << this - << "]: " << md->DebugString() << " into " << DebugString(); - } + GRPC_TRACE_LOG(call, INFO) + << GetContext()->DebugTag() << " PushServerTrailingMetadata[" + << this << "]: " << md->DebugString() << " into " << DebugString(); CHECK(md != nullptr); if (call_state_.PushServerTrailingMetadata( md->get(GrpcCallWasCancelled()).value_or(false))) { diff --git a/src/core/lib/transport/call_spine.h b/src/core/lib/transport/call_spine.h index 4b3d9c6993..99944b301f 100644 --- a/src/core/lib/transport/call_spine.h +++ b/src/core/lib/transport/call_spine.h @@ -17,7 +17,6 @@ #include "absl/log/check.h" -#include #include #include "src/core/lib/gprpp/dual_ref_counted.h" @@ -51,23 +50,24 @@ class CallSpine final : public Party { std::move(client_initial_metadata), std::move(arena))); } - ~CallSpine() override {} + ~CallSpine() override { CallOnDone(true); } CallFilters& call_filters() { return call_filters_; } // Add a callback to be called when server trailing metadata is received. - void OnDone(absl::AnyInvocable fn) { + void OnDone(absl::AnyInvocable fn) { if (on_done_ == nullptr) { on_done_ = std::move(fn); return; } - on_done_ = [first = std::move(fn), next = std::move(on_done_)]() mutable { - first(); - next(); + on_done_ = [first = std::move(fn), + next = std::move(on_done_)](bool cancelled) mutable { + first(cancelled); + next(cancelled); }; } - void CallOnDone() { - if (on_done_ != nullptr) std::exchange(on_done_, nullptr)(); + void CallOnDone(bool cancelled) { + if (on_done_ != nullptr) std::exchange(on_done_, nullptr)(cancelled); } auto PullServerInitialMetadata() { @@ -75,7 +75,12 @@ class CallSpine final : public Party { } auto PullServerTrailingMetadata() { - return call_filters().PullServerTrailingMetadata(); + return Map( + call_filters().PullServerTrailingMetadata(), + [this](ServerMetadataHandle result) { + CallOnDone(result->get(GrpcCallWasCancelled()).value_or(false)); + return result; + }); } auto PushClientToServerMessage(MessageHandle message) { @@ -190,7 +195,7 @@ class CallSpine final : public Party { // Call filters/pipes part of the spine CallFilters call_filters_; - absl::AnyInvocable on_done_{nullptr}; + absl::AnyInvocable on_done_{nullptr}; }; class CallInitiator { @@ -227,7 +232,9 @@ class CallInitiator { spine_->PushServerTrailingMetadata(std::move(status)); } - void OnDone(absl::AnyInvocable fn) { spine_->OnDone(std::move(fn)); } + void OnDone(absl::AnyInvocable fn) { + spine_->OnDone(std::move(fn)); + } template void SpawnGuarded(absl::string_view name, PromiseFactory promise_factory) { @@ -274,7 +281,9 @@ class CallHandler { spine_->PushServerTrailingMetadata(std::move(status)); } - void OnDone(absl::AnyInvocable fn) { spine_->OnDone(std::move(fn)); } + void OnDone(absl::AnyInvocable fn) { + spine_->OnDone(std::move(fn)); + } template auto CancelIfFails(Promise promise) { @@ -327,7 +336,9 @@ class UnstartedCallHandler { spine_->PushServerTrailingMetadata(std::move(status)); } - void OnDone(absl::AnyInvocable fn) { spine_->OnDone(std::move(fn)); } + void OnDone(absl::AnyInvocable fn) { + spine_->OnDone(std::move(fn)); + } template auto CancelIfFails(Promise promise) { diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index 8e4bb0be08..503ff1f7ea 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -72,12 +72,11 @@ class AsyncConnectivityStateWatcherInterface::Notifier { private: static void SendNotification(void* arg, grpc_error_handle /*ignored*/) { Notifier* self = static_cast(arg); - if (GRPC_TRACE_FLAG_ENABLED(connectivity_state)) { - LOG(INFO) << "watcher " << self->watcher_.get() - << ": delivering async notification for " - << ConnectivityStateName(self->state_) << " (" - << self->status_.ToString() << ")"; - } + GRPC_TRACE_LOG(connectivity_state, INFO) + << "watcher " << self->watcher_.get() + << ": delivering async notification for " + << ConnectivityStateName(self->state_) << " (" + << self->status_.ToString() << ")"; self->watcher_->OnConnectivityStateChange(self->state_, self->status_); delete self; } @@ -104,12 +103,11 @@ ConnectivityStateTracker::~ConnectivityStateTracker() { state_.load(std::memory_order_relaxed); if (current_state == GRPC_CHANNEL_SHUTDOWN) return; for (const auto& p : watchers_) { - if (GRPC_TRACE_FLAG_ENABLED(connectivity_state)) { - LOG(INFO) << "ConnectivityStateTracker " << name_ << "[" << this - << "]: notifying watcher " << p.first << ": " - << ConnectivityStateName(current_state) << " -> " - << ConnectivityStateName(GRPC_CHANNEL_SHUTDOWN); - } + GRPC_TRACE_LOG(connectivity_state, INFO) + << "ConnectivityStateTracker " << name_ << "[" << this + << "]: notifying watcher " << p.first << ": " + << ConnectivityStateName(current_state) << " -> " + << ConnectivityStateName(GRPC_CHANNEL_SHUTDOWN); p.second->Notify(GRPC_CHANNEL_SHUTDOWN, absl::Status()); } } @@ -117,19 +115,17 @@ ConnectivityStateTracker::~ConnectivityStateTracker() { void ConnectivityStateTracker::AddWatcher( grpc_connectivity_state initial_state, OrphanablePtr watcher) { - if (GRPC_TRACE_FLAG_ENABLED(connectivity_state)) { - LOG(INFO) << "ConnectivityStateTracker " << name_ << "[" << this - << "]: add watcher " << watcher.get(); - } + GRPC_TRACE_LOG(connectivity_state, INFO) + << "ConnectivityStateTracker " << name_ << "[" << this + << "]: add watcher " << watcher.get(); grpc_connectivity_state current_state = state_.load(std::memory_order_relaxed); if (initial_state != current_state) { - if (GRPC_TRACE_FLAG_ENABLED(connectivity_state)) { - LOG(INFO) << "ConnectivityStateTracker " << name_ << "[" << this - << "]: notifying watcher " << watcher.get() << ": " - << ConnectivityStateName(initial_state) << " -> " - << ConnectivityStateName(current_state); - } + GRPC_TRACE_LOG(connectivity_state, INFO) + << "ConnectivityStateTracker " << name_ << "[" << this + << "]: notifying watcher " << watcher.get() << ": " + << ConnectivityStateName(initial_state) << " -> " + << ConnectivityStateName(current_state); watcher->Notify(current_state, status_); } // If we're in state SHUTDOWN, don't add the watcher, so that it will @@ -141,10 +137,9 @@ void ConnectivityStateTracker::AddWatcher( void ConnectivityStateTracker::RemoveWatcher( ConnectivityStateWatcherInterface* watcher) { - if (GRPC_TRACE_FLAG_ENABLED(connectivity_state)) { - LOG(INFO) << "ConnectivityStateTracker " << name_ << "[" << this - << "]: remove watcher " << watcher; - } + GRPC_TRACE_LOG(connectivity_state, INFO) + << "ConnectivityStateTracker " << name_ << "[" << this + << "]: remove watcher " << watcher; watchers_.erase(watcher); } @@ -154,21 +149,19 @@ void ConnectivityStateTracker::SetState(grpc_connectivity_state state, grpc_connectivity_state current_state = state_.load(std::memory_order_relaxed); if (state == current_state) return; - if (GRPC_TRACE_FLAG_ENABLED(connectivity_state)) { - LOG(INFO) << "ConnectivityStateTracker " << name_ << "[" << this - << "]: " << ConnectivityStateName(current_state) << " -> " - << ConnectivityStateName(state) << " (" << reason << ", " - << status.ToString() << ")"; - } + GRPC_TRACE_LOG(connectivity_state, INFO) + << "ConnectivityStateTracker " << name_ << "[" << this + << "]: " << ConnectivityStateName(current_state) << " -> " + << ConnectivityStateName(state) << " (" << reason << ", " + << status.ToString() << ")"; state_.store(state, std::memory_order_relaxed); status_ = status; for (const auto& p : watchers_) { - if (GRPC_TRACE_FLAG_ENABLED(connectivity_state)) { - LOG(INFO) << "ConnectivityStateTracker " << name_ << "[" << this - << "]: notifying watcher " << p.first << ": " - << ConnectivityStateName(current_state) << " -> " - << ConnectivityStateName(state); - } + GRPC_TRACE_LOG(connectivity_state, INFO) + << "ConnectivityStateTracker " << name_ << "[" << this + << "]: notifying watcher " << p.first << ": " + << ConnectivityStateName(current_state) << " -> " + << ConnectivityStateName(state); p.second->Notify(state, status); } // If the new state is SHUTDOWN, orphan all of the watchers. This @@ -178,10 +171,9 @@ void ConnectivityStateTracker::SetState(grpc_connectivity_state state, grpc_connectivity_state ConnectivityStateTracker::state() const { grpc_connectivity_state state = state_.load(std::memory_order_relaxed); - if (GRPC_TRACE_FLAG_ENABLED(connectivity_state)) { - LOG(INFO) << "ConnectivityStateTracker " << name_ << "[" << this - << "]: get current state: " << ConnectivityStateName(state); - } + GRPC_TRACE_LOG(connectivity_state, INFO) + << "ConnectivityStateTracker " << name_ << "[" << this + << "]: get current state: " << ConnectivityStateName(state); return state; } diff --git a/src/core/lib/transport/metadata_batch.h b/src/core/lib/transport/metadata_batch.h index 3d7779113a..6ede60d480 100644 --- a/src/core/lib/transport/metadata_batch.h +++ b/src/core/lib/transport/metadata_batch.h @@ -36,7 +36,6 @@ #include #include -#include #include #include "src/core/lib/compression/compression_internal.h" @@ -1052,6 +1051,26 @@ struct LogWrapper { } }; +// Callable for the table FilterIn -- for each value, call the +// appropriate filter method to determine of the value should be kept or +// removed. +template +struct FilterWrapper { + Filterer filter_fn; + + template ::value, bool> = true> + bool operator()(const Value& /*which*/) { + return filter_fn(Which()); + } + + template ::value, bool> = true> + bool operator()(const Value& /*which*/) { + return true; + } +}; + // Encoder to compute TransportSize class TransportSizeEncoder { public: @@ -1094,6 +1113,16 @@ class UnknownMap { BackingType::const_iterator begin() const { return unknown_.cbegin(); } BackingType::const_iterator end() const { return unknown_.cend(); } + template + void Filter(Filterer* filter_fn) { + unknown_.erase( + std::remove_if(unknown_.begin(), unknown_.end(), + [&](auto& pair) { + return !(*filter_fn)(pair.first.as_string_view()); + }), + unknown_.end()); + } + bool empty() const { return unknown_.empty(); } size_t size() const { return unknown_.size(); } void Clear() { unknown_.clear(); } @@ -1314,6 +1343,17 @@ class MetadataMap { } } + // Filter the metadata map. + // Iterates over all encodable and unknown headers and calls the filter_fn + // for each of them. If the function returns true, the header is kept. + template + void Filter(Filterer filter_fn) { + table_.template FilterIn, + Value...>( + metadata_detail::FilterWrapper{filter_fn}); + unknown_.Filter(&filter_fn); + } + std::string DebugString() const { metadata_detail::DebugStringBuilder builder; Log([&builder](absl::string_view key, absl::string_view value) { diff --git a/src/core/lib/transport/timeout_encoding.cc b/src/core/lib/transport/timeout_encoding.cc index deb82cb2cd..57621d835c 100644 --- a/src/core/lib/transport/timeout_encoding.cc +++ b/src/core/lib/transport/timeout_encoding.cc @@ -23,7 +23,6 @@ #include "absl/base/attributes.h" #include "absl/log/check.h" -#include #include #include diff --git a/src/core/lib/transport/transport.h b/src/core/lib/transport/transport.h index fa32ce2aed..4c16314558 100644 --- a/src/core/lib/transport/transport.h +++ b/src/core/lib/transport/transport.h @@ -190,10 +190,9 @@ void grpc_stream_ref_init(grpc_stream_refcount* refcount, int initial_refs, #ifndef NDEBUG inline void grpc_stream_ref(grpc_stream_refcount* refcount, const char* reason) { - if (GRPC_TRACE_FLAG_ENABLED(stream_refcount)) { - VLOG(2) << refcount->object_type << " " << refcount << ":" - << refcount->destroy.cb_arg << " REF " << reason; - } + GRPC_TRACE_VLOG(stream_refcount, 2) + << refcount->object_type << " " << refcount << ":" + << refcount->destroy.cb_arg << " REF " << reason; refcount->refs.RefNonZero(DEBUG_LOCATION, reason); } #else @@ -207,10 +206,9 @@ void grpc_stream_destroy(grpc_stream_refcount* refcount); #ifndef NDEBUG inline void grpc_stream_unref(grpc_stream_refcount* refcount, const char* reason) { - if (GRPC_TRACE_FLAG_ENABLED(stream_refcount)) { - VLOG(2) << refcount->object_type << " " << refcount << ":" - << refcount->destroy.cb_arg << " UNREF " << reason; - } + GRPC_TRACE_VLOG(stream_refcount, 2) + << refcount->object_type << " " << refcount << ":" + << refcount->destroy.cb_arg << " UNREF " << reason; if (GPR_UNLIKELY(refcount->refs.Unref(DEBUG_LOCATION, reason))) { grpc_stream_destroy(refcount); } diff --git a/src/core/lib/transport/transport_op_string.cc b/src/core/lib/transport/transport_op_string.cc index 0922233753..40ea5bc2d8 100644 --- a/src/core/lib/transport/transport_op_string.cc +++ b/src/core/lib/transport/transport_op_string.cc @@ -22,7 +22,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" -#include #include #include "src/core/lib/channel/channel_fwd.h" diff --git a/src/core/lib/uri/uri_parser.cc b/src/core/lib/uri/uri_parser.cc index dfb71286c4..95d9266319 100644 --- a/src/core/lib/uri/uri_parser.cc +++ b/src/core/lib/uri/uri_parser.cc @@ -36,7 +36,6 @@ #include "absl/strings/str_split.h" #include "absl/strings/strip.h" -#include #include namespace grpc_core { diff --git a/src/core/load_balancing/grpclb/grpclb.cc b/src/core/load_balancing/grpclb/grpclb.cc index 57eed1dcc6..d91812d959 100644 --- a/src/core/load_balancing/grpclb/grpclb.cc +++ b/src/core/load_balancing/grpclb/grpclb.cc @@ -851,14 +851,12 @@ void GrpcLb::Helper::UpdateState(grpc_connectivity_state state, parent()->lb_calld_->client_stats() != nullptr) { client_stats = parent()->lb_calld_->client_stats()->Ref(); } - if (GRPC_TRACE_FLAG_ENABLED(glb)) { - GRPC_TRACE_LOG(glb, INFO) - << "[grpclb " << parent() << " helper " << this - << "] state=" << ConnectivityStateName(state) << " (" - << status.ToString() << ") wrapping child picker " << picker.get() - << " (serverlist=" << serverlist.get() - << ", client_stats=" << client_stats.get() << ")"; - } + GRPC_TRACE_LOG(glb, INFO) + << "[grpclb " << parent() << " helper " << this + << "] state=" << ConnectivityStateName(state) << " (" << status.ToString() + << ") wrapping child picker " << picker.get() + << " (serverlist=" << serverlist.get() + << ", client_stats=" << client_stats.get() << ")"; parent()->channel_control_helper()->UpdateState( state, status, MakeRefCounted(std::move(serverlist), std::move(picker), @@ -948,10 +946,9 @@ void GrpcLb::BalancerCallState::Orphan() { void GrpcLb::BalancerCallState::StartQuery() { CHECK_NE(lb_call_, nullptr); - if (GRPC_TRACE_FLAG_ENABLED(glb)) { - LOG(INFO) << "[grpclb " << grpclb_policy_.get() << "] lb_calld=" << this - << ": Starting LB call " << lb_call_; - } + GRPC_TRACE_LOG(glb, INFO) + << "[grpclb " << grpclb_policy_.get() << "] lb_calld=" << this + << ": Starting LB call " << lb_call_; // Create the ops. grpc_call_error call_error; grpc_op ops[3]; @@ -1175,17 +1172,16 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked() { if (response.client_stats_report_interval != Duration::Zero()) { client_stats_report_interval_ = std::max( Duration::Seconds(1), response.client_stats_report_interval); - if (GRPC_TRACE_FLAG_ENABLED(glb)) { - LOG(INFO) << "[grpclb " << grpclb_policy() << "] lb_calld=" << this - << ": Received initial LB response message; client load " - "reporting interval = " - << client_stats_report_interval_.millis() - << " milliseconds"; - } - } else if (GRPC_TRACE_FLAG_ENABLED(glb)) { - LOG(INFO) << "[grpclb " << grpclb_policy() << "] lb_calld=" << this - << ": Received initial LB response message; client load " - "reporting NOT enabled"; + GRPC_TRACE_LOG(glb, INFO) + << "[grpclb " << grpclb_policy() << "] lb_calld=" << this + << ": Received initial LB response message; client load " + "reporting interval = " + << client_stats_report_interval_.millis() << " milliseconds"; + } else { + GRPC_TRACE_LOG(glb, INFO) + << "[grpclb " << grpclb_policy() << "] lb_calld=" << this + << ": Received initial LB response message; client load " + "reporting NOT enabled"; } seen_initial_response_ = true; break; @@ -1194,13 +1190,11 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked() { CHECK_NE(lb_call_, nullptr); auto serverlist_wrapper = MakeRefCounted(std::move(response.serverlist)); - if (GRPC_TRACE_FLAG_ENABLED(glb)) { - LOG(INFO) << "[grpclb " << grpclb_policy() << "] lb_calld=" << this - << ": Serverlist with " - << serverlist_wrapper->serverlist().size() - << " servers received:\n" - << serverlist_wrapper->AsText(); - } + GRPC_TRACE_LOG(glb, INFO) + << "[grpclb " << grpclb_policy() << "] lb_calld=" << this + << ": Serverlist with " << serverlist_wrapper->serverlist().size() + << " servers received:\n" + << serverlist_wrapper->AsText(); seen_serverlist_ = true; // Start sending client load report only after we start using the // serverlist returned from the current LB call. @@ -1214,11 +1208,10 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked() { // Check if the serverlist differs from the previous one. if (grpclb_policy()->serverlist_ != nullptr && *grpclb_policy()->serverlist_ == *serverlist_wrapper) { - if (GRPC_TRACE_FLAG_ENABLED(glb)) { - LOG(INFO) << "[grpclb " << grpclb_policy() << "] lb_calld=" << this - << ": Incoming server list identical to current, " - "ignoring."; - } + GRPC_TRACE_LOG(glb, INFO) + << "[grpclb " << grpclb_policy() << "] lb_calld=" << this + << ": Incoming server list identical to current, " + "ignoring."; } else { // New serverlist. // Dispose of the fallback. // TODO(roth): Ideally, we should stay in fallback mode until we @@ -1458,11 +1451,10 @@ GrpcLb::GrpcLb(Args args) GRPC_ARG_GRPCLB_SUBCHANNEL_CACHE_INTERVAL_MS) .value_or(Duration::Milliseconds( GRPC_GRPCLB_DEFAULT_SUBCHANNEL_DELETION_DELAY_MS)))) { - if (GRPC_TRACE_FLAG_ENABLED(glb)) { - LOG(INFO) << "[grpclb " << this << "] Will use '" - << std::string(channel_control_helper()->GetAuthority()) - << "' as the server name for LB request."; - } + GRPC_TRACE_LOG(glb, INFO) + << "[grpclb " << this << "] Will use '" + << std::string(channel_control_helper()->GetAuthority()) + << "' as the server name for LB request."; } void GrpcLb::ShutdownLocked() { @@ -1527,10 +1519,9 @@ class GrpcLb::NullLbTokenEndpointIterator final void ForEach(absl::FunctionRef callback) const override { parent_it_->ForEach([&](const EndpointAddresses& endpoint) { - if (GRPC_TRACE_FLAG_ENABLED(glb)) { - LOG(INFO) << "[grpclb " << this - << "] fallback address: " << endpoint.ToString(); - } + GRPC_TRACE_LOG(glb, INFO) + << "[grpclb " << this + << "] fallback address: " << endpoint.ToString(); callback(EndpointAddresses(endpoint.addresses(), endpoint.args().SetObject(empty_token_))); }); @@ -1544,9 +1535,7 @@ class GrpcLb::NullLbTokenEndpointIterator final }; absl::Status GrpcLb::UpdateLocked(UpdateArgs args) { - if (GRPC_TRACE_FLAG_ENABLED(glb)) { - LOG(INFO) << "[grpclb " << this << "] received update"; - } + GRPC_TRACE_LOG(glb, INFO) << "[grpclb " << this << "] received update"; const bool is_initial_update = lb_channel_ == nullptr; config_ = args.config.TakeAsSubclass(); CHECK(config_ != nullptr); @@ -1658,11 +1647,10 @@ void GrpcLb::StartBalancerCallLocked() { // Init the LB call data. CHECK(lb_calld_ == nullptr); lb_calld_ = MakeOrphanable(Ref()); - if (GRPC_TRACE_FLAG_ENABLED(glb)) { - LOG(INFO) << "[grpclb " << this - << "] Query for backends (lb_channel: " << lb_channel_.get() - << ", lb_calld: " << lb_calld_.get() << ")"; - } + GRPC_TRACE_LOG(glb, INFO) + << "[grpclb " << this + << "] Query for backends (lb_channel: " << lb_channel_.get() + << ", lb_calld: " << lb_calld_.get() << ")"; lb_calld_->StartQuery(); } @@ -1697,9 +1685,8 @@ void GrpcLb::StartBalancerCallRetryTimerLocked() { void GrpcLb::OnBalancerCallRetryTimerLocked() { lb_call_retry_timer_handle_.reset(); if (!shutting_down_ && lb_calld_ == nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(glb)) { - LOG(INFO) << "[grpclb " << this << "] Restarting call to LB server"; - } + GRPC_TRACE_LOG(glb, INFO) + << "[grpclb " << this << "] Restarting call to LB server"; StartBalancerCallLocked(); } } @@ -1765,10 +1752,9 @@ OrphanablePtr GrpcLb::CreateChildPolicyLocked( std::make_unique(RefAsSubclass(DEBUG_LOCATION, "Helper")); OrphanablePtr lb_policy = MakeOrphanable(std::move(lb_policy_args), &glb_trace); - if (GRPC_TRACE_FLAG_ENABLED(glb)) { - LOG(INFO) << "[grpclb " << this << "] Created new child policy handler (" - << lb_policy.get() << ")"; - } + GRPC_TRACE_LOG(glb, INFO) + << "[grpclb " << this << "] Created new child policy handler (" + << lb_policy.get() << ")"; // Add the gRPC LB's interested_parties pollset_set to that of the newly // created child policy. This will make the child policy progress upon // activity on gRPC LB, which in turn is tied to the application's call. @@ -1819,10 +1805,9 @@ void GrpcLb::CreateOrUpdateChildPolicyLocked() { child_policy_ = CreateChildPolicyLocked(update_args.args); } // Update the policy. - if (GRPC_TRACE_FLAG_ENABLED(glb)) { - LOG(INFO) << "[grpclb " << this << "] Updating child policy handler " - << child_policy_.get(); - } + GRPC_TRACE_LOG(glb, INFO) + << "[grpclb " << this << "] Updating child policy handler " + << child_policy_.get(); // TODO(roth): If we're in fallback mode and the child policy rejects the // update, we should propagate that failure back to the resolver somehow. (void)child_policy_->UpdateLocked(std::move(update_args)); @@ -1864,10 +1849,9 @@ void GrpcLb::OnSubchannelCacheTimerLocked() { subchannel_cache_timer_handle_.reset(); auto it = cached_subchannels_.begin(); if (it != cached_subchannels_.end()) { - if (GRPC_TRACE_FLAG_ENABLED(glb)) { - LOG(INFO) << "[grpclb " << this << "] removing " << it->second.size() - << " subchannels from cache"; - } + GRPC_TRACE_LOG(glb, INFO) + << "[grpclb " << this << "] removing " << it->second.size() + << " subchannels from cache"; cached_subchannels_.erase(it); } if (!cached_subchannels_.empty()) { diff --git a/src/core/load_balancing/health_check_client.cc b/src/core/load_balancing/health_check_client.cc index d805ef761e..430c59f28f 100644 --- a/src/core/load_balancing/health_check_client.cc +++ b/src/core/load_balancing/health_check_client.cc @@ -146,11 +146,9 @@ void HealthProducer::HealthChecker::OnConnectivityStateChangeLocked( void HealthProducer::HealthChecker::NotifyWatchersLocked( grpc_connectivity_state state, absl::Status status) { - if (GRPC_TRACE_FLAG_ENABLED(health_check_client)) { - LOG(INFO) << "HealthProducer " << producer_.get() << " HealthChecker " - << this << ": reporting state " << ConnectivityStateName(state) - << " to watchers"; - } + GRPC_TRACE_LOG(health_check_client, INFO) + << "HealthProducer " << producer_.get() << " HealthChecker " << this + << ": reporting state " << ConnectivityStateName(state) << " to watchers"; work_serializer_->Schedule( [self = Ref(), state, status = std::move(status)]() { MutexLock lock(&self->producer_->mu_); @@ -285,11 +283,10 @@ class HealthProducer::HealthChecker::HealthStreamEventHandler final void SetHealthStatusLocked(SubchannelStreamClient* client, grpc_connectivity_state state, const char* reason) { - if (GRPC_TRACE_FLAG_ENABLED(health_check_client)) { - LOG(INFO) << "HealthCheckClient " << client - << ": setting state=" << ConnectivityStateName(state) - << " reason=" << reason; - } + GRPC_TRACE_LOG(health_check_client, INFO) + << "HealthCheckClient " << client + << ": setting state=" << ConnectivityStateName(state) + << " reason=" << reason; health_checker_->OnHealthWatchStatusChange( state, state == GRPC_CHANNEL_TRANSIENT_FAILURE ? absl::UnavailableError(reason) @@ -300,11 +297,9 @@ class HealthProducer::HealthChecker::HealthStreamEventHandler final }; void HealthProducer::HealthChecker::StartHealthStreamLocked() { - if (GRPC_TRACE_FLAG_ENABLED(health_check_client)) { - LOG(INFO) << "HealthProducer " << producer_.get() << " HealthChecker " - << this << ": creating HealthClient for \"" - << health_check_service_name_ << "\""; - } + GRPC_TRACE_LOG(health_check_client, INFO) + << "HealthProducer " << producer_.get() << " HealthChecker " << this + << ": creating HealthClient for \"" << health_check_service_name_ << "\""; stream_client_ = MakeOrphanable( producer_->connected_subchannel_, producer_->subchannel_->pollset_set(), std::make_unique(Ref()), @@ -341,10 +336,9 @@ class HealthProducer::ConnectivityWatcher final // void HealthProducer::Start(RefCountedPtr subchannel) { - if (GRPC_TRACE_FLAG_ENABLED(health_check_client)) { - LOG(INFO) << "HealthProducer " << this << ": starting with subchannel " - << subchannel.get(); - } + GRPC_TRACE_LOG(health_check_client, INFO) + << "HealthProducer " << this << ": starting with subchannel " + << subchannel.get(); subchannel_ = std::move(subchannel); { MutexLock lock(&mu_); @@ -357,9 +351,8 @@ void HealthProducer::Start(RefCountedPtr subchannel) { } void HealthProducer::Orphaned() { - if (GRPC_TRACE_FLAG_ENABLED(health_check_client)) { - LOG(INFO) << "HealthProducer " << this << ": shutting down"; - } + GRPC_TRACE_LOG(health_check_client, INFO) + << "HealthProducer " << this << ": shutting down"; { MutexLock lock(&mu_); health_checkers_.clear(); @@ -407,11 +400,10 @@ void HealthProducer::RemoveWatcher( void HealthProducer::OnConnectivityStateChange(grpc_connectivity_state state, const absl::Status& status) { - if (GRPC_TRACE_FLAG_ENABLED(health_check_client)) { - LOG(INFO) << "HealthProducer " << this - << ": subchannel state update: state=" - << ConnectivityStateName(state) << " status=" << status; - } + GRPC_TRACE_LOG(health_check_client, INFO) + << "HealthProducer " << this + << ": subchannel state update: state=" << ConnectivityStateName(state) + << " status=" << status; MutexLock lock(&mu_); state_ = state; status_ = status; @@ -433,11 +425,10 @@ void HealthProducer::OnConnectivityStateChange(grpc_connectivity_state state, // HealthWatcher::~HealthWatcher() { - if (GRPC_TRACE_FLAG_ENABLED(health_check_client)) { - LOG(INFO) << "HealthWatcher " << this << ": unregistering from producer " - << producer_.get() << " (health_check_service_name=\"" - << health_check_service_name_.value_or("N/A") << "\")"; - } + GRPC_TRACE_LOG(health_check_client, INFO) + << "HealthWatcher " << this << ": unregistering from producer " + << producer_.get() << " (health_check_service_name=\"" + << health_check_service_name_.value_or("N/A") << "\")"; if (producer_ != nullptr) { producer_->RemoveWatcher(this, health_check_service_name_); } @@ -467,12 +458,11 @@ void HealthWatcher::SetSubchannel(Subchannel* subchannel) { if (created) producer_->Start(subchannel->Ref()); // Register ourself with the producer. producer_->AddWatcher(this, health_check_service_name_); - if (GRPC_TRACE_FLAG_ENABLED(health_check_client)) { - LOG(INFO) << "HealthWatcher " << this << ": registered with producer " - << producer_.get() << " (created=" << created - << ", health_check_service_name=\"" - << health_check_service_name_.value_or("N/A") << "\")"; - } + GRPC_TRACE_LOG(health_check_client, INFO) + << "HealthWatcher " << this << ": registered with producer " + << producer_.get() << " (created=" << created + << ", health_check_service_name=\"" + << health_check_service_name_.value_or("N/A") << "\")"; } void HealthWatcher::Notify(grpc_connectivity_state state, absl::Status status) { @@ -498,10 +488,9 @@ MakeHealthCheckWatcher( health_check_service_name = args.GetOwnedString(GRPC_ARG_HEALTH_CHECK_SERVICE_NAME); } - if (GRPC_TRACE_FLAG_ENABLED(health_check_client)) { - LOG(INFO) << "creating HealthWatcher -- health_check_service_name=\"" - << health_check_service_name.value_or("N/A") << "\""; - } + GRPC_TRACE_LOG(health_check_client, INFO) + << "creating HealthWatcher -- health_check_service_name=\"" + << health_check_service_name.value_or("N/A") << "\""; return std::make_unique(std::move(work_serializer), std::move(health_check_service_name), std::move(watcher)); diff --git a/src/core/load_balancing/oob_backend_metric.cc b/src/core/load_balancing/oob_backend_metric.cc index e3c44fe335..1073e74340 100644 --- a/src/core/load_balancing/oob_backend_metric.cc +++ b/src/core/load_balancing/oob_backend_metric.cc @@ -274,10 +274,8 @@ void OrcaProducer::MaybeStartStreamLocked() { void OrcaProducer::NotifyWatchers( const BackendMetricData& backend_metric_data) { - if (GRPC_TRACE_FLAG_ENABLED(orca_client)) { - LOG(INFO) << "OrcaProducer " << this - << ": reporting backend metrics to watchers"; - } + GRPC_TRACE_LOG(orca_client, INFO) + << "OrcaProducer " << this << ": reporting backend metrics to watchers"; MutexLock lock(&mu_); for (OrcaWatcher* watcher : watchers_) { watcher->watcher()->OnBackendMetricReport(backend_metric_data); diff --git a/src/core/load_balancing/outlier_detection/outlier_detection.cc b/src/core/load_balancing/outlier_detection/outlier_detection.cc index 28fa5dd01c..87cffdefe8 100644 --- a/src/core/load_balancing/outlier_detection/outlier_detection.cc +++ b/src/core/load_balancing/outlier_detection/outlier_detection.cc @@ -532,11 +532,10 @@ OutlierDetectionLb::Picker::Picker(OutlierDetectionLb* outlier_detection_lb, RefCountedPtr picker, bool counting_enabled) : picker_(std::move(picker)), counting_enabled_(counting_enabled) { - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << outlier_detection_lb - << "] constructed new picker " << this << " and counting " - << "is " << (counting_enabled ? "enabled" : "disabled"); - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << outlier_detection_lb + << "] constructed new picker " << this << " and counting " + << "is " << (counting_enabled ? "enabled" : "disabled"); } LoadBalancingPolicy::PickResult OutlierDetectionLb::Picker::Pick( @@ -574,22 +573,19 @@ LoadBalancingPolicy::PickResult OutlierDetectionLb::Picker::Pick( OutlierDetectionLb::OutlierDetectionLb(Args args) : LoadBalancingPolicy(std::move(args)) { - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << this << "] created"; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << this << "] created"; } OutlierDetectionLb::~OutlierDetectionLb() { - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << this - << "] destroying outlier_detection LB policy"; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << this + << "] destroying outlier_detection LB policy"; } void OutlierDetectionLb::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << this << "] shutting down"; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << this << "] shutting down"; ejection_timer_.reset(); shutting_down_ = true; // Remove the child policy's interested_parties pollset_set from the @@ -613,25 +609,22 @@ void OutlierDetectionLb::ResetBackoffLocked() { } absl::Status OutlierDetectionLb::UpdateLocked(UpdateArgs args) { - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << this << "] Received update"; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << this << "] Received update"; auto old_config = std::move(config_); // Update config. config_ = args.config.TakeAsSubclass(); // Update outlier detection timer. if (!config_->CountingEnabled()) { // No need for timer. Cancel the current timer, if any. - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << this - << "] counting disabled, cancelling timer"; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << this + << "] counting disabled, cancelling timer"; ejection_timer_.reset(); } else if (ejection_timer_ == nullptr) { // No timer running. Start it now. - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << this << "] starting timer"; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << this << "] starting timer"; ejection_timer_ = MakeOrphanable( RefAsSubclass(), Timestamp::Now()); for (const auto& p : endpoint_state_map_) { @@ -643,10 +636,9 @@ absl::Status OutlierDetectionLb::UpdateLocked(UpdateArgs args) { // with the same start time. // Note that if the new deadline is in the past, the timer will fire // immediately. - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << this - << "] interval changed, replacing timer"; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << this + << "] interval changed, replacing timer"; ejection_timer_ = MakeOrphanable( RefAsSubclass(), ejection_timer_->StartTime()); } @@ -663,10 +655,9 @@ absl::Status OutlierDetectionLb::UpdateLocked(UpdateArgs args) { // Find the entry in the endpoint map. auto it = endpoint_state_map_.find(key); if (it == endpoint_state_map_.end()) { - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << this - << "] adding endpoint entry for " << key.ToString(); - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << this + << "] adding endpoint entry for " << key.ToString(); // The endpoint is not present in the map, so we'll need to add it. // Start by getting a pointer to the entry for each address in the // subchannel map, creating the entry if needed. @@ -691,11 +682,9 @@ absl::Status OutlierDetectionLb::UpdateLocked(UpdateArgs args) { key, MakeRefCounted(std::move(subchannels))); } else if (!config_->CountingEnabled()) { // If counting is not enabled, reset state. - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << this - << "] counting disabled; disabling ejection for " - << key.ToString(); - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << this + << "] counting disabled; disabling ejection for " << key.ToString(); it->second->DisableEjection(); } }); @@ -722,10 +711,9 @@ absl::Status OutlierDetectionLb::UpdateLocked(UpdateArgs args) { for (auto it = endpoint_state_map_.begin(); it != endpoint_state_map_.end();) { if (current_endpoints.find(it->first) == current_endpoints.end()) { - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << this - << "] removing endpoint map entry " << it->first.ToString(); - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << this + << "] removing endpoint map entry " << it->first.ToString(); it = endpoint_state_map_.erase(it); } else { ++it; @@ -742,10 +730,9 @@ absl::Status OutlierDetectionLb::UpdateLocked(UpdateArgs args) { update_args.resolution_note = std::move(args.resolution_note); update_args.config = config_->child_policy(); update_args.args = std::move(args.args); - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << this - << "] Updating child policy handler " << child_policy_.get(); - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << this << "] Updating child policy handler " + << child_policy_.get(); return child_policy_->UpdateLocked(std::move(update_args)); } @@ -753,12 +740,11 @@ void OutlierDetectionLb::MaybeUpdatePickerLocked() { if (picker_ != nullptr) { auto outlier_detection_picker = MakeRefCounted(this, picker_, config_->CountingEnabled()); - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << this - << "] updating connectivity: state=" - << ConnectivityStateName(state_) << " status=(" << status_ - << ") picker=" << outlier_detection_picker.get(); - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << this + << "] updating connectivity: state=" << ConnectivityStateName(state_) + << " status=(" << status_ + << ") picker=" << outlier_detection_picker.get(); channel_control_helper()->UpdateState(state_, status_, std::move(outlier_detection_picker)); } @@ -774,10 +760,9 @@ OrphanablePtr OutlierDetectionLb::CreateChildPolicyLocked( OrphanablePtr lb_policy = MakeOrphanable(std::move(lb_policy_args), &outlier_detection_lb_trace); - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << this - << "] Created new child policy handler " << lb_policy.get(); - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << this + << "] Created new child policy handler " << lb_policy.get(); // Add our interested_parties pollset_set to that of the newly created // child policy. This will make the child policy progress upon activity on // this policy, which in turn is tied to the application's call. @@ -820,12 +805,11 @@ void OutlierDetectionLb::Helper::UpdateState( grpc_connectivity_state state, const absl::Status& status, RefCountedPtr picker) { if (parent()->shutting_down_) return; - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << parent() - << "] child connectivity state update: state=" - << ConnectivityStateName(state) << " (" << status - << ") picker=" << picker.get(); - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << parent() + << "] child connectivity state update: state=" + << ConnectivityStateName(state) << " (" << status + << ") picker=" << picker.get(); // Save the state and picker. parent()->state_ = state; parent()->status_ = status; @@ -842,10 +826,9 @@ OutlierDetectionLb::EjectionTimer::EjectionTimer( RefCountedPtr parent, Timestamp start_time) : parent_(std::move(parent)), start_time_(start_time) { auto interval = parent_->config_->outlier_detection_config().interval; - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << parent_.get() - << "] ejection timer will run in " << interval.ToString(); - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << parent_.get() + << "] ejection timer will run in " << interval.ToString(); timer_handle_ = parent_->channel_control_helper()->GetEventEngine()->RunAfter( interval, [self = Ref(DEBUG_LOCATION, "EjectionTimer")]() mutable { ApplicationCallbackExecCtx callback_exec_ctx; @@ -868,10 +851,9 @@ void OutlierDetectionLb::EjectionTimer::Orphan() { void OutlierDetectionLb::EjectionTimer::OnTimerLocked() { if (!timer_handle_.has_value()) return; timer_handle_.reset(); - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << parent_.get() - << "] ejection timer running"; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << parent_.get() + << "] ejection timer running"; std::map success_rate_ejection_candidates; std::map failure_percentage_ejection_candidates; size_t ejected_host_count = 0; @@ -908,26 +890,24 @@ void OutlierDetectionLb::EjectionTimer::OnTimerLocked() { } } } - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << parent_.get() << "] found " - << success_rate_ejection_candidates.size() - << " success rate candidates and " - << failure_percentage_ejection_candidates.size() - << " failure percentage candidates; ejected_host_count=" - << ejected_host_count << "; success_rate_sum=" - << absl::StrFormat("%.3f", success_rate_sum); - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << parent_.get() << "] found " + << success_rate_ejection_candidates.size() + << " success rate candidates and " + << failure_percentage_ejection_candidates.size() + << " failure percentage candidates; ejected_host_count=" + << ejected_host_count + << "; success_rate_sum=" << absl::StrFormat("%.3f", success_rate_sum); // success rate algorithm if (!success_rate_ejection_candidates.empty() && success_rate_ejection_candidates.size() >= config.success_rate_ejection->minimum_hosts) { - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << parent_.get() - << "] running success rate algorithm: " - << "stdev_factor=" << config.success_rate_ejection->stdev_factor - << ", enforcement_percentage=" - << config.success_rate_ejection->enforcement_percentage; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << parent_.get() + << "] running success rate algorithm: " + << "stdev_factor=" << config.success_rate_ejection->stdev_factor + << ", enforcement_percentage=" + << config.success_rate_ejection->enforcement_percentage; // calculate ejection threshold: (mean - stdev * // (success_rate_ejection.stdev_factor / 1000)) double mean = success_rate_sum / success_rate_ejection_candidates.size(); @@ -940,37 +920,31 @@ void OutlierDetectionLb::EjectionTimer::OnTimerLocked() { const double success_rate_stdev_factor = static_cast(config.success_rate_ejection->stdev_factor) / 1000; double ejection_threshold = mean - stdev * success_rate_stdev_factor; - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << parent_.get() - << "] stdev=" << stdev - << ", ejection_threshold=" << ejection_threshold; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << parent_.get() << "] stdev=" << stdev + << ", ejection_threshold=" << ejection_threshold; for (auto& candidate : success_rate_ejection_candidates) { - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << parent_.get() - << "] checking candidate " << candidate.first - << ": success_rate=" << candidate.second; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << parent_.get() + << "] checking candidate " << candidate.first + << ": success_rate=" << candidate.second; if (candidate.second < ejection_threshold) { uint32_t random_key = absl::Uniform(bit_gen_, 1, 100); double current_percent = 100.0 * ejected_host_count / parent_->endpoint_state_map_.size(); - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << parent_.get() - << "] random_key=" << random_key - << " ejected_host_count=" << ejected_host_count - << " current_percent=" - << absl::StrFormat("%.3f", current_percent); - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << parent_.get() + << "] random_key=" << random_key + << " ejected_host_count=" << ejected_host_count + << " current_percent=" << absl::StrFormat("%.3f", current_percent); if (random_key < config.success_rate_ejection->enforcement_percentage && (ejected_host_count == 0 || (current_percent < config.max_ejection_percent))) { // Eject and record the timestamp for use when ejecting addresses in // this iteration. - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << parent_.get() - << "] ejecting candidate"; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << parent_.get() + << "] ejecting candidate"; candidate.first->Eject(time_now); ++ejected_host_count; } @@ -981,19 +955,17 @@ void OutlierDetectionLb::EjectionTimer::OnTimerLocked() { if (!failure_percentage_ejection_candidates.empty() && failure_percentage_ejection_candidates.size() >= config.failure_percentage_ejection->minimum_hosts) { - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << parent_.get() - << "] running failure percentage algorithm: " - << "threshold=" << config.failure_percentage_ejection->threshold - << ", enforcement_percentage=" - << config.failure_percentage_ejection->enforcement_percentage; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << parent_.get() + << "] running failure percentage algorithm: " + << "threshold=" << config.failure_percentage_ejection->threshold + << ", enforcement_percentage=" + << config.failure_percentage_ejection->enforcement_percentage; for (auto& candidate : failure_percentage_ejection_candidates) { - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << parent_.get() - << "] checking candidate " << candidate.first - << ": success_rate=" << candidate.second; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << parent_.get() + << "] checking candidate " << candidate.first + << ": success_rate=" << candidate.second; // Extra check to make sure success rate algorithm didn't already // eject this backend. if (candidate.first->ejection_time().has_value()) continue; @@ -1002,22 +974,20 @@ void OutlierDetectionLb::EjectionTimer::OnTimerLocked() { uint32_t random_key = absl::Uniform(bit_gen_, 1, 100); double current_percent = 100.0 * ejected_host_count / parent_->endpoint_state_map_.size(); - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << parent_.get() - << "] random_key=" << random_key - << " ejected_host_count=" << ejected_host_count - << " current_percent=" << current_percent; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << parent_.get() + << "] random_key=" << random_key + << " ejected_host_count=" << ejected_host_count + << " current_percent=" << current_percent; if (random_key < config.failure_percentage_ejection->enforcement_percentage && (ejected_host_count == 0 || (current_percent < config.max_ejection_percent))) { // Eject and record the timestamp for use when ejecting addresses in // this iteration. - if (GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) { - LOG(INFO) << "[outlier_detection_lb " << parent_.get() - << "] ejecting candidate"; - } + GRPC_TRACE_LOG(outlier_detection_lb, INFO) + << "[outlier_detection_lb " << parent_.get() + << "] ejecting candidate"; candidate.first->Eject(time_now); ++ejected_host_count; } diff --git a/src/core/load_balancing/pick_first/pick_first.cc b/src/core/load_balancing/pick_first/pick_first.cc index 45a3b32457..c63424cada 100644 --- a/src/core/load_balancing/pick_first/pick_first.cc +++ b/src/core/load_balancing/pick_first/pick_first.cc @@ -420,22 +420,16 @@ PickFirst::PickFirst(Args args) .GetInt(GRPC_ARG_HAPPY_EYEBALLS_CONNECTION_ATTEMPT_DELAY_MS) .value_or(250), 100, 2000))) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << this << " created."; - } + GRPC_TRACE_LOG(pick_first, INFO) << "Pick First " << this << " created."; } PickFirst::~PickFirst() { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Destroying Pick First " << this; - } + GRPC_TRACE_LOG(pick_first, INFO) << "Destroying Pick First " << this; CHECK(subchannel_list_ == nullptr); } void PickFirst::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << this << " Shutting down"; - } + GRPC_TRACE_LOG(pick_first, INFO) << "Pick First " << this << " Shutting down"; shutdown_ = true; UnsetSelectedSubchannel(); subchannel_list_.reset(); @@ -444,9 +438,8 @@ void PickFirst::ShutdownLocked() { void PickFirst::ExitIdleLocked() { if (shutdown_) return; if (IsIdle()) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << this << " exiting idle"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << this << " exiting idle"; AttemptToConnectUsingLatestUpdateArgsLocked(); } } @@ -631,10 +624,10 @@ void PickFirst::GoIdle() { void PickFirst::HealthWatcher::OnConnectivityStateChange( grpc_connectivity_state new_state, absl::Status status) { if (policy_->health_watcher_ != this) return; - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << policy_.get() << "] health watch state update: " - << ConnectivityStateName(new_state) << " (" << status << ")"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << policy_.get() + << "] health watch state update: " << ConnectivityStateName(new_state) + << " (" << status << ")"; switch (new_state) { case GRPC_CHANNEL_READY: policy_->channel_control_helper()->UpdateState( @@ -672,21 +665,19 @@ PickFirst::SubchannelList::SubchannelData::SubchannelState::SubchannelState( : subchannel_data_(subchannel_data), pick_first_(subchannel_data_->subchannel_list_->policy_), subchannel_(std::move(subchannel)) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << pick_first_.get() << "] subchannel state " << this - << " (subchannel " << subchannel_.get() << "): starting watch"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << pick_first_.get() << "] subchannel state " << this + << " (subchannel " << subchannel_.get() << "): starting watch"; auto watcher = std::make_unique(Ref(DEBUG_LOCATION, "Watcher")); watcher_ = watcher.get(); subchannel_->WatchConnectivityState(std::move(watcher)); } void PickFirst::SubchannelList::SubchannelData::SubchannelState::Orphan() { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << pick_first_.get() << "] subchannel state " << this - << " (subchannel " << subchannel_.get() - << "): cancelling watch and unreffing subchannel"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << pick_first_.get() << "] subchannel state " << this + << " (subchannel " << subchannel_.get() + << "): cancelling watch and unreffing subchannel"; subchannel_data_ = nullptr; subchannel_->CancelConnectivityStateWatch(watcher_); watcher_ = nullptr; @@ -696,10 +687,9 @@ void PickFirst::SubchannelList::SubchannelData::SubchannelState::Orphan() { } void PickFirst::SubchannelList::SubchannelData::SubchannelState::Select() { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << pick_first_.get() << " selected subchannel " - << subchannel_.get(); - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << pick_first_.get() << " selected subchannel " + << subchannel_.get(); CHECK_NE(subchannel_data_, nullptr); pick_first_->UnsetSelectedSubchannel(); // Cancel health watch, if any. pick_first_->selected_ = std::move(subchannel_data_->subchannel_state_); @@ -708,9 +698,8 @@ void PickFirst::SubchannelList::SubchannelData::SubchannelState::Select() { // for the health status notification. // If health checking is NOT enabled, report READY. if (pick_first_->enable_health_watch_) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << pick_first_.get() << "] starting health watch"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << pick_first_.get() << "] starting health watch"; auto watcher = std::make_unique( pick_first_.Ref(DEBUG_LOCATION, "HealthWatcher")); pick_first_->health_watcher_ = watcher.get(); @@ -746,15 +735,13 @@ void PickFirst::SubchannelList::SubchannelData::SubchannelState:: OnConnectivityStateChange(grpc_connectivity_state new_state, absl::Status status) { if (watcher_ == nullptr) return; - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << pick_first_.get() << "] subchannel state " << this - << " (subchannel " << subchannel_.get() - << "): connectivity changed: new_state=" - << ConnectivityStateName(new_state) << ", status=" << status - << ", watcher=" << watcher_ - << ", subchannel_data_=" << subchannel_data_ - << ", pick_first_->selected_=" << pick_first_->selected_.get(); - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << pick_first_.get() << "] subchannel state " << this + << " (subchannel " << subchannel_.get() + << "): connectivity changed: new_state=" + << ConnectivityStateName(new_state) << ", status=" << status + << ", watcher=" << watcher_ << ", subchannel_data_=" << subchannel_data_ + << ", pick_first_->selected_=" << pick_first_->selected_.get(); // If we're still part of a subchannel list trying to connect, check // if we're connected. if (subchannel_data_ != nullptr) { @@ -769,11 +756,10 @@ void PickFirst::SubchannelList::SubchannelData::SubchannelState:: } // We aren't trying to connect, so we must be the selected subchannel. CHECK(pick_first_->selected_.get() == this); - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << pick_first_.get() - << " selected subchannel connectivity changed to " - << ConnectivityStateName(new_state); - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << pick_first_.get() + << " selected subchannel connectivity changed to " + << ConnectivityStateName(new_state); // Any state change is considered to be a failure of the existing // connection. Report the failure. auto& stats_plugins = @@ -793,11 +779,10 @@ PickFirst::SubchannelList::SubchannelData::SubchannelData( SubchannelList* subchannel_list, size_t index, RefCountedPtr subchannel) : subchannel_list_(subchannel_list), index_(index) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << subchannel_list_->policy_.get() - << "] subchannel list " << subchannel_list_ << " index " << index_ - << ": creating subchannel data"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << subchannel_list_->policy_.get() << "] subchannel list " + << subchannel_list_ << " index " << index_ + << ": creating subchannel data"; subchannel_state_ = MakeOrphanable(this, std::move(subchannel)); } @@ -805,22 +790,21 @@ PickFirst::SubchannelList::SubchannelData::SubchannelData( void PickFirst::SubchannelList::SubchannelData::OnConnectivityStateChange( grpc_connectivity_state new_state, absl::Status status) { PickFirst* p = subchannel_list_->policy_.get(); - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << p << "] subchannel list " << subchannel_list_ - << " index " << index_ << " of " << subchannel_list_->size() - << " (subchannel_state " << subchannel_state_.get() - << "): connectivity changed: old_state=" - << (connectivity_state_.has_value() - ? ConnectivityStateName(*connectivity_state_) - : "N/A") - << ", new_state=" << ConnectivityStateName(new_state) - << ", status=" << status - << ", seen_transient_failure=" << seen_transient_failure_ - << ", p->selected_=" << p->selected_.get() - << ", p->subchannel_list_=" << p->subchannel_list_.get() - << ", p->subchannel_list_->shutting_down_=" - << p->subchannel_list_->shutting_down_; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << p << "] subchannel list " << subchannel_list_ << " index " + << index_ << " of " << subchannel_list_->size() << " (subchannel_state " + << subchannel_state_.get() << "): connectivity changed: old_state=" + << (connectivity_state_.has_value() + ? ConnectivityStateName(*connectivity_state_) + : "N/A") + << ", new_state=" << ConnectivityStateName(new_state) + << ", status=" << status + << ", seen_transient_failure=" << seen_transient_failure_ + << ", p->selected_=" << p->selected_.get() + << ", p->subchannel_list_=" << p->subchannel_list_.get() + << ", p->subchannel_list_->shutting_down_=" + << p->subchannel_list_->shutting_down_; + if (subchannel_list_->shutting_down_) return; // The notification must be for a subchannel in the current list. CHECK(subchannel_list_ == p->subchannel_list_.get()); @@ -858,11 +842,10 @@ void PickFirst::SubchannelList::SubchannelData::OnConnectivityStateChange( // is not in the new list. In that case, we drop the current // connection and report IDLE. if (p->selected_ != nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << p << "] subchannel list " << subchannel_list_ - << ": new update has no subchannels in " - << "state READY; dropping existing connection and going IDLE"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << p << "] subchannel list " << subchannel_list_ + << ": new update has no subchannels in state READY; dropping " + "existing connection and going IDLE"; p->GoIdle(); } else { // Start trying to connect, starting with the first subchannel. @@ -958,12 +941,10 @@ void PickFirst::SubchannelList::SubchannelData::RequestConnectionWithTimer() { // If this is not the last subchannel in the list, start the timer. if (index_ != subchannel_list_->size() - 1) { PickFirst* p = subchannel_list_->policy_.get(); - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << p << " subchannel list " << subchannel_list_ - << ": starting Connection Attempt Delay timer for " - << p->connection_attempt_delay_.millis() << "ms for index " - << index_; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << p << " subchannel list " << subchannel_list_ + << ": starting Connection Attempt Delay timer for " + << p->connection_attempt_delay_.millis() << "ms for index " << index_; subchannel_list_->timer_handle_ = p->channel_control_helper()->GetEventEngine()->RunAfter( p->connection_attempt_delay_, @@ -974,15 +955,13 @@ void PickFirst::SubchannelList::SubchannelData::RequestConnectionWithTimer() { auto* sl = subchannel_list.get(); sl->policy_->work_serializer()->Run( [subchannel_list = std::move(subchannel_list)]() { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) - << "Pick First " << subchannel_list->policy_.get() - << " subchannel list " << subchannel_list.get() - << ": Connection Attempt Delay timer fired " - "(shutting_down=" - << subchannel_list->shutting_down_ << ", selected=" - << subchannel_list->policy_->selected_.get() << ")"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << subchannel_list->policy_.get() + << " subchannel list " << subchannel_list.get() + << ": Connection Attempt Delay timer fired " + "(shutting_down=" + << subchannel_list->shutting_down_ << ", selected=" + << subchannel_list->policy_->selected_.get() << ")"; if (subchannel_list->shutting_down_) return; if (subchannel_list->policy_->selected_ != nullptr) return; ++subchannel_list->attempting_index_; @@ -1006,10 +985,9 @@ PickFirst::SubchannelList::SubchannelList(RefCountedPtr policy, args_(args.Remove(GRPC_ARG_INTERNAL_PICK_FIRST_ENABLE_HEALTH_CHECKING) .Remove( GRPC_ARG_INTERNAL_PICK_FIRST_OMIT_STATUS_MESSAGE_PREFIX)) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << policy_.get() << "] Creating subchannel list " - << this << " - channel args: " << args_.ToString(); - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << policy_.get() << "] Creating subchannel list " << this + << " - channel args: " << args_.ToString(); if (addresses == nullptr) return; // Create a subchannel for each address. addresses->ForEach([&](const EndpointAddresses& address) { @@ -1019,35 +997,29 @@ PickFirst::SubchannelList::SubchannelList(RefCountedPtr policy, address.address(), address.args(), args_); if (subchannel == nullptr) { // Subchannel could not be created. - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << policy_.get() - << "] could not create subchannel for address " - << address.ToString() << ", ignoring"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << policy_.get() + << "] could not create subchannel for address " << address.ToString() + << ", ignoring"; return; } - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << policy_.get() << "] subchannel list " << this - << " index " << subchannels_.size() << ": Created subchannel " - << subchannel.get() << " for address " << address.ToString(); - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << policy_.get() << "] subchannel list " << this << " index " + << subchannels_.size() << ": Created subchannel " << subchannel.get() + << " for address " << address.ToString(); subchannels_.emplace_back(std::make_unique( this, subchannels_.size(), std::move(subchannel))); }); } PickFirst::SubchannelList::~SubchannelList() { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << policy_.get() << "] Destroying subchannel_list " - << this; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << policy_.get() << "] Destroying subchannel_list " << this; } void PickFirst::SubchannelList::Orphan() { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << policy_.get() << "] Shutting down subchannel_list " - << this; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << policy_.get() << "] Shutting down subchannel_list " << this; CHECK(!shutting_down_); shutting_down_ = true; // Cancel Happy Eyeballs timer, if any. @@ -1089,10 +1061,9 @@ void PickFirst::SubchannelList::MaybeFinishHappyEyeballsPass() { // We didn't find another subchannel not in state TRANSIENT_FAILURE, // so report TRANSIENT_FAILURE and switch to a mode in which we try to // connect to all addresses in parallel. - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << policy_.get() << " subchannel list " << this - << " failed to connect to all subchannels"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << policy_.get() << " subchannel list " << this + << " failed to connect to all subchannels"; // Re-resolve and report TRANSIENT_FAILURE. policy_->channel_control_helper()->RequestReresolution(); absl::Status status = absl::UnavailableError( @@ -1382,23 +1353,17 @@ OldPickFirst::OldPickFirst(Args args) .GetInt(GRPC_ARG_HAPPY_EYEBALLS_CONNECTION_ATTEMPT_DELAY_MS) .value_or(250), 100, 2000))) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << this << " created."; - } + GRPC_TRACE_LOG(pick_first, INFO) << "Pick First " << this << " created."; } OldPickFirst::~OldPickFirst() { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Destroying Pick First " << this; - } + GRPC_TRACE_LOG(pick_first, INFO) << "Destroying Pick First " << this; CHECK(subchannel_list_ == nullptr); CHECK(latest_pending_subchannel_list_ == nullptr); } void OldPickFirst::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << this << " Shutting down"; - } + GRPC_TRACE_LOG(pick_first, INFO) << "Pick First " << this << " Shutting down"; shutdown_ = true; UnsetSelectedSubchannel(); subchannel_list_.reset(); @@ -1408,9 +1373,8 @@ void OldPickFirst::ShutdownLocked() { void OldPickFirst::ExitIdleLocked() { if (shutdown_) return; if (IsIdle()) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << this << " exiting idle"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << this << " exiting idle"; AttemptToConnectUsingLatestUpdateArgsLocked(); } } @@ -1564,10 +1528,10 @@ void OldPickFirst::UnsetSelectedSubchannel() { void OldPickFirst::HealthWatcher::OnConnectivityStateChange( grpc_connectivity_state new_state, absl::Status status) { if (policy_->health_watcher_ != this) return; - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << policy_.get() << "] health watch state update: " - << ConnectivityStateName(new_state) << " (" << status << ")"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << policy_.get() + << "] health watch state update: " << ConnectivityStateName(new_state) + << " (" << status << ")"; switch (new_state) { case GRPC_CHANNEL_READY: policy_->channel_control_helper()->UpdateState( @@ -1605,11 +1569,10 @@ OldPickFirst::SubchannelList::SubchannelData::SubchannelData( : subchannel_list_(subchannel_list), index_(index), subchannel_(std::move(subchannel)) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << subchannel_list_->policy_.get() - << "] subchannel list " << subchannel_list_ << " index " << index_ - << " (subchannel " << subchannel_.get() << "): starting watch"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << subchannel_list_->policy_.get() << "] subchannel list " + << subchannel_list_ << " index " << index_ << " (subchannel " + << subchannel_.get() << "): starting watch"; auto watcher = std::make_unique( subchannel_list_->Ref(DEBUG_LOCATION, "Watcher"), index_); pending_watcher_ = watcher.get(); @@ -1618,13 +1581,11 @@ OldPickFirst::SubchannelList::SubchannelData::SubchannelData( void OldPickFirst::SubchannelList::SubchannelData::ShutdownLocked() { if (subchannel_ != nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << subchannel_list_->policy_.get() - << "] subchannel list " << subchannel_list_ << " index " - << index_ << " of " << subchannel_list_->size() - << " (subchannel " << subchannel_.get() - << "): cancelling watch and unreffing subchannel"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << subchannel_list_->policy_.get() << "] subchannel list " + << subchannel_list_ << " index " << index_ << " of " + << subchannel_list_->size() << " (subchannel " << subchannel_.get() + << "): cancelling watch and unreffing subchannel"; subchannel_->CancelConnectivityStateWatch(pending_watcher_); pending_watcher_ = nullptr; subchannel_.reset(); @@ -1634,24 +1595,23 @@ void OldPickFirst::SubchannelList::SubchannelData::ShutdownLocked() { void OldPickFirst::SubchannelList::SubchannelData::OnConnectivityStateChange( grpc_connectivity_state new_state, absl::Status status) { OldPickFirst* p = subchannel_list_->policy_.get(); - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << p << "] subchannel list " << subchannel_list_ - << " index " << index_ << " of " << subchannel_list_->size() - << " (subchannel " << subchannel_.get() - << "): connectivity changed: old_state=" - << (connectivity_state_.has_value() - ? ConnectivityStateName(*connectivity_state_) - : "N/A") - << ", new_state=" << ConnectivityStateName(new_state) - << ", status=" << status - << ", shutting_down=" << subchannel_list_->shutting_down_ - << ", pending_watcher=" << pending_watcher_ - << ", seen_transient_failure=" << seen_transient_failure_ - << ", p->selected_=" << p->selected_ - << ", p->subchannel_list_=" << p->subchannel_list_.get() - << ", p->latest_pending_subchannel_list_=" - << p->latest_pending_subchannel_list_.get(); - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << p << "] subchannel list " << subchannel_list_ << " index " + << index_ << " of " << subchannel_list_->size() << " (subchannel " + << subchannel_.get() << "): connectivity changed: old_state=" + << (connectivity_state_.has_value() + ? ConnectivityStateName(*connectivity_state_) + : "N/A") + << ", new_state=" << ConnectivityStateName(new_state) + << ", status=" << status + << ", shutting_down=" << subchannel_list_->shutting_down_ + << ", pending_watcher=" << pending_watcher_ + << ", seen_transient_failure=" << seen_transient_failure_ + << ", p->selected_=" << p->selected_ + << ", p->subchannel_list_=" << p->subchannel_list_.get() + << ", p->latest_pending_subchannel_list_=" + << p->latest_pending_subchannel_list_.get(); + if (subchannel_list_->shutting_down_ || pending_watcher_ == nullptr) return; auto& stats_plugins = subchannel_list_->policy_->channel_control_helper() ->GetStatsPluginGroup(); @@ -1666,11 +1626,9 @@ void OldPickFirst::SubchannelList::SubchannelData::OnConnectivityStateChange( // Handle updates for the currently selected subchannel. if (p->selected_ == this) { CHECK(subchannel_list_ == p->subchannel_list_.get()); - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << p - << " selected subchannel connectivity changed to " - << ConnectivityStateName(new_state); - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << p << " selected subchannel connectivity changed to " + << ConnectivityStateName(new_state); // Any state change is considered to be a failure of the existing // connection. stats_plugins.AddCounter( @@ -1685,11 +1643,10 @@ void OldPickFirst::SubchannelList::SubchannelData::OnConnectivityStateChange( p->channel_control_helper()->RequestReresolution(); // If there is a pending update, switch to the pending update. if (p->latest_pending_subchannel_list_ != nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << p << " promoting pending subchannel " - << "list " << p->latest_pending_subchannel_list_.get() - << " to replace " << p->subchannel_list_.get(); - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << p << " promoting pending subchannel " + << "list " << p->latest_pending_subchannel_list_.get() + << " to replace " << p->subchannel_list_.get(); p->UnsetSelectedSubchannel(); p->subchannel_list_ = std::move(p->latest_pending_subchannel_list_); // Set our state to that of the pending subchannel list. @@ -1847,12 +1804,10 @@ void OldPickFirst::SubchannelList::SubchannelData:: // If this is not the last subchannel in the list, start the timer. if (index_ != subchannel_list_->size() - 1) { OldPickFirst* p = subchannel_list_->policy_.get(); - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << p << " subchannel list " << subchannel_list_ - << ": starting Connection Attempt Delay timer for " - << p->connection_attempt_delay_.millis() << "ms for index " - << index_; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << p << " subchannel list " << subchannel_list_ + << ": starting Connection Attempt Delay timer for " + << p->connection_attempt_delay_.millis() << "ms for index " << index_; subchannel_list_->timer_handle_ = p->channel_control_helper()->GetEventEngine()->RunAfter( p->connection_attempt_delay_, @@ -1863,15 +1818,13 @@ void OldPickFirst::SubchannelList::SubchannelData:: auto* sl = subchannel_list.get(); sl->policy_->work_serializer()->Run( [subchannel_list = std::move(subchannel_list)]() { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) - << "Pick First " << subchannel_list->policy_.get() - << " subchannel list " << subchannel_list.get() - << ": Connection Attempt Delay timer fired " - << "(shutting_down=" - << subchannel_list->shutting_down_ << ", selected=" - << subchannel_list->policy_->selected_ << ")"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << subchannel_list->policy_.get() + << " subchannel list " << subchannel_list.get() + << ": Connection Attempt Delay timer fired " + << "(shutting_down=" << subchannel_list->shutting_down_ + << ", selected=" << subchannel_list->policy_->selected_ + << ")"; if (subchannel_list->shutting_down_) return; if (subchannel_list->policy_->selected_ != nullptr) return; ++subchannel_list->attempting_index_; @@ -1903,28 +1856,24 @@ void OldPickFirst::SubchannelList::SubchannelData:: subchannel_list_ == p->latest_pending_subchannel_list_.get()); // Case 2. Promote p->latest_pending_subchannel_list_ to p->subchannel_list_. if (subchannel_list_ == p->latest_pending_subchannel_list_.get()) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << p << " promoting pending subchannel list " - << p->latest_pending_subchannel_list_.get() << " to replace " - << p->subchannel_list_.get(); - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << p << " promoting pending subchannel list " + << p->latest_pending_subchannel_list_.get() << " to replace " + << p->subchannel_list_.get(); p->UnsetSelectedSubchannel(); p->subchannel_list_ = std::move(p->latest_pending_subchannel_list_); } // Cases 1 and 2. - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << p << " selected subchannel " - << subchannel_.get(); - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << p << " selected subchannel " << subchannel_.get(); p->selected_ = this; // If health checking is enabled, start the health watch, but don't // report a new picker -- we want to stay in CONNECTING while we wait // for the health status notification. // If health checking is NOT enabled, report READY. if (p->enable_health_watch_) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << p << "] starting health watch"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << p << "] starting health watch"; auto watcher = std::make_unique( p->RefAsSubclass(DEBUG_LOCATION, "HealthWatcher")); p->health_watcher_ = watcher.get(); @@ -1957,10 +1906,9 @@ OldPickFirst::SubchannelList::SubchannelList( args_(args.Remove(GRPC_ARG_INTERNAL_PICK_FIRST_ENABLE_HEALTH_CHECKING) .Remove( GRPC_ARG_INTERNAL_PICK_FIRST_OMIT_STATUS_MESSAGE_PREFIX)) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << policy_.get() << "] Creating subchannel list " - << this << " - channel args: " << args_.ToString(); - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << policy_.get() << "] Creating subchannel list " << this + << " - channel args: " << args_.ToString(); if (addresses == nullptr) return; // Create a subchannel for each address. addresses->ForEach([&](const EndpointAddresses& address) { @@ -1970,34 +1918,28 @@ OldPickFirst::SubchannelList::SubchannelList( address.address(), address.args(), args_); if (subchannel == nullptr) { // Subchannel could not be created. - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << policy_.get() - << "] could not create subchannel for address " - << address.ToString() << ", ignoring"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << policy_.get() + << "] could not create subchannel for address " << address.ToString() + << ", ignoring"; return; } - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << policy_.get() << "] subchannel list " << this - << " index " << subchannels_.size() << ": Created subchannel " - << subchannel.get() << " for address " << address.ToString(); - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << policy_.get() << "] subchannel list " << this << " index " + << subchannels_.size() << ": Created subchannel " << subchannel.get() + << " for address " << address.ToString(); subchannels_.emplace_back(this, subchannels_.size(), std::move(subchannel)); }); } OldPickFirst::SubchannelList::~SubchannelList() { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << policy_.get() << "] Destroying subchannel_list " - << this; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << policy_.get() << "] Destroying subchannel_list " << this; } void OldPickFirst::SubchannelList::Orphan() { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "[PF " << policy_.get() << "] Shutting down subchannel_list " - << this; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "[PF " << policy_.get() << "] Shutting down subchannel_list " << this; CHECK(!shutting_down_); shutting_down_ = true; for (auto& sd : subchannels_) { @@ -2041,20 +1983,18 @@ void OldPickFirst::SubchannelList::MaybeFinishHappyEyeballsPass() { // We didn't find another subchannel not in state TRANSIENT_FAILURE, // so report TRANSIENT_FAILURE and switch to a mode in which we try to // connect to all addresses in parallel. - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << policy_.get() << " subchannel list " << this - << " failed to connect to all subchannels"; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << policy_.get() << " subchannel list " << this + << " failed to connect to all subchannels"; // In case 2, swap to the new subchannel list. This means reporting // TRANSIENT_FAILURE and dropping the existing (working) connection, // but we can't ignore what the control plane has told us. if (policy_->latest_pending_subchannel_list_.get() == this) { - if (GRPC_TRACE_FLAG_ENABLED(pick_first)) { - LOG(INFO) << "Pick First " << policy_.get() - << " promoting pending subchannel list " - << policy_->latest_pending_subchannel_list_.get() - << " to replace " << this; - } + GRPC_TRACE_LOG(pick_first, INFO) + << "Pick First " << policy_.get() + << " promoting pending subchannel list " + << policy_->latest_pending_subchannel_list_.get() << " to replace " + << this; policy_->UnsetSelectedSubchannel(); policy_->subchannel_list_ = std::move(policy_->latest_pending_subchannel_list_); diff --git a/src/core/load_balancing/priority/priority.cc b/src/core/load_balancing/priority/priority.cc index bd421022f7..07f9a529dd 100644 --- a/src/core/load_balancing/priority/priority.cc +++ b/src/core/load_balancing/priority/priority.cc @@ -294,21 +294,17 @@ PriorityLb::PriorityLb(Args args) channel_args() .GetDurationFromIntMillis(GRPC_ARG_PRIORITY_FAILOVER_TIMEOUT_MS) .value_or(kDefaultChildFailoverTimeout))) { - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << this << "] created"; - } + GRPC_TRACE_LOG(priority_lb, INFO) << "[priority_lb " << this << "] created"; } PriorityLb::~PriorityLb() { - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << this << "] destroying priority LB policy"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << this << "] destroying priority LB policy"; } void PriorityLb::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << this << "] shutting down"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << this << "] shutting down"; shutting_down_ = true; children_.clear(); } @@ -316,11 +312,9 @@ void PriorityLb::ShutdownLocked() { void PriorityLb::ExitIdleLocked() { if (current_priority_ != UINT32_MAX) { const std::string& child_name = config_->priorities()[current_priority_]; - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << this - << "] exiting IDLE for current priority " << current_priority_ - << " child " << child_name; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << this << "] exiting IDLE for current priority " + << current_priority_ << " child " << child_name; children_[child_name]->ExitIdleLocked(); } } @@ -330,9 +324,8 @@ void PriorityLb::ResetBackoffLocked() { } absl::Status PriorityLb::UpdateLocked(UpdateArgs args) { - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << this << "] received update"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << this << "] received update"; // Update config. config_ = args.config.TakeAsSubclass(); // Update args. @@ -402,10 +395,9 @@ void PriorityLb::ChoosePriorityLocked() { ++priority) { // If the child for the priority does not exist yet, create it. const std::string& child_name = config_->priorities()[priority]; - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << this << "] trying priority " << priority - << ", child " << child_name; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << this << "] trying priority " << priority + << ", child " << child_name; auto& child = children_[child_name]; // Create child if needed. if (child == nullptr) { @@ -443,28 +435,25 @@ void PriorityLb::ChoosePriorityLocked() { return; } // Child has been failing for a while. Move on to the next priority. - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << this << "] skipping priority " << priority - << ", child " << child_name << ": state=" - << ConnectivityStateName(child->connectivity_state()) - << ", failover timer not pending"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << this << "] skipping priority " << priority + << ", child " << child_name + << ": state=" << ConnectivityStateName(child->connectivity_state()) + << ", failover timer not pending"; } // If we didn't find any priority to try, pick the first one in state // CONNECTING. - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << this - << "] no priority reachable, checking for CONNECTING priority to " - "delegate to"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << this + << "] no priority reachable, checking for CONNECTING priority to " + "delegate to"; for (uint32_t priority = 0; priority < config_->priorities().size(); ++priority) { // If the child for the priority does not exist yet, create it. const std::string& child_name = config_->priorities()[priority]; - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << this << "] trying priority " << priority - << ", child " << child_name; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << this << "] trying priority " << priority + << ", child " << child_name; auto& child = children_[child_name]; CHECK(child != nullptr); if (child->connectivity_state() == GRPC_CHANNEL_CONNECTING) { @@ -482,12 +471,10 @@ void PriorityLb::ChoosePriorityLocked() { void PriorityLb::SetCurrentPriorityLocked(int32_t priority, bool deactivate_lower_priorities, const char* reason) { - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << this << "] selecting priority " << priority - << ", child " << config_->priorities()[priority] << " (" << reason - << ", deactivate_lower_priorities=" << deactivate_lower_priorities - << ")"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << this << "] selecting priority " << priority + << ", child " << config_->priorities()[priority] << " (" << reason + << ", deactivate_lower_priorities=" << deactivate_lower_priorities << ")"; current_priority_ = priority; if (deactivate_lower_priorities) { for (uint32_t p = priority + 1; p < config_->priorities().size(); ++p) { @@ -510,12 +497,11 @@ void PriorityLb::SetCurrentPriorityLocked(int32_t priority, PriorityLb::ChildPriority::DeactivationTimer::DeactivationTimer( RefCountedPtr child_priority) : child_priority_(std::move(child_priority)) { - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << child_priority_->priority_policy_.get() - << "] child " << child_priority_->name_ << " (" - << child_priority_.get() << "): deactivating -- will remove in " - << kChildRetentionInterval.millis() << "ms"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << child_priority_->priority_policy_.get() + << "] child " << child_priority_->name_ << " (" << child_priority_.get() + << "): deactivating -- will remove in " + << kChildRetentionInterval.millis() << "ms"; timer_handle_ = child_priority_->priority_policy_->channel_control_helper() ->GetEventEngine() @@ -532,11 +518,10 @@ PriorityLb::ChildPriority::DeactivationTimer::DeactivationTimer( void PriorityLb::ChildPriority::DeactivationTimer::Orphan() { if (timer_handle_.has_value()) { - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << child_priority_->priority_policy_.get() - << "] child " << child_priority_->name_ << " (" - << child_priority_.get() << "): reactivating"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << child_priority_->priority_policy_.get() + << "] child " << child_priority_->name_ << " (" << child_priority_.get() + << "): reactivating"; child_priority_->priority_policy_->channel_control_helper() ->GetEventEngine() ->Cancel(*timer_handle_); @@ -548,12 +533,10 @@ void PriorityLb::ChildPriority::DeactivationTimer::Orphan() { void PriorityLb::ChildPriority::DeactivationTimer::OnTimerLocked() { if (timer_handle_.has_value()) { timer_handle_.reset(); - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << child_priority_->priority_policy_.get() - << "] child " << child_priority_->name_ << " (" - << child_priority_.get() - << "): deactivation timer fired, deleting child"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << child_priority_->priority_policy_.get() + << "] child " << child_priority_->name_ << " (" << child_priority_.get() + << "): deactivation timer fired, deleting child"; child_priority_->priority_policy_->DeleteChild(child_priority_.get()); } } @@ -565,14 +548,12 @@ void PriorityLb::ChildPriority::DeactivationTimer::OnTimerLocked() { PriorityLb::ChildPriority::FailoverTimer::FailoverTimer( RefCountedPtr child_priority) : child_priority_(std::move(child_priority)) { - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) - << "[priority_lb " << child_priority_->priority_policy_.get() - << "] child " << child_priority_->name_ << " (" << child_priority_.get() - << "): starting failover timer for " - << child_priority_->priority_policy_->child_failover_timeout_.millis() - << "ms"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << child_priority_->priority_policy_.get() + << "] child " << child_priority_->name_ << " (" << child_priority_.get() + << "): starting failover timer for " + << child_priority_->priority_policy_->child_failover_timeout_.millis() + << "ms"; timer_handle_ = child_priority_->priority_policy_->channel_control_helper() ->GetEventEngine() @@ -590,11 +571,10 @@ PriorityLb::ChildPriority::FailoverTimer::FailoverTimer( void PriorityLb::ChildPriority::FailoverTimer::Orphan() { if (timer_handle_.has_value()) { - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << child_priority_->priority_policy_.get() - << "] child " << child_priority_->name_ << " (" - << child_priority_.get() << "): cancelling failover timer"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << child_priority_->priority_policy_.get() + << "] child " << child_priority_->name_ << " (" << child_priority_.get() + << "): cancelling failover timer"; child_priority_->priority_policy_->channel_control_helper() ->GetEventEngine() ->Cancel(*timer_handle_); @@ -606,12 +586,10 @@ void PriorityLb::ChildPriority::FailoverTimer::Orphan() { void PriorityLb::ChildPriority::FailoverTimer::OnTimerLocked() { if (timer_handle_.has_value()) { timer_handle_.reset(); - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << child_priority_->priority_policy_.get() - << "] child " << child_priority_->name_ << " (" - << child_priority_.get() - << "): failover timer fired, reporting TRANSIENT_FAILURE"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << child_priority_->priority_policy_.get() + << "] child " << child_priority_->name_ << " (" << child_priority_.get() + << "): failover timer fired, reporting TRANSIENT_FAILURE"; child_priority_->OnConnectivityStateUpdateLocked( GRPC_CHANNEL_TRANSIENT_FAILURE, absl::Status(absl::StatusCode::kUnavailable, "failover timer fired"), @@ -626,19 +604,17 @@ void PriorityLb::ChildPriority::FailoverTimer::OnTimerLocked() { PriorityLb::ChildPriority::ChildPriority( RefCountedPtr priority_policy, std::string name) : priority_policy_(std::move(priority_policy)), name_(std::move(name)) { - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << priority_policy_.get() - << "] creating child " << name_ << " (" << this << ")"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << priority_policy_.get() << "] creating child " + << name_ << " (" << this << ")"; // Start the failover timer. failover_timer_ = MakeOrphanable(Ref()); } void PriorityLb::ChildPriority::Orphan() { - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << priority_policy_.get() << "] child " - << name_ << " (" << this << "): orphaned"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << priority_policy_.get() << "] child " << name_ + << " (" << this << "): orphaned"; failover_timer_.reset(); deactivation_timer_.reset(); // Remove the child policy's interested_parties pollset_set from the @@ -665,10 +641,9 @@ absl::Status PriorityLb::ChildPriority::UpdateLocked( RefCountedPtr config, bool ignore_reresolution_requests) { if (priority_policy_->shutting_down_) return absl::OkStatus(); - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << priority_policy_.get() << "] child " - << name_ << " (" << this << "): start update"; - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << priority_policy_.get() << "] child " << name_ + << " (" << this << "): start update"; ignore_reresolution_requests_ = ignore_reresolution_requests; // Create policy if needed. if (child_policy_ == nullptr) { @@ -691,11 +666,10 @@ absl::Status PriorityLb::ChildPriority::UpdateLocked( update_args.resolution_note = priority_policy_->resolution_note_; update_args.args = priority_policy_->args_; // Update the policy. - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << priority_policy_.get() << "] child " - << name_ << " (" << this << "): updating child policy handler " - << child_policy_.get(); - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << priority_policy_.get() << "] child " << name_ + << " (" << this << "): updating child policy handler " + << child_policy_.get(); return child_policy_->UpdateLocked(std::move(update_args)); } @@ -709,11 +683,10 @@ PriorityLb::ChildPriority::CreateChildPolicyLocked(const ChannelArgs& args) { OrphanablePtr lb_policy = MakeOrphanable(std::move(lb_policy_args), &priority_lb_trace); - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << priority_policy_.get() << "] child " - << name_ << " (" << this << "): created new child policy handler " - << lb_policy.get(); - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << priority_policy_.get() << "] child " << name_ + << " (" << this << "): created new child policy handler " + << lb_policy.get(); // Add the parent's interested_parties pollset_set to that of the newly // created child policy. This will make the child policy progress upon // activity on the parent LB, which in turn is tied to the application's call. @@ -733,12 +706,10 @@ void PriorityLb::ChildPriority::ResetBackoffLocked() { void PriorityLb::ChildPriority::OnConnectivityStateUpdateLocked( grpc_connectivity_state state, const absl::Status& status, RefCountedPtr picker) { - if (GRPC_TRACE_FLAG_ENABLED(priority_lb)) { - LOG(INFO) << "[priority_lb " << priority_policy_.get() << "] child " - << name_ << " (" << this - << "): state update: " << ConnectivityStateName(state) << " (" - << status << ") picker " << picker.get(); - } + GRPC_TRACE_LOG(priority_lb, INFO) + << "[priority_lb " << priority_policy_.get() << "] child " << name_ + << " (" << this << "): state update: " << ConnectivityStateName(state) + << " (" << status << ") picker " << picker.get(); // Store the state and picker. connectivity_state_ = state; connectivity_status_ = status; diff --git a/src/core/load_balancing/ring_hash/ring_hash.cc b/src/core/load_balancing/ring_hash/ring_hash.cc index 215e41d84d..da108603a0 100644 --- a/src/core/load_balancing/ring_hash/ring_hash.cc +++ b/src/core/load_balancing/ring_hash/ring_hash.cc @@ -570,15 +570,13 @@ absl::Status RingHash::RingHashEndpoint::UpdateChildPolicyLocked() { void RingHash::RingHashEndpoint::OnStateUpdate( grpc_connectivity_state new_state, const absl::Status& status, RefCountedPtr picker) { - if (GRPC_TRACE_FLAG_ENABLED(ring_hash_lb)) { - LOG(INFO) << "[RH " << ring_hash_.get() - << "] connectivity changed for endpoint " << this << " (" - << ring_hash_->endpoints_[index_].ToString() - << ", child_policy=" << child_policy_.get() - << "): prev_state=" << ConnectivityStateName(connectivity_state_) - << " new_state=" << ConnectivityStateName(new_state) << " (" - << status << ")"; - } + GRPC_TRACE_LOG(ring_hash_lb, INFO) + << "[RH " << ring_hash_.get() << "] connectivity changed for endpoint " + << this << " (" << ring_hash_->endpoints_[index_].ToString() + << ", child_policy=" << child_policy_.get() + << "): prev_state=" << ConnectivityStateName(connectivity_state_) + << " new_state=" << ConnectivityStateName(new_state) << " (" << status + << ")"; if (child_policy_ == nullptr) return; // Already orphaned. // Update state. const bool entered_transient_failure = @@ -597,21 +595,16 @@ void RingHash::RingHashEndpoint::OnStateUpdate( // RingHash::RingHash(Args args) : LoadBalancingPolicy(std::move(args)) { - if (GRPC_TRACE_FLAG_ENABLED(ring_hash_lb)) { - LOG(INFO) << "[RH " << this << "] Created"; - } + GRPC_TRACE_LOG(ring_hash_lb, INFO) << "[RH " << this << "] Created"; } RingHash::~RingHash() { - if (GRPC_TRACE_FLAG_ENABLED(ring_hash_lb)) { - LOG(INFO) << "[RH " << this << "] Destroying Ring Hash policy"; - } + GRPC_TRACE_LOG(ring_hash_lb, INFO) + << "[RH " << this << "] Destroying Ring Hash policy"; } void RingHash::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(ring_hash_lb)) { - LOG(INFO) << "[RH " << this << "] Shutting down"; - } + GRPC_TRACE_LOG(ring_hash_lb, INFO) << "[RH " << this << "] Shutting down"; shutdown_ = true; endpoint_map_.clear(); } @@ -625,9 +618,7 @@ void RingHash::ResetBackoffLocked() { absl::Status RingHash::UpdateLocked(UpdateArgs args) { // Check address list. if (args.addresses.ok()) { - if (GRPC_TRACE_FLAG_ENABLED(ring_hash_lb)) { - LOG(INFO) << "[RH " << this << "] received update"; - } + GRPC_TRACE_LOG(ring_hash_lb, INFO) << "[RH " << this << "] received update"; // De-dup endpoints, taking weight into account. endpoints_.clear(); std::map endpoint_indices; @@ -641,11 +632,10 @@ absl::Status RingHash::UpdateLocked(UpdateArgs args) { endpoint.args().GetInt(GRPC_ARG_ADDRESS_WEIGHT).value_or(1); int prev_weight_arg = prev_endpoint.args().GetInt(GRPC_ARG_ADDRESS_WEIGHT).value_or(1); - if (GRPC_TRACE_FLAG_ENABLED(ring_hash_lb)) { - LOG(INFO) << "[RH " << this << "] merging duplicate endpoint for " - << key.ToString() << ", combined weight " - << weight_arg + prev_weight_arg; - } + GRPC_TRACE_LOG(ring_hash_lb, INFO) + << "[RH " << this << "] merging duplicate endpoint for " + << key.ToString() << ", combined weight " + << weight_arg + prev_weight_arg; prev_endpoint = EndpointAddresses( prev_endpoint.addresses(), prev_endpoint.args().Set(GRPC_ARG_ADDRESS_WEIGHT, @@ -655,10 +645,9 @@ absl::Status RingHash::UpdateLocked(UpdateArgs args) { } }); } else { - if (GRPC_TRACE_FLAG_ENABLED(ring_hash_lb)) { - LOG(INFO) << "[RH " << this << "] received update with addresses error: " - << args.addresses.status(); - } + GRPC_TRACE_LOG(ring_hash_lb, INFO) + << "[RH " << this << "] received update with addresses error: " + << args.addresses.status(); // If we already have an endpoint list, then keep using the existing // list, but still report back that the update was not accepted. if (!endpoints_.empty()) return args.addresses.status(); @@ -765,15 +754,13 @@ void RingHash::UpdateAggregatedConnectivityStateLocked( state = GRPC_CHANNEL_TRANSIENT_FAILURE; start_connection_attempt = true; } - if (GRPC_TRACE_FLAG_ENABLED(ring_hash_lb)) { - LOG(INFO) << "[RH " << this << "] setting connectivity state to " - << ConnectivityStateName(state) << " (num_idle=" << num_idle - << ", num_connecting=" << num_connecting - << ", num_ready=" << num_ready - << ", num_transient_failure=" << num_transient_failure - << ", size=" << endpoints_.size() - << ") -- start_connection_attempt=" << start_connection_attempt; - } + GRPC_TRACE_LOG(ring_hash_lb, INFO) + << "[RH " << this << "] setting connectivity state to " + << ConnectivityStateName(state) << " (num_idle=" << num_idle + << ", num_connecting=" << num_connecting << ", num_ready=" << num_ready + << ", num_transient_failure=" << num_transient_failure + << ", size=" << endpoints_.size() + << ") -- start_connection_attempt=" << start_connection_attempt; // In TRANSIENT_FAILURE, report the last reported failure. // Otherwise, report OK. if (state == GRPC_CHANNEL_TRANSIENT_FAILURE) { @@ -842,13 +829,12 @@ void RingHash::UpdateAggregatedConnectivityStateLocked( auto it = endpoint_map_.find( EndpointAddressSet(endpoints_[first_idle_index].addresses())); CHECK(it != endpoint_map_.end()); - if (GRPC_TRACE_FLAG_ENABLED(ring_hash_lb)) { - LOG(INFO) << "[RH " << this - << "] triggering internal connection attempt for endpoint " - << it->second.get() << " (" - << endpoints_[first_idle_index].ToString() << ") (index " - << first_idle_index << " of " << endpoints_.size() << ")"; - } + GRPC_TRACE_LOG(ring_hash_lb, INFO) + << "[RH " << this + << "] triggering internal connection attempt for endpoint " + << it->second.get() << " (" << endpoints_[first_idle_index].ToString() + << ") (index " << first_idle_index << " of " << endpoints_.size() + << ")"; it->second->RequestConnectionLocked(); } } diff --git a/src/core/load_balancing/rls/rls.cc b/src/core/load_balancing/rls/rls.cc index 9b532bccf0..9138d94e97 100644 --- a/src/core/load_balancing/rls/rls.cc +++ b/src/core/load_balancing/rls/rls.cc @@ -353,7 +353,8 @@ class RlsLb final : public LoadBalancingPolicy { // is called after releasing it. // // Both methods grab the data they need from the parent object. - void StartUpdate() ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_); + void StartUpdate(OrphanablePtr* child_policy_to_delete) + ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_); absl::Status MaybeFinishUpdate() ABSL_LOCKS_EXCLUDED(&RlsLb::mu_); void ExitIdleLocked() { @@ -397,14 +398,14 @@ class RlsLb final : public LoadBalancingPolicy { }; // Note: We are forced to disable lock analysis here because - // Orphan() is called by Unref() which is called by RefCountedPtr<>, which + // Orphaned() is called by Unref() which is called by RefCountedPtr<>, which // cannot have lock annotations for this particular caller. void Orphaned() override ABSL_NO_THREAD_SAFETY_ANALYSIS; RefCountedPtr lb_policy_; std::string target_; - bool is_shutdown_ = false; + bool is_shutdown_ = false; // Protected by WorkSerializer OrphanablePtr child_policy_; RefCountedPtr pending_config_; @@ -503,12 +504,25 @@ class RlsLb final : public LoadBalancingPolicy { // Returns a list of child policy wrappers on which FinishUpdate() // needs to be called after releasing the lock. std::vector OnRlsResponseLocked( - ResponseInfo response, std::unique_ptr backoff_state) + ResponseInfo response, std::unique_ptr backoff_state, + OrphanablePtr* child_policy_to_delete) ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_); // Moves entry to the end of the LRU list. void MarkUsed() ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_); + // Takes entries from child_policy_wrappers_ and appends them to the end + // of \a child_policy_wrappers. + void TakeChildPolicyWrappers( + std::vector>* child_policy_wrappers) + ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_) { + child_policy_wrappers->insert( + child_policy_wrappers->end(), + std::make_move_iterator(child_policy_wrappers_.begin()), + std::make_move_iterator(child_policy_wrappers_.end())); + child_policy_wrappers_.clear(); + } + private: class BackoffTimer final : public InternallyRefCounted { public: @@ -566,19 +580,24 @@ class RlsLb final : public LoadBalancingPolicy { // the caller. Otherwise, the entry found is returned to the caller. The // entry returned to the user is considered recently used and its order in // the LRU list of the cache is updated. - Entry* FindOrInsert(const RequestKey& key) + Entry* FindOrInsert(const RequestKey& key, + std::vector>* + child_policy_wrappers_to_delete) ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_); // Resizes the cache. If the new cache size is greater than the current size // of the cache, do nothing. Otherwise, evict the oldest entries that // exceed the new size limit of the cache. - void Resize(size_t bytes) ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_); + void Resize(size_t bytes, std::vector>* + child_policy_wrappers_to_delete) + ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_); // Resets backoff of all the cache entries. void ResetAllBackoff() ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_); // Shutdown the cache; clean-up and orphan all the stored cache entries. - void Shutdown() ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_); + GRPC_MUST_USE_RESULT std::vector> + Shutdown() ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_); void ReportMetricsLocked(CallbackMetricReporter& reporter) ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_); @@ -594,7 +613,9 @@ class RlsLb final : public LoadBalancingPolicy { // Evicts oversized cache elements when the current size is greater than // the specified limit. - void MaybeShrinkSize(size_t bytes) + void MaybeShrinkSize(size_t bytes, + std::vector>* + child_policy_wrappers_to_delete) ABSL_EXCLUSIVE_LOCKS_REQUIRED(&RlsLb::mu_); RlsLb* lb_policy_; @@ -805,11 +826,9 @@ RlsLb::ChildPolicyWrapper::ChildPolicyWrapper(RefCountedPtr lb_policy, } void RlsLb::ChildPolicyWrapper::Orphaned() { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() - << "] ChildPolicyWrapper=" << this << " [" << target_ - << "]: shutdown"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] ChildPolicyWrapper=" << this + << " [" << target_ << "]: shutdown"; is_shutdown_ = true; lb_policy_->child_policy_map_.erase(target_); if (child_policy_ != nullptr) { @@ -859,32 +878,29 @@ absl::optional InsertOrUpdateChildPolicyField(const std::string& field, return Json::FromArray(std::move(array)); } -void RlsLb::ChildPolicyWrapper::StartUpdate() { +void RlsLb::ChildPolicyWrapper::StartUpdate( + OrphanablePtr* child_policy_to_delete) { ValidationErrors errors; auto child_policy_config = InsertOrUpdateChildPolicyField( lb_policy_->config_->child_policy_config_target_field_name(), target_, lb_policy_->config_->child_policy_config(), &errors); CHECK(child_policy_config.has_value()); - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() - << "] ChildPolicyWrapper=" << this << " [" << target_ - << "]: validating update, config: " - << JsonDump(*child_policy_config); - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] ChildPolicyWrapper=" << this + << " [" << target_ + << "]: validating update, config: " << JsonDump(*child_policy_config); auto config = CoreConfiguration::Get().lb_policy_registry().ParseLoadBalancingConfig( *child_policy_config); // Returned RLS target fails the validation. if (!config.ok()) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() - << "] ChildPolicyWrapper=" << this << " [" << target_ - << "]: config failed to parse: " << config.status(); - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] ChildPolicyWrapper=" << this + << " [" << target_ << "]: config failed to parse: " << config.status(); pending_config_.reset(); picker_ = MakeRefCounted( absl::UnavailableError(config.status().message())); - child_policy_.reset(); + *child_policy_to_delete = std::move(child_policy_); } else { pending_config_ = std::move(*config); } @@ -903,21 +919,18 @@ absl::Status RlsLb::ChildPolicyWrapper::MaybeFinishUpdate() { create_args.args = lb_policy_->channel_args_; child_policy_ = MakeOrphanable(std::move(create_args), &rls_lb_trace); - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() - << "] ChildPolicyWrapper=" << this << " [" << target_ - << "], created new child policy handler " - << child_policy_.get(); - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] ChildPolicyWrapper=" << this + << " [" << target_ << "], created new child policy handler " + << child_policy_.get(); grpc_pollset_set_add_pollset_set(child_policy_->interested_parties(), lb_policy_->interested_parties()); } // Send the child the updated config. - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() - << "] ChildPolicyWrapper=" << this << " [" << target_ - << "], updating child policy handler " << child_policy_.get(); - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] ChildPolicyWrapper=" << this + << " [" << target_ << "], updating child policy handler " + << child_policy_.get(); UpdateArgs update_args; update_args.config = std::move(pending_config_); update_args.addresses = lb_policy_->addresses_; @@ -932,16 +945,15 @@ absl::Status RlsLb::ChildPolicyWrapper::MaybeFinishUpdate() { void RlsLb::ChildPolicyWrapper::ChildPolicyHelper::UpdateState( grpc_connectivity_state state, const absl::Status& status, RefCountedPtr picker) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << wrapper_->lb_policy_.get() - << "] ChildPolicyWrapper=" << wrapper_.get() << " [" - << wrapper_->target_ << "] ChildPolicyHelper=" << this - << ": UpdateState(state=" << ConnectivityStateName(state) - << ", status=" << status << ", picker=" << picker.get() << ")"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << wrapper_->lb_policy_.get() + << "] ChildPolicyWrapper=" << wrapper_.get() << " [" << wrapper_->target_ + << "] ChildPolicyHelper=" << this + << ": UpdateState(state=" << ConnectivityStateName(state) + << ", status=" << status << ", picker=" << picker.get() << ")"; + if (wrapper_->is_shutdown_) return; { MutexLock lock(&wrapper_->lb_policy_->mu_); - if (wrapper_->is_shutdown_) return; // TODO(roth): It looks like this ignores subsequent TF updates that // might change the status used to fail picks, which seems wrong. if (wrapper_->connectivity_state_ == GRPC_CHANNEL_TRANSIENT_FAILURE && @@ -951,7 +963,8 @@ void RlsLb::ChildPolicyWrapper::ChildPolicyHelper::UpdateState( wrapper_->connectivity_state_ = state; DCHECK(picker != nullptr); if (picker != nullptr) { - wrapper_->picker_ = std::move(picker); + // We want to unref the picker after we release the lock. + wrapper_->picker_.swap(picker); } } wrapper_->lb_policy_->UpdatePickerLocked(); @@ -1039,10 +1052,9 @@ LoadBalancingPolicy::PickResult RlsLb::Picker::Pick(PickArgs args) { BuildKeyMap(config_->key_builder_map(), args.path, lb_policy_->channel_control_helper()->GetAuthority(), args.initial_metadata)}; - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() << "] picker=" << this - << ": request keys: " << key.ToString(); - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] picker=" << this + << ": request keys: " << key.ToString(); Timestamp now = Timestamp::Now(); MutexLock lock(&lb_policy_->mu_); if (lb_policy_->is_shutdown_) { @@ -1077,10 +1089,9 @@ LoadBalancingPolicy::PickResult RlsLb::Picker::Pick(PickArgs args) { if (entry != nullptr) { // If the entry has non-expired data, use it. if (entry->data_expiration_time() >= now) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() << "] picker=" << this - << ": using cache entry " << entry; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] picker=" << this + << ": using cache entry " << entry; return entry->Pick(args); } // If the entry is in backoff, then use the default target if set, @@ -1093,29 +1104,26 @@ LoadBalancingPolicy::PickResult RlsLb::Picker::Pick(PickArgs args) { } } // RLS call pending. Queue the pick. - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() << "] picker=" << this - << ": RLS request pending; queuing pick"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] picker=" << this + << ": RLS request pending; queuing pick"; return PickResult::Queue(); } LoadBalancingPolicy::PickResult RlsLb::Picker::PickFromDefaultTargetOrFail( const char* reason, PickArgs args, absl::Status status) { if (default_child_policy_ != nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() << "] picker=" << this << ": " - << reason << "; using default target"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] picker=" << this << ": " + << reason << "; using default target"; auto pick_result = default_child_policy_->Pick(args); lb_policy_->MaybeExportPickCount(kMetricDefaultTargetPicks, config_->default_target(), pick_result); return pick_result; } - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() << "] picker=" << this << ": " - << reason << "; failing pick"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] picker=" << this << ": " << reason + << "; failing pick"; auto& stats_plugins = lb_policy_->channel_control_helper()->GetStatsPluginGroup(); stats_plugins.AddCounter(kMetricFailedPicks, 1, @@ -1149,13 +1157,12 @@ void RlsLb::Cache::Entry::BackoffTimer::Orphan() { if (backoff_timer_task_handle_.has_value() && entry_->lb_policy_->channel_control_helper()->GetEventEngine()->Cancel( *backoff_timer_task_handle_)) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << entry_->lb_policy_.get() - << "] cache entry=" << entry_.get() << " " - << (entry_->is_shutdown_ ? "(shut down)" - : entry_->lru_iterator_->ToString()) - << ", backoff timer canceled"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << entry_->lb_policy_.get() + << "] cache entry=" << entry_.get() << " " + << (entry_->is_shutdown_ ? "(shut down)" + : entry_->lru_iterator_->ToString()) + << ", backoff timer canceled"; } backoff_timer_task_handle_.reset(); Unref(DEBUG_LOCATION, "Orphan"); @@ -1164,13 +1171,12 @@ void RlsLb::Cache::Entry::BackoffTimer::Orphan() { void RlsLb::Cache::Entry::BackoffTimer::OnBackoffTimerLocked() { { MutexLock lock(&entry_->lb_policy_->mu_); - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << entry_->lb_policy_.get() - << "] cache entry=" << entry_.get() << " " - << (entry_->is_shutdown_ ? "(shut down)" - : entry_->lru_iterator_->ToString()) - << ", backoff timer fired"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << entry_->lb_policy_.get() + << "] cache entry=" << entry_.get() << " " + << (entry_->is_shutdown_ ? "(shut down)" + : entry_->lru_iterator_->ToString()) + << ", backoff timer fired"; // Skip the update if Orphaned if (!backoff_timer_task_handle_.has_value()) return; backoff_timer_task_handle_.reset(); @@ -1204,19 +1210,19 @@ RlsLb::Cache::Entry::Entry(RefCountedPtr lb_policy, lb_policy_->cache_.lru_list_.end(), key)) {} void RlsLb::Cache::Entry::Orphan() { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() << "] cache entry=" << this - << " " << lru_iterator_->ToString() << ": cache entry evicted"; - } + // We should be holding RlsLB::mu_. + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] cache entry=" << this << " " + << lru_iterator_->ToString() << ": cache entry evicted"; is_shutdown_ = true; lb_policy_->cache_.lru_list_.erase(lru_iterator_); lru_iterator_ = lb_policy_->cache_.lru_list_.end(); // Just in case. + CHECK(child_policy_wrappers_.empty()); backoff_state_.reset(); if (backoff_timer_ != nullptr) { backoff_timer_.reset(); lb_policy_->UpdatePickerAsync(); } - child_policy_wrappers_.clear(); Unref(DEBUG_LOCATION, "Orphan"); } @@ -1235,28 +1241,25 @@ LoadBalancingPolicy::PickResult RlsLb::Cache::Entry::Pick(PickArgs args) { if (child_policy_wrapper->connectivity_state() == GRPC_CHANNEL_TRANSIENT_FAILURE && i < child_policy_wrappers_.size() - 1) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() << "] cache entry=" << this - << " " << lru_iterator_->ToString() << ": target " - << child_policy_wrapper->target() << " (" << i << " of " - << child_policy_wrappers_.size() - << ") in state TRANSIENT_FAILURE; skipping"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] cache entry=" << this << " " + << lru_iterator_->ToString() << ": target " + << child_policy_wrapper->target() << " (" << i << " of " + << child_policy_wrappers_.size() + << ") in state TRANSIENT_FAILURE; skipping"; continue; } break; } // Child policy not in TRANSIENT_FAILURE or is the last target in // the list, so delegate. - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() << "] cache entry=" << this - << " " << lru_iterator_->ToString() << ": target " - << child_policy_wrapper->target() << " (" << i << " of " - << child_policy_wrappers_.size() << ") in state " - << ConnectivityStateName( - child_policy_wrapper->connectivity_state()) - << "; delegating"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] cache entry=" << this << " " + << lru_iterator_->ToString() << ": target " + << child_policy_wrapper->target() << " (" << i << " of " + << child_policy_wrappers_.size() << ") in state " + << ConnectivityStateName(child_policy_wrapper->connectivity_state()) + << "; delegating"; auto pick_result = child_policy_wrapper->Pick(args); lb_policy_->MaybeExportPickCount(kMetricTargetPicks, child_policy_wrapper->target(), pick_result); @@ -1295,7 +1298,8 @@ void RlsLb::Cache::Entry::MarkUsed() { std::vector RlsLb::Cache::Entry::OnRlsResponseLocked( - ResponseInfo response, std::unique_ptr backoff_state) { + ResponseInfo response, std::unique_ptr backoff_state, + OrphanablePtr* child_policy_to_delete) { // Move the entry to the end of the LRU list. MarkUsed(); // If the request failed, store the failed status and update the @@ -1356,7 +1360,7 @@ RlsLb::Cache::Entry::OnRlsResponseLocked( if (it == lb_policy_->child_policy_map_.end()) { auto new_child = MakeRefCounted( lb_policy_.Ref(DEBUG_LOCATION, "ChildPolicyWrapper"), target); - new_child->StartUpdate(); + new_child->StartUpdate(child_policy_to_delete); child_policies_to_finish_update.push_back(new_child.get()); new_child_policy_wrappers.emplace_back(std::move(new_child)); } else { @@ -1393,38 +1397,39 @@ RlsLb::Cache::Entry* RlsLb::Cache::Find(const RequestKey& key) { return it->second.get(); } -RlsLb::Cache::Entry* RlsLb::Cache::FindOrInsert(const RequestKey& key) { +RlsLb::Cache::Entry* RlsLb::Cache::FindOrInsert( + const RequestKey& key, std::vector>* + child_policy_wrappers_to_delete) { auto it = map_.find(key); // If not found, create new entry. if (it == map_.end()) { size_t entry_size = EntrySizeForKey(key); - MaybeShrinkSize(size_limit_ - std::min(size_limit_, entry_size)); + MaybeShrinkSize(size_limit_ - std::min(size_limit_, entry_size), + child_policy_wrappers_to_delete); Entry* entry = new Entry( lb_policy_->RefAsSubclass(DEBUG_LOCATION, "CacheEntry"), key); map_.emplace(key, OrphanablePtr(entry)); size_ += entry_size; - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_ << "] key=" << key.ToString() - << ": cache entry added, entry=" << entry; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_ << "] key=" << key.ToString() + << ": cache entry added, entry=" << entry; return entry; } // Entry found, so use it. - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_ << "] key=" << key.ToString() - << ": found cache entry " << it->second.get(); - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_ << "] key=" << key.ToString() + << ": found cache entry " << it->second.get(); it->second->MarkUsed(); return it->second.get(); } -void RlsLb::Cache::Resize(size_t bytes) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_ << "] resizing cache to " << bytes - << " bytes"; - } +void RlsLb::Cache::Resize(size_t bytes, + std::vector>* + child_policy_wrappers_to_delete) { + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_ << "] resizing cache to " << bytes << " bytes"; size_limit_ = bytes; - MaybeShrinkSize(size_limit_); + MaybeShrinkSize(size_limit_, child_policy_wrappers_to_delete); } void RlsLb::Cache::ResetAllBackoff() { @@ -1434,17 +1439,22 @@ void RlsLb::Cache::ResetAllBackoff() { lb_policy_->UpdatePickerAsync(); } -void RlsLb::Cache::Shutdown() { +std::vector> RlsLb::Cache::Shutdown() { + std::vector> + child_policy_wrappers_to_delete; + for (auto& entry : map_) { + entry.second->TakeChildPolicyWrappers(&child_policy_wrappers_to_delete); + } map_.clear(); lru_list_.clear(); if (cleanup_timer_handle_.has_value() && lb_policy_->channel_control_helper()->GetEventEngine()->Cancel( *cleanup_timer_handle_)) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_ << "] cache cleanup timer canceled"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_ << "] cache cleanup timer canceled"; } cleanup_timer_handle_.reset(); + return child_policy_wrappers_to_delete; } void RlsLb::Cache::ReportMetricsLocked(CallbackMetricReporter& reporter) { @@ -1478,15 +1488,17 @@ void RlsLb::Cache::StartCleanupTimer() { } void RlsLb::Cache::OnCleanupTimer() { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_ << "] cache cleanup timer fired"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_ << "] cache cleanup timer fired"; + std::vector> + child_policy_wrappers_to_delete; MutexLock lock(&lb_policy_->mu_); if (!cleanup_timer_handle_.has_value()) return; if (lb_policy_->is_shutdown_) return; for (auto it = map_.begin(); it != map_.end();) { if (GPR_UNLIKELY(it->second->ShouldRemove() && it->second->CanEvict())) { size_ -= it->second->Size(); + it->second->TakeChildPolicyWrappers(&child_policy_wrappers_to_delete); it = map_.erase(it); } else { ++it; @@ -1500,25 +1512,25 @@ size_t RlsLb::Cache::EntrySizeForKey(const RequestKey& key) { return (key.Size() * 2) + sizeof(Entry); } -void RlsLb::Cache::MaybeShrinkSize(size_t bytes) { +void RlsLb::Cache::MaybeShrinkSize( + size_t bytes, std::vector>* + child_policy_wrappers_to_delete) { while (size_ > bytes) { auto lru_it = lru_list_.begin(); if (GPR_UNLIKELY(lru_it == lru_list_.end())) break; auto map_it = map_.find(*lru_it); CHECK(map_it != map_.end()); if (!map_it->second->CanEvict()) break; - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_ << "] LRU eviction: removing entry " - << map_it->second.get() << " " << lru_it->ToString(); - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_ << "] LRU eviction: removing entry " + << map_it->second.get() << " " << lru_it->ToString(); size_ -= map_it->second->Size(); + map_it->second->TakeChildPolicyWrappers(child_policy_wrappers_to_delete); map_.erase(map_it); } - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_ - << "] LRU pass complete: desired size=" << bytes - << " size=" << size_; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_ + << "] LRU pass complete: desired size=" << bytes << " size=" << size_; } // @@ -1528,11 +1540,10 @@ void RlsLb::Cache::MaybeShrinkSize(size_t bytes) { void RlsLb::RlsChannel::StateWatcher::OnConnectivityStateChange( grpc_connectivity_state new_state, const absl::Status& status) { auto* lb_policy = rls_channel_->lb_policy_.get(); - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy << "] RlsChannel=" << rls_channel_.get() - << " StateWatcher=" << this << ": state changed to " - << ConnectivityStateName(new_state) << " (" << status << ")"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy << "] RlsChannel=" << rls_channel_.get() + << " StateWatcher=" << this << ": state changed to " + << ConnectivityStateName(new_state) << " (" << status << ")"; if (rls_channel_->is_shutdown_) return; MutexLock lock(&lb_policy->mu_); if (new_state == GRPC_CHANNEL_READY && was_transient_failure_) { @@ -1625,11 +1636,10 @@ RlsLb::RlsChannel::RlsChannel(RefCountedPtr lb_policy) channel_.reset(Channel::FromC( grpc_channel_create(lb_policy_->config_->lookup_service().c_str(), creds.get(), args.ToC().get()))); - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() << "] RlsChannel=" << this - << ": created channel " << channel_.get() << " for " - << lb_policy_->config_->lookup_service(); - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] RlsChannel=" << this + << ": created channel " << channel_.get() << " for " + << lb_policy_->config_->lookup_service(); if (channel_ != nullptr) { // Set up channelz linkage. channelz::ChannelNode* child_channelz_node = channel_->channelz_node(); @@ -1648,10 +1658,9 @@ RlsLb::RlsChannel::RlsChannel(RefCountedPtr lb_policy) } void RlsLb::RlsChannel::Orphan() { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() << "] RlsChannel=" << this - << ", channel=" << channel_.get() << ": shutdown"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] RlsChannel=" << this + << ", channel=" << channel_.get() << ": shutdown"; is_shutdown_ = true; if (channel_ != nullptr) { // Remove channelz linkage. @@ -1715,10 +1724,9 @@ RlsLb::RlsRequest::RlsRequest( backoff_state_(std::move(backoff_state)), reason_(reason), stale_header_data_(std::move(stale_header_data)) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() << "] rls_request=" << this - << ": RLS request created for key " << key_.ToString(); - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] rls_request=" << this + << ": RLS request created for key " << key_.ToString(); GRPC_CLOSURE_INIT(&call_complete_cb_, OnRlsCallComplete, this, nullptr); ExecCtx::Run( DEBUG_LOCATION, @@ -1731,10 +1739,9 @@ RlsLb::RlsRequest::~RlsRequest() { CHECK_EQ(call_, nullptr); } void RlsLb::RlsRequest::Orphan() { if (call_ != nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() << "] rls_request=" << this - << " " << key_.ToString() << ": cancelling RLS call"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] rls_request=" << this << " " + << key_.ToString() << ": cancelling RLS call"; grpc_call_cancel_internal(call_); } Unref(DEBUG_LOCATION, "Orphan"); @@ -1835,19 +1842,22 @@ void RlsLb::RlsRequest::OnRlsCallCompleteLocked(grpc_error_handle error) { grpc_call_unref(call_); call_ = nullptr; // Return result to cache. - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << lb_policy_.get() << "] rls_request=" << this - << " " << key_.ToString() - << ": response info: " << response.ToString(); - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << lb_policy_.get() << "] rls_request=" << this << " " + << key_.ToString() << ": response info: " << response.ToString(); std::vector child_policies_to_finish_update; + std::vector> + child_policy_wrappers_to_delete; + OrphanablePtr child_policy_to_delete; { MutexLock lock(&lb_policy_->mu_); if (lb_policy_->is_shutdown_) return; rls_channel_->ReportResponseLocked(response.status.ok()); - Cache::Entry* cache_entry = lb_policy_->cache_.FindOrInsert(key_); + Cache::Entry* cache_entry = + lb_policy_->cache_.FindOrInsert(key_, &child_policy_wrappers_to_delete); child_policies_to_finish_update = cache_entry->OnRlsResponseLocked( - std::move(response), std::move(backoff_state_)); + std::move(response), std::move(backoff_state_), + &child_policy_to_delete); lb_policy_->request_map_.erase(key_); } // Now that we've released the lock, finish the update on any newly @@ -1946,17 +1956,8 @@ RlsLb::RlsLb(Args args) instance_uuid_(channel_args() .GetOwnedString(GRPC_ARG_TEST_ONLY_RLS_INSTANCE_ID) .value_or(GenerateUUID())), - cache_(this), - registered_metric_callback_( - channel_control_helper()->GetStatsPluginGroup().RegisterCallback( - [this](CallbackMetricReporter& reporter) { - MutexLock lock(&mu_); - cache_.ReportMetricsLocked(reporter); - }, - Duration::Seconds(5), kMetricCacheSize, kMetricCacheEntries)) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << this << "] policy created"; - } + cache_(this) { + GRPC_TRACE_LOG(rls_lb, INFO) << "[rlslb " << this << "] policy created"; } bool EndpointsEqual( @@ -1981,9 +1982,7 @@ bool EndpointsEqual( } absl::Status RlsLb::UpdateLocked(UpdateArgs args) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << this << "] policy updated"; - } + GRPC_TRACE_LOG(rls_lb, INFO) << "[rlslb " << this << "] policy updated"; update_in_progress_ = true; // Swap out config. RefCountedPtr old_config = std::move(config_); @@ -2016,31 +2015,30 @@ absl::Status RlsLb::UpdateLocked(UpdateArgs args) { if (old_config == nullptr || config_->default_target() != old_config->default_target()) { if (config_->default_target().empty()) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << this << "] unsetting default target"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << this << "] unsetting default target"; default_child_policy_.reset(); } else { auto it = child_policy_map_.find(config_->default_target()); if (it == child_policy_map_.end()) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << this << "] creating new default target"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << this << "] creating new default target"; default_child_policy_ = MakeRefCounted( RefAsSubclass(DEBUG_LOCATION, "ChildPolicyWrapper"), config_->default_target()); created_default_child = true; } else { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << this - << "] using existing child for default target"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << this << "] using existing child for default target"; default_child_policy_ = it->second->Ref(DEBUG_LOCATION, "DefaultChildPolicy"); } } } // Now grab the lock to swap out the state it guards. + std::vector> + child_policy_wrappers_to_delete; + OrphanablePtr child_policy_to_delete; { MutexLock lock(&mu_); // Swap out RLS channel if needed. @@ -2052,30 +2050,27 @@ absl::Status RlsLb::UpdateLocked(UpdateArgs args) { // Resize cache if needed. if (old_config == nullptr || config_->cache_size_bytes() != old_config->cache_size_bytes()) { - cache_.Resize(static_cast(config_->cache_size_bytes())); + cache_.Resize(static_cast(config_->cache_size_bytes()), + &child_policy_wrappers_to_delete); } // Start update of child policies if needed. if (update_child_policies) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << this << "] starting child policy updates"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << this << "] starting child policy updates"; for (auto& p : child_policy_map_) { - p.second->StartUpdate(); + p.second->StartUpdate(&child_policy_to_delete); } } else if (created_default_child) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << this - << "] starting default child policy update"; - } - default_child_policy_->StartUpdate(); + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << this << "] starting default child policy update"; + default_child_policy_->StartUpdate(&child_policy_to_delete); } } // Now that we've released the lock, finish update of child policies. std::vector errors; if (update_child_policies) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << this << "] finishing child policy updates"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << this << "] finishing child policy updates"; for (auto& p : child_policy_map_) { absl::Status status = p.second->MaybeFinishUpdate(); if (!status.ok()) { @@ -2084,10 +2079,8 @@ absl::Status RlsLb::UpdateLocked(UpdateArgs args) { } } } else if (created_default_child) { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << this - << "] finishing default child policy update"; - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << this << "] finishing default child policy update"; absl::Status status = default_child_policy_->MaybeFinishUpdate(); if (!status.ok()) { errors.emplace_back(absl::StrCat("target ", config_->default_target(), @@ -2095,6 +2088,20 @@ absl::Status RlsLb::UpdateLocked(UpdateArgs args) { } } update_in_progress_ = false; + // On the initial update only, we set the gauge metric callback. We + // can't do this before the initial update, because otherwise the + // callback could be invoked before we've set state that we need for + // the label values (e.g., we'd add metrics with empty string for the + // RLS server name). + if (registered_metric_callback_ == nullptr) { + registered_metric_callback_ = + channel_control_helper()->GetStatsPluginGroup().RegisterCallback( + [this](CallbackMetricReporter& reporter) { + MutexLock lock(&mu_); + cache_.ReportMetricsLocked(reporter); + }, + Duration::Seconds(5), kMetricCacheSize, kMetricCacheEntries); + } // In principle, we need to update the picker here only if the config // fields used by the picker have changed. However, it seems fragile // to check individual fields, since the picker logic could change in @@ -2129,18 +2136,22 @@ void RlsLb::ResetBackoffLocked() { } void RlsLb::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << this << "] policy shutdown"; - } + GRPC_TRACE_LOG(rls_lb, INFO) << "[rlslb " << this << "] policy shutdown"; registered_metric_callback_.reset(); - MutexLock lock(&mu_); - is_shutdown_ = true; - config_.reset(DEBUG_LOCATION, "ShutdownLocked"); + RefCountedPtr child_policy_to_delete; + std::vector> + child_policy_wrappers_to_delete; + OrphanablePtr rls_channel_to_delete; + { + MutexLock lock(&mu_); + is_shutdown_ = true; + config_.reset(DEBUG_LOCATION, "ShutdownLocked"); + child_policy_wrappers_to_delete = cache_.Shutdown(); + request_map_.clear(); + rls_channel_to_delete = std::move(rls_channel_); + child_policy_to_delete = std::move(default_child_policy_); + } channel_args_ = ChannelArgs(); - cache_.Shutdown(); - request_map_.clear(); - rls_channel_.reset(); - default_child_policy_.reset(); } void RlsLb::UpdatePickerAsync() { @@ -2173,9 +2184,7 @@ void RlsLb::UpdatePickerLocked() { // all children. This avoids unnecessary picker churn while an update // is being propagated to our children. if (update_in_progress_) return; - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << this << "] updating picker"; - } + GRPC_TRACE_LOG(rls_lb, INFO) << "[rlslb " << this << "] updating picker"; grpc_connectivity_state state = GRPC_CHANNEL_IDLE; if (!child_policy_map_.empty()) { state = GRPC_CHANNEL_TRANSIENT_FAILURE; @@ -2186,10 +2195,9 @@ void RlsLb::UpdatePickerLocked() { if (is_shutdown_) return; for (auto& p : child_policy_map_) { grpc_connectivity_state child_state = p.second->connectivity_state(); - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << this << "] target " << p.second->target() - << " in state " << ConnectivityStateName(child_state); - } + GRPC_TRACE_LOG(rls_lb, INFO) + << "[rlslb " << this << "] target " << p.second->target() + << " in state " << ConnectivityStateName(child_state); if (child_state == GRPC_CHANNEL_READY) { state = GRPC_CHANNEL_READY; break; @@ -2208,10 +2216,8 @@ void RlsLb::UpdatePickerLocked() { } } } - if (GRPC_TRACE_FLAG_ENABLED(rls_lb)) { - LOG(INFO) << "[rlslb " << this << "] reporting state " - << ConnectivityStateName(state); - } + GRPC_TRACE_LOG(rls_lb, INFO) << "[rlslb " << this << "] reporting state " + << ConnectivityStateName(state); absl::Status status; if (state == GRPC_CHANNEL_TRANSIENT_FAILURE) { status = absl::UnavailableError("no children available"); diff --git a/src/core/load_balancing/round_robin/round_robin.cc b/src/core/load_balancing/round_robin/round_robin.cc index 0aa66889ad..193c5a5582 100644 --- a/src/core/load_balancing/round_robin/round_robin.cc +++ b/src/core/load_balancing/round_robin/round_robin.cc @@ -35,7 +35,6 @@ #include "absl/types/optional.h" #include -#include #include #include "src/core/lib/channel/channel_args.h" @@ -185,22 +184,19 @@ RoundRobin::Picker::Picker( // the picker, see https://github.com/grpc/grpc-go/issues/2580. size_t index = absl::Uniform(parent->bit_gen_, 0, pickers_.size()); last_picked_index_.store(index, std::memory_order_relaxed); - if (GRPC_TRACE_FLAG_ENABLED(round_robin)) { - LOG(INFO) << "[RR " << parent_ << " picker " << this - << "] created picker from endpoint_list=" - << parent_->endpoint_list_.get() << " with " << pickers_.size() - << " READY children; last_picked_index_=" << index; - } + GRPC_TRACE_LOG(round_robin, INFO) + << "[RR " << parent_ << " picker " << this + << "] created picker from endpoint_list=" << parent_->endpoint_list_.get() + << " with " << pickers_.size() + << " READY children; last_picked_index_=" << index; } RoundRobin::PickResult RoundRobin::Picker::Pick(PickArgs args) { size_t index = last_picked_index_.fetch_add(1, std::memory_order_relaxed) % pickers_.size(); - if (GRPC_TRACE_FLAG_ENABLED(round_robin)) { - LOG(INFO) << "[RR " << parent_ << " picker " << this - << "] using picker index " << index - << ", picker=" << pickers_[index].get(); - } + GRPC_TRACE_LOG(round_robin, INFO) + << "[RR " << parent_ << " picker " << this << "] using picker index " + << index << ", picker=" << pickers_[index].get(); return pickers_[index]->Pick(args); } @@ -209,23 +205,18 @@ RoundRobin::PickResult RoundRobin::Picker::Pick(PickArgs args) { // RoundRobin::RoundRobin(Args args) : LoadBalancingPolicy(std::move(args)) { - if (GRPC_TRACE_FLAG_ENABLED(round_robin)) { - LOG(INFO) << "[RR " << this << "] Created"; - } + GRPC_TRACE_LOG(round_robin, INFO) << "[RR " << this << "] Created"; } RoundRobin::~RoundRobin() { - if (GRPC_TRACE_FLAG_ENABLED(round_robin)) { - LOG(INFO) << "[RR " << this << "] Destroying Round Robin policy"; - } + GRPC_TRACE_LOG(round_robin, INFO) + << "[RR " << this << "] Destroying Round Robin policy"; CHECK(endpoint_list_ == nullptr); CHECK(latest_pending_endpoint_list_ == nullptr); } void RoundRobin::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(round_robin)) { - LOG(INFO) << "[RR " << this << "] Shutting down"; - } + GRPC_TRACE_LOG(round_robin, INFO) << "[RR " << this << "] Shutting down"; shutdown_ = true; endpoint_list_.reset(); latest_pending_endpoint_list_.reset(); @@ -241,15 +232,12 @@ void RoundRobin::ResetBackoffLocked() { absl::Status RoundRobin::UpdateLocked(UpdateArgs args) { EndpointAddressesIterator* addresses = nullptr; if (args.addresses.ok()) { - if (GRPC_TRACE_FLAG_ENABLED(round_robin)) { - LOG(INFO) << "[RR " << this << "] received update"; - } + GRPC_TRACE_LOG(round_robin, INFO) << "[RR " << this << "] received update"; addresses = args.addresses->get(); } else { - if (GRPC_TRACE_FLAG_ENABLED(round_robin)) { - LOG(INFO) << "[RR " << this << "] received update with address error: " - << args.addresses.status(); - } + GRPC_TRACE_LOG(round_robin, INFO) + << "[RR " << this + << "] received update with address error: " << args.addresses.status(); // If we already have a child list, then keep using the existing // list, but still report back that the update was not accepted. if (endpoint_list_ != nullptr) return args.addresses.status(); @@ -302,21 +290,17 @@ void RoundRobin::RoundRobinEndpointList::RoundRobinEndpoint::OnStateUpdate( grpc_connectivity_state new_state, const absl::Status& status) { auto* rr_endpoint_list = endpoint_list(); auto* round_robin = policy(); - if (GRPC_TRACE_FLAG_ENABLED(round_robin)) { - LOG(INFO) << "[RR " << round_robin << "] connectivity changed for child " - << this << ", endpoint_list " << rr_endpoint_list << " (index " - << Index() << " of " << rr_endpoint_list->size() - << "): prev_state=" - << (old_state.has_value() ? ConnectivityStateName(*old_state) - : "N/A") - << " new_state=" << ConnectivityStateName(new_state) << " (" - << status << ")"; - } + GRPC_TRACE_LOG(round_robin, INFO) + << "[RR " << round_robin << "] connectivity changed for child " << this + << ", endpoint_list " << rr_endpoint_list << " (index " << Index() + << " of " << rr_endpoint_list->size() << "): prev_state=" + << (old_state.has_value() ? ConnectivityStateName(*old_state) : "N/A") + << " new_state=" << ConnectivityStateName(new_state) << " (" << status + << ")"; if (new_state == GRPC_CHANNEL_IDLE) { - if (GRPC_TRACE_FLAG_ENABLED(round_robin)) { - LOG(INFO) << "[RR " << round_robin << "] child " << this - << " reported IDLE; requesting connection"; - } + GRPC_TRACE_LOG(round_robin, INFO) + << "[RR " << round_robin << "] child " << this + << " reported IDLE; requesting connection"; ExitIdleLocked(); } // If state changed, update state counters. @@ -396,10 +380,9 @@ void RoundRobin::RoundRobinEndpointList:: // 2) ANY child is CONNECTING => policy is CONNECTING. // 3) ALL children are TRANSIENT_FAILURE => policy is TRANSIENT_FAILURE. if (num_ready_ > 0) { - if (GRPC_TRACE_FLAG_ENABLED(round_robin)) { - LOG(INFO) << "[RR " << round_robin << "] reporting READY with child list " - << this; - } + GRPC_TRACE_LOG(round_robin, INFO) + << "[RR " << round_robin << "] reporting READY with child list " + << this; std::vector> pickers; for (const auto& endpoint : endpoints()) { auto state = endpoint->connectivity_state(); @@ -412,19 +395,17 @@ void RoundRobin::RoundRobinEndpointList:: GRPC_CHANNEL_READY, absl::OkStatus(), MakeRefCounted(round_robin, std::move(pickers))); } else if (num_connecting_ > 0) { - if (GRPC_TRACE_FLAG_ENABLED(round_robin)) { - LOG(INFO) << "[RR " << round_robin - << "] reporting CONNECTING with child list " << this; - } + GRPC_TRACE_LOG(round_robin, INFO) + << "[RR " << round_robin << "] reporting CONNECTING with child list " + << this; round_robin->channel_control_helper()->UpdateState( GRPC_CHANNEL_CONNECTING, absl::Status(), MakeRefCounted(nullptr)); } else if (num_transient_failure_ == size()) { - if (GRPC_TRACE_FLAG_ENABLED(round_robin)) { - LOG(INFO) << "[RR " << round_robin - << "] reporting TRANSIENT_FAILURE with child list " << this - << ": " << status_for_tf; - } + GRPC_TRACE_LOG(round_robin, INFO) + << "[RR " << round_robin + << "] reporting TRANSIENT_FAILURE with child list " << this << ": " + << status_for_tf; if (!status_for_tf.ok()) { last_failure_ = absl::UnavailableError( absl::StrCat("connections to all backends failing; last error: ", diff --git a/src/core/load_balancing/weighted_round_robin/static_stride_scheduler.cc b/src/core/load_balancing/weighted_round_robin/static_stride_scheduler.cc index 0c0d0f1048..785c0ff22d 100644 --- a/src/core/load_balancing/weighted_round_robin/static_stride_scheduler.cc +++ b/src/core/load_balancing/weighted_round_robin/static_stride_scheduler.cc @@ -25,7 +25,6 @@ #include "absl/functional/any_invocable.h" #include "absl/log/check.h" -#include #include namespace grpc_core { 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 8e551372fb..144f1b0088 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 @@ -447,28 +447,24 @@ void WeightedRoundRobin::EndpointWeight::MaybeUpdateWeight( weight = qps / (utilization + penalty); } if (weight == 0) { - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr_.get() << "] subchannel " << key_.ToString() - << ": qps=" << qps << ", eps=" << eps - << ", utilization=" << utilization - << ": error_util_penalty=" << error_utilization_penalty - << ", weight=" << weight << " (not updating)"; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr_.get() << "] subchannel " << key_.ToString() + << ": qps=" << qps << ", eps=" << eps << ", utilization=" << utilization + << ": error_util_penalty=" << error_utilization_penalty + << ", weight=" << weight << " (not updating)"; return; } Timestamp now = Timestamp::Now(); // Grab the lock and update the data. MutexLock lock(&mu_); - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr_.get() << "] subchannel " << key_.ToString() - << ": qps=" << qps << ", eps=" << eps - << ", utilization=" << utilization - << " error_util_penalty=" << error_utilization_penalty - << " : setting weight=" << weight << " weight_=" << weight_ - << " now=" << now.ToString() - << " last_update_time_=" << last_update_time_.ToString() - << " non_empty_since_=" << non_empty_since_.ToString(); - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr_.get() << "] subchannel " << key_.ToString() + << ": qps=" << qps << ", eps=" << eps << ", utilization=" << utilization + << " error_util_penalty=" << error_utilization_penalty + << " : setting weight=" << weight << " weight_=" << weight_ + << " now=" << now.ToString() + << " last_update_time_=" << last_update_time_.ToString() + << " non_empty_since_=" << non_empty_since_.ToString(); if (non_empty_since_ == Timestamp::InfFuture()) non_empty_since_ = now; weight_ = weight; last_update_time_ = now; @@ -478,16 +474,14 @@ float WeightedRoundRobin::EndpointWeight::GetWeight( Timestamp now, Duration weight_expiration_period, Duration blackout_period, uint64_t* num_not_yet_usable, uint64_t* num_stale) { MutexLock lock(&mu_); - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr_.get() << "] subchannel " << key_.ToString() - << ": getting weight: now=" << now.ToString() - << " weight_expiration_period=" - << weight_expiration_period.ToString() - << " blackout_period=" << blackout_period.ToString() - << " last_update_time_=" << last_update_time_.ToString() - << " non_empty_since_=" << non_empty_since_.ToString() - << " weight_=" << weight_; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr_.get() << "] subchannel " << key_.ToString() + << ": getting weight: now=" << now.ToString() + << " weight_expiration_period=" << weight_expiration_period.ToString() + << " blackout_period=" << blackout_period.ToString() + << " last_update_time_=" << last_update_time_.ToString() + << " non_empty_since_=" << non_empty_since_.ToString() + << " weight_=" << weight_; // If the most recent update was longer ago than the expiration // period, reset non_empty_since_ so that we apply the blackout period // again if we start getting data again in the future, and return 0. @@ -555,27 +549,25 @@ WeightedRoundRobin::Picker::Picker(RefCountedPtr wrr, } global_stats().IncrementWrrSubchannelListSize(endpoint_list->size()); global_stats().IncrementWrrSubchannelReadySize(endpoints_.size()); - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr_.get() << " picker " << this - << "] created picker from endpoint_list=" << endpoint_list - << " with " << endpoints_.size() << " subchannels"; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr_.get() << " picker " << this + << "] created picker from endpoint_list=" << endpoint_list << " with " + << endpoints_.size() << " subchannels"; + // Note: BuildSchedulerAndStartTimerLocked() passes out pointers to `this`, + // so we need to ensure that we really hold timer_mu_. + MutexLock lock(&timer_mu_); BuildSchedulerAndStartTimerLocked(); } WeightedRoundRobin::Picker::~Picker() { - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr_.get() << " picker " << this - << "] destroying picker"; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr_.get() << " picker " << this << "] destroying picker"; } void WeightedRoundRobin::Picker::Orphaned() { MutexLock lock(&timer_mu_); - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr_.get() << " picker " << this - << "] cancelling timer"; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr_.get() << " picker " << this << "] cancelling timer"; wrr_->channel_control_helper()->GetEventEngine()->Cancel(*timer_handle_); timer_handle_.reset(); wrr_.reset(); @@ -585,11 +577,9 @@ WeightedRoundRobin::PickResult WeightedRoundRobin::Picker::Pick(PickArgs args) { size_t index = PickIndex(); CHECK(index < endpoints_.size()); auto& endpoint_info = endpoints_[index]; - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr_.get() << " picker " << this - << "] returning index " << index - << ", picker=" << endpoint_info.picker.get(); - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr_.get() << " picker " << this << "] returning index " + << index << ", picker=" << endpoint_info.picker.get(); auto result = endpoint_info.picker->Pick(args); // Collect per-call utilization data if needed. if (!config_->enable_oob_load_report()) { @@ -641,25 +631,22 @@ void WeightedRoundRobin::Picker::BuildSchedulerAndStartTimerLocked() { stats_plugins.AddCounter(kMetricEndpointWeightStale, num_stale, {wrr_->channel_control_helper()->GetTarget()}, {wrr_->locality_name_}); - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr_.get() << " picker " << this - << "] new weights: " << absl::StrJoin(weights, " "); - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr_.get() << " picker " << this + << "] new weights: " << absl::StrJoin(weights, " "); auto scheduler_or = StaticStrideScheduler::Make( weights, [this]() { return wrr_->scheduler_state_.fetch_add(1); }); std::shared_ptr scheduler; if (scheduler_or.has_value()) { scheduler = std::make_shared(std::move(*scheduler_or)); - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr_.get() << " picker " << this - << "] new scheduler: " << scheduler.get(); - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr_.get() << " picker " << this + << "] new scheduler: " << scheduler.get(); } else { - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr_.get() << " picker " << this - << "] no scheduler, falling back to RR"; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr_.get() << " picker " << this + << "] no scheduler, falling back to RR"; stats_plugins.AddCounter(kMetricRrFallback, 1, {wrr_->channel_control_helper()->GetTarget()}, {wrr_->locality_name_}); @@ -669,11 +656,14 @@ void WeightedRoundRobin::Picker::BuildSchedulerAndStartTimerLocked() { scheduler_ = std::move(scheduler); } // Start timer. - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr_.get() << " picker " << this - << "] scheduling timer for " - << config_->weight_update_period().ToString(); - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr_.get() << " picker " << this + << "] scheduling timer for " + << config_->weight_update_period().ToString(); + // It's insufficient to hold the implicit constructor lock here, a real lock + // over timer_mu_ is needed: we update timer_handle_ after the timer is + // scheduled, but it may run on another thread before that occurs, causing a + // race. timer_handle_ = wrr_->channel_control_helper()->GetEventEngine()->RunAfter( config_->weight_update_period(), [self = WeakRefAsSubclass(), @@ -683,10 +673,9 @@ void WeightedRoundRobin::Picker::BuildSchedulerAndStartTimerLocked() { { MutexLock lock(&self->timer_mu_); if (self->timer_handle_.has_value()) { - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << self->wrr_.get() << " picker " - << self.get() << "] timer fired"; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << self->wrr_.get() << " picker " << self.get() + << "] timer fired"; self->BuildSchedulerAndStartTimerLocked(); } } @@ -708,24 +697,21 @@ WeightedRoundRobin::WeightedRoundRobin(Args args) locality_name_(channel_args() .GetString(GRPC_ARG_LB_WEIGHTED_TARGET_CHILD) .value_or("")) { - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << this << "] Created -- locality_name=\"" - << std::string(locality_name_) << "\""; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << this << "] Created -- locality_name=\"" + << std::string(locality_name_) << "\""; } WeightedRoundRobin::~WeightedRoundRobin() { - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << this << "] Destroying Round Robin policy"; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << this << "] Destroying Round Robin policy"; CHECK(endpoint_list_ == nullptr); CHECK(latest_pending_endpoint_list_ == nullptr); } void WeightedRoundRobin::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << this << "] Shutting down"; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << this << "] Shutting down"; shutdown_ = true; endpoint_list_.reset(); latest_pending_endpoint_list_.reset(); @@ -743,9 +729,8 @@ absl::Status WeightedRoundRobin::UpdateLocked(UpdateArgs args) { config_ = args.config.TakeAsSubclass(); std::shared_ptr addresses; if (args.addresses.ok()) { - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << this << "] received update"; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << this << "] received update"; // Weed out duplicate endpoints. Also sort the endpoints so that if // the set of endpoints doesn't change, their indexes in the endpoint // list don't change, since this avoids unnecessary churn in the @@ -771,10 +756,9 @@ absl::Status WeightedRoundRobin::UpdateLocked(UpdateArgs args) { std::make_shared(EndpointAddressesList( ordered_addresses.begin(), ordered_addresses.end())); } else { - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << this << "] received update with address error: " - << args.addresses.status().ToString(); - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << this << "] received update with address error: " + << args.addresses.status().ToString(); // If we already have an endpoint list, then keep using the existing // list, but still report back that the update was not accepted. if (endpoint_list_ != nullptr) return args.addresses.status(); @@ -875,21 +859,17 @@ void WeightedRoundRobin::WrrEndpointList::WrrEndpoint::OnStateUpdate( grpc_connectivity_state new_state, const absl::Status& status) { auto* wrr_endpoint_list = endpoint_list(); auto* wrr = policy(); - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr << "] connectivity changed for child " << this - << ", endpoint_list " << wrr_endpoint_list << " (index " - << Index() << " of " << wrr_endpoint_list->size() - << "): prev_state=" - << (old_state.has_value() ? ConnectivityStateName(*old_state) - : "N/A") - << " new_state=" << ConnectivityStateName(new_state) << " (" - << status << ")"; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr << "] connectivity changed for child " << this + << ", endpoint_list " << wrr_endpoint_list << " (index " << Index() + << " of " << wrr_endpoint_list->size() << "): prev_state=" + << (old_state.has_value() ? ConnectivityStateName(*old_state) : "N/A") + << " new_state=" << ConnectivityStateName(new_state) << " (" << status + << ")"; if (new_state == GRPC_CHANNEL_IDLE) { - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr << "] child " << this - << " reported IDLE; requesting connection"; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr << "] child " << this + << " reported IDLE; requesting connection"; ExitIdleLocked(); } else if (new_state == GRPC_CHANNEL_READY) { // If we transition back to READY state, restart the blackout period. @@ -983,27 +963,22 @@ void WeightedRoundRobin::WrrEndpointList:: // 2) ANY child is CONNECTING => policy is CONNECTING. // 3) ALL children are TRANSIENT_FAILURE => policy is TRANSIENT_FAILURE. if (num_ready_ > 0) { - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr << "] reporting READY with endpoint list " - << this; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr << "] reporting READY with endpoint list " << this; wrr->channel_control_helper()->UpdateState( GRPC_CHANNEL_READY, absl::Status(), MakeRefCounted(wrr->RefAsSubclass(), this)); } else if (num_connecting_ > 0) { - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr - << "] reporting CONNECTING with endpoint list " << this; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr << "] reporting CONNECTING with endpoint list " + << this; wrr->channel_control_helper()->UpdateState( GRPC_CHANNEL_CONNECTING, absl::Status(), MakeRefCounted(nullptr)); } else if (num_transient_failure_ == size()) { - if (GRPC_TRACE_FLAG_ENABLED(weighted_round_robin_lb)) { - LOG(INFO) << "[WRR " << wrr - << "] reporting TRANSIENT_FAILURE with endpoint list " << this - << ": " << status_for_tf; - } + GRPC_TRACE_LOG(weighted_round_robin_lb, INFO) + << "[WRR " << wrr << "] reporting TRANSIENT_FAILURE with endpoint list " + << this << ": " << status_for_tf; if (!status_for_tf.ok()) { last_failure_ = absl::UnavailableError( absl::StrCat("connections to all backends failing; last error: ", diff --git a/src/core/load_balancing/weighted_target/weighted_target.cc b/src/core/load_balancing/weighted_target/weighted_target.cc index ab73a11772..9724720fc6 100644 --- a/src/core/load_balancing/weighted_target/weighted_target.cc +++ b/src/core/load_balancing/weighted_target/weighted_target.cc @@ -284,22 +284,19 @@ WeightedTargetLb::PickResult WeightedTargetLb::WeightedPicker::Pick( WeightedTargetLb::WeightedTargetLb(Args args) : LoadBalancingPolicy(std::move(args)) { - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << this << "] created"; - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << this << "] created"; } WeightedTargetLb::~WeightedTargetLb() { - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << this - << "] destroying weighted_target LB policy"; - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << this + << "] destroying weighted_target LB policy"; } void WeightedTargetLb::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << this << "] shutting down"; - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << this << "] shutting down"; shutting_down_ = true; targets_.clear(); } @@ -310,9 +307,8 @@ void WeightedTargetLb::ResetBackoffLocked() { absl::Status WeightedTargetLb::UpdateLocked(UpdateArgs args) { if (shutting_down_) return absl::OkStatus(); - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << this << "] received update"; - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << this << "] received update"; update_in_progress_ = true; // Update config. config_ = args.config.TakeAsSubclass(); @@ -382,10 +378,9 @@ void WeightedTargetLb::UpdateStateLocked() { // all children. This avoids unnecessary picker churn while an update // is being propagated to our children. if (update_in_progress_) return; - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << this - << "] scanning children to determine connectivity state"; - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << this + << "] scanning children to determine connectivity state"; // Construct lists of child pickers with associated weights, one for // children that are in state READY and another for children that are // in state TRANSIENT_FAILURE. Each child is represented by a portion of @@ -407,13 +402,10 @@ void WeightedTargetLb::UpdateStateLocked() { continue; } auto child_picker = child->picker(); - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << this << "] child=" << child_name - << " state=" - << ConnectivityStateName(child->connectivity_state()) - << " weight=" << child->weight() - << " picker=" << child_picker.get(); - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << this << "] child=" << child_name + << " state=" << ConnectivityStateName(child->connectivity_state()) + << " weight=" << child->weight() << " picker=" << child_picker.get(); switch (child->connectivity_state()) { case GRPC_CHANNEL_READY: { CHECK_GT(child->weight(), 0u); @@ -450,10 +442,9 @@ void WeightedTargetLb::UpdateStateLocked() { } else { connectivity_state = GRPC_CHANNEL_TRANSIENT_FAILURE; } - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << this << "] connectivity changed to " - << ConnectivityStateName(connectivity_state); - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << this << "] connectivity changed to " + << ConnectivityStateName(connectivity_state); RefCountedPtr picker; absl::Status status; switch (connectivity_state) { @@ -494,13 +485,11 @@ WeightedTargetLb::WeightedChild::DelayedRemovalTimer::DelayedRemovalTimer( void WeightedTargetLb::WeightedChild::DelayedRemovalTimer::Orphan() { if (timer_handle_.has_value()) { - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " - << weighted_child_->weighted_target_policy_.get() - << "] WeightedChild " << weighted_child_.get() << " " - << weighted_child_->name_ - << ": cancelling delayed removal timer"; - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " + << weighted_child_->weighted_target_policy_.get() << "] WeightedChild " + << weighted_child_.get() << " " << weighted_child_->name_ + << ": cancelling delayed removal timer"; weighted_child_->weighted_target_policy_->channel_control_helper() ->GetEventEngine() ->Cancel(*timer_handle_); @@ -525,27 +514,22 @@ WeightedTargetLb::WeightedChild::WeightedChild( : weighted_target_policy_(std::move(weighted_target_policy)), name_(name), picker_(MakeRefCounted(nullptr)) { - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << weighted_target_policy_.get() - << "] created WeightedChild " << this << " for " << name_; - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << weighted_target_policy_.get() + << "] created WeightedChild " << this << " for " << name_; } WeightedTargetLb::WeightedChild::~WeightedChild() { - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << weighted_target_policy_.get() - << "] WeightedChild " << this << " " << name_ - << ": destroying child"; - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << weighted_target_policy_.get() + << "] WeightedChild " << this << " " << name_ << ": destroying child"; weighted_target_policy_.reset(DEBUG_LOCATION, "WeightedChild"); } void WeightedTargetLb::WeightedChild::Orphan() { - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << weighted_target_policy_.get() - << "] WeightedChild " << this << " " << name_ - << ": shutting down child"; - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << weighted_target_policy_.get() + << "] WeightedChild " << this << " " << name_ << ": shutting down child"; // Remove the child policy's interested_parties pollset_set from the // xDS policy. grpc_pollset_set_del_pollset_set( @@ -570,11 +554,10 @@ WeightedTargetLb::WeightedChild::CreateChildPolicyLocked( OrphanablePtr lb_policy = MakeOrphanable(std::move(lb_policy_args), &weighted_target_lb_trace); - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << weighted_target_policy_.get() - << "] WeightedChild " << this << " " << name_ - << ": created new child policy handler " << lb_policy.get(); - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << weighted_target_policy_.get() + << "] WeightedChild " << this << " " << name_ + << ": created new child policy handler " << lb_policy.get(); // Add the xDS's interested_parties pollset_set to that of the newly created // child policy. This will make the child policy progress upon activity on // xDS LB, which in turn is tied to the application's call. @@ -598,11 +581,9 @@ absl::Status WeightedTargetLb::WeightedChild::UpdateLocked( weight_ = config.weight; // Reactivate if needed. if (delayed_removal_timer_ != nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << weighted_target_policy_.get() - << "] WeightedChild " << this << " " << name_ - << ": reactivating"; - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << weighted_target_policy_.get() + << "] WeightedChild " << this << " " << name_ << ": reactivating"; delayed_removal_timer_.reset(); } // Create child policy if needed. @@ -617,11 +598,10 @@ absl::Status WeightedTargetLb::WeightedChild::UpdateLocked( update_args.resolution_note = resolution_note; update_args.args = std::move(args); // Update the policy. - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << weighted_target_policy_.get() - << "] WeightedChild " << this << " " << name_ - << ": updating child policy handler " << child_policy_.get(); - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << weighted_target_policy_.get() + << "] WeightedChild " << this << " " << name_ + << ": updating child policy handler " << child_policy_.get(); return child_policy_->UpdateLocked(std::move(update_args)); } @@ -634,13 +614,11 @@ void WeightedTargetLb::WeightedChild::OnConnectivityStateUpdateLocked( RefCountedPtr picker) { // Cache the picker in the WeightedChild. picker_ = std::move(picker); - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << weighted_target_policy_.get() - << "] WeightedChild " << this << " " << name_ - << ": connectivity state update: state=" - << ConnectivityStateName(state) << " (" << status - << ") picker=" << picker_.get(); - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << weighted_target_policy_.get() + << "] WeightedChild " << this << " " << name_ + << ": connectivity state update: state=" << ConnectivityStateName(state) + << " (" << status << ") picker=" << picker_.get(); // If the child reports IDLE, immediately tell it to exit idle. if (state == GRPC_CHANNEL_IDLE) child_policy_->ExitIdleLocked(); // Decide what state to report for aggregation purposes. @@ -657,10 +635,9 @@ void WeightedTargetLb::WeightedChild::OnConnectivityStateUpdateLocked( void WeightedTargetLb::WeightedChild::DeactivateLocked() { // If already deactivated, don't do that again. if (weight_ == 0) return; - if (GRPC_TRACE_FLAG_ENABLED(weighted_target_lb)) { - LOG(INFO) << "[weighted_target_lb " << weighted_target_policy_.get() - << "] WeightedChild " << this << " " << name_ << ": deactivating"; - } + GRPC_TRACE_LOG(weighted_target_lb, INFO) + << "[weighted_target_lb " << weighted_target_policy_.get() + << "] WeightedChild " << this << " " << name_ << ": deactivating"; // Set the child weight to 0 so that future picker won't contain this child. weight_ = 0; // Start a timer to delete the child. diff --git a/src/core/load_balancing/xds/cds.cc b/src/core/load_balancing/xds/cds.cc index 249e327f62..03ee2a00a1 100644 --- a/src/core/load_balancing/xds/cds.cc +++ b/src/core/load_balancing/xds/cds.cc @@ -78,8 +78,6 @@ bool XdsAggregateClusterBackwardCompatibilityEnabled() { return parse_succeeded && parsed_value; } -using XdsConfig = XdsDependencyManager::XdsConfig; - constexpr absl::string_view kCds = "cds_experimental"; // Config for this LB policy. @@ -183,21 +181,16 @@ class CdsLb final : public LoadBalancingPolicy { // CdsLb::CdsLb(Args args) : LoadBalancingPolicy(std::move(args)) { - if (GRPC_TRACE_FLAG_ENABLED(cds_lb)) { - LOG(INFO) << "[cdslb " << this << "] created"; - } + GRPC_TRACE_LOG(cds_lb, INFO) << "[cdslb " << this << "] created"; } CdsLb::~CdsLb() { - if (GRPC_TRACE_FLAG_ENABLED(cds_lb)) { - LOG(INFO) << "[cdslb " << this << "] destroying cds LB policy"; - } + GRPC_TRACE_LOG(cds_lb, INFO) + << "[cdslb " << this << "] destroying cds LB policy"; } void CdsLb::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(cds_lb)) { - LOG(INFO) << "[cdslb " << this << "] shutting down"; - } + GRPC_TRACE_LOG(cds_lb, INFO) << "[cdslb " << this << "] shutting down"; shutting_down_ = true; ResetState(); } @@ -280,11 +273,10 @@ class PriorityEndpointIterator final : public EndpointAddressesIterator { absl::Status CdsLb::UpdateLocked(UpdateArgs args) { // Get new config. auto new_config = args.config.TakeAsSubclass(); - if (GRPC_TRACE_FLAG_ENABLED(cds_lb)) { - LOG(INFO) << "[cdslb " << this - << "] received update: cluster=" << new_config->cluster() - << " is_dynamic=" << new_config->is_dynamic(); - } + GRPC_TRACE_LOG(cds_lb, INFO) + << "[cdslb " << this + << "] received update: cluster=" << new_config->cluster() + << " is_dynamic=" << new_config->is_dynamic(); CHECK(new_config != nullptr); // Cluster name should never change, because we should use a different // child name in xds_cluster_manager in that case. @@ -295,11 +287,9 @@ absl::Status CdsLb::UpdateLocked(UpdateArgs args) { } // Start dynamic subscription if needed. if (new_config->is_dynamic() && subscription_ == nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(cds_lb)) { - LOG(INFO) << "[cdslb " << this - << "] obtaining dynamic subscription for cluster " - << cluster_name_; - } + GRPC_TRACE_LOG(cds_lb, INFO) + << "[cdslb " << this << "] obtaining dynamic subscription for cluster " + << cluster_name_; auto* dependency_mgr = args.args.GetObject(); if (dependency_mgr == nullptr) { // Should never happen. @@ -326,11 +316,10 @@ absl::Status CdsLb::UpdateLocked(UpdateArgs args) { // If we are already subscribed, it's possible that we just // recently subscribed but another update came through before we // got the new cluster, in which case it will still be missing. - if (GRPC_TRACE_FLAG_ENABLED(cds_lb)) { - LOG(INFO) << "[cdslb " << this - << "] xDS config has no entry for dynamic cluster " - << cluster_name_ << ", waiting for subsequent update"; - } + GRPC_TRACE_LOG(cds_lb, INFO) + << "[cdslb " << this + << "] xDS config has no entry for dynamic cluster " << cluster_name_ + << ", waiting for subsequent update"; // Stay in CONNECTING until we get an update that has the cluster. return absl::OkStatus(); } @@ -452,11 +441,9 @@ absl::Status CdsLb::UpdateLocked(UpdateArgs args) { } grpc_pollset_set_add_pollset_set(child_policy_->interested_parties(), interested_parties()); - if (GRPC_TRACE_FLAG_ENABLED(cds_lb)) { - LOG(INFO) << "[cdslb " << this << "] created child policy " - << (*child_config)->name() << " (" << child_policy_.get() - << ")"; - } + GRPC_TRACE_LOG(cds_lb, INFO) + << "[cdslb " << this << "] created child policy " + << (*child_config)->name() << " (" << child_policy_.get() << ")"; } // Update child policy. update_args.config = std::move(*child_config); @@ -662,10 +649,9 @@ Json CdsLb::CreateChildPolicyConfigForLeafCluster( {"outlier_detection_experimental", Json::FromObject(std::move(outlier_detection_config))}, })}); - if (GRPC_TRACE_FLAG_ENABLED(cds_lb)) { - LOG(INFO) << "[cdslb " << this << "] generated config for child policy: " - << JsonDump(outlier_detection_policy, /*indent=*/1); - } + GRPC_TRACE_LOG(cds_lb, INFO) + << "[cdslb " << this << "] generated config for child policy: " + << JsonDump(outlier_detection_policy, /*indent=*/1); return outlier_detection_policy; } @@ -695,10 +681,9 @@ Json CdsLb::CreateChildPolicyConfigForAggregateCluster( {"priorities", Json::FromArray(std::move(priority_priorities))}, })}, })}); - if (GRPC_TRACE_FLAG_ENABLED(cds_lb)) { - LOG(INFO) << "[cdslb " << this << "] generated config for child policy: " - << JsonDump(json, /*indent=*/1); - } + GRPC_TRACE_LOG(cds_lb, INFO) + << "[cdslb " << this << "] generated config for child policy: " + << JsonDump(json, /*indent=*/1); return json; } @@ -714,10 +699,8 @@ void CdsLb::ResetState() { } void CdsLb::ReportTransientFailure(absl::Status status) { - if (GRPC_TRACE_FLAG_ENABLED(cds_lb)) { - LOG(INFO) << "[cdslb " << this - << "] reporting TRANSIENT_FAILURE: " << status; - } + GRPC_TRACE_LOG(cds_lb, INFO) + << "[cdslb " << this << "] reporting TRANSIENT_FAILURE: " << status; ResetState(); channel_control_helper()->UpdateState( GRPC_CHANNEL_TRANSIENT_FAILURE, status, diff --git a/src/core/load_balancing/xds/xds_cluster_impl.cc b/src/core/load_balancing/xds/xds_cluster_impl.cc index c3b025f3ed..e66330a21d 100644 --- a/src/core/load_balancing/xds/xds_cluster_impl.cc +++ b/src/core/load_balancing/xds/xds_cluster_impl.cc @@ -35,7 +35,6 @@ #include "absl/types/variant.h" #include -#include #include #include "src/core/client_channel/client_channel_internal.h" @@ -63,7 +62,7 @@ #include "src/core/load_balancing/subchannel_interface.h" #include "src/core/load_balancing/xds/xds_channel_args.h" #include "src/core/resolver/endpoint_addresses.h" -#include "src/core/resolver/xds/xds_dependency_manager.h" +#include "src/core/resolver/xds/xds_config.h" #include "src/core/resolver/xds/xds_resolver_attributes.h" #include "src/core/telemetry/call_tracer.h" #include "src/core/util/json/json.h" @@ -80,8 +79,6 @@ namespace grpc_core { namespace { -using XdsConfig = XdsDependencyManager::XdsConfig; - // // global circuit breaker atomic map // @@ -293,6 +290,8 @@ class XdsClusterImplLb final : public LoadBalancingPolicy { // Current config from the resolver. RefCountedPtr config_; std::shared_ptr cluster_resource_; + RefCountedStringValue service_telemetry_label_; + RefCountedStringValue namespace_telemetry_label_; RefCountedPtr drop_config_; // Current concurrent number of requests. @@ -397,17 +396,15 @@ XdsClusterImplLb::Picker::Picker(XdsClusterImplLb* xds_cluster_impl_lb, : call_counter_(xds_cluster_impl_lb->call_counter_), max_concurrent_requests_( xds_cluster_impl_lb->cluster_resource_->max_concurrent_requests), - service_telemetry_label_( - xds_cluster_impl_lb->cluster_resource_->service_telemetry_label), + service_telemetry_label_(xds_cluster_impl_lb->service_telemetry_label_), namespace_telemetry_label_( - xds_cluster_impl_lb->cluster_resource_->namespace_telemetry_label), + xds_cluster_impl_lb->namespace_telemetry_label_), drop_config_(xds_cluster_impl_lb->drop_config_), drop_stats_(xds_cluster_impl_lb->drop_stats_), picker_(std::move(picker)) { - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_impl_lb)) { - LOG(INFO) << "[xds_cluster_impl_lb " << xds_cluster_impl_lb - << "] constructed new picker " << this; - } + GRPC_TRACE_LOG(xds_cluster_impl_lb, INFO) + << "[xds_cluster_impl_lb " << xds_cluster_impl_lb + << "] constructed new picker " << this; } LoadBalancingPolicy::PickResult XdsClusterImplLb::Picker::Pick( @@ -500,23 +497,20 @@ LoadBalancingPolicy::PickResult XdsClusterImplLb::Picker::Pick( XdsClusterImplLb::XdsClusterImplLb(RefCountedPtr xds_client, Args args) : LoadBalancingPolicy(std::move(args)), xds_client_(std::move(xds_client)) { - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_impl_lb)) { - LOG(INFO) << "[xds_cluster_impl_lb " << this - << "] created -- using xds client " << xds_client_.get(); - } + GRPC_TRACE_LOG(xds_cluster_impl_lb, INFO) + << "[xds_cluster_impl_lb " << this << "] created -- using xds client " + << xds_client_.get(); } XdsClusterImplLb::~XdsClusterImplLb() { - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_impl_lb)) { - LOG(INFO) << "[xds_cluster_impl_lb " << this - << "] destroying xds_cluster_impl LB policy"; - } + GRPC_TRACE_LOG(xds_cluster_impl_lb, INFO) + << "[xds_cluster_impl_lb " << this + << "] destroying xds_cluster_impl LB policy"; } void XdsClusterImplLb::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_impl_lb)) { - LOG(INFO) << "[xds_cluster_impl_lb " << this << "] shutting down"; - } + GRPC_TRACE_LOG(xds_cluster_impl_lb, INFO) + << "[xds_cluster_impl_lb " << this << "] shutting down"; shutting_down_ = true; ResetState(); xds_client_.reset(DEBUG_LOCATION, "XdsClusterImpl"); @@ -537,10 +531,9 @@ void XdsClusterImplLb::ResetState() { } void XdsClusterImplLb::ReportTransientFailure(absl::Status status) { - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_impl_lb)) { - LOG(INFO) << "[xds_cluster_impl_lb " << this - << "] reporting TRANSIENT_FAILURE: " << status; - } + GRPC_TRACE_LOG(xds_cluster_impl_lb, INFO) + << "[xds_cluster_impl_lb " << this + << "] reporting TRANSIENT_FAILURE: " << status; ResetState(); channel_control_helper()->UpdateState( GRPC_CHANNEL_TRANSIENT_FAILURE, status, @@ -564,9 +557,8 @@ std::string GetEdsResourceName(const XdsClusterResource& cluster_resource) { } absl::Status XdsClusterImplLb::UpdateLocked(UpdateArgs args) { - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_impl_lb)) { - LOG(INFO) << "[xds_cluster_impl_lb " << this << "] Received update"; - } + GRPC_TRACE_LOG(xds_cluster_impl_lb, INFO) + << "[xds_cluster_impl_lb " << this << "] Received update"; // Grab new LB policy config. auto new_config = args.config.TakeAsSubclass(); // Cluster name should never change, because the cds policy will assign a @@ -654,6 +646,23 @@ absl::Status XdsClusterImplLb::UpdateLocked(UpdateArgs args) { // Update config state, now that we're done comparing old and new fields. config_ = std::move(new_config); cluster_resource_ = new_cluster_config.cluster; + const XdsMetadataValue* metadata_value = + cluster_resource_->metadata.Find("com.google.csm.telemetry_labels"); + if (metadata_value != nullptr && + metadata_value->type() == XdsStructMetadataValue::Type()) { + const Json::Object& json_object = + DownCast(metadata_value) + ->json() + .object(); + auto it = json_object.find("service_name"); + if (it != json_object.end() && it->second.type() == Json::Type::kString) { + service_telemetry_label_ = RefCountedStringValue(it->second.string()); + } + it = json_object.find("service_namespace"); + if (it != json_object.end() && it->second.type() == Json::Type::kString) { + namespace_telemetry_label_ = RefCountedStringValue(it->second.string()); + } + } drop_config_ = endpoint_config->endpoints != nullptr ? endpoint_config->endpoints->drop_config : nullptr; @@ -736,11 +745,10 @@ void XdsClusterImplLb::MaybeUpdatePickerLocked() { // whether) the child has reported. if (drop_config_ != nullptr && drop_config_->drop_all()) { auto drop_picker = MakeRefCounted(this, picker_); - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_impl_lb)) { - LOG(INFO) << "[xds_cluster_impl_lb " << this - << "] updating connectivity (drop all): state=READY picker=" - << drop_picker.get(); - } + GRPC_TRACE_LOG(xds_cluster_impl_lb, INFO) + << "[xds_cluster_impl_lb " << this + << "] updating connectivity (drop all): state=READY picker=" + << drop_picker.get(); channel_control_helper()->UpdateState(GRPC_CHANNEL_READY, absl::Status(), std::move(drop_picker)); return; @@ -748,12 +756,10 @@ void XdsClusterImplLb::MaybeUpdatePickerLocked() { // Otherwise, update only if we have a child picker. if (picker_ != nullptr) { auto drop_picker = MakeRefCounted(this, picker_); - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_impl_lb)) { - LOG(INFO) << "[xds_cluster_impl_lb " << this - << "] updating connectivity: state=" - << ConnectivityStateName(state_) << " status=(" << status_ - << ") picker=" << drop_picker.get(); - } + GRPC_TRACE_LOG(xds_cluster_impl_lb, INFO) + << "[xds_cluster_impl_lb " << this + << "] updating connectivity: state=" << ConnectivityStateName(state_) + << " status=(" << status_ << ") picker=" << drop_picker.get(); channel_control_helper()->UpdateState(state_, status_, std::move(drop_picker)); } @@ -769,10 +775,9 @@ OrphanablePtr XdsClusterImplLb::CreateChildPolicyLocked( OrphanablePtr lb_policy = MakeOrphanable(std::move(lb_policy_args), &xds_cluster_impl_lb_trace); - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_impl_lb)) { - LOG(INFO) << "[xds_cluster_impl_lb " << this - << "] Created new child policy handler " << lb_policy.get(); - } + GRPC_TRACE_LOG(xds_cluster_impl_lb, INFO) + << "[xds_cluster_impl_lb " << this + << "] Created new child policy handler " << lb_policy.get(); // Add our interested_parties pollset_set to that of the newly created // child policy. This will make the child policy progress upon activity on // this policy, which in turn is tied to the application's call. @@ -796,10 +801,9 @@ absl::Status XdsClusterImplLb::UpdateChildPolicyLocked( update_args.args = args.Set(GRPC_ARG_XDS_CLUSTER_NAME, config_->cluster_name()); // Update the policy. - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_impl_lb)) { - LOG(INFO) << "[xds_cluster_impl_lb " << this - << "] Updating child policy handler " << child_policy_.get(); - } + GRPC_TRACE_LOG(xds_cluster_impl_lb, INFO) + << "[xds_cluster_impl_lb " << this << "] Updating child policy handler " + << child_policy_.get(); return child_policy_->UpdateLocked(std::move(update_args)); } @@ -850,12 +854,11 @@ void XdsClusterImplLb::Helper::UpdateState( grpc_connectivity_state state, const absl::Status& status, RefCountedPtr picker) { if (parent()->shutting_down_) return; - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_impl_lb)) { - LOG(INFO) << "[xds_cluster_impl_lb " << parent() - << "] child connectivity state update: state=" - << ConnectivityStateName(state) << " (" << status - << ") picker=" << picker.get(); - } + GRPC_TRACE_LOG(xds_cluster_impl_lb, INFO) + << "[xds_cluster_impl_lb " << parent() + << "] child connectivity state update: state=" + << ConnectivityStateName(state) << " (" << status + << ") picker=" << picker.get(); // Save the state and picker. parent()->state_ = state; parent()->status_ = status; diff --git a/src/core/load_balancing/xds/xds_cluster_manager.cc b/src/core/load_balancing/xds/xds_cluster_manager.cc index 67560f523f..5d3dfd9e8b 100644 --- a/src/core/load_balancing/xds/xds_cluster_manager.cc +++ b/src/core/load_balancing/xds/xds_cluster_manager.cc @@ -249,16 +249,14 @@ XdsClusterManagerLb::XdsClusterManagerLb(Args args) : LoadBalancingPolicy(std::move(args)) {} XdsClusterManagerLb::~XdsClusterManagerLb() { - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_manager_lb)) { - LOG(INFO) << "[xds_cluster_manager_lb " << this - << "] destroying xds_cluster_manager LB policy"; - } + GRPC_TRACE_LOG(xds_cluster_manager_lb, INFO) + << "[xds_cluster_manager_lb " << this + << "] destroying xds_cluster_manager LB policy"; } void XdsClusterManagerLb::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_manager_lb)) { - LOG(INFO) << "[xds_cluster_manager_lb " << this << "] shutting down"; - } + GRPC_TRACE_LOG(xds_cluster_manager_lb, INFO) + << "[xds_cluster_manager_lb " << this << "] shutting down"; shutting_down_ = true; children_.clear(); } @@ -273,9 +271,8 @@ void XdsClusterManagerLb::ResetBackoffLocked() { absl::Status XdsClusterManagerLb::UpdateLocked(UpdateArgs args) { if (shutting_down_) return absl::OkStatus(); - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_manager_lb)) { - LOG(INFO) << "[xds_cluster_manager_lb " << this << "] Received update"; - } + GRPC_TRACE_LOG(xds_cluster_manager_lb, INFO) + << "[xds_cluster_manager_lb " << this << "] Received update"; update_in_progress_ = true; // Update config. config_ = args.config.TakeAsSubclass(); @@ -366,22 +363,18 @@ void XdsClusterManagerLb::UpdateStateLocked() { } else { connectivity_state = GRPC_CHANNEL_TRANSIENT_FAILURE; } - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_manager_lb)) { - LOG(INFO) << "[xds_cluster_manager_lb " << this - << "] connectivity changed to " - << ConnectivityStateName(connectivity_state); - } + GRPC_TRACE_LOG(xds_cluster_manager_lb, INFO) + << "[xds_cluster_manager_lb " << this << "] connectivity changed to " + << ConnectivityStateName(connectivity_state); ClusterPicker::ClusterMap cluster_map; for (const auto& p : config_->cluster_map()) { const std::string& cluster_name = p.first; RefCountedPtr& child_picker = cluster_map[cluster_name]; child_picker = children_[cluster_name]->picker(); if (child_picker == nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_manager_lb)) { - LOG(INFO) << "[xds_cluster_manager_lb " << this << "] child " - << cluster_name - << " has not yet returned a picker; creating a QueuePicker."; - } + GRPC_TRACE_LOG(xds_cluster_manager_lb, INFO) + << "[xds_cluster_manager_lb " << this << "] child " << cluster_name + << " has not yet returned a picker; creating a QueuePicker."; child_picker = MakeRefCounted(Ref(DEBUG_LOCATION, "QueuePicker")); } @@ -406,26 +399,22 @@ XdsClusterManagerLb::ClusterChild::ClusterChild( : xds_cluster_manager_policy_(std::move(xds_cluster_manager_policy)), name_(name), picker_(MakeRefCounted(nullptr)) { - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_manager_lb)) { - LOG(INFO) << "[xds_cluster_manager_lb " << xds_cluster_manager_policy_.get() - << "] created ClusterChild " << this << " for " << name_; - } + GRPC_TRACE_LOG(xds_cluster_manager_lb, INFO) + << "[xds_cluster_manager_lb " << xds_cluster_manager_policy_.get() + << "] created ClusterChild " << this << " for " << name_; } XdsClusterManagerLb::ClusterChild::~ClusterChild() { - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_manager_lb)) { - LOG(INFO) << "[xds_cluster_manager_lb " << xds_cluster_manager_policy_.get() - << "] ClusterChild " << this << ": destroying child"; - } + GRPC_TRACE_LOG(xds_cluster_manager_lb, INFO) + << "[xds_cluster_manager_lb " << xds_cluster_manager_policy_.get() + << "] ClusterChild " << this << ": destroying child"; xds_cluster_manager_policy_.reset(DEBUG_LOCATION, "ClusterChild"); } void XdsClusterManagerLb::ClusterChild::Orphan() { - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_manager_lb)) { - LOG(INFO) << "[xds_cluster_manager_lb " << xds_cluster_manager_policy_.get() - << "] ClusterChild " << this << " " << name_ - << ": shutting down child"; - } + GRPC_TRACE_LOG(xds_cluster_manager_lb, INFO) + << "[xds_cluster_manager_lb " << xds_cluster_manager_policy_.get() + << "] ClusterChild " << this << " " << name_ << ": shutting down child"; // Remove the child policy's interested_parties pollset_set from the // xDS policy. grpc_pollset_set_del_pollset_set( @@ -456,11 +445,10 @@ XdsClusterManagerLb::ClusterChild::CreateChildPolicyLocked( OrphanablePtr lb_policy = MakeOrphanable(std::move(lb_policy_args), &xds_cluster_manager_lb_trace); - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_manager_lb)) { - LOG(INFO) << "[xds_cluster_manager_lb " << xds_cluster_manager_policy_.get() - << "] ClusterChild " << this << " " << name_ - << ": Created new child policy handler " << lb_policy.get(); - } + GRPC_TRACE_LOG(xds_cluster_manager_lb, INFO) + << "[xds_cluster_manager_lb " << xds_cluster_manager_policy_.get() + << "] ClusterChild " << this << " " << name_ + << ": Created new child policy handler " << lb_policy.get(); // Add the xDS's interested_parties pollset_set to that of the newly created // child policy. This will make the child policy progress upon activity on // xDS LB, which in turn is tied to the application's call. @@ -493,11 +481,10 @@ absl::Status XdsClusterManagerLb::ClusterChild::UpdateLocked( update_args.addresses = addresses; update_args.args = args; // Update the policy. - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_manager_lb)) { - LOG(INFO) << "[xds_cluster_manager_lb " << xds_cluster_manager_policy_.get() - << "] ClusterChild " << this << " " << name_ - << ": Updating child policy handler " << child_policy_.get(); - } + GRPC_TRACE_LOG(xds_cluster_manager_lb, INFO) + << "[xds_cluster_manager_lb " << xds_cluster_manager_policy_.get() + << "] ClusterChild " << this << " " << name_ + << ": Updating child policy handler " << child_policy_.get(); return child_policy_->UpdateLocked(std::move(update_args)); } @@ -544,13 +531,12 @@ void XdsClusterManagerLb::ClusterChild::OnDelayedRemovalTimerLocked() { void XdsClusterManagerLb::ClusterChild::Helper::UpdateState( grpc_connectivity_state state, const absl::Status& status, RefCountedPtr picker) { - if (GRPC_TRACE_FLAG_ENABLED(xds_cluster_manager_lb)) { - LOG(INFO) << "[xds_cluster_manager_lb " - << xds_cluster_manager_child_->xds_cluster_manager_policy_.get() - << "] child " << xds_cluster_manager_child_->name_ - << ": received update: state=" << ConnectivityStateName(state) - << " (" << status << ") picker=" << picker.get(); - } + GRPC_TRACE_LOG(xds_cluster_manager_lb, INFO) + << "[xds_cluster_manager_lb " + << xds_cluster_manager_child_->xds_cluster_manager_policy_.get() + << "] child " << xds_cluster_manager_child_->name_ + << ": received update: state=" << ConnectivityStateName(state) << " (" + << status << ") picker=" << picker.get(); if (xds_cluster_manager_child_->xds_cluster_manager_policy_->shutting_down_) { return; } diff --git a/src/core/load_balancing/xds/xds_override_host.cc b/src/core/load_balancing/xds/xds_override_host.cc index 1514e55277..62a1632f2c 100644 --- a/src/core/load_balancing/xds/xds_override_host.cc +++ b/src/core/load_balancing/xds/xds_override_host.cc @@ -77,7 +77,7 @@ #include "src/core/load_balancing/lb_policy_registry.h" #include "src/core/load_balancing/subchannel_interface.h" #include "src/core/resolver/endpoint_addresses.h" -#include "src/core/resolver/xds/xds_dependency_manager.h" +#include "src/core/resolver/xds/xds_config.h" #include "src/core/util/json/json.h" #include "src/core/util/json/json_args.h" #include "src/core/util/json/json_object_loader.h" @@ -464,10 +464,9 @@ XdsOverrideHostLb::Picker::Picker( : policy_(std::move(xds_override_host_lb)), picker_(std::move(picker)), override_host_health_status_set_(override_host_health_status_set) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << policy_.get() - << "] constructed new picker " << this; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << policy_.get() + << "] constructed new picker " << this; } absl::optional @@ -487,18 +486,15 @@ XdsOverrideHostLb::Picker::PickOverridenHost( if (it == policy_->subchannel_map_.end()) continue; if (!override_host_health_status_set_.Contains( it->second->eds_health_status())) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "Subchannel " << address - << " health status is not overridden (" - << it->second->eds_health_status().ToString() << ")"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "Subchannel " << address << " health status is not overridden (" + << it->second->eds_health_status().ToString() << ")"; continue; } auto subchannel = it->second->GetSubchannelRef(); if (subchannel == nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "No subchannel for " << address; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "No subchannel for " << address; if (address_with_no_subchannel.empty()) { address_with_no_subchannel = it->first; } @@ -508,9 +504,8 @@ XdsOverrideHostLb::Picker::PickOverridenHost( if (connectivity_state == GRPC_CHANNEL_READY) { // Found a READY subchannel. Pass back the actual address list // and return the subchannel. - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "Picker override found READY subchannel " << address; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "Picker override found READY subchannel " << address; it->second->set_last_used_time(); override_host_attr->set_actual_address_list(it->second->address_list()); return PickResult::Complete(subchannel->wrapped_subchannel()); @@ -524,9 +519,8 @@ XdsOverrideHostLb::Picker::PickOverridenHost( // No READY subchannel found. If we found an IDLE subchannel, trigger // a connection attempt and queue the pick until that attempt completes. if (idle_subchannel != nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "Picker override found IDLE subchannel"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "Picker override found IDLE subchannel"; // Deletes itself after the connection is requested. new SubchannelConnectionRequester(std::move(idle_subchannel)); return PickResult::Queue(); @@ -534,18 +528,16 @@ XdsOverrideHostLb::Picker::PickOverridenHost( // No READY or IDLE subchannels. If we found a CONNECTING subchannel, // queue the pick and wait for the connection attempt to complete. if (found_connecting) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "Picker override found CONNECTING subchannel"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "Picker override found CONNECTING subchannel"; return PickResult::Queue(); } // No READY, IDLE, or CONNECTING subchannels found. If we found an // entry that has no subchannel, then queue the pick and trigger // creation of a subchannel for that entry. if (!address_with_no_subchannel.empty()) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "Picker override found entry with no subchannel"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "Picker override found entry with no subchannel"; if (!IsWorkSerializerDispatchEnabled()) { new SubchannelCreationRequester(policy_, address_with_no_subchannel); } else { @@ -605,10 +597,9 @@ XdsOverrideHostLb::IdleTimer::IdleTimer(RefCountedPtr policy, // Min time between timer runs is 5s so that we don't kill ourselves // with lock contention and CPU usage due to sweeps over the map. duration = std::max(duration, Duration::Seconds(5)); - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << policy_.get() << "] idle timer " - << this << ": subchannel cleanup pass will run in " << duration; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << policy_.get() << "] idle timer " << this + << ": subchannel cleanup pass will run in " << duration; timer_handle_ = policy_->channel_control_helper()->GetEventEngine()->RunAfter( duration, [self = RefAsSubclass()]() mutable { ApplicationCallbackExecCtx callback_exec_ctx; @@ -622,10 +613,9 @@ XdsOverrideHostLb::IdleTimer::IdleTimer(RefCountedPtr policy, void XdsOverrideHostLb::IdleTimer::Orphan() { if (timer_handle_.has_value()) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << policy_.get() << "] idle timer " - << this << ": cancelling"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << policy_.get() << "] idle timer " << this + << ": cancelling"; policy_->channel_control_helper()->GetEventEngine()->Cancel(*timer_handle_); timer_handle_.reset(); } @@ -635,10 +625,9 @@ void XdsOverrideHostLb::IdleTimer::Orphan() { void XdsOverrideHostLb::IdleTimer::OnTimerLocked() { if (timer_handle_.has_value()) { timer_handle_.reset(); - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << policy_.get() << "] idle timer " - << this << ": timer fired"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << policy_.get() << "] idle timer " << this + << ": timer fired"; policy_->CleanupSubchannels(); } } @@ -649,22 +638,19 @@ void XdsOverrideHostLb::IdleTimer::OnTimerLocked() { XdsOverrideHostLb::XdsOverrideHostLb(Args args) : LoadBalancingPolicy(std::move(args)) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this << "] created"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this << "] created"; } XdsOverrideHostLb::~XdsOverrideHostLb() { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this - << "] destroying xds_override_host LB policy"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this + << "] destroying xds_override_host LB policy"; } void XdsOverrideHostLb::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this << "] shutting down"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this << "] shutting down"; shutting_down_ = true; ResetState(); } @@ -695,10 +681,9 @@ void XdsOverrideHostLb::ResetState() { } void XdsOverrideHostLb::ReportTransientFailure(absl::Status status) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this - << "] reporting TRANSIENT_FAILURE: " << status; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this + << "] reporting TRANSIENT_FAILURE: " << status; ResetState(); channel_control_helper()->UpdateState( GRPC_CHANNEL_TRANSIENT_FAILURE, status, @@ -732,11 +717,9 @@ class ChildEndpointIterator final : public EndpointAddressesIterator { parent_it_->ForEach([&](const EndpointAddresses& endpoint) { XdsHealthStatus status = GetEndpointHealthStatus(endpoint); if (status.status() != XdsHealthStatus::kDraining) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this << "] endpoint " - << endpoint.ToString() - << ": not draining, passing to child"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this << "] endpoint " + << endpoint.ToString() << ": not draining, passing to child"; callback(endpoint); } }); @@ -747,17 +730,15 @@ class ChildEndpointIterator final : public EndpointAddressesIterator { }; absl::Status XdsOverrideHostLb::UpdateLocked(UpdateArgs args) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this << "] Received update"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this << "] Received update"; // Grab new LB policy config. if (args.config == nullptr) { return absl::InvalidArgumentError("Missing policy config"); } auto new_config = args.config.TakeAsSubclass(); // Get xDS config. - auto new_xds_config = - args.args.GetObjectRef(); + auto new_xds_config = args.args.GetObjectRef(); if (new_xds_config == nullptr) { // Should never happen. absl::Status status = absl::InternalError( @@ -777,23 +758,19 @@ absl::Status XdsOverrideHostLb::UpdateLocked(UpdateArgs args) { args_ = std::move(args.args); override_host_status_set_ = it->second->cluster->override_host_statuses; connection_idle_timeout_ = it->second->cluster->connection_idle_timeout; - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this - << "] override host status set: " - << override_host_status_set_.ToString() - << " connection idle timeout: " - << connection_idle_timeout_.ToString(); - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this + << "] override host status set: " << override_host_status_set_.ToString() + << " connection idle timeout: " << connection_idle_timeout_.ToString(); // Update address map and wrap endpoint iterator for child policy. if (args.addresses.ok()) { UpdateAddressMap(**args.addresses); args.addresses = std::make_shared(std::move(*args.addresses)); } else { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this - << "] address error: " << args.addresses.status(); - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this + << "] address error: " << args.addresses.status(); } // Create child policy if needed. if (child_policy_ == nullptr) { @@ -805,10 +782,9 @@ absl::Status XdsOverrideHostLb::UpdateLocked(UpdateArgs args) { update_args.resolution_note = std::move(args.resolution_note); update_args.config = new_config->child_config(); update_args.args = args_; - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this - << "] Updating child policy handler " << child_policy_.get(); - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this << "] Updating child policy handler " + << child_policy_.get(); return child_policy_->UpdateLocked(std::move(update_args)); } @@ -816,12 +792,11 @@ void XdsOverrideHostLb::MaybeUpdatePickerLocked() { if (picker_ != nullptr) { auto xds_override_host_picker = MakeRefCounted( RefAsSubclass(), picker_, override_host_status_set_); - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this - << "] updating connectivity: state=" - << ConnectivityStateName(state_) << " status=(" << status_ - << ") picker=" << xds_override_host_picker.get(); - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this + << "] updating connectivity: state=" << ConnectivityStateName(state_) + << " status=(" << status_ + << ") picker=" << xds_override_host_picker.get(); channel_control_helper()->UpdateState(state_, status_, std::move(xds_override_host_picker)); } @@ -837,10 +812,9 @@ OrphanablePtr XdsOverrideHostLb::CreateChildPolicyLocked( OrphanablePtr lb_policy = MakeOrphanable(std::move(lb_policy_args), &xds_override_host_lb_trace); - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this - << "] Created new child policy handler " << lb_policy.get(); - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this + << "] Created new child policy handler " << lb_policy.get(); // Add our interested_parties pollset_set to that of the newly created // child policy. This will make the child policy progress upon activity on // this policy, which in turn is tied to the application's call. @@ -864,12 +838,11 @@ void XdsOverrideHostLb::UpdateAddressMap( // Skip draining hosts if not in the override status set. if (status.status() == XdsHealthStatus::kDraining && !override_host_status_set_.Contains(status)) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this << "] endpoint " - << endpoint.ToString() - << ": draining but not in override_host_status set -- " - "ignoring"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this << "] endpoint " + << endpoint.ToString() + << ": draining but not in override_host_status set -- " + "ignoring"; return; } std::vector addresses; @@ -877,10 +850,9 @@ void XdsOverrideHostLb::UpdateAddressMap( for (const auto& address : endpoint.addresses()) { auto key = grpc_sockaddr_to_string(&address, /*normalize=*/false); if (!key.ok()) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this - << "] no key for endpoint address; not adding to map"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this + << "] no key for endpoint address; not adding to map"; } else { addresses.push_back(*std::move(key)); } @@ -907,10 +879,9 @@ void XdsOverrideHostLb::UpdateAddressMap( MutexLock lock(&mu_); for (auto it = subchannel_map_.begin(); it != subchannel_map_.end();) { if (addresses_for_map.find(it->first) == addresses_for_map.end()) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this << "] removing map key " - << it->first; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this << "] removing map key " + << it->first; it->second->UnsetSubchannel(&subchannel_refs_to_drop); it = subchannel_map_.erase(it); } else { @@ -922,20 +893,17 @@ void XdsOverrideHostLb::UpdateAddressMap( auto& address_info = p.second; auto it = subchannel_map_.find(address); if (it == subchannel_map_.end()) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this << "] adding map key " - << address; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this << "] adding map key " + << address; it = subchannel_map_.emplace(address, MakeRefCounted()) .first; } - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this << "] map key " << address - << ": setting " - << "eds_health_status=" - << address_info.eds_health_status.ToString() - << " address_list=" << address_info.address_list.c_str(); - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this << "] map key " << address + << ": setting " + << "eds_health_status=" << address_info.eds_health_status.ToString() + << " address_list=" << address_info.address_list.c_str(); it->second->set_eds_health_status(address_info.eds_health_status); it->second->set_address_list(std::move(address_info.address_list)); // Check the entry's last_used_time to determine the next time at @@ -973,10 +941,9 @@ XdsOverrideHostLb::AdoptSubchannel( } void XdsOverrideHostLb::CreateSubchannelForAddress(absl::string_view address) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this - << "] creating owned subchannel for " << address; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this << "] creating owned subchannel for " + << address; auto addr = StringToSockaddr(address); CHECK(addr.ok()); // Note: We don't currently have any cases where per_address_args need to @@ -1016,10 +983,9 @@ void XdsOverrideHostLb::CleanupSubchannels() { if (p.second->last_used_time() <= idle_threshold) { auto subchannel = p.second->TakeOwnedSubchannel(); if (subchannel != nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << this - << "] dropping subchannel for " << p.first; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << this + << "] dropping subchannel for " << p.first; subchannel_refs_to_drop.push_back(std::move(subchannel)); } } else { @@ -1093,10 +1059,9 @@ void XdsOverrideHostLb::SubchannelWrapper::CancelConnectivityStateWatch( } void XdsOverrideHostLb::SubchannelWrapper::Orphaned() { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb " << policy_.get() - << "] subchannel wrapper " << this << " orphaned"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb " << policy_.get() << "] subchannel wrapper " + << this << " orphaned"; if (!IsWorkSerializerDispatchEnabled()) { wrapped_subchannel()->CancelConnectivityStateWatch(watcher_); if (subchannel_entry_ != nullptr) { @@ -1206,20 +1171,19 @@ void XdsOverrideHostLb::SubchannelEntry::OnSubchannelWrapperOrphan( auto* subchannel = GetSubchannel(); if (subchannel != wrapper) return; if (last_used_time_ < (Timestamp::Now() - connection_idle_timeout)) { - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb] removing unowned subchannel wrapper " - << subchannel; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb] removing unowned subchannel " + "wrapper " + << subchannel; subchannel_ = nullptr; } else { // The subchannel is being released by the child policy, but it // is still within its idle timeout, so we make a new copy of // the wrapper with the same underlying subchannel, and we hold // our own ref to it. - if (GRPC_TRACE_FLAG_ENABLED(xds_override_host_lb)) { - LOG(INFO) << "[xds_override_host_lb] subchannel wrapper " << subchannel - << ": cloning to gain ownership"; - } + GRPC_TRACE_LOG(xds_override_host_lb, INFO) + << "[xds_override_host_lb] subchannel wrapper " << subchannel + << ": cloning to gain ownership"; subchannel_ = wrapper->Clone(); } } diff --git a/src/core/load_balancing/xds/xds_wrr_locality.cc b/src/core/load_balancing/xds/xds_wrr_locality.cc index 25b1b4f0a9..7435032cee 100644 --- a/src/core/load_balancing/xds/xds_wrr_locality.cc +++ b/src/core/load_balancing/xds/xds_wrr_locality.cc @@ -29,7 +29,6 @@ #include #include -#include #include #include "src/core/lib/channel/channel_args.h" @@ -136,15 +135,13 @@ XdsWrrLocalityLb::XdsWrrLocalityLb(Args args) : LoadBalancingPolicy(std::move(args)) {} XdsWrrLocalityLb::~XdsWrrLocalityLb() { - if (GRPC_TRACE_FLAG_ENABLED(xds_wrr_locality_lb)) { - LOG(INFO) << "[xds_wrr_locality_lb " << this << "] destroying"; - } + GRPC_TRACE_LOG(xds_wrr_locality_lb, INFO) + << "[xds_wrr_locality_lb " << this << "] destroying"; } void XdsWrrLocalityLb::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(xds_wrr_locality_lb)) { - LOG(INFO) << "[xds_wrr_locality_lb " << this << "] shutting down"; - } + GRPC_TRACE_LOG(xds_wrr_locality_lb, INFO) + << "[xds_wrr_locality_lb " << this << "] shutting down"; if (child_policy_ != nullptr) { grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(), interested_parties()); @@ -161,9 +158,8 @@ void XdsWrrLocalityLb::ResetBackoffLocked() { } absl::Status XdsWrrLocalityLb::UpdateLocked(UpdateArgs args) { - if (GRPC_TRACE_FLAG_ENABLED(xds_wrr_locality_lb)) { - LOG(INFO) << "[xds_wrr_locality_lb " << this << "] Received update"; - } + GRPC_TRACE_LOG(xds_wrr_locality_lb, INFO) + << "[xds_wrr_locality_lb " << this << "] Received update"; auto config = args.config.TakeAsSubclass(); // Scan the addresses to find the weight for each locality. std::map locality_weights; @@ -203,11 +199,9 @@ absl::Status XdsWrrLocalityLb::UpdateLocked(UpdateArgs args) { })}, }), }); - if (GRPC_TRACE_FLAG_ENABLED(xds_wrr_locality_lb)) { - LOG(INFO) << "[xds_wrr_locality_lb " << this - << "] generated child policy config: " - << JsonDump(child_config_json, /*indent=*/1); - } + GRPC_TRACE_LOG(xds_wrr_locality_lb, INFO) + << "[xds_wrr_locality_lb " << this << "] generated child policy config: " + << JsonDump(child_config_json, /*indent=*/1); // Parse config. auto child_config = CoreConfiguration::Get().lb_policy_registry().ParseLoadBalancingConfig( @@ -239,10 +233,9 @@ absl::Status XdsWrrLocalityLb::UpdateLocked(UpdateArgs args) { update_args.resolution_note = std::move(args.resolution_note); update_args.args = std::move(args.args); // Update the policy. - if (GRPC_TRACE_FLAG_ENABLED(xds_wrr_locality_lb)) { - LOG(INFO) << "[xds_wrr_locality_lb " << this << "] updating child policy " - << child_policy_.get(); - } + GRPC_TRACE_LOG(xds_wrr_locality_lb, INFO) + << "[xds_wrr_locality_lb " << this << "] updating child policy " + << child_policy_.get(); return child_policy_->UpdateLocked(std::move(update_args)); } @@ -256,10 +249,9 @@ OrphanablePtr XdsWrrLocalityLb::CreateChildPolicyLocked( auto lb_policy = CoreConfiguration::Get().lb_policy_registry().CreateLoadBalancingPolicy( "weighted_target_experimental", std::move(lb_policy_args)); - if (GRPC_TRACE_FLAG_ENABLED(xds_wrr_locality_lb)) { - LOG(INFO) << "[xds_wrr_locality_lb " << this - << "] created new child policy " << lb_policy.get(); - } + GRPC_TRACE_LOG(xds_wrr_locality_lb, INFO) + << "[xds_wrr_locality_lb " << this << "] created new child policy " + << lb_policy.get(); // Add our interested_parties pollset_set to that of the newly created // child policy. This will make the child policy progress upon activity on // this LB policy, which in turn is tied to the application's call. diff --git a/src/core/resolver/binder/binder_resolver.cc b/src/core/resolver/binder/binder_resolver.cc index 7cd03f2919..f8da4cfd5e 100644 --- a/src/core/resolver/binder/binder_resolver.cc +++ b/src/core/resolver/binder/binder_resolver.cc @@ -43,8 +43,6 @@ #include "absl/strings/string_view.h" #include "absl/strings/strip.h" -#include - #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/config/core_configuration.h" #include "src/core/lib/gprpp/orphanable.h" 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 87f4d7f3f2..dbd8fc34a3 100644 --- a/src/core/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/resolver/dns/c_ares/dns_resolver_ares.cc @@ -34,7 +34,6 @@ #include #include -#include #include #include "src/core/lib/config/core_configuration.h" @@ -106,9 +105,10 @@ class AresClientChannelDNSResolver final : public PollingResolver { resolver_->authority().c_str(), resolver_->name_to_resolve().c_str(), kDefaultSecurePort, resolver_->interested_parties(), &on_hostname_resolved_, &addresses_, resolver_->query_timeout_ms_)); - GRPC_CARES_TRACE_LOG( - "resolver:%p Started resolving hostnames. hostname_request_:%p", - resolver_.get(), hostname_request_.get()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) resolver:" << resolver_.get() + << " Started resolving hostnames. hostname_request_:" + << hostname_request_.get(); if (resolver_->enable_srv_queries_) { Ref(DEBUG_LOCATION, "OnSRVResolved").release(); GRPC_CLOSURE_INIT(&on_srv_resolved_, OnSRVResolved, this, nullptr); @@ -117,9 +117,10 @@ class AresClientChannelDNSResolver final : public PollingResolver { resolver_->name_to_resolve().c_str(), resolver_->interested_parties(), &on_srv_resolved_, &balancer_addresses_, resolver_->query_timeout_ms_)); - GRPC_CARES_TRACE_LOG( - "resolver:%p Started resolving SRV records. srv_request_:%p", - resolver_.get(), srv_request_.get()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) resolver:" << resolver_.get() + << " Started resolving SRV records. srv_request_:" + << srv_request_.get(); } if (resolver_->request_service_config_) { Ref(DEBUG_LOCATION, "OnTXTResolved").release(); @@ -129,9 +130,10 @@ class AresClientChannelDNSResolver final : public PollingResolver { resolver_->name_to_resolve().c_str(), resolver_->interested_parties(), &on_txt_resolved_, &service_config_json_, resolver_->query_timeout_ms_)); - GRPC_CARES_TRACE_LOG( - "resolver:%p Started resolving TXT records. txt_request_:%p", - resolver_.get(), txt_request_.get()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) resolver:" << resolver_.get() + << " Started resolving TXT records. txt_request_:" + << txt_request_.get(); } } @@ -219,8 +221,9 @@ AresClientChannelDNSResolver::AresClientChannelDNSResolver( .value_or(GRPC_DNS_ARES_DEFAULT_QUERY_TIMEOUT_MS))) {} AresClientChannelDNSResolver::~AresClientChannelDNSResolver() { - GRPC_CARES_TRACE_LOG("resolver:%p destroying AresClientChannelDNSResolver", - this); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) resolver:" << this + << " destroying AresClientChannelDNSResolver"; } OrphanablePtr AresClientChannelDNSResolver::StartRequest() { @@ -283,15 +286,16 @@ AresClientChannelDNSResolver::AresRequestWrapper::OnResolvedLocked( grpc_error_handle error) ABSL_EXCLUSIVE_LOCKS_REQUIRED(on_resolved_mu_) { if (hostname_request_ != nullptr || srv_request_ != nullptr || txt_request_ != nullptr) { - GRPC_CARES_TRACE_LOG( - "resolver:%p OnResolved() waiting for results (hostname: %s, srv: %s, " - "txt: %s)", - this, hostname_request_ != nullptr ? "waiting" : "done", - srv_request_ != nullptr ? "waiting" : "done", - txt_request_ != nullptr ? "waiting" : "done"); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) resolver:" << this + << " OnResolved() waiting for results (hostname: " + << (hostname_request_ != nullptr ? "waiting" : "done") + << ", srv: " << (srv_request_ != nullptr ? "waiting" : "done") + << ", txt: " << (txt_request_ != nullptr ? "waiting" : "done") << ")"; return absl::nullopt; } - GRPC_CARES_TRACE_LOG("resolver:%p OnResolved() proceeding", this); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) resolver:" << this << " OnResolved() proceeding"; Result result; result.args = resolver_->channel_args(); // TODO(roth): Change logic to be able to report failures for addresses @@ -309,8 +313,9 @@ AresClientChannelDNSResolver::AresRequestWrapper::OnResolvedLocked( absl::StrCat("failed to parse service config: ", StatusToString(service_config_string.status()))); } else if (!service_config_string->empty()) { - GRPC_CARES_TRACE_LOG("resolver:%p selected service config choice: %s", - this, service_config_string->c_str()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) resolver:" << this + << " selected service config choice: " << *service_config_string; result.service_config = ServiceConfigImpl::Create( resolver_->channel_args(), *service_config_string); if (!result.service_config.ok()) { @@ -325,8 +330,9 @@ AresClientChannelDNSResolver::AresRequestWrapper::OnResolvedLocked( SetGrpcLbBalancerAddresses(result.args, *balancer_addresses_); } } else { - GRPC_CARES_TRACE_LOG("resolver:%p dns resolution failed: %s", this, - StatusToString(error).c_str()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) resolver:" << this + << " dns resolution failed: " << StatusToString(error); std::string error_message; grpc_error_get_str(error, StatusStrProperty::kDescription, &error_message); absl::Status status = absl::UnavailableError( @@ -375,8 +381,9 @@ class AresDNSResolver final : public DNSResolver { class AresRequest { public: virtual ~AresRequest() { - GRPC_CARES_TRACE_LOG("AresRequest:%p dtor ares_request_:%p", this, - grpc_ares_request_.get()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) AresRequest:" << this + << " dtor ares_request_:" << grpc_ares_request_.get(); resolver_->UnregisterRequest(task_handle()); grpc_pollset_set_destroy(pollset_set_); } @@ -397,8 +404,9 @@ class AresDNSResolver final : public DNSResolver { bool Cancel() { MutexLock lock(&mu_); if (grpc_ares_request_ != nullptr) { - GRPC_CARES_TRACE_LOG("AresRequest:%p Cancel ares_request_:%p", this, - grpc_ares_request_.get()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) AresRequest:" << this + << " Cancel ares_request_:" << grpc_ares_request_.get(); if (completed_) return false; // OnDnsLookupDone will still be run completed_ = true; @@ -499,7 +507,8 @@ class AresDNSResolver final : public DNSResolver { aba_token), default_port_(default_port), on_resolve_address_done_(std::move(on_resolve_address_done)) { - GRPC_CARES_TRACE_LOG("AresHostnameRequest:%p ctor", this); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) AresHostnameRequest:" << this << " ctor"; } std::unique_ptr MakeRequestLocked() override { @@ -508,13 +517,15 @@ class AresDNSResolver final : public DNSResolver { name_server().c_str(), name().c_str(), default_port_.c_str(), pollset_set(), on_dns_lookup_done(), &addresses_, timeout().millis())); - GRPC_CARES_TRACE_LOG("AresHostnameRequest:%p Start ares_request_:%p", - this, ares_request.get()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) AresHostnameRequest:" << this + << " Start ares_request_:" << ares_request.get(); return ares_request; } void OnComplete(grpc_error_handle error) override { - GRPC_CARES_TRACE_LOG("AresHostnameRequest:%p OnComplete", this); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) AresHostnameRequest:" << this << " OnComplete"; if (!error.ok()) { on_resolve_address_done_(grpc_error_to_absl_status(error)); return; @@ -550,7 +561,8 @@ class AresDNSResolver final : public DNSResolver { : AresRequest(name, name_server, timeout, interested_parties, resolver, aba_token), on_resolve_address_done_(std::move(on_resolve_address_done)) { - GRPC_CARES_TRACE_LOG("AresSRVRequest:%p ctor", this); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) AresSRVRequest:" << this << " ctor"; } std::unique_ptr MakeRequestLocked() override { @@ -558,13 +570,15 @@ class AresDNSResolver final : public DNSResolver { std::unique_ptr(grpc_dns_lookup_srv_ares( name_server().c_str(), name().c_str(), pollset_set(), on_dns_lookup_done(), &balancer_addresses_, timeout().millis())); - GRPC_CARES_TRACE_LOG("AresSRVRequest:%p Start ares_request_:%p", this, - ares_request.get()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) AresSRVRequest:" << this + << " Start ares_request_:" << ares_request.get(); return ares_request; } void OnComplete(grpc_error_handle error) override { - GRPC_CARES_TRACE_LOG("AresSRVRequest:%p OnComplete", this); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) AresSRVRequest:" << this << " OnComplete"; if (!error.ok()) { on_resolve_address_done_(grpc_error_to_absl_status(error)); return; @@ -596,7 +610,8 @@ class AresDNSResolver final : public DNSResolver { : AresRequest(name, name_server, timeout, interested_parties, resolver, aba_token), on_resolved_(std::move(on_resolved)) { - GRPC_CARES_TRACE_LOG("AresTXTRequest:%p ctor", this); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) AresTXTRequest:" << this << " ctor"; } ~AresTXTRequest() override { gpr_free(service_config_json_); } @@ -606,13 +621,15 @@ class AresDNSResolver final : public DNSResolver { std::unique_ptr(grpc_dns_lookup_txt_ares( name_server().c_str(), name().c_str(), pollset_set(), on_dns_lookup_done(), &service_config_json_, timeout().millis())); - GRPC_CARES_TRACE_LOG("AresSRVRequest:%p Start ares_request_:%p", this, - ares_request.get()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) AresSRVRequest:" << this + << " Start ares_request_:" << ares_request.get(); return ares_request; } void OnComplete(grpc_error_handle error) override { - GRPC_CARES_TRACE_LOG("AresSRVRequest:%p OnComplete", this); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) AresSRVRequest:" << this << " OnComplete"; if (!error.ok()) { on_resolved_(grpc_error_to_absl_status(error)); return; @@ -684,14 +701,15 @@ class AresDNSResolver final : public DNSResolver { MutexLock lock(&mu_); if (!open_requests_.contains(handle)) { // Unknown request, possibly completed already, or an invalid handle. - GRPC_CARES_TRACE_LOG( - "AresDNSResolver:%p attempt to cancel unknown TaskHandle:%s", this, - HandleToString(handle).c_str()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) AresDNSResolver:" << this + << " attempt to cancel unknown TaskHandle:" << HandleToString(handle); return false; } auto* request = reinterpret_cast(handle.keys[0]); - GRPC_CARES_TRACE_LOG("AresDNSResolver:%p cancel ares_request:%p", this, - request); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) AresDNSResolver:" << this + << " cancel ares_request:" << request; return request->Cancel(); } diff --git a/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc b/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc index 0773894220..ce54f647f1 100644 --- a/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +++ b/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc @@ -39,8 +39,6 @@ #include "absl/log/check.h" #include "absl/strings/str_cat.h" -#include - #include "src/core/lib/gprpp/sync.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/error.h" 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 ef70bfc5b6..9b9a79b320 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 @@ -33,7 +33,6 @@ #include "absl/strings/str_format.h" #include -#include #include #include #include @@ -73,7 +72,7 @@ namespace { // instantiated at the top of the virtual socket function callstack. class WSAErrorContext final { public: - explicit WSAErrorContext(){}; + explicit WSAErrorContext() {}; ~WSAErrorContext() { if (error_ != 0) { @@ -133,8 +132,9 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { } ~GrpcPolledFdWindows() override { - GRPC_CARES_TRACE_LOG("fd:|%s| ~GrpcPolledFdWindows shutdown_called_: %d ", - GetName(), shutdown_called_); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:|" << GetName() + << "| ~GrpcPolledFdWindows shutdown_called_: " << shutdown_called_; CSliceUnref(read_buf_); CSliceUnref(write_buf_); CHECK_EQ(read_closure_, nullptr); @@ -173,10 +173,10 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { } void ContinueRegisterForOnReadableLocked() { - GRPC_CARES_TRACE_LOG( - "fd:|%s| ContinueRegisterForOnReadableLocked " - "wsa_connect_error_:%d", - GetName(), wsa_connect_error_); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:|" << GetName() + << "| ContinueRegisterForOnReadableLocked " + << "wsa_connect_error_:" << wsa_connect_error_; CHECK(connect_done_); if (wsa_connect_error_ != 0) { ScheduleAndNullReadClosure(GRPC_WSA_ERROR(wsa_connect_error_, "connect")); @@ -194,10 +194,10 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { &winsocket_->read_info.overlapped, nullptr)) { int wsa_last_error = WSAGetLastError(); char* msg = gpr_format_message(wsa_last_error); - GRPC_CARES_TRACE_LOG( - "fd:|%s| RegisterForOnReadableLocked WSARecvFrom error code:|%d| " - "msg:|%s|", - GetName(), wsa_last_error, msg); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:|" << GetName() + << "| RegisterForOnReadableLocked WSARecvFrom error code:|" + << wsa_last_error << "| msg:|" << msg << "|"; gpr_free(msg); if (wsa_last_error != WSA_IO_PENDING) { ScheduleAndNullReadClosure( @@ -210,14 +210,15 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { void RegisterForOnWriteableLocked(grpc_closure* write_closure) override { if (socket_type_ == SOCK_DGRAM) { - GRPC_CARES_TRACE_LOG("fd:|%s| RegisterForOnWriteableLocked called", - GetName()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:|" << GetName() + << "| RegisterForOnWriteableLocked called"; } else { CHECK(socket_type_ == SOCK_STREAM); - GRPC_CARES_TRACE_LOG( - "fd:|%s| RegisterForOnWriteableLocked called tcp_write_state_: %d " - "connect_done_: %d", - GetName(), tcp_write_state_, connect_done_); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:|" << GetName() + << "| RegisterForOnWriteableLocked called tcp_write_state_: " + << tcp_write_state_ << " connect_done_: " << connect_done_; } CHECK_EQ(write_closure_, nullptr); write_closure_ = write_closure; @@ -234,10 +235,10 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { } void ContinueRegisterForOnWriteableLocked() { - GRPC_CARES_TRACE_LOG( - "fd:|%s| ContinueRegisterForOnWriteableLocked " - "wsa_connect_error_:%d", - GetName(), wsa_connect_error_); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:|" << GetName() + << "| ContinueRegisterForOnWriteableLocked " + << "wsa_connect_error_:" << wsa_connect_error_; CHECK(connect_done_); if (wsa_connect_error_ != 0) { ScheduleAndNullWriteClosure( @@ -288,10 +289,10 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { ares_ssize_t RecvFrom(WSAErrorContext* wsa_error_ctx, void* data, ares_socket_t data_len, int /* flags */, struct sockaddr* from, ares_socklen_t* from_len) { - GRPC_CARES_TRACE_LOG( - "fd:|%s| RecvFrom called read_buf_has_data:%d Current read buf " - "length:|%d|", - GetName(), read_buf_has_data_, GRPC_SLICE_LENGTH(read_buf_)); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << GetName() + << " RecvFrom called read_buf_has_data:" << read_buf_has_data_ + << " Current read buf length:" << GRPC_SLICE_LENGTH(read_buf_); if (!read_buf_has_data_) { wsa_error_ctx->SetWSAError(WSAEWOULDBLOCK); return -1; @@ -340,20 +341,21 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { int out = WSASend(grpc_winsocket_wrapped_socket(winsocket_), &buf, 1, bytes_sent_ptr, flags, overlapped, nullptr); *wsa_error_code = WSAGetLastError(); - GRPC_CARES_TRACE_LOG( - "fd:|%s| SendWriteBuf WSASend buf.len:%d *bytes_sent_ptr:%d " - "overlapped:%p " - "return:%d *wsa_error_code:%d", - GetName(), buf.len, bytes_sent_ptr != nullptr ? *bytes_sent_ptr : 0, - overlapped, out, *wsa_error_code); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << GetName() + << " SendWriteBuf WSASend buf.len:" << buf.len << " *bytes_sent_ptr:" + << (bytes_sent_ptr != nullptr ? *bytes_sent_ptr : 0) + << " overlapped:" << overlapped << " return:" << out + << " *wsa_error_code:" << *wsa_error_code; return out; } ares_ssize_t SendV(WSAErrorContext* wsa_error_ctx, const struct iovec* iov, int iov_count) { - GRPC_CARES_TRACE_LOG( - "fd:|%s| SendV called connect_done_:%d wsa_connect_error_:%d", - GetName(), connect_done_, wsa_connect_error_); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << GetName() + << " SendV called connect_done_:" << connect_done_ + << " wsa_connect_error_:" << wsa_connect_error_; if (!connect_done_) { wsa_error_ctx->SetWSAError(WSAEWOULDBLOCK); return -1; @@ -377,7 +379,8 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { // c-ares doesn't handle retryable errors on writes of UDP sockets. // Therefore, the sendv handler for UDP sockets must only attempt // to write everything inline. - GRPC_CARES_TRACE_LOG("fd:|%s| SendVUDP called", GetName()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << GetName() << " SendVUDP called"; CHECK_EQ(GRPC_SLICE_LENGTH(write_buf_), 0); CSliceUnref(write_buf_); write_buf_ = FlattenIovec(iov, iov_count); @@ -388,9 +391,10 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { write_buf_ = grpc_empty_slice(); wsa_error_ctx->SetWSAError(wsa_error_code); char* msg = gpr_format_message(wsa_error_code); - GRPC_CARES_TRACE_LOG( - "fd:|%s| SendVUDP SendWriteBuf error code:%d msg:|%s|", GetName(), - wsa_error_code, msg); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << GetName() + << " SendVUDP SendWriteBuf error code:" << wsa_error_code + << " msg:" << msg; gpr_free(msg); return -1; } @@ -406,8 +410,9 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { // out in the background, and making further send progress in general, will // happen as long as c-ares continues to show interest in writeability on // this fd. - GRPC_CARES_TRACE_LOG("fd:|%s| SendVTCP called tcp_write_state_:%d", - GetName(), tcp_write_state_); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << GetName() + << " SendVTCP called tcp_write_state_:" << tcp_write_state_; switch (tcp_write_state_) { case WRITE_IDLE: tcp_write_state_ = WRITE_REQUESTED; @@ -450,13 +455,13 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { } void OnTcpConnectLocked(grpc_error_handle error) { - GRPC_CARES_TRACE_LOG( - "fd:%s InnerOnTcpConnectLocked error:|%s| " - "pending_register_for_readable:%d" - " pending_register_for_writeable:%d", - GetName(), StatusToString(error).c_str(), - pending_continue_register_for_on_readable_locked_, - pending_continue_register_for_on_writeable_locked_); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << GetName() + << " InnerOnTcpConnectLocked error:" << StatusToString(error) + << " pending_register_for_readable:" + << pending_continue_register_for_on_readable_locked_ + << " pending_register_for_writeable:" + << pending_continue_register_for_on_writeable_locked_; CHECK(!connect_done_); connect_done_ = true; CHECK_EQ(wsa_connect_error_, 0); @@ -473,10 +478,10 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { if (!wsa_success) { wsa_connect_error_ = WSAGetLastError(); char* msg = gpr_format_message(wsa_connect_error_); - GRPC_CARES_TRACE_LOG( - "fd:%s InnerOnTcpConnectLocked WSA overlapped result code:%d " - "msg:|%s|", - GetName(), wsa_connect_error_, msg); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << GetName() + << " InnerOnTcpConnectLocked WSA overlapped result code:" + << wsa_connect_error_ << " msg:" << msg; gpr_free(msg); } } @@ -502,7 +507,8 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { int ConnectUDP(WSAErrorContext* wsa_error_ctx, const struct sockaddr* target, ares_socklen_t target_len) { - GRPC_CARES_TRACE_LOG("fd:%s ConnectUDP", GetName()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << GetName() << " ConnectUDP"; CHECK(!connect_done_); CHECK_EQ(wsa_connect_error_, 0); SOCKET s = grpc_winsocket_wrapped_socket(winsocket_); @@ -512,8 +518,9 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { wsa_error_ctx->SetWSAError(wsa_connect_error_); connect_done_ = true; char* msg = gpr_format_message(wsa_connect_error_); - GRPC_CARES_TRACE_LOG("fd:%s WSAConnect error code:|%d| msg:|%s|", GetName(), - wsa_connect_error_, msg); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << GetName() << " WSAConnect error code:|" + << wsa_connect_error_ << "| msg:|" << msg << "|"; gpr_free(msg); // c-ares expects a posix-style connect API return out == 0 ? 0 : -1; @@ -521,7 +528,8 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { int ConnectTCP(WSAErrorContext* wsa_error_ctx, const struct sockaddr* target, ares_socklen_t target_len) { - GRPC_CARES_TRACE_LOG("fd:%s ConnectTCP", GetName()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << GetName() << " ConnectTCP"; LPFN_CONNECTEX ConnectEx; GUID guid = WSAID_CONNECTEX; DWORD ioctl_num_bytes; @@ -532,10 +540,10 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { int wsa_last_error = WSAGetLastError(); wsa_error_ctx->SetWSAError(wsa_last_error); char* msg = gpr_format_message(wsa_last_error); - GRPC_CARES_TRACE_LOG( - "fd:%s WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER) error code:%d " - "msg:|%s|", - GetName(), wsa_last_error, msg); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << GetName() + << " WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER) error code:" + << wsa_last_error << " msg:|" << msg << "|"; gpr_free(msg); connect_done_ = true; wsa_connect_error_ = wsa_last_error; @@ -555,8 +563,9 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { int wsa_last_error = WSAGetLastError(); wsa_error_ctx->SetWSAError(wsa_last_error); char* msg = gpr_format_message(wsa_last_error); - GRPC_CARES_TRACE_LOG("fd:%s bind error code:%d msg:|%s|", GetName(), - wsa_last_error, msg); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << GetName() + << " bind error code:" << wsa_last_error << " msg:|" << msg << "|"; gpr_free(msg); connect_done_ = true; wsa_connect_error_ = wsa_last_error; @@ -569,8 +578,10 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { int wsa_last_error = WSAGetLastError(); wsa_error_ctx->SetWSAError(wsa_last_error); char* msg = gpr_format_message(wsa_last_error); - GRPC_CARES_TRACE_LOG("fd:%s ConnectEx error code:%d msg:|%s|", GetName(), - wsa_last_error, msg); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << GetName() + << " ConnectEx error code:" << wsa_last_error << " msg:|" << msg + << "|"; gpr_free(msg); if (wsa_last_error == WSA_IO_PENDING) { // c-ares only understands WSAEINPROGRESS and EWOULDBLOCK error codes on @@ -610,11 +621,12 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { if (winsocket_->read_info.wsa_error != WSAEMSGSIZE) { error = GRPC_WSA_ERROR(winsocket_->read_info.wsa_error, "OnIocpReadableInner"); - GRPC_CARES_TRACE_LOG( - "fd:|%s| OnIocpReadableInner winsocket_->read_info.wsa_error " - "code:|%d| msg:|%s|", - GetName(), winsocket_->read_info.wsa_error, - StatusToString(error).c_str()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:|" << GetName() + << "| OnIocpReadableInner winsocket_->read_info.wsa_error " + "code:|" + << winsocket_->read_info.wsa_error << "| msg:|" + << StatusToString(error) << "|"; } } } @@ -626,9 +638,10 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { CSliceUnref(read_buf_); read_buf_ = grpc_empty_slice(); } - GRPC_CARES_TRACE_LOG( - "fd:|%s| OnIocpReadable finishing. read buf length now:|%d|", GetName(), - GRPC_SLICE_LENGTH(read_buf_)); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:|" << GetName() + << "| OnIocpReadable finishing. read buf length now:|" + << GRPC_SLICE_LENGTH(read_buf_) << "|"; ScheduleAndNullReadClosure(error); } @@ -639,17 +652,19 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { } void OnIocpWriteableLocked(grpc_error_handle error) { - GRPC_CARES_TRACE_LOG("OnIocpWriteableInner. fd:|%s|", GetName()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) OnIocpWriteableInner. fd:|" << GetName() << "|"; CHECK(socket_type_ == SOCK_STREAM); if (error.ok()) { if (winsocket_->write_info.wsa_error != 0) { error = GRPC_WSA_ERROR(winsocket_->write_info.wsa_error, "OnIocpWriteableInner"); - GRPC_CARES_TRACE_LOG( - "fd:|%s| OnIocpWriteableInner. winsocket_->write_info.wsa_error " - "code:|%d| msg:|%s|", - GetName(), winsocket_->write_info.wsa_error, - StatusToString(error).c_str()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:|" << GetName() + << "| OnIocpWriteableInner. winsocket_->write_info.wsa_error " + "code:|" + << winsocket_->write_info.wsa_error << "| msg:|" + << StatusToString(error) << "|"; } } CHECK(tcp_write_state_ == WRITE_PENDING); @@ -657,8 +672,10 @@ class GrpcPolledFdWindows final : public GrpcPolledFd { tcp_write_state_ = WRITE_WAITING_FOR_VERIFICATION_UPON_RETRY; write_buf_ = grpc_slice_sub_no_ref( write_buf_, 0, winsocket_->write_info.bytes_transferred); - GRPC_CARES_TRACE_LOG("fd:|%s| OnIocpWriteableInner. bytes transferred:%d", - GetName(), winsocket_->write_info.bytes_transferred); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:|" << GetName() + << "| OnIocpWriteableInner. bytes transferred:" + << winsocket_->write_info.bytes_transferred; } else { CSliceUnref(write_buf_); write_buf_ = grpc_empty_slice(); @@ -728,7 +745,9 @@ class GrpcPolledFdFactoryWindows final : public GrpcPolledFdFactory { // static ares_socket_t Socket(int af, int type, int protocol, void* user_data) { if (type != SOCK_DGRAM && type != SOCK_STREAM) { - GRPC_CARES_TRACE_LOG("Socket called with invalid socket type:%d", type); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) Socket called with invalid socket type:" + << type; return INVALID_SOCKET; } GrpcPolledFdFactoryWindows* self = @@ -736,15 +755,16 @@ class GrpcPolledFdFactoryWindows final : public GrpcPolledFdFactory { SOCKET s = WSASocket(af, type, protocol, nullptr, 0, grpc_get_default_wsa_socket_flags()); if (s == INVALID_SOCKET) { - GRPC_CARES_TRACE_LOG( - "WSASocket failed with params af:%d type:%d protocol:%d", af, type, - protocol); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) WSASocket failed with params af:" << af + << " type:" << type << " protocol:" << protocol; return s; } grpc_error_handle error = grpc_tcp_set_non_block(s); if (!error.ok()) { - GRPC_CARES_TRACE_LOG("WSAIoctl failed with error: %s", - StatusToString(error).c_str()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) WSAIoctl failed with error: " + << StatusToString(error); return INVALID_SOCKET; } auto on_shutdown_locked = [self, s]() { @@ -755,9 +775,10 @@ class GrpcPolledFdFactoryWindows final : public GrpcPolledFdFactory { }; auto polled_fd = new GrpcPolledFdWindows(s, self->mu_, af, type, std::move(on_shutdown_locked)); - GRPC_CARES_TRACE_LOG( - "fd:|%s| created with params af:%d type:%d protocol:%d", - polled_fd->GetName(), af, type, protocol); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) fd:" << polled_fd->GetName() + << " created with params af:" << af << " type:" << type + << " protocol:" << protocol; CHECK(self->sockets_.insert({s, polled_fd}).second); return s; } 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 373727a990..50161653ea 100644 --- a/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc +++ b/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc @@ -181,11 +181,28 @@ class GrpcAresQuery final { const std::string name_; }; +static absl::Status AresStatusToAbslStatus(int status, + absl::string_view error_msg) { + switch (status) { + case ARES_ECANCELLED: + return absl::CancelledError(error_msg); + case ARES_ENOTIMP: + return absl::UnimplementedError(error_msg); + case ARES_ENOTFOUND: + return absl::NotFoundError(error_msg); + case ARES_ECONNREFUSED: + return absl::UnavailableError(error_msg); + default: + return absl::UnknownError(error_msg); + } +} + static grpc_ares_ev_driver* grpc_ares_ev_driver_ref( grpc_ares_ev_driver* ev_driver) ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) { - GRPC_CARES_TRACE_LOG("request:%p Ref ev_driver %p", ev_driver->request, - ev_driver); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << ev_driver->request << " Ref ev_driver " + << ev_driver; gpr_ref(&ev_driver->refs); return ev_driver; } @@ -195,11 +212,13 @@ static void grpc_ares_complete_request_locked(grpc_ares_request* r) static void grpc_ares_ev_driver_unref(grpc_ares_ev_driver* ev_driver) ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) { - GRPC_CARES_TRACE_LOG("request:%p Unref ev_driver %p", ev_driver->request, - ev_driver); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << ev_driver->request + << " Unref ev_driver " << ev_driver; if (gpr_unref(&ev_driver->refs)) { - GRPC_CARES_TRACE_LOG("request:%p destroy ev_driver %p", ev_driver->request, - ev_driver); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << ev_driver->request + << " destroy ev_driver " << ev_driver; CHECK_EQ(ev_driver->fds, nullptr); ares_destroy(ev_driver->channel); grpc_ares_complete_request_locked(ev_driver->request); @@ -209,8 +228,9 @@ static void grpc_ares_ev_driver_unref(grpc_ares_ev_driver* ev_driver) static void fd_node_destroy_locked(fd_node* fdn) ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) { - GRPC_CARES_TRACE_LOG("request:%p delete fd: %s", fdn->ev_driver->request, - fdn->grpc_polled_fd->GetName()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << fdn->ev_driver->request + << " delete fd: " << fdn->grpc_polled_fd->GetName(); CHECK(!fdn->readable_registered); CHECK(!fdn->writable_registered); CHECK(fdn->already_shutdown); @@ -276,21 +296,21 @@ static grpc_core::Timestamp calculate_next_ares_backup_poll_alarm( // by the c-ares code comments. grpc_core::Duration until_next_ares_backup_poll_alarm = grpc_core::Duration::Seconds(1); - GRPC_CARES_TRACE_LOG( - "request:%p ev_driver=%p. next ares process poll time in " - "%" PRId64 " ms", - driver->request, driver, until_next_ares_backup_poll_alarm.millis()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << driver->request + << " ev_driver=" << driver << ". next ares process poll time in " + << until_next_ares_backup_poll_alarm.millis() << " ms"; return grpc_core::Timestamp::Now() + until_next_ares_backup_poll_alarm; } static void on_timeout(void* arg, grpc_error_handle error) { grpc_ares_ev_driver* driver = static_cast(arg); grpc_core::MutexLock lock(&driver->request->mu); - GRPC_CARES_TRACE_LOG( - "request:%p ev_driver=%p on_timeout_locked. driver->shutting_down=%d. " - "err=%s", - driver->request, driver, driver->shutting_down, - grpc_core::StatusToString(error).c_str()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << driver->request + << " ev_driver=" << driver + << " on_timeout_locked. driver->shutting_down=" << driver->shutting_down + << ". err=" << grpc_core::StatusToString(error); if (!driver->shutting_down && error.ok()) { grpc_ares_ev_driver_shutdown_locked(driver); } @@ -311,20 +331,20 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) static void on_ares_backup_poll_alarm(void* arg, grpc_error_handle error) { grpc_ares_ev_driver* driver = static_cast(arg); grpc_core::MutexLock lock(&driver->request->mu); - GRPC_CARES_TRACE_LOG( - "request:%p ev_driver=%p on_ares_backup_poll_alarm_locked. " - "driver->shutting_down=%d. " - "err=%s", - driver->request, driver, driver->shutting_down, - grpc_core::StatusToString(error).c_str()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << driver->request + << " ev_driver=" << driver + << " on_ares_backup_poll_alarm_locked. driver->shutting_down=" + << driver->shutting_down << ". err=" << grpc_core::StatusToString(error); if (!driver->shutting_down && error.ok()) { fd_node* fdn = driver->fds; while (fdn != nullptr) { if (!fdn->already_shutdown) { - GRPC_CARES_TRACE_LOG( - "request:%p ev_driver=%p on_ares_backup_poll_alarm_locked; " - "ares_process_fd. fd=%s", - driver->request, driver, fdn->grpc_polled_fd->GetName()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << driver->request + << " ev_driver=" << driver + << " on_ares_backup_poll_alarm_locked; ares_process_fd. fd=" + << fdn->grpc_polled_fd->GetName(); ares_socket_t as = fdn->grpc_polled_fd->GetWrappedAresSocketLocked(); ares_process_fd(driver->channel, as, as); } @@ -357,8 +377,9 @@ static void on_readable(void* arg, grpc_error_handle error) { grpc_ares_ev_driver* ev_driver = fdn->ev_driver; const ares_socket_t as = fdn->grpc_polled_fd->GetWrappedAresSocketLocked(); fdn->readable_registered = false; - GRPC_CARES_TRACE_LOG("request:%p readable on %s", fdn->ev_driver->request, - fdn->grpc_polled_fd->GetName()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << fdn->ev_driver->request + << " readable on " << fdn->grpc_polled_fd->GetName(); if (error.ok() && !ev_driver->shutting_down) { ares_process_fd(ev_driver->channel, as, ARES_SOCKET_BAD); } else { @@ -381,8 +402,9 @@ static void on_writable(void* arg, grpc_error_handle error) { grpc_ares_ev_driver* ev_driver = fdn->ev_driver; const ares_socket_t as = fdn->grpc_polled_fd->GetWrappedAresSocketLocked(); fdn->writable_registered = false; - GRPC_CARES_TRACE_LOG("request:%p writable on %s", ev_driver->request, - fdn->grpc_polled_fd->GetName()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << ev_driver->request << " writable on " + << fdn->grpc_polled_fd->GetName(); if (error.ok() && !ev_driver->shutting_down) { ares_process_fd(ev_driver->channel, ARES_SOCKET_BAD, as); } else { @@ -417,8 +439,9 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) fdn->grpc_polled_fd = ev_driver->polled_fd_factory->NewGrpcPolledFdLocked( socks[i], ev_driver->pollset_set); - GRPC_CARES_TRACE_LOG("request:%p new fd: %s", ev_driver->request, - fdn->grpc_polled_fd->GetName()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << ev_driver->request + << " new fd: " << fdn->grpc_polled_fd->GetName(); fdn->readable_registered = false; fdn->writable_registered = false; fdn->already_shutdown = false; @@ -433,15 +456,16 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) GRPC_CLOSURE_INIT(&fdn->read_closure, on_readable, fdn, grpc_schedule_on_exec_ctx); if (fdn->grpc_polled_fd->IsFdStillReadableLocked()) { - GRPC_CARES_TRACE_LOG("request:%p schedule direct read on: %s", - ev_driver->request, - fdn->grpc_polled_fd->GetName()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << ev_driver->request + << " schedule direct read on: " + << fdn->grpc_polled_fd->GetName(); grpc_core::ExecCtx::Run(DEBUG_LOCATION, &fdn->read_closure, absl::OkStatus()); } else { - GRPC_CARES_TRACE_LOG("request:%p notify read on: %s", - ev_driver->request, - fdn->grpc_polled_fd->GetName()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << ev_driver->request + << " notify read on: " << fdn->grpc_polled_fd->GetName(); fdn->grpc_polled_fd->RegisterForOnReadableLocked( &fdn->read_closure); } @@ -451,9 +475,9 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) // has not been registered with this socket. if (ARES_GETSOCK_WRITABLE(socks_bitmask, i) && !fdn->writable_registered) { - GRPC_CARES_TRACE_LOG("request:%p notify write on: %s", - ev_driver->request, - fdn->grpc_polled_fd->GetName()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << ev_driver->request + << " notify write on: " << fdn->grpc_polled_fd->GetName(); grpc_ares_ev_driver_ref(ev_driver); GRPC_CLOSURE_INIT(&fdn->write_closure, on_writable, fdn, grpc_schedule_on_exec_ctx); @@ -489,10 +513,11 @@ void grpc_ares_ev_driver_start_locked(grpc_ares_ev_driver* ev_driver) ev_driver->query_timeout_ms == 0 ? grpc_core::Duration::Infinity() : grpc_core::Duration::Milliseconds(ev_driver->query_timeout_ms); - GRPC_CARES_TRACE_LOG( - "request:%p ev_driver=%p grpc_ares_ev_driver_start_locked. timeout in " - "%" PRId64 " ms", - ev_driver->request, ev_driver, timeout.millis()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << ev_driver->request + << " ev_driver=" << ev_driver + << " grpc_ares_ev_driver_start_locked. timeout in " << timeout.millis() + << " ms"; grpc_ares_ev_driver_ref(ev_driver); GRPC_CLOSURE_INIT(&ev_driver->on_timeout_locked, on_timeout, ev_driver, grpc_schedule_on_exec_ctx); @@ -531,7 +556,8 @@ grpc_error_handle grpc_ares_ev_driver_create_locked( } int status = ares_init_options(&(*ev_driver)->channel, &opts, ARES_OPT_FLAGS); grpc_ares_test_only_inject_config(&(*ev_driver)->channel); - GRPC_CARES_TRACE_LOG("request:%p grpc_ares_ev_driver_create_locked", request); + GRPC_TRACE_VLOG(cares_resolver, 2) << "(c-ares resolver) request:" << request + << " grpc_ares_ev_driver_create_locked"; if (status != ARES_SUCCESS) { grpc_error_handle err = GRPC_ERROR_CREATE(absl::StrCat( "Failed to init ares channel. C-ares error: ", ares_strerror(status))); @@ -629,10 +655,10 @@ static grpc_ares_hostbyname_request* create_hostbyname_request_locked( grpc_ares_request* parent_request, const char* host, uint16_t port, bool is_balancer, const char* qtype) ABSL_EXCLUSIVE_LOCKS_REQUIRED(parent_request->mu) { - GRPC_CARES_TRACE_LOG( - "request:%p create_hostbyname_request_locked host:%s port:%d " - "is_balancer:%d qtype:%s", - parent_request, host, port, is_balancer, qtype); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << parent_request + << " create_hostbyname_request_locked host:" << host << " port:" << port + << " is_balancer:" << is_balancer << " qtype:" << qtype; grpc_ares_hostbyname_request* hr = new grpc_ares_hostbyname_request(); hr->parent_request = parent_request; hr->host = gpr_strdup(host); @@ -659,9 +685,10 @@ static void on_hostbyname_done_locked(void* arg, int status, int /*timeouts*/, static_cast(arg); grpc_ares_request* r = hr->parent_request; if (status == ARES_SUCCESS) { - GRPC_CARES_TRACE_LOG( - "request:%p on_hostbyname_done_locked qtype=%s host=%s ARES_SUCCESS", r, - hr->qtype, hr->host); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << r + << " on_hostbyname_done_locked qtype=" << hr->qtype + << " host=" << hr->host << " ARES_SUCCESS"; std::unique_ptr* address_list_ptr = hr->is_balancer ? r->balancer_addresses_out : r->addresses_out; if (*address_list_ptr == nullptr) { @@ -685,10 +712,11 @@ static void on_hostbyname_done_locked(void* arg, int status, int /*timeouts*/, addr->sin6_port = hr->port; char output[INET6_ADDRSTRLEN]; ares_inet_ntop(AF_INET6, &addr->sin6_addr, output, INET6_ADDRSTRLEN); - GRPC_CARES_TRACE_LOG( - "request:%p c-ares resolver gets a AF_INET6 result: \n" - " addr: %s\n port: %d\n sin6_scope_id: %d\n", - r, output, ntohs(hr->port), addr->sin6_scope_id); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << r + << " c-ares resolver gets a AF_INET6 result: \n" + << " addr: " << output << "\n port: " << ntohs(hr->port) + << "\n sin6_scope_id: " << addr->sin6_scope_id << "\n"; break; } case AF_INET: { @@ -700,10 +728,10 @@ static void on_hostbyname_done_locked(void* arg, int status, int /*timeouts*/, addr->sin_port = hr->port; char output[INET_ADDRSTRLEN]; ares_inet_ntop(AF_INET, &addr->sin_addr, output, INET_ADDRSTRLEN); - GRPC_CARES_TRACE_LOG( - "request:%p c-ares resolver gets a AF_INET result: \n" - " addr: %s\n port: %d\n", - r, output, ntohs(hr->port)); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << r + << " c-ares resolver gets a AF_INET result: \n addr: " << output + << "\n port: " << ntohs(hr->port) << "\n"; break; } } @@ -713,10 +741,11 @@ static void on_hostbyname_done_locked(void* arg, int status, int /*timeouts*/, std::string error_msg = absl::StrFormat( "C-ares status is not ARES_SUCCESS qtype=%s name=%s is_balancer=%d: %s", hr->qtype, hr->host, hr->is_balancer, ares_strerror(status)); - GRPC_CARES_TRACE_LOG("request:%p on_hostbyname_done_locked: %s", r, - error_msg.c_str()); - grpc_error_handle error = GRPC_ERROR_CREATE(error_msg); - r->error = grpc_error_add_child(error, r->error); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << r + << " on_hostbyname_done_locked: " << error_msg; + r->error = grpc_error_add_child(AresStatusToAbslStatus(status, error_msg), + r->error); } destroy_hostbyname_request_locked(hr); } @@ -729,13 +758,14 @@ static void on_srv_query_done_locked(void* arg, int status, int /*timeouts*/, GrpcAresQuery* q = static_cast(arg); grpc_ares_request* r = q->parent_request(); if (status == ARES_SUCCESS) { - GRPC_CARES_TRACE_LOG( - "request:%p on_srv_query_done_locked name=%s ARES_SUCCESS", r, - q->name().c_str()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << r + << " on_srv_query_done_locked name=" << q->name() << " ARES_SUCCESS"; struct ares_srv_reply* reply; const int parse_status = ares_parse_srv_reply(abuf, alen, &reply); - GRPC_CARES_TRACE_LOG("request:%p ares_parse_srv_reply: %d", r, - parse_status); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << r + << " ares_parse_srv_reply: " << parse_status; if (parse_status == ARES_SUCCESS) { for (struct ares_srv_reply* srv_it = reply; srv_it != nullptr; srv_it = srv_it->next) { @@ -759,10 +789,11 @@ static void on_srv_query_done_locked(void* arg, int status, int /*timeouts*/, std::string error_msg = absl::StrFormat( "C-ares status is not ARES_SUCCESS qtype=SRV name=%s: %s", q->name(), ares_strerror(status)); - GRPC_CARES_TRACE_LOG("request:%p on_srv_query_done_locked: %s", r, - error_msg.c_str()); - grpc_error_handle error = GRPC_ERROR_CREATE(error_msg); - r->error = grpc_error_add_child(error, r->error); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << r + << " on_srv_query_done_locked: " << error_msg; + r->error = grpc_error_add_child(AresStatusToAbslStatus(status, error_msg), + r->error); } delete q; } @@ -780,10 +811,10 @@ static void on_txt_done_locked(void* arg, int status, int /*timeouts*/, const size_t prefix_len = sizeof(g_service_config_attribute_prefix) - 1; struct ares_txt_ext* result = nullptr; struct ares_txt_ext* reply = nullptr; - grpc_error_handle error; if (status != ARES_SUCCESS) goto fail; - GRPC_CARES_TRACE_LOG("request:%p on_txt_done_locked name=%s ARES_SUCCESS", r, - q->name().c_str()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << r + << " on_txt_done_locked name=" << q->name() << " ARES_SUCCESS"; status = ares_parse_txt_reply_ext(buf, len, &reply); if (status != ARES_SUCCESS) goto fail; // Find service config in TXT record. @@ -811,8 +842,9 @@ static void on_txt_done_locked(void* arg, int status, int /*timeouts*/, service_config_len += result->length; } (*r->service_config_json_out)[service_config_len] = '\0'; - GRPC_CARES_TRACE_LOG("request:%p found service config: %s", r, - *r->service_config_json_out); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << r + << " found service config: " << *r->service_config_json_out; } // Clean up. ares_free_data(reply); @@ -822,18 +854,19 @@ static void on_txt_done_locked(void* arg, int status, int /*timeouts*/, std::string error_msg = absl::StrFormat("C-ares status is not ARES_SUCCESS qtype=TXT name=%s: %s", q->name(), ares_strerror(status)); - GRPC_CARES_TRACE_LOG("request:%p on_txt_done_locked %s", r, - error_msg.c_str()); - error = GRPC_ERROR_CREATE(error_msg); - r->error = grpc_error_add_child(error, r->error); + GRPC_TRACE_VLOG(cares_resolver, 2) << "(c-ares resolver) request:" << r + << " on_txt_done_locked " << error_msg; + r->error = + grpc_error_add_child(AresStatusToAbslStatus(status, error_msg), r->error); } grpc_error_handle set_request_dns_server(grpc_ares_request* r, absl::string_view dns_server) ABSL_EXCLUSIVE_LOCKS_REQUIRED(r->mu) { if (!dns_server.empty()) { - GRPC_CARES_TRACE_LOG("request:%p Using DNS server %s", r, - dns_server.data()); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << r << " Using DNS server " + << dns_server.data(); grpc_resolved_address addr; if (grpc_parse_ipv4_hostport(dns_server, &addr, /*log_errors=*/false)) { r->dns_server_addr.family = AF_INET; @@ -1028,10 +1061,10 @@ static grpc_ares_request* grpc_dns_lookup_hostname_ares_impl( r->ev_driver = nullptr; r->on_done = on_done; r->addresses_out = addrs; - GRPC_CARES_TRACE_LOG( - "request:%p c-ares grpc_dns_lookup_hostname_ares_impl name=%s, " - "default_port=%s", - r, name, default_port); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << r + << " c-ares grpc_dns_lookup_hostname_ares_impl name=" << name + << ", default_port=" << default_port; // Early out if the target is an ipv4 or ipv6 literal. if (resolve_as_ip_literal_locked(name, default_port, addrs)) { grpc_ares_complete_request_locked(r); @@ -1082,8 +1115,9 @@ grpc_ares_request* grpc_dns_lookup_srv_ares_impl( r->ev_driver = nullptr; r->on_done = on_done; r->balancer_addresses_out = balancer_addresses; - GRPC_CARES_TRACE_LOG( - "request:%p c-ares grpc_dns_lookup_srv_ares_impl name=%s", r, name); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << r + << " c-ares grpc_dns_lookup_srv_ares_impl name=" << name; grpc_error_handle error; // Don't query for SRV records if the target is "localhost" if (target_matches_localhost(name)) { @@ -1120,8 +1154,9 @@ grpc_ares_request* grpc_dns_lookup_txt_ares_impl( r->ev_driver = nullptr; r->on_done = on_done; r->service_config_json_out = service_config_json; - GRPC_CARES_TRACE_LOG( - "request:%p c-ares grpc_dns_lookup_txt_ares_impl name=%s", r, name); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << r + << " c-ares grpc_dns_lookup_txt_ares_impl name=" << name; grpc_error_handle error; // Don't query for TXT records if the target is "localhost" if (target_matches_localhost(name)) { @@ -1170,8 +1205,9 @@ grpc_ares_request* (*grpc_dns_lookup_txt_ares)( static void grpc_cancel_ares_request_impl(grpc_ares_request* r) { CHECK_NE(r, nullptr); grpc_core::MutexLock lock(&r->mu); - GRPC_CARES_TRACE_LOG("request:%p grpc_cancel_ares_request ev_driver:%p", r, - r->ev_driver); + GRPC_TRACE_VLOG(cares_resolver, 2) + << "(c-ares resolver) request:" << r + << " grpc_cancel_ares_request ev_driver:" << r->ev_driver; if (r->ev_driver != nullptr) { grpc_ares_ev_driver_shutdown_locked(r->ev_driver); } diff --git a/src/core/resolver/dns/c_ares/grpc_ares_wrapper.h b/src/core/resolver/dns/c_ares/grpc_ares_wrapper.h index 9fdb94c0da..bd4fbe2720 100644 --- a/src/core/resolver/dns/c_ares/grpc_ares_wrapper.h +++ b/src/core/resolver/dns/c_ares/grpc_ares_wrapper.h @@ -39,13 +39,6 @@ #define GRPC_DNS_ARES_DEFAULT_QUERY_TIMEOUT_MS 120000 -#define GRPC_CARES_TRACE_LOG(format, ...) \ - do { \ - if (GRPC_TRACE_FLAG_ENABLED(cares_resolver)) { \ - VLOG(2) << "(c-ares resolver) " << absl::StrFormat(format, __VA_ARGS__); \ - } \ - } while (0) - typedef struct grpc_ares_ev_driver grpc_ares_ev_driver; struct grpc_ares_request { diff --git a/src/core/resolver/dns/dns_resolver_plugin.cc b/src/core/resolver/dns/dns_resolver_plugin.cc index 9abce007fd..0a3c78488e 100644 --- a/src/core/resolver/dns/dns_resolver_plugin.cc +++ b/src/core/resolver/dns/dns_resolver_plugin.cc @@ -18,7 +18,6 @@ #include "absl/log/log.h" #include "absl/strings/match.h" -#include #include #include "src/core/lib/config/config_vars.h" 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 44ad399585..3efb937523 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 @@ -77,12 +77,6 @@ using grpc_event_engine::experimental::EventEngine; // TODO(hork): Add a test that checks for proper authority from balancer // addresses. -#define GRPC_EVENT_ENGINE_RESOLVER_TRACE(format, ...) \ - if (GRPC_TRACE_FLAG_ENABLED(event_engine_client_channel_resolver)) { \ - VLOG(2) << "(event_engine client channel resolver) " \ - << absl::StrFormat(format, __VA_ARGS__); \ - } - // ---------------------------------------------------------------------------- // EventEngineClientChannelDNSResolver // ---------------------------------------------------------------------------- @@ -221,9 +215,10 @@ EventEngineClientChannelDNSResolver::EventEngineDNSRequestWrapper:: event_engine_resolver_(std::move(event_engine_resolver)) { // Locking to prevent completion before all records are queried MutexLock lock(&on_resolved_mu_); - GRPC_EVENT_ENGINE_RESOLVER_TRACE( - "DNSResolver::%p Starting hostname resolution for %s", resolver_.get(), - resolver_->name_to_resolve().c_str()); + GRPC_TRACE_VLOG(event_engine_client_channel_resolver, 2) + << "(event_engine client channel resolver) DNSResolver::" + << resolver_.get() << " Starting hostname resolution for " + << resolver_->name_to_resolve(); is_hostname_inflight_ = true; event_engine_resolver_->LookupHostname( [self = Ref(DEBUG_LOCATION, "OnHostnameResolved")]( @@ -236,9 +231,10 @@ EventEngineClientChannelDNSResolver::EventEngineDNSRequestWrapper:: }, resolver_->name_to_resolve(), kDefaultSecurePort); if (resolver_->enable_srv_queries_) { - GRPC_EVENT_ENGINE_RESOLVER_TRACE( - "DNSResolver::%p Starting SRV record resolution for %s", - resolver_.get(), resolver_->name_to_resolve().c_str()); + GRPC_TRACE_VLOG(event_engine_client_channel_resolver, 2) + << "(event_engine client channel resolver) DNSResolver::" + << resolver_.get() << " Starting SRV record resolution for " + << resolver_->name_to_resolve(); is_srv_inflight_ = true; event_engine_resolver_->LookupSRV( [self = Ref(DEBUG_LOCATION, "OnSRVResolved")]( @@ -252,9 +248,10 @@ EventEngineClientChannelDNSResolver::EventEngineDNSRequestWrapper:: absl::StrCat("_grpclb._tcp.", resolver_->name_to_resolve())); } if (resolver_->request_service_config_) { - GRPC_EVENT_ENGINE_RESOLVER_TRACE( - "DNSResolver::%p Starting TXT record resolution for %s", - resolver_.get(), resolver_->name_to_resolve().c_str()); + GRPC_TRACE_VLOG(event_engine_client_channel_resolver, 2) + << "(event_engine client channel resolver) DNSResolver::" + << resolver_.get() << " Starting TXT record resolution for " + << resolver_->name_to_resolve(); is_txt_inflight_ = true; event_engine_resolver_->LookupTXT( [self = Ref(DEBUG_LOCATION, "OnTXTResolved")]( @@ -303,8 +300,9 @@ void EventEngineClientChannelDNSResolver::EventEngineDNSRequestWrapper:: void EventEngineClientChannelDNSResolver::EventEngineDNSRequestWrapper:: OnTimeout() { MutexLock lock(&on_resolved_mu_); - GRPC_EVENT_ENGINE_RESOLVER_TRACE("DNSResolver::%p OnTimeout", - resolver_.get()); + GRPC_TRACE_VLOG(event_engine_client_channel_resolver, 2) + << "(event_engine client channel resolver) DNSResolver::" + << resolver_.get() << " OnTimeout"; timeout_handle_.reset(); event_engine_resolver_.reset(); } @@ -368,9 +366,10 @@ void EventEngineClientChannelDNSResolver::EventEngineDNSRequestWrapper:: } // Do a subsequent hostname query since SRV records were returned for (auto& srv_record : *srv_records) { - GRPC_EVENT_ENGINE_RESOLVER_TRACE( - "DNSResolver::%p Starting balancer hostname resolution for %s:%d", - resolver_.get(), srv_record.host.c_str(), srv_record.port); + GRPC_TRACE_VLOG(event_engine_client_channel_resolver, 2) + << "(event_engine client channel resolver) DNSResolver::" + << resolver_.get() << " Starting balancer hostname resolution for " + << srv_record.host << ":" << srv_record.port; ++number_of_balancer_hostnames_initiated_; event_engine_resolver_->LookupHostname( [host = srv_record.host, @@ -446,9 +445,10 @@ void EventEngineClientChannelDNSResolver::EventEngineDNSRequestWrapper:: // Found a service config record. service_config_json_ = result->substr(kServiceConfigAttributePrefix.size()); - GRPC_EVENT_ENGINE_RESOLVER_TRACE( - "DNSResolver::%p found service config: %s", - event_engine_resolver_.get(), service_config_json_->c_str()); + GRPC_TRACE_VLOG(event_engine_client_channel_resolver, 2) + << "(event_engine client channel resolver) DNSResolver::" + << event_engine_resolver_.get() + << " found service config: " << service_config_json_->c_str(); } else { service_config_json_ = absl::UnavailableError(absl::StrCat( "failed to find attribute prefix: ", kServiceConfigAttributePrefix, @@ -492,9 +492,10 @@ void EventEngineClientChannelDNSResolver::EventEngineDNSRequestWrapper:: return; } if (service_config->empty()) return; - GRPC_EVENT_ENGINE_RESOLVER_TRACE( - "DNSResolver::%p selected service config choice: %s", - event_engine_resolver_.get(), service_config->c_str()); + GRPC_TRACE_VLOG(event_engine_client_channel_resolver, 2) + << "(event_engine client channel resolver) DNSResolver::" + << event_engine_resolver_.get() + << " selected service config choice: " << service_config->c_str(); result->service_config = ServiceConfigImpl::Create(resolver_->channel_args(), *service_config); if (!result->service_config.ok()) { @@ -511,20 +512,19 @@ absl::optional EventEngineClientChannelDNSResolver:: if (is_hostname_inflight_ || is_srv_inflight_ || is_txt_inflight_ || number_of_balancer_hostnames_resolved_ != number_of_balancer_hostnames_initiated_) { - GRPC_EVENT_ENGINE_RESOLVER_TRACE( - "DNSResolver::%p OnResolved() waiting for results (hostname: %s, " - "srv: %s, " - "txt: %s, " - "balancer addresses: %" PRIuPTR "/%" PRIuPTR " complete", - this, is_hostname_inflight_ ? "waiting" : "done", - is_srv_inflight_ ? "waiting" : "done", - is_txt_inflight_ ? "waiting" : "done", - number_of_balancer_hostnames_resolved_, - number_of_balancer_hostnames_initiated_); + GRPC_TRACE_VLOG(event_engine_client_channel_resolver, 2) + << "(event_engine client channel resolver) DNSResolver::" << this + << " OnResolved() waiting for results (hostname: " + << (is_hostname_inflight_ ? "waiting" : "done") + << ", srv: " << (is_srv_inflight_ ? "waiting" : "done") + << ", txt: " << (is_txt_inflight_ ? "waiting" : "done") + << ", balancer addresses: " << number_of_balancer_hostnames_resolved_ + << "/" << number_of_balancer_hostnames_initiated_ << " complete"; return absl::nullopt; } - GRPC_EVENT_ENGINE_RESOLVER_TRACE( - "DNSResolver::%p OnResolvedLocked() proceeding", this); + GRPC_TRACE_VLOG(event_engine_client_channel_resolver, 2) + << "(event_engine client channel resolver) DNSResolver::" << this + << " OnResolvedLocked() proceeding"; Resolver::Result result; result.args = resolver_->channel_args(); // If both addresses and balancer addresses failed, return an error for both @@ -538,7 +538,8 @@ absl::optional EventEngineClientChannelDNSResolver:: // return an error. Validation errors may be empty. status = absl::UnavailableError("No results from DNS queries"); } - GRPC_EVENT_ENGINE_RESOLVER_TRACE("%s", status.message().data()); + GRPC_TRACE_VLOG(event_engine_client_channel_resolver, 2) + << "(event_engine client channel resolver) " << status.message().data(); result.addresses = status; result.service_config = status; return std::move(result); diff --git a/src/core/resolver/dns/native/dns_resolver.cc b/src/core/resolver/dns/native/dns_resolver.cc index 0fb59889d0..1a3ca55f9b 100644 --- a/src/core/resolver/dns/native/dns_resolver.cc +++ b/src/core/resolver/dns/native/dns_resolver.cc @@ -90,15 +90,11 @@ NativeClientChannelDNSResolver::NativeClientChannelDNSResolver( .set_max_backoff(Duration::Milliseconds( GRPC_DNS_RECONNECT_MAX_BACKOFF_SECONDS * 1000)), &dns_resolver_trace) { - if (GRPC_TRACE_FLAG_ENABLED(dns_resolver)) { - VLOG(2) << "[dns_resolver=" << this << "] created"; - } + GRPC_TRACE_VLOG(dns_resolver, 2) << "[dns_resolver=" << this << "] created"; } NativeClientChannelDNSResolver::~NativeClientChannelDNSResolver() { - if (GRPC_TRACE_FLAG_ENABLED(dns_resolver)) { - VLOG(2) << "[dns_resolver=" << this << "] destroyed"; - } + GRPC_TRACE_VLOG(dns_resolver, 2) << "[dns_resolver=" << this << "] destroyed"; } OrphanablePtr NativeClientChannelDNSResolver::StartRequest() { @@ -107,19 +103,17 @@ OrphanablePtr NativeClientChannelDNSResolver::StartRequest() { absl::bind_front(&NativeClientChannelDNSResolver::OnResolved, this), name_to_resolve(), kDefaultSecurePort, kDefaultDNSRequestTimeout, interested_parties(), /*name_server=*/""); - if (GRPC_TRACE_FLAG_ENABLED(dns_resolver)) { - VLOG(2) << "[dns_resolver=" << this << "] starting request=" - << DNSResolver::HandleToString(dns_request_handle); - } + GRPC_TRACE_VLOG(dns_resolver, 2) + << "[dns_resolver=" << this << "] starting request=" + << DNSResolver::HandleToString(dns_request_handle); return MakeOrphanable(); } void NativeClientChannelDNSResolver::OnResolved( absl::StatusOr> addresses_or) { - if (GRPC_TRACE_FLAG_ENABLED(dns_resolver)) { - VLOG(2) << "[dns_resolver=" << this - << "] request complete, status=" << addresses_or.status(); - } + GRPC_TRACE_VLOG(dns_resolver, 2) + << "[dns_resolver=" << this + << "] request complete, status=" << addresses_or.status(); // Convert result from iomgr DNS API into Resolver::Result. Result result; if (addresses_or.ok()) { diff --git a/src/core/resolver/endpoint_addresses.cc b/src/core/resolver/endpoint_addresses.cc index 19fbfdfbc1..7fc7d8d333 100644 --- a/src/core/resolver/endpoint_addresses.cc +++ b/src/core/resolver/endpoint_addresses.cc @@ -30,7 +30,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" -#include #include #include "src/core/lib/address_utils/sockaddr_utils.h" diff --git a/src/core/resolver/fake/fake_resolver.cc b/src/core/resolver/fake/fake_resolver.cc index 99703f8a6e..b1659f84bf 100644 --- a/src/core/resolver/fake/fake_resolver.cc +++ b/src/core/resolver/fake/fake_resolver.cc @@ -26,7 +26,6 @@ #include "absl/log/check.h" #include "absl/strings/string_view.h" -#include #include #include "src/core/lib/channel/channel_args.h" diff --git a/src/core/resolver/xds/xds_config.cc b/src/core/resolver/xds/xds_config.cc new file mode 100644 index 0000000000..1fcb2aa81c --- /dev/null +++ b/src/core/resolver/xds/xds_config.cc @@ -0,0 +1,96 @@ +// +// Copyright 2019 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/resolver/xds/xds_config.h" + +#include +#include +#include +#include + +#include "absl/strings/str_cat.h" +#include "absl/strings/str_join.h" + +#include "src/core/lib/gprpp/match.h" + +namespace grpc_core { + +// +// XdsConfig::ClusterConfig +// + +XdsConfig::ClusterConfig::ClusterConfig( + std::shared_ptr cluster, + std::shared_ptr endpoints, + std::string resolution_note) + : cluster(std::move(cluster)), + children(absl::in_place_type_t(), std::move(endpoints), + std::move(resolution_note)) {} + +XdsConfig::ClusterConfig::ClusterConfig( + std::shared_ptr cluster, + std::vector leaf_clusters) + : cluster(std::move(cluster)), + children(absl::in_place_type_t(), + std::move(leaf_clusters)) {} + +// +// XdsConfig +// + +std::string XdsConfig::ToString() const { + std::vector parts = { + "{\n listener: {", listener->ToString(), + "}\n route_config: {", route_config->ToString(), + "}\n virtual_host: {", virtual_host->ToString(), + "}\n clusters: {\n"}; + for (const auto& p : clusters) { + parts.push_back(absl::StrCat(" \"", p.first, "\": ")); + if (!p.second.ok()) { + parts.push_back(p.second.status().ToString()); + parts.push_back("\n"); + } else { + parts.push_back( + absl::StrCat(" {\n" + " cluster: {", + p.second->cluster->ToString(), "}\n")); + Match( + p.second->children, + [&](const ClusterConfig::EndpointConfig& endpoint_config) { + parts.push_back( + absl::StrCat(" endpoints: {", + endpoint_config.endpoints == nullptr + ? "" + : endpoint_config.endpoints->ToString(), + "}\n" + " resolution_note: \"", + endpoint_config.resolution_note, "\"\n")); + }, + [&](const ClusterConfig::AggregateConfig& aggregate_config) { + parts.push_back(absl::StrCat( + " leaf_clusters: [", + absl::StrJoin(aggregate_config.leaf_clusters, ", "), "]\n")); + }); + parts.push_back( + " }\n" + " ]\n"); + } + } + parts.push_back(" }\n}"); + return absl::StrJoin(parts, ""); +} + +} // namespace grpc_core diff --git a/src/core/resolver/xds/xds_config.h b/src/core/resolver/xds/xds_config.h new file mode 100644 index 0000000000..9c328a2057 --- /dev/null +++ b/src/core/resolver/xds/xds_config.h @@ -0,0 +1,109 @@ +// +// Copyright 2019 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_RESOLVER_XDS_XDS_CONFIG_H +#define GRPC_SRC_CORE_RESOLVER_XDS_XDS_CONFIG_H + +#include +#include +#include +#include + +#include "absl/container/flat_hash_map.h" +#include "absl/status/statusor.h" +#include "absl/strings/string_view.h" +#include "absl/types/variant.h" + +#include "src/core/lib/gprpp/ref_counted.h" +#include "src/core/xds/grpc/xds_cluster.h" +#include "src/core/xds/grpc/xds_endpoint.h" +#include "src/core/xds/grpc/xds_listener.h" +#include "src/core/xds/grpc/xds_route_config.h" + +namespace grpc_core { + +// A complete gRPC client-side xDS config containing all necessary +// resources. +struct XdsConfig : public RefCounted { + // Listener resource. Always non-null. + std::shared_ptr listener; + // RouteConfig resource. Will be populated even if RouteConfig is + // inlined into the Listener resource. + std::shared_ptr route_config; + // Virtual host. Points into route_config. Will always be non-null. + const XdsRouteConfigResource::VirtualHost* virtual_host; + + struct ClusterConfig { + // Cluster resource. Always non-null. + std::shared_ptr cluster; + // Endpoint info for EDS and LOGICAL_DNS clusters. If there was an + // error, endpoints will be null and resolution_note will be set. + struct EndpointConfig { + std::shared_ptr endpoints; + std::string resolution_note; + + EndpointConfig(std::shared_ptr endpoints, + std::string resolution_note) + : endpoints(std::move(endpoints)), + resolution_note(std::move(resolution_note)) {} + bool operator==(const EndpointConfig& other) const { + return endpoints == other.endpoints && + resolution_note == other.resolution_note; + } + }; + // The list of leaf clusters for an aggregate cluster. + struct AggregateConfig { + std::vector leaf_clusters; + + explicit AggregateConfig(std::vector leaf_clusters) + : leaf_clusters(std::move(leaf_clusters)) {} + bool operator==(const AggregateConfig& other) const { + return leaf_clusters == other.leaf_clusters; + } + }; + absl::variant children; + + // Ctor for leaf clusters. + ClusterConfig(std::shared_ptr cluster, + std::shared_ptr endpoints, + std::string resolution_note); + // Ctor for aggregate clusters. + ClusterConfig(std::shared_ptr cluster, + std::vector leaf_clusters); + + bool operator==(const ClusterConfig& other) const { + return cluster == other.cluster && children == other.children; + } + }; + // Cluster map. A cluster will have a non-OK status if either + // (a) there was an error and we did not already have a valid + // resource or (b) the resource does not exist. + absl::flat_hash_map> clusters; + + std::string ToString() const; + + static absl::string_view ChannelArgName() { + return GRPC_ARG_NO_SUBCHANNEL_PREFIX "xds_config"; + } + static int ChannelArgsCompare(const XdsConfig* a, const XdsConfig* b) { + return QsortCompare(a, b); + } + static constexpr bool ChannelArgUseConstPtr() { return true; } +}; + +} // namespace grpc_core + +#endif // GRPC_SRC_CORE_RESOLVER_XDS_XDS_CONFIG_H diff --git a/src/core/resolver/xds/xds_dependency_manager.cc b/src/core/resolver/xds/xds_dependency_manager.cc index 2ae913308b..293586f40f 100644 --- a/src/core/resolver/xds/xds_dependency_manager.cc +++ b/src/core/resolver/xds/xds_dependency_manager.cc @@ -43,71 +43,6 @@ constexpr int kMaxXdsAggregateClusterRecursionDepth = 16; } // namespace -// -// XdsDependencyManager::XdsConfig::ClusterConfig -// - -XdsDependencyManager::XdsConfig::ClusterConfig::ClusterConfig( - std::shared_ptr cluster, - std::shared_ptr endpoints, - std::string resolution_note) - : cluster(std::move(cluster)), - children(absl::in_place_type_t(), std::move(endpoints), - std::move(resolution_note)) {} - -XdsDependencyManager::XdsConfig::ClusterConfig::ClusterConfig( - std::shared_ptr cluster, - std::vector leaf_clusters) - : cluster(std::move(cluster)), - children(absl::in_place_type_t(), - std::move(leaf_clusters)) {} - -// -// XdsDependencyManager::XdsConfig -// - -std::string XdsDependencyManager::XdsConfig::ToString() const { - std::vector parts = { - "{\n listener: {", listener->ToString(), - "}\n route_config: {", route_config->ToString(), - "}\n virtual_host: {", virtual_host->ToString(), - "}\n clusters: {\n"}; - for (const auto& p : clusters) { - parts.push_back(absl::StrCat(" \"", p.first, "\": ")); - if (!p.second.ok()) { - parts.push_back(p.second.status().ToString()); - parts.push_back("\n"); - } else { - parts.push_back( - absl::StrCat(" {\n" - " cluster: {", - p.second->cluster->ToString(), "}\n")); - Match( - p.second->children, - [&](const ClusterConfig::EndpointConfig& endpoint_config) { - parts.push_back( - absl::StrCat(" endpoints: {", - endpoint_config.endpoints == nullptr - ? "" - : endpoint_config.endpoints->ToString(), - "}\n" - " resolution_note: \"", - endpoint_config.resolution_note, "\"\n")); - }, - [&](const ClusterConfig::AggregateConfig& aggregate_config) { - parts.push_back(absl::StrCat( - " leaf_clusters: [", - absl::StrJoin(aggregate_config.leaf_clusters, ", "), "]\n")); - }); - parts.push_back( - " }\n" - " ]\n"); - } - } - parts.push_back(" }\n}"); - return absl::StrJoin(parts, ""); -} - // // XdsDependencyManager::ListenerWatcher // @@ -364,10 +299,9 @@ XdsDependencyManager::XdsDependencyManager( listener_resource_name_(std::move(listener_resource_name)), args_(std::move(args)), interested_parties_(interested_parties) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] starting watch for listener " << listener_resource_name_; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this << "] starting watch for listener " + << listener_resource_name_; auto listener_watcher = MakeRefCounted(Ref()); listener_watcher_ = listener_watcher.get(); XdsListenerResourceType::StartWatch( @@ -375,9 +309,8 @@ XdsDependencyManager::XdsDependencyManager( } void XdsDependencyManager::Orphan() { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this << "] shutting down"; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this << "] shutting down"; if (listener_watcher_ != nullptr) { XdsListenerResourceType::CancelWatch( xds_client_.get(), listener_resource_name_, listener_watcher_, @@ -420,10 +353,8 @@ void XdsDependencyManager::ResetBackoff() { void XdsDependencyManager::OnListenerUpdate( std::shared_ptr listener) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] received Listener update"; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this << "] received Listener update"; if (xds_client_ == nullptr) return; const auto* hcm = absl::get_if( &listener->listener); @@ -453,11 +384,9 @@ void XdsDependencyManager::OnListenerUpdate( } // Start watch for the new RDS resource name. route_config_name_ = rds_name; - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] starting watch for route config " - << route_config_name_; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this + << "] starting watch for route config " << route_config_name_; auto watcher = MakeRefCounted(Ref(), route_config_name_); route_config_watcher_ = watcher.get(); @@ -540,11 +469,9 @@ absl::flat_hash_set GetClustersFromVirtualHost( void XdsDependencyManager::OnRouteConfigUpdate( const std::string& name, std::shared_ptr route_config) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] received RouteConfig update for " - << (name.empty() ? "" : name); - } + GRPC_TRACE_LOG(xds_resolver, INFO) << "[XdsDependencyManager " << this + << "] received RouteConfig update for " + << (name.empty() ? "" : name); if (xds_client_ == nullptr) return; // Ignore updates for stale names. if (name.empty()) { @@ -575,20 +502,18 @@ void XdsDependencyManager::OnRouteConfigUpdate( } void XdsDependencyManager::OnError(std::string context, absl::Status status) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] received Listener or RouteConfig error: " << context << " " - << status; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this + << "] received Listener or RouteConfig error: " << context << " " + << status; if (xds_client_ == nullptr) return; if (current_virtual_host_ != nullptr) return; watcher_->OnError(context, std::move(status)); } void XdsDependencyManager::OnResourceDoesNotExist(std::string context) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this << "] " << context; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this << "] " << context; if (xds_client_ == nullptr) return; current_virtual_host_ = nullptr; watcher_->OnResourceDoesNotExist(std::move(context)); @@ -597,10 +522,8 @@ void XdsDependencyManager::OnResourceDoesNotExist(std::string context) { void XdsDependencyManager::OnClusterUpdate( const std::string& name, std::shared_ptr cluster) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] received Cluster update: " << name; - } + GRPC_TRACE_LOG(xds_resolver, INFO) << "[XdsDependencyManager " << this + << "] received Cluster update: " << name; if (xds_client_ == nullptr) return; auto it = cluster_watchers_.find(name); if (it == cluster_watchers_.end()) return; @@ -610,10 +533,9 @@ void XdsDependencyManager::OnClusterUpdate( void XdsDependencyManager::OnClusterError(const std::string& name, absl::Status status) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] received Cluster error: " << name << " " << status; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this + << "] received Cluster error: " << name << " " << status; if (xds_client_ == nullptr) return; auto it = cluster_watchers_.find(name); if (it == cluster_watchers_.end()) return; @@ -625,10 +547,8 @@ void XdsDependencyManager::OnClusterError(const std::string& name, } void XdsDependencyManager::OnClusterDoesNotExist(const std::string& name) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] Cluster does not exist: " << name; - } + GRPC_TRACE_LOG(xds_resolver, INFO) << "[XdsDependencyManager " << this + << "] Cluster does not exist: " << name; if (xds_client_ == nullptr) return; auto it = cluster_watchers_.find(name); if (it == cluster_watchers_.end()) return; @@ -640,10 +560,8 @@ void XdsDependencyManager::OnClusterDoesNotExist(const std::string& name) { void XdsDependencyManager::OnEndpointUpdate( const std::string& name, std::shared_ptr endpoint) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] received Endpoint update: " << name; - } + GRPC_TRACE_LOG(xds_resolver, INFO) << "[XdsDependencyManager " << this + << "] received Endpoint update: " << name; if (xds_client_ == nullptr) return; auto it = endpoint_watchers_.find(name); if (it == endpoint_watchers_.end()) return; @@ -672,10 +590,9 @@ void XdsDependencyManager::OnEndpointUpdate( void XdsDependencyManager::OnEndpointError(const std::string& name, absl::Status status) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] received Endpoint error: " << name << " " << status; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this + << "] received Endpoint error: " << name << " " << status; if (xds_client_ == nullptr) return; auto it = endpoint_watchers_.find(name); if (it == endpoint_watchers_.end()) return; @@ -687,10 +604,8 @@ void XdsDependencyManager::OnEndpointError(const std::string& name, } void XdsDependencyManager::OnEndpointDoesNotExist(const std::string& name) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] Endpoint does not exist: " << name; - } + GRPC_TRACE_LOG(xds_resolver, INFO) << "[XdsDependencyManager " << this + << "] Endpoint does not exist: " << name; if (xds_client_ == nullptr) return; auto it = endpoint_watchers_.find(name); if (it == endpoint_watchers_.end()) return; @@ -702,10 +617,8 @@ void XdsDependencyManager::OnEndpointDoesNotExist(const std::string& name) { void XdsDependencyManager::OnDnsResult(const std::string& dns_name, Resolver::Result result) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] received DNS update: " << dns_name; - } + GRPC_TRACE_LOG(xds_resolver, INFO) << "[XdsDependencyManager " << this + << "] received DNS update: " << dns_name; if (xds_client_ == nullptr) return; auto it = dns_resolvers_.find(dns_name); if (it == dns_resolvers_.end()) return; @@ -765,10 +678,9 @@ bool XdsDependencyManager::PopulateClusterConfigMap( // Create a new watcher if needed. if (state.watcher == nullptr) { auto watcher = MakeRefCounted(Ref(), name); - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] starting watch for cluster " << name; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this << "] starting watch for cluster " + << name; state.watcher = watcher.get(); XdsClusterResourceType::StartWatch(xds_client_.get(), name, std::move(watcher)); @@ -792,10 +704,9 @@ bool XdsDependencyManager::PopulateClusterConfigMap( // Start EDS watch if needed. auto& eds_state = endpoint_watchers_[eds_resource_name]; if (eds_state.watcher == nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] starting watch for endpoint " << eds_resource_name; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this + << "] starting watch for endpoint " << eds_resource_name; auto watcher = MakeRefCounted(Ref(), eds_resource_name); eds_state.watcher = watcher.get(); @@ -820,10 +731,9 @@ bool XdsDependencyManager::PopulateClusterConfigMap( // Start DNS resolver if needed. auto& dns_state = dns_resolvers_[logical_dns.hostname]; if (dns_state.resolver == nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] starting DNS resolver for " << logical_dns.hostname; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this + << "] starting DNS resolver for " << logical_dns.hostname; auto* fake_resolver_response_generator = args_.GetPointer< FakeResolverResponseGenerator>( GRPC_ARG_XDS_LOGICAL_DNS_CLUSTER_FAKE_RESOLVER_RESPONSE_GENERATOR); @@ -987,10 +897,9 @@ void XdsDependencyManager::MaybeReportUpdate() { ++it; continue; } - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] cancelling watch for cluster " << cluster_name; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this << "] cancelling watch for cluster " + << cluster_name; XdsClusterResourceType::CancelWatch(xds_client_.get(), cluster_name, it->second.watcher, /*delay_unsubscription=*/false); @@ -1005,10 +914,9 @@ void XdsDependencyManager::MaybeReportUpdate() { ++it; continue; } - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] cancelling watch for EDS resource " << eds_resource_name; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this + << "] cancelling watch for EDS resource " << eds_resource_name; XdsEndpointResourceType::CancelWatch(xds_client_.get(), eds_resource_name, it->second.watcher, /*delay_unsubscription=*/false); @@ -1022,24 +930,21 @@ void XdsDependencyManager::MaybeReportUpdate() { ++it; continue; } - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] shutting down DNS resolver for " << dns_name; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this + << "] shutting down DNS resolver for " << dns_name; dns_resolvers_.erase(it++); } // If we have all the data we need, then send an update. if (!have_all_resources) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] missing data -- NOT returning config"; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this + << "] missing data -- NOT returning config"; return; } - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[XdsDependencyManager " << this - << "] returning config: " << config->ToString(); - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[XdsDependencyManager " << this + << "] returning config: " << config->ToString(); watcher_->OnUpdate(std::move(config)); } diff --git a/src/core/resolver/xds/xds_dependency_manager.h b/src/core/resolver/xds/xds_dependency_manager.h index 959ee7f2a7..b2b62ddf22 100644 --- a/src/core/resolver/xds/xds_dependency_manager.h +++ b/src/core/resolver/xds/xds_dependency_manager.h @@ -21,10 +21,9 @@ #include "absl/container/flat_hash_set.h" #include "absl/strings/string_view.h" -#include - #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/resolver/resolver.h" +#include "src/core/resolver/xds/xds_config.h" #include "src/core/xds/grpc/xds_client_grpc.h" #include "src/core/xds/grpc/xds_cluster.h" #include "src/core/xds/grpc/xds_endpoint.h" @@ -38,73 +37,6 @@ namespace grpc_core { class XdsDependencyManager final : public RefCounted, public Orphanable { public: - struct XdsConfig : public RefCounted { - // Listener resource. Always non-null. - std::shared_ptr listener; - // RouteConfig resource. Will be populated even if RouteConfig is - // inlined into the Listener resource. - std::shared_ptr route_config; - // Virtual host. Points into route_config. Will always be non-null. - const XdsRouteConfigResource::VirtualHost* virtual_host; - - struct ClusterConfig { - // Cluster resource. Always non-null. - std::shared_ptr cluster; - // Endpoint info for EDS and LOGICAL_DNS clusters. If there was an - // error, endpoints will be null and resolution_note will be set. - struct EndpointConfig { - std::shared_ptr endpoints; - std::string resolution_note; - - EndpointConfig(std::shared_ptr endpoints, - std::string resolution_note) - : endpoints(std::move(endpoints)), - resolution_note(std::move(resolution_note)) {} - bool operator==(const EndpointConfig& other) const { - return endpoints == other.endpoints && - resolution_note == other.resolution_note; - } - }; - // The list of leaf clusters for an aggregate cluster. - struct AggregateConfig { - std::vector leaf_clusters; - - explicit AggregateConfig(std::vector leaf_clusters) - : leaf_clusters(std::move(leaf_clusters)) {} - bool operator==(const AggregateConfig& other) const { - return leaf_clusters == other.leaf_clusters; - } - }; - absl::variant children; - - // Ctor for leaf clusters. - ClusterConfig(std::shared_ptr cluster, - std::shared_ptr endpoints, - std::string resolution_note); - // Ctor for aggregate clusters. - ClusterConfig(std::shared_ptr cluster, - std::vector leaf_clusters); - - bool operator==(const ClusterConfig& other) const { - return cluster == other.cluster && children == other.children; - } - }; - // Cluster map. A cluster will have a non-OK status if either - // (a) there was an error and we did not already have a valid - // resource or (b) the resource does not exist. - absl::flat_hash_map> clusters; - - std::string ToString() const; - - static absl::string_view ChannelArgName() { - return GRPC_ARG_NO_SUBCHANNEL_PREFIX "xds_config"; - } - static int ChannelArgsCompare(const XdsConfig* a, const XdsConfig* b) { - return QsortCompare(a, b); - } - static constexpr bool ChannelArgUseConstPtr() { return true; } - }; - class Watcher { public: virtual ~Watcher() = default; diff --git a/src/core/resolver/xds/xds_resolver.cc b/src/core/resolver/xds/xds_resolver.cc index ef42070cac..9cb4909853 100644 --- a/src/core/resolver/xds/xds_resolver.cc +++ b/src/core/resolver/xds/xds_resolver.cc @@ -110,17 +110,14 @@ class XdsResolver final : public Resolver { uri_(std::move(args.uri)), data_plane_authority_(std::move(data_plane_authority)), channel_id_(absl::Uniform(absl::BitGen())) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[xds_resolver " << this << "] created for URI " - << uri_.ToString() << "; data plane authority is " - << data_plane_authority_; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[xds_resolver " << this << "] created for URI " << uri_.ToString() + << "; data plane authority is " << data_plane_authority_; } ~XdsResolver() override { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[xds_resolver " << this << "] destroyed"; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[xds_resolver " << this << "] destroyed"; } void StartLocked() override; @@ -142,8 +139,7 @@ class XdsResolver final : public Resolver { explicit XdsWatcher(RefCountedPtr resolver) : resolver_(std::move(resolver)) {} - void OnUpdate( - RefCountedPtr config) override { + void OnUpdate(RefCountedPtr config) override { resolver_->OnUpdate(std::move(config)); } @@ -366,7 +362,7 @@ class XdsResolver final : public Resolver { return it->second->Ref(); } - void OnUpdate(RefCountedPtr config); + void OnUpdate(RefCountedPtr config); void OnError(absl::string_view context, absl::Status status); void OnResourceDoesNotExist(std::string context); @@ -385,7 +381,7 @@ class XdsResolver final : public Resolver { const uint64_t channel_id_; OrphanablePtr dependency_mgr_; - RefCountedPtr current_config_; + RefCountedPtr current_config_; std::map> cluster_ref_map_; }; @@ -545,10 +541,9 @@ XdsResolver::RouteConfigData::CreateMethodConfig( absl::Status XdsResolver::RouteConfigData::AddRouteEntry( XdsResolver* resolver, const XdsRouteConfigResource::Route& route, const Duration& default_max_stream_duration) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[xds_resolver " << resolver << "] XdsConfigSelector " << this - << ": route: " << route.ToString(); - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[xds_resolver " << resolver << "] XdsConfigSelector " << this + << ": route: " << route.ToString(); routes_.emplace_back(route); auto* route_entry = &routes_.back(); auto maybe_add_cluster = [&](absl::string_view cluster_key, @@ -637,10 +632,8 @@ XdsResolver::XdsConfigSelector::XdsConfigSelector( RefCountedPtr route_config_data) : resolver_(std::move(resolver)), route_config_data_(std::move(route_config_data)) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[xds_resolver " << resolver_.get() - << "] creating XdsConfigSelector " << this; - } + GRPC_TRACE_LOG(xds_resolver, INFO) << "[xds_resolver " << resolver_.get() + << "] creating XdsConfigSelector " << this; // Populate filter list. const auto& http_filter_registry = static_cast(resolver_->xds_client_->bootstrap()) @@ -660,10 +653,9 @@ XdsResolver::XdsConfigSelector::XdsConfigSelector( } XdsResolver::XdsConfigSelector::~XdsConfigSelector() { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[xds_resolver " << resolver_.get() - << "] destroying XdsConfigSelector " << this; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[xds_resolver " << resolver_.get() + << "] destroying XdsConfigSelector " << this; route_config_data_.reset(); if (!IsWorkSerializerDispatchEnabled()) { resolver_->MaybeRemoveUnusedClusters(); @@ -962,10 +954,9 @@ void XdsResolver::StartLocked() { lds_resource_name_ = absl::StrReplaceAll(name_template, {{"%s", resource_name_fragment}}); } - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[xds_resolver " << this << "] Started with lds_resource_name " - << lds_resource_name_; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[xds_resolver " << this << "] Started with lds_resource_name " + << lds_resource_name_; // Start watch for xDS config. dependency_mgr_ = MakeOrphanable( xds_client_, work_serializer_, @@ -974,9 +965,8 @@ void XdsResolver::StartLocked() { } void XdsResolver::ShutdownLocked() { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[xds_resolver " << this << "] shutting down"; - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[xds_resolver " << this << "] shutting down"; if (xds_client_ != nullptr) { dependency_mgr_.reset(); grpc_pollset_set_del_pollset_set(xds_client_->interested_parties(), @@ -985,11 +975,9 @@ void XdsResolver::ShutdownLocked() { } } -void XdsResolver::OnUpdate( - RefCountedPtr config) { - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[xds_resolver " << this << "] received updated xDS config"; - } +void XdsResolver::OnUpdate(RefCountedPtr config) { + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[xds_resolver " << this << "] received updated xDS config"; if (xds_client_ == nullptr) return; current_config_ = std::move(config); GenerateResult(); @@ -1086,12 +1074,11 @@ void XdsResolver::GenerateResult() { Result result; result.addresses.emplace(); result.service_config = CreateServiceConfig(); - if (GRPC_TRACE_FLAG_ENABLED(xds_resolver)) { - LOG(INFO) << "[xds_resolver " << this << "] generated service config: " - << (result.service_config.ok() - ? ((*result.service_config)->json_string()) - : result.service_config.status().ToString()); - } + GRPC_TRACE_LOG(xds_resolver, INFO) + << "[xds_resolver " << this << "] generated service config: " + << (result.service_config.ok() + ? ((*result.service_config)->json_string()) + : result.service_config.status().ToString()); result.args = args_.SetObject(xds_client_.Ref(DEBUG_LOCATION, "xds resolver result")) .SetObject(config_selector) diff --git a/src/core/server/server_config_selector_filter.cc b/src/core/server/server_config_selector_filter.cc index 4dfe26fb5c..3773eeb3b7 100644 --- a/src/core/server/server_config_selector_filter.cc +++ b/src/core/server/server_config_selector_filter.cc @@ -24,7 +24,6 @@ #include "absl/status/statusor.h" #include "absl/types/optional.h" -#include #include #include "src/core/lib/channel/channel_args.h" diff --git a/src/core/server/xds_server_config_fetcher.cc b/src/core/server/xds_server_config_fetcher.cc index 037e54470c..52a3703171 100644 --- a/src/core/server/xds_server_config_fetcher.cc +++ b/src/core/server/xds_server_config_fetcher.cc @@ -586,11 +586,9 @@ XdsServerConfigFetcher::ListenerWatcher::ListenerWatcher( void XdsServerConfigFetcher::ListenerWatcher::OnResourceChanged( std::shared_ptr listener, RefCountedPtr /* read_delay_handle */) { - if (GRPC_TRACE_FLAG_ENABLED(xds_server_config_fetcher)) { - LOG(INFO) << "[ListenerWatcher " << this - << "] Received LDS update from xds client " << xds_client_.get() - << ": " << listener->ToString(); - } + GRPC_TRACE_LOG(xds_server_config_fetcher, INFO) + << "[ListenerWatcher " << this << "] Received LDS update from xds client " + << xds_client_.get() << ": " << listener->ToString(); auto* tcp_listener = absl::get_if(&listener->listener); if (tcp_listener == nullptr) { 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 96a5b3f8b8..063ecbd987 100644 --- a/src/core/service_config/service_config_channel_arg_filter.cc +++ b/src/core/service_config/service_config_channel_arg_filter.cc @@ -28,7 +28,6 @@ #include "absl/types/optional.h" #include -#include #include #include "src/core/ext/filters/message_size/message_size_filter.h" diff --git a/src/core/service_config/service_config_impl.h b/src/core/service_config/service_config_impl.h index f617163a95..a36a803abf 100644 --- a/src/core/service_config/service_config_impl.h +++ b/src/core/service_config/service_config_impl.h @@ -29,7 +29,6 @@ #include "absl/strings/string_view.h" #include -#include #include #include "src/core/lib/channel/channel_args.h" diff --git a/src/core/telemetry/call_tracer.cc b/src/core/telemetry/call_tracer.cc index f09721a062..873db2d192 100644 --- a/src/core/telemetry/call_tracer.cc +++ b/src/core/telemetry/call_tracer.cc @@ -24,7 +24,6 @@ #include "absl/log/check.h" -#include #include #include "src/core/lib/promise/context.h" diff --git a/src/core/telemetry/metrics.h b/src/core/telemetry/metrics.h index 589aa7964e..2f60ff541d 100644 --- a/src/core/telemetry/metrics.h +++ b/src/core/telemetry/metrics.h @@ -25,7 +25,6 @@ #include "absl/strings/string_view.h" #include "absl/types/span.h" -#include #include #include diff --git a/src/core/telemetry/stats_data.cc b/src/core/telemetry/stats_data.cc index 4a317b7fcf..b39702f476 100644 --- a/src/core/telemetry/stats_data.cc +++ b/src/core/telemetry/stats_data.cc @@ -106,6 +106,20 @@ Histogram_10000_20 operator-(const Histogram_10000_20& left, } return result; } +void HistogramCollector_1800000_40::Collect( + Histogram_1800000_40* result) const { + for (int i = 0; i < 40; i++) { + result->buckets_[i] += buckets_[i].load(std::memory_order_relaxed); + } +} +Histogram_1800000_40 operator-(const Histogram_1800000_40& left, + const Histogram_1800000_40& right) { + Histogram_1800000_40 result; + for (int i = 0; i < 40; i++) { + result.buckets_[i] = left.buckets_[i] - right.buckets_[i]; + } + return result; +} const absl::string_view GlobalStats::counter_name[static_cast(Counter::COUNT)] = { "client_calls_created", @@ -123,6 +137,8 @@ const absl::string_view "http2_writes_begun", "http2_transport_stalls", "http2_stream_stalls", + "http2_hpack_hits", + "http2_hpack_misses", "cq_pluck_creates", "cq_next_creates", "cq_callback_creates", @@ -161,6 +177,8 @@ const absl::string_view GlobalStats::counter_doc[static_cast( "control window", "Number of times sending was completely stalled by the stream flow control " "window", + "Number of HPACK cache hits", + "Number of HPACK cache misses (entries added but never used)", "Number of completion queues created for cq_pluck (indicates sync api " "usage)", "Number of completion queues created for cq_next (indicates cq async api " @@ -192,6 +210,7 @@ const absl::string_view "tcp_read_offer_iov_size", "http2_send_message_size", "http2_metadata_size", + "http2_hpack_entry_lifetime", "wrr_subchannel_list_size", "wrr_subchannel_ready_size", "work_serializer_run_time_ms", @@ -223,6 +242,7 @@ const absl::string_view GlobalStats::histogram_doc[static_cast( "Number of byte segments offered to each syscall_read", "Size of messages received by HTTP2 transport", "Number of bytes consumed by metadata, according to HPACK accounting rules", + "Lifetime of HPACK entries in the cache (in milliseconds)", "Number of subchannels in a subchannel list at picker creation time", "Number of READY subchannels in a subchannel list at picker creation time", "Number of milliseconds work serializers run for", @@ -278,6 +298,15 @@ const int kStatsTable10[21] = {0, 1, 2, 4, 7, 12, 19, const uint8_t kStatsTable11[23] = {3, 3, 4, 5, 5, 6, 7, 8, 9, 9, 10, 11, 12, 12, 13, 14, 15, 15, 16, 17, 18, 18, 19}; +const int kStatsTable12[41] = { + 0, 1, 2, 3, 5, 8, 12, 18, 26, + 37, 53, 76, 108, 153, 217, 308, 436, 617, + 873, 1235, 1748, 2473, 3499, 4950, 7003, 9907, 14015, + 19825, 28044, 39670, 56116, 79379, 112286, 158835, 224680, 317821, + 449574, 635945, 899575, 1272492, 1800000}; +const uint8_t kStatsTable13[37] = { + 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39}; } // namespace int Histogram_100000_20::BucketFor(int value) { if (value < 3) { @@ -405,6 +434,29 @@ int Histogram_10000_20::BucketFor(int value) { } } } +int Histogram_1800000_40::BucketFor(int value) { + if (value < 4) { + if (value < 0) { + return 0; + } else { + return value; + } + } else { + if (value < 1048577) { + DblUint val; + val.dbl = value; + const int bucket = + kStatsTable13[((val.uint - 4616189618054758400ull) >> 51)]; + return bucket - (value < kStatsTable12[bucket]); + } else { + if (value < 1272492) { + return 38; + } else { + return 39; + } + } + } +} GlobalStats::GlobalStats() : client_calls_created{0}, server_calls_created{0}, @@ -421,6 +473,8 @@ GlobalStats::GlobalStats() http2_writes_begun{0}, http2_transport_stalls{0}, http2_stream_stalls{0}, + http2_hpack_hits{0}, + http2_hpack_misses{0}, cq_pluck_creates{0}, cq_next_creates{0}, cq_callback_creates{0}, @@ -466,6 +520,9 @@ HistogramView GlobalStats::histogram(Histogram which) const { case Histogram::kHttp2MetadataSize: return HistogramView{&Histogram_65536_26::BucketFor, kStatsTable2, 26, http2_metadata_size.buckets()}; + case Histogram::kHttp2HpackEntryLifetime: + return HistogramView{&Histogram_1800000_40::BucketFor, kStatsTable12, 40, + http2_hpack_entry_lifetime.buckets()}; case Histogram::kWrrSubchannelListSize: return HistogramView{&Histogram_10000_20::BucketFor, kStatsTable10, 20, wrr_subchannel_list_size.buckets()}; @@ -560,6 +617,10 @@ std::unique_ptr GlobalStatsCollector::Collect() const { data.http2_transport_stalls.load(std::memory_order_relaxed); result->http2_stream_stalls += data.http2_stream_stalls.load(std::memory_order_relaxed); + result->http2_hpack_hits += + data.http2_hpack_hits.load(std::memory_order_relaxed); + result->http2_hpack_misses += + data.http2_hpack_misses.load(std::memory_order_relaxed); result->cq_pluck_creates += data.cq_pluck_creates.load(std::memory_order_relaxed); result->cq_next_creates += @@ -598,6 +659,8 @@ std::unique_ptr GlobalStatsCollector::Collect() const { data.tcp_read_offer_iov_size.Collect(&result->tcp_read_offer_iov_size); data.http2_send_message_size.Collect(&result->http2_send_message_size); data.http2_metadata_size.Collect(&result->http2_metadata_size); + data.http2_hpack_entry_lifetime.Collect( + &result->http2_hpack_entry_lifetime); data.wrr_subchannel_list_size.Collect(&result->wrr_subchannel_list_size); data.wrr_subchannel_ready_size.Collect(&result->wrr_subchannel_ready_size); data.work_serializer_run_time_ms.Collect( @@ -664,6 +727,8 @@ std::unique_ptr GlobalStats::Diff(const GlobalStats& other) const { result->http2_transport_stalls = http2_transport_stalls - other.http2_transport_stalls; result->http2_stream_stalls = http2_stream_stalls - other.http2_stream_stalls; + result->http2_hpack_hits = http2_hpack_hits - other.http2_hpack_hits; + result->http2_hpack_misses = http2_hpack_misses - other.http2_hpack_misses; result->cq_pluck_creates = cq_pluck_creates - other.cq_pluck_creates; result->cq_next_creates = cq_next_creates - other.cq_next_creates; result->cq_callback_creates = cq_callback_creates - other.cq_callback_creates; @@ -695,6 +760,8 @@ std::unique_ptr GlobalStats::Diff(const GlobalStats& other) const { result->http2_send_message_size = http2_send_message_size - other.http2_send_message_size; result->http2_metadata_size = http2_metadata_size - other.http2_metadata_size; + result->http2_hpack_entry_lifetime = + http2_hpack_entry_lifetime - other.http2_hpack_entry_lifetime; result->wrr_subchannel_list_size = wrr_subchannel_list_size - other.wrr_subchannel_list_size; result->wrr_subchannel_ready_size = diff --git a/src/core/telemetry/stats_data.h b/src/core/telemetry/stats_data.h index 6220a118f2..89f360e268 100644 --- a/src/core/telemetry/stats_data.h +++ b/src/core/telemetry/stats_data.h @@ -35,6 +35,7 @@ class Histogram_100000_20 { public: static int BucketFor(int value); const uint64_t* buckets() const { return buckets_; } + size_t bucket_count() const { return 20; } friend Histogram_100000_20 operator-(const Histogram_100000_20& left, const Histogram_100000_20& right); @@ -58,6 +59,7 @@ class Histogram_65536_26 { public: static int BucketFor(int value); const uint64_t* buckets() const { return buckets_; } + size_t bucket_count() const { return 26; } friend Histogram_65536_26 operator-(const Histogram_65536_26& left, const Histogram_65536_26& right); @@ -81,6 +83,7 @@ class Histogram_100_20 { public: static int BucketFor(int value); const uint64_t* buckets() const { return buckets_; } + size_t bucket_count() const { return 20; } friend Histogram_100_20 operator-(const Histogram_100_20& left, const Histogram_100_20& right); @@ -104,6 +107,7 @@ class Histogram_16777216_20 { public: static int BucketFor(int value); const uint64_t* buckets() const { return buckets_; } + size_t bucket_count() const { return 20; } friend Histogram_16777216_20 operator-(const Histogram_16777216_20& left, const Histogram_16777216_20& right); @@ -127,6 +131,7 @@ class Histogram_80_10 { public: static int BucketFor(int value); const uint64_t* buckets() const { return buckets_; } + size_t bucket_count() const { return 10; } friend Histogram_80_10 operator-(const Histogram_80_10& left, const Histogram_80_10& right); @@ -150,6 +155,7 @@ class Histogram_10000_20 { public: static int BucketFor(int value); const uint64_t* buckets() const { return buckets_; } + size_t bucket_count() const { return 20; } friend Histogram_10000_20 operator-(const Histogram_10000_20& left, const Histogram_10000_20& right); @@ -168,6 +174,30 @@ class HistogramCollector_10000_20 { private: std::atomic buckets_[20]{}; }; +class HistogramCollector_1800000_40; +class Histogram_1800000_40 { + public: + static int BucketFor(int value); + const uint64_t* buckets() const { return buckets_; } + size_t bucket_count() const { return 40; } + friend Histogram_1800000_40 operator-(const Histogram_1800000_40& left, + const Histogram_1800000_40& right); + + private: + friend class HistogramCollector_1800000_40; + uint64_t buckets_[40]{}; +}; +class HistogramCollector_1800000_40 { + public: + void Increment(int value) { + buckets_[Histogram_1800000_40::BucketFor(value)].fetch_add( + 1, std::memory_order_relaxed); + } + void Collect(Histogram_1800000_40* result) const; + + private: + std::atomic buckets_[40]{}; +}; struct GlobalStats { enum class Counter { kClientCallsCreated, @@ -185,6 +215,8 @@ struct GlobalStats { kHttp2WritesBegun, kHttp2TransportStalls, kHttp2StreamStalls, + kHttp2HpackHits, + kHttp2HpackMisses, kCqPluckCreates, kCqNextCreates, kCqCallbackCreates, @@ -213,6 +245,7 @@ struct GlobalStats { kTcpReadOfferIovSize, kHttp2SendMessageSize, kHttp2MetadataSize, + kHttp2HpackEntryLifetime, kWrrSubchannelListSize, kWrrSubchannelReadySize, kWorkSerializerRunTimeMs, @@ -259,6 +292,8 @@ struct GlobalStats { uint64_t http2_writes_begun; uint64_t http2_transport_stalls; uint64_t http2_stream_stalls; + uint64_t http2_hpack_hits; + uint64_t http2_hpack_misses; uint64_t cq_pluck_creates; uint64_t cq_next_creates; uint64_t cq_callback_creates; @@ -287,6 +322,7 @@ struct GlobalStats { Histogram_80_10 tcp_read_offer_iov_size; Histogram_16777216_20 http2_send_message_size; Histogram_65536_26 http2_metadata_size; + Histogram_1800000_40 http2_hpack_entry_lifetime; Histogram_10000_20 wrr_subchannel_list_size; Histogram_10000_20 wrr_subchannel_ready_size; Histogram_100000_20 work_serializer_run_time_ms; @@ -367,6 +403,12 @@ class GlobalStatsCollector { data_.this_cpu().http2_stream_stalls.fetch_add(1, std::memory_order_relaxed); } + void IncrementHttp2HpackHits() { + data_.this_cpu().http2_hpack_hits.fetch_add(1, std::memory_order_relaxed); + } + void IncrementHttp2HpackMisses() { + data_.this_cpu().http2_hpack_misses.fetch_add(1, std::memory_order_relaxed); + } void IncrementCqPluckCreates() { data_.this_cpu().cq_pluck_creates.fetch_add(1, std::memory_order_relaxed); } @@ -447,6 +489,9 @@ class GlobalStatsCollector { void IncrementHttp2MetadataSize(int value) { data_.this_cpu().http2_metadata_size.Increment(value); } + void IncrementHttp2HpackEntryLifetime(int value) { + data_.this_cpu().http2_hpack_entry_lifetime.Increment(value); + } void IncrementWrrSubchannelListSize(int value) { data_.this_cpu().wrr_subchannel_list_size.Increment(value); } @@ -526,6 +571,8 @@ class GlobalStatsCollector { std::atomic http2_writes_begun{0}; std::atomic http2_transport_stalls{0}; std::atomic http2_stream_stalls{0}; + std::atomic http2_hpack_hits{0}; + std::atomic http2_hpack_misses{0}; std::atomic cq_pluck_creates{0}; std::atomic cq_next_creates{0}; std::atomic cq_callback_creates{0}; @@ -551,6 +598,7 @@ class GlobalStatsCollector { HistogramCollector_80_10 tcp_read_offer_iov_size; HistogramCollector_16777216_20 http2_send_message_size; HistogramCollector_65536_26 http2_metadata_size; + HistogramCollector_1800000_40 http2_hpack_entry_lifetime; HistogramCollector_10000_20 wrr_subchannel_list_size; HistogramCollector_10000_20 wrr_subchannel_ready_size; HistogramCollector_100000_20 work_serializer_run_time_ms; diff --git a/src/core/tsi/alts/handshaker/alts_shared_resource.cc b/src/core/tsi/alts/handshaker/alts_shared_resource.cc index 03e2b4439e..8407ee7cac 100644 --- a/src/core/tsi/alts/handshaker/alts_shared_resource.cc +++ b/src/core/tsi/alts/handshaker/alts_shared_resource.cc @@ -20,7 +20,6 @@ #include "absl/log/check.h" -#include #include #include "src/core/lib/channel/channel_args.h" diff --git a/src/core/tsi/alts/handshaker/transport_security_common_api.h b/src/core/tsi/alts/handshaker/transport_security_common_api.h index a8cb4c3f79..81819c09e7 100644 --- a/src/core/tsi/alts/handshaker/transport_security_common_api.h +++ b/src/core/tsi/alts/handshaker/transport_security_common_api.h @@ -22,7 +22,6 @@ #include #include #include -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc index 40046f0769..2ae8bb534d 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc @@ -22,7 +22,6 @@ #include #include -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index d32faac9e2..83af8b25c6 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -28,6 +28,7 @@ #include #include "src/core/lib/gprpp/crash.h" +#include "src/core/lib/gprpp/dump_args.h" #include "src/core/lib/gprpp/memory.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/tsi/transport_security_grpc.h" @@ -210,6 +211,8 @@ static tsi_result tsi_fake_frame_decode(const unsigned char* incoming_bytes, frame->offset += to_read_size; available_size -= to_read_size; frame->size = load32_little_endian(frame->data); + if (frame->size < 4) return TSI_DATA_CORRUPTED; + if (frame->size > 16 * 1024 * 1024) return TSI_DATA_CORRUPTED; tsi_fake_frame_ensure_size(frame); } @@ -639,11 +642,9 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer( if (next_message_to_send > TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { next_message_to_send = TSI_FAKE_HANDSHAKE_MESSAGE_MAX; } - if (GRPC_TRACE_FLAG_ENABLED(tsi)) { - LOG(INFO) << (impl->is_client ? "Client" : "Server") << " prepared " - << tsi_fake_handshake_message_to_string( - impl->next_message_to_send); - } + GRPC_TRACE_LOG(tsi, INFO) + << (impl->is_client ? "Client" : "Server") << " prepared " + << tsi_fake_handshake_message_to_string(impl->next_message_to_send); impl->next_message_to_send = next_message_to_send; } result = 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 de89e3e85f..d6c5d556b9 100644 --- a/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +++ b/src/core/tsi/ssl/session_cache/ssl_session_cache.cc @@ -21,7 +21,6 @@ #include "absl/log/check.h" #include "absl/log/log.h" -#include #include #include diff --git a/src/core/util/alloc.cc b/src/core/util/alloc.cc index a8b92260a9..6afba483d4 100644 --- a/src/core/util/alloc.cc +++ b/src/core/util/alloc.cc @@ -24,7 +24,6 @@ #include "absl/log/check.h" #include -#include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/util/android/log.cc b/src/core/util/android/log.cc deleted file mode 100644 index 942ac4bd2f..0000000000 --- a/src/core/util/android/log.cc +++ /dev/null @@ -1,51 +0,0 @@ -// -// -// Copyright 2015 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 - -#ifdef GPR_ANDROID - -#include -#include -#include -#include - -#include -#include - -#include "src/core/lib/gprpp/crash.h" - -extern void gpr_log_message(const char* file, int line, - gpr_log_severity severity, const char* message); - -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 - if (gpr_should_log(severity) == 0) { - return; - } - char* message = NULL; - va_list args; - va_start(args, format); - vasprintf(&message, format, args); - va_end(args); - gpr_log_message(file, line, severity, message); - free(message); -} - -#endif // GPR_ANDROID diff --git a/src/core/util/gcp_metadata_query.cc b/src/core/util/gcp_metadata_query.cc index db2c382bea..351f6e7a57 100644 --- a/src/core/util/gcp_metadata_query.cc +++ b/src/core/util/gcp_metadata_query.cc @@ -35,7 +35,6 @@ #include #include #include -#include #include "src/core/lib/debug/trace.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" diff --git a/src/core/util/http_client/httpcli.cc b/src/core/util/http_client/httpcli.cc index 12f1334747..4220cb58b6 100644 --- a/src/core/util/http_client/httpcli.cc +++ b/src/core/util/http_client/httpcli.cc @@ -33,7 +33,6 @@ #include #include #include -#include #include "src/core/handshaker/handshaker.h" #include "src/core/handshaker/handshaker_registry.h" @@ -78,8 +77,7 @@ OrphanablePtr HttpRequest::Get( // Note that capturing request here assumes it will remain alive // until after Start is called. This avoids making a copy as this // code path is only used for test mocks. - g_get_override(request, uri.authority().c_str(), uri.path().c_str(), - deadline, on_done, response); + g_get_override(request, uri, deadline, on_done, response); }; } std::string name = @@ -101,9 +99,9 @@ OrphanablePtr HttpRequest::Post( if (g_post_override != nullptr) { test_only_generate_response = [request, uri, deadline, on_done, response]() { - g_post_override(request, uri.authority().c_str(), uri.path().c_str(), - request->body, request->body_length, deadline, on_done, - response); + g_post_override(request, uri, + absl::string_view(request->body, request->body_length), + deadline, on_done, response); }; } std::string name = @@ -125,9 +123,9 @@ OrphanablePtr HttpRequest::Put( if (g_put_override != nullptr) { test_only_generate_response = [request, uri, deadline, on_done, response]() { - g_put_override(request, uri.authority().c_str(), uri.path().c_str(), - request->body, request->body_length, deadline, on_done, - response); + g_put_override(request, uri, + absl::string_view(request->body, request->body_length), + deadline, on_done, response); }; } std::string name = diff --git a/src/core/util/http_client/httpcli.h b/src/core/util/http_client/httpcli.h index 7101ebf7ed..dd676a5b1c 100644 --- a/src/core/util/http_client/httpcli.h +++ b/src/core/util/http_client/httpcli.h @@ -30,6 +30,7 @@ #include "absl/base/thread_annotations.h" #include "absl/status/status.h" #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" #include "absl/types/optional.h" #include @@ -59,18 +60,22 @@ // override functions return 1 if they handled the request, 0 otherwise typedef int (*grpc_httpcli_get_override)(const grpc_http_request* request, - const char* host, const char* path, + const grpc_core::URI& uri, + grpc_core::Timestamp deadline, + grpc_closure* on_complete, + grpc_http_response* response); +typedef int (*grpc_httpcli_post_override)(const grpc_http_request* request, + const grpc_core::URI& uri, + absl::string_view body, + grpc_core::Timestamp deadline, + grpc_closure* on_complete, + grpc_http_response* response); +typedef int (*grpc_httpcli_put_override)(const grpc_http_request* request, + const grpc_core::URI& uri, + absl::string_view body, grpc_core::Timestamp deadline, grpc_closure* on_complete, grpc_http_response* response); -typedef int (*grpc_httpcli_post_override)( - const grpc_http_request* request, const char* host, const char* path, - const char* body_bytes, size_t body_size, grpc_core::Timestamp deadline, - grpc_closure* on_complete, grpc_http_response* response); -typedef int (*grpc_httpcli_put_override)( - const grpc_http_request* request, const char* host, const char* path, - const char* body_bytes, size_t body_size, grpc_core::Timestamp deadline, - grpc_closure* on_complete, grpc_http_response* response); namespace grpc_core { diff --git a/src/core/util/http_client/parser.cc b/src/core/util/http_client/parser.cc index 5e905ce3ac..b0c7416c6c 100644 --- a/src/core/util/http_client/parser.cc +++ b/src/core/util/http_client/parser.cc @@ -376,10 +376,9 @@ static grpc_error_handle addbyte(grpc_http_parser* parser, uint8_t byte, case GRPC_HTTP_HEADERS: case GRPC_HTTP_TRAILERS: if (parser->cur_line_length >= GRPC_HTTP_PARSER_MAX_HEADER_LENGTH) { - if (GRPC_TRACE_FLAG_ENABLED(http1)) { - LOG(ERROR) << "HTTP header max line length (" - << GRPC_HTTP_PARSER_MAX_HEADER_LENGTH << ") exceeded"; - } + GRPC_TRACE_LOG(http1, ERROR) + << "HTTP header max line length (" + << GRPC_HTTP_PARSER_MAX_HEADER_LENGTH << ") exceeded"; return GRPC_ERROR_CREATE("HTTP header max line length exceeded"); } parser->cur_line[parser->cur_line_length] = byte; diff --git a/src/core/util/json/json_reader.cc b/src/core/util/json/json_reader.cc index 291e96544d..20a1a04a75 100644 --- a/src/core/util/json/json_reader.cc +++ b/src/core/util/json/json_reader.cc @@ -36,7 +36,6 @@ #include "absl/types/variant.h" #include -#include #include "src/core/lib/gprpp/match.h" #include "src/core/util/json/json.h" diff --git a/src/core/util/latent_see.cc b/src/core/util/latent_see.cc index 7234ad5156..6bb250b445 100644 --- a/src/core/util/latent_see.cc +++ b/src/core/util/latent_see.cc @@ -15,12 +15,19 @@ #include "src/core/util/latent_see.h" #ifdef GRPC_ENABLE_LATENT_SEE +#include #include #include +#include +#include #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "absl/types/optional.h" +#include "src/core/lib/gprpp/sync.h" +#include "src/core/util/ring_buffer.h" + namespace grpc_core { namespace latent_see { @@ -28,13 +35,25 @@ thread_local uint64_t Log::thread_id_ = Log::Get().next_thread_id_.fetch_add(1); thread_local Bin* Log::bin_ = nullptr; thread_local void* Log::bin_owner_ = nullptr; std::atomic Flow::next_flow_id_{1}; -std::atomic Log::free_bins_; +std::atomic Log::free_bins_{0}; std::string Log::GenerateJson() { std::vector events; + RingBuffer* other; for (auto& fragment : fragments_) { - MutexLock lock(&fragment.mu); - events.insert(events.end(), fragment.events.begin(), fragment.events.end()); + { + MutexLock lock(&fragment.mu); + other = fragment.active; + if (fragment.active == &fragment.primary) { + fragment.active = &fragment.secondary; + } else { + fragment.active = &fragment.primary; + } + } + for (auto it = other->begin(); it != other->end(); ++it) { + events.push_back(*it); + } + other->Clear(); } absl::optional start_time; for (auto& event : events) { @@ -103,7 +122,7 @@ void Log::FlushBin(Bin* bin) { { MutexLock lock(&fragment.mu); for (auto event : bin->events) { - fragment.events.push_back(RecordedEvent{thread_id, batch_id, event}); + fragment.active->Append(RecordedEvent{thread_id, batch_id, event}); } } bin->events.clear(); diff --git a/src/core/util/latent_see.h b/src/core/util/latent_see.h index d5b9e297cd..4d4f1584b0 100644 --- a/src/core/util/latent_see.h +++ b/src/core/util/latent_see.h @@ -18,15 +18,28 @@ #include #ifdef GRPC_ENABLE_LATENT_SEE +#include +#include + +#include #include #include +#include +#include +#include #include #include +#include "absl/base/thread_annotations.h" +#include "absl/functional/any_invocable.h" #include "absl/log/log.h" +#include "absl/strings/string_view.h" #include "src/core/lib/gprpp/per_cpu.h" #include "src/core/lib/gprpp/sync.h" +#include "src/core/util/ring_buffer.h" + +#define TAGGED_POINTER_SIZE_BITS 48 namespace grpc_core { namespace latent_see { @@ -54,46 +67,59 @@ struct Bin { } std::vector events; - Bin* next_free; + uintptr_t next_free = 0; }; class Log { public: - static Bin* MaybeStartBin(void* owner) { - if (bin_ != nullptr) return bin_; - Bin* bin = free_bins_.load(std::memory_order_acquire); + static constexpr int kMaxEventsPerCpu = 50000; + static constexpr uintptr_t kTagMask = (1ULL << TAGGED_POINTER_SIZE_BITS) - 1; + + GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION static uintptr_t IncrementTag( + uintptr_t input) { + return input + (1UL << TAGGED_POINTER_SIZE_BITS); + } + + GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION static Bin* ToBin(uintptr_t ptr) { + return reinterpret_cast(ptr & kTagMask); + } + + static uintptr_t StartBin(void* owner) { + uintptr_t bin_descriptor = free_bins_.load(std::memory_order_acquire); + Bin* bin; do { - if (bin == nullptr) { + if (bin_descriptor == 0) { bin = new Bin(); break; } - } while (!free_bins_.compare_exchange_weak(bin, bin->next_free, - std::memory_order_acq_rel)); + bin = ToBin(bin_descriptor); + } while (!free_bins_.compare_exchange_strong(bin_descriptor, bin->next_free, + std::memory_order_acq_rel)); bin_ = bin; bin_owner_ = owner; - return bin; + return reinterpret_cast(bin); } - static void EndBin(void* owner) { - if (bin_owner_ != owner) return; - FlushBin(bin_); - bin_->next_free = free_bins_.load(std::memory_order_acquire); - while (!free_bins_.compare_exchange_weak(bin_->next_free, bin_, - std::memory_order_acq_rel)) { + static void EndBin(uintptr_t bin_descriptor, void* owner) { + if (bin_owner_ != owner || bin_descriptor == 0) return; + FlushBin(ToBin(bin_descriptor)); + uintptr_t next_free = free_bins_.load(std::memory_order_acquire); + while (!free_bins_.compare_exchange_strong( + next_free, IncrementTag(bin_descriptor), std::memory_order_acq_rel)) { } bin_ = nullptr; + bin_owner_ = nullptr; } static Bin* CurrentThreadBin() { return bin_; } - private: - Log() = default; - - static void FlushBin(Bin* bin); - GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION static Log& Get() { static Log* log = []() { atexit([] { + if (log->stats_flusher_ != nullptr) { + log->stats_flusher_(log->GenerateJson()); + return; + } LOG(INFO) << "Writing latent_see.json in " << get_current_dir_name(); FILE* f = fopen("latent_see.json", "w"); if (f == nullptr) return; @@ -107,6 +133,16 @@ class Log { std::string GenerateJson(); + void OverrideStatsFlusher( + absl::AnyInvocable stats_exporter) { + stats_flusher_ = std::move(stats_exporter); + } + + private: + Log() = default; + + static void FlushBin(Bin* bin); + struct RecordedEvent { uint64_t thread_id; uint64_t batch_id; @@ -117,10 +153,15 @@ class Log { static thread_local uint64_t thread_id_; static thread_local Bin* bin_; static thread_local void* bin_owner_; - static std::atomic free_bins_; + static std::atomic free_bins_; + absl::AnyInvocable stats_flusher_ = nullptr; struct Fragment { + Fragment() : active(&primary) {}; Mutex mu; - std::vector events ABSL_GUARDED_BY(mu); + RingBuffer* active + ABSL_GUARDED_BY(mu); + RingBuffer primary; + RingBuffer secondary; }; PerCpu fragments_{PerCpuOptions()}; }; @@ -130,11 +171,17 @@ class Scope { public: GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION explicit Scope(const Metadata* metadata) : metadata_(metadata) { + bin_ = Log::CurrentThreadBin(); + if (kParent && bin_ == nullptr) { + bin_descriptor_ = Log::StartBin(this); + bin_ = Log::ToBin(bin_descriptor_); + } + CHECK_NE(bin_, nullptr); bin_->Append(metadata_, EventType::kBegin, 0); } GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION ~Scope() { bin_->Append(metadata_, EventType::kEnd, 0); - if (kParent) Log::EndBin(this); + if (kParent) Log::EndBin(bin_descriptor_, this); } Scope(const Scope&) = delete; @@ -142,8 +189,8 @@ class Scope { private: const Metadata* const metadata_; - Bin* const bin_ = - kParent ? Log::MaybeStartBin(this) : Log::CurrentThreadBin(); + uintptr_t bin_descriptor_ = 0; + Bin* bin_ = nullptr; }; using ParentScope = Scope; diff --git a/src/core/util/linux/log.cc b/src/core/util/linux/log.cc deleted file mode 100644 index bede7c8c21..0000000000 --- a/src/core/util/linux/log.cc +++ /dev/null @@ -1,72 +0,0 @@ -// -// -// Copyright 2015 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 _POSIX_SOURCE -#define _POSIX_SOURCE -#endif - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include - -#ifdef GPR_LINUX_LOG - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "absl/strings/str_format.h" - -#include -#include -#include - -#include "src/core/lib/gprpp/crash.h" -#include "src/core/lib/gprpp/examine_stack.h" - -extern void gpr_log_message(const char* file, int line, - gpr_log_severity severity, const char* message); - -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 - if (gpr_should_log(severity) == 0) { - return; - } - char* message = nullptr; - va_list args; - va_start(args, format); - if (vasprintf(&message, format, args) == -1) { - va_end(args); - return; - } - va_end(args); - gpr_log_message(file, line, severity, message); - // message has been allocated by vasprintf above, and needs free - free(message); -} - -#endif // GPR_LINUX_LOG diff --git a/src/core/util/log.cc b/src/core/util/log.cc index 411f76a14c..0a1ef08f75 100644 --- a/src/core/util/log.cc +++ b/src/core/util/log.cc @@ -23,6 +23,7 @@ #include #include +#include "absl/log/check.h" #include "absl/log/globals.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -40,53 +41,61 @@ void gpr_unreachable_code(const char* reason, const char* file, int line) { grpc_core::SourceLocation(file, line)); } -int gpr_should_log(gpr_log_severity severity) { +GPRAPI void grpc_absl_log(const char* file, int line, gpr_log_severity severity, + const char* message_str) { switch (severity) { - case GPR_LOG_SEVERITY_ERROR: - return absl::MinLogLevel() <= absl::LogSeverityAtLeast::kError; - case GPR_LOG_SEVERITY_INFO: - // There is no documentation about how expensive or inexpensive - // MinLogLevel is. We could have saved this in a static const variable. - // But decided against it just in case anyone programatically sets absl - // min log level settings after this has been initialized. - // Same holds for ABSL_VLOG_IS_ON(2). - return absl::MinLogLevel() <= absl::LogSeverityAtLeast::kInfo; case GPR_LOG_SEVERITY_DEBUG: - return ABSL_VLOG_IS_ON(2); + VLOG(2).AtLocation(file, line) << message_str; + return; + case GPR_LOG_SEVERITY_INFO: + LOG(INFO).AtLocation(file, line) << message_str; + return; + case GPR_LOG_SEVERITY_ERROR: + LOG(ERROR).AtLocation(file, line) << message_str; + return; default: - DLOG(ERROR) << "Invalid gpr_log_severity."; - return true; + DCHECK(false) << "Invalid severity"; } } -void gpr_log_message(const char* file, int line, gpr_log_severity severity, - const char* message) { - if (gpr_should_log(severity) == 0) { - return; +GPRAPI void grpc_absl_log_int(const char* file, int line, + gpr_log_severity severity, + const char* message_str, intptr_t num) { + switch (severity) { + case GPR_LOG_SEVERITY_DEBUG: + VLOG(2).AtLocation(file, line) << message_str << num; + return; + case GPR_LOG_SEVERITY_INFO: + LOG(INFO).AtLocation(file, line) << message_str << num; + return; + case GPR_LOG_SEVERITY_ERROR: + LOG(ERROR).AtLocation(file, line) << message_str << num; + return; + default: + DCHECK(false) << "Invalid severity"; } +} + +GPRAPI void grpc_absl_log_str(const char* file, int line, + gpr_log_severity severity, + const char* message_str1, + const char* message_str2) { switch (severity) { case GPR_LOG_SEVERITY_DEBUG: - // Log DEBUG messages as VLOG(2). - VLOG(2).AtLocation(file, line) << message; + VLOG(2).AtLocation(file, line) << message_str1 << message_str2; return; case GPR_LOG_SEVERITY_INFO: - LOG(INFO).AtLocation(file, line) << message; + LOG(INFO).AtLocation(file, line) << message_str1 << message_str2; return; case GPR_LOG_SEVERITY_ERROR: - LOG(ERROR).AtLocation(file, line) << message; + LOG(ERROR).AtLocation(file, line) << message_str1 << message_str2; return; default: - LOG(ERROR) << __func__ << ": unknown gpr log severity(" << severity - << "), using ERROR"; - LOG(ERROR).AtLocation(file, line) << message; + DCHECK(false) << "Invalid severity"; } } void gpr_log_verbosity_init(void) { -// This is enabled in Github only. -// This ifndef is converted to ifdef internally by copybara. -// Internally grpc verbosity is managed using absl settings. -// So internally we avoid setting it like this. #ifndef GRPC_VERBOSITY_MACRO // SetMinLogLevel sets the value for the entire binary, not just gRPC. // This setting will change things for other libraries/code that is unrelated diff --git a/src/core/util/msys/tmpfile.cc b/src/core/util/msys/tmpfile.cc index 41a04f1c75..dc1cdf7bc3 100644 --- a/src/core/util/msys/tmpfile.cc +++ b/src/core/util/msys/tmpfile.cc @@ -26,7 +26,6 @@ #include #include -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/util/posix/log.cc b/src/core/util/posix/log.cc deleted file mode 100644 index 2d1fe2ebb6..0000000000 --- a/src/core/util/posix/log.cc +++ /dev/null @@ -1,72 +0,0 @@ -// -// -// Copyright 2015 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 - -#ifdef GPR_POSIX_LOG - -#include -#include -#include -#include -#include -#include - -#include - -#include "absl/strings/str_format.h" - -#include -#include -#include - -#include "src/core/lib/gprpp/crash.h" -#include "src/core/lib/gprpp/examine_stack.h" - -extern void gpr_log_message(const char* file, int line, - gpr_log_severity severity, const char* message); - -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 - if (gpr_should_log(severity) == 0) { - return; - } - char buf[64]; - char* allocated = nullptr; - char* message = nullptr; - int ret; - va_list args; - va_start(args, format); - ret = vsnprintf(buf, sizeof(buf), format, args); - va_end(args); - if (ret < 0) { - message = nullptr; - } else if ((size_t)ret <= sizeof(buf) - 1) { - message = buf; - } else { - message = allocated = (char*)gpr_malloc((size_t)ret + 1); - va_start(args, format); - vsnprintf(message, (size_t)(ret + 1), format, args); - va_end(args); - } - gpr_log_message(file, line, severity, message); - gpr_free(allocated); -} - -#endif // defined(GPR_POSIX_LOG) diff --git a/src/core/util/posix/sync.cc b/src/core/util/posix/sync.cc index 912a1a6b48..1ccaa28199 100644 --- a/src/core/util/posix/sync.cc +++ b/src/core/util/posix/sync.cc @@ -27,7 +27,6 @@ #include "absl/log/check.h" #include -#include #include #include diff --git a/src/core/util/posix/time.cc b/src/core/util/posix/time.cc index 6624b0fd65..5fea711d59 100644 --- a/src/core/util/posix/time.cc +++ b/src/core/util/posix/time.cc @@ -31,7 +31,6 @@ #include "absl/log/check.h" #include -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/util/ring_buffer.h b/src/core/util/ring_buffer.h new file mode 100644 index 0000000000..ab0f30f635 --- /dev/null +++ b/src/core/util/ring_buffer.h @@ -0,0 +1,123 @@ +// 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_UTIL_RING_BUFFER_H +#define GRPC_SRC_CORE_UTIL_RING_BUFFER_H + +#include + +#include +#include +#include + +#include "absl/types/optional.h" + +namespace grpc_core { + +template +class RingBuffer { + public: + class RingBufferIterator { + public: + using iterator_category = std::forward_iterator_tag; + using value_type = const T; + using pointer = void; + using reference = void; + using difference_type = std::ptrdiff_t; + + RingBufferIterator& operator++() { + if (--size_ <= 0) { + head_ = 0; + size_ = 0; + buffer_ = nullptr; + } else { + head_ = (head_ + 1) % kCapacity; + } + return *this; + } + + RingBufferIterator operator++(int) { + RingBufferIterator tmp(*this); + operator++(); + return tmp; + } + + bool operator==(const RingBufferIterator& rhs) const { + return (buffer_ == rhs.buffer_ && head_ == rhs.head_ && + size_ == rhs.size_); + } + + bool operator!=(const RingBufferIterator& rhs) const { + return !operator==(rhs); + } + + T operator*() { return buffer_->data_[head_]; } + + RingBufferIterator() : buffer_(nullptr), head_(0), size_(0) {}; + RingBufferIterator(const RingBufferIterator& other) = default; + explicit RingBufferIterator(const RingBuffer* buffer) + : buffer_(buffer), head_(buffer->head_), size_(buffer->size_) { + if (!size_) { + buffer_ = nullptr; + } + } + + private: + friend class RingBuffer; + const RingBuffer* buffer_; + int head_ = 0; + int size_ = 0; + }; + + RingBuffer() = default; + + void Append(T data) { + if (size_ < kCapacity) { + data_[size_] = std::move(data); + size_++; + } else { + data_[head_] = std::move(data); + head_ = (head_ + 1) % kCapacity; + } + } + + // Returns the data of the first element in the buffer and removes it from + // the buffer. If the buffer is empty, returns absl::nullopt. + absl::optional PopIfNotEmpty() { + if (!size_) return absl::nullopt; + T data = std::move(data_[head_]); + --size_; + head_ = (head_ + 1) % kCapacity; + return data; + } + + void Clear() { + head_ = 0; + size_ = 0; + } + + RingBufferIterator begin() const { return RingBufferIterator(this); } + + RingBufferIterator end() const { return RingBufferIterator(); } + + private: + friend class RingBufferIterator; + std::array data_; + int head_ = 0; + int size_ = 0; +}; + +} // namespace grpc_core + +#endif // GRPC_SRC_CORE_UTIL_RING_BUFFER_H diff --git a/src/core/util/spinlock.h b/src/core/util/spinlock.h index b46db8e2a6..b95d324e98 100644 --- a/src/core/util/spinlock.h +++ b/src/core/util/spinlock.h @@ -34,8 +34,7 @@ struct gpr_spinlock { #else #define GPR_SPINLOCK_INITIALIZER ((gpr_spinlock){0}) #endif -#define GPR_SPINLOCK_STATIC_INITIALIZER \ - { 0 } +#define GPR_SPINLOCK_STATIC_INITIALIZER {0} #define gpr_spinlock_trylock(lock) (gpr_atm_acq_cas(&(lock)->atm, 0, 1)) #define gpr_spinlock_unlock(lock) (gpr_atm_rel_store(&(lock)->atm, 0)) diff --git a/src/core/util/string.cc b/src/core/util/string.cc index 7efbd09f51..31ffb9eb4b 100644 --- a/src/core/util/string.cc +++ b/src/core/util/string.cc @@ -31,7 +31,6 @@ #include "absl/strings/str_cat.h" #include -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/util/sync.cc b/src/core/util/sync.cc index b70435a992..dd3db7e642 100644 --- a/src/core/util/sync.cc +++ b/src/core/util/sync.cc @@ -25,7 +25,6 @@ #include "absl/log/check.h" #include -#include #include // Number of mutexes to allocate for events, to avoid lock contention. diff --git a/src/core/util/sync_abseil.cc b/src/core/util/sync_abseil.cc index cc23c3d1cd..1d826f6565 100644 --- a/src/core/util/sync_abseil.cc +++ b/src/core/util/sync_abseil.cc @@ -29,7 +29,6 @@ #include "absl/time/time.h" #include -#include #include #include diff --git a/src/core/util/time.cc b/src/core/util/time.cc index a46e95ef35..d71cee90ca 100644 --- a/src/core/util/time.cc +++ b/src/core/util/time.cc @@ -26,7 +26,6 @@ #include "absl/log/check.h" -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/util/unique_ptr_with_bitset.h b/src/core/util/unique_ptr_with_bitset.h new file mode 100644 index 0000000000..112c3ea49e --- /dev/null +++ b/src/core/util/unique_ptr_with_bitset.h @@ -0,0 +1,86 @@ +// 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_UTIL_UNIQUE_PTR_WITH_BITSET_H +#define GRPC_SRC_CORE_UTIL_UNIQUE_PTR_WITH_BITSET_H + +#include +#include + +#include "absl/log/check.h" +#include "absl/numeric/bits.h" + +namespace grpc_core { + +// Like std::unique_ptr, but also includes a small bitset stored in the lower +// bits of the underlying T*. +template +class UniquePtrWithBitset { + public: + UniquePtrWithBitset() : p_(0) {} + // NOLINTNEXTLINE(google-explicit-constructor) + UniquePtrWithBitset(std::nullptr_t) : p_(0) {} + explicit UniquePtrWithBitset(T* p) : p_(reinterpret_cast(p)) {} + // NOLINTNEXTLINE(google-explicit-constructor) + UniquePtrWithBitset(std::unique_ptr&& p) + : UniquePtrWithBitset(p.release()) {} + ~UniquePtrWithBitset() { + DCHECK_LE(kBits, static_cast(absl::countr_zero(alignof(T)))); + delete get(); + } + UniquePtrWithBitset(const UniquePtrWithBitset&) = delete; + UniquePtrWithBitset& operator=(const UniquePtrWithBitset&) = delete; + UniquePtrWithBitset(UniquePtrWithBitset&& other) noexcept + : p_(std::exchange(other.p_, 0)) {} + UniquePtrWithBitset& operator=(UniquePtrWithBitset&& other) noexcept { + p_ = std::exchange(other.p_, 0); + return *this; + } + + T* get() const { return reinterpret_cast(p_ & ~kBitMask); } + T* operator->() const { return get(); } + T& operator*() const { return *get(); } + explicit operator bool() const { return get() != nullptr; } + void reset(T* p = nullptr) { + uintptr_t bits = p_ & kBitMask; + delete get(); + p_ = reinterpret_cast(p) | bits; + } + + void SetBit(size_t bit) { + DCHECK_LT(bit, kBits); + p_ |= 1 << bit; + } + void ClearBit(size_t bit) { + DCHECK_LT(bit, kBits); + p_ &= ~(1 << bit); + } + bool TestBit(size_t bit) const { + DCHECK_LT(bit, kBits); + return p_ & (1 << bit); + } + + friend bool operator==(const UniquePtrWithBitset& a, + const UniquePtrWithBitset& b) { + return a.p_ == b.p_; + } + + private: + static constexpr uintptr_t kBitMask = (1 << kBits) - 1; + uintptr_t p_; +}; + +} // namespace grpc_core + +#endif // GRPC_SRC_CORE_UTIL_UNIQUE_PTR_WITH_BITSET_H diff --git a/src/core/util/useful.h b/src/core/util/useful.h index 37a5161190..8007c4ca33 100644 --- a/src/core/util/useful.h +++ b/src/core/util/useful.h @@ -57,30 +57,6 @@ bool GetBit(T i, size_t n) { return (i & (T(1) << n)) != 0; } -#if GRPC_HAS_BUILTIN(__builtin_ctz) -GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION inline uint32_t CountTrailingZeros( - uint32_t i) { - DCHECK_NE(i, 0u); // __builtin_ctz returns undefined behavior for 0 - return __builtin_ctz(i); -} -GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION inline uint32_t CountTrailingZeros( - uint64_t i) { - DCHECK_NE(i, 0u); // __builtin_ctz returns undefined behavior for 0 - return __builtin_ctzll(i); -} -#else -GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION inline uint32_t CountTrailingZeros( - uint32_t i) { - DCHECK_NE(i, 0); // __builtin_ctz returns undefined behavior for 0 - return absl::popcount((i & -i) - 1); -} -GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION inline uint32_t CountTrailingZeros( - uint64_t i) { - DCHECK_NE(i, 0); // __builtin_ctz returns undefined behavior for 0 - return absl::popcount((i & -i) - 1); -} -#endif - // This function uses operator< to implement a qsort-style comparison, whereby: // if a is smaller than b, a number smaller than 0 is returned. // if a is bigger than b, a number greater than 0 is returned. diff --git a/src/core/util/windows/cpu.cc b/src/core/util/windows/cpu.cc index 94af1e419c..a8ba5952f8 100644 --- a/src/core/util/windows/cpu.cc +++ b/src/core/util/windows/cpu.cc @@ -20,7 +20,6 @@ #ifdef GPR_WINDOWS #include -#include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/util/windows/log.cc b/src/core/util/windows/log.cc deleted file mode 100644 index e3c7b1179f..0000000000 --- a/src/core/util/windows/log.cc +++ /dev/null @@ -1,76 +0,0 @@ -// -// -// Copyright 2015 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 - -#ifdef GPR_WINDOWS_LOG - -#include -#include - -#include -#include -#include -#include -#include - -#include "src/core/lib/gprpp/crash.h" -#include "src/core/lib/gprpp/examine_stack.h" -#include "src/core/util/string.h" - -extern void gpr_log_message(const char* file, int line, - gpr_log_severity severity, const char* message); - -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 - if (gpr_should_log(severity) == 0) { - return; - } - - char* message = NULL; - va_list args; - int ret; - - // Determine the length. - va_start(args, format); - ret = _vscprintf(format, args); - va_end(args); - if (ret < 0) { - message = NULL; - } else { - // Allocate a new buffer, with space for the NUL terminator. - size_t strp_buflen = (size_t)ret + 1; - message = (char*)gpr_malloc(strp_buflen); - - // Print to the buffer. - va_start(args, format); - ret = vsnprintf_s(message, strp_buflen, _TRUNCATE, format, args); - va_end(args); - if ((size_t)ret != strp_buflen - 1) { - // This should never happen. - gpr_free(message); - message = NULL; - } - } - - gpr_log_message(file, line, severity, message); - gpr_free(message); -} - -#endif // GPR_WINDOWS_LOG diff --git a/src/core/util/windows/sync.cc b/src/core/util/windows/sync.cc index 800188bf29..0f7fd78868 100644 --- a/src/core/util/windows/sync.cc +++ b/src/core/util/windows/sync.cc @@ -25,7 +25,6 @@ #include "absl/log/check.h" -#include #include #include diff --git a/src/core/util/windows/time.cc b/src/core/util/windows/time.cc index b80a4a5a14..21cfed52a1 100644 --- a/src/core/util/windows/time.cc +++ b/src/core/util/windows/time.cc @@ -28,7 +28,6 @@ #include "absl/log/check.h" -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/util/windows/tmpfile.cc b/src/core/util/windows/tmpfile.cc index cd3838bc4e..23d647a2b8 100644 --- a/src/core/util/windows/tmpfile.cc +++ b/src/core/util/windows/tmpfile.cc @@ -26,7 +26,6 @@ #include #include -#include #include #include "src/core/lib/gprpp/crash.h" diff --git a/src/core/xds/grpc/xds_certificate_provider.cc b/src/core/xds/grpc/xds_certificate_provider.cc index 35c537bf36..fecc658d36 100644 --- a/src/core/xds/grpc/xds_certificate_provider.cc +++ b/src/core/xds/grpc/xds_certificate_provider.cc @@ -24,7 +24,6 @@ #include "absl/log/check.h" #include "absl/types/optional.h" -#include #include #include "src/core/lib/channel/channel_args.h" diff --git a/src/core/xds/grpc/xds_client_grpc.cc b/src/core/xds/grpc/xds_client_grpc.cc index 96492ff31f..e3092c16f4 100644 --- a/src/core/xds/grpc/xds_client_grpc.cc +++ b/src/core/xds/grpc/xds_client_grpc.cc @@ -198,11 +198,10 @@ absl::StatusOr GetBootstrapContents(const char* fallback_config) { // First, try GRPC_XDS_BOOTSTRAP env var. auto path = GetEnv("GRPC_XDS_BOOTSTRAP"); if (path.has_value()) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "Got bootstrap file location from GRPC_XDS_BOOTSTRAP " - "environment variable: " - << *path; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "Got bootstrap file location from GRPC_XDS_BOOTSTRAP " + "environment variable: " + << *path; auto contents = LoadFile(*path, /*add_null_terminator=*/true); if (!contents.ok()) return contents.status(); return std::string(contents->as_string_view()); @@ -210,10 +209,9 @@ absl::StatusOr GetBootstrapContents(const char* fallback_config) { // Next, try GRPC_XDS_BOOTSTRAP_CONFIG env var. auto env_config = GetEnv("GRPC_XDS_BOOTSTRAP_CONFIG"); if (env_config.has_value()) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "Got bootstrap contents from GRPC_XDS_BOOTSTRAP_CONFIG " - "environment variable"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "Got bootstrap contents from GRPC_XDS_BOOTSTRAP_CONFIG " + << "environment variable"; return std::move(*env_config); } // Finally, try fallback config. @@ -258,9 +256,8 @@ absl::StatusOr> GrpcXdsClient::GetOrCreate( // Find bootstrap contents. auto bootstrap_contents = GetBootstrapContents(g_fallback_bootstrap_config); if (!bootstrap_contents.ok()) return bootstrap_contents.status(); - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "xDS bootstrap contents: " << *bootstrap_contents; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "xDS bootstrap contents: " << *bootstrap_contents; // Parse bootstrap. auto bootstrap = GrpcXdsBootstrap::Create(*bootstrap_contents); if (!bootstrap.ok()) return bootstrap.status(); @@ -270,10 +267,8 @@ absl::StatusOr> GrpcXdsClient::GetOrCreate( key, std::move(*bootstrap), channel_args, MakeOrphanable(channel_args)); g_xds_client_map->emplace(xds_client->key(), xds_client.get()); - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client.get() - << "] Created xDS client for key " << key; - } + GRPC_TRACE_LOG(xds_client, INFO) << "[xds_client " << xds_client.get() + << "] Created xDS client for key " << key; return xds_client; } diff --git a/src/core/xds/grpc/xds_cluster.cc b/src/core/xds/grpc/xds_cluster.cc index 300528f5a1..1f0c6b05cb 100644 --- a/src/core/xds/grpc/xds_cluster.cc +++ b/src/core/xds/grpc/xds_cluster.cc @@ -65,14 +65,8 @@ std::string XdsClusterResource::ToString() const { absl::StrCat("max_concurrent_requests=", max_concurrent_requests)); contents.push_back(absl::StrCat("override_host_statuses=", override_host_statuses.ToString())); - if (!service_telemetry_label.as_string_view().empty()) { - contents.push_back(absl::StrCat("service_name_telemetry_label=", - service_telemetry_label.as_string_view())); - } - if (!namespace_telemetry_label.as_string_view().empty()) { - contents.push_back( - absl::StrCat("service_namespace_telemetry_label=", - namespace_telemetry_label.as_string_view())); + if (!metadata.empty()) { + contents.push_back(absl::StrCat("metadata={", metadata.ToString(), "}")); } return absl::StrCat("{", absl::StrJoin(contents, ", "), "}"); } diff --git a/src/core/xds/grpc/xds_cluster.h b/src/core/xds/grpc/xds_cluster.h index 601593541e..7021b61b30 100644 --- a/src/core/xds/grpc/xds_cluster.h +++ b/src/core/xds/grpc/xds_cluster.h @@ -20,6 +20,7 @@ #include #include +#include "absl/container/flat_hash_map.h" #include "absl/types/optional.h" #include "absl/types/variant.h" @@ -27,6 +28,7 @@ #include "src/core/util/json/json.h" #include "src/core/xds/grpc/xds_common_types.h" #include "src/core/xds/grpc/xds_health_status.h" +#include "src/core/xds/grpc/xds_metadata.h" #include "src/core/xds/grpc/xds_server_grpc.h" #include "src/core/xds/xds_client/xds_resource_type.h" #include "src/core/xds/xds_client/xds_resource_type_impl.h" @@ -86,8 +88,7 @@ struct XdsClusterResource : public XdsResourceType::ResourceData { XdsHealthStatusSet override_host_statuses; - RefCountedStringValue service_telemetry_label; - RefCountedStringValue namespace_telemetry_label; + XdsMetadataMap metadata; bool operator==(const XdsClusterResource& other) const { return type == other.type && lb_policy_config == other.lb_policy_config && @@ -97,8 +98,7 @@ struct XdsClusterResource : public XdsResourceType::ResourceData { max_concurrent_requests == other.max_concurrent_requests && outlier_detection == other.outlier_detection && override_host_statuses == other.override_host_statuses && - service_telemetry_label == other.service_telemetry_label && - namespace_telemetry_label == other.namespace_telemetry_label; + metadata == other.metadata; } std::string ToString() const; diff --git a/src/core/xds/grpc/xds_cluster_parser.cc b/src/core/xds/grpc/xds_cluster_parser.cc index c26c62c458..bcf07881f4 100644 --- a/src/core/xds/grpc/xds_cluster_parser.cc +++ b/src/core/xds/grpc/xds_cluster_parser.cc @@ -58,6 +58,7 @@ #include "src/core/xds/grpc/xds_common_types.h" #include "src/core/xds/grpc/xds_common_types_parser.h" #include "src/core/xds/grpc/xds_lb_policy_registry.h" +#include "src/core/xds/grpc/xds_metadata_parser.h" namespace grpc_core { @@ -300,22 +301,22 @@ void ParseLbPolicyConfig(const XdsResourceType::DecodeContext& context, uint64_t max_ring_size = 8388608; if (ring_hash_config != nullptr) { ValidationErrors::ScopedField field(errors, ".ring_hash_lb_config"); - const google_protobuf_UInt64Value* uint64_value = + auto value = ParseUInt64Value( envoy_config_cluster_v3_Cluster_RingHashLbConfig_maximum_ring_size( - ring_hash_config); - if (uint64_value != nullptr) { + ring_hash_config)); + if (value.has_value()) { ValidationErrors::ScopedField field(errors, ".maximum_ring_size"); - max_ring_size = google_protobuf_UInt64Value_value(uint64_value); + max_ring_size = *value; if (max_ring_size > 8388608 || max_ring_size == 0) { errors->AddError("must be in the range of 1 to 8388608"); } } - uint64_value = + value = ParseUInt64Value( envoy_config_cluster_v3_Cluster_RingHashLbConfig_minimum_ring_size( - ring_hash_config); - if (uint64_value != nullptr) { + ring_hash_config)); + if (value.has_value()) { ValidationErrors::ScopedField field(errors, ".minimum_ring_size"); - min_ring_size = google_protobuf_UInt64Value_value(uint64_value); + min_ring_size = *value; if (min_ring_size > 8388608 || min_ring_size == 0) { errors->AddError("must be in the range of 1 to 8388608"); } @@ -478,13 +479,10 @@ absl::StatusOr> CdsResourceParse( const auto* threshold = thresholds[i]; if (envoy_config_cluster_v3_CircuitBreakers_Thresholds_priority( threshold) == envoy_config_core_v3_DEFAULT) { - const google_protobuf_UInt32Value* max_requests = + auto value = ParseUInt32Value( envoy_config_cluster_v3_CircuitBreakers_Thresholds_max_requests( - threshold); - if (max_requests != nullptr) { - cds_update->max_concurrent_requests = - google_protobuf_UInt32Value_value(max_requests); - } + threshold)); + if (value.has_value()) cds_update->max_concurrent_requests = *value; break; } } @@ -515,91 +513,80 @@ absl::StatusOr> CdsResourceParse( outlier_detection_update.max_ejection_time = ParseDuration(duration, &errors); } - const google_protobuf_UInt32Value* max_ejection_percent = + auto max_ejection_percent = ParseUInt32Value( envoy_config_cluster_v3_OutlierDetection_max_ejection_percent( - outlier_detection); - if (max_ejection_percent != nullptr) { - outlier_detection_update.max_ejection_percent = - google_protobuf_UInt32Value_value(max_ejection_percent); + outlier_detection)); + if (max_ejection_percent.has_value()) { + outlier_detection_update.max_ejection_percent = *max_ejection_percent; if (outlier_detection_update.max_ejection_percent > 100) { ValidationErrors::ScopedField field(&errors, ".max_ejection_percent"); errors.AddError("value must be <= 100"); } } - const google_protobuf_UInt32Value* enforcing_success_rate = + auto enforcement_percentage = ParseUInt32Value( envoy_config_cluster_v3_OutlierDetection_enforcing_success_rate( - outlier_detection); - if (enforcing_success_rate != nullptr) { - uint32_t enforcement_percentage = - google_protobuf_UInt32Value_value(enforcing_success_rate); - if (enforcement_percentage > 100) { + outlier_detection)); + if (enforcement_percentage.has_value()) { + if (*enforcement_percentage > 100) { ValidationErrors::ScopedField field(&errors, ".enforcing_success_rate"); errors.AddError("value must be <= 100"); } - if (enforcement_percentage != 0) { + if (*enforcement_percentage != 0) { OutlierDetectionConfig::SuccessRateEjection success_rate_ejection; - success_rate_ejection.enforcement_percentage = enforcement_percentage; - const google_protobuf_UInt32Value* minimum_hosts = + success_rate_ejection.enforcement_percentage = *enforcement_percentage; + auto minimum_hosts = ParseUInt32Value( envoy_config_cluster_v3_OutlierDetection_success_rate_minimum_hosts( - outlier_detection); - if (minimum_hosts != nullptr) { - success_rate_ejection.minimum_hosts = - google_protobuf_UInt32Value_value(minimum_hosts); + outlier_detection)); + if (minimum_hosts.has_value()) { + success_rate_ejection.minimum_hosts = *minimum_hosts; } - const google_protobuf_UInt32Value* request_volume = + auto request_volume = ParseUInt32Value( envoy_config_cluster_v3_OutlierDetection_success_rate_request_volume( - outlier_detection); - if (request_volume != nullptr) { - success_rate_ejection.request_volume = - google_protobuf_UInt32Value_value(request_volume); + outlier_detection)); + if (request_volume.has_value()) { + success_rate_ejection.request_volume = *request_volume; } - const google_protobuf_UInt32Value* stdev_factor = + auto stdev_factor = ParseUInt32Value( envoy_config_cluster_v3_OutlierDetection_success_rate_stdev_factor( - outlier_detection); - if (stdev_factor != nullptr) { - success_rate_ejection.stdev_factor = - google_protobuf_UInt32Value_value(stdev_factor); + outlier_detection)); + if (stdev_factor.has_value()) { + success_rate_ejection.stdev_factor = *stdev_factor; } outlier_detection_update.success_rate_ejection = success_rate_ejection; } } - const google_protobuf_UInt32Value* enforcing_failure_percentage = + enforcement_percentage = ParseUInt32Value( envoy_config_cluster_v3_OutlierDetection_enforcing_failure_percentage( - outlier_detection); - if (enforcing_failure_percentage != nullptr) { - uint32_t enforcement_percentage = - google_protobuf_UInt32Value_value(enforcing_failure_percentage); - if (enforcement_percentage > 100) { + outlier_detection)); + if (enforcement_percentage.has_value()) { + if (*enforcement_percentage > 100) { ValidationErrors::ScopedField field(&errors, ".enforcing_failure_percentage"); errors.AddError("value must be <= 100"); } - if (enforcement_percentage != 0) { + if (*enforcement_percentage != 0) { OutlierDetectionConfig::FailurePercentageEjection failure_percentage_ejection; failure_percentage_ejection.enforcement_percentage = - enforcement_percentage; - const google_protobuf_UInt32Value* minimum_hosts = + *enforcement_percentage; + auto minimum_hosts = ParseUInt32Value( envoy_config_cluster_v3_OutlierDetection_failure_percentage_minimum_hosts( - outlier_detection); - if (minimum_hosts != nullptr) { - failure_percentage_ejection.minimum_hosts = - google_protobuf_UInt32Value_value(minimum_hosts); + outlier_detection)); + if (minimum_hosts.has_value()) { + failure_percentage_ejection.minimum_hosts = *minimum_hosts; } - const google_protobuf_UInt32Value* request_volume = + auto request_volume = ParseUInt32Value( envoy_config_cluster_v3_OutlierDetection_failure_percentage_request_volume( - outlier_detection); - if (request_volume != nullptr) { - failure_percentage_ejection.request_volume = - google_protobuf_UInt32Value_value(request_volume); + outlier_detection)); + if (request_volume.has_value()) { + failure_percentage_ejection.request_volume = *request_volume; } - const google_protobuf_UInt32Value* threshold = + auto threshold = ParseUInt32Value( envoy_config_cluster_v3_OutlierDetection_failure_percentage_threshold( - outlier_detection); - if (threshold != nullptr) { - failure_percentage_ejection.threshold = - google_protobuf_UInt32Value_value(threshold); - if (enforcement_percentage > 100) { + outlier_detection)); + if (threshold.has_value()) { + failure_percentage_ejection.threshold = *threshold; + if (*enforcement_percentage > 100) { ValidationErrors::ScopedField field( &errors, ".failure_percentage_threshold"); errors.AddError("value must be <= 100"); @@ -641,36 +628,11 @@ absl::StatusOr> CdsResourceParse( cds_update->override_host_statuses.Add( XdsHealthStatus(XdsHealthStatus::kHealthy)); } - // Record telemetry labels (if any). - const envoy_config_core_v3_Metadata* metadata = - envoy_config_cluster_v3_Cluster_metadata(cluster); - if (metadata != nullptr) { - google_protobuf_Struct* telemetry_labels_struct; - if (envoy_config_core_v3_Metadata_filter_metadata_get( - metadata, - StdStringToUpbString( - absl::string_view("com.google.csm.telemetry_labels")), - &telemetry_labels_struct)) { - size_t iter = kUpb_Map_Begin; - const google_protobuf_Struct_FieldsEntry* fields_entry; - while ((fields_entry = google_protobuf_Struct_fields_next( - telemetry_labels_struct, &iter)) != nullptr) { - // Adds any entry whose value is a string to telemetry_labels. - const google_protobuf_Value* value = - google_protobuf_Struct_FieldsEntry_value(fields_entry); - if (google_protobuf_Value_has_string_value(value)) { - if (UpbStringToAbsl(google_protobuf_Struct_FieldsEntry_key( - fields_entry)) == "service_name") { - cds_update->service_telemetry_label = RefCountedStringValue( - UpbStringToAbsl(google_protobuf_Value_string_value(value))); - } else if (UpbStringToAbsl(google_protobuf_Struct_FieldsEntry_key( - fields_entry)) == "service_namespace") { - cds_update->namespace_telemetry_label = RefCountedStringValue( - UpbStringToAbsl(google_protobuf_Value_string_value(value))); - } - } - } - } + // Parse metadata. + { + ValidationErrors::ScopedField field(&errors, ".metadata"); + cds_update->metadata = ParseXdsMetadataMap( + context, envoy_config_cluster_v3_Cluster_metadata(cluster), &errors); } // Return result. if (!errors.ok()) { diff --git a/src/core/xds/grpc/xds_cluster_specifier_plugin.cc b/src/core/xds/grpc/xds_cluster_specifier_plugin.cc index 11a707a0d6..8d77160224 100644 --- a/src/core/xds/grpc/xds_cluster_specifier_plugin.cc +++ b/src/core/xds/grpc/xds_cluster_specifier_plugin.cc @@ -30,7 +30,6 @@ #include "upb/mem/arena.hpp" #include -#include #include #include "src/core/util/json/json.h" diff --git a/src/core/xds/grpc/xds_common_types_parser.cc b/src/core/xds/grpc/xds_common_types_parser.cc index 3da948fe50..8b617a6143 100644 --- a/src/core/xds/grpc/xds_common_types_parser.cc +++ b/src/core/xds/grpc/xds_common_types_parser.cc @@ -372,11 +372,9 @@ CommonTlsContext CommonTlsContextParse( } // -// ExtractXdsExtension +// ParseProtobufStructToJson() // -namespace { - absl::StatusOr ParseProtobufStructToJson( const XdsResourceType::DecodeContext& context, const google_protobuf_Struct* resource) { @@ -405,7 +403,9 @@ absl::StatusOr ParseProtobufStructToJson( return std::move(*json); } -} // namespace +// +// ExtractXdsExtension() +// absl::optional ExtractXdsExtension( const XdsResourceType::DecodeContext& context, diff --git a/src/core/xds/grpc/xds_common_types_parser.h b/src/core/xds/grpc/xds_common_types_parser.h index 880e50b7de..4d14539416 100644 --- a/src/core/xds/grpc/xds_common_types_parser.h +++ b/src/core/xds/grpc/xds_common_types_parser.h @@ -21,6 +21,7 @@ #include "envoy/extensions/transport_sockets/tls/v3/tls.upb.h" #include "google/protobuf/any.upb.h" #include "google/protobuf/duration.upb.h" +#include "google/protobuf/struct.upb.h" #include "google/protobuf/wrappers.upb.h" #include "src/core/lib/gprpp/time.h" @@ -39,12 +40,28 @@ inline bool ParseBoolValue(const google_protobuf_BoolValue* bool_value_proto, return google_protobuf_BoolValue_value(bool_value_proto); } +inline absl::optional ParseUInt64Value( + const google_protobuf_UInt64Value* proto) { + if (proto == nullptr) return absl::nullopt; + return google_protobuf_UInt64Value_value(proto); +} + +inline absl::optional ParseUInt32Value( + const google_protobuf_UInt32Value* proto) { + if (proto == nullptr) return absl::nullopt; + return google_protobuf_UInt32Value_value(proto); +} + CommonTlsContext CommonTlsContextParse( const XdsResourceType::DecodeContext& context, const envoy_extensions_transport_sockets_tls_v3_CommonTlsContext* common_tls_context_proto, ValidationErrors* errors); +absl::StatusOr ParseProtobufStructToJson( + const XdsResourceType::DecodeContext& context, + const google_protobuf_Struct* resource); + absl::optional ExtractXdsExtension( const XdsResourceType::DecodeContext& context, const google_protobuf_Any* any, ValidationErrors* errors); diff --git a/src/core/xds/grpc/xds_endpoint_parser.cc b/src/core/xds/grpc/xds_endpoint_parser.cc index 89a42ab9ce..011a739c4a 100644 --- a/src/core/xds/grpc/xds_endpoint_parser.cc +++ b/src/core/xds/grpc/xds_endpoint_parser.cc @@ -52,6 +52,7 @@ #include "src/core/lib/iomgr/resolved_address.h" #include "src/core/util/string.h" #include "src/core/util/upb_utils.h" +#include "src/core/xds/grpc/xds_common_types_parser.h" #include "src/core/xds/grpc/xds_health_status.h" #include "src/core/xds/xds_client/xds_resource_type.h" @@ -61,10 +62,10 @@ namespace grpc_core { namespace { -// TODO(roth): Remove this once dualstack support is stable. +// TODO(roth): Remove this after 1.67 is released. bool XdsDualstackEndpointsEnabled() { auto value = GetEnv("GRPC_EXPERIMENTAL_XDS_DUALSTACK_ENDPOINTS"); - if (!value.has_value()) return false; + if (!value.has_value()) return true; bool parsed_value; bool parse_succeeded = gpr_parse_bool_value(value->c_str(), &parsed_value); return parse_succeeded && parsed_value; @@ -126,16 +127,15 @@ absl::optional EndpointAddressesParse( auto status = XdsHealthStatus::FromUpb(health_status); if (!status.has_value()) return absl::nullopt; // load_balancing_weight - uint32_t weight = 1; + uint32_t weight; { ValidationErrors::ScopedField field(errors, ".load_balancing_weight"); - const google_protobuf_UInt32Value* load_balancing_weight = - envoy_config_endpoint_v3_LbEndpoint_load_balancing_weight(lb_endpoint); - if (load_balancing_weight != nullptr) { - weight = google_protobuf_UInt32Value_value(load_balancing_weight); - if (weight == 0) { - errors->AddError("must be greater than 0"); - } + weight = ParseUInt32Value( + envoy_config_endpoint_v3_LbEndpoint_load_balancing_weight( + lb_endpoint)) + .value_or(1); + if (weight == 0) { + errors->AddError("must be greater than 0"); } } // endpoint @@ -207,11 +207,11 @@ absl::optional LocalityParse( // load_balancing_weight // If LB weight is not specified or 0, it means this locality is assigned // no load. - const google_protobuf_UInt32Value* lb_weight = - envoy_config_endpoint_v3_LocalityLbEndpoints_load_balancing_weight( - locality_lb_endpoints); parsed_locality.locality.lb_weight = - lb_weight != nullptr ? google_protobuf_UInt32Value_value(lb_weight) : 0; + ParseUInt32Value( + envoy_config_endpoint_v3_LocalityLbEndpoints_load_balancing_weight( + locality_lb_endpoints)) + .value_or(0); if (parsed_locality.locality.lb_weight == 0) return absl::nullopt; // locality const envoy_config_core_v3_Locality* locality = diff --git a/src/core/xds/grpc/xds_http_fault_filter.cc b/src/core/xds/grpc/xds_http_fault_filter.cc index 846a4b490d..e46eeb79f1 100644 --- a/src/core/xds/grpc/xds_http_fault_filter.cc +++ b/src/core/xds/grpc/xds_http_fault_filter.cc @@ -195,12 +195,12 @@ XdsHttpFaultFilter::GenerateFilterConfig( } } // Section 3: Parse the maximum active faults - const auto* max_fault_wrapper = + auto max_fault_wrapper = ParseUInt32Value( envoy_extensions_filters_http_fault_v3_HTTPFault_max_active_faults( - http_fault); - if (max_fault_wrapper != nullptr) { + http_fault)); + if (max_fault_wrapper.has_value()) { fault_injection_policy_json["maxFaults"] = - Json::FromNumber(google_protobuf_UInt32Value_value(max_fault_wrapper)); + Json::FromNumber(*max_fault_wrapper); } return FilterConfig{ConfigProtoName(), Json::FromObject(std::move(fault_injection_policy_json))}; diff --git a/src/core/xds/grpc/xds_http_filter_registry.cc b/src/core/xds/grpc/xds_http_filter_registry.cc index c0ed05e7db..9a6f18e226 100644 --- a/src/core/xds/grpc/xds_http_filter_registry.cc +++ b/src/core/xds/grpc/xds_http_filter_registry.cc @@ -25,7 +25,6 @@ #include "envoy/extensions/filters/http/router/v3/router.upb.h" #include "envoy/extensions/filters/http/router/v3/router.upbdefs.h" -#include #include #include "src/core/util/json/json.h" diff --git a/src/core/xds/grpc/xds_http_rbac_filter.cc b/src/core/xds/grpc/xds_http_rbac_filter.cc index 3fadf5d2eb..64a793abad 100644 --- a/src/core/xds/grpc/xds_http_rbac_filter.cc +++ b/src/core/xds/grpc/xds_http_rbac_filter.cc @@ -53,6 +53,7 @@ #include "src/core/util/upb_utils.h" #include "src/core/xds/grpc/xds_audit_logger_registry.h" #include "src/core/xds/grpc/xds_bootstrap_grpc.h" +#include "src/core/xds/grpc/xds_common_types_parser.h" #include "src/core/xds/xds_client/xds_client.h" namespace grpc_core { @@ -190,11 +191,10 @@ Json ParseCidrRangeToJson(const envoy_config_core_v3_CidrRange* range) { json.emplace("addressPrefix", Json::FromString(UpbStringToStdString( envoy_config_core_v3_CidrRange_address_prefix(range)))); - const auto* prefix_len = envoy_config_core_v3_CidrRange_prefix_len(range); - if (prefix_len != nullptr) { - json.emplace( - "prefixLen", - Json::FromNumber(google_protobuf_UInt32Value_value(prefix_len))); + auto prefix_len = + ParseUInt32Value(envoy_config_core_v3_CidrRange_prefix_len(range)); + if (prefix_len.has_value()) { + json.emplace("prefixLen", Json::FromNumber(*prefix_len)); } return Json::FromObject(std::move(json)); } diff --git a/src/core/xds/grpc/xds_lb_policy_registry.cc b/src/core/xds/grpc/xds_lb_policy_registry.cc index 6aa25a9b69..67b9805827 100644 --- a/src/core/xds/grpc/xds_lb_policy_registry.cc +++ b/src/core/xds/grpc/xds_lb_policy_registry.cc @@ -173,23 +173,21 @@ class RingHashLbPolicyConfigFactory final ValidationErrors::ScopedField field(errors, ".hash_function"); errors->AddError("unsupported value (must be XX_HASH)"); } - uint64_t max_ring_size = 8388608; - const auto* uint64_value = - envoy_extensions_load_balancing_policies_ring_hash_v3_RingHash_maximum_ring_size( - resource); - if (uint64_value != nullptr) { - max_ring_size = google_protobuf_UInt64Value_value(uint64_value); - if (max_ring_size == 0 || max_ring_size > 8388608) { - ValidationErrors::ScopedField field(errors, ".maximum_ring_size"); - errors->AddError("value must be in the range [1, 8388608]"); - } + uint64_t max_ring_size = + ParseUInt64Value( + envoy_extensions_load_balancing_policies_ring_hash_v3_RingHash_maximum_ring_size( + resource)) + .value_or(8388608); + if (max_ring_size == 0 || max_ring_size > 8388608) { + ValidationErrors::ScopedField field(errors, ".maximum_ring_size"); + errors->AddError("value must be in the range [1, 8388608]"); } - uint64_t min_ring_size = 1024; - uint64_value = - envoy_extensions_load_balancing_policies_ring_hash_v3_RingHash_minimum_ring_size( - resource); - if (uint64_value != nullptr) { - min_ring_size = google_protobuf_UInt64Value_value(uint64_value); + uint64_t min_ring_size = + ParseUInt64Value( + envoy_extensions_load_balancing_policies_ring_hash_v3_RingHash_minimum_ring_size( + resource)) + .value_or(1024); + { ValidationErrors::ScopedField field(errors, ".minimum_ring_size"); if (min_ring_size == 0 || min_ring_size > 8388608) { errors->AddError("value must be in the range [1, 8388608]"); diff --git a/src/core/xds/grpc/xds_listener_parser.cc b/src/core/xds/grpc/xds_listener_parser.cc index 1c8ef65c5c..b536472a80 100644 --- a/src/core/xds/grpc/xds_listener_parser.cc +++ b/src/core/xds/grpc/xds_listener_parser.cc @@ -478,11 +478,11 @@ absl::optional CidrRangeParse( } cidr_range.address = *address; cidr_range.prefix_len = 0; - auto* prefix_len_proto = - envoy_config_core_v3_CidrRange_prefix_len(cidr_range_proto); - if (prefix_len_proto != nullptr) { + auto value = ParseUInt32Value( + envoy_config_core_v3_CidrRange_prefix_len(cidr_range_proto)); + if (value.has_value()) { cidr_range.prefix_len = std::min( - google_protobuf_UInt32Value_value(prefix_len_proto), + *value, (reinterpret_cast(cidr_range.address.addr)) ->sa_family == GRPC_AF_INET ? uint32_t{32} @@ -499,12 +499,11 @@ absl::optional FilterChainMatchParse( FilterChain::FilterChainMatch filter_chain_match; const size_t original_error_size = errors->size(); // destination_port - auto* destination_port = + auto destination_port = ParseUInt32Value( envoy_config_listener_v3_FilterChainMatch_destination_port( - filter_chain_match_proto); - if (destination_port != nullptr) { - filter_chain_match.destination_port = - google_protobuf_UInt32Value_value(destination_port); + filter_chain_match_proto)); + if (destination_port.has_value()) { + filter_chain_match.destination_port = *destination_port; } // prefix_ranges size_t size = 0; diff --git a/src/core/xds/grpc/xds_metadata.cc b/src/core/xds/grpc/xds_metadata.cc new file mode 100644 index 0000000000..b14ad78896 --- /dev/null +++ b/src/core/xds/grpc/xds_metadata.cc @@ -0,0 +1,62 @@ +// +// 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/xds/grpc/xds_metadata.h" + +#include +#include +#include +#include + +#include "absl/log/check.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/str_join.h" +#include "absl/strings/string_view.h" + +namespace grpc_core { + +void XdsMetadataMap::Insert(absl::string_view key, + std::unique_ptr value) { + CHECK(value != nullptr); + CHECK(map_.emplace(key, std::move(value)).second) << "duplicate key: " << key; +} + +const XdsMetadataValue* XdsMetadataMap::Find(absl::string_view key) const { + auto it = map_.find(key); + if (it == map_.end()) return nullptr; + return it->second.get(); +} + +bool XdsMetadataMap::operator==(const XdsMetadataMap& other) const { + if (map_.size() != other.map_.size()) return false; + for (const auto& p : map_) { + auto it = other.map_.find(p.first); + if (it == other.map_.end()) return false; + if (*p.second != *it->second) return false; + } + return true; +} + +std::string XdsMetadataMap::ToString() const { + std::vector entries; + for (const auto& p : map_) { + entries.push_back(absl::StrCat(p.first, "=", p.second->ToString())); + } + std::sort(entries.begin(), entries.end()); + return absl::StrCat("{", absl::StrJoin(entries, ", "), "}"); +} + +} // namespace grpc_core diff --git a/src/core/xds/grpc/xds_metadata.h b/src/core/xds/grpc/xds_metadata.h new file mode 100644 index 0000000000..4e784d90d2 --- /dev/null +++ b/src/core/xds/grpc/xds_metadata.h @@ -0,0 +1,127 @@ +// +// 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_XDS_GRPC_XDS_METADATA_H +#define GRPC_SRC_CORE_XDS_GRPC_XDS_METADATA_H + +#include +#include +#include + +#include "absl/container/flat_hash_map.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" + +#include "src/core/lib/gprpp/down_cast.h" +#include "src/core/lib/gprpp/validation_errors.h" +#include "src/core/util/json/json.h" +#include "src/core/util/json/json_writer.h" + +namespace grpc_core { + +// Interface for metadata value types. +class XdsMetadataValue { + public: + virtual ~XdsMetadataValue() = default; + + // The proto message name. + virtual absl::string_view type() const = 0; + + bool operator==(const XdsMetadataValue& other) const { + return type() == other.type() && Equals(other); + } + bool operator!=(const XdsMetadataValue& other) const { + return !(*this == other); + } + + virtual std::string ToString() const = 0; + + private: + // Called only if the type() methods return the same thing. + virtual bool Equals(const XdsMetadataValue& other) const = 0; +}; + +// Metadata map. +class XdsMetadataMap { + public: + void Insert(absl::string_view key, std::unique_ptr value); + + const XdsMetadataValue* Find(absl::string_view key) const; + + bool empty() const { return map_.empty(); } + size_t size() const { return map_.size(); } + + bool operator==(const XdsMetadataMap& other) const; + + std::string ToString() const; + + private: + absl::flat_hash_map> map_; +}; + +// Concrete metadata value type for google.protobuf.Struct. +class XdsStructMetadataValue : public XdsMetadataValue { + public: + explicit XdsStructMetadataValue(Json json) : json_(std::move(json)) {} + + static absl::string_view Type() { return "google.protobuf.Struct"; } + + absl::string_view type() const override { return Type(); } + + const Json& json() const { return json_; } + + std::string ToString() const override { + return absl::StrCat(type(), "{", JsonDump(json_), "}"); + } + + private: + bool Equals(const XdsMetadataValue& other) const override { + return json_ == DownCast(other).json_; + } + + Json json_; +}; + +// Concrete metadata value type for GCP Authn filter Audience. +class XdsGcpAuthnAudienceMetadataValue : public XdsMetadataValue { + public: + explicit XdsGcpAuthnAudienceMetadataValue(absl::string_view url) + : url_(url) {} + + static absl::string_view Type() { + return "envoy.extensions.filters.http.gcp_authn.v3.Audience"; + } + + absl::string_view type() const override { return Type(); } + + const std::string& url() const { return url_; } + + std::string ToString() const override { + return absl::StrCat(type(), "{url=\"", url_, "\"}"); + } + + private: + bool Equals(const XdsMetadataValue& other) const override { + return url_ == + DownCast(other).url_; + } + + std::string url_; +}; + +} // namespace grpc_core + +#endif // GRPC_SRC_CORE_XDS_GRPC_XDS_METADATA_H diff --git a/src/core/xds/grpc/xds_metadata_parser.cc b/src/core/xds/grpc/xds_metadata_parser.cc new file mode 100644 index 0000000000..90f11a79ca --- /dev/null +++ b/src/core/xds/grpc/xds_metadata_parser.cc @@ -0,0 +1,143 @@ +// Copyright 2018 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/xds/grpc/xds_metadata_parser.h" + +#include +#include + +#include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" +#include "absl/types/variant.h" +#include "envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb.h" +#include "envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.h" +#include "upb/base/string_view.h" +#include "upb/text/encode.h" + +#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gprpp/validation_errors.h" +#include "src/core/util/string.h" +#include "src/core/util/upb_utils.h" +#include "src/core/xds/grpc/xds_common_types.h" +#include "src/core/xds/grpc/xds_common_types_parser.h" + +namespace grpc_core { + +// TODO(roth): Remove this once GCP auth filter support is stable. +bool XdsGcpAuthFilterEnabled() { + auto value = GetEnv("GRPC_EXPERIMENTAL_XDS_GCP_AUTHENTICATION_FILTER"); + if (!value.has_value()) return false; + bool parsed_value; + bool parse_succeeded = gpr_parse_bool_value(value->c_str(), &parsed_value); + return parse_succeeded && parsed_value; +} + +namespace { + +std::unique_ptr ParseGcpAuthnAudience( + const XdsResourceType::DecodeContext& context, XdsExtension extension, + ValidationErrors* errors) { + absl::string_view* serialized_proto = + absl::get_if(&extension.value); + if (serialized_proto == nullptr) { + errors->AddError("could not parse audience metadata"); + return nullptr; + } + auto* proto = envoy_extensions_filters_http_gcp_authn_v3_Audience_parse( + serialized_proto->data(), serialized_proto->size(), context.arena); + if (proto == nullptr) { + errors->AddError("could not parse audience metadata"); + return nullptr; + } + if (GRPC_TRACE_FLAG_ENABLED_OBJ(*context.tracer) && ABSL_VLOG_IS_ON(2)) { + const upb_MessageDef* msg_type = + envoy_extensions_filters_http_gcp_authn_v3_Audience_getmsgdef( + context.symtab); + char buf[10240]; + upb_TextEncode(reinterpret_cast(proto), msg_type, + nullptr, 0, buf, sizeof(buf)); + VLOG(2) << "[xds_client " << context.client + << "] cluster metadata Audience: " << buf; + } + absl::string_view url = UpbStringToAbsl( + envoy_extensions_filters_http_gcp_authn_v3_Audience_url(proto)); + if (url.empty()) { + ValidationErrors::ScopedField field(errors, ".url"); + errors->AddError("must be non-empty"); + return nullptr; + } + return std::make_unique(url); +} + +} // namespace + +XdsMetadataMap ParseXdsMetadataMap( + const XdsResourceType::DecodeContext& context, + const envoy_config_core_v3_Metadata* metadata, ValidationErrors* errors) { + XdsMetadataMap metadata_map; + if (metadata == nullptr) return metadata_map; // Not present == empty. + // First, try typed_filter_metadata. + size_t iter = kUpb_Map_Begin; + const envoy_config_core_v3_Metadata_TypedFilterMetadataEntry* typed_entry; + while ( + (typed_entry = envoy_config_core_v3_Metadata_typed_filter_metadata_next( + metadata, &iter)) != nullptr) { + absl::string_view key = UpbStringToAbsl( + envoy_config_core_v3_Metadata_TypedFilterMetadataEntry_key( + typed_entry)); + ValidationErrors::ScopedField field( + errors, absl::StrCat(".typed_filter_metadata[", key, "]")); + auto extension = ExtractXdsExtension( + context, + envoy_config_core_v3_Metadata_TypedFilterMetadataEntry_value( + typed_entry), + errors); + if (!extension.has_value()) continue; + // TODO(roth): If we ever need to support another type here, refactor + // this into a separate registry. + if (XdsGcpAuthFilterEnabled() && + extension->type == XdsGcpAuthnAudienceMetadataValue::Type()) { + auto metadata_value = + ParseGcpAuthnAudience(context, std::move(*extension), errors); + if (metadata_value != nullptr) { + metadata_map.Insert(key, std::move(metadata_value)); + } + } + } + // Then, try filter_metadata. + iter = kUpb_Map_Begin; + const envoy_config_core_v3_Metadata_FilterMetadataEntry* entry; + while ((entry = envoy_config_core_v3_Metadata_filter_metadata_next( + metadata, &iter)) != nullptr) { + absl::string_view key = UpbStringToAbsl( + envoy_config_core_v3_Metadata_FilterMetadataEntry_key(entry)); + auto json = ParseProtobufStructToJson( + context, + envoy_config_core_v3_Metadata_FilterMetadataEntry_value(entry)); + if (!json.ok()) { + ValidationErrors::ScopedField field( + errors, absl::StrCat(".filter_metadata[", key, "]")); + errors->AddError(json.status().message()); + } + // Add only if not already added from typed_filter_metadata. + else if (metadata_map.Find(key) == nullptr) { + metadata_map.Insert( + key, std::make_unique(std::move(*json))); + } + } + return metadata_map; +} + +} // namespace grpc_core diff --git a/src/core/xds/grpc/xds_metadata_parser.h b/src/core/xds/grpc/xds_metadata_parser.h new file mode 100644 index 0000000000..f3d0a522ab --- /dev/null +++ b/src/core/xds/grpc/xds_metadata_parser.h @@ -0,0 +1,36 @@ +// +// 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_XDS_GRPC_XDS_METADATA_PARSER_H +#define GRPC_SRC_CORE_XDS_GRPC_XDS_METADATA_PARSER_H + +#include "envoy/config/core/v3/base.upb.h" + +#include "src/core/lib/gprpp/validation_errors.h" +#include "src/core/xds/grpc/xds_metadata.h" +#include "src/core/xds/xds_client/xds_resource_type.h" + +namespace grpc_core { + +bool XdsGcpAuthFilterEnabled(); + +XdsMetadataMap ParseXdsMetadataMap( + const XdsResourceType::DecodeContext& context, + const envoy_config_core_v3_Metadata* metadata, ValidationErrors* errors); + +} // namespace grpc_core + +#endif // GRPC_SRC_CORE_XDS_GRPC_XDS_METADATA_PARSER_H diff --git a/src/core/xds/grpc/xds_route_config_parser.cc b/src/core/xds/grpc/xds_route_config_parser.cc index 45096c5b99..d6ac0f858a 100644 --- a/src/core/xds/grpc/xds_route_config_parser.cc +++ b/src/core/xds/grpc/xds_route_config_parser.cc @@ -474,18 +474,13 @@ XdsRouteConfigResource::RetryPolicy RetryPolicyParse( } } } - const google_protobuf_UInt32Value* num_retries = - envoy_config_route_v3_RetryPolicy_num_retries(retry_policy_proto); - if (num_retries != nullptr) { - uint32_t num_retries_value = google_protobuf_UInt32Value_value(num_retries); - if (num_retries_value == 0) { - ValidationErrors::ScopedField field(errors, ".num_retries"); - errors->AddError("must be greater than 0"); - } else { - retry_policy.num_retries = num_retries_value; - } - } else { - retry_policy.num_retries = 1; + retry_policy.num_retries = + ParseUInt32Value( + envoy_config_route_v3_RetryPolicy_num_retries(retry_policy_proto)) + .value_or(1); + if (retry_policy.num_retries == 0) { + ValidationErrors::ScopedField field(errors, ".num_retries"); + errors->AddError("must be greater than 0"); } const envoy_config_route_v3_RetryPolicy_RetryBackOff* backoff = envoy_config_route_v3_RetryPolicy_retry_back_off(retry_policy_proto); @@ -692,14 +687,14 @@ absl::optional RouteActionParse( errors->AddError("must be non-empty"); } // weight - const google_protobuf_UInt32Value* weight_proto = + auto weight = ParseUInt32Value( envoy_config_route_v3_WeightedCluster_ClusterWeight_weight( - cluster_proto); - if (weight_proto == nullptr) { + cluster_proto)); + if (!weight.has_value()) { ValidationErrors::ScopedField field(errors, ".weight"); errors->AddError("field not present"); } else { - cluster.weight = google_protobuf_UInt32Value_value(weight_proto); + cluster.weight = *weight; if (cluster.weight == 0) continue; total_weight += cluster.weight; } diff --git a/src/core/xds/grpc/xds_routing.cc b/src/core/xds/grpc/xds_routing.cc index 1cedfd603d..83c9d620e4 100644 --- a/src/core/xds/grpc/xds_routing.cc +++ b/src/core/xds/grpc/xds_routing.cc @@ -31,7 +31,6 @@ #include "absl/strings/match.h" #include "absl/strings/str_cat.h" -#include #include #include "src/core/lib/channel/channel_args.h" diff --git a/src/core/xds/grpc/xds_transport_grpc.cc b/src/core/xds/grpc/xds_transport_grpc.cc index f2759b251a..6af60f0516 100644 --- a/src/core/xds/grpc/xds_transport_grpc.cc +++ b/src/core/xds/grpc/xds_transport_grpc.cc @@ -34,7 +34,6 @@ #include #include #include -#include #include #include "src/core/client_channel/client_channel_filter.h" diff --git a/src/core/xds/xds_client/xds_client.cc b/src/core/xds/xds_client/xds_client.cc index 8a9456cdad..7c4cef0dd1 100644 --- a/src/core/xds/xds_client/xds_client.cc +++ b/src/core/xds/xds_client/xds_client.cc @@ -250,16 +250,14 @@ class XdsClient::XdsChannel::AdsCall final } void OnTimer() { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << ads_call_->xds_client() - << "] xds server " - << ads_call_->xds_channel()->server_.server_uri() - << ": timeout obtaining resource {type=" << type_->type_url() - << " name=" - << XdsClient::ConstructFullXdsResourceName( - name_.authority, type_->type_url(), name_.key) - << "} from xds server"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << ads_call_->xds_client() << "] xds server " + << ads_call_->xds_channel()->server_.server_uri() + << ": timeout obtaining resource {type=" << type_->type_url() + << " name=" + << XdsClient::ConstructFullXdsResourceName( + name_.authority, type_->type_url(), name_.key) + << "} from xds server"; { MutexLock lock(&ads_call_->xds_client()->mu_); timer_handle_.reset(); @@ -457,10 +455,9 @@ XdsClient::XdsChannel::XdsChannel(WeakRefCountedPtr xds_client, : nullptr), xds_client_(std::move(xds_client)), server_(server) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client_.get() << "] creating channel " - << this << " for server " << server.server_uri(); - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client_.get() << "] creating channel " << this + << " for server " << server.server_uri(); absl::Status status; transport_ = xds_client_->transport_factory_->Create( server, @@ -474,10 +471,9 @@ XdsClient::XdsChannel::XdsChannel(WeakRefCountedPtr xds_client, } XdsClient::XdsChannel::~XdsChannel() { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client() << "] destroying xds channel " - << this << " for server " << server_.server_uri(); - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client() << "] destroying xds channel " << this + << " for server " << server_.server_uri(); xds_client_.reset(DEBUG_LOCATION, "XdsChannel"); } @@ -486,10 +482,9 @@ XdsClient::XdsChannel::~XdsChannel() { // called from DualRefCounted::Unref, which cannot have a lock annotation for // a lock in this subclass. void XdsClient::XdsChannel::Orphaned() ABSL_NO_THREAD_SAFETY_ANALYSIS { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client() << "] orphaning xds channel " - << this << " for server " << server_.server_uri(); - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client() << "] orphaning xds channel " << this + << " for server " << server_.server_uri(); shutting_down_ = true; transport_.reset(); // At this time, all strong refs are removed, remove from channel map to @@ -574,19 +569,15 @@ bool XdsClient::XdsChannel::MaybeFallbackLocked( type_resource.first, {authority, key_state.first}); } } - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client_.get() << "] authority " - << authority << ": added fallback server " - << xds_servers[i]->server_uri() << " (" - << authority_state.xds_channels.back()->status().ToString() - << ")"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client_.get() << "] authority " << authority + << ": added fallback server " << xds_servers[i]->server_uri() << " (" + << authority_state.xds_channels.back()->status().ToString() << ")"; if (authority_state.xds_channels.back()->status().ok()) return true; } - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client_.get() << "] authority " - << authority << ": No fallback server"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client_.get() << "] authority " << authority + << ": No fallback server"; return false; } @@ -603,11 +594,9 @@ void XdsClient::XdsChannel::SetHealthyLocked() { auto channel_it = std::find(channels.begin(), channels.end(), this); // Skip if this is not on the list if (channel_it != channels.end()) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client_.get() << "] authority " - << authority.first << ": Falling forward to " - << server_.server_uri(); - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client_.get() << "] authority " + << authority.first << ": Falling forward to " << server_.server_uri(); // Lower priority channels are no longer needed, connection is back! channels.erase(channel_it + 1, channels.end()); } @@ -715,11 +704,10 @@ void XdsClient::XdsChannel::RetryableCall::StartNewCallLocked() { if (shutting_down_) return; CHECK(xds_channel_->transport_ != nullptr); CHECK(call_ == nullptr); - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_channel()->xds_client() - << "] xds server " << xds_channel()->server_.server_uri() - << ": start new call from retryable call " << this; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_channel()->xds_client() << "] xds server " + << xds_channel()->server_.server_uri() + << ": start new call from retryable call " << this; call_ = MakeOrphanable( this->Ref(DEBUG_LOCATION, "RetryableCall+start_new_call")); } @@ -730,12 +718,11 @@ void XdsClient::XdsChannel::RetryableCall::StartRetryTimerLocked() { const Timestamp next_attempt_time = backoff_.NextAttemptTime(); const Duration timeout = std::max(next_attempt_time - Timestamp::Now(), Duration::Zero()); - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_channel()->xds_client() - << "] xds server " << xds_channel()->server_.server_uri() - << ": call attempt failed; retry timer will fire in " - << timeout.millis() << "ms."; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_channel()->xds_client() << "] xds server " + << xds_channel()->server_.server_uri() + << ": call attempt failed; retry timer will fire in " << timeout.millis() + << "ms."; timer_handle_ = xds_channel()->xds_client()->engine()->RunAfter( timeout, [self = this->Ref(DEBUG_LOCATION, "RetryableCall+retry_timer_start")]() { @@ -751,11 +738,10 @@ void XdsClient::XdsChannel::RetryableCall::OnRetryTimer() { if (timer_handle_.has_value()) { timer_handle_.reset(); if (shutting_down_) return; - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_channel()->xds_client() - << "] xds server " << xds_channel()->server_.server_uri() - << ": retry timer fired (retryable call: " << this << ")"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_channel()->xds_client() << "] xds server " + << xds_channel()->server_.server_uri() + << ": retry timer fired (retryable call: " << this << ")"; StartNewCallLocked(); } } @@ -787,13 +773,12 @@ class XdsClient::XdsChannel::AdsCall::AdsReadDelayHandle final absl::Status XdsClient::XdsChannel::AdsCall::AdsResponseParser::ProcessAdsResponseFields( AdsResponseFields fields) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << ads_call_->xds_client() << "] xds server " - << ads_call_->xds_channel()->server_.server_uri() - << ": received ADS response: type_url=" << fields.type_url - << ", version=" << fields.version << ", nonce=" << fields.nonce - << ", num_resources=" << fields.num_resources; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << ads_call_->xds_client() << "] xds server " + << ads_call_->xds_channel()->server_.server_uri() + << ": received ADS response: type_url=" << fields.type_url + << ", version=" << fields.version << ", nonce=" << fields.nonce + << ", num_resources=" << fields.num_resources; result_.type = ads_call_->xds_client()->GetResourceTypeLocked(fields.type_url); if (result_.type == nullptr) { @@ -949,11 +934,9 @@ void XdsClient::XdsChannel::AdsCall::AdsResponseParser::ParseResource( if (resource_state.resource != nullptr && result_.type->ResourcesEqual(resource_state.resource.get(), decode_result.resource->get())) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client() << "] " << result_.type_url - << " resource " << resource_name - << " identical to current, ignoring."; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client() << "] " << result_.type_url + << " resource " << resource_name << " identical to current, ignoring."; return; } // Update the resource state. @@ -1001,12 +984,11 @@ XdsClient::XdsChannel::AdsCall::AdsCall( RefCountedPtr(this))); CHECK(streaming_call_ != nullptr); // Start the call. - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client() << "] xds server " - << xds_channel()->server_.server_uri() - << ": starting ADS call (ads_call: " << this - << ", streaming_call: " << streaming_call_.get() << ")"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client() << "] xds server " + << xds_channel()->server_.server_uri() + << ": starting ADS call (ads_call: " << this + << ", streaming_call: " << streaming_call_.get() << ")"; // If this is a reconnect, add any necessary subscriptions from what's // already in the cache. for (auto& a : xds_client()->authority_state_map_) { @@ -1054,13 +1036,12 @@ void XdsClient::XdsChannel::AdsCall::SendMessageLocked( state.nonce, ResourceNamesForRequest(type), state.status, !sent_initial_message_); sent_initial_message_ = true; - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client() << "] xds server " - << xds_channel()->server_.server_uri() - << ": sending ADS request: type=" << type->type_url() - << " version=" << xds_channel()->resource_type_version_map_[type] - << " nonce=" << state.nonce << " error=" << state.status; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client() << "] xds server " + << xds_channel()->server_.server_uri() + << ": sending ADS request: type=" << type->type_url() + << " version=" << xds_channel()->resource_type_version_map_[type] + << " nonce=" << state.nonce << " error=" << state.status; state.status = absl::OkStatus(); streaming_call_->SendMessage(std::move(serialized_message)); send_message_pending_ = type; @@ -1238,14 +1219,12 @@ void XdsClient::XdsChannel::AdsCall::OnRecvMessage(absl::string_view payload) { void XdsClient::XdsChannel::AdsCall::OnStatusReceived(absl::Status status) { { MutexLock lock(&xds_client()->mu_); - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client() << "] xds server " - << xds_channel()->server_.server_uri() - << ": ADS call status received (xds_channel=" << xds_channel() - << ", ads_call=" << this - << ", streaming_call=" << streaming_call_.get() - << "): " << status; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client() << "] xds server " + << xds_channel()->server_.server_uri() + << ": ADS call status received (xds_channel=" << xds_channel() + << ", ads_call=" << this << ", streaming_call=" << streaming_call_.get() + << "): " << status; // Cancel any does-not-exist timers that may be pending. for (const auto& p : state_map_) { for (const auto& q : p.second.subscribed_resources) { @@ -1311,12 +1290,11 @@ void XdsClient::XdsChannel::LrsCall::Timer::Orphan() { } void XdsClient::XdsChannel::LrsCall::Timer::ScheduleNextReportLocked() { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client() << "] xds server " - << lrs_call_->xds_channel()->server_.server_uri() - << ": scheduling next load report in " - << lrs_call_->load_reporting_interval_; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client() << "] xds server " + << lrs_call_->xds_channel()->server_.server_uri() + << ": scheduling next load report in " + << lrs_call_->load_reporting_interval_; timer_handle_ = xds_client()->engine()->RunAfter( lrs_call_->load_reporting_interval_, [self = Ref(DEBUG_LOCATION, "timer")]() { @@ -1354,12 +1332,11 @@ XdsClient::XdsChannel::LrsCall::LrsCall( RefCountedPtr(this))); CHECK(streaming_call_ != nullptr); // Start the call. - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client() << "] xds server " - << xds_channel()->server_.server_uri() - << ": starting LRS call (lrs_call=" << this - << ", streaming_call=" << streaming_call_.get() << ")"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client() << "] xds server " + << xds_channel()->server_.server_uri() + << ": starting LRS call (lrs_call=" << this + << ", streaming_call=" << streaming_call_.get() << ")"; // Send the initial request. std::string serialized_payload = xds_client()->api_.CreateLrsInitialRequest(); SendMessageLocked(std::move(serialized_payload)); @@ -1483,22 +1460,20 @@ void XdsClient::XdsChannel::LrsCall::OnRecvMessage(absl::string_view payload) { Duration::Milliseconds(GRPC_XDS_MIN_CLIENT_LOAD_REPORTING_INTERVAL_MS)) { new_load_reporting_interval = Duration::Milliseconds(GRPC_XDS_MIN_CLIENT_LOAD_REPORTING_INTERVAL_MS); - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client() << "] xds server " - << xds_channel()->server_.server_uri() - << ": increased load_report_interval to minimum value " - << GRPC_XDS_MIN_CLIENT_LOAD_REPORTING_INTERVAL_MS << "ms"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client() << "] xds server " + << xds_channel()->server_.server_uri() + << ": increased load_report_interval to minimum value " + << GRPC_XDS_MIN_CLIENT_LOAD_REPORTING_INTERVAL_MS << "ms"; } // Ignore identical update. if (send_all_clusters == send_all_clusters_ && cluster_names_ == new_cluster_names && load_reporting_interval_ == new_load_reporting_interval) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client() << "] xds server " - << xds_channel()->server_.server_uri() - << ": incoming LRS response identical to current, ignoring."; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client() << "] xds server " + << xds_channel()->server_.server_uri() + << ": incoming LRS response identical to current, ignoring."; return; } // If the interval has changed, we'll need to restart the timer below. @@ -1517,14 +1492,12 @@ void XdsClient::XdsChannel::LrsCall::OnRecvMessage(absl::string_view payload) { void XdsClient::XdsChannel::LrsCall::OnStatusReceived(absl::Status status) { MutexLock lock(&xds_client()->mu_); - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client() << "] xds server " - << xds_channel()->server_.server_uri() - << ": LRS call status received (xds_channel=" << xds_channel() - << ", lrs_call=" << this - << ", streaming_call=" << streaming_call_.get() - << "): " << status; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client() << "] xds server " + << xds_channel()->server_.server_uri() + << ": LRS call status received (xds_channel=" << xds_channel() + << ", lrs_call=" << this << ", streaming_call=" << streaming_call_.get() + << "): " << status; // Ignore status from a stale call. if (IsCurrentCallOnChannel()) { // Try to restart the call. @@ -1563,26 +1536,24 @@ XdsClient::XdsClient( work_serializer_(engine), engine_(std::move(engine)), metrics_reporter_(std::move(metrics_reporter)) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << this << "] creating xds client"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << this << "] creating xds client"; CHECK(bootstrap_ != nullptr); if (bootstrap_->node() != nullptr) { - LOG(INFO) << "[xds_client " << this - << "] xDS node ID: " << bootstrap_->node()->id(); + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << this + << "] xDS node ID: " << bootstrap_->node()->id(); } } XdsClient::~XdsClient() { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << this << "] destroying xds client"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << this << "] destroying xds client"; } void XdsClient::Orphaned() { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << this << "] shutting down xds client"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << this << "] shutting down xds client"; MutexLock lock(&mu_); shutting_down_ = true; // Clear cache and any remaining watchers that may not have been cancelled. @@ -1702,10 +1673,9 @@ void XdsClient::WatchResource(const XdsResourceType* type, // If we already have a cached value for the resource, notify the new // watcher immediately. if (resource_state.resource != nullptr) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << this - << "] returning cached listener data for " << name; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << this << "] returning cached listener data for " + << name; work_serializer_.Schedule( [watcher, value = resource_state.resource]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(&work_serializer_) { @@ -1715,10 +1685,9 @@ void XdsClient::WatchResource(const XdsResourceType* type, DEBUG_LOCATION); } else if (resource_state.meta.client_status == XdsApi::ResourceMetadata::DOES_NOT_EXIST) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << this - << "] reporting cached does-not-exist for " << name; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << this + << "] reporting cached does-not-exist for " << name; work_serializer_.Schedule( [watcher]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(&work_serializer_) { watcher->OnResourceDoesNotExist(ReadDelayHandle::NoWait()); @@ -1726,11 +1695,10 @@ void XdsClient::WatchResource(const XdsResourceType* type, DEBUG_LOCATION); } else if (resource_state.meta.client_status == XdsApi::ResourceMetadata::NACKED) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << this - << "] reporting cached validation failure for " << name - << ": " << resource_state.meta.failed_details; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << this + << "] reporting cached validation failure for " << name << ": " + << resource_state.meta.failed_details; std::string details = resource_state.meta.failed_details; const auto* node = bootstrap_->node(); if (node != nullptr) { @@ -1749,11 +1717,9 @@ void XdsClient::WatchResource(const XdsResourceType* type, } absl::Status channel_status = authority_state.xds_channels.back()->status(); if (!channel_status.ok()) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << this - << "] returning cached channel error for " << name << ": " - << channel_status; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << this << "] returning cached channel error for " + << name << ": " << channel_status; work_serializer_.Schedule( [watcher = std::move(watcher), status = std::move(channel_status)]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(&work_serializer_) mutable { @@ -2052,9 +2018,8 @@ void XdsClient::NotifyWatchersOnResourceDoesNotExist( XdsApi::ClusterLoadReportMap XdsClient::BuildLoadReportSnapshotLocked( const XdsBootstrap::XdsServer& xds_server, bool send_all_clusters, const std::set& clusters) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << this << "] start building load report"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << this << "] start building load report"; XdsApi::ClusterLoadReportMap snapshot_map; auto server_it = xds_load_report_server_map_.find(xds_server.Key()); if (server_it == xds_load_report_server_map_.end()) return snapshot_map; @@ -2079,11 +2044,10 @@ XdsApi::ClusterLoadReportMap XdsClient::BuildLoadReportSnapshotLocked( if (load_report.drop_stats != nullptr) { snapshot.dropped_requests += load_report.drop_stats->GetSnapshotAndReset(); - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << this << "] cluster=" << cluster_key.first - << " eds_service_name=" << cluster_key.second - << " drop_stats=" << load_report.drop_stats; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << this << "] cluster=" << cluster_key.first + << " eds_service_name=" << cluster_key.second + << " drop_stats=" << load_report.drop_stats; } // Aggregate locality stats. for (auto it = load_report.locality_stats.begin(); @@ -2096,14 +2060,12 @@ XdsApi::ClusterLoadReportMap XdsClient::BuildLoadReportSnapshotLocked( if (locality_state.locality_stats != nullptr) { locality_snapshot += locality_state.locality_stats->GetSnapshotAndReset(); - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << this - << "] cluster=" << cluster_key.first.c_str() - << " eds_service_name=" << cluster_key.second.c_str() - << " locality=" - << locality_name->human_readable_string().c_str() - << " locality_stats=" << locality_state.locality_stats; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << this + << "] cluster=" << cluster_key.first.c_str() + << " eds_service_name=" << cluster_key.second.c_str() + << " locality=" << locality_name->human_readable_string().c_str() + << " locality_stats=" << locality_state.locality_stats; } // If the only thing left in this entry was final snapshots from // deleted locality stats objects, remove the entry. diff --git a/src/core/xds/xds_client/xds_client_stats.cc b/src/core/xds/xds_client/xds_client_stats.cc index dba8683e93..3219b224a9 100644 --- a/src/core/xds/xds_client/xds_client_stats.cc +++ b/src/core/xds/xds_client/xds_client_stats.cc @@ -51,19 +51,17 @@ XdsClusterDropStats::XdsClusterDropStats(RefCountedPtr xds_client, lrs_server_(lrs_server), cluster_name_(cluster_name), eds_service_name_(eds_service_name) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client_.get() << "] created drop stats " - << this << " for {" << lrs_server_ << ", " << cluster_name_ - << ", " << eds_service_name_ << "}"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client_.get() << "] created drop stats " << this + << " for {" << lrs_server_ << ", " << cluster_name_ << ", " + << eds_service_name_ << "}"; } XdsClusterDropStats::~XdsClusterDropStats() { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client_.get() - << "] destroying drop stats " << this << " for {" << lrs_server_ - << ", " << cluster_name_ << ", " << eds_service_name_ << "}"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client_.get() << "] destroying drop stats " + << this << " for {" << lrs_server_ << ", " << cluster_name_ << ", " + << eds_service_name_ << "}"; xds_client_->RemoveClusterDropStats(lrs_server_, cluster_name_, eds_service_name_, this); xds_client_.reset(DEBUG_LOCATION, "DropStats"); @@ -102,26 +100,21 @@ XdsClusterLocalityStats::XdsClusterLocalityStats( cluster_name_(cluster_name), eds_service_name_(eds_service_name), name_(std::move(name)) { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client_.get() - << "] created locality stats " << this << " for {" << lrs_server_ - << ", " << cluster_name_ << ", " << eds_service_name_ << ", " - << (name_ == nullptr ? "" - : name_->human_readable_string().c_str()) - << "}"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client_.get() << "] created locality stats " + << this << " for {" << lrs_server_ << ", " << cluster_name_ << ", " + << eds_service_name_ << ", " + << (name_ == nullptr ? "" : name_->human_readable_string().c_str()) + << "}"; } XdsClusterLocalityStats::~XdsClusterLocalityStats() { - if (GRPC_TRACE_FLAG_ENABLED(xds_client)) { - LOG(INFO) << "[xds_client " << xds_client_.get() - << "] destroying locality stats " << this << " for {" - << lrs_server_ << ", " << cluster_name_ << ", " - << eds_service_name_ << ", " - << (name_ == nullptr ? "" - : name_->human_readable_string().c_str()) - << "}"; - } + GRPC_TRACE_LOG(xds_client, INFO) + << "[xds_client " << xds_client_.get() << "] destroying locality stats " + << this << " for {" << lrs_server_ << ", " << cluster_name_ << ", " + << eds_service_name_ << ", " + << (name_ == nullptr ? "" : name_->human_readable_string().c_str()) + << "}"; xds_client_->RemoveClusterLocalityStats(lrs_server_, cluster_name_, eds_service_name_, name_, this); xds_client_.reset(DEBUG_LOCATION, "LocalityStats"); diff --git a/src/cpp/client/channel_cc.cc b/src/cpp/client/channel_cc.cc index 8b8e37fc9f..457f9db37a 100644 --- a/src/cpp/client/channel_cc.cc +++ b/src/cpp/client/channel_cc.cc @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc index 76bee4cb6b..78c0bd1600 100644 --- a/src/cpp/client/client_context.cc +++ b/src/cpp/client/client_context.cc @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include diff --git a/src/cpp/client/global_callback_hook.cc b/src/cpp/client/global_callback_hook.cc new file mode 100644 index 0000000000..2431508b7b --- /dev/null +++ b/src/cpp/client/global_callback_hook.cc @@ -0,0 +1,36 @@ +// 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 + +#include "absl/base/no_destructor.h" +#include "absl/log/check.h" + +#include + +namespace grpc { + +static absl::NoDestructor> g_callback_hook( + std::make_shared()); + +std::shared_ptr GetGlobalCallbackHook() { + return *g_callback_hook; +} + +void SetGlobalCallbackHook(GlobalCallbackHook* hook) { + CHECK(hook != nullptr); + CHECK(hook != (*g_callback_hook).get()); + *g_callback_hook = std::shared_ptr(hook); +} +} // namespace grpc diff --git a/src/cpp/client/xds_credentials.cc b/src/cpp/client/xds_credentials.cc index d7878e5cb5..e3fefd04c4 100644 --- a/src/cpp/client/xds_credentials.cc +++ b/src/cpp/client/xds_credentials.cc @@ -22,7 +22,6 @@ #include #include -#include #include namespace grpc { diff --git a/src/cpp/common/alarm.cc b/src/cpp/common/alarm.cc index 918922eb23..041584eb48 100644 --- a/src/cpp/common/alarm.cc +++ b/src/cpp/common/alarm.cc @@ -25,7 +25,6 @@ #include #include -#include #include #include #include diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc index 3eb56c3280..fc09938b99 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -24,7 +24,6 @@ #include #include -#include #include #include #include diff --git a/src/cpp/common/tls_certificate_provider.cc b/src/cpp/common/tls_certificate_provider.cc index b94a807bfd..7d841b38fd 100644 --- a/src/cpp/common/tls_certificate_provider.cc +++ b/src/cpp/common/tls_certificate_provider.cc @@ -21,7 +21,6 @@ #include #include -#include #include namespace grpc { diff --git a/src/cpp/common/tls_certificate_verifier.cc b/src/cpp/common/tls_certificate_verifier.cc index a642760a4a..d298cf2677 100644 --- a/src/cpp/common/tls_certificate_verifier.cc +++ b/src/cpp/common/tls_certificate_verifier.cc @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/src/cpp/common/tls_credentials_options.cc b/src/cpp/common/tls_credentials_options.cc index ef260b8690..74e7412832 100644 --- a/src/cpp/common/tls_credentials_options.cc +++ b/src/cpp/common/tls_credentials_options.cc @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/src/cpp/server/backend_metric_recorder.cc b/src/cpp/server/backend_metric_recorder.cc index d92fac3db0..40a19f3a72 100644 --- a/src/cpp/server/backend_metric_recorder.cc +++ b/src/cpp/server/backend_metric_recorder.cc @@ -26,7 +26,6 @@ #include "absl/log/log.h" -#include #include #include @@ -70,88 +69,73 @@ void ServerMetricRecorder::UpdateBackendMetricDataState( void ServerMetricRecorder::SetCpuUtilization(double value) { if (!IsUtilizationWithSoftLimitsValid(value)) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] CPU utilization rejected: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] CPU utilization rejected: " << value; return; } UpdateBackendMetricDataState( [value](BackendMetricData* data) { data->cpu_utilization = value; }); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] CPU utilization set: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] CPU utilization set: " << value; } void ServerMetricRecorder::SetMemoryUtilization(double value) { if (!IsUtilizationValid(value)) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Mem utilization rejected: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Mem utilization rejected: " << value; return; } UpdateBackendMetricDataState( [value](BackendMetricData* data) { data->mem_utilization = value; }); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Mem utilization set: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Mem utilization set: " << value; } void ServerMetricRecorder::SetApplicationUtilization(double value) { if (!IsUtilizationWithSoftLimitsValid(value)) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this - << "] Application utilization rejected: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Application utilization rejected: " << value; return; } UpdateBackendMetricDataState([value](BackendMetricData* data) { data->application_utilization = value; }); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Application utilization set: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Application utilization set: " << value; } void ServerMetricRecorder::SetQps(double value) { if (!IsRateValid(value)) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] QPS rejected: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] QPS rejected: " << value; return; } UpdateBackendMetricDataState( [value](BackendMetricData* data) { data->qps = value; }); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] QPS set: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) << "[" << this << "] QPS set: " << value; } void ServerMetricRecorder::SetEps(double value) { if (!IsRateValid(value)) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] EPS rejected: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] EPS rejected: " << value; return; } UpdateBackendMetricDataState( [value](BackendMetricData* data) { data->eps = value; }); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] EPS set: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) << "[" << this << "] EPS set: " << value; } void ServerMetricRecorder::SetNamedUtilization(string_ref name, double value) { if (!IsUtilizationValid(value)) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Named utilization rejected: " << value - << " name: " << std::string(name.data(), name.size()); - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Named utilization rejected: " << value + << " name: " << std::string(name.data(), name.size()); return; } - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Named utilization set: " << value - << " name: " << std::string(name.data(), name.size()); - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Named utilization set: " << value + << " name: " << std::string(name.data(), name.size()); UpdateBackendMetricDataState([name, value](BackendMetricData* data) { data->utilization[absl::string_view(name.data(), name.size())] = value; }); @@ -159,10 +143,9 @@ void ServerMetricRecorder::SetNamedUtilization(string_ref name, double value) { void ServerMetricRecorder::SetAllNamedUtilization( std::map named_utilization) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] All named utilization updated. size: " - << named_utilization.size(); - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this + << "] All named utilization updated. size: " << named_utilization.size(); UpdateBackendMetricDataState( [utilization = std::move(named_utilization)](BackendMetricData* data) { data->utilization.clear(); @@ -176,46 +159,40 @@ void ServerMetricRecorder::SetAllNamedUtilization( void ServerMetricRecorder::ClearCpuUtilization() { UpdateBackendMetricDataState( [](BackendMetricData* data) { data->cpu_utilization = -1; }); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] CPU utilization cleared."; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] CPU utilization cleared."; } void ServerMetricRecorder::ClearMemoryUtilization() { UpdateBackendMetricDataState( [](BackendMetricData* data) { data->mem_utilization = -1; }); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Mem utilization cleared."; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Mem utilization cleared."; } void ServerMetricRecorder::ClearApplicationUtilization() { UpdateBackendMetricDataState( [](BackendMetricData* data) { data->application_utilization = -1; }); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Application utilization cleared."; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Application utilization cleared."; } void ServerMetricRecorder::ClearQps() { UpdateBackendMetricDataState([](BackendMetricData* data) { data->qps = -1; }); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] QPS utilization cleared."; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] QPS utilization cleared."; } void ServerMetricRecorder::ClearEps() { UpdateBackendMetricDataState([](BackendMetricData* data) { data->eps = -1; }); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] EPS utilization cleared."; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] EPS utilization cleared."; } void ServerMetricRecorder::ClearNamedUtilization(string_ref name) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Named utilization cleared. name: " - << std::string(name.data(), name.size()); - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Named utilization cleared. name: " + << std::string(name.data(), name.size()); UpdateBackendMetricDataState([name](BackendMetricData* data) { data->utilization.erase(absl::string_view(name.data(), name.size())); }); @@ -251,95 +228,81 @@ ServerMetricRecorder::GetMetricsIfChanged() const { experimental::CallMetricRecorder& BackendMetricState::RecordCpuUtilizationMetric(double value) { if (!IsUtilizationWithSoftLimitsValid(value)) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] CPU utilization value rejected: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] CPU utilization value rejected: " << value; return *this; } cpu_utilization_.store(value, std::memory_order_relaxed); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] CPU utilization recorded: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] CPU utilization recorded: " << value; return *this; } experimental::CallMetricRecorder& BackendMetricState::RecordMemoryUtilizationMetric(double value) { if (!IsUtilizationValid(value)) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Mem utilization value rejected: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Mem utilization value rejected: " << value; return *this; } mem_utilization_.store(value, std::memory_order_relaxed); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Mem utilization recorded: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Mem utilization recorded: " << value; return *this; } experimental::CallMetricRecorder& BackendMetricState::RecordApplicationUtilizationMetric(double value) { if (!IsUtilizationWithSoftLimitsValid(value)) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this - << "] Application utilization value rejected: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Application utilization value rejected: " << value; return *this; } application_utilization_.store(value, std::memory_order_relaxed); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Application utilization recorded: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Application utilization recorded: " << value; return *this; } experimental::CallMetricRecorder& BackendMetricState::RecordQpsMetric( double value) { if (!IsRateValid(value)) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] QPS value rejected: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] QPS value rejected: " << value; return *this; } qps_.store(value, std::memory_order_relaxed); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] QPS recorded: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] QPS recorded: " << value; return *this; } experimental::CallMetricRecorder& BackendMetricState::RecordEpsMetric( double value) { if (!IsRateValid(value)) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] EPS value rejected: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] EPS value rejected: " << value; return *this; } eps_.store(value, std::memory_order_relaxed); - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] EPS recorded: " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] EPS recorded: " << value; return *this; } experimental::CallMetricRecorder& BackendMetricState::RecordUtilizationMetric( string_ref name, double value) { if (!IsUtilizationValid(value)) { - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Utilization value rejected: " - << std::string(name.data(), name.length()) << " " << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Utilization value rejected: " + << std::string(name.data(), name.length()) << " " << value; return *this; } internal::MutexLock lock(&mu_); absl::string_view name_sv(name.data(), name.length()); utilization_[name_sv] = value; - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Utilization recorded: " << name_sv << " " - << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Utilization recorded: " << name_sv << " " << value; return *this; } @@ -348,10 +311,8 @@ experimental::CallMetricRecorder& BackendMetricState::RecordRequestCostMetric( internal::MutexLock lock(&mu_); absl::string_view name_sv(name.data(), name.length()); request_cost_[name_sv] = value; - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Request cost recorded: " << name_sv << " " - << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Request cost recorded: " << name_sv << " " << value; return *this; } @@ -360,10 +321,8 @@ experimental::CallMetricRecorder& BackendMetricState::RecordNamedMetric( internal::MutexLock lock(&mu_); absl::string_view name_sv(name.data(), name.length()); named_metrics_[name_sv] = value; - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this << "] Named metric recorded: " << name_sv << " " - << value; - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this << "] Named metric recorded: " << name_sv << " " << value; return *this; } @@ -408,15 +367,13 @@ BackendMetricData BackendMetricState::GetBackendMetricData() { data.named_metrics[r.first] = r.second; } } - if (GRPC_TRACE_FLAG_ENABLED(backend_metric)) { - LOG(INFO) << "[" << this - << "] Backend metric data returned: cpu:" << data.cpu_utilization - << " mem:" << data.mem_utilization << " qps:" << data.qps - << " eps:" << data.eps - << " utilization size:" << data.utilization.size() - << " request_cost size:" << data.request_cost.size() - << "named_metrics size:" << data.named_metrics.size(); - } + GRPC_TRACE_LOG(backend_metric, INFO) + << "[" << this + << "] Backend metric data returned: cpu:" << data.cpu_utilization + << " mem:" << data.mem_utilization << " qps:" << data.qps + << " eps:" << data.eps << " utilization size:" << data.utilization.size() + << " request_cost size:" << data.request_cost.size() + << "named_metrics size:" << data.named_metrics.size(); return data; } diff --git a/src/cpp/server/insecure_server_credentials.cc b/src/cpp/server/insecure_server_credentials.cc index ed14ac3def..a48b9cb93c 100644 --- a/src/cpp/server/insecure_server_credentials.cc +++ b/src/cpp/server/insecure_server_credentials.cc @@ -20,7 +20,6 @@ #include #include -#include #include #include diff --git a/src/cpp/server/xds_server_credentials.cc b/src/cpp/server/xds_server_credentials.cc index eb7f6ddfda..df05e254d4 100644 --- a/src/cpp/server/xds_server_credentials.cc +++ b/src/cpp/server/xds_server_credentials.cc @@ -22,7 +22,6 @@ #include #include -#include #include namespace grpc { diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.mm b/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.mm index 7f29485fee..93919d0f5e 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.mm +++ b/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.mm @@ -18,8 +18,6 @@ #import "GRPCChannel.h" -#include - #import "../../internal/GRPCCallOptions+Internal.h" #import "../GRPCTransport+Private.h" #import "ChannelArgsUtil.h" diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.mm b/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.mm index b42fd6e0a1..a261300cd5 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.mm +++ b/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.mm @@ -28,8 +28,6 @@ #import "GRPCSecureChannelFactory.h" #import "GRPCWrappedCall.h" -#include - extern const char *kCFStreamVarName; static GRPCChannelPool *gChannelPool;