// total availability. Load is assigned to each priority according to how available each priority is
// @param per_priority_availability the percentage availability of each priority, used to determine
// @param total_load the amount of load that may be distributed. Will be updated with the amount of
class LoadBalancerBase : public LoadBalancer, protected Logger::Loggable<Logger::Id::upstream> {
// Returns the priority, a number between 0 and per_priority_load.size()-1 as well as which host
OptRef<Envoy::Http::ConnectionPool::ConnectionLifetimeCallbacks> lifetimeCallbacks() override {
LoadBalancerBase(const PrioritySet& priority_set, ClusterLbStats& stats, Runtime::Loader& runtime,
std::accumulate(per_priority_degraded.get().begin(), per_priority_degraded.get().end(), 0);
using LocalityLbConfig = envoy::extensions::load_balancing_policies::common::v3::LocalityLbConfig;
ZoneAwareLoadBalancerBase(const PrioritySet& priority_set, const PrioritySet* local_priority_set,
* Pick the host source to use, doing zone aware routing when the hosts are sufficiently healthy.
* Regenerate locality aware routing structures for fast decisions on upstream locality selection.
static absl::optional<HostsSource::SourceType> sourceType(HostAvailability host_availability) {
return absl::make_optional<HostsSource::SourceType>(HostsSource::SourceType::HealthyHosts);
return absl::make_optional<HostsSource::SourceType>(HostsSource::SourceType::DegradedHosts);
* Base implementation of LoadBalancer that performs weighted RR selection across the hosts in the
* n) pick and insertion time complexity, O(n) memory use. The key insight is that if we schedule
* with 1 / weight deadline, we will achieve the desired pick frequency for weighted RR in a given
* interval. Naive implementations of weighted RR are either O(n) pick time or O(m * n) memory use,
* where m is the weight range. We also explicitly check for the unweighted special case and use a
* support large ranges of weights or arbitrary precision floating weights, we could construct an
* behavior. Derived classes can also override how host weight is determined when in weighted mode.
using SlowStartConfig = envoy::extensions::load_balancing_policies::common::v3::SlowStartConfig;