Skip to content

support srv cluster queries #16

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

nduitz
Copy link

@nduitz nduitz commented Jun 12, 2025

Hey there.
Due to the infrastracture setup of one of our projects we can only use srv dns records.
This addition should support them besides A / AAAA records.

Let me know if you need further adjustments :)

@hkrutzer
Copy link

FYI: #8

@nduitz
Copy link
Author

nduitz commented Jun 12, 2025

FYI: #8

Oh, thanks totally missed that issue. I think I searched for 'svr' instead of 'srv'. I made that mistake a couple of times already today :D

@nduitz
Copy link
Author

nduitz commented Jun 12, 2025

I added a second commit to make the dns_rr_type configurable

Comment on lines 74 to 80
|> Enum.map(fn {_prio, _weight, _port, host_name} ->
case :inet.gethostbyname(host_name) do
{:ok, hostent(h_addr_list: addr_list)} -> addr_list
{:error, _} -> []
end
end)
|> List.flatten()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do flat_map

if valid_query?(query) do
with(
{:valid_query?, true} <- {:valid_query?, valid_query?(query)},
{:valid_rr_types?, true} <- {:valid_rr_types?, valid_rr_types?(dns_rr_types)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's write those as regular conditions instead:

if not valid_query?(query) do
  raise ...
end

if not valid_rr_type?(...) do
  raise ...
end

This way there is no need for with and tagged tuples.

max_concurrency: max(1, length(ips)),
timeout: timeout
)
|> Stream.run()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change, please revert it to keep history clean.

Comment on lines 241 to 242
MapSet.new(dns_rr_types)
|> MapSet.subset?(MapSet.new(@valid_rr_types))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MapSet.new(dns_rr_types)
|> MapSet.subset?(MapSet.new(@valid_rr_types))
Enum.all?(dns_rr_types, & &1 in @valid_rr_types)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or:

Suggested change
MapSet.new(dns_rr_types)
|> MapSet.subset?(MapSet.new(@valid_rr_types))
(dns_rr_types -- @valid_rr_types) == []

@nduitz nduitz force-pushed the support-srv-dns-queries branch from d1c8682 to eb703dd Compare June 13, 2025 07:21
@nduitz
Copy link
Author

nduitz commented Jun 13, 2025

Thanks for your feedback. I removed the unrelated change with a fix up so it's gone :)

{:error, _} -> []
end
end)
|> Enum.filter(& &1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can an entry in h_addr_list ever be nil or false? :) Or can we remove this filter?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah true, thanks I had the error case return nil before. That filter does not make sense anymore.

@@ -70,6 +91,8 @@ defmodule DNSCluster do
`"myapp.internal"` or `["foo.internal", "bar.internal"]`. If the basename
differs between nodes, a tuple of `{basename, query}` can be provided as well.
The value `:ignore` can be used to ignore starting the DNSCluster.
* `:dns_rr_types` - the resource records types that are used for node discovery.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we should call it resource_types?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially because dns is somewhat implied? and rr may not be clear enough

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intention was to mirror the name of the type in erlang:
https://www.erlang.org/doc/apps/kernel/inet_res.html#t:dns_rr_type/0

But I am happy to change the name to resource_types

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that as an implementation detail, I think something higher level would be better! Thank you!

Copy link
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two final nits and we are good to go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants