Skip to content

Commit

Permalink
updated all connections to use local Kong dns resolver, except cli + db
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Sep 2, 2016
1 parent 42c73b0 commit 6c3ab98
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion kong/plugins/galileo/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion kong/plugins/http-log/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion kong/plugins/ldap-auth/access.lua
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions kong/plugins/rate-limiting/policies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions kong/plugins/response-ratelimiting/policies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion kong/plugins/runscope/log.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local cjson = require "cjson"
local url = require "socket.url"
local connect = require("kong.singletons").dns.connect

local _M = {}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion kong/plugins/tcp-log/handler.lua
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions kong/singletons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local _M = {
configuration = nil,
events = nil,
dao = nil,
dns = nil,
serf = nil,
loaded_plugins = nil
}
Expand Down

0 comments on commit 6c3ab98

Please sign in to comment.