/proc/self/cwd/source/extensions/load_balancing_policies/least_request/config.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "source/extensions/load_balancing_policies/least_request/config.h" |
2 | | |
3 | | #include "envoy/extensions/load_balancing_policies/least_request/v3/least_request.pb.h" |
4 | | |
5 | | #include "source/common/upstream/load_balancer_impl.h" |
6 | | |
7 | | namespace Envoy { |
8 | | namespace Extensions { |
9 | | namespace LoadBalancingPolices { |
10 | | namespace LeastRequest { |
11 | | |
12 | 0 | LegacyLeastRequestLbConfig::LegacyLeastRequestLbConfig(const ClusterProto& cluster) { |
13 | 0 | if (cluster.has_least_request_lb_config()) { |
14 | 0 | lb_config_ = cluster.least_request_lb_config(); |
15 | 0 | } |
16 | 0 | } |
17 | | |
18 | | TypedLeastRequestLbConfig::TypedLeastRequestLbConfig(const LeastRequestLbProto& lb_config) |
19 | 0 | : lb_config_(lb_config) {} |
20 | | |
21 | | Upstream::LoadBalancerPtr LeastRequestCreator::operator()( |
22 | | Upstream::LoadBalancerParams params, OptRef<const Upstream::LoadBalancerConfig> lb_config, |
23 | | const Upstream::ClusterInfo& cluster_info, const Upstream::PrioritySet&, |
24 | 0 | Runtime::Loader& runtime, Random::RandomGenerator& random, TimeSource& time_source) { |
25 | |
|
26 | 0 | auto active_or_legacy = |
27 | 0 | Common::ActiveOrLegacy<TypedLeastRequestLbConfig, LegacyLeastRequestLbConfig>::get( |
28 | 0 | 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 | 0 | ASSERT(active_or_legacy.hasLegacy() || active_or_legacy.hasActive(), |
33 | 0 | "Invalid load balancing policy configuration for least request load balancer"); |
34 | | |
35 | 0 | if (active_or_legacy.hasActive()) { |
36 | 0 | return std::make_unique<Upstream::LeastRequestLoadBalancer>( |
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 | 0 | } else { |
42 | 0 | return std::make_unique<Upstream::LeastRequestLoadBalancer>( |
43 | 0 | params.priority_set, params.local_priority_set, cluster_info.lbStats(), runtime, random, |
44 | 0 | cluster_info.lbConfig(), active_or_legacy.legacy()->lbConfig(), time_source); |
45 | 0 | } |
46 | 0 | } |
47 | | |
48 | | /** |
49 | | * Static registration for the Factory. @see RegisterFactory. |
50 | | */ |
51 | | REGISTER_FACTORY(Factory, Upstream::TypedLoadBalancerFactory); |
52 | | |
53 | | } // namespace LeastRequest |
54 | | } // namespace LoadBalancingPolices |
55 | | } // namespace Extensions |
56 | | } // namespace Envoy |