Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.

Commit a4a5cbd

Browse files
committed
Change the way DNS queries are handled in monitor
This is to accommodate to nixon-dns sometimes returning “more than one answer” when returning the A records.
1 parent 0a74ef1 commit a4a5cbd

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

lua/concurredis.lua

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ local save_host_and_port_in_cache = function(host, port)
5151
end
5252

5353
local make_dns_query = function(r, name, query_type)
54-
ngx.log(ngx.INFO, ("Performing DNS query for %s"):format(name))
54+
ngx.log(ngx.INFO, ("Performing DNS query of type %s for %s"):format(query_type, name))
5555
local answers = assert(r:query(name, {qtype = query_type}))
5656

5757
if answers.errcode then
@@ -62,9 +62,7 @@ local make_dns_query = function(r, name, query_type)
6262
error(("Name server %s resolving name %s with query type %s returned no answers"):format(REDIS_NAME_SERVER, name, query_type))
6363
end
6464

65-
ngx.log(ngx.INFO, ("Got DNS answer: %s"):format(inspect(answers)))
66-
67-
return answers[1]
65+
return answers
6866
end
6967

7068
local get_connection_from_cache = function()
@@ -91,7 +89,7 @@ end
9189
local get_connection_from_dns = function()
9290
if not REDIS_NAME_SERVER or not REDIS_NAME then return end
9391

94-
ngx.log(ngx.INFO, ("Resolving name %s with %s"):format(REDIS_NAME, REDIS_NAME_SERVER))
92+
ngx.log(ngx.INFO, ("Resolving name %s with server %s"):format(REDIS_NAME, REDIS_NAME_SERVER))
9593

9694
local red, host, port
9795

@@ -102,13 +100,19 @@ local get_connection_from_dns = function()
102100
}))
103101

104102
lock.around('concurredis.resolve', function()
105-
local answer_srv = make_dns_query(r, REDIS_NAME, r.TYPE_SRV)
106-
ngx.log(ngx.INFO, ("Got target %s from DNS SRV request"):format(answer_srv.target))
103+
local answer_srv = make_dns_query(r, REDIS_NAME, r.TYPE_SRV)[1]
104+
port = answer_srv.port
107105

108-
local answer_a = make_dns_query(r, answer_srv.target, r.TYPE_A)
109-
ngx.log(ngx.INFO, ("Got ip %s from DNS A request"):format(answer_srv.address))
106+
ngx.log(ngx.INFO, ("Got target %s and port %s from DNS SRV request"):format(answer_srv.target, port))
110107

111-
host, port = answer_a.address, answer_srv.port
108+
local answer_a = make_dns_query(r, answer_srv.target, r.TYPE_A)
109+
for i=1,#answer_a do
110+
if answer_a[i].address then
111+
host = answer_a[i].address
112+
ngx.log(ngx.INFO, ("Got host %s from DNS A request"):format(host))
113+
break
114+
end
115+
end
112116
end)
113117

114118
if not host or not port then

0 commit comments

Comments
 (0)