From 6c3ab98bd055c80b841a252e6b453e15085bc57e Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Fri, 2 Sep 2016 16:27:24 +0200 Subject: [PATCH] updated all connections to use local Kong dns resolver, except cli + db --- kong/plugins/galileo/buffer.lua | 3 ++- kong/plugins/http-log/handler.lua | 3 ++- kong/plugins/ldap-auth/access.lua | 5 ++++- kong/plugins/rate-limiting/policies.lua | 4 ++-- kong/plugins/response-ratelimiting/policies.lua | 5 +++-- kong/plugins/runscope/log.lua | 3 ++- kong/plugins/tcp-log/handler.lua | 4 +++- kong/singletons.lua | 1 + 8 files changed, 19 insertions(+), 9 deletions(-) diff --git a/kong/plugins/galileo/buffer.lua b/kong/plugins/galileo/buffer.lua index 0f0f1ac93039..07752f72a065 100644 --- a/kong/plugins/galileo/buffer.lua +++ b/kong/plugins/galileo/buffer.lua @@ -21,6 +21,7 @@ local alf_serializer = require "kong.plugins.galileo.alf" local http = require "resty.http" +local connect = require("kong.singletons").dns.connect local setmetatable = setmetatable local timer_at = ngx.timer.at @@ -111,7 +112,7 @@ _send = function(premature, self, to_send) local client = http.new() client:set_timeout(self.connection_timeout) - local ok, err = client:connect(self.host, self.port) + local ok, err = connect(client, self.host, self.port) if not ok then retry = true log(ERR, "could not connect to Galileo collector: ", err) diff --git a/kong/plugins/http-log/handler.lua b/kong/plugins/http-log/handler.lua index 5ab42e4ff9c7..7ba18fa35990 100644 --- a/kong/plugins/http-log/handler.lua +++ b/kong/plugins/http-log/handler.lua @@ -2,6 +2,7 @@ local basic_serializer = require "kong.plugins.log-serializers.basic" local BasePlugin = require "kong.plugins.base_plugin" local cjson = require "cjson" local url = require "socket.url" +local connect = require("kong.singletons").dns.connect local HttpLogHandler = BasePlugin:extend() @@ -54,7 +55,7 @@ local function log(premature, conf, body, name) local sock = ngx.socket.tcp() sock:settimeout(conf.timeout) - ok, err = sock:connect(host, port) + ok, err = connect(sock, host, port) if not ok then ngx.log(ngx.ERR, name.."failed to connect to "..host..":"..tostring(port)..": ", err) return diff --git a/kong/plugins/ldap-auth/access.lua b/kong/plugins/ldap-auth/access.lua index aebbc3081530..534a545b1231 100644 --- a/kong/plugins/ldap-auth/access.lua +++ b/kong/plugins/ldap-auth/access.lua @@ -1,3 +1,4 @@ +local singletons = require "kong.singletons" local responses = require "kong.tools.responses" local constants = require "kong.constants" local cache = require "kong.tools.database_cache" @@ -11,6 +12,7 @@ local ngx_debug = ngx.DEBUG local decode_base64 = ngx.decode_base64 local ngx_socket_tcp = ngx.socket.tcp local tostring = tostring +local connect = singletons.dns.connect local AUTHORIZATION = "authorization" local PROXY_AUTHORIZATION = "proxy-authorization" @@ -37,7 +39,8 @@ local function ldap_authenticate(given_username, given_password, conf) local sock = ngx_socket_tcp() sock:settimeout(conf.timeout) - ok, error = sock:connect(conf.ldap_host, conf.ldap_port) + + ok, error = connect(sock, conf.ldap_host, conf.ldap_port) if not ok then ngx_log(ngx_error, "[ldap-auth] failed to connect to "..conf.ldap_host..":"..tostring(conf.ldap_port)..": ", error) return responses.send_HTTP_INTERNAL_SERVER_ERROR(error) diff --git a/kong/plugins/rate-limiting/policies.lua b/kong/plugins/rate-limiting/policies.lua index 22b8f56530af..d98cf8c72121 100644 --- a/kong/plugins/rate-limiting/policies.lua +++ b/kong/plugins/rate-limiting/policies.lua @@ -65,7 +65,7 @@ return { increment = function(conf, api_id, identifier, current_timestamp, value) local red = redis:new() red:set_timeout(conf.redis_timeout) - local ok, err = red:connect(conf.redis_host, conf.redis_port) + local ok, err = connect(red, conf.redis_host, conf.redis_port) if not ok then ngx_log(ngx.ERR, "failed to connect to Redis: ", err) return @@ -110,7 +110,7 @@ return { usage = function(conf, api_id, identifier, current_timestamp, name) local red = redis:new() red:set_timeout(conf.redis_timeout) - local ok, err = red:connect(conf.redis_host, conf.redis_port) + local ok, err = connect(red, conf.redis_host, conf.redis_port) if not ok then ngx_log(ngx.ERR, "failed to connect to Redis: ", err) return diff --git a/kong/plugins/response-ratelimiting/policies.lua b/kong/plugins/response-ratelimiting/policies.lua index a726d86631f2..305aefacdb42 100644 --- a/kong/plugins/response-ratelimiting/policies.lua +++ b/kong/plugins/response-ratelimiting/policies.lua @@ -3,6 +3,7 @@ local timestamp = require "kong.tools.timestamp" local cache = require "kong.tools.database_cache" local redis = require "resty.redis" local ngx_log = ngx.log +local connect = require("kong.singletons").dns.connect local pairs = pairs local fmt = string.format @@ -65,7 +66,7 @@ return { increment = function(conf, api_id, identifier, current_timestamp, value, name) local red = redis:new() red:set_timeout(conf.redis_timeout) - local ok, err = red:connect(conf.redis_host, conf.redis_port) + local ok, err = connect(red, conf.redis_host, conf.redis_port) if not ok then ngx_log(ngx.ERR, "failed to connect to Redis: ", err) return @@ -110,7 +111,7 @@ return { usage = function(conf, api_id, identifier, current_timestamp, period, name) local red = redis:new() red:set_timeout(conf.redis_timeout) - local ok, err = red:connect(conf.redis_host, conf.redis_port) + local ok, err = connect(red, conf.redis_host, conf.redis_port) if not ok then ngx_log(ngx.ERR, "failed to connect to Redis: ", err) return diff --git a/kong/plugins/runscope/log.lua b/kong/plugins/runscope/log.lua index 6fd13dca59d9..7515776d098f 100644 --- a/kong/plugins/runscope/log.lua +++ b/kong/plugins/runscope/log.lua @@ -1,5 +1,6 @@ local cjson = require "cjson" local url = require "socket.url" +local connect = require("kong.singletons").dns.connect local _M = {} @@ -59,7 +60,7 @@ local function log(premature, conf, message) local sock = ngx.socket.tcp() sock:settimeout(conf.timeout) - ok, err = sock:connect(host, port) + ok, err = connect(sock, host, port) if not ok then ngx_log(ngx_log_ERR, "[runscope] failed to connect to "..host..":"..tostring(port)..": ", err) return diff --git a/kong/plugins/tcp-log/handler.lua b/kong/plugins/tcp-log/handler.lua index ee5182b59ecb..cab8fd9111c9 100644 --- a/kong/plugins/tcp-log/handler.lua +++ b/kong/plugins/tcp-log/handler.lua @@ -1,6 +1,8 @@ local BasePlugin = require "kong.plugins.base_plugin" local basic_serializer = require "kong.plugins.log-serializers.basic" local cjson = require "cjson" +local singletons = require "kong.singletons" +local connect = singletons.dns.connect local TcpLogHandler = BasePlugin:extend() @@ -16,7 +18,7 @@ local function log(premature, conf, message) local sock = ngx.socket.tcp() sock:settimeout(timeout) - ok, err = sock:connect(host, port) + ok, err = connect(sock, host, port) if not ok then ngx.log(ngx.ERR, "[tcp-log] failed to connect to "..host..":"..tostring(port)..": ", err) return diff --git a/kong/singletons.lua b/kong/singletons.lua index 0d9e7b3a2fca..faee14a42dd8 100644 --- a/kong/singletons.lua +++ b/kong/singletons.lua @@ -2,6 +2,7 @@ local _M = { configuration = nil, events = nil, dao = nil, + dns = nil, serf = nil, loaded_plugins = nil }