Skip to content

Commit

Permalink
fix(dns): added /status/dns API to status_listen port
Browse files Browse the repository at this point in the history
  • Loading branch information
chobits committed Aug 8, 2024
1 parent 0f73339 commit 39e6b79
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 7 deletions.
1 change: 1 addition & 0 deletions kong-3.8.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ build = {
["kong.api.routes.tags"] = "kong/api/routes/tags.lua",
["kong.api.routes.targets"] = "kong/api/routes/targets.lua",
["kong.api.routes.upstreams"] = "kong/api/routes/upstreams.lua",
["kong.api.routes.dns"] = "kong/api/routes/dns.lua",

["kong.admin_gui"] = "kong/admin_gui/init.lua",
["kong.admin_gui.utils"] = "kong/admin_gui/utils.lua",
Expand Down
23 changes: 23 additions & 0 deletions kong/api/routes/dns.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local kong = kong


return {
["/status/dns"] = {
GET = function (self, db, helpers)

if kong.configuration.legacy_dns_client then
return kong.response.exit(501, {
message = "not implemented with the legacy DNS client"
})
end

return kong.response.exit(200, {
worker = {
id = ngx.worker.id() or -1,
count = ngx.worker.count(),
},
stats = kong.dns.stats(),
})
end
},
}
1 change: 1 addition & 0 deletions kong/status/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ngx.log(ngx.DEBUG, "Loading Status API endpoints")
-- Load core health route
api_helpers.attach_routes(app, require "kong.api.routes.health")
api_helpers.attach_routes(app, require "kong.status.ready")
api_helpers.attach_routes(app, require "kong.api.routes.dns")


if kong.configuration.database == "off" then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
local helpers = require "spec.helpers"
local cjson = require "cjson"

local tcp_status_port = helpers.get_available_port()

for _, strategy in helpers.each_strategy() do
describe("Admin API - DNS client route with [#" .. strategy .. "]" , function()
describe("[#traditional] Status API - DNS client route with [#" .. strategy .. "]" , function()
local client

lazy_setup(function()
Expand All @@ -20,11 +21,11 @@ for _, strategy in helpers.each_strategy() do

assert(helpers.start_kong({
database = strategy,
nginx_conf = "spec/fixtures/custom_nginx.template",
status_listen = "127.0.0.1:" .. tcp_status_port,
legacy_dns_client = "off",
}))

client = helpers.admin_client()
client = helpers.http_client("127.0.0.1", tcp_status_port, 20000)
end)

teardown(function()
Expand Down Expand Up @@ -65,19 +66,19 @@ for _, strategy in helpers.each_strategy() do
end)
end)

describe("Admin API - DNS client route with [#" .. strategy .. "]" , function()
describe("[#traditional] Status API - DNS client route with [#" .. strategy .. "]" , function()
local client

lazy_setup(function()
helpers.get_db_utils(strategy)

assert(helpers.start_kong({
database = strategy,
nginx_conf = "spec/fixtures/custom_nginx.template",
legacy_dns_client = true,
status_listen = "127.0.0.1:" .. tcp_status_port,
legacy_dns_client = "on",
}))

client = helpers.admin_client()
client = helpers.http_client("127.0.0.1", tcp_status_port, 20000)
end)

teardown(function()
Expand All @@ -100,3 +101,63 @@ for _, strategy in helpers.each_strategy() do
end)
end)
end


-- hybrid mode

for _, strategy in helpers.each_strategy() do

describe("[#hybrid] Status API - DNS client route with [#" .. strategy .. "]" , function()
local client

lazy_setup(function()
helpers.get_db_utils(strategy) -- runs migrations

assert(helpers.start_kong({
role = "control_plane",
cluster_cert = "spec/fixtures/kong_clustering.crt",
cluster_cert_key = "spec/fixtures/kong_clustering.key",
database = strategy,
cluster_listen = "127.0.0.1:9005",
nginx_conf = "spec/fixtures/custom_nginx.template",
legacy_dns_client = "off",
}))

assert(helpers.start_kong({
role = "data_plane",
database = "off",
prefix = "servroot2",
cluster_cert = "spec/fixtures/kong_clustering.crt",
cluster_cert_key = "spec/fixtures/kong_clustering.key",
cluster_control_plane = "127.0.0.1:9005",
proxy_listen = "0.0.0.0:9002",
nginx_conf = "spec/fixtures/custom_nginx.template",
status_listen = "127.0.0.1:" .. tcp_status_port,
legacy_dns_client = "off",
}))

client = helpers.http_client("127.0.0.1", tcp_status_port, 20000)
end)

teardown(function()
if client then
client:close()
end
helpers.stop_kong("servroot2")
helpers.stop_kong()
end)

it("/status/dns - status code 200", function ()
local res = assert(client:send {
method = "GET",
path = "/status/dns",
headers = { ["Content-Type"] = "application/json" }
})

local body = assert.res_status(200 , res)
local json = assert(cjson.decode(body))
assert(type(json.stats) == "table")
end)

end)
end

0 comments on commit 39e6b79

Please sign in to comment.