Skip to content
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

feat(core) implement internal dns with loadbalancing, replace dnsmasq #1587

Merged
merged 38 commits into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2b9486d
initial dns commit
Tieske Sep 1, 2016
42c73b0
fixed unit tests after extracting feature/dns2 branch
Tieske Sep 2, 2016
6c3ab98
updated all connections to use local Kong dns resolver, except cli + db
Tieske Sep 2, 2016
67431fd
patch the global tcp.connect function to use the internal dns resolver
Tieske Sep 5, 2016
03693df
Merge pull request #1598 from Mashape/fix/dns2-globalpatch
Tieske Sep 5, 2016
5f60bf0
Merge branch 'next' of https://github.com/Mashape/kong into feature/dns2
Tieske Sep 5, 2016
2927eda
implements the api property `retries`
Tieske Sep 8, 2016
9916ef4
Merge branch 'next' of https://github.com/Mashape/kong into feature/dns2
Tieske Sep 8, 2016
1a4d03b
fix double drop-column statement and added commenst regarding 2 step …
Tieske Sep 12, 2016
ee654dd
fix a remnant from merging `next`. The config file parsing now delive…
Tieske Sep 12, 2016
42277d1
fix linter errors
Tieske Sep 12, 2016
cc1c446
added some debug stuff, failing all over...
Tieske Sep 13, 2016
3fc057f
wtf
Tieske Sep 13, 2016
19ba990
added patches to make the cli work with co-sockets instead of luasocket
Tieske Sep 14, 2016
ddc7230
Merge branch 'next' of https://github.com/Mashape/kong into fix/dns2-…
Tieske Sep 15, 2016
e089725
fix Kong starting errors, due to yield across c-boundary error
Tieske Sep 15, 2016
04d1489
fixes the cassandra tests
Tieske Sep 16, 2016
4771514
Merge pull request #1647 from Mashape/fix/dns2-cli-tcp-override
Tieske Sep 16, 2016
3c59cb7
Merge branch 'next' of https://github.com/Mashape/kong into feature/dns2
Tieske Sep 23, 2016
5d38d4c
fix linter error
Tieske Sep 26, 2016
f06576b
make keepalive setting configurable
Tieske Oct 12, 2016
6e3e3d7
removed connections setting from shebang
Tieske Oct 12, 2016
85c0c43
replaced `ngx.exit` calls with the proper `kong.tools.responses` equi…
Tieske Oct 12, 2016
f2469c7
Merge branch 'next' of https://github.com/Mashape/kong into feature/dns2
Tieske Oct 12, 2016
4d93ede
updated comments
Tieske Oct 15, 2016
6565d3f
updated dns.lua dependency to release 0.2.0
Tieske Oct 18, 2016
b138dc2
update dns.lua dependency to 0.2.1
Tieske Oct 24, 2016
c085643
Merge branch 'next' of https://github.com/Mashape/kong into feature/dns2
Tieske Oct 24, 2016
ece41c7
Merge branch 'next' of https://github.com/Mashape/kong into feature/dns2
Tieske Oct 27, 2016
773afac
fix merge issues
Tieske Oct 27, 2016
6d9194f
multiple small updates after reviewing and a bug fix
Tieske Oct 27, 2016
e6ebd98
fix typo
Tieske Oct 27, 2016
fa11a9c
fix cassandra-abstraction failing to parse version string correctly
Tieske Oct 27, 2016
4d9921e
fix tests, implemented pure lua semaphore only to be used for testing…
Tieske Oct 28, 2016
d876c50
Merge branch 'next' of https://github.com/Mashape/kong into feature/dns2
Tieske Oct 28, 2016
b3d8eef
Merge branch 'next' of https://github.com/Mashape/kong into feature/dns2
Tieske Nov 3, 2016
74e4c13
Merge branch 'next' of https://github.com/Mashape/kong into feature/dns2
Tieske Nov 4, 2016
3aa85a7
remove `pgmoon-mashape` reference accidentally reintroduced while mer…
Tieske Nov 4, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions bin/busted
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#!/usr/bin/env resty
#!/usr/bin/env resty -c 65535

-- a flag to detect whether our modules (especially kong.core.globalpatches)
-- are running under resty-cli or in a real ngx_lua, runtime environment.
ngx.RESTY_CLI = true

-- force LuaSocket usage to resolve `/etc/hosts` until
-- supported by resty-cli.
-- See https://github.com/Mashape/kong/issues/1523
for _, namespace in ipairs({"cassandra", "pgmoon-mashape"}) do
local socket = require(namespace .. ".socket")
socket.force_luasocket(ngx.get_phase(), true)
end
require "kong.core.globalpatches"

if ngx ~= nil then
ngx.exit = function()end
ngx.exit = function() end
end

-- Busted command-line runner
Expand Down
12 changes: 4 additions & 8 deletions bin/kong
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#!/usr/bin/env resty
#!/usr/bin/env resty -c 65535
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would override whatever ulimit I have already set - do we really need it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it, latest dns.lua master doesn't use it anymore


-- a flag to detect whether our modules (especially kong.core.globalpatches)
-- are running under resty-cli or in a real ngx_lua, runtime environment.
ngx.RESTY_CLI = true

-- force LuaSocket usage to resolve `/etc/hosts` until
-- supported by resty-cli.
-- See https://github.com/Mashape/kong/issues/1523
for _, namespace in ipairs({"cassandra", "pgmoon-mashape"}) do
local socket = require(namespace .. ".socket")
socket.force_luasocket(ngx.get_phase(), true)
end
-- require global patches, to enable dns resolution by the internal client
-- initializing the dns client is done in `./kong/conf_loader.lua`
require "kong.core.globalpatches"

if ngx ~= nil then
ngx.exit = function()end
Expand Down
8 changes: 5 additions & 3 deletions kong-0.9.2-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ dependencies = {
"version == 0.2",
"lapis == 1.5.1",
"lua-cassandra == 0.5.4",
"pgmoon-mashape == 2.0.0",
"pgmoon == 1.6.0",
"luatz == 0.3",
"lua_system_constants == 0.1.1",
"lua-resty-iputils == 0.2.1",
"luacrypto == 0.3.2",
"luasyslog == 1.0.0",
"lua_pack == 1.0.4"
"lua_pack == 1.0.4",
"dns == 0.1.0",
}
build = {
type = "builtin",
Expand Down Expand Up @@ -63,7 +64,6 @@ build = {
["kong.cmd.utils.serf_signals"] = "kong/cmd/utils/serf_signals.lua",
["kong.cmd.utils.nginx_signals"] = "kong/cmd/utils/nginx_signals.lua",
["kong.cmd.utils.prefix_handler"] = "kong/cmd/utils/prefix_handler.lua",
["kong.cmd.utils.dnsmasq_signals"] = "kong/cmd/utils/dnsmasq_signals.lua",

["kong.api.init"] = "kong/api/init.lua",
["kong.api.api_helpers"] = "kong/api/api_helpers.lua",
Expand All @@ -75,6 +75,7 @@ build = {
["kong.api.routes.cache"] = "kong/api/routes/cache.lua",
["kong.api.routes.cluster"] = "kong/api/routes/cluster.lua",

["kong.tools.dns"] = "kong/tools/dns.lua",
["kong.tools.utils"] = "kong/tools/utils.lua",
["kong.tools.printable"] = "kong/tools/printable.lua",
["kong.tools.responses"] = "kong/tools/responses.lua",
Expand All @@ -91,6 +92,7 @@ build = {
["kong.core.events"] = "kong/core/events.lua",
["kong.core.error_handlers"] = "kong/core/error_handlers.lua",
["kong.core.globalpatches"] = "kong/core/globalpatches.lua",
["kong.core.balancer"] = "kong/core/balancer.lua",

["kong.dao.errors"] = "kong/dao/errors.lua",
["kong.dao.schemas_validation"] = "kong/dao/schemas_validation.lua",
Expand Down
19 changes: 7 additions & 12 deletions kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,13 @@
# DNS RESOLVER
#------------------------------------------------------------------------------

#dnsmasq = on # Toggles if Kong should start/stop dnsmasq,
# which can be used as the Nginx DNS resolver.
# Using dnsmasq allows Nginx to resolve
# domains defined in /etc/hosts.
# dnsmasq must be installed and available in
# your $PATH.

#dnsmasq_port = 8053 # The port on which dnsmasq should listen to
# for queries.

#dns_resolver = 8.8.8.8 # Configure a name server to be used by Nginx.
# Only valid when `dnsmasq` is disabled.
#dns_resolver = # Comma separated list of name servers, each
# entry in `ipv4[:port]` format to be used by
# Kong. If not specified the nameservers in
# the local `resolv.conf` file will be used.
# Port defaults to 53 if omitted.

#dns_hostsfile = /etc/hosts # The `hosts` file to use.

#------------------------------------------------------------------------------
# DEVELOPMENT & MISCELLANEOUS
Expand Down
2 changes: 1 addition & 1 deletion kong/cmd/compile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Example usage:
}
Note:
Third-party services such as Serf and dnsmasq need to be properly configured
Third-party services such as Serf need to be properly configured
and started for Kong to be fully compatible while embedded.
Options:
Expand Down
1 change: 0 additions & 1 deletion kong/cmd/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ local function execute(args)
local pids = {
serf = conf.serf_pid,
nginx = conf.nginx_pid,
dnsmasq = conf.dnsmasq and conf.dnsmasq_pid or nil
}

local count = 0
Expand Down
5 changes: 0 additions & 5 deletions kong/cmd/quit.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local dnsmasq_signals = require "kong.cmd.utils.dnsmasq_signals"
local nginx_signals = require "kong.cmd.utils.nginx_signals"
local serf_signals = require "kong.cmd.utils.serf_signals"
local conf_loader = require "kong.conf_loader"
Expand Down Expand Up @@ -39,10 +38,6 @@ local function execute(args)

assert(serf_signals.stop(conf, DAOFactory(conf)))

if conf.dnsmasq then
assert(dnsmasq_signals.stop(conf))
end

log("Kong stopped (gracefully)")
end

Expand Down
4 changes: 0 additions & 4 deletions kong/cmd/reload.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local dnsmasq_signals = require "kong.cmd.utils.dnsmasq_signals"
local prefix_handler = require "kong.cmd.utils.prefix_handler"
local nginx_signals = require "kong.cmd.utils.nginx_signals"
local serf_signals = require "kong.cmd.utils.serf_signals"
Expand All @@ -22,9 +21,6 @@ local function execute(args)
prefix = args.prefix
}))
assert(prefix_handler.prepare_prefix(conf, args.nginx_conf))
if conf.dnsmasq then
assert(dnsmasq_signals.start(conf))
end
assert(serf_signals.start(conf, DAOFactory(conf)))
assert(nginx_signals.reload(conf))
log("Kong reloaded")
Expand Down
2 changes: 1 addition & 1 deletion kong/cmd/restart.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end
local lapp = [[
Usage: kong restart [OPTIONS]
Restart a Kong node (and other configured services like dnsmasq and Serf)
Restart a Kong node (and other configured services like Serf)
in the given prefix directory.
This command is equivalent to doing both 'kong stop' and
Expand Down
15 changes: 4 additions & 11 deletions kong/cmd/start.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local dnsmasq_signals = require "kong.cmd.utils.dnsmasq_signals"
local prefix_handler = require "kong.cmd.utils.prefix_handler"
local nginx_signals = require "kong.cmd.utils.nginx_signals"
local serf_signals = require "kong.cmd.utils.serf_signals"
Expand All @@ -20,24 +19,18 @@ local function execute(args)
xpcall(function()
assert(prefix_handler.prepare_prefix(conf, args.nginx_conf))
assert(dao:run_migrations())
if conf.dnsmasq then
assert(dnsmasq_signals.start(conf))
end
assert(serf_signals.start(conf, dao))
assert(nginx_signals.start(conf))
log("Kong started")
end, function(e)
log.verbose("could not start Kong, stopping services")
pcall(nginx_signals.stop(conf))
pcall(serf_signals.stop(conf, dao))
if conf.dnsmasq then
pcall(dnsmasq_signals.stop(conf))
end
err = e -- cannot throw from this function
log.verbose("stopped services")
end)

if err then
log.verbose("could not start Kong, stopping services")
pcall(nginx_signals.stop(conf))
pcall(serf_signals.stop(conf, dao))
log.verbose("stopped services")
error(err) -- report to main error handler
end
end
Expand Down
4 changes: 0 additions & 4 deletions kong/cmd/stop.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local dnsmasq_signals = require "kong.cmd.utils.dnsmasq_signals"
local nginx_signals = require "kong.cmd.utils.nginx_signals"
local serf_signals = require "kong.cmd.utils.serf_signals"
local conf_loader = require "kong.conf_loader"
Expand All @@ -20,9 +19,6 @@ local function execute(args)
local conf = assert(conf_loader(default_conf.kong_conf))
assert(nginx_signals.stop(conf))
assert(serf_signals.stop(conf, DAOFactory(conf)))
if conf.dnsmasq then
assert(dnsmasq_signals.stop(conf))
end
log("Kong stopped")
end

Expand Down
75 changes: 0 additions & 75 deletions kong/cmd/utils/dnsmasq_signals.lua

This file was deleted.

3 changes: 0 additions & 3 deletions kong/cmd/utils/prefix_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ local function compile_conf(kong_config, conf_template)
tostring = tostring
}

if kong_config.dnsmasq then
compile_env["dns_resolver"] = "127.0.0.1:"..kong_config.dnsmasq_port
end
if kong_config.anonymous_reports and socket.dns.toip(constants.SYSLOG.ADDRESS) then
compile_env["syslog_reports"] = fmt("error_log syslog:server=%s:%d error;",
constants.SYSLOG.ADDRESS, constants.SYSLOG.PORT)
Expand Down
25 changes: 16 additions & 9 deletions kong/conf_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ local pl_config = require "pl.config"
local pl_file = require "pl.file"
local pl_path = require "pl.path"
local tablex = require "pl.tablex"
local utils = require "kong.tools.utils"
local log = require "kong.cmd.utils.log"

local ipv4_port_pattern = "^(%d+)%.(%d+)%.(%d+)%.(%d+):(%d+)$"

local DEFAULT_PATHS = {
"/etc/kong.conf",
"/etc/kong/kong.conf"
}

local PREFIX_PATHS = {
dnsmasq_pid = {"pids", "dnsmasq.pid"}
;
serf_pid = {"pids", "serf.pid"},
serf_log = {"logs", "serf.log"},
serf_event = {"serf", "serf_event.sh"},
Expand Down Expand Up @@ -75,8 +76,7 @@ local CONF_INFERENCES = {
cluster_profile = {enum = {"local", "lan", "wan"}},
cluster_ttl_on_failure = {typ = "number"},

dnsmasq = {typ = "boolean"},
dnsmasq_port = {typ = "number"},
dns_resolver = {typ = "array"},

ssl = {typ = "boolean"},

Expand Down Expand Up @@ -177,13 +177,16 @@ local function check_and_infer(conf)
end
end

if conf.dns_resolver and conf.dnsmasq then
errors[#errors+1] = "must disable dnsmasq when a custom DNS resolver is specified"
elseif not conf.dns_resolver and not conf.dnsmasq then
errors[#errors+1] = "must specify a custom DNS resolver when dnsmasq is turned off"
if conf.dns_resolver then
for _, server in ipairs(conf.dns_resolver) do
local dns = utils.normalize_ip(server)
if (not dns) or (dns.type ~= "ipv4") then
errors[#errors+1] = "dns_resolver must be a comma separated list in the form of IPv4 or IPv4:port"
break -- one error is enough
end
end
end

local ipv4_port_pattern = "^(%d+)%.(%d+)%.(%d+)%.(%d+):(%d+)$"
if not conf.cluster_listen:match(ipv4_port_pattern) then
errors[#errors+1] = "cluster_listen must be in the form of IPv4:port"
end
Expand Down Expand Up @@ -371,6 +374,10 @@ local function load(path, custom_conf)

log.verbose("prefix in use: %s", conf.prefix)

-- initialize the dns client, so the globally patched tcp.connect method
-- will work from here onwards.
assert(require("kong.tools.dns")(conf))

return setmetatable(conf, nil) -- remove Map mt
end

Expand Down
Loading