Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]How to specify the service registration endpoint when binding a server to multiple network interfaces? #2902

Closed
youzhixiaomutou opened this issue Jul 4, 2023 · 8 comments · Fixed by #2904
Labels
feature question Further information is requested

Comments

@youzhixiaomutou
Copy link
Contributor

How to listen on 0.0.0.0 for a service while specifying a custom registration endpoint in the service registry? Currently, there doesn't seem to be a direct way.

@youzhixiaomutou youzhixiaomutou added the question Further information is requested label Jul 4, 2023
@shenqidebaozi
Copy link
Member

// Endpoint with service endpoint.
func Endpoint(endpoints ...*url.URL) Option {
	return func(o *options) { o.endpoints = endpoints }
}

@youzhixiaomutou
Copy link
Contributor Author

Using Endpoint() With kratos.New()? If I start multiple servers in kratos.Server(), I have to explicitly specify the endpoint for each server, and I also need to manually convert 0.0.0.0:port to the actual ip:port. Would it be a solution to prioritize using the internal IP for service registration when specifying 0.0.0.0:port?

@shenqidebaozi
Copy link
Member

The current design of HTTP/gRPC transport is to use private IP as the endpoint value, and it is unclear what exactly you want to do. If you want to control the registered values yourself, you can use the endpoint configuration item to override them yourself

func (s *Server) listenAndEndpoint() error {

@shenqidebaozi
Copy link
Member

When you listen to port 0.0.0.0, the private IP of the service will be parsed and registered with the registry. Is the expression of your issue question incorrect.

It is recommended to conduct actual testing. If there are any issues, please provide the minimum replication environment or describe the relevant information clearly

@youzhixiaomutou
Copy link
Contributor Author

My goal is to prioritize registering the internal IP when configuring 0.0.0.0, but in reality, it doesn't seem to work that way. This issue is difficult to reproduce. Our production services are deployed on physical machines with one network card bound to the internal network and another network card bound to the external network. According to the Extract() method in internal/host/host.go, it seems to iterate through all network cards that meet the conditions and ultimately return the last one, making the actual registered IP unpredictable. Is my understanding correct?

return net.JoinHostPort(ips[len(ips)-1].String(), port), nil

I will also try to provide a minimal replication environment.

@youzhixiaomutou
Copy link
Contributor Author

I think Extract() code should include a condition to return early if it is an internal IP.

@shenqidebaozi
Copy link
Member

It is difficult to coexist with the needs of different users. It is recommended to use endpoint to handle the address registered to the registration center on your own, or consider changing this part to an interface for users to implement on their own

@youzhixiaomutou
Copy link
Contributor Author

Thanks a lot for the answer. I can handle this part of the code myself (although I believe it deviates from the original design in terms of the Extract() method).
There is an another question. Can transport/server.go expose a function option:

endpoint *url.URL

func Endpoint(endpoint *url.URL) ServerOption {
   return func(s *Server) {
   	s.endpoint = endpoint
   }
}

that allows me to specify the endpoint when defining the server, instead of manually specifying it for each server when creating a new app? I believe this implementation would be more elegant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants