sozu icon indicating copy to clipboard operation
sozu copied to clipboard

Add possibility to resolve domains in the backend definition

Open PierreZ opened this issue 7 years ago • 6 comments

Hi!

I was playing a bit with sozu yesterday. I had a configuration file like this:

#...
[applications]
[applications.ingress]
hostname   = "sozu"
path_begin = "/api/v0/update"
backends  = [ "ingress:8080" ]

[applications.egress]
hostname   = "sozu"
path_begin = "/api/v0/exec"
backends  = [ "egress:8080" ]

Here's the log:

sozu | 2018-02-15T15:05:08Z 51870899701997 1 MASTER INFO     starting up
sozu | 2018-02-15T15:05:08Z 51870922854097 1 MASTER INFO     0 launching worker
sozu | 2018-02-15T15:05:08Z 51870923186297 1 MASTER INFO     0 worker launched: 6
sozu | 7 send empty
sozu | 2018-02-15T15:05:08Z 51870923594997 1 MASTER INFO     sent listeners from master: Ok(())
sozu | 2018-02-15T15:05:08Z 51870926268397 1 MASTER INFO     1 launching worker
sozu | 2018-02-15T15:05:08Z 51870926630997 1 MASTER INFO     1 worker launched: 7
sozu | 9 send empty
sozu | 2018-02-15T15:05:08Z 51870927136197 1 MASTER INFO     sent listeners from master: Ok(())
sozu | 2018-02-15T15:05:08Z 51870927216397 1 MASTER INFO     created workers: [Worker { id: 0, run_state: Running }, Worker { id: 1, run_state: Running }]
sozu | 2018-02-15T15:05:08Z 51870927462697 1 MASTER ERROR    could not get saved state path: No such file or directory (os error 2)
sozu | 2018-02-15T15:05:08Z 51870939343597 7 WRK-01 INFO     worker 1 starting...
sozu | 2018-02-15T15:05:08Z 51870945467597 6 WRK-00 INFO     worker 0 starting...
sozu | 2018-02-15T15:05:08Z 51871060998497 7 WRK-01 INFO     will try to receive listeners
sozu | 10 received :(35, 0)
sozu | 2018-02-15T15:05:08Z 51871061689697 7 WRK-01 INFO     received listeners: Some(
sozu |     Listeners {
sozu |         http: None,
sozu |         tls: None,
sozu |         tcp: []
sozu |     }
sozu | )
sozu | 2018-02-15T15:05:08Z 51871062593397 7 WRK-01 ERROR    Couldn't parse address of HTTP proxy: invalid IP address syntax
sozu | 2018-02-15T15:05:08Z 51871064190197 1 MASTER ERROR    could not parse address: egress:8080
sozu | 2018-02-15T15:05:08Z 51871071132097 7 WRK-01 INFO     1 starting event loop
sozu | 2018-02-15T15:05:08Z 51871088278097 1 MASTER INFO     waiting for configuration client connections

As I was playing with sozu with docker-compose using links, I don't have to use IPs. From what I see in the log could not parse address: egress:8080 doesn't seems to be parsed into an IPv4 address.

Am i right? If so, is it possible to add the possibility to resolve domain using /etc/hosts file?

As I am always looking for new challenges, if it's an easy PR, I would love to give it a try!

PierreZ avatar Feb 15 '18 15:02 PierreZ

Hello,

The feature is a bit tricky, because we must think about where and how often the name check happens. The various solutions:

  • the master checks the domain regularly and updates the configuration of the workers. A bit complex to implement but very few DNS requests (not all usages of this feature would rely on /etc/hosts) and a small state to keep around
  • the worker checks the domain before connecting to the backend. Easy to do, but potentially lots of DNS requests. We can have a cache, but then each worker would end up with their own cache (or rely on the OS's DNS cache?)

In the configuration messages, do we make an enum domain/IP to identify a backend?

The lookup_host feature in libstd is only available on nightly. Or do we embed a DNS client in sozu? TrustDNS is nicely designed.

Geal avatar Feb 15 '18 16:02 Geal

we should do this now

Geal avatar Jul 29 '21 10:07 Geal