kitex-contrib / registry-etcd

Apache License 2.0
20 stars 24 forks source link

etcd_registry add tags to custom etcd address #5

Closed dashengli closed 2 years ago

dashengli commented 2 years ago

Is your feature request related to a problem? Please describe.

in docker , server use net.Addr with (0.0.0.0:8999) or (127.0.0.1:8999)

{"network":"tcp","address":"[::]:8999","weight":10,"tags":null}

client can't to connect [::]:8999 or 127.0.0.1:8999

Describe the solution you'd like

func (e *etcdRegistry) register(info *registry.Info, leaseID clientv3.LeaseID) error {
    address := info.Addr.String()
    if info.Tags != nil {
        addr, ok := info.Tags["addr"]
        if ok {
            address = addr
        }
    }
    val, err := json.Marshal(&instanceInfo{
        Network: info.Addr.Network(),
        Address: address,
        Weight:  info.Weight,
        Tags:    info.Tags,
    })
    if err != nil {
        return err
    }
    ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
    defer cancel()
    _, err = e.etcdClient.Put(ctx, serviceKey(info.ServiceName, address), string(val), clientv3.WithLease(leaseID))
    return err
}
lizhemingi commented 2 years ago

I believe it's not a good idea to get server address from tag.

When kitex call Register to register an instance, the real address which server bind would be set in registry.Info.Addr, check https://github.com/cloudwego/kitex/blob/157c1c6813c0c66a5360f2ff7fec190470693071/server/server.go#L380

Could you describe the step to reproduce the problem of "client can't connect to [::]:8999 or 127.0.0.1:8999"

(Maybe forgot to use --network host or -p 8999:8999 when run docker ?)

dashengli commented 2 years ago
  1. Could you describe the step to reproduce the problem of "client can't connect to [::]:8999 or 127.0.0.1:8999" First sorry port 8999 to 8877. Like this:
    
        address := fmt.Sprintf("%s:%d", "0.0.0.0", 8877)
    addr, _ := net.ResolveTCPAddr("tcp", address)
    opts := []server.Option{
        server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: "sName"}), //server name
        server.WithServiceAddr(addr),
        server.WithRegistry(r), // registry

Other computers can connect this server by `192.168.1.11:8877`
I think register address is 
![image](https://user-images.githubusercontent.com/22268505/157174923-4cddde79-cadd-400b-9598-3960edd8e5cf.png)

not 
![image](https://user-images.githubusercontent.com/22268505/157174564-60ef9dd5-5b6b-4851-9fc8-d8b03d45ed78.png)

This doesn't seem to be a problem with the framework [registry-etcd](https://github.com/kitex-contrib/registry-etcd/issues/5). 
This seems to be my own network design problem.