Skip to content

Commit

Permalink
upstream lb: move all subset related code to extensions/ (envoyproxy#…
Browse files Browse the repository at this point in the history
…33964)

* upstream lb: move all subset related code to extensions/

Signed-off-by: wbpcode <[email protected]>

* address comments

Signed-off-by: wbpcode <[email protected]>

---------

Signed-off-by: wbpcode <[email protected]>
Co-authored-by: wbpcode <[email protected]>
  • Loading branch information
code and wbpcode authored May 7, 2024
1 parent 0bf91cd commit a96b7ad
Show file tree
Hide file tree
Showing 21 changed files with 560 additions and 875 deletions.
11 changes: 0 additions & 11 deletions envoy/upstream/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,6 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "load_balancer_type_interface",
hdrs = ["load_balancer_type.h"],
deps = [
"//source/common/protobuf",
"@envoy_api//envoy/config/cluster/v3:pkg_cc_proto",
],
)

envoy_cc_library(
name = "locality_lib",
hdrs = ["locality.h"],
Expand Down Expand Up @@ -158,7 +149,6 @@ envoy_cc_library(
external_deps = ["abseil_optional"],
deps = [
":health_check_host_monitor_interface",
":load_balancer_type_interface",
":locality_lib",
":resource_manager_interface",
"//envoy/common:callback",
Expand All @@ -184,7 +174,6 @@ envoy_cc_library(
deps = [
":cluster_manager_interface",
":health_check_host_monitor_interface",
":load_balancer_type_interface",
":locality_lib",
":resource_manager_interface",
":upstream_interface",
Expand Down
126 changes: 0 additions & 126 deletions envoy/upstream/load_balancer_type.h

This file was deleted.

1 change: 0 additions & 1 deletion envoy/upstream/upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "envoy/stats/scope.h"
#include "envoy/stats/stats.h"
#include "envoy/upstream/health_check_host_monitor.h"
#include "envoy/upstream/load_balancer_type.h"
#include "envoy/upstream/locality.h"
#include "envoy/upstream/outlier_detection.h"
#include "envoy/upstream/resource_manager.h"
Expand Down
1 change: 1 addition & 0 deletions mobile/test/performance/files_em_does_not_use
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ source/server/watchdog_impl.h
source/server/options_impl.cc
source/extensions/access_loggers/common/file_access_log_impl.h
source/common/router/scoped_rds.h
source/extensions/load_balancing_policies/subset/subset_lb.h
15 changes: 0 additions & 15 deletions source/common/upstream/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -257,27 +257,12 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "subset_lb_config_lib",
srcs = ["subset_lb_config.cc"],
hdrs = ["subset_lb_config.h"],
deps = [
"//envoy/upstream:load_balancer_interface",
"//envoy/upstream:upstream_interface",
"//source/common/config:utility_lib",
"@envoy_api//envoy/config/cluster/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/load_balancing_policies/common/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/load_balancing_policies/subset/v3:pkg_cc_proto",
],
)

envoy_cc_library(
name = "load_balancer_lib",
srcs = ["load_balancer_impl.cc"],
hdrs = ["load_balancer_impl.h"],
deps = [
":scheduler_lib",
":subset_lb_config_lib",
"//envoy/common:random_generator_interface",
"//envoy/runtime:runtime_interface",
"//envoy/stats:stats_interface",
Expand Down
5 changes: 2 additions & 3 deletions source/common/upstream/cluster_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,8 @@ class ClusterManagerImpl : public ClusterManager,
// Don't change the order of cluster_info_ and lb_factory_/lb_ as the the lb_factory_/lb_
// may keep a reference to the cluster_info_.
ClusterInfoConstSharedPtr cluster_info_;
// LB factory if applicable. Not all load balancer types have a factory. LB types that have
// a factory will create a new LB on every membership update. LB types that don't have a
// factory will create an LB on construction and use it forever.

// Factory to create active LB.
LoadBalancerFactorySharedPtr lb_factory_;
// Current active LB.
LoadBalancerPtr lb_;
Expand Down
1 change: 0 additions & 1 deletion source/common/upstream/load_balancer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "source/common/protobuf/utility.h"
#include "source/common/runtime/runtime_protos.h"
#include "source/common/upstream/edf_scheduler.h"
#include "source/common/upstream/subset_lb_config.h"

namespace Envoy {
namespace Upstream {
Expand Down
53 changes: 0 additions & 53 deletions source/common/upstream/subset_lb_config.cc

This file was deleted.

20 changes: 17 additions & 3 deletions source/extensions/load_balancing_policies/subset/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@ envoy_cc_library(
srcs = ["subset_lb.cc"],
hdrs = ["subset_lb.h"],
deps = [
":subset_lb_config_lib",
"//envoy/runtime:runtime_interface",
"//envoy/upstream:load_balancer_interface",
"//source/common/common:assert_lib",
"//source/common/common:minimal_logger_lib",
"//source/common/config:metadata_lib",
"//source/common/protobuf",
"//source/common/protobuf:utility_lib",
"//source/common/upstream:load_balancer_lib",
"//source/common/upstream:upstream_lib",
"//source/extensions/load_balancing_policies/common:factory_base",
"//source/extensions/load_balancing_policies/maglev:maglev_lb_lib",
"//source/extensions/load_balancing_policies/ring_hash:ring_hash_lb_lib",
"@envoy_api//envoy/config/cluster/v3:pkg_cc_proto",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/load_balancing_policies/subset/v3:pkg_cc_proto",
Expand All @@ -47,3 +45,19 @@ envoy_cc_extension(
"//source/common/upstream:load_balancer_lib",
],
)

envoy_cc_extension(
name = "subset_lb_config_lib",
srcs = ["subset_lb_config.cc"],
hdrs = ["subset_lb_config.h"],
deps = [
"//envoy/upstream:load_balancer_interface",
"//envoy/upstream:upstream_interface",
"//source/common/config:utility_lib",
"//source/common/upstream:load_balancer_lib",
"//source/common/upstream:upstream_lib",
"@envoy_api//envoy/config/cluster/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/load_balancing_policies/common/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/load_balancing_policies/subset/v3:pkg_cc_proto",
],
)
43 changes: 4 additions & 39 deletions source/extensions/load_balancing_policies/subset/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,6 @@ namespace Subset {
using SubsetLbProto = envoy::extensions::load_balancing_policies::subset::v3::Subset;
using ClusterProto = envoy::config::cluster::v3::Cluster;

class ChildLoadBalancerCreatorImpl : public Upstream::ChildLoadBalancerCreator {
public:
ChildLoadBalancerCreatorImpl(const Upstream::SubsetLoadBalancerConfig& subset_config,
const Upstream::ClusterInfo& cluster_info)
: subset_config_(subset_config), cluster_info_(cluster_info) {}

std::pair<Upstream::ThreadAwareLoadBalancerPtr, Upstream::LoadBalancerPtr>
createLoadBalancer(const Upstream::PrioritySet& child_priority_set, const Upstream::PrioritySet*,
Upstream::ClusterLbStats&, Stats::Scope&, Runtime::Loader& runtime,
Random::RandomGenerator& random, TimeSource& time_source) override {
return {subset_config_.createLoadBalancer(cluster_info_, child_priority_set, runtime, random,
time_source),
nullptr};
}

private:
const Upstream::SubsetLoadBalancerConfig& subset_config_;
const Upstream::ClusterInfo& cluster_info_;
};

class LbFactory : public Upstream::LoadBalancerFactory {
public:
LbFactory(const Upstream::SubsetLoadBalancerConfig& subset_config,
Expand All @@ -41,13 +21,9 @@ class LbFactory : public Upstream::LoadBalancerFactory {
random_(random), time_source_(time_source) {}

Upstream::LoadBalancerPtr create(Upstream::LoadBalancerParams params) override {
auto child_lb_creator =
std::make_unique<ChildLoadBalancerCreatorImpl>(subset_config_, cluster_info_);

return std::make_unique<Upstream::SubsetLoadBalancer>(
subset_config_.subsetInfo(), std::move(child_lb_creator), params.priority_set,
params.local_priority_set, cluster_info_.lbStats(), cluster_info_.statsScope(), runtime_,
random_, time_source_);
subset_config_, cluster_info_, params.priority_set, params.local_priority_set,
cluster_info_.lbStats(), cluster_info_.statsScope(), runtime_, random_, time_source_);
}
bool recreateOnHostChange() const override { return false; }

Expand Down Expand Up @@ -97,7 +73,6 @@ SubsetLbFactory::create(OptRef<const Upstream::LoadBalancerConfig> lb_config,
Upstream::LoadBalancerConfigPtr
SubsetLbFactory::loadConfig(const Protobuf::Message& config,
ProtobufMessage::ValidationVisitor& visitor) {

auto active_or_legacy = Common::ActiveOrLegacy<SubsetLbProto, ClusterProto>::get(&config);
ASSERT(active_or_legacy.hasLegacy() || active_or_legacy.hasActive());

Expand All @@ -109,18 +84,8 @@ SubsetLbFactory::loadConfig(const Protobuf::Message& config,
envoy::config::cluster::v3::Cluster::LbPolicy_Name(
active_or_legacy.legacy()->lb_policy())));
}

auto sub_lb_pair =
Upstream::LegacyLbPolicyConfigHelper::getTypedLbConfigFromLegacyProtoWithoutSubset(
*active_or_legacy.legacy(), visitor);

if (!sub_lb_pair.ok()) {
throw EnvoyException(std::string(sub_lb_pair.status().message()));
}

return std::make_unique<Upstream::SubsetLoadBalancerConfig>(
active_or_legacy.legacy()->lb_subset_config(), std::move(sub_lb_pair->config),
sub_lb_pair->factory);
return std::make_unique<Upstream::SubsetLoadBalancerConfig>(*active_or_legacy.legacy(),
visitor);
}

// Load the subset load balancer configuration. This will contains child load balancer
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/load_balancing_policies/subset/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace LoadBalancingPolices {
namespace Subset {

class SubsetLbFactory
: public Upstream::TypedLoadBalancerFactoryBase<Upstream::SubsetLoadbalancingPolicyProto> {
: public Upstream::TypedLoadBalancerFactoryBase<Upstream::SubsetLbConfigProto> {
public:
SubsetLbFactory() : TypedLoadBalancerFactoryBase("envoy.load_balancing_policies.subset") {}

Expand Down
Loading

0 comments on commit a96b7ad

Please sign in to comment.