fabiolb / fabio

Consul Load-Balancing made simple
https://fabiolb.net
MIT License
7.25k stars 621 forks source link

TCP Dynamic Proxy route without specifying exact IP? #797

Closed evandam closed 3 years ago

evandam commented 3 years ago

I'm using tcp-dynamic proxy with proxy.addr = :9999,0.0.0.0:0;proto=tcp-dynamic;refresh=5s but wondering if there's a way to use routes without hardcoding an IP address if I understand correctly?

For example, I have a service with the following tags:

fabio-0.0.0.0:6379 proto=tcp
fabio-:6379 proto=tcp
fabio-mydnsrecord:6379 proto=tcp

The routes get added successfully, but they all result in "No route found" logs.

Oct 30 18:07:52 default-ubuntu-1804 fabio[19887]: 2020/10/30 18:07:52 [WARN] No route for 192.168.33.33:6379

Is it possible to be able to resolve a hostname instead of use an IP address, or route based on port-only instead of ip:port?

Thanks in advance!

nathanejohnson commented 3 years ago

This is not currently possible because currently routes are matched based on the host, and no wildcards are currently supported. It might be feasible to come up with a custom lookup function just for tcp dynamic, but I'm not sure there is a general enough use case to support it. Also, since with tcp fabio has no idea which dns name may have been used to connect there really isn't a clean way to match it on hostname either. With http or https we have other ways of determining that, but not with TCP.

How are you spinning up your environment?

nathanejohnson commented 3 years ago

So after digging in it's not a terribly difficult change to make (~ 4 lines), but I'm not really sure how generally useful this is. The change involved doing a lookup on the existing full local address with port, and then falling back to a route based on a target name which just used the local port that was connected to. I'll have to think this over, I may put together a small PR to get some eyes on it. I don't personally use the tcp dynamic feature.