Add support for connecting to nodes by their hostname#20
Conversation
We'll support connecting to hostnames soon too
|
Thank you for the PR! Given address_type |
05b80c5 to
d7ed718
Compare
|
@josevalim I've updated the implementation and added One could also think of keeping |
|
Hrm... sorry for the back and forth. What if we do |
All good! 😉 It wasn't my plan to come with THE implementation. That's why the PR is still marked as a draft, to figure out what is the best way to go.
Isn't this the same as what is pushed currently, just with I am fine with using tuples instead of atoms. In the end, both ways are the same. |
|
Yes, they are the same, but I think it is more elegant to say :srv is shortcut for {:srv, :ips} then a completely different atom. It also makes it clear they are both using the same mechanism (srv) but in different ways. |
d7ed718 to
31af08a
Compare
|
Pushed an update for using tuples instead of the atoms. |
| def lookup(query, {:srv, :hostnames}), do: lookup_by_name(query, :srv) | ||
| def lookup(query, {:srv, :ips}), do: lookup(query, :srv) | ||
|
|
||
| def lookup(query, :srv) do |
There was a problem hiding this comment.
Let's normalize :srv into {:srv, :ips} during initialization, so dns_cluster/resolver.ex doesn't have to worry about all formats. I guess that's a backwards incompatible change, but they need to update anyway to support hostnames (and we are before v1.0)? Then we can ship it!
There was a problem hiding this comment.
This way you would break custom resolver implementations as they would then also receive 🤔{:srv, :ips} instead of the expected :srv
Okay, I only read half of your answer before adding this comment 😅
31af08a to
7bcfbd7
Compare
|
Looks good to me! |
|
@josevalim Would it be okay to add a mocking library (mock, mox, mimic, ...) to mock the calls for |
|
mimic is fine for unit testing! |
|
Another option is to trim down the resolver interface to be What do you think? In fact, I believe I would prefer this approach. |
|
@josevalim I somehow have the feeling that this becomes more and more a refactoring 😅 Maybe we first make it work (with mocking) and rework it afterwards. WDYT? |
|
@janpieper or maybe we refactor first and then we add the feature, given the feature itself is straight-forward? Otherwise it feels backwards to add the mocking library simply to remove it after? 🤔 |
This PR adds a new option
address_typewhich can be:ip(default) or:hostnameto control whether to connect to other nodes via their ip address or hostname.The resolver
lookupfunction changed from 2-arity to 3-arity, because we now also need to pass the newaddress_typeto it.To not break backwards compatibility for users with custom resolver implementations (e.g. custom dns servers, DB lookup), the implementation calls
lookup/3if available, callslookup/3whenaddress_type == :hostnameand otherwise falls back tolookup/2.Setup
Resolving
TODOs
Fixes #14