in dp_check/dp_check.go [473:516]
func resolveBackends(balancerAddress string, balancerHostname string, srvQueriesSucceeded bool) ([]string, error) {
var addressFamily string
var matchAddrFamily func(net.IP) bool
balancerHost, _, err := net.SplitHostPort(balancerAddress)
if err != nil {
return nil, fmt.Errorf("failed to split balancer address: %v into host and port components", balancerAddress)
}
balancerIP := net.ParseIP(balancerHost)
if balancerIP == nil {
return nil, fmt.Errorf("failed to parse IP component of balancer address: %v", balancerAddress)
}
if balancerIP.To4() != nil {
addressFamily = "IPv4"
matchAddrFamily = func(ip net.IP) bool { return ip.To4() != nil }
} else if balancerIP.To16() != nil {
addressFamily = "IPv6"
matchAddrFamily = func(ip net.IP) bool { return ip.To16() != nil }
} else {
return nil, fmt.Errorf("balancer IP: %v not recognized as IPv4 or IPv6", balancerIP)
}
var backends []string
infoLog.Printf("Find %v backend addresses for %v by making a \"BalanceLoad\" RPC to the load balancers...", addressFamily, *service)
if backends, err = getBackendAddrsFromGrpclb(balancerAddress, balancerHostname, srvQueriesSucceeded); err != nil {
return nil, fmt.Errorf(`Failed to get any %v backend VIPs from the load balancer because: %v.
Consider running this binary under environment variables:
* GRPC_GO_LOG_VERBOSITY_LEVEL=99
* GRPC_GO_LOG_SEVERITY_LEVEL=INFO
in order to get more debug logs from the grpc library (which was just used when reaching out to the load balancer)`, addressFamily, err)
}
if !srvQueriesSucceeded {
infoLog.Printf(`Because we received an assignment from the load balancer, it's unexpected that earlier SRV queries failed. However, one possible reason is that the service is in the process of denying some attributes of this specific VM (for example the VPC network project number of this VM's primary network interface, the VM project number, or the current region or zone we're running in), and that the load balancer will start to respond to our BalanceLoad RPCs for %s with FallbackResponse messages soon.`, *service)
}
for _, addr := range backends {
infoLog.Printf("Found %v backend address:|%v|", addressFamily, addr)
ipStr, _, err := net.SplitHostPort(addr)
if err != nil {
return nil, fmt.Errorf("failed to split %v into ip and port components: %v", addr, err)
}
if ip := net.ParseIP(ipStr); ip == nil || !matchAddrFamily(ip) {
return nil, fmt.Errorf("ip %v from address %v was not recognized as a valid %v address", ipStr, addr, addressFamily)
}
}
return backends, nil
}