You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/09/07 02:53:30 UTC

[apisix] branch master updated: fix(DNS): prefer SRV in service discovery (#4992)

This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 2f45642  fix(DNS): prefer SRV in service discovery (#4992)
2f45642 is described below

commit 2f4564218c8b4daa7dda990065ca7fd81f0ff23a
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Tue Sep 7 10:53:23 2021 +0800

    fix(DNS): prefer SRV in service discovery (#4992)
    
    Fix #4986
    
    Signed-off-by: spacewander <sp...@gmail.com>
---
 apisix/discovery/dns.lua |  2 +-
 t/coredns/db.test.local  |  4 ++++
 t/discovery/dns/mix.t    |  4 ++++
 t/discovery/dns/sanity.t | 14 ++++++++++++++
 4 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/apisix/discovery/dns.lua b/apisix/discovery/dns.lua
index e599cf6..45d7141 100644
--- a/apisix/discovery/dns.lua
+++ b/apisix/discovery/dns.lua
@@ -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)
diff --git a/t/coredns/db.test.local b/t/coredns/db.test.local
index 27296bf..094b73a 100644
--- a/t/coredns/db.test.local
+++ b/t/coredns/db.test.local
@@ -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
diff --git a/t/discovery/dns/mix.t b/t/discovery/dns/mix.t
index 46c1e16..5308f4b 100644
--- a/t/discovery/dns/mix.t
+++ b/t/discovery/dns/mix.t
@@ -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
@@ -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
diff --git a/t/discovery/dns/sanity.t b/t/discovery/dns/sanity.t
index 9e4ed2a..4aec648 100644
--- a/t/discovery/dns/sanity.t
+++ b/t/discovery/dns/sanity.t
@@ -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