Documentation ¶
Overview ¶
Package balancerconfig contains utility functions to build balancer config. The built config will generate a tree of balancers with priority, cluster_impl, weighted_target, lrs, and roundrobin.
This is in a subpackage of cluster_resolver so that it can be used by the EDS balancer. Eventually we will delete the EDS balancer, and replace it with cluster_resolver, then we can move the functions to package cluster_resolver, and unexport them.
TODO: move and unexport. Read above.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildPriorityConfigJSON ¶
func BuildPriorityConfigJSON(priorities []PriorityConfig, endpointPickingPolicy *internalserviceconfig.BalancerConfig) ([]byte, []resolver.Address, error)
BuildPriorityConfigJSON builds balancer config for the passed in priorities.
The built tree of balancers (see test for the output struct).
┌────────┐ │priority│ └┬──────┬┘ │ │ ┌───────────▼┐ ┌▼───────────┐ │cluster_impl│ │cluster_impl│ └─┬──────────┘ └──────────┬─┘ │ │ ┌──────────────▼─┐ ┌─▼──────────────┐ │locality_picking│ │locality_picking│ └┬──────────────┬┘ └┬──────────────┬┘ │ │ │ │ ┌─▼─┐ ┌─▼─┐ ┌─▼─┐ ┌─▼─┐ │LRS│ │LRS│ │LRS│ │LRS│ └─┬─┘ └─┬─┘ └─┬─┘ └─┬─┘ │ │ │ │
┌──────────▼─────┐ ┌─────▼──────────┐ ┌──────────▼─────┐ ┌─────▼──────────┐ │endpoint_picking│ │endpoint_picking│ │endpoint_picking│ │endpoint_picking│ └────────────────┘ └────────────────┘ └────────────────┘ └────────────────┘
If endpointPickingPolicy is nil, roundrobin will be used.
Custom locality picking policy isn't support, and weighted_target is always used.
TODO: support setting locality picking policy, and add a parameter for locality picking policy.
Types ¶
type DiscoveryMechanism ¶
type DiscoveryMechanism struct { // Cluster is the cluster name. Cluster string `json:"cluster,omitempty"` // LoadReportingServerName is the LRS server to send load reports to. If // not present, load reporting will be disabled. If set to the empty string, // load reporting will be sent to the same server that we obtained CDS data // from. LoadReportingServerName *string `json:"lrsLoadReportingServerName,omitempty"` // MaxConcurrentRequests is the maximum number of outstanding requests can // be made to the upstream cluster. Default is 1024. MaxConcurrentRequests *uint32 `json:"maxConcurrentRequests,omitempty"` // Type is the discovery mechanism type. Type DiscoveryMechanismType `json:"type,omitempty"` // EDSServiceName is the EDS service name, as returned in CDS. May be unset // if not specified in CDS. For type EDS only. // // This is used for EDS watch if set. If unset, Cluster is used for EDS // watch. EDSServiceName string `json:"edsServiceName,omitempty"` }
DiscoveryMechanism is the discovery mechanism, can be either EDS or DNS.
For DNS, the ClientConn target will be used for name resolution.
For EDS, if EDSServiceName is not empty, it will be used for watching. If EDSServiceName is empty, Cluster will be used.
type DiscoveryMechanismType ¶
type DiscoveryMechanismType int
DiscoveryMechanismType is the type of discovery mechanism.
const ( // DiscoveryMechanismTypeEDS is eds. DiscoveryMechanismTypeEDS DiscoveryMechanismType = iota // `json:EDS` // DiscoveryMechanismTypeLogicalDNS is DNS. DiscoveryMechanismTypeLogicalDNS // `json:LOGICAL_DNS` )
func (*DiscoveryMechanismType) MarshalJSON ¶
func (t *DiscoveryMechanismType) MarshalJSON() ([]byte, error)
MarshalJSON marshals a DiscoveryMechanismType to a quoted json string.
This is necessary to handle enum (as strings) from JSON.
func (*DiscoveryMechanismType) UnmarshalJSON ¶
func (t *DiscoveryMechanismType) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals a quoted json string to the DiscoveryMechanismType.
type PriorityConfig ¶
type PriorityConfig struct { Mechanism DiscoveryMechanism // EDSResp is set only if type is EDS. EDSResp xdsclient.EndpointsUpdate // Addresses is set only if type is DNS. Addresses []string }
PriorityConfig is config for one priority. For example, if there an EDS and a DNS, the priority list will be [priorityConfig{EDS}, PriorityConfig{DNS}].
Each PriorityConfig corresponds to one discovery mechanism from the LBConfig generated by the CDS balancer. The CDS balancer resolves the cluster name to an ordered list of discovery mechanisms (if the top cluster is an aggregated cluster), one for each underlying cluster.