channel_init --> core configuration system (#27347)

* channel_init --> core configuration system

* Automated change: Fix sanity tests

* fixes

* Automated change: Fix sanity tests

* fixes

* fixes

* eliminate grpc_base_c

* fixes

* fix merge

* fix

* update visibility

* fixes

* feedback

* fix comment

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/27497/head
Craig Tiller 3 years ago committed by GitHub
parent c3759da7cc
commit 9b41852a5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 171
      BUILD
  2. 4
      CMakeLists.txt
  3. 2
      Makefile
  4. 8
      build_autogenerated.yaml
  5. 1
      config.m4
  6. 1
      config.w32
  7. 2
      gRPC-C++.podspec
  8. 3
      gRPC-Core.podspec
  9. 2
      grpc.gemspec
  10. 2
      grpc.gyp
  11. 2
      package.xml
  12. 19
      src/core/ext/filters/client_channel/client_channel_plugin.cc
  13. 56
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  14. 36
      src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc
  15. 5
      src/core/ext/filters/client_channel/subchannel.cc
  16. 35
      src/core/ext/filters/client_idle/client_idle_filter.cc
  17. 41
      src/core/ext/filters/deadline/deadline_filter.cc
  18. 24
      src/core/ext/filters/http/client_authority_filter.cc
  19. 124
      src/core/ext/filters/http/http_filters_plugin.cc
  20. 50
      src/core/ext/filters/max_age/max_age_filter.cc
  21. 30
      src/core/ext/filters/message_size/message_size_filter.cc
  22. 16
      src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc
  23. 2
      src/core/ext/transport/binder/client/BUILD
  24. 2
      src/core/ext/transport/binder/server/BUILD
  25. 2
      src/core/ext/transport/binder/transport/BUILD
  26. 1
      src/core/ext/transport/inproc/inproc_transport.cc
  27. 1
      src/core/ext/xds/xds_client.cc
  28. 4
      src/core/lib/channel/connected_channel.cc
  29. 3
      src/core/lib/channel/connected_channel.h
  30. 46
      src/core/lib/config/core_configuration.cc
  31. 38
      src/core/lib/config/core_configuration.h
  32. 49
      src/core/lib/surface/builtins.cc
  33. 26
      src/core/lib/surface/builtins.h
  34. 5
      src/core/lib/surface/channel.cc
  35. 100
      src/core/lib/surface/channel_init.cc
  36. 96
      src/core/lib/surface/channel_init.h
  37. 36
      src/core/lib/surface/init.cc
  38. 31
      src/core/lib/surface/init_secure.cc
  39. 77
      src/core/plugin_registry/grpc_plugin_registry.cc
  40. 67
      src/core/plugin_registry/grpc_unsecure_plugin_registry.cc
  41. 50
      src/cpp/common/channel_filter.cc
  42. 49
      src/cpp/common/channel_filter.h
  43. 1
      src/python/grpcio/grpc_core_dependencies.py
  44. 36
      test/core/channel/channel_stack_builder_test.cc
  45. 3
      test/core/channel/minimal_stack_is_minimal_test.cc
  46. 37
      test/core/end2end/tests/filter_causes_close.cc
  47. 70
      test/core/end2end/tests/filter_context.cc
  48. 111
      test/core/end2end/tests/filter_init_fails.cc
  49. 70
      test/core/end2end/tests/filter_latency.cc
  50. 81
      test/core/end2end/tests/filter_status_code.cc
  51. 35
      test/core/end2end/tests/retry_cancel_with_multiple_send_batches.cc
  52. 28
      test/core/end2end/tests/retry_recv_trailing_metadata_error.cc
  53. 50
      test/core/end2end/tests/retry_send_op_fails.cc
  54. 2
      test/core/security/BUILD
  55. 2
      test/core/transport/binder/end2end/BUILD
  56. 2
      test/core/transport/binder/end2end/fuzzers/BUILD
  57. 4
      test/core/tsi/alts/zero_copy_frame_protector/BUILD
  58. 2
      test/core/util/BUILD
  59. 3
      test/cpp/microbenchmarks/bm_opencensus_plugin.cc
  60. 2
      tools/doxygen/Doxyfile.c++.internal
  61. 2
      tools/doxygen/Doxyfile.core.internal

171
BUILD

@ -359,7 +359,7 @@ grpc_cc_library(
deps = [ deps = [
"config", "config",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_common", "grpc_common",
"grpc_lb_policy_grpclb", "grpc_lb_policy_grpclb",
"grpc_trace", "grpc_trace",
@ -398,7 +398,7 @@ grpc_cc_library(
deps = [ deps = [
"config", "config",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_common", "grpc_common",
"grpc_lb_policy_grpclb_secure", "grpc_lb_policy_grpclb_secure",
"grpc_secure", "grpc_secure",
@ -483,7 +483,7 @@ grpc_cc_library(
"grpc++_codegen_base", "grpc++_codegen_base",
"grpc++_codegen_base_src", "grpc++_codegen_base_src",
"grpc++_codegen_proto", "grpc++_codegen_proto",
"grpc_base_c", "grpc_base",
"grpc_codegen", "grpc_codegen",
"grpc_secure", "grpc_secure",
"ref_counted_ptr", "ref_counted_ptr",
@ -613,7 +613,7 @@ grpc_cc_library(
visibility = ["@grpc:public"], visibility = ["@grpc:public"],
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_trace", "grpc_trace",
], ],
) )
@ -819,7 +819,8 @@ grpc_cc_library(
"src/core/lib/config/core_configuration.h", "src/core/lib/config/core_configuration.h",
], ],
deps = [ deps = [
"gpr_platform", "channel_init",
"gpr_base",
"handshaker_registry", "handshaker_registry",
], ],
) )
@ -1374,7 +1375,7 @@ grpc_cc_library(
) )
grpc_cc_library( grpc_cc_library(
name = "grpc_base_c", name = "grpc_base",
srcs = [ srcs = [
"src/core/lib/address_utils/parse_address.cc", "src/core/lib/address_utils/parse_address.cc",
"src/core/lib/address_utils/sockaddr_utils.cc", "src/core/lib/address_utils/sockaddr_utils.cc",
@ -1505,18 +1506,18 @@ grpc_cc_library(
"src/core/lib/slice/slice_intern.cc", "src/core/lib/slice/slice_intern.cc",
"src/core/lib/slice/slice_split.cc", "src/core/lib/slice/slice_split.cc",
"src/core/lib/surface/api_trace.cc", "src/core/lib/surface/api_trace.cc",
"src/core/lib/surface/builtins.cc",
"src/core/lib/surface/byte_buffer.cc", "src/core/lib/surface/byte_buffer.cc",
"src/core/lib/surface/byte_buffer_reader.cc", "src/core/lib/surface/byte_buffer_reader.cc",
"src/core/lib/surface/call.cc", "src/core/lib/surface/call.cc",
"src/core/lib/surface/call_details.cc", "src/core/lib/surface/call_details.cc",
"src/core/lib/surface/call_log_batch.cc", "src/core/lib/surface/call_log_batch.cc",
"src/core/lib/surface/channel.cc", "src/core/lib/surface/channel.cc",
"src/core/lib/surface/channel_init.cc",
"src/core/lib/surface/channel_ping.cc", "src/core/lib/surface/channel_ping.cc",
"src/core/lib/surface/channel_stack_type.cc",
"src/core/lib/surface/completion_queue.cc", "src/core/lib/surface/completion_queue.cc",
"src/core/lib/surface/completion_queue_factory.cc", "src/core/lib/surface/completion_queue_factory.cc",
"src/core/lib/surface/event_string.cc", "src/core/lib/surface/event_string.cc",
"src/core/lib/surface/lame_client.cc",
"src/core/lib/surface/metadata_array.cc", "src/core/lib/surface/metadata_array.cc",
"src/core/lib/surface/server.cc", "src/core/lib/surface/server.cc",
"src/core/lib/surface/validate_metadata.cc", "src/core/lib/surface/validate_metadata.cc",
@ -1646,11 +1647,10 @@ grpc_cc_library(
"src/core/lib/slice/b64.h", "src/core/lib/slice/b64.h",
"src/core/lib/slice/percent_encoding.h", "src/core/lib/slice/percent_encoding.h",
"src/core/lib/surface/api_trace.h", "src/core/lib/surface/api_trace.h",
"src/core/lib/surface/builtins.h",
"src/core/lib/surface/call.h", "src/core/lib/surface/call.h",
"src/core/lib/surface/call_test_only.h", "src/core/lib/surface/call_test_only.h",
"src/core/lib/surface/channel.h", "src/core/lib/surface/channel.h",
"src/core/lib/surface/channel_init.h",
"src/core/lib/surface/channel_stack_type.h",
"src/core/lib/surface/completion_queue.h", "src/core/lib/surface/completion_queue.h",
"src/core/lib/surface/completion_queue_factory.h", "src/core/lib/surface/completion_queue_factory.h",
"src/core/lib/surface/event_string.h", "src/core/lib/surface/event_string.h",
@ -1706,7 +1706,9 @@ grpc_cc_library(
visibility = ["@grpc:alt_grpc_base_legacy"], visibility = ["@grpc:alt_grpc_base_legacy"],
deps = [ deps = [
"bitset", "bitset",
"channel_stack_type",
"closure", "closure",
"config",
"dual_ref_counted", "dual_ref_counted",
"error", "error",
"exec_ctx", "exec_ctx",
@ -1725,15 +1727,31 @@ grpc_cc_library(
) )
grpc_cc_library( grpc_cc_library(
name = "grpc_base", name = "channel_stack_type",
srcs = [ srcs = [
"src/core/lib/surface/lame_client.cc", "src/core/lib/surface/channel_stack_type.cc",
],
hdrs = [
"src/core/lib/surface/channel_stack_type.h",
],
language = "c++",
deps = [
"gpr_base",
],
)
grpc_cc_library(
name = "channel_init",
srcs = [
"src/core/lib/surface/channel_init.cc",
],
hdrs = [
"src/core/lib/surface/channel_init.h",
], ],
language = "c++", language = "c++",
visibility = ["@grpc:alt_grpc_base_legacy"],
deps = [ deps = [
"channel_stack_type",
"gpr_base", "gpr_base",
"grpc_base_c",
], ],
) )
@ -1851,7 +1869,7 @@ grpc_cc_library(
"debug_location", "debug_location",
"error", "error",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_authority_filter", "grpc_client_authority_filter",
"grpc_deadline_filter", "grpc_deadline_filter",
"grpc_health_upb", "grpc_health_upb",
@ -1873,8 +1891,9 @@ grpc_cc_library(
], ],
language = "c++", language = "c++",
deps = [ deps = [
"config",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
], ],
) )
@ -1888,8 +1907,9 @@ grpc_cc_library(
], ],
language = "c++", language = "c++",
deps = [ deps = [
"config",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
], ],
) )
@ -1903,8 +1923,9 @@ grpc_cc_library(
], ],
language = "c++", language = "c++",
deps = [ deps = [
"config",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"slice", "slice",
], ],
) )
@ -1919,8 +1940,10 @@ grpc_cc_library(
], ],
language = "c++", language = "c++",
deps = [ deps = [
"channel_stack_type",
"config",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"slice", "slice",
], ],
) )
@ -1936,8 +1959,9 @@ grpc_cc_library(
external_deps = ["absl/strings:str_format"], external_deps = ["absl/strings:str_format"],
language = "c++", language = "c++",
deps = [ deps = [
"config",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_codegen", "grpc_codegen",
"ref_counted", "ref_counted",
@ -1959,7 +1983,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
], ],
) )
@ -1986,8 +2010,9 @@ grpc_cc_library(
], ],
language = "c++", language = "c++",
deps = [ deps = [
"config",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_message_size_filter", "grpc_message_size_filter",
"slice", "slice",
], ],
@ -2003,8 +2028,9 @@ grpc_cc_library(
], ],
language = "c++", language = "c++",
deps = [ deps = [
"config",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_server_backward_compatibility", "grpc_server_backward_compatibility",
], ],
) )
@ -2040,7 +2066,7 @@ grpc_cc_library(
visibility = ["@grpc:grpclb"], visibility = ["@grpc:grpclb"],
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"useful", "useful",
], ],
@ -2071,10 +2097,11 @@ grpc_cc_library(
], ],
language = "c++", language = "c++",
deps = [ deps = [
"config",
"error", "error",
"google_api_upb", "google_api_upb",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_grpclb_balancer_addresses", "grpc_grpclb_balancer_addresses",
"grpc_lb_upb", "grpc_lb_upb",
@ -2111,10 +2138,11 @@ grpc_cc_library(
], ],
language = "c++", language = "c++",
deps = [ deps = [
"config",
"error", "error",
"google_api_upb", "google_api_upb",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_grpclb_balancer_addresses", "grpc_grpclb_balancer_addresses",
"grpc_lb_upb", "grpc_lb_upb",
@ -2180,7 +2208,7 @@ grpc_cc_library(
"google_api_upb", "google_api_upb",
"gpr_base", "gpr_base",
"gpr_codegen", "gpr_codegen",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_codegen", "grpc_codegen",
"grpc_fault_injection_filter", "grpc_fault_injection_filter",
@ -2208,7 +2236,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_xds_client", "grpc_xds_client",
], ],
) )
@ -2228,7 +2256,7 @@ grpc_cc_library(
deps = [ deps = [
"error", "error",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_xds_client", "grpc_xds_client",
"slice", "slice",
], ],
@ -2245,7 +2273,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_xds_client", "grpc_xds_client",
"orphanable", "orphanable",
@ -2269,7 +2297,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_xds_client", "grpc_xds_client",
], ],
@ -2287,7 +2315,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_lb_address_filtering", "grpc_lb_address_filtering",
"grpc_lb_policy_ring_hash", "grpc_lb_policy_ring_hash",
@ -2311,7 +2339,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_lb_xds_channel_args", "grpc_lb_xds_channel_args",
"grpc_lb_xds_common", "grpc_lb_xds_common",
@ -2333,7 +2361,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_resolver_xds_header", "grpc_resolver_xds_header",
"orphanable", "orphanable",
@ -2356,7 +2384,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
], ],
) )
@ -2369,7 +2397,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
], ],
) )
@ -2382,7 +2410,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_lb_subchannel_list", "grpc_lb_subchannel_list",
], ],
@ -2403,7 +2431,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_lb_subchannel_list", "grpc_lb_subchannel_list",
"grpc_trace", "grpc_trace",
@ -2419,7 +2447,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_lb_subchannel_list", "grpc_lb_subchannel_list",
"grpc_trace", "grpc_trace",
@ -2439,7 +2467,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_lb_address_filtering", "grpc_lb_address_filtering",
"orphanable", "orphanable",
@ -2459,7 +2487,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_lb_address_filtering", "grpc_lb_address_filtering",
"orphanable", "orphanable",
@ -2487,7 +2515,7 @@ grpc_cc_library(
"error", "error",
"gpr", "gpr",
"grpc++_base", "grpc++_base",
"grpc_base_c", "grpc_base",
"grpc_secure", "grpc_secure",
"slice", "slice",
], ],
@ -2508,7 +2536,7 @@ grpc_cc_library(
"gpr", "gpr",
"gpr_codegen", "gpr_codegen",
"grpc++", "grpc++",
"grpc_base_c", "grpc_base",
], ],
) )
@ -2615,7 +2643,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
], ],
) )
@ -2630,7 +2658,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_resolver_dns_selection", "grpc_resolver_dns_selection",
], ],
@ -2663,7 +2691,7 @@ grpc_cc_library(
deps = [ deps = [
"error", "error",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_grpclb_balancer_addresses", "grpc_grpclb_balancer_addresses",
"grpc_resolver_dns_selection", "grpc_resolver_dns_selection",
@ -2681,7 +2709,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"slice", "slice",
], ],
@ -2698,7 +2726,7 @@ grpc_cc_library(
], ],
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"slice", "slice",
"useful", "useful",
@ -2726,7 +2754,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_lb_policy_ring_hash", "grpc_lb_policy_ring_hash",
"grpc_xds_client", "grpc_xds_client",
@ -2742,7 +2770,7 @@ grpc_cc_library(
deps = [ deps = [
"alts_util", "alts_util",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_xds_client", "grpc_xds_client",
], ],
@ -2866,7 +2894,6 @@ grpc_cc_library(
"error", "error",
"gpr_base", "gpr_base",
"grpc_base", "grpc_base",
"grpc_base_c",
"grpc_client_channel", "grpc_client_channel",
"grpc_codegen", "grpc_codegen",
"grpc_lb_xds_channel_args", "grpc_lb_xds_channel_args",
@ -2895,7 +2922,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"google_api_upb", "google_api_upb",
"grpc_base_c", "grpc_base",
], ],
) )
@ -2917,7 +2944,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
], ],
) )
@ -2941,7 +2968,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_matchers", "grpc_matchers",
"grpc_secure", "grpc_secure",
], ],
@ -3009,7 +3036,7 @@ grpc_cc_library(
"envoy_ads_upb", "envoy_ads_upb",
"google_api_upb", "google_api_upb",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_mock_cel", "grpc_mock_cel",
"grpc_rbac_engine", "grpc_rbac_engine",
], ],
@ -3134,7 +3161,7 @@ grpc_cc_library(
visibility = ["@grpc:grpclb"], visibility = ["@grpc:grpclb"],
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_http_filters", "grpc_http_filters",
"grpc_trace", "grpc_trace",
"grpc_transport_chttp2_alpn", "grpc_transport_chttp2_alpn",
@ -3178,7 +3205,7 @@ grpc_cc_library(
deps = [ deps = [
"config", "config",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_transport_chttp2", "grpc_transport_chttp2",
"slice", "slice",
@ -3194,7 +3221,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_transport_chttp2", "grpc_transport_chttp2",
"grpc_transport_chttp2_client_connector", "grpc_transport_chttp2_client_connector",
@ -3210,7 +3237,7 @@ grpc_cc_library(
deps = [ deps = [
"error", "error",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_secure", "grpc_secure",
"grpc_transport_chttp2", "grpc_transport_chttp2",
@ -3235,7 +3262,7 @@ grpc_cc_library(
deps = [ deps = [
"config", "config",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_codegen", "grpc_codegen",
"grpc_http_filters", "grpc_http_filters",
"grpc_transport_chttp2", "grpc_transport_chttp2",
@ -3257,7 +3284,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_transport_chttp2", "grpc_transport_chttp2",
"grpc_transport_chttp2_server", "grpc_transport_chttp2_server",
], ],
@ -3274,7 +3301,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_secure", "grpc_secure",
"grpc_transport_chttp2", "grpc_transport_chttp2",
"grpc_transport_chttp2_server", "grpc_transport_chttp2_server",
@ -3294,7 +3321,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_trace", "grpc_trace",
"slice", "slice",
], ],
@ -3358,7 +3385,7 @@ grpc_cc_library(
visibility = ["@grpc:alts_frame_protector"], visibility = ["@grpc:alts_frame_protector"],
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"slice", "slice",
"tsi_interface", "tsi_interface",
"useful", "useful",
@ -3391,7 +3418,7 @@ grpc_cc_library(
deps = [ deps = [
"alts_upb", "alts_upb",
"gpr", "gpr",
"grpc_base_c", "grpc_base",
], ],
) )
@ -3436,7 +3463,7 @@ grpc_cc_library(
"alts_frame_protector", "alts_frame_protector",
"alts_util", "alts_util",
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
"grpc_transport_chttp2_client_insecure", "grpc_transport_chttp2_client_insecure",
"slice", "slice",
"tsi_interface", "tsi_interface",
@ -3458,12 +3485,13 @@ grpc_cc_library(
public_hdrs = GRPCXX_PUBLIC_HDRS, public_hdrs = GRPCXX_PUBLIC_HDRS,
visibility = ["@grpc:alt_grpc++_base_legacy"], visibility = ["@grpc:alt_grpc++_base_legacy"],
deps = [ deps = [
"config",
"gpr_base", "gpr_base",
"grpc", "grpc",
"grpc++_codegen_base", "grpc++_codegen_base",
"grpc++_codegen_base_src", "grpc++_codegen_base_src",
"grpc++_internal_hdrs_only", "grpc++_internal_hdrs_only",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_codegen", "grpc_codegen",
"grpc_health_upb", "grpc_health_upb",
@ -3489,11 +3517,12 @@ grpc_cc_library(
tags = ["avoid_dep"], tags = ["avoid_dep"],
visibility = ["@grpc:alt_grpc++_base_unsecure_legacy"], visibility = ["@grpc:alt_grpc++_base_unsecure_legacy"],
deps = [ deps = [
"config",
"gpr_base", "gpr_base",
"grpc++_codegen_base", "grpc++_codegen_base",
"grpc++_codegen_base_src", "grpc++_codegen_base_src",
"grpc++_internal_hdrs_only", "grpc++_internal_hdrs_only",
"grpc_base_c", "grpc_base",
"grpc_client_channel", "grpc_client_channel",
"grpc_codegen", "grpc_codegen",
"grpc_health_upb", "grpc_health_upb",
@ -3751,7 +3780,7 @@ grpc_cc_library(
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc++", "grpc++",
"grpc_base_c", "grpc_base",
], ],
) )
@ -3766,7 +3795,7 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"gpr_base", "gpr_base",
"grpc_base_c", "grpc_base",
], ],
) )
@ -3827,7 +3856,7 @@ grpc_cc_library(
"census", "census",
"gpr_base", "gpr_base",
"grpc++", "grpc++",
"grpc_base_c", "grpc_base",
], ],
) )

4
CMakeLists.txt generated

@ -2050,6 +2050,7 @@ add_library(grpc
src/core/lib/slice/slice_string_helpers.cc src/core/lib/slice/slice_string_helpers.cc
src/core/lib/slice/static_slice.cc src/core/lib/slice/static_slice.cc
src/core/lib/surface/api_trace.cc src/core/lib/surface/api_trace.cc
src/core/lib/surface/builtins.cc
src/core/lib/surface/byte_buffer.cc src/core/lib/surface/byte_buffer.cc
src/core/lib/surface/byte_buffer_reader.cc src/core/lib/surface/byte_buffer_reader.cc
src/core/lib/surface/call.cc src/core/lib/surface/call.cc
@ -2634,6 +2635,7 @@ add_library(grpc_unsecure
src/core/lib/slice/slice_string_helpers.cc src/core/lib/slice/slice_string_helpers.cc
src/core/lib/slice/static_slice.cc src/core/lib/slice/static_slice.cc
src/core/lib/surface/api_trace.cc src/core/lib/surface/api_trace.cc
src/core/lib/surface/builtins.cc
src/core/lib/surface/byte_buffer.cc src/core/lib/surface/byte_buffer.cc
src/core/lib/surface/byte_buffer_reader.cc src/core/lib/surface/byte_buffer_reader.cc
src/core/lib/surface/call.cc src/core/lib/surface/call.cc
@ -10505,6 +10507,8 @@ add_executable(core_configuration_test
src/core/lib/gprpp/time_util.cc src/core/lib/gprpp/time_util.cc
src/core/lib/profiling/basic_timers.cc src/core/lib/profiling/basic_timers.cc
src/core/lib/profiling/stap_timers.cc src/core/lib/profiling/stap_timers.cc
src/core/lib/surface/channel_init.cc
src/core/lib/surface/channel_stack_type.cc
test/core/config/core_configuration_test.cc test/core/config/core_configuration_test.cc
third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc third_party/googletest/googlemock/src/gmock-all.cc

2
Makefile generated

@ -1551,6 +1551,7 @@ LIBGRPC_SRC = \
src/core/lib/slice/slice_string_helpers.cc \ src/core/lib/slice/slice_string_helpers.cc \
src/core/lib/slice/static_slice.cc \ src/core/lib/slice/static_slice.cc \
src/core/lib/surface/api_trace.cc \ src/core/lib/surface/api_trace.cc \
src/core/lib/surface/builtins.cc \
src/core/lib/surface/byte_buffer.cc \ src/core/lib/surface/byte_buffer.cc \
src/core/lib/surface/byte_buffer_reader.cc \ src/core/lib/surface/byte_buffer_reader.cc \
src/core/lib/surface/call.cc \ src/core/lib/surface/call.cc \
@ -1983,6 +1984,7 @@ LIBGRPC_UNSECURE_SRC = \
src/core/lib/slice/slice_string_helpers.cc \ src/core/lib/slice/slice_string_helpers.cc \
src/core/lib/slice/static_slice.cc \ src/core/lib/slice/static_slice.cc \
src/core/lib/surface/api_trace.cc \ src/core/lib/surface/api_trace.cc \
src/core/lib/surface/builtins.cc \
src/core/lib/surface/byte_buffer.cc \ src/core/lib/surface/byte_buffer.cc \
src/core/lib/surface/byte_buffer_reader.cc \ src/core/lib/surface/byte_buffer_reader.cc \
src/core/lib/surface/call.cc \ src/core/lib/surface/call.cc \

@ -902,6 +902,7 @@ libs:
- src/core/lib/slice/slice_utils.h - src/core/lib/slice/slice_utils.h
- src/core/lib/slice/static_slice.h - src/core/lib/slice/static_slice.h
- src/core/lib/surface/api_trace.h - src/core/lib/surface/api_trace.h
- src/core/lib/surface/builtins.h
- src/core/lib/surface/call.h - src/core/lib/surface/call.h
- src/core/lib/surface/call_test_only.h - src/core/lib/surface/call_test_only.h
- src/core/lib/surface/channel.h - src/core/lib/surface/channel.h
@ -1465,6 +1466,7 @@ libs:
- src/core/lib/slice/slice_string_helpers.cc - src/core/lib/slice/slice_string_helpers.cc
- src/core/lib/slice/static_slice.cc - src/core/lib/slice/static_slice.cc
- src/core/lib/surface/api_trace.cc - src/core/lib/surface/api_trace.cc
- src/core/lib/surface/builtins.cc
- src/core/lib/surface/byte_buffer.cc - src/core/lib/surface/byte_buffer.cc
- src/core/lib/surface/byte_buffer_reader.cc - src/core/lib/surface/byte_buffer_reader.cc
- src/core/lib/surface/call.cc - src/core/lib/surface/call.cc
@ -1906,6 +1908,7 @@ libs:
- src/core/lib/slice/slice_utils.h - src/core/lib/slice/slice_utils.h
- src/core/lib/slice/static_slice.h - src/core/lib/slice/static_slice.h
- src/core/lib/surface/api_trace.h - src/core/lib/surface/api_trace.h
- src/core/lib/surface/builtins.h
- src/core/lib/surface/call.h - src/core/lib/surface/call.h
- src/core/lib/surface/call_test_only.h - src/core/lib/surface/call_test_only.h
- src/core/lib/surface/channel.h - src/core/lib/surface/channel.h
@ -2187,6 +2190,7 @@ libs:
- src/core/lib/slice/slice_string_helpers.cc - src/core/lib/slice/slice_string_helpers.cc
- src/core/lib/slice/static_slice.cc - src/core/lib/slice/static_slice.cc
- src/core/lib/surface/api_trace.cc - src/core/lib/surface/api_trace.cc
- src/core/lib/surface/builtins.cc
- src/core/lib/surface/byte_buffer.cc - src/core/lib/surface/byte_buffer.cc
- src/core/lib/surface/byte_buffer_reader.cc - src/core/lib/surface/byte_buffer_reader.cc
- src/core/lib/surface/call.cc - src/core/lib/surface/call.cc
@ -5401,6 +5405,8 @@ targets:
- src/core/lib/gprpp/thd.h - src/core/lib/gprpp/thd.h
- src/core/lib/gprpp/time_util.h - src/core/lib/gprpp/time_util.h
- src/core/lib/profiling/timers.h - src/core/lib/profiling/timers.h
- src/core/lib/surface/channel_init.h
- src/core/lib/surface/channel_stack_type.h
src: src:
- src/core/ext/upb-generated/google/api/annotations.upb.c - src/core/ext/upb-generated/google/api/annotations.upb.c
- src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c - src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c
@ -5460,6 +5466,8 @@ targets:
- src/core/lib/gprpp/time_util.cc - src/core/lib/gprpp/time_util.cc
- src/core/lib/profiling/basic_timers.cc - src/core/lib/profiling/basic_timers.cc
- src/core/lib/profiling/stap_timers.cc - src/core/lib/profiling/stap_timers.cc
- src/core/lib/surface/channel_init.cc
- src/core/lib/surface/channel_stack_type.cc
- test/core/config/core_configuration_test.cc - test/core/config/core_configuration_test.cc
deps: deps:
- absl/base:base - absl/base:base

1
config.m4 generated

@ -604,6 +604,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/slice/slice_string_helpers.cc \ src/core/lib/slice/slice_string_helpers.cc \
src/core/lib/slice/static_slice.cc \ src/core/lib/slice/static_slice.cc \
src/core/lib/surface/api_trace.cc \ src/core/lib/surface/api_trace.cc \
src/core/lib/surface/builtins.cc \
src/core/lib/surface/byte_buffer.cc \ src/core/lib/surface/byte_buffer.cc \
src/core/lib/surface/byte_buffer_reader.cc \ src/core/lib/surface/byte_buffer_reader.cc \
src/core/lib/surface/call.cc \ src/core/lib/surface/call.cc \

1
config.w32 generated

@ -570,6 +570,7 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\slice\\slice_string_helpers.cc " + "src\\core\\lib\\slice\\slice_string_helpers.cc " +
"src\\core\\lib\\slice\\static_slice.cc " + "src\\core\\lib\\slice\\static_slice.cc " +
"src\\core\\lib\\surface\\api_trace.cc " + "src\\core\\lib\\surface\\api_trace.cc " +
"src\\core\\lib\\surface\\builtins.cc " +
"src\\core\\lib\\surface\\byte_buffer.cc " + "src\\core\\lib\\surface\\byte_buffer.cc " +
"src\\core\\lib\\surface\\byte_buffer_reader.cc " + "src\\core\\lib\\surface\\byte_buffer_reader.cc " +
"src\\core\\lib\\surface\\call.cc " + "src\\core\\lib\\surface\\call.cc " +

2
gRPC-C++.podspec generated

@ -714,6 +714,7 @@ Pod::Spec.new do |s|
'src/core/lib/slice/slice_utils.h', 'src/core/lib/slice/slice_utils.h',
'src/core/lib/slice/static_slice.h', 'src/core/lib/slice/static_slice.h',
'src/core/lib/surface/api_trace.h', 'src/core/lib/surface/api_trace.h',
'src/core/lib/surface/builtins.h',
'src/core/lib/surface/call.h', 'src/core/lib/surface/call.h',
'src/core/lib/surface/call_test_only.h', 'src/core/lib/surface/call_test_only.h',
'src/core/lib/surface/channel.h', 'src/core/lib/surface/channel.h',
@ -1385,6 +1386,7 @@ Pod::Spec.new do |s|
'src/core/lib/slice/slice_utils.h', 'src/core/lib/slice/slice_utils.h',
'src/core/lib/slice/static_slice.h', 'src/core/lib/slice/static_slice.h',
'src/core/lib/surface/api_trace.h', 'src/core/lib/surface/api_trace.h',
'src/core/lib/surface/builtins.h',
'src/core/lib/surface/call.h', 'src/core/lib/surface/call.h',
'src/core/lib/surface/call_test_only.h', 'src/core/lib/surface/call_test_only.h',
'src/core/lib/surface/channel.h', 'src/core/lib/surface/channel.h',

3
gRPC-Core.podspec generated

@ -1269,6 +1269,8 @@ Pod::Spec.new do |s|
'src/core/lib/slice/static_slice.h', 'src/core/lib/slice/static_slice.h',
'src/core/lib/surface/api_trace.cc', 'src/core/lib/surface/api_trace.cc',
'src/core/lib/surface/api_trace.h', 'src/core/lib/surface/api_trace.h',
'src/core/lib/surface/builtins.cc',
'src/core/lib/surface/builtins.h',
'src/core/lib/surface/byte_buffer.cc', 'src/core/lib/surface/byte_buffer.cc',
'src/core/lib/surface/byte_buffer_reader.cc', 'src/core/lib/surface/byte_buffer_reader.cc',
'src/core/lib/surface/call.cc', 'src/core/lib/surface/call.cc',
@ -1972,6 +1974,7 @@ Pod::Spec.new do |s|
'src/core/lib/slice/slice_utils.h', 'src/core/lib/slice/slice_utils.h',
'src/core/lib/slice/static_slice.h', 'src/core/lib/slice/static_slice.h',
'src/core/lib/surface/api_trace.h', 'src/core/lib/surface/api_trace.h',
'src/core/lib/surface/builtins.h',
'src/core/lib/surface/call.h', 'src/core/lib/surface/call.h',
'src/core/lib/surface/call_test_only.h', 'src/core/lib/surface/call_test_only.h',
'src/core/lib/surface/channel.h', 'src/core/lib/surface/channel.h',

2
grpc.gemspec generated

@ -1182,6 +1182,8 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/slice/static_slice.h ) s.files += %w( src/core/lib/slice/static_slice.h )
s.files += %w( src/core/lib/surface/api_trace.cc ) s.files += %w( src/core/lib/surface/api_trace.cc )
s.files += %w( src/core/lib/surface/api_trace.h ) s.files += %w( src/core/lib/surface/api_trace.h )
s.files += %w( src/core/lib/surface/builtins.cc )
s.files += %w( src/core/lib/surface/builtins.h )
s.files += %w( src/core/lib/surface/byte_buffer.cc ) s.files += %w( src/core/lib/surface/byte_buffer.cc )
s.files += %w( src/core/lib/surface/byte_buffer_reader.cc ) s.files += %w( src/core/lib/surface/byte_buffer_reader.cc )
s.files += %w( src/core/lib/surface/call.cc ) s.files += %w( src/core/lib/surface/call.cc )

2
grpc.gyp generated

@ -992,6 +992,7 @@
'src/core/lib/slice/slice_string_helpers.cc', 'src/core/lib/slice/slice_string_helpers.cc',
'src/core/lib/slice/static_slice.cc', 'src/core/lib/slice/static_slice.cc',
'src/core/lib/surface/api_trace.cc', 'src/core/lib/surface/api_trace.cc',
'src/core/lib/surface/builtins.cc',
'src/core/lib/surface/byte_buffer.cc', 'src/core/lib/surface/byte_buffer.cc',
'src/core/lib/surface/byte_buffer_reader.cc', 'src/core/lib/surface/byte_buffer_reader.cc',
'src/core/lib/surface/call.cc', 'src/core/lib/surface/call.cc',
@ -1399,6 +1400,7 @@
'src/core/lib/slice/slice_string_helpers.cc', 'src/core/lib/slice/slice_string_helpers.cc',
'src/core/lib/slice/static_slice.cc', 'src/core/lib/slice/static_slice.cc',
'src/core/lib/surface/api_trace.cc', 'src/core/lib/surface/api_trace.cc',
'src/core/lib/surface/builtins.cc',
'src/core/lib/surface/byte_buffer.cc', 'src/core/lib/surface/byte_buffer.cc',
'src/core/lib/surface/byte_buffer_reader.cc', 'src/core/lib/surface/byte_buffer_reader.cc',
'src/core/lib/surface/call.cc', 'src/core/lib/surface/call.cc',

2
package.xml generated

@ -1162,6 +1162,8 @@
<file baseinstalldir="/" name="src/core/lib/slice/static_slice.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/slice/static_slice.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/api_trace.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/surface/api_trace.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/api_trace.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/surface/api_trace.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/builtins.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/builtins.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/byte_buffer.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/surface/byte_buffer.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/byte_buffer_reader.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/surface/byte_buffer_reader.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/call.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/surface/call.cc" role="src" />

@ -37,12 +37,7 @@
#include "src/core/ext/filters/client_channel/retry_service_config.h" #include "src/core/ext/filters/client_channel/retry_service_config.h"
#include "src/core/ext/filters/client_channel/retry_throttle.h" #include "src/core/ext/filters/client_channel/retry_throttle.h"
#include "src/core/ext/filters/client_channel/service_config_parser.h" #include "src/core/ext/filters/client_channel/service_config_parser.h"
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/config/core_configuration.h"
static bool append_filter(grpc_channel_stack_builder* builder, void* arg) {
return grpc_channel_stack_builder_append_filter(
builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
}
void grpc_client_channel_init(void) { void grpc_client_channel_init(void) {
grpc_core::ServiceConfigParser::Init(); grpc_core::ServiceConfigParser::Init();
@ -54,16 +49,11 @@ void grpc_client_channel_init(void) {
grpc_core::ProxyMapperRegistry::Init(); grpc_core::ProxyMapperRegistry::Init();
grpc_core::RegisterHttpProxyMapper(); grpc_core::RegisterHttpProxyMapper();
grpc_core::GlobalSubchannelPool::Init(); grpc_core::GlobalSubchannelPool::Init();
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter,
const_cast<grpc_channel_filter*>(
&grpc_core::ClientChannel::kFilterVtable));
grpc_client_channel_global_init_backup_polling(); grpc_client_channel_global_init_backup_polling();
} }
void grpc_client_channel_shutdown(void) { void grpc_client_channel_shutdown(void) {
grpc_core::GlobalSubchannelPool::Shutdown(); grpc_core::GlobalSubchannelPool::Shutdown();
grpc_channel_init_shutdown();
grpc_core::ProxyMapperRegistry::Shutdown(); grpc_core::ProxyMapperRegistry::Shutdown();
grpc_core::internal::ServerRetryThrottleMap::Shutdown(); grpc_core::internal::ServerRetryThrottleMap::Shutdown();
grpc_core::ResolverRegistry::Builder::ShutdownRegistry(); grpc_core::ResolverRegistry::Builder::ShutdownRegistry();
@ -75,6 +65,13 @@ namespace grpc_core {
void BuildClientChannelConfiguration(CoreConfiguration::Builder* builder) { void BuildClientChannelConfiguration(CoreConfiguration::Builder* builder) {
RegisterHttpConnectHandshaker(builder); RegisterHttpConnectHandshaker(builder);
builder->channel_init()->RegisterStage(
GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
[](grpc_channel_stack_builder* builder) {
return grpc_channel_stack_builder_append_filter(
builder, &grpc_core::ClientChannel::kFilterVtable, nullptr,
nullptr);
});
} }
} // namespace grpc_core } // namespace grpc_core

@ -88,6 +88,8 @@
#include "src/core/lib/backoff/backoff.h" #include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/manual_constructor.h" #include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/gprpp/memory.h" #include "src/core/lib/gprpp/memory.h"
@ -100,7 +102,6 @@
#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/surface/call.h" #include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/static_metadata.h"
#define GRPC_GRPCLB_INITIAL_CONNECT_BACKOFF_SECONDS 1 #define GRPC_GRPCLB_INITIAL_CONNECT_BACKOFF_SECONDS 1
@ -1744,39 +1745,34 @@ class GrpcLbFactory : public LoadBalancingPolicyFactory {
// Plugin registration // Plugin registration
// //
namespace {
// Only add client_load_reporting filter if the grpclb LB policy is used.
bool maybe_add_client_load_reporting_filter(grpc_channel_stack_builder* builder,
void* arg) {
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
const grpc_arg* channel_arg =
grpc_channel_args_find(args, GRPC_ARG_LB_POLICY_NAME);
if (channel_arg != nullptr && channel_arg->type == GRPC_ARG_STRING &&
strcmp(channel_arg->value.string, "grpclb") == 0) {
// TODO(roth): When we get around to re-attempting
// https://github.com/grpc/grpc/pull/16214, we should try to keep
// this filter at the very top of the subchannel stack, since that
// will minimize the number of metadata elements that the filter
// needs to iterate through to find the ClientStats object.
return grpc_channel_stack_builder_prepend_filter(
builder, static_cast<const grpc_channel_filter*>(arg), nullptr,
nullptr);
}
return true;
}
} // namespace
void grpc_lb_policy_grpclb_init() { void grpc_lb_policy_grpclb_init() {
grpc_core::LoadBalancingPolicyRegistry::Builder:: grpc_core::LoadBalancingPolicyRegistry::Builder::
RegisterLoadBalancingPolicyFactory( RegisterLoadBalancingPolicyFactory(
absl::make_unique<grpc_core::GrpcLbFactory>()); absl::make_unique<grpc_core::GrpcLbFactory>());
grpc_channel_init_register_stage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_client_load_reporting_filter,
const_cast<grpc_channel_filter*>(&grpc_client_load_reporting_filter));
} }
void grpc_lb_policy_grpclb_shutdown() {} void grpc_lb_policy_grpclb_shutdown() {}
namespace grpc_core {
void RegisterGrpcLbLoadReportingFilter(CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
[](grpc_channel_stack_builder* builder) {
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
const grpc_arg* channel_arg =
grpc_channel_args_find(args, GRPC_ARG_LB_POLICY_NAME);
if (channel_arg != nullptr && channel_arg->type == GRPC_ARG_STRING &&
strcmp(channel_arg->value.string, "grpclb") == 0) {
// TODO(roth): When we get around to re-attempting
// https://github.com/grpc/grpc/pull/16214, we should try to keep
// this filter at the very top of the subchannel stack, since that
// will minimize the number of metadata elements that the filter
// needs to iterate through to find the ClientStats object.
return grpc_channel_stack_builder_prepend_filter(
builder, &grpc_client_load_reporting_filter, nullptr, nullptr);
}
return true;
});
}
} // namespace grpc_core

@ -23,7 +23,7 @@
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/config/core_configuration.h"
namespace grpc_core { namespace grpc_core {
@ -117,27 +117,23 @@ const grpc_channel_filter ServiceConfigChannelArgFilter = {
grpc_channel_next_get_info, grpc_channel_next_get_info,
"service_config_channel_arg"}; "service_config_channel_arg"};
bool maybe_add_service_config_channel_arg_filter(
grpc_channel_stack_builder* builder, void* /* arg */) {
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (grpc_channel_args_want_minimal_stack(channel_args) ||
grpc_channel_args_find_string(channel_args, GRPC_ARG_SERVICE_CONFIG) ==
nullptr) {
return true;
}
return grpc_channel_stack_builder_prepend_filter(
builder, &ServiceConfigChannelArgFilter, nullptr, nullptr);
}
} // namespace } // namespace
} // namespace grpc_core void RegisterServiceConfigChannelArgFilter(
CoreConfiguration::Builder* builder) {
void grpc_service_config_channel_arg_filter_init(void) { builder->channel_init()->RegisterStage(
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_core::maybe_add_service_config_channel_arg_filter, nullptr); [](grpc_channel_stack_builder* builder) {
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (grpc_channel_args_want_minimal_stack(channel_args) ||
grpc_channel_args_find_string(channel_args,
GRPC_ARG_SERVICE_CONFIG) == nullptr) {
return true;
}
return grpc_channel_stack_builder_prepend_filter(
builder, &ServiceConfigChannelArgFilter, nullptr, nullptr);
});
} }
void grpc_service_config_channel_arg_filter_shutdown(void) {} } // namespace grpc_core

@ -41,6 +41,7 @@
#include "src/core/lib/backoff/backoff.h" #include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/stats.h"
#include "src/core/lib/gpr/alloc.h" #include "src/core/lib/gpr/alloc.h"
#include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/debug_location.h"
@ -50,7 +51,6 @@
#include "src/core/lib/profiling/timers.h" #include "src/core/lib/profiling/timers.h"
#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/connectivity_state.h"
#include "src/core/lib/transport/error_utils.h" #include "src/core/lib/transport/error_utils.h"
#include "src/core/lib/transport/status_metadata.h" #include "src/core/lib/transport/status_metadata.h"
@ -1036,7 +1036,8 @@ bool Subchannel::PublishTransportLocked() {
builder, connecting_result_.channel_args); builder, connecting_result_.channel_args);
grpc_channel_stack_builder_set_transport(builder, grpc_channel_stack_builder_set_transport(builder,
connecting_result_.transport); connecting_result_.transport);
if (!grpc_channel_init_create_stack(builder, GRPC_CLIENT_SUBCHANNEL)) { if (!CoreConfiguration::Get().channel_init().CreateStack(
builder, GRPC_CLIENT_SUBCHANNEL)) {
grpc_channel_stack_builder_destroy(builder); grpc_channel_stack_builder_destroy(builder);
return false; return false;
} }

@ -24,8 +24,8 @@
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/iomgr/timer.h" #include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/http2_errors.h" #include "src/core/lib/transport/http2_errors.h"
// TODO(juanlishen): The idle filter is disabled in client channel by default // TODO(juanlishen): The idle filter is disabled in client channel by default
@ -422,26 +422,21 @@ const grpc_channel_filter grpc_client_idle_filter = {
grpc_channel_next_get_info, grpc_channel_next_get_info,
"client_idle"}; "client_idle"};
static bool MaybeAddClientIdleFilter(grpc_channel_stack_builder* builder,
void* /*arg*/) {
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (!grpc_channel_args_want_minimal_stack(channel_args) &&
GetClientIdleTimeout(channel_args) != INT_MAX) {
return grpc_channel_stack_builder_prepend_filter(
builder, &grpc_client_idle_filter, nullptr, nullptr);
} else {
return true;
}
}
} // namespace } // namespace
} // namespace grpc_core
void grpc_client_idle_filter_init(void) { void RegisterClientIdleFilter(CoreConfiguration::Builder* builder) {
grpc_channel_init_register_stage( builder->channel_init()->RegisterStage(
GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_core::MaybeAddClientIdleFilter, nullptr); [](grpc_channel_stack_builder* builder) {
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (!grpc_channel_args_want_minimal_stack(channel_args) &&
GetClientIdleTimeout(channel_args) != INT_MAX) {
return grpc_channel_stack_builder_prepend_filter(
builder, &grpc_client_idle_filter, nullptr, nullptr);
} else {
return true;
}
});
} }
} // namespace grpc_core
void grpc_client_idle_filter_shutdown(void) {}

@ -27,10 +27,10 @@
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gprpp/memory.h" #include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/timer.h" #include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/channel_init.h"
namespace grpc_core { namespace grpc_core {
@ -370,25 +370,22 @@ bool grpc_deadline_checking_enabled(const grpc_channel_args* channel_args) {
!grpc_channel_args_want_minimal_stack(channel_args)); !grpc_channel_args_want_minimal_stack(channel_args));
} }
static bool maybe_add_deadline_filter(grpc_channel_stack_builder* builder, namespace grpc_core {
void* arg) { void RegisterDeadlineFilter(CoreConfiguration::Builder* builder) {
return grpc_deadline_checking_enabled( auto register_filter = [builder](grpc_channel_stack_type type,
grpc_channel_stack_builder_get_channel_arguments(builder)) const grpc_channel_filter* filter) {
? grpc_channel_stack_builder_prepend_filter( builder->channel_init()->RegisterStage(
builder, static_cast<const grpc_channel_filter*>(arg), type, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
nullptr, nullptr) [filter](grpc_channel_stack_builder* builder) {
: true; if (grpc_deadline_checking_enabled(
} grpc_channel_stack_builder_get_channel_arguments(builder))) {
return grpc_channel_stack_builder_prepend_filter(builder, filter,
void grpc_deadline_filter_init(void) { nullptr, nullptr);
grpc_channel_init_register_stage( }
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, return true;
maybe_add_deadline_filter, });
const_cast<grpc_channel_filter*>(&grpc_client_deadline_filter)); };
grpc_channel_init_register_stage( register_filter(GRPC_CLIENT_DIRECT_CHANNEL, &grpc_client_deadline_filter);
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, register_filter(GRPC_SERVER_CHANNEL, &grpc_server_deadline_filter);
maybe_add_deadline_filter,
const_cast<grpc_channel_filter*>(&grpc_server_deadline_filter));
} }
} // namespace grpc_core
void grpc_deadline_filter_shutdown(void) {}

@ -29,11 +29,12 @@
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/surface/call.h" #include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/surface/channel_stack_type.h" #include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/static_metadata.h"
@ -132,8 +133,7 @@ const grpc_channel_filter grpc_client_authority_filter = {
grpc_channel_next_get_info, grpc_channel_next_get_info,
"authority"}; "authority"};
static bool add_client_authority_filter(grpc_channel_stack_builder* builder, static bool add_client_authority_filter(grpc_channel_stack_builder* builder) {
void* arg) {
const grpc_channel_args* channel_args = const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder); grpc_channel_stack_builder_get_channel_arguments(builder);
const grpc_arg* disable_client_authority_filter_arg = grpc_channel_args_find( const grpc_arg* disable_client_authority_filter_arg = grpc_channel_args_find(
@ -146,16 +146,14 @@ static bool add_client_authority_filter(grpc_channel_stack_builder* builder,
} }
} }
return grpc_channel_stack_builder_prepend_filter( return grpc_channel_stack_builder_prepend_filter(
builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr); builder, &grpc_client_authority_filter, nullptr, nullptr);
} }
void grpc_client_authority_filter_init(void) { namespace grpc_core {
grpc_channel_init_register_stage( void RegisterClientAuthorityFilter(CoreConfiguration::Builder* builder) {
GRPC_CLIENT_SUBCHANNEL, INT_MAX, add_client_authority_filter, builder->channel_init()->RegisterStage(GRPC_CLIENT_SUBCHANNEL, INT_MAX,
const_cast<grpc_channel_filter*>(&grpc_client_authority_filter)); add_client_authority_filter);
grpc_channel_init_register_stage( builder->channel_init()->RegisterStage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX,
GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, add_client_authority_filter, add_client_authority_filter);
const_cast<grpc_channel_filter*>(&grpc_client_authority_filter));
} }
} // namespace grpc_core
void grpc_client_authority_filter_shutdown(void) {}

@ -25,84 +25,66 @@
#include "src/core/ext/filters/http/message_compress/message_decompress_filter.h" #include "src/core/ext/filters/http/message_compress/message_decompress_filter.h"
#include "src/core/ext/filters/http/server/http_server_filter.h" #include "src/core/ext/filters/http/server/http_server_filter.h"
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/call.h" #include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/transport_impl.h" #include "src/core/lib/transport/transport_impl.h"
struct optional_filter {
const grpc_channel_filter* filter;
const char* control_channel_arg;
};
static optional_filter compress_filter = {
&grpc_message_compress_filter, GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION};
static optional_filter decompress_filter = {
&grpc_core::MessageDecompressFilter,
GRPC_ARG_ENABLE_PER_MESSAGE_DECOMPRESSION};
static bool is_building_http_like_transport( static bool is_building_http_like_transport(
grpc_channel_stack_builder* builder) { grpc_channel_stack_builder* builder) {
grpc_transport* t = grpc_channel_stack_builder_get_transport(builder); grpc_transport* t = grpc_channel_stack_builder_get_transport(builder);
return t != nullptr && strstr(t->vtable->name, "http"); return t != nullptr && strstr(t->vtable->name, "http");
} }
template <bool enable_in_minimal_stack> namespace grpc_core {
static bool maybe_add_optional_filter(grpc_channel_stack_builder* builder, void RegisterHttpFilters(CoreConfiguration::Builder* builder) {
void* arg) { auto optional = [builder](grpc_channel_stack_type channel_type,
if (!is_building_http_like_transport(builder)) return true; bool enable_in_minimal_stack,
optional_filter* filtarg = static_cast<optional_filter*>(arg); const char* control_channel_arg,
const grpc_channel_args* channel_args = const grpc_channel_filter* filter) {
grpc_channel_stack_builder_get_channel_arguments(builder); builder->channel_init()->RegisterStage(
bool enable = grpc_channel_arg_get_bool( channel_type, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_channel_args_find(channel_args, filtarg->control_channel_arg), [enable_in_minimal_stack, control_channel_arg,
enable_in_minimal_stack || filter](grpc_channel_stack_builder* builder) {
!grpc_channel_args_want_minimal_stack(channel_args)); if (!is_building_http_like_transport(builder)) return true;
return enable ? grpc_channel_stack_builder_prepend_filter( const grpc_channel_args* channel_args =
builder, filtarg->filter, nullptr, nullptr) grpc_channel_stack_builder_get_channel_arguments(builder);
: true; bool enable = grpc_channel_arg_get_bool(
} grpc_channel_args_find(channel_args, control_channel_arg),
enable_in_minimal_stack ||
static bool maybe_add_required_filter(grpc_channel_stack_builder* builder, !grpc_channel_args_want_minimal_stack(channel_args));
void* arg) { if (!enable) return true;
return is_building_http_like_transport(builder) return grpc_channel_stack_builder_prepend_filter(builder, filter,
? grpc_channel_stack_builder_prepend_filter( nullptr, nullptr);
builder, static_cast<const grpc_channel_filter*>(arg), });
nullptr, nullptr) };
: true; auto required = [builder](grpc_channel_stack_type channel_type,
} const grpc_channel_filter* filter) {
builder->channel_init()->RegisterStage(
void grpc_http_filters_init(void) { channel_type, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_channel_init_register_stage( [filter](grpc_channel_stack_builder* builder) {
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, if (!is_building_http_like_transport(builder)) return true;
maybe_add_optional_filter<false>, &compress_filter); return grpc_channel_stack_builder_prepend_filter(builder, filter,
grpc_channel_init_register_stage( nullptr, nullptr);
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, });
maybe_add_optional_filter<false>, &compress_filter); };
grpc_channel_init_register_stage( optional(GRPC_CLIENT_SUBCHANNEL, false,
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION,
maybe_add_optional_filter<false>, &compress_filter); &grpc_message_compress_filter);
grpc_channel_init_register_stage( optional(GRPC_CLIENT_DIRECT_CHANNEL, false,
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION,
maybe_add_optional_filter<true>, &decompress_filter); &grpc_message_compress_filter);
grpc_channel_init_register_stage( optional(GRPC_SERVER_CHANNEL, false, GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION,
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, &grpc_message_compress_filter);
maybe_add_optional_filter<true>, &decompress_filter); optional(GRPC_CLIENT_SUBCHANNEL, true,
grpc_channel_init_register_stage( GRPC_ARG_ENABLE_PER_MESSAGE_DECOMPRESSION,
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, &grpc_core::MessageDecompressFilter);
maybe_add_optional_filter<true>, &decompress_filter); optional(GRPC_CLIENT_DIRECT_CHANNEL, true,
grpc_channel_init_register_stage( GRPC_ARG_ENABLE_PER_MESSAGE_DECOMPRESSION,
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, &grpc_core::MessageDecompressFilter);
maybe_add_required_filter, optional(GRPC_SERVER_CHANNEL, true, GRPC_ARG_ENABLE_PER_MESSAGE_DECOMPRESSION,
const_cast<grpc_channel_filter*>(&grpc_http_client_filter)); &grpc_core::MessageDecompressFilter);
grpc_channel_init_register_stage( required(GRPC_CLIENT_SUBCHANNEL, &grpc_http_client_filter);
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, required(GRPC_CLIENT_DIRECT_CHANNEL, &grpc_http_client_filter);
maybe_add_required_filter, required(GRPC_SERVER_CHANNEL, &grpc_http_server_filter);
const_cast<grpc_channel_filter*>(&grpc_http_client_filter));
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_required_filter,
const_cast<grpc_channel_filter*>(&grpc_http_server_filter));
} }
} // namespace grpc_core
void grpc_http_filters_shutdown(void) {}

@ -25,8 +25,8 @@
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/iomgr/timer.h" #include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/http2_errors.h" #include "src/core/lib/transport/http2_errors.h"
/* If these settings change, make sure that we are not sending a GOAWAY for /* If these settings change, make sure that we are not sending a GOAWAY for
@ -534,29 +534,27 @@ const grpc_channel_filter grpc_max_age_filter = {
grpc_channel_next_get_info, grpc_channel_next_get_info,
"max_age"}; "max_age"};
static bool maybe_add_max_age_filter(grpc_channel_stack_builder* builder, namespace grpc_core {
void* /*arg*/) { void RegisterMaxAgeFilter(CoreConfiguration::Builder* builder) {
const grpc_channel_args* channel_args = builder->channel_init()->RegisterStage(
grpc_channel_stack_builder_get_channel_arguments(builder); GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
bool enable = [](grpc_channel_stack_builder* builder) {
grpc_channel_arg_get_integer( const grpc_channel_args* channel_args =
grpc_channel_args_find(channel_args, GRPC_ARG_MAX_CONNECTION_AGE_MS), grpc_channel_stack_builder_get_channel_arguments(builder);
MAX_CONNECTION_AGE_INTEGER_OPTIONS) != INT_MAX || bool enable = grpc_channel_arg_get_integer(
grpc_channel_arg_get_integer( grpc_channel_args_find(
grpc_channel_args_find(channel_args, GRPC_ARG_MAX_CONNECTION_IDLE_MS), channel_args, GRPC_ARG_MAX_CONNECTION_AGE_MS),
MAX_CONNECTION_IDLE_INTEGER_OPTIONS) != INT_MAX; MAX_CONNECTION_AGE_INTEGER_OPTIONS) != INT_MAX ||
if (enable) { grpc_channel_arg_get_integer(
return grpc_channel_stack_builder_prepend_filter( grpc_channel_args_find(
builder, &grpc_max_age_filter, nullptr, nullptr); channel_args, GRPC_ARG_MAX_CONNECTION_IDLE_MS),
} else { MAX_CONNECTION_IDLE_INTEGER_OPTIONS) != INT_MAX;
return true; if (enable) {
} return grpc_channel_stack_builder_prepend_filter(
} builder, &grpc_max_age_filter, nullptr, nullptr);
} else {
void grpc_max_age_filter_init(void) { return true;
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, }
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, });
maybe_add_max_age_filter, nullptr);
} }
} // namespace grpc_core
void grpc_max_age_filter_shutdown(void) {}

@ -31,11 +31,11 @@
#include "src/core/ext/filters/client_channel/service_config_call_data.h" #include "src/core/ext/filters/client_channel/service_config_call_data.h"
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/surface/call.h" #include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel_init.h"
static void recv_message_ready(void* user_data, grpc_error_handle error); static void recv_message_ready(void* user_data, grpc_error_handle error);
static void recv_trailing_metadata_ready(void* user_data, static void recv_trailing_metadata_ready(void* user_data,
@ -344,7 +344,7 @@ const grpc_channel_filter grpc_message_size_filter = {
// Used for GRPC_CLIENT_SUBCHANNEL // Used for GRPC_CLIENT_SUBCHANNEL
static bool maybe_add_message_size_filter_subchannel( static bool maybe_add_message_size_filter_subchannel(
grpc_channel_stack_builder* builder, void* /*arg*/) { grpc_channel_stack_builder* builder) {
const grpc_channel_args* channel_args = const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder); grpc_channel_stack_builder_get_channel_arguments(builder);
if (grpc_channel_args_want_minimal_stack(channel_args)) { if (grpc_channel_args_want_minimal_stack(channel_args)) {
@ -356,8 +356,7 @@ static bool maybe_add_message_size_filter_subchannel(
// Used for GRPC_CLIENT_DIRECT_CHANNEL and GRPC_SERVER_CHANNEL. Adds the filter // Used for GRPC_CLIENT_DIRECT_CHANNEL and GRPC_SERVER_CHANNEL. Adds the filter
// only if message size limits or service config is specified. // only if message size limits or service config is specified.
static bool maybe_add_message_size_filter(grpc_channel_stack_builder* builder, static bool maybe_add_message_size_filter(grpc_channel_stack_builder* builder) {
void* /*arg*/) {
const grpc_channel_args* channel_args = const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder); grpc_channel_stack_builder_get_channel_arguments(builder);
if (grpc_channel_args_want_minimal_stack(channel_args)) { if (grpc_channel_args_want_minimal_stack(channel_args)) {
@ -384,16 +383,21 @@ static bool maybe_add_message_size_filter(grpc_channel_stack_builder* builder,
} }
void grpc_message_size_filter_init(void) { void grpc_message_size_filter_init(void) {
grpc_channel_init_register_stage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_message_size_filter_subchannel, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_message_size_filter, nullptr);
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_message_size_filter, nullptr);
grpc_core::MessageSizeParser::Register(); grpc_core::MessageSizeParser::Register();
} }
void grpc_message_size_filter_shutdown(void) {} void grpc_message_size_filter_shutdown(void) {}
namespace grpc_core {
void RegisterMessageSizeFilter(CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_message_size_filter_subchannel);
builder->channel_init()->RegisterStage(GRPC_CLIENT_DIRECT_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_message_size_filter);
builder->channel_init()->RegisterStage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_message_size_filter);
}
} // namespace grpc_core

@ -24,7 +24,7 @@
#include "src/core/ext/filters/workarounds/workaround_utils.h" #include "src/core/ext/filters/workarounds/workaround_utils.h"
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/metadata.h"
namespace { namespace {
@ -185,7 +185,7 @@ const grpc_channel_filter grpc_workaround_cronet_compression_filter = {
"workaround_cronet_compression"}; "workaround_cronet_compression"};
static bool register_workaround_cronet_compression( static bool register_workaround_cronet_compression(
grpc_channel_stack_builder* builder, void* /*arg*/) { grpc_channel_stack_builder* builder) {
const grpc_channel_args* channel_args = const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder); grpc_channel_stack_builder_get_channel_arguments(builder);
const grpc_arg* a = grpc_channel_args_find( const grpc_arg* a = grpc_channel_args_find(
@ -201,11 +201,17 @@ static bool register_workaround_cronet_compression(
} }
void grpc_workaround_cronet_compression_filter_init(void) { void grpc_workaround_cronet_compression_filter_init(void) {
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, GRPC_WORKAROUND_PRIORITY_HIGH,
register_workaround_cronet_compression, nullptr);
grpc_register_workaround(GRPC_WORKAROUND_ID_CRONET_COMPRESSION, grpc_register_workaround(GRPC_WORKAROUND_ID_CRONET_COMPRESSION,
parse_user_agent); parse_user_agent);
} }
void grpc_workaround_cronet_compression_filter_shutdown(void) {} void grpc_workaround_cronet_compression_filter_shutdown(void) {}
namespace grpc_core {
void RegisterWorkaroundCronetCompressionFilter(
CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(
GRPC_SERVER_CHANNEL, GRPC_WORKAROUND_PRIORITY_HIGH,
register_workaround_cronet_compression);
}
} // namespace grpc_core

@ -47,7 +47,6 @@ grpc_cc_library(
"//:grpc", "//:grpc",
"//:grpc++_base", "//:grpc++_base",
"//:grpc_base", "//:grpc_base",
"//:grpc_base_c",
"//:grpc_codegen", "//:grpc_codegen",
"//src/core/ext/transport/binder/transport:binder_transport", "//src/core/ext/transport/binder/transport:binder_transport",
"//src/core/ext/transport/binder/utils:transport_stream_receiver", "//src/core/ext/transport/binder/utils:transport_stream_receiver",
@ -68,7 +67,6 @@ grpc_cc_library(
"//:grpc", "//:grpc",
"//:grpc++_base", "//:grpc++_base",
"//:grpc_base", "//:grpc_base",
"//:grpc_base_c",
"//:grpc_codegen", "//:grpc_codegen",
"//src/core/ext/transport/binder/transport:binder_transport", "//src/core/ext/transport/binder/transport:binder_transport",
"//src/core/ext/transport/binder/wire_format:binder", "//src/core/ext/transport/binder/wire_format:binder",

@ -42,7 +42,7 @@ grpc_cc_library(
deps = [ deps = [
"//:gpr_platform", "//:gpr_platform",
"//:grpc++_internals", "//:grpc++_internals",
"//:grpc_base_c", "//:grpc_base",
"//src/core/ext/transport/binder/transport:binder_transport", "//src/core/ext/transport/binder/transport:binder_transport",
"//src/core/ext/transport/binder/wire_format:binder", "//src/core/ext/transport/binder/wire_format:binder",
"//src/core/ext/transport/binder/wire_format:binder_android", "//src/core/ext/transport/binder/wire_format:binder_android",

@ -40,7 +40,7 @@ grpc_cc_library(
deps = [ deps = [
"//:gpr_base", "//:gpr_base",
"//:gpr_platform", "//:gpr_platform",
"//:grpc_base_c", "//:grpc_base",
"//:slice_refcount", "//:slice_refcount",
"//src/core/ext/transport/binder/utils:transport_stream_receiver", "//src/core/ext/transport/binder/utils:transport_stream_receiver",
"//src/core/ext/transport/binder/wire_format:binder", "//src/core/ext/transport/binder/wire_format:binder",

@ -32,7 +32,6 @@
#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/surface/server.h" #include "src/core/lib/surface/server.h"
#include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/connectivity_state.h"
#include "src/core/lib/transport/error_utils.h" #include "src/core/lib/transport/error_utils.h"

@ -55,7 +55,6 @@
#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/surface/call.h" #include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/static_metadata.h"
#define GRPC_XDS_INITIAL_CONNECT_BACKOFF_SECONDS 1 #define GRPC_XDS_INITIAL_CONNECT_BACKOFF_SECONDS 1

@ -232,9 +232,7 @@ static void bind_transport(grpc_channel_stack* channel_stack,
grpc_transport_stream_size(static_cast<grpc_transport*>(t)); grpc_transport_stream_size(static_cast<grpc_transport*>(t));
} }
bool grpc_add_connected_filter(grpc_channel_stack_builder* builder, bool grpc_add_connected_filter(grpc_channel_stack_builder* builder) {
void* arg_must_be_null) {
GPR_ASSERT(arg_must_be_null == nullptr);
grpc_transport* t = grpc_channel_stack_builder_get_transport(builder); grpc_transport* t = grpc_channel_stack_builder_get_transport(builder);
GPR_ASSERT(t != nullptr); GPR_ASSERT(t != nullptr);
return grpc_channel_stack_builder_append_filter( return grpc_channel_stack_builder_append_filter(

@ -25,8 +25,7 @@
extern const grpc_channel_filter grpc_connected_filter; extern const grpc_channel_filter grpc_connected_filter;
bool grpc_add_connected_filter(grpc_channel_stack_builder* builder, bool grpc_add_connected_filter(grpc_channel_stack_builder* builder);
void* arg_must_be_null);
/* Debug helper to dig the transport stream out of a call element */ /* Debug helper to dig the transport stream out of a call element */
grpc_stream* grpc_connected_channel_get_stream(grpc_call_element* elem); grpc_stream* grpc_connected_channel_get_stream(grpc_call_element* elem);

@ -12,13 +12,17 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <grpc/impl/codegen/port_platform.h> #include <grpc/support/port_platform.h>
#include "src/core/lib/config/core_configuration.h" #include "src/core/lib/config/core_configuration.h"
#include <grpc/support/log.h>
namespace grpc_core { namespace grpc_core {
std::atomic<CoreConfiguration*> CoreConfiguration::config_{nullptr}; std::atomic<CoreConfiguration*> CoreConfiguration::config_{nullptr};
std::atomic<CoreConfiguration::RegisteredBuilder*> CoreConfiguration::builders_{
nullptr};
CoreConfiguration::Builder::Builder() = default; CoreConfiguration::Builder::Builder() = default;
@ -27,11 +31,42 @@ CoreConfiguration* CoreConfiguration::Builder::Build() {
} }
CoreConfiguration::CoreConfiguration(Builder* builder) CoreConfiguration::CoreConfiguration(Builder* builder)
: handshaker_registry_(builder->handshaker_registry_.Build()) {} : channel_init_(builder->channel_init_.Build()),
handshaker_registry_(builder->handshaker_registry_.Build()) {}
void CoreConfiguration::RegisterBuilder(std::function<void(Builder*)> builder) {
GPR_ASSERT(config_.load(std::memory_order_relaxed) == nullptr &&
"CoreConfiguration was already instantiated before builder "
"registration was completed");
RegisteredBuilder* n = new RegisteredBuilder();
n->builder = std::move(builder);
n->next = builders_.load(std::memory_order_relaxed);
while (!builders_.compare_exchange_weak(n->next, n, std::memory_order_acq_rel,
std::memory_order_relaxed)) {
}
GPR_ASSERT(config_.load(std::memory_order_relaxed) == nullptr &&
"CoreConfiguration was already instantiated before builder "
"registration was completed");
}
const CoreConfiguration& CoreConfiguration::BuildNewAndMaybeSet() { const CoreConfiguration& CoreConfiguration::BuildNewAndMaybeSet() {
// Construct builder, pass it up to code that knows about build configuration // Construct builder, pass it up to code that knows about build configuration
Builder builder; Builder builder;
// The linked list of builders stores things in reverse registration order.
// To get things registered as systems relying on this expect however, we
// actually need to run things in forward registration order, so we iterate
// once over the linked list to build a vector of builders, and then iterate
// over said vector in reverse to actually run the builders.
std::vector<RegisteredBuilder*> registered_builders;
for (RegisteredBuilder* b = builders_.load(std::memory_order_acquire);
b != nullptr; b = b->next) {
registered_builders.push_back(b);
}
for (auto it = registered_builders.rbegin(); it != registered_builders.rend();
++it) {
(*it)->builder(&builder);
}
// Finally, call the built in configuration builder.
BuildCoreConfiguration(&builder); BuildCoreConfiguration(&builder);
// Use builder to construct a confguration // Use builder to construct a confguration
CoreConfiguration* p = builder.Build(); CoreConfiguration* p = builder.Build();
@ -49,6 +84,13 @@ const CoreConfiguration& CoreConfiguration::BuildNewAndMaybeSet() {
void CoreConfiguration::Reset() { void CoreConfiguration::Reset() {
delete config_.exchange(nullptr, std::memory_order_acquire); delete config_.exchange(nullptr, std::memory_order_acquire);
RegisteredBuilder* builder =
builders_.exchange(nullptr, std::memory_order_acquire);
while (builder != nullptr) {
RegisteredBuilder* next = builder->next;
delete builder;
builder = next;
}
} }
} // namespace grpc_core } // namespace grpc_core

@ -20,6 +20,7 @@
#include <atomic> #include <atomic>
#include "src/core/lib/channel/handshaker_registry.h" #include "src/core/lib/channel/handshaker_registry.h"
#include "src/core/lib/surface/channel_init.h"
namespace grpc_core { namespace grpc_core {
@ -34,6 +35,8 @@ class CoreConfiguration {
// their configuration and assemble the published CoreConfiguration. // their configuration and assemble the published CoreConfiguration.
class Builder { class Builder {
public: public:
ChannelInit::Builder* channel_init() { return &channel_init_; }
HandshakerRegistry::Builder* handshaker_registry() { HandshakerRegistry::Builder* handshaker_registry() {
return &handshaker_registry_; return &handshaker_registry_;
} }
@ -41,6 +44,7 @@ class CoreConfiguration {
private: private:
friend class CoreConfiguration; friend class CoreConfiguration;
ChannelInit::Builder channel_init_;
HandshakerRegistry::Builder handshaker_registry_; HandshakerRegistry::Builder handshaker_registry_;
Builder(); Builder();
@ -77,13 +81,38 @@ class CoreConfiguration {
delete config_.exchange(p, std::memory_order_release); delete config_.exchange(p, std::memory_order_release);
} }
// Attach a registration function globally.
// Each registration function is called *in addition to*
// BuildCoreConfiguration for the default core configuration. When using
// BuildSpecialConfiguration, one can use CallRegisteredBuilders to call them.
// Must be called before a configuration is built.
static void RegisterBuilder(std::function<void(Builder*)> builder);
// Call all registered builders.
// See RegisterBuilder for why you might want to call this.
static void CallRegisteredBuilders(Builder* builder);
// Drop the core configuration. Users must ensure no other threads are // Drop the core configuration. Users must ensure no other threads are
// accessing the configuration. // accessing the configuration.
// Clears any dynamically registered builders. // Clears any dynamically registered builders.
static void Reset(); static void Reset();
// Helper for tests: Reset the configuration, build a special one, run some
// code, and then reset the configuration again.
// Templatized to be sure no codegen in normal builds.
template <typename BuildFunc, typename RunFunc>
static void RunWithSpecialConfiguration(BuildFunc build_configuration,
RunFunc code_to_run) {
Reset();
BuildSpecialConfiguration(build_configuration);
code_to_run();
Reset();
}
// Accessors // Accessors
const ChannelInit& channel_init() const { return channel_init_; }
const HandshakerRegistry& handshaker_registry() const { const HandshakerRegistry& handshaker_registry() const {
return handshaker_registry_; return handshaker_registry_;
} }
@ -91,13 +120,22 @@ class CoreConfiguration {
private: private:
explicit CoreConfiguration(Builder* builder); explicit CoreConfiguration(Builder* builder);
// Stores a builder for RegisterBuilder
struct RegisteredBuilder {
std::function<void(Builder*)> builder;
RegisteredBuilder* next;
};
// Create a new CoreConfiguration, and either set it or throw it away. // Create a new CoreConfiguration, and either set it or throw it away.
// We allow multiple CoreConfiguration's to be created in parallel. // We allow multiple CoreConfiguration's to be created in parallel.
static const CoreConfiguration& BuildNewAndMaybeSet(); static const CoreConfiguration& BuildNewAndMaybeSet();
// The configuration // The configuration
static std::atomic<CoreConfiguration*> config_; static std::atomic<CoreConfiguration*> config_;
// Extra registered builders
static std::atomic<RegisteredBuilder*> builders_;
ChannelInit channel_init_;
HandshakerRegistry handshaker_registry_; HandshakerRegistry handshaker_registry_;
}; };

@ -0,0 +1,49 @@
// Copyright 2021 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 <grpc/impl/codegen/port_platform.h>
#include "src/core/lib/surface/builtins.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/lame_client.h"
#include "src/core/lib/surface/server.h"
namespace grpc_core {
void RegisterBuiltins(CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(GRPC_CLIENT_SUBCHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter);
builder->channel_init()->RegisterStage(GRPC_CLIENT_DIRECT_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter);
builder->channel_init()->RegisterStage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter);
builder->channel_init()->RegisterStage(
GRPC_CLIENT_LAME_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
[](grpc_channel_stack_builder* builder) {
return grpc_channel_stack_builder_append_filter(
builder, &grpc_lame_filter, nullptr, nullptr);
});
builder->channel_init()->RegisterStage(
GRPC_SERVER_CHANNEL, INT_MAX, [](grpc_channel_stack_builder* builder) {
return grpc_channel_stack_builder_prepend_filter(
builder, &grpc_core::Server::kServerTopFilter, nullptr, nullptr);
});
}
} // namespace grpc_core

@ -0,0 +1,26 @@
// Copyright 2021 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_CORE_LIB_SURFACE_BUILTINS_H
#define GRPC_CORE_LIB_SURFACE_BUILTINS_H
#include <grpc/impl/codegen/port_platform.h>
#include "src/core/lib/config/core_configuration.h"
namespace grpc_core {
void RegisterBuiltins(CoreConfiguration::Builder* builder);
} // namespace grpc_core
#endif // GRPC_CORE_LIB_SURFACE_BUILTINS_H

@ -34,6 +34,7 @@
#include "src/core/lib/channel/channel_trace.h" #include "src/core/lib/channel/channel_trace.h"
#include "src/core/lib/channel/channelz.h" #include "src/core/lib/channel/channelz.h"
#include "src/core/lib/channel/channelz_registry.h" #include "src/core/lib/channel/channelz_registry.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/stats.h"
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/manual_constructor.h" #include "src/core/lib/gprpp/manual_constructor.h"
@ -44,7 +45,6 @@
#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/call.h" #include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/static_metadata.h"
/** Cache grpc-status: X mdelems for X = 0..NUM_CACHED_STATUS_ELEMS. /** Cache grpc-status: X mdelems for X = 0..NUM_CACHED_STATUS_ELEMS.
@ -269,7 +269,8 @@ grpc_channel* grpc_channel_create(const char* target,
grpc_channel_args_destroy(args); grpc_channel_args_destroy(args);
grpc_channel_stack_builder_set_target(builder, target); grpc_channel_stack_builder_set_target(builder, target);
grpc_channel_stack_builder_set_transport(builder, optional_transport); grpc_channel_stack_builder_set_transport(builder, optional_transport);
if (!grpc_channel_init_create_stack(builder, channel_stack_type)) { if (!grpc_core::CoreConfiguration::Get().channel_init().CreateStack(
builder, channel_stack_type)) {
grpc_channel_stack_builder_destroy(builder); grpc_channel_stack_builder_destroy(builder);
if (resource_user != nullptr) { if (resource_user != nullptr) {
if (preallocated_bytes > 0) { if (preallocated_bytes > 0) {

@ -20,91 +20,37 @@
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/surface/channel_init.h"
#include <grpc/support/alloc.h> #include <algorithm>
typedef struct stage_slot { namespace grpc_core {
grpc_channel_init_stage fn;
void* arg;
int priority;
size_t insertion_order;
} stage_slot;
typedef struct stage_slots { void ChannelInit::Builder::RegisterStage(grpc_channel_stack_type type,
stage_slot* slots; int priority, Stage stage) {
size_t num_slots; slots_[type].emplace_back(std::move(stage), priority);
size_t cap_slots;
} stage_slots;
static stage_slots g_slots[GRPC_NUM_CHANNEL_STACK_TYPES];
static bool g_finalized;
void grpc_channel_init_init(void) {
for (int i = 0; i < GRPC_NUM_CHANNEL_STACK_TYPES; i++) {
g_slots[i].slots = nullptr;
g_slots[i].num_slots = 0;
g_slots[i].cap_slots = 0;
}
g_finalized = false;
}
void grpc_channel_init_register_stage(grpc_channel_stack_type type,
int priority,
grpc_channel_init_stage stage,
void* stage_arg) {
GPR_ASSERT(!g_finalized);
if (g_slots[type].cap_slots == g_slots[type].num_slots) {
g_slots[type].cap_slots =
std::max(size_t(8), 3 * g_slots[type].cap_slots / 2);
g_slots[type].slots = static_cast<stage_slot*>(
gpr_realloc(g_slots[type].slots,
g_slots[type].cap_slots * sizeof(*g_slots[type].slots)));
}
stage_slot* s = &g_slots[type].slots[g_slots[type].num_slots++];
s->insertion_order = g_slots[type].num_slots;
s->priority = priority;
s->fn = stage;
s->arg = stage_arg;
}
static int compare_slots(const void* a, const void* b) {
const stage_slot* sa = static_cast<const stage_slot*>(a);
const stage_slot* sb = static_cast<const stage_slot*>(b);
int c = grpc_core::QsortCompare(sa->priority, sb->priority);
if (c != 0) return c;
return grpc_core::QsortCompare(sa->insertion_order, sb->insertion_order);
} }
void grpc_channel_init_finalize(void) { ChannelInit ChannelInit::Builder::Build() {
GPR_ASSERT(!g_finalized); ChannelInit result;
for (int i = 0; i < GRPC_NUM_CHANNEL_STACK_TYPES; i++) { for (int i = 0; i < GRPC_NUM_CHANNEL_STACK_TYPES; i++) {
qsort(g_slots[i].slots, g_slots[i].num_slots, sizeof(*g_slots[i].slots), auto& slots = slots_[i];
compare_slots); std::stable_sort(
} slots.begin(), slots.end(),
g_finalized = true; [](const Slot& a, const Slot& b) { return a.priority < b.priority; });
} auto& result_slots = result.slots_[i];
result_slots.reserve(slots.size());
void grpc_channel_init_shutdown(void) { for (auto& slot : slots) {
for (int i = 0; i < GRPC_NUM_CHANNEL_STACK_TYPES; i++) { result_slots.emplace_back(std::move(slot.stage));
gpr_free(g_slots[i].slots); }
g_slots[i].slots =
static_cast<stage_slot*>(reinterpret_cast<void*>(0xdeadbeef));
} }
return result;
} }
bool grpc_channel_init_create_stack(grpc_channel_stack_builder* builder, bool ChannelInit::CreateStack(grpc_channel_stack_builder* builder,
grpc_channel_stack_type type) { grpc_channel_stack_type type) const {
GPR_ASSERT(g_finalized); for (const auto& stage : slots_[type]) {
if (!stage(builder)) return false;
grpc_channel_stack_builder_set_name(builder,
grpc_channel_stack_type_string(type));
for (size_t i = 0; i < g_slots[type].num_slots; i++) {
const stage_slot* slot = &g_slots[type].slots[i];
if (!slot->fn(builder, slot->arg)) {
return false;
}
} }
return true; return true;
} }
} // namespace grpc_core

@ -21,9 +21,10 @@
#include <grpc/support/port_platform.h> #include <grpc/support/port_platform.h>
#include "src/core/lib/channel/channel_stack_builder.h" #include <functional>
#include <vector>
#include "src/core/lib/surface/channel_stack_type.h" #include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/transport/transport.h"
#define GRPC_CHANNEL_INIT_BUILTIN_PRIORITY 10000 #define GRPC_CHANNEL_INIT_BUILTIN_PRIORITY 10000
@ -32,47 +33,54 @@
/// It also provides a universal entry path to run those mutators to build /// It also provides a universal entry path to run those mutators to build
/// a channel stack for various subsystems. /// a channel stack for various subsystems.
/// One stage of mutation: call functions against \a builder to influence the typedef struct grpc_channel_stack_builder grpc_channel_stack_builder;
/// finally constructed channel stack
typedef bool (*grpc_channel_init_stage)(grpc_channel_stack_builder* builder, namespace grpc_core {
void* arg);
class ChannelInit {
/// Global initialization of the system public:
void grpc_channel_init_init(void); /// One stage of mutation: call functions against \a builder to influence the
/// finally constructed channel stack
/// Register one stage of mutators. using Stage = std::function<bool(grpc_channel_stack_builder* builder)>;
/// Stages are run in priority order (lowest to highest), and then in
/// registration order (in the case of a tie). class Builder {
/// Stages are registered against one of the pre-determined channel stack public:
/// types. /// Register one stage of mutators.
/// If the channel stack type is GRPC_CLIENT_SUBCHANNEL, the caller should /// Stages are run in priority order (lowest to highest), and then in
/// ensure that subchannels with different filter lists will always have /// registration order (in the case of a tie).
/// different channel args. This requires setting a channel arg in case the /// Stages are registered against one of the pre-determined channel stack
/// registration function relies on some condition other than channel args to /// types.
/// decide whether to add a filter or not. /// If the channel stack type is GRPC_CLIENT_SUBCHANNEL, the caller should
void grpc_channel_init_register_stage(grpc_channel_stack_type type, /// ensure that subchannels with different filter lists will always have
int priority, /// different channel args. This requires setting a channel arg in case the
grpc_channel_init_stage stage_fn, /// registration function relies on some condition other than channel args
void* stage_arg); /// to decide whether to add a filter or not.
void RegisterStage(grpc_channel_stack_type type, int priority, Stage stage);
/// Finalize registration. No more calls to grpc_channel_init_register_stage are
/// allowed. /// Finalize registration. No more calls to grpc_channel_init_register_stage
void grpc_channel_init_finalize(void); /// are allowed.
/// Shutdown the channel init system ChannelInit Build();
void grpc_channel_init_shutdown(void);
private:
/// Construct a channel stack of some sort: see channel_stack.h for details struct Slot {
/// \a type is the type of channel stack to create Slot(Stage stage, int priority)
/// \a prefix_bytes is the number of bytes before the channel stack to allocate : stage(std::move(stage)), priority(priority) {}
/// \a args are configuration arguments for the channel stack Stage stage;
/// \a initial_refs is the initial refcount to give the channel stack int priority;
/// \a destroy and \a destroy_arg specify how to destroy the channel stack };
/// if destroy_arg is NULL, the returned value from this function will be std::vector<Slot> slots_[GRPC_NUM_CHANNEL_STACK_TYPES];
/// substituted };
/// \a optional_transport is either NULL or a constructed transport object
/// Returns a pointer to the base of the memory allocated (the actual channel /// Construct a channel stack of some sort: see channel_stack.h for details
/// stack object will be prefix_bytes past that pointer) /// \a type is the type of channel stack to create
bool grpc_channel_init_create_stack(grpc_channel_stack_builder* builder, /// \a builder is the channel stack builder to build into.
grpc_channel_stack_type type); bool CreateStack(grpc_channel_stack_builder* builder,
grpc_channel_stack_type type) const;
private:
std::vector<Stage> slots_[GRPC_NUM_CHANNEL_STACK_TYPES];
};
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H */ #endif /* GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H */

@ -48,7 +48,6 @@
#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/call.h" #include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/surface/completion_queue.h" #include "src/core/lib/surface/completion_queue.h"
#include "src/core/lib/surface/lame_client.h" #include "src/core/lib/surface/lame_client.h"
#include "src/core/lib/surface/server.h" #include "src/core/lib/surface/server.h"
@ -77,34 +76,6 @@ static void do_basic_init(void) {
gpr_time_init(); gpr_time_init();
} }
static bool append_filter(grpc_channel_stack_builder* builder, void* arg) {
return grpc_channel_stack_builder_append_filter(
builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
}
static bool prepend_filter(grpc_channel_stack_builder* builder, void* arg) {
return grpc_channel_stack_builder_prepend_filter(
builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
}
static void register_builtin_channel_init() {
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter, nullptr);
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter, nullptr);
grpc_channel_init_register_stage(
GRPC_CLIENT_LAME_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
append_filter, const_cast<grpc_channel_filter*>(&grpc_lame_filter));
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, INT_MAX, prepend_filter,
const_cast<grpc_channel_filter*>(&grpc_core::Server::kServerTopFilter));
}
typedef struct grpc_plugin { typedef struct grpc_plugin {
void (*init)(); void (*init)();
void (*destroy)(); void (*destroy)();
@ -136,7 +107,6 @@ void grpc_init(void) {
grpc_stats_init(); grpc_stats_init();
grpc_slice_intern_init(); grpc_slice_intern_init();
grpc_mdctx_global_init(); grpc_mdctx_global_init();
grpc_channel_init_init();
grpc_core::channelz::ChannelzRegistry::Init(); grpc_core::channelz::ChannelzRegistry::Init();
grpc_security_pre_init(); grpc_security_pre_init();
grpc_core::ApplicationCallbackExecCtx::GlobalInit(); grpc_core::ApplicationCallbackExecCtx::GlobalInit();
@ -148,13 +118,7 @@ void grpc_init(void) {
g_all_of_the_plugins[i].init(); g_all_of_the_plugins[i].init();
} }
} }
/* register channel finalization AFTER all plugins, to ensure that it's run
* at the appropriate time */
grpc_register_security_filters();
register_builtin_channel_init();
grpc_tracer_init(); grpc_tracer_init();
/* no more changes to channel init pipelines */
grpc_channel_init_finalize();
grpc_iomgr_start(); grpc_iomgr_start();
} }

@ -21,6 +21,8 @@
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/trace.h" #include "src/core/lib/debug/trace.h"
#include "src/core/lib/security/authorization/sdk_server_authz_filter.h" #include "src/core/lib/security/authorization/sdk_server_authz_filter.h"
#include "src/core/lib/security/context/security_context.h" #include "src/core/lib/security/context/security_context.h"
@ -30,14 +32,13 @@
#include "src/core/lib/security/transport/auth_filters.h" #include "src/core/lib/security/transport/auth_filters.h"
#include "src/core/lib/security/transport/secure_endpoint.h" #include "src/core/lib/security/transport/secure_endpoint.h"
#include "src/core/lib/security/transport/security_handshaker.h" #include "src/core/lib/security/transport/security_handshaker.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/surface/init.h" #include "src/core/lib/surface/init.h"
#include "src/core/tsi/transport_security_interface.h" #include "src/core/tsi/transport_security_interface.h"
void grpc_security_pre_init(void) {} void grpc_security_pre_init(void) {}
static bool maybe_prepend_client_auth_filter( static bool maybe_prepend_client_auth_filter(
grpc_channel_stack_builder* builder, void* /*arg*/) { grpc_channel_stack_builder* builder) {
const grpc_channel_args* args = const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder); grpc_channel_stack_builder_get_channel_arguments(builder);
if (args) { if (args) {
@ -52,7 +53,7 @@ static bool maybe_prepend_client_auth_filter(
} }
static bool maybe_prepend_server_auth_filter( static bool maybe_prepend_server_auth_filter(
grpc_channel_stack_builder* builder, void* /*arg*/) { grpc_channel_stack_builder* builder) {
const grpc_channel_args* args = const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder); grpc_channel_stack_builder_get_channel_arguments(builder);
if (args) { if (args) {
@ -67,7 +68,7 @@ static bool maybe_prepend_server_auth_filter(
} }
static bool maybe_prepend_sdk_server_authz_filter( static bool maybe_prepend_sdk_server_authz_filter(
grpc_channel_stack_builder* builder, void* /*arg*/) { grpc_channel_stack_builder* builder) {
const grpc_channel_args* args = const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder); grpc_channel_stack_builder_get_channel_arguments(builder);
const auto* provider = const auto* provider =
@ -81,20 +82,22 @@ static bool maybe_prepend_sdk_server_authz_filter(
return true; return true;
} }
void grpc_register_security_filters(void) { namespace grpc_core {
void RegisterSecurityFilters(CoreConfiguration::Builder* builder) {
// Register the auth client with a priority < INT_MAX to allow the authority // Register the auth client with a priority < INT_MAX to allow the authority
// filter -on which the auth filter depends- to be higher on the channel // filter -on which the auth filter depends- to be higher on the channel
// stack. // stack.
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX - 1, builder->channel_init()->RegisterStage(GRPC_CLIENT_SUBCHANNEL, INT_MAX - 1,
maybe_prepend_client_auth_filter, nullptr); maybe_prepend_client_auth_filter);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX - 1, builder->channel_init()->RegisterStage(GRPC_CLIENT_DIRECT_CHANNEL,
maybe_prepend_client_auth_filter, nullptr); INT_MAX - 1,
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX - 1, maybe_prepend_client_auth_filter);
maybe_prepend_server_auth_filter, nullptr); builder->channel_init()->RegisterStage(GRPC_SERVER_CHANNEL, INT_MAX - 1,
maybe_prepend_server_auth_filter);
// Register the SdkServerAuthzFilter with a priority less than // Register the SdkServerAuthzFilter with a priority less than
// server_auth_filter to allow server_auth_filter on which the sdk filter // server_auth_filter to allow server_auth_filter on which the sdk filter
// depends on to be higher on the channel stack. // depends on to be higher on the channel stack.
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX - 2, builder->channel_init()->RegisterStage(GRPC_SERVER_CHANNEL, INT_MAX - 2,
maybe_prepend_sdk_server_authz_filter, maybe_prepend_sdk_server_authz_filter);
nullptr);
} }
} // namespace grpc_core

@ -21,13 +21,10 @@
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include "src/core/lib/config/core_configuration.h" #include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/builtins.h"
void grpc_http_filters_init(void);
void grpc_http_filters_shutdown(void);
void grpc_chttp2_plugin_init(void); void grpc_chttp2_plugin_init(void);
void grpc_chttp2_plugin_shutdown(void); void grpc_chttp2_plugin_shutdown(void);
void grpc_deadline_filter_init(void);
void grpc_deadline_filter_shutdown(void);
void grpc_client_channel_init(void); void grpc_client_channel_init(void);
void grpc_client_channel_shutdown(void); void grpc_client_channel_shutdown(void);
void grpc_inproc_plugin_init(void); void grpc_inproc_plugin_init(void);
@ -50,16 +47,8 @@ void grpc_resolver_dns_native_init(void);
void grpc_resolver_dns_native_shutdown(void); void grpc_resolver_dns_native_shutdown(void);
void grpc_resolver_sockaddr_init(void); void grpc_resolver_sockaddr_init(void);
void grpc_resolver_sockaddr_shutdown(void); void grpc_resolver_sockaddr_shutdown(void);
void grpc_client_idle_filter_init(void);
void grpc_client_idle_filter_shutdown(void);
void grpc_max_age_filter_init(void);
void grpc_max_age_filter_shutdown(void);
void grpc_message_size_filter_init(void); void grpc_message_size_filter_init(void);
void grpc_message_size_filter_shutdown(void); void grpc_message_size_filter_shutdown(void);
void grpc_service_config_channel_arg_filter_init(void);
void grpc_service_config_channel_arg_filter_shutdown(void);
void grpc_client_authority_filter_init(void);
void grpc_client_authority_filter_shutdown(void);
void grpc_workaround_cronet_compression_filter_init(void); void grpc_workaround_cronet_compression_filter_init(void);
void grpc_workaround_cronet_compression_filter_shutdown(void); void grpc_workaround_cronet_compression_filter_shutdown(void);
namespace grpc_core { namespace grpc_core {
@ -93,22 +82,14 @@ void grpc_resolver_xds_shutdown(void);
namespace grpc_core { namespace grpc_core {
void GoogleCloud2ProdResolverInit(); void GoogleCloud2ProdResolverInit();
void GoogleCloud2ProdResolverShutdown(); void GoogleCloud2ProdResolverShutdown();
} } // namespace grpc_core
#endif #endif
void grpc_register_built_in_plugins(void) { void grpc_register_built_in_plugins(void) {
grpc_register_plugin(grpc_http_filters_init, grpc_register_plugin(grpc_chttp2_plugin_init, grpc_chttp2_plugin_shutdown);
grpc_http_filters_shutdown); grpc_register_plugin(grpc_client_channel_init, grpc_client_channel_shutdown);
grpc_register_plugin(grpc_chttp2_plugin_init, grpc_register_plugin(grpc_inproc_plugin_init, grpc_inproc_plugin_shutdown);
grpc_chttp2_plugin_shutdown); grpc_register_plugin(grpc_resolver_fake_init, grpc_resolver_fake_shutdown);
grpc_register_plugin(grpc_deadline_filter_init,
grpc_deadline_filter_shutdown);
grpc_register_plugin(grpc_client_channel_init,
grpc_client_channel_shutdown);
grpc_register_plugin(grpc_inproc_plugin_init,
grpc_inproc_plugin_shutdown);
grpc_register_plugin(grpc_resolver_fake_init,
grpc_resolver_fake_shutdown);
grpc_register_plugin(grpc_lb_policy_grpclb_init, grpc_register_plugin(grpc_lb_policy_grpclb_init,
grpc_lb_policy_grpclb_shutdown); grpc_lb_policy_grpclb_shutdown);
grpc_register_plugin(grpc_lb_policy_priority_init, grpc_register_plugin(grpc_lb_policy_priority_init,
@ -127,18 +108,10 @@ void grpc_register_built_in_plugins(void) {
grpc_resolver_dns_native_shutdown); grpc_resolver_dns_native_shutdown);
grpc_register_plugin(grpc_resolver_sockaddr_init, grpc_register_plugin(grpc_resolver_sockaddr_init,
grpc_resolver_sockaddr_shutdown); grpc_resolver_sockaddr_shutdown);
grpc_register_plugin(grpc_client_idle_filter_init,
grpc_client_idle_filter_shutdown);
grpc_register_plugin(grpc_max_age_filter_init,
grpc_max_age_filter_shutdown);
grpc_register_plugin(grpc_message_size_filter_init, grpc_register_plugin(grpc_message_size_filter_init,
grpc_message_size_filter_shutdown); grpc_message_size_filter_shutdown);
grpc_register_plugin(grpc_core::FaultInjectionFilterInit, grpc_register_plugin(grpc_core::FaultInjectionFilterInit,
grpc_core::FaultInjectionFilterShutdown); grpc_core::FaultInjectionFilterShutdown);
grpc_register_plugin(grpc_service_config_channel_arg_filter_init,
grpc_service_config_channel_arg_filter_shutdown);
grpc_register_plugin(grpc_client_authority_filter_init,
grpc_client_authority_filter_shutdown);
grpc_register_plugin(grpc_workaround_cronet_compression_filter_init, grpc_register_plugin(grpc_workaround_cronet_compression_filter_init,
grpc_workaround_cronet_compression_filter_shutdown); grpc_workaround_cronet_compression_filter_shutdown);
#ifndef GRPC_NO_XDS #ifndef GRPC_NO_XDS
@ -148,16 +121,14 @@ void grpc_register_built_in_plugins(void) {
grpc_certificate_provider_registry_shutdown); grpc_certificate_provider_registry_shutdown);
grpc_register_plugin(grpc_core::FileWatcherCertificateProviderInit, grpc_register_plugin(grpc_core::FileWatcherCertificateProviderInit,
grpc_core::FileWatcherCertificateProviderShutdown); grpc_core::FileWatcherCertificateProviderShutdown);
grpc_register_plugin(grpc_lb_policy_cds_init, grpc_register_plugin(grpc_lb_policy_cds_init, grpc_lb_policy_cds_shutdown);
grpc_lb_policy_cds_shutdown);
grpc_register_plugin(grpc_lb_policy_xds_cluster_impl_init, grpc_register_plugin(grpc_lb_policy_xds_cluster_impl_init,
grpc_lb_policy_xds_cluster_impl_shutdown); grpc_lb_policy_xds_cluster_impl_shutdown);
grpc_register_plugin(grpc_lb_policy_xds_cluster_resolver_init, grpc_register_plugin(grpc_lb_policy_xds_cluster_resolver_init,
grpc_lb_policy_xds_cluster_resolver_shutdown); grpc_lb_policy_xds_cluster_resolver_shutdown);
grpc_register_plugin(grpc_lb_policy_xds_cluster_manager_init, grpc_register_plugin(grpc_lb_policy_xds_cluster_manager_init,
grpc_lb_policy_xds_cluster_manager_shutdown); grpc_lb_policy_xds_cluster_manager_shutdown);
grpc_register_plugin(grpc_resolver_xds_init, grpc_register_plugin(grpc_resolver_xds_init, grpc_resolver_xds_shutdown);
grpc_resolver_xds_shutdown);
grpc_register_plugin(grpc_core::GoogleCloud2ProdResolverInit, grpc_register_plugin(grpc_core::GoogleCloud2ProdResolverInit,
grpc_core::GoogleCloud2ProdResolverShutdown); grpc_core::GoogleCloud2ProdResolverShutdown);
#endif #endif
@ -165,12 +136,40 @@ void grpc_register_built_in_plugins(void) {
namespace grpc_core { namespace grpc_core {
extern void BuildClientChannelConfiguration(CoreConfiguration::Builder* builder); extern void BuildClientChannelConfiguration(
extern void SecurityRegisterHandshakerFactories(CoreConfiguration::Builder* builder); CoreConfiguration::Builder* builder);
extern void SecurityRegisterHandshakerFactories(
CoreConfiguration::Builder* builder);
extern void RegisterClientAuthorityFilter(CoreConfiguration::Builder* builder);
extern void RegisterClientIdleFilter(CoreConfiguration::Builder* builder);
extern void RegisterDeadlineFilter(CoreConfiguration::Builder* builder);
extern void RegisterGrpcLbLoadReportingFilter(
CoreConfiguration::Builder* builder);
extern void RegisterHttpFilters(CoreConfiguration::Builder* builder);
extern void RegisterMaxAgeFilter(CoreConfiguration::Builder* builder);
extern void RegisterMessageSizeFilter(CoreConfiguration::Builder* builder);
extern void RegisterSecurityFilters(CoreConfiguration::Builder* builder);
extern void RegisterServiceConfigChannelArgFilter(
CoreConfiguration::Builder* builder);
extern void RegisterWorkaroundCronetCompressionFilter(
CoreConfiguration::Builder* builder);
void BuildCoreConfiguration(CoreConfiguration::Builder* builder) { void BuildCoreConfiguration(CoreConfiguration::Builder* builder) {
BuildClientChannelConfiguration(builder); BuildClientChannelConfiguration(builder);
SecurityRegisterHandshakerFactories(builder); SecurityRegisterHandshakerFactories(builder);
RegisterClientAuthorityFilter(builder);
RegisterClientIdleFilter(builder);
RegisterGrpcLbLoadReportingFilter(builder);
RegisterHttpFilters(builder);
RegisterMaxAgeFilter(builder);
RegisterDeadlineFilter(builder);
RegisterMessageSizeFilter(builder);
RegisterWorkaroundCronetCompressionFilter(builder);
RegisterServiceConfigChannelArgFilter(builder);
// Run last so it gets a consistent location.
// TODO(ctiller): Is this actually necessary?
RegisterSecurityFilters(builder);
RegisterBuiltins(builder);
} }
} // namespace grpc_core } // namespace grpc_core

@ -21,13 +21,10 @@
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include "src/core/lib/config/core_configuration.h" #include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/builtins.h"
void grpc_http_filters_init(void);
void grpc_http_filters_shutdown(void);
void grpc_chttp2_plugin_init(void); void grpc_chttp2_plugin_init(void);
void grpc_chttp2_plugin_shutdown(void); void grpc_chttp2_plugin_shutdown(void);
void grpc_deadline_filter_init(void);
void grpc_deadline_filter_shutdown(void);
void grpc_client_channel_init(void); void grpc_client_channel_init(void);
void grpc_client_channel_shutdown(void); void grpc_client_channel_shutdown(void);
void grpc_inproc_plugin_init(void); void grpc_inproc_plugin_init(void);
@ -50,10 +47,6 @@ void grpc_lb_policy_pick_first_init(void);
void grpc_lb_policy_pick_first_shutdown(void); void grpc_lb_policy_pick_first_shutdown(void);
void grpc_lb_policy_round_robin_init(void); void grpc_lb_policy_round_robin_init(void);
void grpc_lb_policy_round_robin_shutdown(void); void grpc_lb_policy_round_robin_shutdown(void);
void grpc_client_idle_filter_init(void);
void grpc_client_idle_filter_shutdown(void);
void grpc_max_age_filter_init(void);
void grpc_max_age_filter_shutdown(void);
void grpc_message_size_filter_init(void); void grpc_message_size_filter_init(void);
void grpc_message_size_filter_shutdown(void); void grpc_message_size_filter_shutdown(void);
namespace grpc_core { namespace grpc_core {
@ -62,32 +55,20 @@ void FaultInjectionFilterShutdown(void);
void GrpcLbPolicyRingHashInit(void); void GrpcLbPolicyRingHashInit(void);
void GrpcLbPolicyRingHashShutdown(void); void GrpcLbPolicyRingHashShutdown(void);
} // namespace grpc_core } // namespace grpc_core
void grpc_service_config_channel_arg_filter_init(void);
void grpc_service_config_channel_arg_filter_shutdown(void);
void grpc_client_authority_filter_init(void);
void grpc_client_authority_filter_shutdown(void);
void grpc_workaround_cronet_compression_filter_init(void); void grpc_workaround_cronet_compression_filter_init(void);
void grpc_workaround_cronet_compression_filter_shutdown(void); void grpc_workaround_cronet_compression_filter_shutdown(void);
void grpc_register_built_in_plugins(void) { void grpc_register_built_in_plugins(void) {
grpc_register_plugin(grpc_http_filters_init, grpc_register_plugin(grpc_chttp2_plugin_init, grpc_chttp2_plugin_shutdown);
grpc_http_filters_shutdown); grpc_register_plugin(grpc_client_channel_init, grpc_client_channel_shutdown);
grpc_register_plugin(grpc_chttp2_plugin_init, grpc_register_plugin(grpc_inproc_plugin_init, grpc_inproc_plugin_shutdown);
grpc_chttp2_plugin_shutdown);
grpc_register_plugin(grpc_deadline_filter_init,
grpc_deadline_filter_shutdown);
grpc_register_plugin(grpc_client_channel_init,
grpc_client_channel_shutdown);
grpc_register_plugin(grpc_inproc_plugin_init,
grpc_inproc_plugin_shutdown);
grpc_register_plugin(grpc_resolver_dns_ares_init, grpc_register_plugin(grpc_resolver_dns_ares_init,
grpc_resolver_dns_ares_shutdown); grpc_resolver_dns_ares_shutdown);
grpc_register_plugin(grpc_resolver_dns_native_init, grpc_register_plugin(grpc_resolver_dns_native_init,
grpc_resolver_dns_native_shutdown); grpc_resolver_dns_native_shutdown);
grpc_register_plugin(grpc_resolver_sockaddr_init, grpc_register_plugin(grpc_resolver_sockaddr_init,
grpc_resolver_sockaddr_shutdown); grpc_resolver_sockaddr_shutdown);
grpc_register_plugin(grpc_resolver_fake_init, grpc_register_plugin(grpc_resolver_fake_init, grpc_resolver_fake_shutdown);
grpc_resolver_fake_shutdown);
grpc_register_plugin(grpc_lb_policy_grpclb_init, grpc_register_plugin(grpc_lb_policy_grpclb_init,
grpc_lb_policy_grpclb_shutdown); grpc_lb_policy_grpclb_shutdown);
grpc_register_plugin(grpc_lb_policy_priority_init, grpc_register_plugin(grpc_lb_policy_priority_init,
@ -100,28 +81,46 @@ void grpc_register_built_in_plugins(void) {
grpc_lb_policy_round_robin_shutdown); grpc_lb_policy_round_robin_shutdown);
grpc_register_plugin(grpc_core::GrpcLbPolicyRingHashInit, grpc_register_plugin(grpc_core::GrpcLbPolicyRingHashInit,
grpc_core::GrpcLbPolicyRingHashShutdown); grpc_core::GrpcLbPolicyRingHashShutdown);
grpc_register_plugin(grpc_client_idle_filter_init,
grpc_client_idle_filter_shutdown);
grpc_register_plugin(grpc_max_age_filter_init,
grpc_max_age_filter_shutdown);
grpc_register_plugin(grpc_message_size_filter_init, grpc_register_plugin(grpc_message_size_filter_init,
grpc_message_size_filter_shutdown); grpc_message_size_filter_shutdown);
grpc_register_plugin(grpc_core::FaultInjectionFilterInit, grpc_register_plugin(grpc_core::FaultInjectionFilterInit,
grpc_core::FaultInjectionFilterShutdown); grpc_core::FaultInjectionFilterShutdown);
grpc_register_plugin(grpc_service_config_channel_arg_filter_init,
grpc_service_config_channel_arg_filter_shutdown);
grpc_register_plugin(grpc_client_authority_filter_init,
grpc_client_authority_filter_shutdown);
grpc_register_plugin(grpc_workaround_cronet_compression_filter_init, grpc_register_plugin(grpc_workaround_cronet_compression_filter_init,
grpc_workaround_cronet_compression_filter_shutdown); grpc_workaround_cronet_compression_filter_shutdown);
} }
namespace grpc_core { namespace grpc_core {
extern void BuildClientChannelConfiguration(CoreConfiguration::Builder* builder); extern void BuildClientChannelConfiguration(
CoreConfiguration::Builder* builder);
extern void RegisterClientAuthorityFilter(CoreConfiguration::Builder* builder);
extern void RegisterClientIdleFilter(CoreConfiguration::Builder* builder);
extern void RegisterDeadlineFilter(CoreConfiguration::Builder* builder);
extern void RegisterGrpcLbLoadReportingFilter(
CoreConfiguration::Builder* builder);
extern void RegisterHttpFilters(CoreConfiguration::Builder* builder);
extern void RegisterMaxAgeFilter(CoreConfiguration::Builder* builder);
extern void RegisterMessageSizeFilter(CoreConfiguration::Builder* builder);
extern void RegisterSecurityFilters(CoreConfiguration::Builder* builder);
extern void RegisterServiceConfigChannelArgFilter(
CoreConfiguration::Builder* builder);
extern void RegisterWorkaroundCronetCompressionFilter(
CoreConfiguration::Builder* builder);
void BuildCoreConfiguration(CoreConfiguration::Builder* builder) { void BuildCoreConfiguration(CoreConfiguration::Builder* builder) {
BuildClientChannelConfiguration(builder); BuildClientChannelConfiguration(builder);
RegisterClientAuthorityFilter(builder);
RegisterClientIdleFilter(builder);
RegisterGrpcLbLoadReportingFilter(builder);
RegisterHttpFilters(builder);
RegisterMaxAgeFilter(builder);
RegisterDeadlineFilter(builder);
RegisterMessageSizeFilter(builder);
RegisterWorkaroundCronetCompressionFilter(builder);
RegisterServiceConfigChannelArgFilter(builder);
// Run last so it gets a consistent location.
// TODO(ctiller): Is this actually necessary?
RegisterBuiltins(builder);
} }
} } // namespace grpc_core

@ -23,6 +23,8 @@
#include <grpcpp/impl/codegen/slice.h> #include <grpcpp/impl/codegen/slice.h>
#include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
namespace grpc { namespace grpc {
@ -61,38 +63,30 @@ void CallData::SetPollsetOrPollsetSet(grpc_call_element* elem,
grpc_call_stack_ignore_set_pollset_or_pollset_set(elem, pollent); grpc_call_stack_ignore_set_pollset_or_pollset_set(elem, pollent);
} }
// internal code used by RegisterChannelFilter()
namespace internal { namespace internal {
// Note: Implicitly initialized to nullptr due to static lifetime. void RegisterChannelFilter(
std::vector<FilterRecord>* channel_filters; grpc_channel_stack_type stack_type, int priority,
std::function<bool(const grpc_channel_args&)> include_filter,
namespace { const grpc_channel_filter* filter) {
auto maybe_add_filter = [include_filter,
bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* arg) { filter](grpc_channel_stack_builder* builder) {
const FilterRecord& filter = *static_cast<FilterRecord*>(arg); if (include_filter != nullptr) {
if (filter.include_filter) { const grpc_channel_args* args =
const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder);
grpc_channel_stack_builder_get_channel_arguments(builder); if (!include_filter(*args)) return true;
if (!filter.include_filter(*args)) return true; }
} return grpc_channel_stack_builder_prepend_filter(builder, filter, nullptr,
return grpc_channel_stack_builder_prepend_filter(builder, &filter.filter, nullptr);
nullptr, nullptr); };
grpc_core::CoreConfiguration::RegisterBuilder(
[stack_type, priority,
maybe_add_filter](grpc_core::CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(stack_type, priority,
maybe_add_filter);
});
} }
} // namespace
void ChannelFilterPluginInit() {
for (size_t i = 0; i < channel_filters->size(); ++i) {
FilterRecord& filter = (*channel_filters)[i];
grpc_channel_init_register_stage(filter.stack_type, filter.priority,
MaybeAddFilter, &filter);
}
}
void ChannelFilterPluginShutdown() {}
} // namespace internal } // namespace internal
} // namespace grpc } // namespace grpc

@ -306,16 +306,10 @@ class ChannelFilter final {
} }
}; };
struct FilterRecord { void RegisterChannelFilter(
grpc_channel_stack_type stack_type; grpc_channel_stack_type stack_type, int priority,
int priority; std::function<bool(const grpc_channel_args&)> include_filter,
std::function<bool(const grpc_channel_args&)> include_filter; const grpc_channel_filter* filter);
grpc_channel_filter filter;
};
extern std::vector<FilterRecord>* channel_filters;
void ChannelFilterPluginInit();
void ChannelFilterPluginShutdown();
} // namespace internal } // namespace internal
@ -333,26 +327,21 @@ template <typename ChannelDataType, typename CallDataType>
void RegisterChannelFilter( void RegisterChannelFilter(
const char* name, grpc_channel_stack_type stack_type, int priority, const char* name, grpc_channel_stack_type stack_type, int priority,
std::function<bool(const grpc_channel_args&)> include_filter) { std::function<bool(const grpc_channel_args&)> include_filter) {
// If we haven't been called before, initialize channel_filters and using FilterType = internal::ChannelFilter<ChannelDataType, CallDataType>;
// call grpc_register_plugin(). static const grpc_channel_filter filter = {
if (internal::channel_filters == nullptr) { FilterType::StartTransportStreamOpBatch,
grpc_register_plugin(internal::ChannelFilterPluginInit, FilterType::StartTransportOp,
internal::ChannelFilterPluginShutdown); FilterType::call_data_size,
internal::channel_filters = new std::vector<internal::FilterRecord>(); FilterType::InitCallElement,
} FilterType::SetPollsetOrPollsetSet,
// Add an entry to channel_filters. The filter will be added when the FilterType::DestroyCallElement,
// C-core initialization code calls ChannelFilterPluginInit(). FilterType::channel_data_size,
typedef internal::ChannelFilter<ChannelDataType, CallDataType> FilterType; FilterType::InitChannelElement,
internal::FilterRecord filter_record = { FilterType::DestroyChannelElement,
stack_type, FilterType::GetChannelInfo,
priority, name};
include_filter, grpc::internal::RegisterChannelFilter(stack_type, priority,
{FilterType::StartTransportStreamOpBatch, FilterType::StartTransportOp, std::move(include_filter), &filter);
FilterType::call_data_size, FilterType::InitCallElement,
FilterType::SetPollsetOrPollsetSet, FilterType::DestroyCallElement,
FilterType::channel_data_size, FilterType::InitChannelElement,
FilterType::DestroyChannelElement, FilterType::GetChannelInfo, name}};
internal::channel_filters->push_back(filter_record);
} }
} // namespace grpc } // namespace grpc

@ -579,6 +579,7 @@ CORE_SOURCE_FILES = [
'src/core/lib/slice/slice_string_helpers.cc', 'src/core/lib/slice/slice_string_helpers.cc',
'src/core/lib/slice/static_slice.cc', 'src/core/lib/slice/static_slice.cc',
'src/core/lib/surface/api_trace.cc', 'src/core/lib/surface/api_trace.cc',
'src/core/lib/surface/builtins.cc',
'src/core/lib/surface/byte_buffer.cc', 'src/core/lib/surface/byte_buffer.cc',
'src/core/lib/surface/byte_buffer_reader.cc', 'src/core/lib/surface/byte_buffer_reader.cc',
'src/core/lib/surface/call.cc', 'src/core/lib/surface/call.cc',

@ -25,6 +25,7 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/surface/channel_init.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
@ -92,38 +93,29 @@ const grpc_channel_filter original_filter = {
grpc_channel_next_get_info, grpc_channel_next_get_info,
"filter_name"}; "filter_name"};
static bool add_replacement_filter(grpc_channel_stack_builder* builder, static bool add_replacement_filter(grpc_channel_stack_builder* builder) {
void* arg) {
const grpc_channel_filter* filter =
static_cast<const grpc_channel_filter*>(arg);
// Get rid of any other version of the filter, as determined by having the // Get rid of any other version of the filter, as determined by having the
// same name. // same name.
GPR_ASSERT(grpc_channel_stack_builder_remove_filter(builder, filter->name)); GPR_ASSERT(grpc_channel_stack_builder_remove_filter(builder,
replacement_filter.name));
return grpc_channel_stack_builder_prepend_filter( return grpc_channel_stack_builder_prepend_filter(
builder, filter, set_arg_once_fn, &g_replacement_fn_called); builder, &replacement_filter, set_arg_once_fn, &g_replacement_fn_called);
} }
static bool add_original_filter(grpc_channel_stack_builder* builder, static bool add_original_filter(grpc_channel_stack_builder* builder) {
void* arg) {
return grpc_channel_stack_builder_prepend_filter( return grpc_channel_stack_builder_prepend_filter(
builder, static_cast<const grpc_channel_filter*>(arg), set_arg_once_fn, builder, &original_filter, set_arg_once_fn, &g_original_fn_called);
&g_original_fn_called);
} }
static void init_plugin(void) {
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, INT_MAX, add_original_filter,
const_cast<grpc_channel_filter*>(&original_filter));
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, INT_MAX, add_replacement_filter,
const_cast<grpc_channel_filter*>(&replacement_filter));
}
static void destroy_plugin(void) {}
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(argc, argv); grpc::testing::TestEnvironment env(argc, argv);
grpc_register_plugin(init_plugin, destroy_plugin); grpc_core::CoreConfiguration::RegisterBuilder(
[](grpc_core::CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(GRPC_CLIENT_CHANNEL, INT_MAX,
add_original_filter);
builder->channel_init()->RegisterStage(GRPC_CLIENT_CHANNEL, INT_MAX,
add_replacement_filter);
});
grpc_init(); grpc_init();
test_channel_stack_builder_filter_replace(); test_channel_stack_builder_filter_replace();
grpc_shutdown(); grpc_shutdown();

@ -40,6 +40,7 @@
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/surface/channel_stack_type.h" #include "src/core/lib/surface/channel_stack_type.h"
@ -138,7 +139,7 @@ static int check_stack(const char* file, int line, const char* transport_name,
{ {
grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx exec_ctx;
grpc_channel_stack_builder_set_channel_arguments(builder, channel_args); grpc_channel_stack_builder_set_channel_arguments(builder, channel_args);
GPR_ASSERT(grpc_channel_init_create_stack( GPR_ASSERT(grpc_core::CoreConfiguration::Get().channel_init().CreateStack(
builder, (grpc_channel_stack_type)channel_stack_type)); builder, (grpc_channel_stack_type)channel_stack_type));
} }

@ -26,12 +26,11 @@
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/surface/channel_init.h"
#include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h" #include "test/core/end2end/end2end_tests.h"
static bool g_enable_filter = false;
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); } static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
@ -251,29 +250,17 @@ static const grpc_channel_filter test_filter = {
* Registration * Registration
*/ */
static bool maybe_add_filter(grpc_channel_stack_builder* builder,
void* /*arg*/) {
if (g_enable_filter) {
return grpc_channel_stack_builder_prepend_filter(builder, &test_filter,
nullptr, nullptr);
} else {
return true;
}
}
static void init_plugin(void) {
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, 0, maybe_add_filter,
nullptr);
}
static void destroy_plugin(void) {}
void filter_causes_close(grpc_end2end_test_config config) { void filter_causes_close(grpc_end2end_test_config config) {
g_enable_filter = true; grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
test_request(config); [](grpc_core::CoreConfiguration::Builder* builder) {
g_enable_filter = false; grpc_core::BuildCoreConfiguration(builder);
builder->channel_init()->RegisterStage(
GRPC_SERVER_CHANNEL, 0, [](grpc_channel_stack_builder* builder) {
return grpc_channel_stack_builder_prepend_filter(
builder, &test_filter, nullptr, nullptr);
});
},
[config] { test_request(config); });
} }
void filter_causes_close_pre_init(void) { void filter_causes_close_pre_init(void) {}
grpc_register_plugin(init_plugin, destroy_plugin);
}

@ -27,14 +27,13 @@
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/surface/channel_init.h"
#include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h" #include "test/core/end2end/end2end_tests.h"
enum { TIMEOUT = 200000 }; enum { TIMEOUT = 200000 };
static bool g_enable_filter = false;
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); } static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
@ -274,48 +273,31 @@ static const grpc_channel_filter test_filter = {
* Registration * Registration
*/ */
static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) {
grpc_channel_filter* filter = static_cast<grpc_channel_filter*>(arg);
if (g_enable_filter) {
// Want to add the filter as close to the end as possible, to make
// sure that all of the filters work well together. However, we
// can't add it at the very end, because the connected channel filter
// must be the last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
} else {
return true;
}
}
static void init_plugin(void) {
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_filter));
grpc_channel_init_register_stage(
GRPC_CLIENT_SUBCHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_filter));
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_filter));
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_filter));
}
static void destroy_plugin(void) {}
void filter_context(grpc_end2end_test_config config) { void filter_context(grpc_end2end_test_config config) {
g_enable_filter = true; grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
test_request(config); [](grpc_core::CoreConfiguration::Builder* builder) {
g_enable_filter = false; grpc_core::BuildCoreConfiguration(builder);
for (auto type : {GRPC_CLIENT_CHANNEL, GRPC_CLIENT_SUBCHANNEL,
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_SERVER_CHANNEL}) {
builder->channel_init()->RegisterStage(
type, INT_MAX, [](grpc_channel_stack_builder* builder) {
// Want to add the filter as close to the end as possible, to
// make sure that all of the filters work well together.
// However, we can't add it at the very end, because the
// connected channel filter must be the last one. So we add it
// right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval =
grpc_channel_stack_builder_add_filter_before(
it, &test_filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
});
}
},
[config] { test_request(config); });
} }
void filter_context_pre_init(void) { void filter_context_pre_init(void) {}
grpc_register_plugin(init_plugin, destroy_plugin);
}

@ -27,6 +27,7 @@
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/surface/channel_init.h"
#include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h" #include "test/core/end2end/end2end_tests.h"
@ -456,76 +457,6 @@ static const grpc_channel_filter test_filter = {
* Registration * Registration
*/ */
static bool maybe_add_server_channel_filter(grpc_channel_stack_builder* builder,
void* /*arg*/) {
if (g_enable_server_channel_filter) {
// Want to add the filter as close to the end as possible, to make
// sure that all of the filters work well together. However, we
// can't add it at the very end, because the connected channel filter
// must be the last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, &test_filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
} else {
return true;
}
}
static bool maybe_add_client_channel_filter(grpc_channel_stack_builder* builder,
void* /*arg*/) {
if (g_enable_client_channel_filter) {
// Want to add the filter as close to the end as possible, to make
// sure that all of the filters work well together. However, we
// can't add it at the very end, because the connected channel filter
// must be the last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, &test_filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
} else {
return true;
}
}
static bool maybe_add_client_subchannel_filter(
grpc_channel_stack_builder* builder, void* /*arg*/) {
if (g_enable_client_subchannel_filter) {
// Want to add the filter as close to the end as possible, to make
// sure that all of the filters work well together. However, we
// can't add it at the very end, because the client channel filter
// must be the last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, &test_filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
} else {
return true;
}
}
static void init_plugin(void) {
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX,
maybe_add_server_channel_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX,
maybe_add_client_channel_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX,
maybe_add_client_subchannel_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX,
maybe_add_client_channel_filter, nullptr);
}
static void destroy_plugin(void) {}
static void filter_init_fails_internal(grpc_end2end_test_config config) { static void filter_init_fails_internal(grpc_end2end_test_config config) {
gpr_log(GPR_INFO, "Testing SERVER_CHANNEL filter."); gpr_log(GPR_INFO, "Testing SERVER_CHANNEL filter.");
g_enable_server_channel_filter = true; g_enable_server_channel_filter = true;
@ -552,13 +483,37 @@ static void filter_init_fails_internal(grpc_end2end_test_config config) {
} }
void filter_init_fails(grpc_end2end_test_config config) { void filter_init_fails(grpc_end2end_test_config config) {
filter_init_fails_internal(config); grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
gpr_log(GPR_INFO, "Testing with channel filter init error"); [](grpc_core::CoreConfiguration::Builder* builder) {
g_channel_filter_init_failure = true; grpc_core::BuildCoreConfiguration(builder);
filter_init_fails_internal(config); auto register_stage = [builder](grpc_channel_stack_type type,
g_channel_filter_init_failure = false; bool* enable) {
builder->channel_init()->RegisterStage(
type, INT_MAX, [enable](grpc_channel_stack_builder* builder) {
if (!*enable) return true;
// Want to add the filter as close to the end as possible,
// to make sure that all of the filters work well together.
// However, we can't add it at the very end, because either the
// client_channel filter or connected_channel filter must be the
// last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval =
grpc_channel_stack_builder_add_filter_before(
it, &test_filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
});
};
register_stage(GRPC_SERVER_CHANNEL, &g_enable_server_channel_filter);
register_stage(GRPC_CLIENT_CHANNEL, &g_enable_client_channel_filter);
register_stage(GRPC_CLIENT_SUBCHANNEL,
&g_enable_client_subchannel_filter);
register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
&g_enable_client_channel_filter);
},
[config] { filter_init_fails_internal(config); });
} }
void filter_init_fails_pre_init(void) { void filter_init_fails_pre_init(void) {}
grpc_register_plugin(init_plugin, destroy_plugin);
}

@ -27,13 +27,13 @@
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/surface/channel_init.h"
#include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h" #include "test/core/end2end/end2end_tests.h"
enum { TIMEOUT = 200000 }; enum { TIMEOUT = 200000 };
static bool g_enable_filter = false;
static gpr_mu g_mu; static gpr_mu g_mu;
static gpr_timespec g_client_latency; static gpr_timespec g_client_latency;
static gpr_timespec g_server_latency; static gpr_timespec g_server_latency;
@ -304,46 +304,34 @@ static const grpc_channel_filter test_server_filter = {
* Registration * Registration
*/ */
static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) {
grpc_channel_filter* filter = static_cast<grpc_channel_filter*>(arg);
if (g_enable_filter) {
// Want to add the filter as close to the end as possible, to make
// sure that all of the filters work well together. However, we
// can't add it at the very end, because the connected channel filter
// must be the last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
} else {
return true;
}
}
static void init_plugin(void) {
gpr_mu_init(&g_mu);
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_client_filter));
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_client_filter));
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_server_filter));
}
static void destroy_plugin(void) { gpr_mu_destroy(&g_mu); }
void filter_latency(grpc_end2end_test_config config) { void filter_latency(grpc_end2end_test_config config) {
g_enable_filter = true; grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
test_request(config); [](grpc_core::CoreConfiguration::Builder* builder) {
g_enable_filter = false; grpc_core::BuildCoreConfiguration(builder);
auto register_stage = [builder](grpc_channel_stack_type type,
const grpc_channel_filter* filter) {
builder->channel_init()->RegisterStage(
type, INT_MAX, [filter](grpc_channel_stack_builder* builder) {
// Want to add the filter as close to the end as possible, to
// make sure that all of the filters work well together.
// However, we can't add it at the very end, because the
// connected channel filter must be the last one. So we add it
// right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval =
grpc_channel_stack_builder_add_filter_before(
it, filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
});
};
register_stage(GRPC_CLIENT_CHANNEL, &test_client_filter);
register_stage(GRPC_CLIENT_DIRECT_CHANNEL, &test_client_filter);
register_stage(GRPC_SERVER_CHANNEL, &test_server_filter);
},
[config] { test_request(config); });
} }
void filter_latency_pre_init(void) { void filter_latency_pre_init(void) { gpr_mu_init(&g_mu); }
grpc_register_plugin(init_plugin, destroy_plugin);
}

@ -35,12 +35,12 @@
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/call.h" #include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/surface/channel_init.h"
#include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h" #include "test/core/end2end/end2end_tests.h"
static bool g_enable_filter = false;
static gpr_mu g_mu; static gpr_mu g_mu;
static grpc_call_stack* g_client_call_stack; static grpc_call_stack* g_client_call_stack;
static grpc_call_stack* g_server_call_stack; static grpc_call_stack* g_server_call_stack;
@ -109,6 +109,9 @@ static void end_test(grpc_end2end_test_fixture* f) {
// Simple request via a server filter that saves the reported status code. // Simple request via a server filter that saves the reported status code.
static void test_request(grpc_end2end_test_config config) { static void test_request(grpc_end2end_test_config config) {
g_client_code_recv = false;
g_server_code_recv = false;
grpc_call* c; grpc_call* c;
grpc_call* s; grpc_call* s;
grpc_end2end_test_fixture f = grpc_end2end_test_fixture f =
@ -348,56 +351,38 @@ static const grpc_channel_filter test_server_filter = {
* Registration * Registration
*/ */
static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) { void filter_status_code(grpc_end2end_test_config config) {
grpc_channel_filter* filter = static_cast<grpc_channel_filter*>(arg); grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
if (g_enable_filter) { [](grpc_core::CoreConfiguration::Builder* builder) {
// Want to add the filter as close to the end as possible, to make grpc_core::BuildCoreConfiguration(builder);
// sure that all of the filters work well together. However, we auto register_stage = [builder](grpc_channel_stack_type type,
// can't add it at the very end, because the const grpc_channel_filter* filter) {
// connected_channel/client_channel filter must be the last one. builder->channel_init()->RegisterStage(
// So we add it right before the last one. type, INT_MAX, [filter](grpc_channel_stack_builder* builder) {
grpc_channel_stack_builder_iterator* it = // Want to add the filter as close to the end as possible, to
grpc_channel_stack_builder_create_iterator_at_last(builder); // make sure that all of the filters work well together.
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it)); // However, we can't add it at the very end, because the
const bool retval = grpc_channel_stack_builder_add_filter_before( // connected_channel/client_channel filter must be the last one.
it, filter, nullptr, nullptr); // So we add it right before the last one.
grpc_channel_stack_builder_iterator_destroy(it); grpc_channel_stack_builder_iterator* it =
return retval; grpc_channel_stack_builder_create_iterator_at_last(builder);
} else { GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
return true; const bool retval =
} grpc_channel_stack_builder_add_filter_before(
it, filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
});
};
register_stage(GRPC_CLIENT_CHANNEL, &test_client_filter);
register_stage(GRPC_CLIENT_DIRECT_CHANNEL, &test_client_filter);
register_stage(GRPC_SERVER_CHANNEL, &test_server_filter);
},
[config] { test_request(config); });
} }
static void init_plugin(void) { void filter_status_code_pre_init(void) {
gpr_mu_init(&g_mu); gpr_mu_init(&g_mu);
gpr_cv_init(&g_client_code_cv); gpr_cv_init(&g_client_code_cv);
gpr_cv_init(&g_server_code_cv); gpr_cv_init(&g_server_code_cv);
g_client_code_recv = false;
g_server_code_recv = false;
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_client_filter));
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_client_filter));
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_server_filter));
}
static void destroy_plugin(void) {
gpr_cv_destroy(&g_client_code_cv);
gpr_cv_destroy(&g_server_code_cv);
gpr_mu_destroy(&g_mu);
}
void filter_status_code(grpc_end2end_test_config config) {
g_enable_filter = true;
test_request(config);
g_enable_filter = false;
}
void filter_status_code_pre_init(void) {
grpc_register_plugin(init_plugin, destroy_plugin);
} }

@ -31,6 +31,7 @@
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/exec_ctx.h"
@ -305,11 +306,7 @@ grpc_channel_filter FailSendOpsFilter::kFilterVtable = {
"FailSendOpsFilter", "FailSendOpsFilter",
}; };
bool g_enable_filter = false; bool MaybeAddFilter(grpc_channel_stack_builder* builder) {
bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* /*arg*/) {
// Skip if filter is not enabled.
if (!g_enable_filter) return true;
// Skip on proxy (which explicitly disables retries). // Skip on proxy (which explicitly disables retries).
const grpc_channel_args* args = const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder); grpc_channel_stack_builder_get_channel_arguments(builder);
@ -321,24 +318,22 @@ bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* /*arg*/) {
builder, &FailSendOpsFilter::kFilterVtable, nullptr, nullptr); builder, &FailSendOpsFilter::kFilterVtable, nullptr, nullptr);
} }
void InitPlugin(void) {
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, 0, MaybeAddFilter,
nullptr);
}
void DestroyPlugin(void) {}
} // namespace } // namespace
void retry_cancel_with_multiple_send_batches(grpc_end2end_test_config config) { void retry_cancel_with_multiple_send_batches(grpc_end2end_test_config config) {
GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL); GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL);
g_enable_filter = true; grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
for (size_t i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); ++i) { [](grpc_core::CoreConfiguration::Builder* builder) {
test_retry_cancel_with_multiple_send_batches(config, cancellation_modes[i]); grpc_core::BuildCoreConfiguration(builder);
} builder->channel_init()->RegisterStage(GRPC_CLIENT_SUBCHANNEL, 0,
g_enable_filter = false; MaybeAddFilter);
},
[config]() {
for (size_t i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); ++i) {
test_retry_cancel_with_multiple_send_batches(config,
cancellation_modes[i]);
}
});
} }
void retry_cancel_with_multiple_send_batches_pre_init(void) { void retry_cancel_with_multiple_send_batches_pre_init(void) {}
grpc_register_plugin(InitPlugin, DestroyPlugin);
}

@ -27,6 +27,7 @@
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/exec_ctx.h"
@ -337,11 +338,7 @@ grpc_channel_filter InjectStatusFilter::kFilterVtable = {
"InjectStatusFilter", "InjectStatusFilter",
}; };
bool g_enable_filter = false; bool AddFilter(grpc_channel_stack_builder* builder) {
bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* /*arg*/) {
// Skip if filter is not enabled.
if (!g_enable_filter) return true;
// Skip on proxy (which explicitly disables retries). // Skip on proxy (which explicitly disables retries).
const grpc_channel_args* args = const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder); grpc_channel_stack_builder_get_channel_arguments(builder);
@ -353,22 +350,17 @@ bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* /*arg*/) {
builder, &InjectStatusFilter::kFilterVtable, nullptr, nullptr); builder, &InjectStatusFilter::kFilterVtable, nullptr, nullptr);
} }
void InitPlugin(void) {
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, 0, MaybeAddFilter,
nullptr);
}
void DestroyPlugin(void) {}
} // namespace } // namespace
void retry_recv_trailing_metadata_error(grpc_end2end_test_config config) { void retry_recv_trailing_metadata_error(grpc_end2end_test_config config) {
GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL); GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL);
g_enable_filter = true; grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
test_retry_recv_trailing_metadata_error(config); [](grpc_core::CoreConfiguration::Builder* builder) {
g_enable_filter = false; grpc_core::BuildCoreConfiguration(builder);
builder->channel_init()->RegisterStage(GRPC_CLIENT_SUBCHANNEL, 0,
AddFilter);
},
[config] { test_retry_recv_trailing_metadata_error(config); });
} }
void retry_recv_trailing_metadata_error_pre_init() { void retry_recv_trailing_metadata_error_pre_init() {}
grpc_register_plugin(InitPlugin, DestroyPlugin);
}

@ -29,6 +29,7 @@
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/exec_ctx.h"
@ -355,38 +356,29 @@ grpc_channel_filter FailFirstSendOpFilter::kFilterVtable = {
"FailFirstSendOpFilter", "FailFirstSendOpFilter",
}; };
bool g_enable_filter = false;
bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* /*arg*/) {
// Skip if filter is not enabled.
if (!g_enable_filter) return true;
// Skip on proxy (which explicitly disables retries).
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (!grpc_channel_args_find_bool(args, GRPC_ARG_ENABLE_RETRIES, true)) {
return true;
}
// Install filter.
return grpc_channel_stack_builder_prepend_filter(
builder, &FailFirstSendOpFilter::kFilterVtable, nullptr, nullptr);
}
void InitPlugin(void) {
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, 0, MaybeAddFilter,
nullptr);
}
void DestroyPlugin(void) {}
} // namespace } // namespace
void retry_send_op_fails(grpc_end2end_test_config config) { void retry_send_op_fails(grpc_end2end_test_config config) {
GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL); GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL);
g_enable_filter = true; grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
test_retry_send_op_fails(config); [](grpc_core::CoreConfiguration::Builder* builder) {
g_enable_filter = false; grpc_core::BuildCoreConfiguration(builder);
builder->channel_init()->RegisterStage(
GRPC_CLIENT_SUBCHANNEL, 0, [](grpc_channel_stack_builder* builder) {
// Skip on proxy (which explicitly disables retries).
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (!grpc_channel_args_find_bool(args, GRPC_ARG_ENABLE_RETRIES,
true)) {
return true;
}
// Install filter.
return grpc_channel_stack_builder_prepend_filter(
builder, &FailFirstSendOpFilter::kFilterVtable, nullptr,
nullptr);
});
},
[config] { test_retry_send_op_fails(config); });
} }
void retry_send_op_fails_pre_init(void) { void retry_send_op_fails_pre_init(void) {}
grpc_register_plugin(InitPlugin, DestroyPlugin);
}

@ -280,7 +280,7 @@ grpc_cc_test(
deps = [ deps = [
"//:gpr", "//:gpr",
"//:grpc", "//:grpc",
"//:grpc_base_c", "//:grpc_base",
"//:grpc_secure", "//:grpc_secure",
"//:tsi", "//:tsi",
"//:tsi_interface", "//:tsi_interface",

@ -66,7 +66,7 @@ grpc_cc_library(
deps = [ deps = [
":fake_binder", ":fake_binder",
"//:grpc++_base", "//:grpc++_base",
"//:grpc_base_c", "//:grpc_base",
"//src/core/ext/transport/binder/transport:binder_transport", "//src/core/ext/transport/binder/transport:binder_transport",
"//src/core/ext/transport/binder/wire_format:wire_reader", "//src/core/ext/transport/binder/wire_format:wire_reader",
], ],

@ -58,7 +58,6 @@ grpc_fuzzer(
"//:gpr_base", "//:gpr_base",
"//:grpc++_base", "//:grpc++_base",
"//:grpc_base", "//:grpc_base",
"//:grpc_base_c",
"//src/core/ext/transport/binder/transport:binder_transport", "//src/core/ext/transport/binder/transport:binder_transport",
"//test/core/util:grpc_test_util", "//test/core/util:grpc_test_util",
], ],
@ -79,7 +78,6 @@ grpc_fuzzer(
"//:gpr_base", "//:gpr_base",
"//:grpc++_base", "//:grpc++_base",
"//:grpc_base", "//:grpc_base",
"//:grpc_base_c",
"//src/core/ext/transport/binder/transport:binder_transport", "//src/core/ext/transport/binder/transport:binder_transport",
"//test/core/util:grpc_test_util", "//test/core/util:grpc_test_util",
], ],

@ -26,7 +26,7 @@ grpc_cc_test(
"//:alts_frame_protector", "//:alts_frame_protector",
"//:gpr", "//:gpr",
"//:grpc", "//:grpc",
"//:grpc_base_c", "//:grpc_base",
"//test/core/tsi/alts/crypt:alts_crypt_test_util", "//test/core/tsi/alts/crypt:alts_crypt_test_util",
"//test/core/util:grpc_test_util", "//test/core/util:grpc_test_util",
], ],
@ -53,7 +53,7 @@ grpc_cc_test(
"//:alts_frame_protector", "//:alts_frame_protector",
"//:gpr", "//:gpr",
"//:grpc", "//:grpc",
"//:grpc_base_c", "//:grpc_base",
"//test/core/tsi/alts/crypt:alts_crypt_test_util", "//test/core/tsi/alts/crypt:alts_crypt_test_util",
"//test/core/util:grpc_test_util", "//test/core/util:grpc_test_util",
], ],

@ -88,7 +88,7 @@ grpc_cc_library(
":grpc_suppressions", ":grpc_suppressions",
":stack_tracer", ":stack_tracer",
"//:gpr", "//:gpr",
"//:grpc_base_c", "//:grpc_base",
"//:grpc_common", "//:grpc_common",
], ],
) )

@ -28,6 +28,7 @@
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpcpp/grpcpp.h> #include <grpcpp/grpcpp.h>
#include "src/core/lib/config/core_configuration.h"
#include "src/cpp/ext/filters/census/grpc_plugin.h" #include "src/cpp/ext/filters/census/grpc_plugin.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
@ -86,6 +87,7 @@ class EchoServerThread final {
}; };
static void BM_E2eLatencyCensusDisabled(benchmark::State& state) { static void BM_E2eLatencyCensusDisabled(benchmark::State& state) {
grpc_core::CoreConfiguration::Reset();
grpc::testing::TestGrpcScope grpc_scope; grpc::testing::TestGrpcScope grpc_scope;
EchoServerThread server; EchoServerThread server;
std::unique_ptr<grpc::testing::EchoTestService::Stub> stub = std::unique_ptr<grpc::testing::EchoTestService::Stub> stub =
@ -102,6 +104,7 @@ static void BM_E2eLatencyCensusDisabled(benchmark::State& state) {
BENCHMARK(BM_E2eLatencyCensusDisabled); BENCHMARK(BM_E2eLatencyCensusDisabled);
static void BM_E2eLatencyCensusEnabled(benchmark::State& state) { static void BM_E2eLatencyCensusEnabled(benchmark::State& state) {
grpc_core::CoreConfiguration::Reset();
// Now start the test by registering the plugin (once in the execution) // Now start the test by registering the plugin (once in the execution)
RegisterOnce(); RegisterOnce();
// This we can safely repeat, and doing so clears accumulated data to avoid // This we can safely repeat, and doing so clears accumulated data to avoid

@ -2115,6 +2115,8 @@ src/core/lib/slice/static_slice.cc \
src/core/lib/slice/static_slice.h \ src/core/lib/slice/static_slice.h \
src/core/lib/surface/api_trace.cc \ src/core/lib/surface/api_trace.cc \
src/core/lib/surface/api_trace.h \ src/core/lib/surface/api_trace.h \
src/core/lib/surface/builtins.cc \
src/core/lib/surface/builtins.h \
src/core/lib/surface/byte_buffer.cc \ src/core/lib/surface/byte_buffer.cc \
src/core/lib/surface/byte_buffer_reader.cc \ src/core/lib/surface/byte_buffer_reader.cc \
src/core/lib/surface/call.cc \ src/core/lib/surface/call.cc \

@ -1956,6 +1956,8 @@ src/core/lib/slice/static_slice.h \
src/core/lib/surface/README.md \ src/core/lib/surface/README.md \
src/core/lib/surface/api_trace.cc \ src/core/lib/surface/api_trace.cc \
src/core/lib/surface/api_trace.h \ src/core/lib/surface/api_trace.h \
src/core/lib/surface/builtins.cc \
src/core/lib/surface/builtins.h \
src/core/lib/surface/byte_buffer.cc \ src/core/lib/surface/byte_buffer.cc \
src/core/lib/surface/byte_buffer_reader.cc \ src/core/lib/surface/byte_buffer_reader.cc \
src/core/lib/surface/call.cc \ src/core/lib/surface/call.cc \

Loading…
Cancel
Save