Skip to content

Commit

Permalink
[xDS] move XdsConfig out of XdsDependencyManager
Browse files Browse the repository at this point in the history
  • Loading branch information
markdroth committed Aug 23, 2024
1 parent 158976a commit 0575c5b
Show file tree
Hide file tree
Showing 23 changed files with 268 additions and 153 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Package.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions build_autogenerated.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config.m4

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config.w32

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions gRPC-C++.podspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions gRPC-Core.podspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions grpc.gemspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 30 additions & 2 deletions src/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5858,6 +5858,7 @@ grpc_cc_library(
"unique_type_name",
"xds_cluster",
"xds_common_types",
"xds_config",
"xds_dependency_manager",
"xds_health_status",
"//:config",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -6636,7 +6637,7 @@ grpc_cc_library(
"resolved_address",
"subchannel_interface",
"validation_errors",
"xds_dependency_manager",
"xds_config",
"xds_health_status",
"//:config",
"//:debug_location",
Expand Down Expand Up @@ -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 = [
Expand All @@ -7006,6 +7032,7 @@ grpc_cc_library(
"xds_endpoint",
"xds_listener",
"xds_route_config",
"xds_config",
"//:config",
"//:gpr",
"//:grpc_resolver",
Expand Down Expand Up @@ -7057,6 +7084,7 @@ grpc_cc_library(
"xds_http_filter",
"xds_listener",
"xds_route_config",
"xds_config",
"xxhash_inline",
"//:channel_arg_names",
"//:config",
Expand Down
2 changes: 0 additions & 2 deletions src/core/load_balancing/xds/cds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions src/core/load_balancing/xds/xds_cluster_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -79,8 +79,6 @@ namespace grpc_core {

namespace {

using XdsConfig = XdsDependencyManager::XdsConfig;

//
// global circuit breaker atomic map
//
Expand Down
5 changes: 2 additions & 3 deletions src/core/load_balancing/xds/xds_override_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -738,8 +738,7 @@ absl::Status XdsOverrideHostLb::UpdateLocked(UpdateArgs args) {
}
auto new_config = args.config.TakeAsSubclass<XdsOverrideHostLbConfig>();
// Get xDS config.
auto new_xds_config =
args.args.GetObjectRef<XdsDependencyManager::XdsConfig>();
auto new_xds_config = args.args.GetObjectRef<XdsConfig>();
if (new_xds_config == nullptr) {
// Should never happen.
absl::Status status = absl::InternalError(
Expand Down
96 changes: 96 additions & 0 deletions src/core/resolver/xds/xds_config.cc
Original file line number Diff line number Diff line change
@@ -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 <memory>
#include <string>
#include <utility>
#include <vector>

#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<const XdsClusterResource> cluster,
std::shared_ptr<const XdsEndpointResource> endpoints,
std::string resolution_note)
: cluster(std::move(cluster)),
children(absl::in_place_type_t<EndpointConfig>(), std::move(endpoints),
std::move(resolution_note)) {}

XdsConfig::ClusterConfig::ClusterConfig(
std::shared_ptr<const XdsClusterResource> cluster,
std::vector<absl::string_view> leaf_clusters)
: cluster(std::move(cluster)),
children(absl::in_place_type_t<AggregateConfig>(),
std::move(leaf_clusters)) {}

//
// XdsConfig
//

std::string XdsConfig::ToString() const {
std::vector<std::string> 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
? "<null>"
: 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
Loading

0 comments on commit 0575c5b

Please sign in to comment.