-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(*) cassandra contact points initialization #4378
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,77 @@ function CassandraConnector.new(kong_config) | |
do | ||
-- Resolve contact points before instantiating cluster, since the | ||
-- driver does not support hostnames in the contact points list. | ||
|
||
-- TODO: this is an ugly hack to force lua sockets on a third party library | ||
|
||
local tcp_old = ngx.socket.tcp | ||
local udp_old = ngx.socket.udp | ||
|
||
local dns_no_sync_old = kong_config.dns_no_sync | ||
|
||
package.loaded["socket"] = nil | ||
package.loaded["kong.tools.dns"] = nil | ||
package.loaded["resty.dns.client"] = nil | ||
package.loaded["resty.dns.resolver"] = nil | ||
|
||
ngx.socket.tcp = function(...) | ||
local tcp = require("socket").tcp(...) | ||
return setmetatable({}, { | ||
__newindex = function(_, k, v) | ||
tcp[k] = v | ||
end, | ||
__index = function(_, k) | ||
if type(tcp[k]) == "function" then | ||
return function(_, ...) | ||
if k == "send" then | ||
local value = select(1, ...) | ||
if type(value) == "table" then | ||
return tcp.send(tcp, table.concat(value)) | ||
end | ||
|
||
return tcp.send(tcp, ...) | ||
end | ||
|
||
return tcp[k](tcp, ...) | ||
end | ||
end | ||
|
||
return tcp[k] | ||
end | ||
}) | ||
end | ||
|
||
ngx.socket.udp = function(...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note for posterity: ideally we should add support for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yes, looks like it already has all things covered. Lets add dependency to it with 1.1+. |
||
local udp = require("socket").udp(...) | ||
return setmetatable({}, { | ||
__newindex = function(_, k, v) | ||
udp[k] = v | ||
end, | ||
__index = function(_, k) | ||
if type(udp[k]) == "function" then | ||
return function(_, ...) | ||
if k == "send" then | ||
local value = select(1, ...) | ||
if type(value) == "table" then | ||
return udp.send(udp, table.concat(value)) | ||
end | ||
|
||
return udp.send(udp, ...) | ||
end | ||
|
||
return udp[k](udp, ...) | ||
end | ||
end | ||
|
||
return udp[k] | ||
end | ||
}) | ||
end | ||
|
||
local dns_tools = require "kong.tools.dns" | ||
|
||
kong_config.dns_no_sync = true | ||
|
||
local dns = dns_tools(kong_config) | ||
|
||
for i, cp in ipairs(kong_config.cassandra_contact_points) do | ||
|
@@ -28,6 +98,16 @@ function CassandraConnector.new(kong_config) | |
resolved_contact_points[i] = ip | ||
end | ||
end | ||
|
||
kong_config.dns_no_sync = dns_no_sync_old | ||
|
||
package.loaded["resty.dns.resolver"] = nil | ||
package.loaded["resty.dns.client"] = nil | ||
package.loaded["kong.tools.dns"] = nil | ||
package.loaded["socket"] = nil | ||
|
||
ngx.socket.udp = udp_old | ||
ngx.socket.tcp = tcp_old | ||
end | ||
|
||
if #resolved_contact_points == 0 then | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be worth being more explicit here:
Can add at merge time, in fact let me take care of it, no worries 👍