Package io.grpc.xds

Class LoadBalancerConfigFactory

java.lang.Object
io.grpc.xds.LoadBalancerConfigFactory

class LoadBalancerConfigFactory extends Object
Creates service config JSON load balancer config objects for a given xDS Cluster message. Supports both the "legacy" configuration style and the new, more advanced one that utilizes the xDS "typed extension" mechanism.

Legacy configuration is done by setting the lb_policy enum field and any supporting configuration fields needed by the particular policy.

The new approach is to set the load_balancing_policy field that contains both the policy selection as well as any supporting configuration data. Providing a list of acceptable policies is also supported. Note that if this field is used, it will override any configuration set using the legacy approach. The new configuration approach is explained in detail in the Custom LB Policies gRFC

  • Field Details

  • Constructor Details

    • LoadBalancerConfigFactory

      LoadBalancerConfigFactory()
  • Method Details

    • newConfig

      static com.google.common.collect.ImmutableMap<String,?> newConfig(Cluster cluster, boolean enableLeastRequest) throws XdsResourceType.ResourceInvalidException
      Factory method for creating a new {link LoadBalancerConfigConverter} for a given xDS Cluster.
      Throws:
      XdsResourceType.ResourceInvalidException - If the Cluster has an invalid LB configuration.
    • buildRingHashConfig

      private static com.google.common.collect.ImmutableMap<String,?> buildRingHashConfig(Long minRingSize, Long maxRingSize)
      Builds a service config JSON object for the ring_hash load balancer config based on the given config values.
    • buildWrrConfig

      private static com.google.common.collect.ImmutableMap<String,?> buildWrrConfig(String blackoutPeriod, String weightExpirationPeriod, String oobReportingPeriod, Boolean enableOobLoadReport, String weightUpdatePeriod, Float errorUtilizationPenalty)
      Builds a service config JSON object for the weighted_round_robin load balancer config based on the given config values.
    • buildLeastRequestConfig

      private static com.google.common.collect.ImmutableMap<String,?> buildLeastRequestConfig(Integer choiceCount)
      Builds a service config JSON object for the least_request load balancer config based on the given config values.
    • buildWrrLocalityConfig

      private static com.google.common.collect.ImmutableMap<String,?> buildWrrLocalityConfig(com.google.common.collect.ImmutableMap<String,?> childConfig)
      Builds a service config JSON wrr_locality by wrapping another policy config.
    • buildRoundRobinConfig

      private static com.google.common.collect.ImmutableMap<String,?> buildRoundRobinConfig()
      Builds an empty service config JSON config object for round robin (it is not configurable).
    • buildPickFirstConfig

      private static com.google.common.collect.ImmutableMap<String,?> buildPickFirstConfig(boolean shuffleAddressList)
      Builds a service config JSON object for the pick_first load balancer config based on the given config values.