mirror of
https://github.com/coredns/coredns.git
synced 2025-12-05 09:55:10 -05:00
@@ -71,20 +71,20 @@ func (a *assignment) clusters() []string {
|
||||
}
|
||||
|
||||
// Select selects a endpoint from cluster load assignments, using weighted random selection. It only selects endpoints that are reporting healthy.
|
||||
func (a *assignment) Select(cluster string, locality []Locality, ignore bool) (*SocketAddress, bool) {
|
||||
func (a *assignment) Select(cluster string, ignore bool) (*SocketAddress, bool) {
|
||||
cla := a.ClusterLoadAssignment(cluster)
|
||||
if cla == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
total := 0
|
||||
weight := 0
|
||||
healthy := 0
|
||||
for _, ep := range cla.Endpoints {
|
||||
for _, lb := range ep.GetLbEndpoints() {
|
||||
if !ignore && lb.GetHealthStatus() != corepb.HealthStatus_HEALTHY {
|
||||
continue
|
||||
}
|
||||
total += int(lb.GetLoadBalancingWeight().GetValue())
|
||||
weight += int(lb.GetLoadBalancingWeight().GetValue())
|
||||
healthy++
|
||||
}
|
||||
}
|
||||
@@ -92,8 +92,8 @@ func (a *assignment) Select(cluster string, locality []Locality, ignore bool) (*
|
||||
return nil, true
|
||||
}
|
||||
|
||||
if total == 0 {
|
||||
// all weights are 0, randomly select one of the endpoints.
|
||||
// all weights are 0, randomly select one of the endpoints,
|
||||
if weight == 0 {
|
||||
r := rand.Intn(healthy)
|
||||
i := 0
|
||||
for _, ep := range cla.Endpoints {
|
||||
@@ -110,7 +110,7 @@ func (a *assignment) Select(cluster string, locality []Locality, ignore bool) (*
|
||||
return nil, true
|
||||
}
|
||||
|
||||
r := rand.Intn(total) + 1
|
||||
r := rand.Intn(healthy) + 1
|
||||
for _, ep := range cla.Endpoints {
|
||||
for _, lb := range ep.GetLbEndpoints() {
|
||||
if !ignore && lb.GetHealthStatus() != corepb.HealthStatus_HEALTHY {
|
||||
@@ -126,7 +126,7 @@ func (a *assignment) Select(cluster string, locality []Locality, ignore bool) (*
|
||||
}
|
||||
|
||||
// All returns all healthy endpoints.
|
||||
func (a *assignment) All(cluster string, locality []Locality, ignore bool) ([]*SocketAddress, bool) {
|
||||
func (a *assignment) All(cluster string, ignore bool) ([]*SocketAddress, bool) {
|
||||
cla := a.ClusterLoadAssignment(cluster)
|
||||
if cla == nil {
|
||||
return nil, false
|
||||
|
||||
@@ -199,22 +199,23 @@ func (c *Client) receive(stream adsStream) error {
|
||||
|
||||
// Select returns an address that is deemed to be the correct one for this cluster. The returned
|
||||
// boolean indicates if the cluster exists.
|
||||
func (c *Client) Select(cluster string, locality []Locality, ignore bool) (*SocketAddress, bool) {
|
||||
func (c *Client) Select(cluster string, ignore bool) (*SocketAddress, bool) {
|
||||
if cluster == "" {
|
||||
return nil, false
|
||||
}
|
||||
return c.assignments.Select(cluster, locality, ignore)
|
||||
return c.assignments.Select(cluster, ignore)
|
||||
}
|
||||
|
||||
// All returns all endpoints.
|
||||
func (c *Client) All(cluster string, locality []Locality, ignore bool) ([]*SocketAddress, bool) {
|
||||
func (c *Client) All(cluster string, ignore bool) ([]*SocketAddress, bool) {
|
||||
if cluster == "" {
|
||||
return nil, false
|
||||
}
|
||||
return c.assignments.All(cluster, locality, ignore)
|
||||
return c.assignments.All(cluster, ignore)
|
||||
}
|
||||
|
||||
// Locality holds the locality for this server. It contains a Region, Zone and SubZone.
|
||||
// Currently this is not used.
|
||||
type Locality struct {
|
||||
Region string
|
||||
Zone string
|
||||
|
||||
@@ -18,6 +18,6 @@ var (
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "traffic",
|
||||
Name: "endpoints_tracked",
|
||||
Help: "Gauge of all tracked endpoints.",
|
||||
Help: "Gauge of tracked endpoints.",
|
||||
})
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user