feat: allow disabling search option in resolv.conf (#3609)

Also disable it in the test to avoid occassional DNS query timeout.
This commit is contained in:
罗泽轩 2021-02-20 15:38:45 +08:00 committed by GitHub
parent 5656649d11
commit 18909a2a0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 0 deletions

View File

@ -88,6 +88,8 @@ local function dns_parse(domain)
if dns_resolvers ~= current_inited_resolvers then
local local_conf = config_local.local_conf()
local valid = table.try_read_attr(local_conf, "apisix", "dns_resolver_valid")
local enable_resolv_search_opt = table.try_read_attr(local_conf, "apisix",
"enable_resolv_search_opt")
local opts = {
ipv6 = true,
@ -97,6 +99,11 @@ local function dns_parse(domain)
order = {"last", "A", "AAAA", "CNAME"}, -- avoid querying SRV (we don't support it yet)
validTtl = valid,
}
if not enable_resolv_search_opt then
opts.search = {}
end
local ok, err = dns_client.init(opts)
if not ok then
return nil, "failed to init the dns client: " .. err

View File

@ -110,6 +110,7 @@ apisix:
# - 8.8.8.8
# dns_resolver_valid: 30 # if given, override the TTL of the valid records. The unit is second.
resolver_timeout: 5 # resolver timeout
enable_resolv_search_opt: true # enable search option in resolv.conf
ssl:
enable: true
enable_http2: true

1
t/APISIX.pm vendored
View File

@ -93,6 +93,7 @@ apisix:
tcp:
- 9100
admin_key: null
enable_resolv_search_opt: false
_EOC_
my $etcd_enable_auth = $ENV{"ETCD_ENABLE_AUTH"} || "false";

View File

@ -271,6 +271,10 @@ ip_info: {"address":"127.0.0.1","class":1,"name":"test.com","ttl":315360000,"typ
=== TEST 8: search host with '.org' suffix
--- yaml_config
apisix:
node_listen: 1984
enable_resolv_search_opt: true
--- config
location /t {
content_by_lua_block {
@ -289,3 +293,27 @@ GET /t
.+"name":"apisix\.apache\.org".+
--- no_error_log
[error]
=== TEST 9: disable search option
--- yaml_config
apisix:
node_listen: 1984
enable_resolv_search_opt: false
--- config
location /t {
content_by_lua_block {
local core = require("apisix.core")
local ip_info, err = core.utils.dns_parse("apisix")
if not ip_info then
core.log.error("failed to parse domain: ", host, ", error: ",err)
return
end
ngx.say("ip_info: ", require("toolkit.json").encode(ip_info))
}
}
--- request
GET /t
--- error_log
error: failed to query the DNS server