in dp_check/dp_check.go [876:919]
func processEdsResponse(edsReply *v3discoverypb.DiscoveryResponse) ([]string, error) {
if len(edsReply.GetResources()) != 1 {
if len(edsReply.GetResources()) == 0 {
return []string{}, fmt.Errorf("no cluster_load_assignment resource received in EDS response")
}
return []string{}, fmt.Errorf("expect to receive only 1 cluster_load_assigment resource in EDS response, but received %v", len(edsReply.GetResources()))
}
resource := edsReply.GetResources()[0]
clusterLoadAssignment := &v3endpointpb.ClusterLoadAssignment{}
if err := proto.Unmarshal(resource.GetValue(), clusterLoadAssignment); err != nil {
return []string{}, fmt.Errorf("failed to unmarshal cluster_load_assigement resource from EDS response: %v", err)
}
var results []string
countPriorityZero, countPriorityOne, countPriorityOthers := 0, 0, 0
numBackendInPriorityZero, numBackendInPriorityOne := 0, 0
for _, endpoint := range clusterLoadAssignment.GetEndpoints() {
switch endpoint.GetPriority() {
case 0:
countPriorityZero++
numBackendInPriorityZero += len(endpoint.GetLbEndpoints())
for _, lbendpoint := range endpoint.GetLbEndpoints() {
endpoint := lbendpoint.GetEndpoint().GetAddress().GetSocketAddress()
results = append(results, net.JoinHostPort(endpoint.GetAddress(), fmt.Sprint(endpoint.GetPortValue())))
}
case 1:
countPriorityOne++
numBackendInPriorityOne += len(endpoint.GetLbEndpoints())
default:
countPriorityOthers++
}
}
if countPriorityZero == 0 {
return []string{}, fmt.Errorf("expected to receive at least 1 endpoint with priority 0, but received %v", countPriorityZero)
}
if countPriorityOthers != 0 {
return []string{}, fmt.Errorf("received endpoint whose priority is not 0 or 1")
}
if results == nil {
return []string{}, fmt.Errorf("no endpoints received in EDS response")
}
infoLog.Printf("Received %v backends in the primary cluster", numBackendInPriorityZero)
infoLog.Printf("Received %v backends in the secondary cluster", numBackendInPriorityOne)
return results, nil
}