Registry router fixes (#1961)
* only cache routes if told to do so * Use roundrobin selector and retry in proxy * Update lookup to require service * Fix compile * Fix compile * Update * Update * rename query to lookup * Update router.go * Update
This commit is contained in:
parent
ef95569c61
commit
25a0aca7dd
60
dns.go
60
dns.go
@ -17,19 +17,17 @@ func NewRouter(opts ...router.Option) router.Router {
|
|||||||
if len(options.Network) == 0 {
|
if len(options.Network) == 0 {
|
||||||
options.Network = "micro"
|
options.Network = "micro"
|
||||||
}
|
}
|
||||||
return &dns{options, &table{options}}
|
return &dns{options}
|
||||||
}
|
}
|
||||||
|
|
||||||
type dns struct {
|
type dns struct {
|
||||||
options router.Options
|
options router.Options
|
||||||
table *table
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dns) Init(opts ...router.Option) error {
|
func (d *dns) Init(opts ...router.Option) error {
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&d.options)
|
o(&d.options)
|
||||||
}
|
}
|
||||||
d.table.options = d.options
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,50 +36,16 @@ func (d *dns) Options() router.Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *dns) Table() router.Table {
|
func (d *dns) Table() router.Table {
|
||||||
return d.table
|
return nil
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dns) Lookup(opts ...router.QueryOption) ([]router.Route, error) {
|
|
||||||
return d.table.Query(opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dns) Watch(opts ...router.WatchOption) (router.Watcher, error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dns) Close() error {
|
func (d *dns) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dns) String() string {
|
func (d *dns) Lookup(service string, opts ...router.LookupOption) ([]router.Route, error) {
|
||||||
return "dns"
|
|
||||||
}
|
|
||||||
|
|
||||||
type table struct {
|
|
||||||
options router.Options
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *table) Create(router.Route) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *table) Delete(router.Route) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *table) Update(router.Route) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *table) List() ([]router.Route, error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *table) Query(opts ...router.QueryOption) ([]router.Route, error) {
|
|
||||||
options := router.NewQuery(opts...)
|
|
||||||
|
|
||||||
// check to see if we have the port provided in the service, e.g. go-micro-srv-foo:8000
|
// check to see if we have the port provided in the service, e.g. go-micro-srv-foo:8000
|
||||||
host, port, err := net.SplitHostPort(options.Service)
|
host, port, err := net.SplitHostPort(service)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// lookup the service using A records
|
// lookup the service using A records
|
||||||
ips, err := net.LookupHost(host)
|
ips, err := net.LookupHost(host)
|
||||||
@ -95,7 +59,7 @@ func (t *table) Query(opts ...router.QueryOption) ([]router.Route, error) {
|
|||||||
result := make([]router.Route, len(ips))
|
result := make([]router.Route, len(ips))
|
||||||
for i, ip := range ips {
|
for i, ip := range ips {
|
||||||
result[i] = router.Route{
|
result[i] = router.Route{
|
||||||
Service: options.Service,
|
Service: service,
|
||||||
Address: fmt.Sprintf("%s:%d", ip, uint16(p)),
|
Address: fmt.Sprintf("%s:%d", ip, uint16(p)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,7 +68,7 @@ func (t *table) Query(opts ...router.QueryOption) ([]router.Route, error) {
|
|||||||
|
|
||||||
// we didn't get the port so we'll lookup the service using SRV records. If we can't lookup the
|
// we didn't get the port so we'll lookup the service using SRV records. If we can't lookup the
|
||||||
// service using the SRV record, we return the error.
|
// service using the SRV record, we return the error.
|
||||||
_, nodes, err := net.LookupSRV(options.Service, "tcp", t.options.Network)
|
_, nodes, err := net.LookupSRV(service, "tcp", d.options.Network)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -113,10 +77,18 @@ func (t *table) Query(opts ...router.QueryOption) ([]router.Route, error) {
|
|||||||
result := make([]router.Route, len(nodes))
|
result := make([]router.Route, len(nodes))
|
||||||
for i, n := range nodes {
|
for i, n := range nodes {
|
||||||
result[i] = router.Route{
|
result[i] = router.Route{
|
||||||
Service: options.Service,
|
Service: service,
|
||||||
Address: fmt.Sprintf("%s:%d", n.Target, n.Port),
|
Address: fmt.Sprintf("%s:%d", n.Target, n.Port),
|
||||||
Network: t.options.Network,
|
Network: d.options.Network,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *dns) Watch(opts ...router.WatchOption) (router.Watcher, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dns) String() string {
|
||||||
|
return "dns"
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user