Line data Source code
1 : #include "source/extensions/load_balancing_policies/round_robin/config.h" 2 : 3 : #include "envoy/extensions/load_balancing_policies/round_robin/v3/round_robin.pb.h" 4 : 5 : #include "source/common/upstream/load_balancer_impl.h" 6 : 7 : namespace Envoy { 8 : namespace Extensions { 9 : namespace LoadBalancingPolices { 10 : namespace RoundRobin { 11 : 12 159 : LegacyRoundRobinLbConfig::LegacyRoundRobinLbConfig(const ClusterProto& cluster) { 13 159 : if (cluster.has_round_robin_lb_config()) { 14 0 : lb_config_ = cluster.round_robin_lb_config(); 15 0 : } 16 159 : } 17 : 18 : TypedRoundRobinLbConfig::TypedRoundRobinLbConfig(const RoundRobinLbProto& lb_config) 19 0 : : lb_config_(lb_config) {} 20 : 21 : Upstream::LoadBalancerPtr RoundRobinCreator::operator()( 22 : Upstream::LoadBalancerParams params, OptRef<const Upstream::LoadBalancerConfig> lb_config, 23 : const Upstream::ClusterInfo& cluster_info, const Upstream::PrioritySet&, 24 306 : Runtime::Loader& runtime, Random::RandomGenerator& random, TimeSource& time_source) { 25 : 26 306 : auto active_or_legacy = 27 306 : Common::ActiveOrLegacy<TypedRoundRobinLbConfig, LegacyRoundRobinLbConfig>::get( 28 306 : lb_config.ptr()); 29 : 30 : // The load balancing policy configuration will be loaded and validated in the main thread when we 31 : // load the cluster configuration. So we can assume the configuration is valid here. 32 306 : ASSERT(active_or_legacy.hasLegacy() || active_or_legacy.hasActive(), 33 306 : "Invalid load balancing policy configuration for least request load balancer"); 34 : 35 306 : if (active_or_legacy.hasActive()) { 36 0 : return std::make_unique<Upstream::RoundRobinLoadBalancer>( 37 0 : params.priority_set, params.local_priority_set, cluster_info.lbStats(), runtime, random, 38 0 : PROTOBUF_PERCENT_TO_ROUNDED_INTEGER_OR_DEFAULT(cluster_info.lbConfig(), 39 0 : healthy_panic_threshold, 100, 50), 40 0 : active_or_legacy.active()->lb_config_, time_source); 41 306 : } else { 42 306 : return std::make_unique<Upstream::RoundRobinLoadBalancer>( 43 306 : params.priority_set, params.local_priority_set, cluster_info.lbStats(), runtime, random, 44 306 : cluster_info.lbConfig(), active_or_legacy.legacy()->lbConfig(), time_source); 45 306 : } 46 306 : } 47 : 48 : /** 49 : * Static registration for the Factory. @see RegisterFactory. 50 : */ 51 : REGISTER_FACTORY(Factory, Upstream::TypedLoadBalancerFactory); 52 : 53 : } // namespace RoundRobin 54 : } // namespace LoadBalancingPolices 55 : } // namespace Extensions 56 : } // namespace Envoy