[lb_policy] Move to core configuration system (#30483)

* [load_balancing] Move interfaces to src/core/lib/load_balancing

* Automated change: Fix sanity tests

* progress

* progress

* fix

* missed file

* Automated change: Fix sanity tests

* update tests

* Automated change: Fix sanity tests

* Automated change: Fix sanity tests

* fix

* fix

* Automated change: Fix sanity tests

* fix

* fixes

* fix

* fix

* fix

* fix

* fix

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/30774/head
Craig Tiller 3 years ago committed by GitHub
parent 8d35fcff3b
commit 535168431a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 56
      BUILD
  2. 8
      src/core/ext/filters/client_channel/client_channel.cc
  3. 3
      src/core/ext/filters/client_channel/client_channel_plugin.cc
  4. 6
      src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc
  5. 6
      src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h
  6. 14
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  7. 23
      src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc
  8. 12
      src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc
  9. 21
      src/core/ext/filters/client_channel/lb_policy/priority/priority.cc
  10. 7
      src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc
  11. 14
      src/core/ext/filters/client_channel/lb_policy/rls/rls.cc
  12. 12
      src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc
  13. 21
      src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc
  14. 26
      src/core/ext/filters/client_channel/lb_policy/xds/cds.cc
  15. 27
      src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc
  16. 21
      src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc
  17. 21
      src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc
  18. 1
      src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc
  19. 9
      src/core/ext/filters/client_channel/resolver_result_parsing.cc
  20. 1
      src/core/ext/transport/chttp2/server/chttp2_server.cc
  21. 1
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  22. 1
      src/core/ext/transport/cronet/transport/cronet_transport.cc
  23. 1
      src/core/ext/transport/inproc/inproc_transport.cc
  24. 4
      src/core/ext/xds/xds_cluster_specifier_plugin.cc
  25. 6
      src/core/ext/xds/xds_lb_policy_registry.cc
  26. 3
      src/core/lib/config/core_configuration.cc
  27. 11
      src/core/lib/config/core_configuration.h
  28. 1
      src/core/lib/iomgr/iomgr_fwd.h
  29. 2
      src/core/lib/iomgr/pollset.h
  30. 1
      src/core/lib/iomgr/pollset_set.h
  31. 1
      src/core/lib/iomgr/resolve_address.h
  32. 1
      src/core/lib/iomgr/resolve_address_impl.h
  33. 1
      src/core/lib/iomgr/resolve_address_posix.cc
  34. 1
      src/core/lib/iomgr/resolve_address_windows.cc
  35. 84
      src/core/lib/load_balancing/lb_policy_registry.cc
  36. 34
      src/core/lib/load_balancing/lb_policy_registry.h
  37. 1
      src/core/lib/security/credentials/google_default/google_default_credentials.cc
  38. 1
      src/core/lib/security/credentials/jwt/jwt_verifier.cc
  39. 2
      src/core/lib/security/credentials/jwt/jwt_verifier.h
  40. 1
      src/core/lib/security/transport/secure_endpoint.cc
  41. 2
      src/core/lib/surface/completion_queue.h
  42. 1
      src/core/lib/surface/server.h
  43. 1
      src/core/lib/transport/transport.h
  44. 1
      src/core/lib/transport/transport_impl.h
  45. 64
      src/core/plugin_registry/grpc_plugin_registry.cc
  46. 25
      src/core/plugin_registry/grpc_plugin_registry_extra.cc
  47. 1
      test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc
  48. 8
      test/core/client_channel/service_config_test.cc
  49. 2
      test/core/end2end/BUILD
  50. 2
      test/core/end2end/bad_server_response_test.cc
  51. 25
      test/core/end2end/tests/retry_lb_drop.cc
  52. 9
      test/core/end2end/tests/retry_lb_fail.cc
  53. 1
      test/core/iomgr/resolve_address_posix_test.cc
  54. 1
      test/core/iomgr/resolve_address_test.cc
  55. 2
      test/core/security/verify_jwt.cc
  56. 1
      test/core/surface/completion_queue_test.cc
  57. 1
      test/core/surface/completion_queue_threading_test.cc
  58. 1
      test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc
  59. 1
      test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc
  60. 4
      test/core/util/BUILD
  61. 1
      test/core/util/mock_endpoint.cc
  62. 1
      test/core/util/passthru_endpoint.cc
  63. 1
      test/core/util/port_server_client.cc
  64. 2
      test/core/util/reconnect_server.cc
  65. 28
      test/core/util/test_lb_policies.cc
  66. 18
      test/core/util/test_lb_policies.h
  67. 1
      test/core/util/test_tcp_server.cc
  68. 2
      test/core/util/test_tcp_server.h
  69. 10
      test/core/xds/xds_lb_policy_registry_test.cc
  70. 50
      test/cpp/end2end/client_lb_end2end_test.cc
  71. 4
      test/cpp/end2end/rls_end2end_test.cc
  72. 2
      test/cpp/end2end/xds/xds_outlier_detection_end2end_test.cc

56
BUILD

@ -1134,6 +1134,7 @@ grpc_cc_library(
"gpr",
"grpc_resolver",
"handshaker_registry",
"lb_policy_registry",
"service_config_parser",
],
)
@ -1803,6 +1804,7 @@ grpc_cc_library(
"handshaker_factory",
"handshaker_registry",
"iomgr_fwd",
"pollset_set",
"ref_counted_ptr",
"resolved_address",
"slice",
@ -2852,6 +2854,20 @@ grpc_cc_library(
],
)
grpc_cc_library(
name = "pollset_set",
srcs = [
"src/core/lib/iomgr/pollset_set.cc",
],
hdrs = [
"src/core/lib/iomgr/pollset_set.h",
],
deps = [
"gpr",
"iomgr_fwd",
],
)
grpc_cc_library(
name = "grpc_base",
srcs = [
@ -2902,7 +2918,6 @@ grpc_cc_library(
"src/core/lib/iomgr/lockfree_event.cc",
"src/core/lib/iomgr/polling_entity.cc",
"src/core/lib/iomgr/pollset.cc",
"src/core/lib/iomgr/pollset_set.cc",
"src/core/lib/iomgr/pollset_set_windows.cc",
"src/core/lib/iomgr/pollset_windows.cc",
"src/core/lib/iomgr/resolve_address.cc",
@ -3008,7 +3023,6 @@ grpc_cc_library(
"src/core/lib/iomgr/nameser.h",
"src/core/lib/iomgr/polling_entity.h",
"src/core/lib/iomgr/pollset.h",
"src/core/lib/iomgr/pollset_set.h",
"src/core/lib/iomgr/pollset_set_windows.h",
"src/core/lib/iomgr/pollset_windows.h",
"src/core/lib/iomgr/python_util.h",
@ -3129,6 +3143,7 @@ grpc_cc_library(
"orphanable",
"percent_encoding",
"poll",
"pollset_set",
"promise",
"ref_counted",
"ref_counted_ptr",
@ -3432,14 +3447,18 @@ grpc_cc_library(
"absl/types:variant",
],
deps = [
"channel_args",
"closure",
"debug_location",
"error",
"exec_ctx",
"gpr_platform",
"grpc_backend_metric_data",
"grpc_base",
"grpc_codegen",
"grpc_trace",
"iomgr_fwd",
"orphanable",
"pollset_set",
"ref_counted",
"ref_counted_ptr",
"server_address",
@ -3489,8 +3508,8 @@ grpc_cc_library(
hdrs = ["src/core/lib/load_balancing/subchannel_interface.h"],
external_deps = ["absl/status"],
deps = [
"gpr",
"grpc_base",
"channel_args",
"gpr_platform",
"grpc_codegen",
"iomgr_fwd",
"ref_counted",
@ -3598,6 +3617,7 @@ grpc_cc_library(
"lb_policy_registry",
"memory_quota",
"orphanable",
"pollset_set",
"protobuf_duration_upb",
"ref_counted",
"ref_counted_ptr",
@ -4057,6 +4077,7 @@ grpc_cc_library(
"lb_policy_factory",
"lb_policy_registry",
"orphanable",
"pollset_set",
"protobuf_duration_upb",
"protobuf_timestamp_upb",
"ref_counted",
@ -4122,6 +4143,7 @@ grpc_cc_library(
"lb_policy_factory",
"lb_policy_registry",
"orphanable",
"pollset_set",
"ref_counted_ptr",
"rls_upb",
"server_address",
@ -4277,6 +4299,7 @@ grpc_cc_library(
"lb_policy_registry",
"match",
"orphanable",
"pollset_set",
"protobuf_any_upb",
"protobuf_duration_upb",
"protobuf_struct_upb",
@ -4431,6 +4454,7 @@ grpc_cc_library(
],
language = "c++",
deps = [
"config",
"debug_location",
"gpr",
"grpc_base",
@ -4446,6 +4470,7 @@ grpc_cc_library(
"lb_policy_factory",
"lb_policy_registry",
"orphanable",
"pollset_set",
"ref_counted_ptr",
"server_address",
"subchannel_interface",
@ -4513,6 +4538,7 @@ grpc_cc_library(
"lb_policy_factory",
"lb_policy_registry",
"orphanable",
"pollset_set",
"ref_counted_ptr",
"server_address",
"subchannel_interface",
@ -4537,6 +4563,7 @@ grpc_cc_library(
language = "c++",
deps = [
"channel_args",
"config",
"debug_location",
"gpr",
"grpc_base",
@ -4551,6 +4578,7 @@ grpc_cc_library(
"lb_policy_factory",
"lb_policy_registry",
"orphanable",
"pollset_set",
"ref_counted",
"ref_counted_ptr",
"server_address",
@ -4573,6 +4601,7 @@ grpc_cc_library(
deps = [
"channel_args",
"closure",
"config",
"debug_location",
"exec_ctx",
"gpr",
@ -4587,6 +4616,7 @@ grpc_cc_library(
"lb_policy_factory",
"lb_policy_registry",
"orphanable",
"pollset_set",
"ref_counted",
"ref_counted_ptr",
"server_address",
@ -4655,6 +4685,7 @@ grpc_cc_library(
language = "c++",
deps = [
"channel_args",
"config",
"debug_location",
"gpr",
"grpc_base",
@ -4693,6 +4724,7 @@ grpc_cc_library(
language = "c++",
deps = [
"closure",
"config",
"debug_location",
"exec_ctx",
"gpr",
@ -4729,6 +4761,7 @@ grpc_cc_library(
],
language = "c++",
deps = [
"config",
"debug_location",
"gpr",
"grpc_base",
@ -4776,6 +4809,7 @@ grpc_cc_library(
deps = [
"channel_args",
"closure",
"config",
"debug_location",
"exec_ctx",
"gpr",
@ -4792,6 +4826,7 @@ grpc_cc_library(
"lb_policy_factory",
"lb_policy_registry",
"orphanable",
"pollset_set",
"ref_counted",
"ref_counted_ptr",
"server_address",
@ -4817,6 +4852,7 @@ grpc_cc_library(
deps = [
"channel_args",
"closure",
"config",
"debug_location",
"exec_ctx",
"gpr",
@ -4831,6 +4867,7 @@ grpc_cc_library(
"lb_policy_factory",
"lb_policy_registry",
"orphanable",
"pollset_set",
"ref_counted",
"ref_counted_ptr",
"server_address",
@ -4855,6 +4892,7 @@ grpc_cc_library(
language = "c++",
deps = [
"channel_args",
"config",
"debug_location",
"default_event_engine",
"gpr",
@ -4868,6 +4906,7 @@ grpc_cc_library(
"lb_policy_factory",
"lb_policy_registry",
"orphanable",
"pollset_set",
"ref_counted",
"ref_counted_ptr",
"server_address",
@ -5167,6 +5206,7 @@ grpc_cc_library(
"json",
"orphanable",
"polling_resolver",
"pollset_set",
"ref_counted_ptr",
"resolved_address",
"server_address",
@ -5309,6 +5349,7 @@ grpc_cc_library(
"iomgr_fwd",
"match",
"orphanable",
"pollset_set",
"ref_counted_ptr",
"server_address",
"time",
@ -5389,6 +5430,7 @@ grpc_cc_library(
"handshaker_registry",
"iomgr_fwd",
"orphanable",
"pollset_set",
"ref_counted_ptr",
"resolved_address",
"resource_quota",
@ -5690,6 +5732,7 @@ grpc_cc_library(
"grpc_ssl_credentials",
"grpc_trace",
"httpcli",
"iomgr_fwd",
"json",
"ref_counted_ptr",
"slice_refcount",
@ -5819,6 +5862,7 @@ grpc_cc_library(
"grpc_trace",
"httpcli",
"httpcli_ssl_credentials",
"iomgr_fwd",
"json",
"orphanable",
"promise",
@ -5864,6 +5908,7 @@ grpc_cc_library(
"json",
"orphanable",
"poll",
"pollset_set",
"promise",
"ref_counted",
"ref_counted_ptr",
@ -6630,6 +6675,7 @@ grpc_cc_library(
"iomgr_timer",
"memory_quota",
"orphanable",
"pollset_set",
"ref_counted_ptr",
"resolved_address",
"resource_quota",

@ -1112,8 +1112,9 @@ RefCountedPtr<LoadBalancingPolicy::Config> ChooseLbPolicy(
policy_name = resolver_result.args.GetString(GRPC_ARG_LB_POLICY_NAME);
bool requires_config = false;
if (policy_name.has_value() &&
(!LoadBalancingPolicyRegistry::LoadBalancingPolicyExists(
*policy_name, &requires_config) ||
(!CoreConfiguration::Get()
.lb_policy_registry()
.LoadBalancingPolicyExists(*policy_name, &requires_config) ||
requires_config)) {
if (requires_config) {
gpr_log(GPR_ERROR,
@ -1137,7 +1138,8 @@ RefCountedPtr<LoadBalancingPolicy::Config> ChooseLbPolicy(
{std::string(*policy_name), Json::Object{}},
}};
auto lb_policy_config =
LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(config_json);
CoreConfiguration::Get().lb_policy_registry().ParseLoadBalancingConfig(
config_json);
// The policy name came from one of three places:
// - The deprecated loadBalancingPolicy field in the service config,
// in which case the code in ClientChannelServiceConfigParser

@ -26,12 +26,10 @@
#include "src/core/ext/filters/client_channel/retry_service_config.h"
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/load_balancing/lb_policy_registry.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/surface/channel_stack_type.h"
void grpc_client_channel_init(void) {
grpc_core::LoadBalancingPolicyRegistry::Builder::InitRegistry();
grpc_core::ProxyMapperRegistry::Init();
grpc_core::RegisterHttpProxyMapper();
grpc_client_channel_global_init_backup_polling();
@ -39,7 +37,6 @@ void grpc_client_channel_init(void) {
void grpc_client_channel_shutdown(void) {
grpc_core::ProxyMapperRegistry::Shutdown();
grpc_core::LoadBalancingPolicyRegistry::Builder::ShutdownRegistry();
}
namespace grpc_core {

@ -29,6 +29,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/iomgr/pollset_set.h"
#include "src/core/lib/load_balancing/lb_policy_registry.h"
@ -311,8 +312,9 @@ bool ChildPolicyHandler::ConfigChangeRequiresNewPolicyInstance(
OrphanablePtr<LoadBalancingPolicy>
ChildPolicyHandler::CreateLoadBalancingPolicy(
absl::string_view name, LoadBalancingPolicy::Args args) const {
return LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
name, std::move(args));
return CoreConfiguration::Get()
.lb_policy_registry()
.CreateLoadBalancingPolicy(name, std::move(args));
}
} // namespace grpc_core

@ -33,9 +33,9 @@ namespace grpc_core {
// A class that makes it easy to gracefully switch child policies.
//
// Callers should instantiate this instead of using
// LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(). Once
// instantiated, this object will automatically take care of
// constructing the child policy as needed upon receiving an update.
// CoreConfiguration::Get().lb_policy_registry().CreateLoadBalancingPolicy().
// Once instantiated, this object will automatically take care of constructing
// the child policy as needed upon receiving an update.
class ChildPolicyHandler : public LoadBalancingPolicy {
public:
ChildPolicyHandler(Args args, TraceFlag* tracer)

@ -1877,7 +1877,7 @@ class GrpcLbFactory : public LoadBalancingPolicyFactory {
child_policy_config_json = &it->second;
}
auto child_policy_config =
LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(
CoreConfiguration::Get().lb_policy_registry().ParseLoadBalancingConfig(
*child_policy_config_json);
if (!child_policy_config.ok()) {
error_list.emplace_back(
@ -1903,16 +1903,10 @@ class GrpcLbFactory : public LoadBalancingPolicyFactory {
// Plugin registration
//
void grpc_lb_policy_grpclb_init() {
grpc_core::LoadBalancingPolicyRegistry::Builder::
RegisterLoadBalancingPolicyFactory(
absl::make_unique<grpc_core::GrpcLbFactory>());
}
void grpc_lb_policy_grpclb_shutdown() {}
namespace grpc_core {
void RegisterGrpcLbLoadReportingFilter(CoreConfiguration::Builder* builder) {
void RegisterGrpcLbPolicy(CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<GrpcLbFactory>());
builder->channel_init()->RegisterStage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
[](ChannelStackBuilder* builder) {

@ -48,6 +48,7 @@
#include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h"
#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/string.h"
@ -1105,8 +1106,9 @@ class OutlierDetectionLbFactory : public LoadBalancingPolicyFactory {
if (it == json.object_value().end()) {
errors.emplace_back("field:childPolicy error:required field missing");
} else {
auto child_policy_config =
LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(it->second);
auto child_policy_config = CoreConfiguration::Get()
.lb_policy_registry()
.ParseLoadBalancingConfig(it->second);
if (!child_policy_config.ok()) {
errors.emplace_back(
absl::StrCat("error parsing childPolicy field: ",
@ -1131,18 +1133,11 @@ class OutlierDetectionLbFactory : public LoadBalancingPolicyFactory {
} // namespace
} // namespace grpc_core
//
// Plugin registration
//
void grpc_lb_policy_outlier_detection_init() {
if (grpc_core::XdsOutlierDetectionEnabled()) {
grpc_core::LoadBalancingPolicyRegistry::Builder::
RegisterLoadBalancingPolicyFactory(
absl::make_unique<grpc_core::OutlierDetectionLbFactory>());
void RegisterOutlierDetectionLbPolicy(CoreConfiguration::Builder* builder) {
if (XdsOutlierDetectionEnabled()) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<OutlierDetectionLbFactory>());
}
}
void grpc_lb_policy_outlier_detection_shutdown() {}
} // namespace grpc_core

@ -38,6 +38,7 @@
#include "src/core/ext/filters/client_channel/lb_policy/subchannel_list.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/orphanable.h"
@ -527,12 +528,9 @@ class PickFirstFactory : public LoadBalancingPolicyFactory {
} // namespace
} // namespace grpc_core
void grpc_lb_policy_pick_first_init() {
grpc_core::LoadBalancingPolicyRegistry::Builder::
RegisterLoadBalancingPolicyFactory(
absl::make_unique<grpc_core::PickFirstFactory>());
void RegisterPickFirstLbPolicy(CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<PickFirstFactory>());
}
void grpc_lb_policy_pick_first_shutdown() {}
} // namespace grpc_core

@ -41,6 +41,7 @@
#include "src/core/ext/filters/client_channel/lb_policy/address_filtering.h"
#include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/orphanable.h"
@ -983,8 +984,9 @@ class PriorityLbFactory : public LoadBalancingPolicyFactory {
"be type boolean"));
}
}
auto config = LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(
it2->second);
auto config = CoreConfiguration::Get()
.lb_policy_registry()
.ParseLoadBalancingConfig(it2->second);
if (!config.ok()) {
errors.emplace_back(
absl::StrCat("field:children key:", child_name, ": ",
@ -1038,16 +1040,9 @@ class PriorityLbFactory : public LoadBalancingPolicyFactory {
} // namespace
} // namespace grpc_core
//
// Plugin registration
//
void grpc_lb_policy_priority_init() {
grpc_core::LoadBalancingPolicyRegistry::Builder::
RegisterLoadBalancingPolicyFactory(
absl::make_unique<grpc_core::PriorityLbFactory>());
void RegisterPriorityLbPolicy(CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<PriorityLbFactory>());
}
void grpc_lb_policy_priority_shutdown() {}
} // namespace grpc_core

@ -52,6 +52,7 @@
#include "src/core/ext/filters/client_channel/lb_policy/subchannel_list.h"
#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/debug_location.h"
@ -897,11 +898,9 @@ class RingHashFactory : public LoadBalancingPolicyFactory {
} // namespace
void GrpcLbPolicyRingHashInit() {
LoadBalancingPolicyRegistry::Builder::RegisterLoadBalancingPolicyFactory(
void RegisterRingHashLbPolicy(CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<RingHashFactory>());
}
void GrpcLbPolicyRingHashShutdown() {}
} // namespace grpc_core

@ -790,8 +790,9 @@ void RlsLb::ChildPolicyWrapper::StartUpdate() {
lb_policy_.get(), this, target_.c_str(),
child_policy_config.Dump().c_str());
}
auto config = LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(
child_policy_config);
auto config =
CoreConfiguration::Get().lb_policy_registry().ParseLoadBalancingConfig(
child_policy_config);
// Returned RLS target fails the validation.
if (!config.ok()) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_rls_trace)) {
@ -2441,8 +2442,9 @@ grpc_error_handle ValidateChildPolicyList(
child_policy_config_target_field_name, target, child_policy_config);
if (!GRPC_ERROR_IS_NONE(error)) return error;
// Parse the config.
auto parsed_config = LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(
*child_policy_config);
auto parsed_config =
CoreConfiguration::Get().lb_policy_registry().ParseLoadBalancingConfig(
*child_policy_config);
if (!parsed_config.ok()) {
return absl_status_to_grpc_error(parsed_config.status());
}
@ -2558,8 +2560,8 @@ class RlsLbFactory : public LoadBalancingPolicyFactory {
} // namespace
void RlsLbPluginInit() {
LoadBalancingPolicyRegistry::Builder::RegisterLoadBalancingPolicyFactory(
void RegisterRlsLbPolicy(CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<RlsLbFactory>());
}

@ -37,6 +37,7 @@
#include "src/core/ext/filters/client_channel/lb_policy/subchannel_list.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/orphanable.h"
@ -520,12 +521,9 @@ class RoundRobinFactory : public LoadBalancingPolicyFactory {
} // namespace
} // namespace grpc_core
void grpc_lb_policy_round_robin_init() {
grpc_core::LoadBalancingPolicyRegistry::Builder::
RegisterLoadBalancingPolicyFactory(
absl::make_unique<grpc_core::RoundRobinFactory>());
void RegisterRoundRobinLbPolicy(CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<RoundRobinFactory>());
}
void grpc_lb_policy_round_robin_shutdown() {}
} // namespace grpc_core

@ -41,6 +41,7 @@
#include "src/core/ext/filters/client_channel/lb_policy/address_filtering.h"
#include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/event_engine/default_event_engine.h"
#include "src/core/lib/gpr/string.h"
@ -749,8 +750,9 @@ class WeightedTargetLbFactory : public LoadBalancingPolicyFactory {
// Child policy.
it = json.object_value().find("childPolicy");
if (it != json.object_value().end()) {
auto config =
LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(it->second);
auto config = CoreConfiguration::Get()
.lb_policy_registry()
.ParseLoadBalancingConfig(it->second);
if (!config.ok()) {
errors.emplace_back(
absl::StrCat("field:childPolicy: ", config.status().message()));
@ -769,16 +771,9 @@ class WeightedTargetLbFactory : public LoadBalancingPolicyFactory {
} // namespace
} // namespace grpc_core
//
// Plugin registration
//
void grpc_lb_policy_weighted_target_init() {
grpc_core::LoadBalancingPolicyRegistry::Builder::
RegisterLoadBalancingPolicyFactory(
absl::make_unique<grpc_core::WeightedTargetLbFactory>());
void RegisterWeightedTargetLbPolicy(CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<WeightedTargetLbFactory>());
}
void grpc_lb_policy_weighted_target_shutdown() {}
} // namespace grpc_core

@ -47,6 +47,7 @@
#include "src/core/ext/xds/xds_common_types.h"
#include "src/core/ext/xds/xds_resource_type_impl.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/orphanable.h"
@ -517,7 +518,9 @@ void CdsLb::OnClusterChanged(const std::string& name,
this, json_str.c_str());
}
grpc_error_handle error = GRPC_ERROR_NONE;
auto config = LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(json);
auto config =
CoreConfiguration::Get().lb_policy_registry().ParseLoadBalancingConfig(
json);
if (!config.ok()) {
OnError(name, absl::UnavailableError(config.status().message()));
return;
@ -528,8 +531,10 @@ void CdsLb::OnClusterChanged(const std::string& name,
args.work_serializer = work_serializer();
args.args = args_;
args.channel_control_helper = absl::make_unique<Helper>(Ref());
child_policy_ = LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
(*config)->name(), std::move(args));
child_policy_ =
CoreConfiguration::Get()
.lb_policy_registry()
.CreateLoadBalancingPolicy((*config)->name(), std::move(args));
if (child_policy_ == nullptr) {
OnError(name, absl::UnavailableError("failed to create child policy"));
return;
@ -756,16 +761,9 @@ class CdsLbFactory : public LoadBalancingPolicyFactory {
} // namespace
} // namespace grpc_core
//
// Plugin registration
//
void grpc_lb_policy_cds_init() {
grpc_core::LoadBalancingPolicyRegistry::Builder::
RegisterLoadBalancingPolicyFactory(
absl::make_unique<grpc_core::CdsLbFactory>());
void RegisterCdsLbPolicy(CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<CdsLbFactory>());
}
void grpc_lb_policy_cds_shutdown() {}
} // namespace grpc_core

@ -50,6 +50,7 @@
#include "src/core/ext/xds/xds_client_stats.h"
#include "src/core/ext/xds/xds_endpoint.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/debug_location.h"
@ -106,7 +107,8 @@ class CircuitBreakerCallCounterMap {
std::map<Key, CallCounter*> map_ ABSL_GUARDED_BY(mu_);
};
CircuitBreakerCallCounterMap* g_call_counter_map = nullptr;
CircuitBreakerCallCounterMap* const g_call_counter_map =
new CircuitBreakerCallCounterMap;
RefCountedPtr<CircuitBreakerCallCounterMap::CallCounter>
CircuitBreakerCallCounterMap::GetOrCreate(const std::string& cluster,
@ -724,8 +726,9 @@ class XdsClusterImplLbFactory : public LoadBalancingPolicyFactory {
if (it == json.object_value().end()) {
errors.emplace_back("field:childPolicy error:required field missing");
} else {
auto config =
LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(it->second);
auto config = CoreConfiguration::Get()
.lb_policy_registry()
.ParseLoadBalancingConfig(it->second);
if (!config.ok()) {
errors.emplace_back(absl::StrCat("field:childPolicy error:",
config.status().message()));
@ -863,19 +866,9 @@ class XdsClusterImplLbFactory : public LoadBalancingPolicyFactory {
} // namespace
} // namespace grpc_core
//
// Plugin registration
//
void grpc_lb_policy_xds_cluster_impl_init() {
grpc_core::g_call_counter_map = new grpc_core::CircuitBreakerCallCounterMap();
grpc_core::LoadBalancingPolicyRegistry::Builder::
RegisterLoadBalancingPolicyFactory(
absl::make_unique<grpc_core::XdsClusterImplLbFactory>());
void RegisterXdsClusterImplLbPolicy(CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<XdsClusterImplLbFactory>());
}
void grpc_lb_policy_xds_cluster_impl_shutdown() {
delete grpc_core::g_call_counter_map;
}
} // namespace grpc_core

@ -40,6 +40,7 @@
#include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h"
#include "src/core/ext/filters/client_channel/resolver/xds/xds_resolver.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/orphanable.h"
@ -685,8 +686,9 @@ class XdsClusterManagerLbFactory : public LoadBalancingPolicyFactory {
if (it == json.object_value().end()) {
errors.emplace_back("did not find childPolicy");
} else {
auto config =
LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(it->second);
auto config = CoreConfiguration::Get()
.lb_policy_registry()
.ParseLoadBalancingConfig(it->second);
if (!config.ok()) {
errors.emplace_back(absl::StrCat("field:childPolicy error:",
config.status().message()));
@ -703,16 +705,9 @@ class XdsClusterManagerLbFactory : public LoadBalancingPolicyFactory {
} // namespace
} // namespace grpc_core
//
// Plugin registration
//
void grpc_lb_policy_xds_cluster_manager_init() {
grpc_core::LoadBalancingPolicyRegistry::Builder::
RegisterLoadBalancingPolicyFactory(
absl::make_unique<grpc_core::XdsClusterManagerLbFactory>());
void RegisterXdsClusterManagerLbPolicy(CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<XdsClusterManagerLbFactory>());
}
void grpc_lb_policy_xds_cluster_manager_shutdown() {}
} // namespace grpc_core

@ -976,7 +976,9 @@ XdsClusterResolverLb::CreateChildPolicyConfigLocked() {
"[xds_cluster_resolver_lb %p] generated config for child policy: %s",
this, json_str.c_str());
}
auto config = LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(json);
auto config =
CoreConfiguration::Get().lb_policy_registry().ParseLoadBalancingConfig(
json);
if (!config.ok()) {
// This should never happen, but if it does, we basically have no
// way to fix it, so we put the channel in TRANSIENT_FAILURE.
@ -1029,7 +1031,7 @@ XdsClusterResolverLb::CreateChildPolicyLocked(const ChannelArgs& args) {
lb_policy_args.channel_control_helper =
absl::make_unique<Helper>(Ref(DEBUG_LOCATION, "Helper"));
OrphanablePtr<LoadBalancingPolicy> lb_policy =
LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
CoreConfiguration::Get().lb_policy_registry().CreateLoadBalancingPolicy(
"priority_experimental", std::move(lb_policy_args));
if (GPR_UNLIKELY(lb_policy == nullptr)) {
gpr_log(GPR_ERROR,
@ -1335,16 +1337,9 @@ class XdsClusterResolverLbFactory : public LoadBalancingPolicyFactory {
} // namespace
} // namespace grpc_core
//
// Plugin registration
//
void grpc_lb_policy_xds_cluster_resolver_init() {
grpc_core::LoadBalancingPolicyRegistry::Builder::
RegisterLoadBalancingPolicyFactory(
absl::make_unique<grpc_core::XdsClusterResolverLbFactory>());
void RegisterXdsClusterResolverLbPolicy(CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<XdsClusterResolverLbFactory>());
}
void grpc_lb_policy_xds_cluster_resolver_shutdown() {}
} // namespace grpc_core

@ -20,6 +20,7 @@
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "absl/memory/memory.h"
#include "absl/status/statusor.h"

@ -85,12 +85,13 @@ absl::StatusOr<std::unique_ptr<ServiceConfigParser::ParsedConfig>>
ClientChannelServiceConfigParser::ParseGlobalParams(const ChannelArgs& /*args*/,
const Json& json) {
std::vector<grpc_error_handle> error_list;
const auto& lb_policy_registry =
CoreConfiguration::Get().lb_policy_registry();
// Parse LB config.
RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config;
auto it = json.object_value().find("loadBalancingConfig");
if (it != json.object_value().end()) {
auto config =
LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(it->second);
auto config = lb_policy_registry.ParseLoadBalancingConfig(it->second);
if (!config.ok()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat(
"field:loadBalancingConfig error:", config.status().message())));
@ -111,8 +112,8 @@ ClientChannelServiceConfigParser::ParseGlobalParams(const ChannelArgs& /*args*/,
lb_policy_name[i] = tolower(lb_policy_name[i]);
}
bool requires_config = false;
if (!LoadBalancingPolicyRegistry::LoadBalancingPolicyExists(
lb_policy_name.c_str(), &requires_config)) {
if (!lb_policy_registry.LoadBalancingPolicyExists(lb_policy_name.c_str(),
&requires_config)) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"field:loadBalancingPolicy error:Unknown lb policy"));
} else if (requires_config) {

@ -63,7 +63,6 @@
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/pollset_set.h"
#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/resolved_address.h"

@ -72,7 +72,6 @@
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/promise/poll.h"

@ -51,7 +51,6 @@
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/resource_quota/arena.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_buffer.h"

@ -54,7 +54,6 @@
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/resource_quota/arena.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_buffer.h"

@ -33,6 +33,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/json/json.h"
#include "src/core/lib/load_balancing/lb_policy_registry.h"
#include "src/proto/grpc/lookup/v1/rls_config.upb.h"
@ -97,7 +98,8 @@ XdsRouteLookupClusterSpecifierPlugin::GenerateLoadBalancingPolicyConfig(
// the gRPC LB policy registry instead of requiring each plugin to do that
// itself.
auto config =
LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(lb_policy_config);
CoreConfiguration::Get().lb_policy_registry().ParseLoadBalancingConfig(
lb_policy_config);
if (!config.ok()) {
return absl::InvalidArgumentError(absl::StrCat(
kXdsRouteLookupClusterSpecifierPluginConfigName,

@ -43,6 +43,7 @@
#include "src/core/ext/xds/upb_utils.h"
#include "src/core/ext/xds/xds_common_types.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/load_balancing/lb_policy_registry.h"
namespace grpc_core {
@ -238,8 +239,9 @@ absl::StatusOr<Json::Array> XdsLbPolicyRegistry::ConvertXdsLbPolicyConfig(
} else if (type->typed_struct != nullptr) {
// Custom lb policy config
std::string custom_type = std::string(type->type);
if (!LoadBalancingPolicyRegistry::LoadBalancingPolicyExists(
custom_type.c_str(), nullptr)) {
if (!CoreConfiguration::Get()
.lb_policy_registry()
.LoadBalancingPolicyExists(custom_type.c_str(), nullptr)) {
// Skip unsupported custom lb policy.
continue;
}

@ -43,7 +43,8 @@ CoreConfiguration::CoreConfiguration(Builder* builder)
handshaker_registry_(builder->handshaker_registry_.Build()),
channel_creds_registry_(builder->channel_creds_registry_.Build()),
service_config_parser_(builder->service_config_parser_.Build()),
resolver_registry_(builder->resolver_registry_.Build()) {}
resolver_registry_(builder->resolver_registry_.Build()),
lb_policy_registry_(builder->lb_policy_registry_.Build()) {}
void CoreConfiguration::RegisterBuilder(std::function<void(Builder*)> builder) {
GPR_ASSERT(config_.load(std::memory_order_relaxed) == nullptr &&

@ -23,6 +23,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args_preconditioning.h"
#include "src/core/lib/load_balancing/lb_policy_registry.h"
#include "src/core/lib/resolver/resolver_registry.h"
#include "src/core/lib/security/credentials/channel_creds_registry.h"
#include "src/core/lib/service_config/service_config_parser.h"
@ -64,6 +65,10 @@ class CoreConfiguration {
return &resolver_registry_;
}
LoadBalancingPolicyRegistry::Builder* lb_policy_registry() {
return &lb_policy_registry_;
}
private:
friend class CoreConfiguration;
@ -73,6 +78,7 @@ class CoreConfiguration {
ChannelCredsRegistry<>::Builder channel_creds_registry_;
ServiceConfigParser::Builder service_config_parser_;
ResolverRegistry::Builder resolver_registry_;
LoadBalancingPolicyRegistry::Builder lb_policy_registry_;
Builder();
CoreConfiguration* Build();
@ -177,6 +183,10 @@ class CoreConfiguration {
return resolver_registry_;
}
const LoadBalancingPolicyRegistry& lb_policy_registry() const {
return lb_policy_registry_;
}
static void SetDefaultBuilder(void (*builder)(CoreConfiguration::Builder*)) {
default_builder_ = builder;
}
@ -201,6 +211,7 @@ class CoreConfiguration {
ChannelCredsRegistry<> channel_creds_registry_;
ServiceConfigParser service_config_parser_;
ResolverRegistry resolver_registry_;
LoadBalancingPolicyRegistry lb_policy_registry_;
};
extern void BuildCoreConfiguration(CoreConfiguration::Builder* builder);

@ -21,5 +21,6 @@
#include <grpc/support/port_platform.h>
typedef struct grpc_pollset_set grpc_pollset_set;
typedef struct grpc_pollset grpc_pollset;
#endif // GRPC_CORE_LIB_IOMGR_IOMGR_FWD_H

@ -25,6 +25,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
extern grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount;
@ -35,7 +36,6 @@ extern grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount;
- a completion queue might keep a pollset with an entry for each transport
that is servicing a call that it's tracking */
typedef struct grpc_pollset grpc_pollset;
typedef struct grpc_pollset_worker grpc_pollset_worker;
typedef struct grpc_pollset_vtable {

@ -22,7 +22,6 @@
#include <grpc/support/port_platform.h>
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/pollset.h"
/* A grpc_pollset_set is a set of pollsets that are interested in an
action. Adding a pollset to a pollset_set automatically adds any

@ -28,6 +28,7 @@
#include <grpc/event_engine/event_engine.h>
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/pollset_set.h"
#include "src/core/lib/iomgr/port.h"
#include "src/core/lib/iomgr/resolved_address.h"

@ -21,6 +21,7 @@
#include <stddef.h>
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/port.h"
#include "src/core/lib/iomgr/resolve_address.h"

@ -35,6 +35,7 @@
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/block_annotate.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/iomgr_internal.h"
#include "src/core/lib/iomgr/resolve_address.h"

@ -39,6 +39,7 @@
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/block_annotate.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/iomgr_internal.h"
#include "src/core/lib/iomgr/resolve_address.h"

@ -32,75 +32,53 @@
#include <grpc/support/log.h>
namespace grpc_core {
namespace {
class RegistryState {
public:
void RegisterLoadBalancingPolicyFactory(
std::unique_ptr<LoadBalancingPolicyFactory> factory) {
gpr_log(GPR_DEBUG, "registering LB policy factory for \"%s\"",
std::string(factory->name()).c_str());
GPR_ASSERT(factories_.find(factory->name()) == factories_.end());
factories_.emplace(factory->name(), std::move(factory));
}
LoadBalancingPolicyFactory* GetLoadBalancingPolicyFactory(
absl::string_view name) const {
auto it = factories_.find(name);
if (it == factories_.end()) return nullptr;
return it->second.get();
}
private:
std::map<absl::string_view, std::unique_ptr<LoadBalancingPolicyFactory>>
factories_;
};
RegistryState* g_state = nullptr;
#include "src/core/lib/load_balancing/lb_policy.h"
} // namespace
namespace grpc_core {
//
// LoadBalancingPolicyRegistry::Builder
//
void LoadBalancingPolicyRegistry::Builder::InitRegistry() {
if (g_state == nullptr) g_state = new RegistryState();
}
void LoadBalancingPolicyRegistry::Builder::ShutdownRegistry() {
delete g_state;
g_state = nullptr;
}
void LoadBalancingPolicyRegistry::Builder::RegisterLoadBalancingPolicyFactory(
std::unique_ptr<LoadBalancingPolicyFactory> factory) {
InitRegistry();
g_state->RegisterLoadBalancingPolicyFactory(std::move(factory));
gpr_log(GPR_DEBUG, "registering LB policy factory for \"%s\"",
std::string(factory->name()).c_str());
GPR_ASSERT(factories_.find(factory->name()) == factories_.end());
factories_.emplace(factory->name(), std::move(factory));
}
LoadBalancingPolicyRegistry LoadBalancingPolicyRegistry::Builder::Build() {
LoadBalancingPolicyRegistry out;
out.factories_ = std::move(factories_);
return out;
}
//
// LoadBalancingPolicyRegistry
//
LoadBalancingPolicyFactory*
LoadBalancingPolicyRegistry::GetLoadBalancingPolicyFactory(
absl::string_view name) const {
auto it = factories_.find(name);
if (it == factories_.end()) return nullptr;
return it->second.get();
}
OrphanablePtr<LoadBalancingPolicy>
LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
absl::string_view name, LoadBalancingPolicy::Args args) {
GPR_ASSERT(g_state != nullptr);
absl::string_view name, LoadBalancingPolicy::Args args) const {
// Find factory.
LoadBalancingPolicyFactory* factory =
g_state->GetLoadBalancingPolicyFactory(name);
LoadBalancingPolicyFactory* factory = GetLoadBalancingPolicyFactory(name);
if (factory == nullptr) return nullptr; // Specified name not found.
// Create policy via factory.
return factory->CreateLoadBalancingPolicy(std::move(args));
}
bool LoadBalancingPolicyRegistry::LoadBalancingPolicyExists(
absl::string_view name, bool* requires_config) {
GPR_ASSERT(g_state != nullptr);
auto* factory = g_state->GetLoadBalancingPolicyFactory(name);
absl::string_view name, bool* requires_config) const {
auto* factory = GetLoadBalancingPolicyFactory(name);
if (factory == nullptr) return false;
// If requested, check if the load balancing policy allows an empty config.
if (requires_config != nullptr) {
@ -110,12 +88,11 @@ bool LoadBalancingPolicyRegistry::LoadBalancingPolicyExists(
return true;
}
namespace {
// Returns the JSON node of policy (with both policy name and config content)
// given the JSON node of a LoadBalancingConfig array.
absl::StatusOr<Json::Object::const_iterator> ParseLoadBalancingConfigHelper(
const Json& lb_config_array) {
absl::StatusOr<Json::Object::const_iterator>
LoadBalancingPolicyRegistry::ParseLoadBalancingConfigHelper(
const Json& lb_config_array) const {
if (lb_config_array.type() != Json::Type::ARRAY) {
return absl::InvalidArgumentError("type should be array");
}
@ -146,16 +123,13 @@ absl::StatusOr<Json::Object::const_iterator> ParseLoadBalancingConfigHelper(
"No known policies in list: ", absl::StrJoin(policies_tried, " ")));
}
} // namespace
absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>>
LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(const Json& json) {
GPR_ASSERT(g_state != nullptr);
LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(const Json& json) const {
auto policy = ParseLoadBalancingConfigHelper(json);
if (!policy.ok()) return policy.status();
// Find factory.
LoadBalancingPolicyFactory* factory =
g_state->GetLoadBalancingPolicyFactory((*policy)->first.c_str());
GetLoadBalancingPolicyFactory((*policy)->first.c_str());
if (factory == nullptr) {
return absl::FailedPreconditionError(absl::StrFormat(
"Factory not found for policy \"%s\"", (*policy)->first));

@ -19,6 +19,7 @@
#include <grpc/support/port_platform.h>
#include <map>
#include <memory>
#include "absl/status/statusor.h"
@ -39,30 +40,41 @@ class LoadBalancingPolicyRegistry {
/// initialization and shutdown.
class Builder {
public:
/// Global initialization and shutdown hooks.
static void InitRegistry();
static void ShutdownRegistry();
/// Registers an LB policy factory. The factory will be used to create an
/// LB policy whose name matches that of the factory.
static void RegisterLoadBalancingPolicyFactory(
void RegisterLoadBalancingPolicyFactory(
std::unique_ptr<LoadBalancingPolicyFactory> factory);
LoadBalancingPolicyRegistry Build();
private:
std::map<absl::string_view, std::unique_ptr<LoadBalancingPolicyFactory>>
factories_;
};
/// Creates an LB policy of the type specified by \a name.
static OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
absl::string_view name, LoadBalancingPolicy::Args args);
OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
absl::string_view name, LoadBalancingPolicy::Args args) const;
/// Returns true if the LB policy factory specified by \a name exists in this
/// registry. If the load balancing policy requires a config to be specified
/// then sets \a requires_config to true.
static bool LoadBalancingPolicyExists(absl::string_view name,
bool* requires_config);
bool LoadBalancingPolicyExists(absl::string_view name,
bool* requires_config) const;
/// Returns a parsed object of the load balancing policy to be used from a
/// LoadBalancingConfig array \a json.
static absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>>
ParseLoadBalancingConfig(const Json& json);
absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>>
ParseLoadBalancingConfig(const Json& json) const;
private:
LoadBalancingPolicyFactory* GetLoadBalancingPolicyFactory(
absl::string_view name) const;
absl::StatusOr<Json::Object::const_iterator> ParseLoadBalancingConfigHelper(
const Json& lb_config_array) const;
std::map<absl::string_view, std::unique_ptr<LoadBalancingPolicyFactory>>
factories_;
};
} // namespace grpc_core

@ -54,6 +54,7 @@
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/iomgr/polling_entity.h"
#include "src/core/lib/iomgr/pollset.h"

@ -59,6 +59,7 @@
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/polling_entity.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/slice/b64.h"

@ -26,7 +26,7 @@
#include <grpc/impl/codegen/gpr_types.h>
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/json/json.h"
/* --- Constants. --- */

@ -49,7 +49,6 @@
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/resource_quota/api.h"
#include "src/core/lib/resource_quota/memory_quota.h"

@ -31,7 +31,7 @@
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/gprpp/mpscq.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
/* These trace flags default to 1. The corresponding lines are only traced
if grpc_api_trace is also truthy */

@ -58,7 +58,6 @@
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/completion_queue.h"

@ -49,7 +49,6 @@
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/polling_entity.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/promise/arena_promise.h"
#include "src/core/lib/promise/context.h"
#include "src/core/lib/promise/latch.h"

@ -28,7 +28,6 @@
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/promise/arena_promise.h"
#include "src/core/lib/resource_quota/arena.h"
#include "src/core/lib/transport/transport.h"

@ -27,53 +27,13 @@
extern void grpc_register_extra_plugins(void);
void grpc_chttp2_plugin_init(void);
void grpc_chttp2_plugin_shutdown(void);
void grpc_client_channel_init(void);
void grpc_client_channel_shutdown(void);
void grpc_lb_policy_grpclb_init(void);
void grpc_lb_policy_grpclb_shutdown(void);
void grpc_lb_policy_priority_init(void);
void grpc_lb_policy_priority_shutdown(void);
void grpc_lb_policy_outlier_detection_init(void);
void grpc_lb_policy_outlier_detection_shutdown(void);
void grpc_lb_policy_weighted_target_init(void);
void grpc_lb_policy_weighted_target_shutdown(void);
void grpc_lb_policy_pick_first_init(void);
void grpc_lb_policy_pick_first_shutdown(void);
void grpc_lb_policy_round_robin_init(void);
void grpc_lb_policy_round_robin_shutdown(void);
void grpc_resolver_dns_ares_init(void);
void grpc_resolver_dns_ares_shutdown(void);
namespace grpc_core {
void GrpcLbPolicyRingHashInit(void);
void GrpcLbPolicyRingHashShutdown(void);
#ifndef GRPC_NO_RLS
void RlsLbPluginInit();
void RlsLbPluginShutdown();
#endif // !GRPC_NO_RLS
} // namespace grpc_core
void grpc_register_built_in_plugins(void) {
grpc_register_plugin(grpc_client_channel_init, grpc_client_channel_shutdown);
grpc_register_plugin(grpc_lb_policy_grpclb_init,
grpc_lb_policy_grpclb_shutdown);
#ifndef GRPC_NO_RLS
grpc_register_plugin(grpc_core::RlsLbPluginInit,
grpc_core::RlsLbPluginShutdown);
#endif // !GRPC_NO_RLS
grpc_register_plugin(grpc_lb_policy_outlier_detection_init,
grpc_lb_policy_outlier_detection_shutdown);
grpc_register_plugin(grpc_lb_policy_priority_init,
grpc_lb_policy_priority_shutdown);
grpc_register_plugin(grpc_lb_policy_weighted_target_init,
grpc_lb_policy_weighted_target_shutdown);
grpc_register_plugin(grpc_lb_policy_pick_first_init,
grpc_lb_policy_pick_first_shutdown);
grpc_register_plugin(grpc_lb_policy_round_robin_init,
grpc_lb_policy_round_robin_shutdown);
grpc_register_plugin(grpc_core::GrpcLbPolicyRingHashInit,
grpc_core::GrpcLbPolicyRingHashShutdown);
grpc_register_plugin(grpc_resolver_dns_ares_init,
grpc_resolver_dns_ares_shutdown);
grpc_register_extra_plugins();
@ -88,8 +48,7 @@ extern void SecurityRegisterHandshakerFactories(
extern void RegisterClientAuthorityFilter(CoreConfiguration::Builder* builder);
extern void RegisterChannelIdleFilters(CoreConfiguration::Builder* builder);
extern void RegisterDeadlineFilter(CoreConfiguration::Builder* builder);
extern void RegisterGrpcLbLoadReportingFilter(
CoreConfiguration::Builder* builder);
extern void RegisterGrpcLbPolicy(CoreConfiguration::Builder* builder);
extern void RegisterHttpFilters(CoreConfiguration::Builder* builder);
extern void RegisterMessageSizeFilter(CoreConfiguration::Builder* builder);
extern void RegisterSecurityFilters(CoreConfiguration::Builder* builder);
@ -102,6 +61,16 @@ extern void RegisterNativeDnsResolver(CoreConfiguration::Builder* builder);
extern void RegisterAresDnsResolver(CoreConfiguration::Builder* builder);
extern void RegisterSockaddrResolver(CoreConfiguration::Builder* builder);
extern void RegisterFakeResolver(CoreConfiguration::Builder* builder);
extern void RegisterPriorityLbPolicy(CoreConfiguration::Builder* builder);
extern void RegisterOutlierDetectionLbPolicy(
CoreConfiguration::Builder* builder);
extern void RegisterWeightedTargetLbPolicy(CoreConfiguration::Builder* builder);
extern void RegisterPickFirstLbPolicy(CoreConfiguration::Builder* builder);
extern void RegisterRoundRobinLbPolicy(CoreConfiguration::Builder* builder);
extern void RegisterRingHashLbPolicy(CoreConfiguration::Builder* builder);
#ifndef GRPC_NO_RLS
extern void RegisterRlsLbPolicy(CoreConfiguration::Builder* builder);
#endif // !GRPC_NO_RLS
#ifdef GPR_SUPPORT_BINDER_TRANSPORT
extern void RegisterBinderResolver(CoreConfiguration::Builder* builder);
#endif
@ -112,11 +81,17 @@ void BuildCoreConfiguration(CoreConfiguration::Builder* builder) {
// the start of the handshaker list.
RegisterHttpConnectHandshaker(builder);
RegisterTCPConnectHandshaker(builder);
RegisterPriorityLbPolicy(builder);
RegisterOutlierDetectionLbPolicy(builder);
RegisterWeightedTargetLbPolicy(builder);
RegisterPickFirstLbPolicy(builder);
RegisterRoundRobinLbPolicy(builder);
RegisterRingHashLbPolicy(builder);
BuildClientChannelConfiguration(builder);
SecurityRegisterHandshakerFactories(builder);
RegisterClientAuthorityFilter(builder);
RegisterChannelIdleFilters(builder);
RegisterGrpcLbLoadReportingFilter(builder);
RegisterGrpcLbPolicy(builder);
RegisterHttpFilters(builder);
RegisterDeadlineFilter(builder);
RegisterMessageSizeFilter(builder);
@ -130,6 +105,9 @@ void BuildCoreConfiguration(CoreConfiguration::Builder* builder) {
#ifdef GPR_SUPPORT_BINDER_TRANSPORT
RegisterBinderResolver(builder);
#endif
#ifndef GRPC_NO_RLS
RegisterRlsLbPolicy(builder);
#endif // !GRPC_NO_RLS
// Run last so it gets a consistent location.
// TODO(ctiller): Is this actually necessary?
RegisterSecurityFilters(builder);

@ -32,14 +32,6 @@ namespace grpc_core {
void FileWatcherCertificateProviderInit();
void FileWatcherCertificateProviderShutdown();
} // namespace grpc_core
void grpc_lb_policy_cds_init(void);
void grpc_lb_policy_cds_shutdown(void);
void grpc_lb_policy_xds_cluster_impl_init(void);
void grpc_lb_policy_xds_cluster_impl_shutdown(void);
void grpc_lb_policy_xds_cluster_resolver_init(void);
void grpc_lb_policy_xds_cluster_resolver_shutdown(void);
void grpc_lb_policy_xds_cluster_manager_init(void);
void grpc_lb_policy_xds_cluster_manager_shutdown(void);
#endif
void grpc_register_extra_plugins() {
@ -50,13 +42,6 @@ void grpc_register_extra_plugins() {
grpc_certificate_provider_registry_shutdown);
grpc_register_plugin(grpc_core::FileWatcherCertificateProviderInit,
grpc_core::FileWatcherCertificateProviderShutdown);
grpc_register_plugin(grpc_lb_policy_cds_init, grpc_lb_policy_cds_shutdown);
grpc_register_plugin(grpc_lb_policy_xds_cluster_impl_init,
grpc_lb_policy_xds_cluster_impl_shutdown);
grpc_register_plugin(grpc_lb_policy_xds_cluster_resolver_init,
grpc_lb_policy_xds_cluster_resolver_shutdown);
grpc_register_plugin(grpc_lb_policy_xds_cluster_manager_init,
grpc_lb_policy_xds_cluster_manager_shutdown);
#endif
}
@ -68,6 +53,12 @@ extern void RegisterXdsChannelStackModifier(
extern void RegisterChannelDefaultCreds(CoreConfiguration::Builder* builder);
extern void RegisterXdsResolver(CoreConfiguration::Builder* builder);
extern void RegisterCloud2ProdResolver(CoreConfiguration::Builder* builder);
extern void RegisterXdsClusterManagerLbPolicy(
CoreConfiguration::Builder* builder);
extern void RegisterXdsClusterImplLbPolicy(CoreConfiguration::Builder* builder);
extern void RegisterCdsLbPolicy(CoreConfiguration::Builder* builder);
extern void RegisterXdsClusterResolverLbPolicy(
CoreConfiguration::Builder* builder);
#endif
void RegisterExtraFilters(CoreConfiguration::Builder* builder) {
// Use builder to avoid unused-parameter warning.
@ -80,6 +71,10 @@ void RegisterExtraFilters(CoreConfiguration::Builder* builder) {
RegisterChannelDefaultCreds(builder);
RegisterXdsResolver(builder);
RegisterCloud2ProdResolver(builder);
RegisterXdsClusterManagerLbPolicy(builder);
RegisterXdsClusterImplLbPolicy(builder);
RegisterCdsLbPolicy(builder);
RegisterXdsClusterResolverLbPolicy(builder);
#endif
}
} // namespace grpc_core

@ -33,6 +33,7 @@
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/gprpp/work_serializer.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/resolver/resolver_registry.h"
#include "src/core/lib/resolver/server_address.h"

@ -473,18 +473,10 @@ TEST_F(ErroredParsersScopingTest, MethodParams) {
class ClientChannelParserTest : public ::testing::Test {
protected:
void SetUp() override {
builder_ = std::make_unique<CoreConfiguration::WithSubstituteBuilder>(
[](CoreConfiguration::Builder* builder) {
builder->service_config_parser()->RegisterParser(
absl::make_unique<internal::ClientChannelServiceConfigParser>());
});
EXPECT_EQ(CoreConfiguration::Get().service_config_parser().GetParserIndex(
"client_channel"),
0);
}
private:
std::unique_ptr<CoreConfiguration::WithSubstituteBuilder> builder_;
};
TEST_F(ClientChannelParserTest, ValidLoadBalancingConfigPickFirst) {

@ -69,6 +69,7 @@ grpc_cc_library(
"//:grpc",
"//:httpcli",
"//:iomgr_fwd",
"//:pollset_set",
"//:resolved_address",
"//:slice_refcount",
"//:sockaddr_utils",
@ -116,6 +117,7 @@ grpc_cc_test(
"//:grpc",
"//:grpc_codegen",
"//:grpc_public_hdrs",
"//:iomgr_fwd",
"//test/core/util:grpc_test_util",
],
)

@ -43,7 +43,7 @@
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/tcp_server.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h"

@ -35,6 +35,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
@ -98,15 +99,9 @@ class DropPolicyFactory : public LoadBalancingPolicyFactory {
std::vector<PickArgsSeen>* g_pick_args_vector = nullptr;
void RegisterDropPolicy() {
LoadBalancingPolicyRegistry::Builder::RegisterLoadBalancingPolicyFactory(
void RegisterDropPolicy(CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<DropPolicyFactory>());
RegisterTestPickArgsLoadBalancingPolicy(
[](const PickArgsSeen& pick_args) {
GPR_ASSERT(g_pick_args_vector != nullptr);
g_pick_args_vector->push_back(pick_args);
},
kDropPolicyName);
}
} // namespace
@ -280,4 +275,16 @@ void retry_lb_drop(grpc_end2end_test_config config) {
test_retry_lb_drop(config);
}
void retry_lb_drop_pre_init(void) { grpc_core::RegisterDropPolicy(); }
void retry_lb_drop_pre_init(void) {
grpc_core::CoreConfiguration::RegisterBuilder(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::RegisterTestPickArgsLoadBalancingPolicy(
builder,
[](const grpc_core::PickArgsSeen& pick_args) {
GPR_ASSERT(grpc_core::g_pick_args_vector != nullptr);
grpc_core::g_pick_args_vector->push_back(pick_args);
},
grpc_core::kDropPolicyName);
});
grpc_core::CoreConfiguration::RegisterBuilder(grpc_core::RegisterDropPolicy);
}

@ -34,6 +34,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
@ -103,8 +104,8 @@ class FailPolicyFactory : public LoadBalancingPolicyFactory {
}
};
void RegisterFailPolicy() {
LoadBalancingPolicyRegistry::Builder::RegisterLoadBalancingPolicyFactory(
void RegisterFailPolicy(CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<FailPolicyFactory>());
}
@ -278,4 +279,6 @@ void retry_lb_fail(grpc_end2end_test_config config) {
test_retry_lb_fail(config);
}
void retry_lb_fail_pre_init(void) { grpc_core::RegisterFailPolicy(); }
void retry_lb_fail_pre_init(void) {
grpc_core::CoreConfiguration::RegisterBuilder(grpc_core::RegisterFailPolicy);
}

@ -42,6 +42,7 @@
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/resolve_address.h"
#include "test/core/util/cmdline.h"
#include "test/core/util/test_config.h"

@ -40,6 +40,7 @@
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/pollset.h"
#include "test/core/util/cmdline.h"
#include "test/core/util/fake_udp_and_tcp_server.h"
#include "test/core/util/test_config.h"

@ -26,6 +26,8 @@
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/security/credentials/jwt/jwt_verifier.h"
#include "test/core/util/cmdline.h"

@ -28,6 +28,7 @@
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "test/core/util/test_config.h"

@ -25,6 +25,7 @@
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/surface/completion_queue.h"
#include "test/core/util/test_config.h"

@ -25,6 +25,7 @@
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/tsi/alts/handshaker/alts_shared_resource.h"
#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h"
#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h"

@ -29,6 +29,7 @@
#include <grpc/support/sync.h>
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/tsi/alts/handshaker/alts_handshaker_client.h"
#include "src/core/tsi/alts/handshaker/alts_shared_resource.h"
#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h"

@ -132,6 +132,7 @@ grpc_cc_library(
"//:grpc_sockaddr",
"//:grpc_trace",
"//:httpcli",
"//:iomgr_fwd",
"//:iomgr_port",
"//:orphanable",
"//:ref_counted_ptr",
@ -167,6 +168,7 @@ grpc_cc_library(
"//:grpc_sockaddr",
"//:grpc_unsecure",
"//:httpcli",
"//:iomgr_fwd",
"//:iomgr_port",
"//:orphanable",
"//:ref_counted_ptr",
@ -285,6 +287,7 @@ grpc_cc_library(
"absl/types:variant",
],
deps = [
"//:config",
"//:gpr",
"//:grpc",
"//:grpc_backend_metric_data",
@ -295,6 +298,7 @@ grpc_cc_library(
"//:lb_policy_factory",
"//:lb_policy_registry",
"//:orphanable",
"//:pollset_set",
"//:ref_counted_ptr",
"//:resolved_address",
"//:server_address",

@ -29,7 +29,6 @@
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/sockaddr.h"
typedef struct mock_endpoint {

@ -39,7 +39,6 @@
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_refcount.h"

@ -35,6 +35,7 @@
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/polling_entity.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/uri/uri_parser.h"

@ -29,7 +29,7 @@
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/tcp_server.h"
#include "test/core/util/test_tcp_server.h"

@ -33,6 +33,7 @@
#include "src/core/ext/filters/client_channel/lb_policy/oob_backend_metric.h"
#include "src/core/lib/address_utils/parse_address.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/time.h"
@ -66,8 +67,9 @@ class ForwardingLoadBalancingPolicy : public LoadBalancingPolicy {
delegate_args.work_serializer = work_serializer();
delegate_args.channel_control_helper = std::move(delegating_helper);
delegate_args.args = channel_args();
delegate_ = LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
delegate_policy_name, std::move(delegate_args));
delegate_ =
CoreConfiguration::Get().lb_policy_registry().CreateLoadBalancingPolicy(
delegate_policy_name, std::move(delegate_args));
grpc_pollset_set_add_pollset_set(delegate_->interested_parties(),
interested_parties());
}
@ -657,31 +659,35 @@ class OobBackendMetricTestFactory : public LoadBalancingPolicyFactory {
} // namespace
void RegisterTestPickArgsLoadBalancingPolicy(
TestPickArgsCallback cb, absl::string_view delegate_policy_name) {
LoadBalancingPolicyRegistry::Builder::RegisterLoadBalancingPolicyFactory(
CoreConfiguration::Builder* builder, TestPickArgsCallback cb,
absl::string_view delegate_policy_name) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<TestPickArgsLbFactory>(std::move(cb),
delegate_policy_name));
}
void RegisterInterceptRecvTrailingMetadataLoadBalancingPolicy(
CoreConfiguration::Builder* builder,
InterceptRecvTrailingMetadataCallback cb) {
LoadBalancingPolicyRegistry::Builder::RegisterLoadBalancingPolicyFactory(
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<InterceptTrailingFactory>(std::move(cb)));
}
void RegisterAddressTestLoadBalancingPolicy(AddressTestCallback cb) {
LoadBalancingPolicyRegistry::Builder::RegisterLoadBalancingPolicyFactory(
void RegisterAddressTestLoadBalancingPolicy(CoreConfiguration::Builder* builder,
AddressTestCallback cb) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<AddressTestFactory>(std::move(cb)));
}
void RegisterFixedAddressLoadBalancingPolicy() {
LoadBalancingPolicyRegistry::Builder::RegisterLoadBalancingPolicyFactory(
void RegisterFixedAddressLoadBalancingPolicy(
CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<FixedAddressFactory>());
}
void RegisterOobBackendMetricTestLoadBalancingPolicy(
OobBackendMetricCallback cb) {
LoadBalancingPolicyRegistry::Builder::RegisterLoadBalancingPolicyFactory(
CoreConfiguration::Builder* builder, OobBackendMetricCallback cb) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<OobBackendMetricTestFactory>(std::move(cb)));
}

@ -17,6 +17,8 @@
#ifndef GRPC_TEST_CORE_UTIL_TEST_LB_POLICIES_H
#define GRPC_TEST_CORE_UTIL_TEST_LB_POLICIES_H
#include <grpc/support/port_platform.h>
#include <functional>
#include <string>
#include <utility>
@ -26,6 +28,7 @@
#include "absl/strings/string_view.h"
#include "src/core/ext/filters/client_channel/lb_policy/backend_metric_data.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/resolver/server_address.h"
namespace grpc_core {
@ -39,10 +42,10 @@ struct PickArgsSeen {
using TestPickArgsCallback = std::function<void(const PickArgsSeen&)>;
// Registers an LB policy called "test_pick_args_lb" that passes the args
// passed to SubchannelPicker::Pick() to cb.
// Registers an LB policy called "test_pick_args_lb" that passes the args passed
// to SubchannelPicker::Pick() to cb.
void RegisterTestPickArgsLoadBalancingPolicy(
TestPickArgsCallback cb,
CoreConfiguration::Builder* builder, TestPickArgsCallback cb,
absl::string_view delegate_policy_name = "pick_first");
struct TrailingMetadataArgsSeen {
@ -57,17 +60,20 @@ using InterceptRecvTrailingMetadataCallback =
// Registers an LB policy called "intercept_trailing_metadata_lb" that
// invokes cb when trailing metadata is received for each call.
void RegisterInterceptRecvTrailingMetadataLoadBalancingPolicy(
CoreConfiguration::Builder* builder,
InterceptRecvTrailingMetadataCallback cb);
using AddressTestCallback = std::function<void(const ServerAddress&)>;
// Registers an LB policy called "address_test_lb" that invokes cb for each
// address used to create a subchannel.
void RegisterAddressTestLoadBalancingPolicy(AddressTestCallback cb);
void RegisterAddressTestLoadBalancingPolicy(CoreConfiguration::Builder* builder,
AddressTestCallback cb);
// Registers an LB policy called "fixed_address_lb" that provides a
// single subchannel whose address is in its configuration.
void RegisterFixedAddressLoadBalancingPolicy();
void RegisterFixedAddressLoadBalancingPolicy(
CoreConfiguration::Builder* builder);
using OobBackendMetricCallback =
std::function<void(ServerAddress, const BackendMetricData&)>;
@ -75,7 +81,7 @@ using OobBackendMetricCallback =
// Registers an LB policy called "oob_backend_metric_test_lb" that invokes
// cb for each OOB backend metric report on each subchannel.
void RegisterOobBackendMetricTestLoadBalancingPolicy(
OobBackendMetricCallback cb);
CoreConfiguration::Builder* builder, OobBackendMetricCallback cb);
} // namespace grpc_core

@ -36,6 +36,7 @@
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/resolved_address.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/iomgr/socket_utils.h"

@ -24,7 +24,7 @@
#include <grpc/support/sync.h>
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/iomgr_fwd.h"
#include "src/core/lib/iomgr/tcp_server.h"
// test_tcp_server should be stack-allocated or new'ed, never gpr_malloc'ed

@ -28,6 +28,7 @@
#include <grpc/grpc.h>
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/load_balancing/lb_policy_factory.h"
#include "src/core/lib/load_balancing/lb_policy_registry.h"
#include "src/proto/grpc/testing/xds/v3/cluster.grpc.pb.h"
@ -508,9 +509,12 @@ TEST(XdsLbPolicyRegistryTest, MaxRecursion) {
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
grpc::testing::TestEnvironment env(&argc, argv);
grpc_core::LoadBalancingPolicyRegistry::Builder::
RegisterLoadBalancingPolicyFactory(
absl::make_unique<grpc_core::testing::CustomLbPolicyFactory>());
grpc_core::CoreConfiguration::RegisterBuilder(
[](grpc_core::CoreConfiguration::Builder* builder) {
builder->lb_policy_registry()->RegisterLoadBalancingPolicyFactory(
absl::make_unique<grpc_core::testing::CustomLbPolicyFactory>());
});
grpc_init();
auto result = RUN_ALL_TESTS();
grpc_shutdown();

@ -2126,11 +2126,19 @@ class ClientLbPickArgsTest : public ClientLbEnd2endTest {
}
static void SetUpTestCase() {
grpc_core::CoreConfiguration::Reset();
grpc_core::CoreConfiguration::RegisterBuilder(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::RegisterTestPickArgsLoadBalancingPolicy(builder,
SavePickArgs);
});
grpc_init();
grpc_core::RegisterTestPickArgsLoadBalancingPolicy(SavePickArgs);
}
static void TearDownTestCase() { grpc_shutdown(); }
static void TearDownTestCase() {
grpc_shutdown();
grpc_core::CoreConfiguration::Reset();
}
std::vector<grpc_core::PickArgsSeen> args_seen_list() {
grpc_core::MutexLock lock(&mu_);
@ -2223,12 +2231,19 @@ class ClientLbInterceptTrailingMetadataTest : public ClientLbEnd2endTest {
}
static void SetUpTestCase() {
grpc_core::CoreConfiguration::Reset();
grpc_core::CoreConfiguration::RegisterBuilder(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::RegisterInterceptRecvTrailingMetadataLoadBalancingPolicy(
builder, ReportTrailerIntercepted);
});
grpc_init();
grpc_core::RegisterInterceptRecvTrailingMetadataLoadBalancingPolicy(
ReportTrailerIntercepted);
}
static void TearDownTestCase() { grpc_shutdown(); }
static void TearDownTestCase() {
grpc_shutdown();
grpc_core::CoreConfiguration::Reset();
}
int num_trailers_intercepted() {
grpc_core::MutexLock lock(&mu_);
@ -2497,11 +2512,19 @@ class ClientLbAddressTest : public ClientLbEnd2endTest {
}
static void SetUpTestCase() {
grpc_core::CoreConfiguration::Reset();
grpc_core::CoreConfiguration::RegisterBuilder(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::RegisterAddressTestLoadBalancingPolicy(builder,
SaveAddress);
});
grpc_init();
grpc_core::RegisterAddressTestLoadBalancingPolicy(SaveAddress);
}
static void TearDownTestCase() { grpc_shutdown(); }
static void TearDownTestCase() {
grpc_shutdown();
grpc_core::CoreConfiguration::Reset();
}
const std::vector<std::string>& addresses_seen() {
grpc_core::MutexLock lock(&mu_);
@ -2562,12 +2585,19 @@ class OobBackendMetricTest : public ClientLbEnd2endTest {
}
static void SetUpTestCase() {
grpc_core::CoreConfiguration::Reset();
grpc_core::CoreConfiguration::RegisterBuilder(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::RegisterOobBackendMetricTestLoadBalancingPolicy(
builder, BackendMetricCallback);
});
grpc_init();
grpc_core::RegisterOobBackendMetricTestLoadBalancingPolicy(
BackendMetricCallback);
}
static void TearDownTestCase() { grpc_shutdown(); }
static void TearDownTestCase() {
grpc_shutdown();
grpc_core::CoreConfiguration::Reset();
}
absl::optional<BackendMetricReport> GetBackendMetricReport() {
grpc_core::MutexLock lock(&mu_);

@ -160,13 +160,15 @@ class RlsEnd2endTest : public ::testing::Test {
static void SetUpTestSuite() {
gpr_setenv("GRPC_EXPERIMENTAL_ENABLE_RLS_LB_POLICY", "true");
GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
grpc_core::CoreConfiguration::RegisterBuilder(
grpc_core::RegisterFixedAddressLoadBalancingPolicy);
grpc_init();
grpc_core::RegisterFixedAddressLoadBalancingPolicy();
}
static void TearDownTestSuite() {
grpc_shutdown_blocking();
gpr_unsetenv("GRPC_EXPERIMENTAL_ENABLE_RLS_LB_POLICY");
grpc_core::CoreConfiguration::Reset();
}
void SetUp() override {

@ -1253,8 +1253,8 @@ int main(int argc, char** argv) {
// CoreConfiguration::BuildSpecialConfiguration() instead.
gpr_setenv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION", "true");
grpc_init();
gpr_unsetenv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION");
const auto result = RUN_ALL_TESTS();
grpc_shutdown();
gpr_unsetenv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION");
return result;
}

Loading…
Cancel
Save