Skip to content

Commit

Permalink
Merge pull request #19 from myENA/feature/serviceAddressAsNodeOnBlank
Browse files Browse the repository at this point in the history
Handle case where service address is empty coming from health endpoint
  • Loading branch information
dcarbone authored Jun 27, 2020
2 parents 3148f91 + 90c793f commit bbd905a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,22 @@ func (c *Client) PickServiceMultipleTags(service string, tags []string, passingO
return nil, nil, err
}
svcLen := len(svcs)
var svc *api.ServiceEntry
switch svcLen {
case 0:
return nil, qm, nil
case 1:
return svcs[0], qm, nil
svc = svcs[0]
default:
return svcs[rand.Intn(svcLen)], qm, nil
svc = svcs[rand.Intn(svcLen)]
}

// Handle case where service address is blank, default to node address
if svc.Service.Address == "" {
svc.Service.Address = svc.Node.Address
}

return svc, qm, nil
}

// PickService will attempt to locate any registered service with a name + tag combination and return one at random from
Expand Down Expand Up @@ -303,6 +311,9 @@ OUTER:
}

}
if se.Service.Address == "" {
se.Service.Address = se.Node.Address
}
retv = append(retv, se)
}

Expand Down

0 comments on commit bbd905a

Please sign in to comment.