From 0575c5b08205a40b9c9823cde2ea6216f4df041e Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 23 Aug 2024 16:30:30 +0000 Subject: [PATCH] [xDS] move XdsConfig out of XdsDependencyManager --- CMakeLists.txt | 1 + Makefile | 1 + Package.swift | 2 + build_autogenerated.yaml | 2 + config.m4 | 1 + config.w32 | 1 + gRPC-C++.podspec | 2 + gRPC-Core.podspec | 3 + grpc.gemspec | 2 + package.xml | 2 + src/core/BUILD | 32 ++++- src/core/load_balancing/xds/cds.cc | 2 - .../load_balancing/xds/xds_cluster_impl.cc | 4 +- .../load_balancing/xds/xds_override_host.cc | 5 +- src/core/resolver/xds/xds_config.cc | 96 +++++++++++++++ src/core/resolver/xds/xds_config.h | 109 ++++++++++++++++++ .../resolver/xds/xds_dependency_manager.cc | 65 ----------- .../resolver/xds/xds_dependency_manager.h | 70 +---------- src/core/resolver/xds/xds_resolver.cc | 10 +- src/python/grpcio/grpc_core_dependencies.py | 1 + .../load_balancing/xds_override_host_test.cc | 6 +- tools/doxygen/Doxyfile.c++.internal | 2 + tools/doxygen/Doxyfile.core.internal | 2 + 23 files changed, 268 insertions(+), 153 deletions(-) create mode 100644 src/core/resolver/xds/xds_config.cc create mode 100644 src/core/resolver/xds/xds_config.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ebf76ecc93ab5..05ed1ffa55bd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2567,6 +2567,7 @@ add_library(grpc src/core/resolver/resolver.cc src/core/resolver/resolver_registry.cc src/core/resolver/sockaddr/sockaddr_resolver.cc + src/core/resolver/xds/xds_config.cc src/core/resolver/xds/xds_dependency_manager.cc src/core/resolver/xds/xds_resolver.cc src/core/server/server.cc diff --git a/Makefile b/Makefile index a426c5ae922e7..4da690fad14bd 100644 --- a/Makefile +++ b/Makefile @@ -1404,6 +1404,7 @@ LIBGRPC_SRC = \ src/core/resolver/resolver.cc \ src/core/resolver/resolver_registry.cc \ src/core/resolver/sockaddr/sockaddr_resolver.cc \ + src/core/resolver/xds/xds_config.cc \ src/core/resolver/xds/xds_dependency_manager.cc \ src/core/resolver/xds/xds_resolver.cc \ src/core/server/server.cc \ diff --git a/Package.swift b/Package.swift index a6e7852597f28..c961e86c73373 100644 --- a/Package.swift +++ b/Package.swift @@ -1813,6 +1813,8 @@ let package = Package( "src/core/resolver/resolver_registry.h", "src/core/resolver/server_address.h", "src/core/resolver/sockaddr/sockaddr_resolver.cc", + "src/core/resolver/xds/xds_config.cc", + "src/core/resolver/xds/xds_config.h", "src/core/resolver/xds/xds_dependency_manager.cc", "src/core/resolver/xds/xds_dependency_manager.h", "src/core/resolver/xds/xds_resolver.cc", diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 33b71cfa8ae6c..a13b85e2315da 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -1158,6 +1158,7 @@ libs: - src/core/resolver/resolver_factory.h - src/core/resolver/resolver_registry.h - src/core/resolver/server_address.h + - src/core/resolver/xds/xds_config.h - src/core/resolver/xds/xds_dependency_manager.h - src/core/resolver/xds/xds_resolver_attributes.h - src/core/server/server.h @@ -1980,6 +1981,7 @@ libs: - src/core/resolver/resolver.cc - src/core/resolver/resolver_registry.cc - src/core/resolver/sockaddr/sockaddr_resolver.cc + - src/core/resolver/xds/xds_config.cc - src/core/resolver/xds/xds_dependency_manager.cc - src/core/resolver/xds/xds_resolver.cc - src/core/server/server.cc diff --git a/config.m4 b/config.m4 index c7f38bced2a98..00e99a729af37 100644 --- a/config.m4 +++ b/config.m4 @@ -779,6 +779,7 @@ if test "$PHP_GRPC" != "no"; then src/core/resolver/resolver.cc \ src/core/resolver/resolver_registry.cc \ src/core/resolver/sockaddr/sockaddr_resolver.cc \ + src/core/resolver/xds/xds_config.cc \ src/core/resolver/xds/xds_dependency_manager.cc \ src/core/resolver/xds/xds_resolver.cc \ src/core/server/server.cc \ diff --git a/config.w32 b/config.w32 index 0e722d1bd9b68..e7bc1d8aac86e 100644 --- a/config.w32 +++ b/config.w32 @@ -744,6 +744,7 @@ if (PHP_GRPC != "no") { "src\\core\\resolver\\resolver.cc " + "src\\core\\resolver\\resolver_registry.cc " + "src\\core\\resolver\\sockaddr\\sockaddr_resolver.cc " + + "src\\core\\resolver\\xds\\xds_config.cc " + "src\\core\\resolver\\xds\\xds_dependency_manager.cc " + "src\\core\\resolver\\xds\\xds_resolver.cc " + "src\\core\\server\\server.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 42545ee1bf598..b38dd52347071 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -1262,6 +1262,7 @@ Pod::Spec.new do |s| 'src/core/resolver/resolver_factory.h', 'src/core/resolver/resolver_registry.h', 'src/core/resolver/server_address.h', + 'src/core/resolver/xds/xds_config.h', 'src/core/resolver/xds/xds_dependency_manager.h', 'src/core/resolver/xds/xds_resolver_attributes.h', 'src/core/server/server.h', @@ -2548,6 +2549,7 @@ Pod::Spec.new do |s| 'src/core/resolver/resolver_factory.h', 'src/core/resolver/resolver_registry.h', 'src/core/resolver/server_address.h', + 'src/core/resolver/xds/xds_config.h', 'src/core/resolver/xds/xds_dependency_manager.h', 'src/core/resolver/xds/xds_resolver_attributes.h', 'src/core/server/server.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 9b35f946375d6..a623cc501e5f3 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -1929,6 +1929,8 @@ Pod::Spec.new do |s| 'src/core/resolver/resolver_registry.h', 'src/core/resolver/server_address.h', 'src/core/resolver/sockaddr/sockaddr_resolver.cc', + 'src/core/resolver/xds/xds_config.cc', + 'src/core/resolver/xds/xds_config.h', 'src/core/resolver/xds/xds_dependency_manager.cc', 'src/core/resolver/xds/xds_dependency_manager.h', 'src/core/resolver/xds/xds_resolver.cc', @@ -3327,6 +3329,7 @@ Pod::Spec.new do |s| 'src/core/resolver/resolver_factory.h', 'src/core/resolver/resolver_registry.h', 'src/core/resolver/server_address.h', + 'src/core/resolver/xds/xds_config.h', 'src/core/resolver/xds/xds_dependency_manager.h', 'src/core/resolver/xds/xds_resolver_attributes.h', 'src/core/server/server.h', diff --git a/grpc.gemspec b/grpc.gemspec index d90dfc5dddd9b..90311d3ce380f 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -1815,6 +1815,8 @@ Gem::Specification.new do |s| s.files += %w( src/core/resolver/resolver_registry.h ) s.files += %w( src/core/resolver/server_address.h ) s.files += %w( src/core/resolver/sockaddr/sockaddr_resolver.cc ) + s.files += %w( src/core/resolver/xds/xds_config.cc ) + s.files += %w( src/core/resolver/xds/xds_config.h ) s.files += %w( src/core/resolver/xds/xds_dependency_manager.cc ) s.files += %w( src/core/resolver/xds/xds_dependency_manager.h ) s.files += %w( src/core/resolver/xds/xds_resolver.cc ) diff --git a/package.xml b/package.xml index fde0df1ef9ca2..4493c88e9661b 100644 --- a/package.xml +++ b/package.xml @@ -1797,6 +1797,8 @@ + + diff --git a/src/core/BUILD b/src/core/BUILD index 641ba363ab8f2..9147f08558899 100644 --- a/src/core/BUILD +++ b/src/core/BUILD @@ -5858,6 +5858,7 @@ grpc_cc_library( "unique_type_name", "xds_cluster", "xds_common_types", + "xds_config", "xds_dependency_manager", "xds_health_status", "//:config", @@ -5923,8 +5924,8 @@ grpc_cc_library( "resolved_address", "subchannel_interface", "validation_errors", + "xds_config", "xds_credentials", - "xds_dependency_manager", "xds_endpoint", "//:call_tracer", "//:config", @@ -6636,7 +6637,7 @@ grpc_cc_library( "resolved_address", "subchannel_interface", "validation_errors", - "xds_dependency_manager", + "xds_config", "xds_health_status", "//:config", "//:debug_location", @@ -6981,6 +6982,31 @@ grpc_cc_library( ], ) +grpc_cc_library( + name = "xds_config", + srcs = [ + "resolver/xds/xds_config.cc", + ], + hdrs = [ + "resolver/xds/xds_config.h", + ], + external_deps = [ + "absl/container:flat_hash_map", + "absl/status:statusor", + "absl/strings", + "absl/types:variant", + ], + language = "c++", + deps = [ + "match", + "ref_counted", + "xds_cluster", + "xds_endpoint", + "xds_listener", + "xds_route_config", + ], +) + grpc_cc_library( name = "xds_dependency_manager", srcs = [ @@ -7006,6 +7032,7 @@ grpc_cc_library( "xds_endpoint", "xds_listener", "xds_route_config", + "xds_config", "//:config", "//:gpr", "//:grpc_resolver", @@ -7057,6 +7084,7 @@ grpc_cc_library( "xds_http_filter", "xds_listener", "xds_route_config", + "xds_config", "xxhash_inline", "//:channel_arg_names", "//:config", diff --git a/src/core/load_balancing/xds/cds.cc b/src/core/load_balancing/xds/cds.cc index c17e6f954d2cd..03ee2a00a1830 100644 --- a/src/core/load_balancing/xds/cds.cc +++ b/src/core/load_balancing/xds/cds.cc @@ -78,8 +78,6 @@ bool XdsAggregateClusterBackwardCompatibilityEnabled() { return parse_succeeded && parsed_value; } -using XdsConfig = XdsDependencyManager::XdsConfig; - constexpr absl::string_view kCds = "cds_experimental"; // Config for this LB policy. diff --git a/src/core/load_balancing/xds/xds_cluster_impl.cc b/src/core/load_balancing/xds/xds_cluster_impl.cc index 911e5e44c417a..a53094da48566 100644 --- a/src/core/load_balancing/xds/xds_cluster_impl.cc +++ b/src/core/load_balancing/xds/xds_cluster_impl.cc @@ -62,7 +62,7 @@ #include "src/core/load_balancing/subchannel_interface.h" #include "src/core/load_balancing/xds/xds_channel_args.h" #include "src/core/resolver/endpoint_addresses.h" -#include "src/core/resolver/xds/xds_dependency_manager.h" +#include "src/core/resolver/xds/xds_config.h" #include "src/core/resolver/xds/xds_resolver_attributes.h" #include "src/core/telemetry/call_tracer.h" #include "src/core/util/json/json.h" @@ -79,8 +79,6 @@ namespace grpc_core { namespace { -using XdsConfig = XdsDependencyManager::XdsConfig; - // // global circuit breaker atomic map // diff --git a/src/core/load_balancing/xds/xds_override_host.cc b/src/core/load_balancing/xds/xds_override_host.cc index a3de3e6b97c93..62a1632f2ca8e 100644 --- a/src/core/load_balancing/xds/xds_override_host.cc +++ b/src/core/load_balancing/xds/xds_override_host.cc @@ -77,7 +77,7 @@ #include "src/core/load_balancing/lb_policy_registry.h" #include "src/core/load_balancing/subchannel_interface.h" #include "src/core/resolver/endpoint_addresses.h" -#include "src/core/resolver/xds/xds_dependency_manager.h" +#include "src/core/resolver/xds/xds_config.h" #include "src/core/util/json/json.h" #include "src/core/util/json/json_args.h" #include "src/core/util/json/json_object_loader.h" @@ -738,8 +738,7 @@ absl::Status XdsOverrideHostLb::UpdateLocked(UpdateArgs args) { } auto new_config = args.config.TakeAsSubclass(); // Get xDS config. - auto new_xds_config = - args.args.GetObjectRef(); + auto new_xds_config = args.args.GetObjectRef(); if (new_xds_config == nullptr) { // Should never happen. absl::Status status = absl::InternalError( diff --git a/src/core/resolver/xds/xds_config.cc b/src/core/resolver/xds/xds_config.cc new file mode 100644 index 0000000000000..1fcb2aa81c7a1 --- /dev/null +++ b/src/core/resolver/xds/xds_config.cc @@ -0,0 +1,96 @@ +// +// Copyright 2019 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include "src/core/resolver/xds/xds_config.h" + +#include +#include +#include +#include + +#include "absl/strings/str_cat.h" +#include "absl/strings/str_join.h" + +#include "src/core/lib/gprpp/match.h" + +namespace grpc_core { + +// +// XdsConfig::ClusterConfig +// + +XdsConfig::ClusterConfig::ClusterConfig( + std::shared_ptr cluster, + std::shared_ptr endpoints, + std::string resolution_note) + : cluster(std::move(cluster)), + children(absl::in_place_type_t(), std::move(endpoints), + std::move(resolution_note)) {} + +XdsConfig::ClusterConfig::ClusterConfig( + std::shared_ptr cluster, + std::vector leaf_clusters) + : cluster(std::move(cluster)), + children(absl::in_place_type_t(), + std::move(leaf_clusters)) {} + +// +// XdsConfig +// + +std::string XdsConfig::ToString() const { + std::vector parts = { + "{\n listener: {", listener->ToString(), + "}\n route_config: {", route_config->ToString(), + "}\n virtual_host: {", virtual_host->ToString(), + "}\n clusters: {\n"}; + for (const auto& p : clusters) { + parts.push_back(absl::StrCat(" \"", p.first, "\": ")); + if (!p.second.ok()) { + parts.push_back(p.second.status().ToString()); + parts.push_back("\n"); + } else { + parts.push_back( + absl::StrCat(" {\n" + " cluster: {", + p.second->cluster->ToString(), "}\n")); + Match( + p.second->children, + [&](const ClusterConfig::EndpointConfig& endpoint_config) { + parts.push_back( + absl::StrCat(" endpoints: {", + endpoint_config.endpoints == nullptr + ? "" + : endpoint_config.endpoints->ToString(), + "}\n" + " resolution_note: \"", + endpoint_config.resolution_note, "\"\n")); + }, + [&](const ClusterConfig::AggregateConfig& aggregate_config) { + parts.push_back(absl::StrCat( + " leaf_clusters: [", + absl::StrJoin(aggregate_config.leaf_clusters, ", "), "]\n")); + }); + parts.push_back( + " }\n" + " ]\n"); + } + } + parts.push_back(" }\n}"); + return absl::StrJoin(parts, ""); +} + +} // namespace grpc_core diff --git a/src/core/resolver/xds/xds_config.h b/src/core/resolver/xds/xds_config.h new file mode 100644 index 0000000000000..9c328a205783d --- /dev/null +++ b/src/core/resolver/xds/xds_config.h @@ -0,0 +1,109 @@ +// +// Copyright 2019 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef GRPC_SRC_CORE_RESOLVER_XDS_XDS_CONFIG_H +#define GRPC_SRC_CORE_RESOLVER_XDS_XDS_CONFIG_H + +#include +#include +#include +#include + +#include "absl/container/flat_hash_map.h" +#include "absl/status/statusor.h" +#include "absl/strings/string_view.h" +#include "absl/types/variant.h" + +#include "src/core/lib/gprpp/ref_counted.h" +#include "src/core/xds/grpc/xds_cluster.h" +#include "src/core/xds/grpc/xds_endpoint.h" +#include "src/core/xds/grpc/xds_listener.h" +#include "src/core/xds/grpc/xds_route_config.h" + +namespace grpc_core { + +// A complete gRPC client-side xDS config containing all necessary +// resources. +struct XdsConfig : public RefCounted { + // Listener resource. Always non-null. + std::shared_ptr listener; + // RouteConfig resource. Will be populated even if RouteConfig is + // inlined into the Listener resource. + std::shared_ptr route_config; + // Virtual host. Points into route_config. Will always be non-null. + const XdsRouteConfigResource::VirtualHost* virtual_host; + + struct ClusterConfig { + // Cluster resource. Always non-null. + std::shared_ptr cluster; + // Endpoint info for EDS and LOGICAL_DNS clusters. If there was an + // error, endpoints will be null and resolution_note will be set. + struct EndpointConfig { + std::shared_ptr endpoints; + std::string resolution_note; + + EndpointConfig(std::shared_ptr endpoints, + std::string resolution_note) + : endpoints(std::move(endpoints)), + resolution_note(std::move(resolution_note)) {} + bool operator==(const EndpointConfig& other) const { + return endpoints == other.endpoints && + resolution_note == other.resolution_note; + } + }; + // The list of leaf clusters for an aggregate cluster. + struct AggregateConfig { + std::vector leaf_clusters; + + explicit AggregateConfig(std::vector leaf_clusters) + : leaf_clusters(std::move(leaf_clusters)) {} + bool operator==(const AggregateConfig& other) const { + return leaf_clusters == other.leaf_clusters; + } + }; + absl::variant children; + + // Ctor for leaf clusters. + ClusterConfig(std::shared_ptr cluster, + std::shared_ptr endpoints, + std::string resolution_note); + // Ctor for aggregate clusters. + ClusterConfig(std::shared_ptr cluster, + std::vector leaf_clusters); + + bool operator==(const ClusterConfig& other) const { + return cluster == other.cluster && children == other.children; + } + }; + // Cluster map. A cluster will have a non-OK status if either + // (a) there was an error and we did not already have a valid + // resource or (b) the resource does not exist. + absl::flat_hash_map> clusters; + + std::string ToString() const; + + static absl::string_view ChannelArgName() { + return GRPC_ARG_NO_SUBCHANNEL_PREFIX "xds_config"; + } + static int ChannelArgsCompare(const XdsConfig* a, const XdsConfig* b) { + return QsortCompare(a, b); + } + static constexpr bool ChannelArgUseConstPtr() { return true; } +}; + +} // namespace grpc_core + +#endif // GRPC_SRC_CORE_RESOLVER_XDS_XDS_CONFIG_H diff --git a/src/core/resolver/xds/xds_dependency_manager.cc b/src/core/resolver/xds/xds_dependency_manager.cc index edbb4599af47f..293586f40f5bf 100644 --- a/src/core/resolver/xds/xds_dependency_manager.cc +++ b/src/core/resolver/xds/xds_dependency_manager.cc @@ -43,71 +43,6 @@ constexpr int kMaxXdsAggregateClusterRecursionDepth = 16; } // namespace -// -// XdsDependencyManager::XdsConfig::ClusterConfig -// - -XdsDependencyManager::XdsConfig::ClusterConfig::ClusterConfig( - std::shared_ptr cluster, - std::shared_ptr endpoints, - std::string resolution_note) - : cluster(std::move(cluster)), - children(absl::in_place_type_t(), std::move(endpoints), - std::move(resolution_note)) {} - -XdsDependencyManager::XdsConfig::ClusterConfig::ClusterConfig( - std::shared_ptr cluster, - std::vector leaf_clusters) - : cluster(std::move(cluster)), - children(absl::in_place_type_t(), - std::move(leaf_clusters)) {} - -// -// XdsDependencyManager::XdsConfig -// - -std::string XdsDependencyManager::XdsConfig::ToString() const { - std::vector parts = { - "{\n listener: {", listener->ToString(), - "}\n route_config: {", route_config->ToString(), - "}\n virtual_host: {", virtual_host->ToString(), - "}\n clusters: {\n"}; - for (const auto& p : clusters) { - parts.push_back(absl::StrCat(" \"", p.first, "\": ")); - if (!p.second.ok()) { - parts.push_back(p.second.status().ToString()); - parts.push_back("\n"); - } else { - parts.push_back( - absl::StrCat(" {\n" - " cluster: {", - p.second->cluster->ToString(), "}\n")); - Match( - p.second->children, - [&](const ClusterConfig::EndpointConfig& endpoint_config) { - parts.push_back( - absl::StrCat(" endpoints: {", - endpoint_config.endpoints == nullptr - ? "" - : endpoint_config.endpoints->ToString(), - "}\n" - " resolution_note: \"", - endpoint_config.resolution_note, "\"\n")); - }, - [&](const ClusterConfig::AggregateConfig& aggregate_config) { - parts.push_back(absl::StrCat( - " leaf_clusters: [", - absl::StrJoin(aggregate_config.leaf_clusters, ", "), "]\n")); - }); - parts.push_back( - " }\n" - " ]\n"); - } - } - parts.push_back(" }\n}"); - return absl::StrJoin(parts, ""); -} - // // XdsDependencyManager::ListenerWatcher // diff --git a/src/core/resolver/xds/xds_dependency_manager.h b/src/core/resolver/xds/xds_dependency_manager.h index 959ee7f2a7650..b2b62ddf2224b 100644 --- a/src/core/resolver/xds/xds_dependency_manager.h +++ b/src/core/resolver/xds/xds_dependency_manager.h @@ -21,10 +21,9 @@ #include "absl/container/flat_hash_set.h" #include "absl/strings/string_view.h" -#include - #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/resolver/resolver.h" +#include "src/core/resolver/xds/xds_config.h" #include "src/core/xds/grpc/xds_client_grpc.h" #include "src/core/xds/grpc/xds_cluster.h" #include "src/core/xds/grpc/xds_endpoint.h" @@ -38,73 +37,6 @@ namespace grpc_core { class XdsDependencyManager final : public RefCounted, public Orphanable { public: - struct XdsConfig : public RefCounted { - // Listener resource. Always non-null. - std::shared_ptr listener; - // RouteConfig resource. Will be populated even if RouteConfig is - // inlined into the Listener resource. - std::shared_ptr route_config; - // Virtual host. Points into route_config. Will always be non-null. - const XdsRouteConfigResource::VirtualHost* virtual_host; - - struct ClusterConfig { - // Cluster resource. Always non-null. - std::shared_ptr cluster; - // Endpoint info for EDS and LOGICAL_DNS clusters. If there was an - // error, endpoints will be null and resolution_note will be set. - struct EndpointConfig { - std::shared_ptr endpoints; - std::string resolution_note; - - EndpointConfig(std::shared_ptr endpoints, - std::string resolution_note) - : endpoints(std::move(endpoints)), - resolution_note(std::move(resolution_note)) {} - bool operator==(const EndpointConfig& other) const { - return endpoints == other.endpoints && - resolution_note == other.resolution_note; - } - }; - // The list of leaf clusters for an aggregate cluster. - struct AggregateConfig { - std::vector leaf_clusters; - - explicit AggregateConfig(std::vector leaf_clusters) - : leaf_clusters(std::move(leaf_clusters)) {} - bool operator==(const AggregateConfig& other) const { - return leaf_clusters == other.leaf_clusters; - } - }; - absl::variant children; - - // Ctor for leaf clusters. - ClusterConfig(std::shared_ptr cluster, - std::shared_ptr endpoints, - std::string resolution_note); - // Ctor for aggregate clusters. - ClusterConfig(std::shared_ptr cluster, - std::vector leaf_clusters); - - bool operator==(const ClusterConfig& other) const { - return cluster == other.cluster && children == other.children; - } - }; - // Cluster map. A cluster will have a non-OK status if either - // (a) there was an error and we did not already have a valid - // resource or (b) the resource does not exist. - absl::flat_hash_map> clusters; - - std::string ToString() const; - - static absl::string_view ChannelArgName() { - return GRPC_ARG_NO_SUBCHANNEL_PREFIX "xds_config"; - } - static int ChannelArgsCompare(const XdsConfig* a, const XdsConfig* b) { - return QsortCompare(a, b); - } - static constexpr bool ChannelArgUseConstPtr() { return true; } - }; - class Watcher { public: virtual ~Watcher() = default; diff --git a/src/core/resolver/xds/xds_resolver.cc b/src/core/resolver/xds/xds_resolver.cc index a8880674c4dbf..9cb490985343b 100644 --- a/src/core/resolver/xds/xds_resolver.cc +++ b/src/core/resolver/xds/xds_resolver.cc @@ -139,8 +139,7 @@ class XdsResolver final : public Resolver { explicit XdsWatcher(RefCountedPtr resolver) : resolver_(std::move(resolver)) {} - void OnUpdate( - RefCountedPtr config) override { + void OnUpdate(RefCountedPtr config) override { resolver_->OnUpdate(std::move(config)); } @@ -363,7 +362,7 @@ class XdsResolver final : public Resolver { return it->second->Ref(); } - void OnUpdate(RefCountedPtr config); + void OnUpdate(RefCountedPtr config); void OnError(absl::string_view context, absl::Status status); void OnResourceDoesNotExist(std::string context); @@ -382,7 +381,7 @@ class XdsResolver final : public Resolver { const uint64_t channel_id_; OrphanablePtr dependency_mgr_; - RefCountedPtr current_config_; + RefCountedPtr current_config_; std::map> cluster_ref_map_; }; @@ -976,8 +975,7 @@ void XdsResolver::ShutdownLocked() { } } -void XdsResolver::OnUpdate( - RefCountedPtr config) { +void XdsResolver::OnUpdate(RefCountedPtr config) { GRPC_TRACE_LOG(xds_resolver, INFO) << "[xds_resolver " << this << "] received updated xDS config"; if (xds_client_ == nullptr) return; diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 74eedd1126cf2..65b4ee1136870 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -753,6 +753,7 @@ 'src/core/resolver/resolver.cc', 'src/core/resolver/resolver_registry.cc', 'src/core/resolver/sockaddr/sockaddr_resolver.cc', + 'src/core/resolver/xds/xds_config.cc', 'src/core/resolver/xds/xds_dependency_manager.cc', 'src/core/resolver/xds/xds_resolver.cc', 'src/core/server/server.cc', diff --git a/test/core/load_balancing/xds_override_host_test.cc b/test/core/load_balancing/xds_override_host_test.cc index 989545290a668..11208870e89de 100644 --- a/test/core/load_balancing/xds_override_host_test.cc +++ b/test/core/load_balancing/xds_override_host_test.cc @@ -43,7 +43,7 @@ #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/load_balancing/lb_policy.h" #include "src/core/resolver/endpoint_addresses.h" -#include "src/core/resolver/xds/xds_dependency_manager.h" +#include "src/core/resolver/xds/xds_config.h" #include "src/core/util/json/json.h" #include "src/core/xds/grpc/xds_health_status.h" #include "test/core/load_balancing/lb_policy_test_lib.h" @@ -57,7 +57,7 @@ class XdsOverrideHostTest : public LoadBalancingPolicyTest { XdsOverrideHostTest() : LoadBalancingPolicyTest("xds_override_host_experimental") {} - static RefCountedPtr MakeXdsConfig( + static RefCountedPtr MakeXdsConfig( absl::Span override_host_statuses = {"UNKNOWN", "HEALTHY"}, absl::optional connection_idle_timeout = absl::nullopt, @@ -70,7 +70,7 @@ class XdsOverrideHostTest : public LoadBalancingPolicyTest { if (connection_idle_timeout.has_value()) { cluster_resource->connection_idle_timeout = *connection_idle_timeout; } - auto xds_config = MakeRefCounted(); + auto xds_config = MakeRefCounted(); xds_config->clusters[std::move(cluster_name)].emplace( std::move(cluster_resource), nullptr, ""); return xds_config; diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index bdcc33a9a7009..c1790c49ad1ed 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -2820,6 +2820,8 @@ src/core/resolver/resolver_registry.cc \ src/core/resolver/resolver_registry.h \ src/core/resolver/server_address.h \ src/core/resolver/sockaddr/sockaddr_resolver.cc \ +src/core/resolver/xds/xds_config.cc \ +src/core/resolver/xds/xds_config.h \ src/core/resolver/xds/xds_dependency_manager.cc \ src/core/resolver/xds/xds_dependency_manager.h \ src/core/resolver/xds/xds_resolver.cc \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 978ef442a3620..32375b762787c 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -2597,6 +2597,8 @@ src/core/resolver/resolver_registry.h \ src/core/resolver/server_address.h \ src/core/resolver/sockaddr/README.md \ src/core/resolver/sockaddr/sockaddr_resolver.cc \ +src/core/resolver/xds/xds_config.cc \ +src/core/resolver/xds/xds_config.h \ src/core/resolver/xds/xds_dependency_manager.cc \ src/core/resolver/xds/xds_dependency_manager.h \ src/core/resolver/xds/xds_resolver.cc \