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

fix(DNS): prefer SRV in service discovery #4992

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apisix/discovery/dns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function _M.init_worker()
hosts = {},
resolvConf = {},
nameservers = servers,
order = {"last", "A", "AAAA", "SRV", "CNAME"},
order = {"last", "SRV", "A", "AAAA", "CNAME"},
}

local client, err = core.dns_client.new(opts)
Expand Down
4 changes: 4 additions & 0 deletions t/coredns/db.test.local
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ split-weight.srv 86400 IN SRV 10 0 1980 C

priority.srv 86400 IN SRV 10 60 1979 A
priority.srv 86400 IN SRV 20 60 1980 B

; a domain has both SRV & A records
srv-a 86400 IN SRV 10 60 1980 A
srv-a IN A 127.0.0.1
4 changes: 4 additions & 0 deletions t/discovery/dns/mix.t
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ upstreams:
end
end
-- It is expected to have 5 DNS queries
-- the first turn: one for global resolver & two for discovery (SRV, then A)
-- the second turn: each one for both global resolver & discovery
if i < 2 then
ngx.sleep(1.1)
end
Expand All @@ -125,3 +128,4 @@ connect to 127.0.0.1:1053
connect to 127.0.0.1:1053
connect to 127.0.0.1:1053
connect to 127.0.0.1:1053
connect to 127.0.0.1:1053
14 changes: 14 additions & 0 deletions t/discovery/dns/sanity.t
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,17 @@ qr/proxy request to \S+/
--- grep_error_log_out
proxy request to 127.0.0.1:1979
proxy request to 127.0.0.2:1980
=== TEST 14: prefer SRV than A
--- apisix_yaml
upstreams:
- service_name: "srv-a.test.local"
discovery_type: dns
type: roundrobin
id: 1
--- error_log
proxy request to 127.0.0.1:1980
--- response_body
hello world