diff --git a/kong/status/init.lua b/kong/status/init.lua index ffe7ca2e54cf..f6c7c41e3cd5 100644 --- a/kong/status/init.lua +++ b/kong/status/init.lua @@ -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 diff --git a/spec/02-integration/04-admin_api/26-dns_client_spec.lua b/spec/02-integration/08-status_api/05-dns_client_spec.lua similarity index 54% rename from spec/02-integration/04-admin_api/26-dns_client_spec.lua rename to spec/02-integration/08-status_api/05-dns_client_spec.lua index 036671732a8a..8ab480f8bf09 100644 --- a/spec/02-integration/04-admin_api/26-dns_client_spec.lua +++ b/spec/02-integration/08-status_api/05-dns_client_spec.lua @@ -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() @@ -20,11 +21,11 @@ for _, strategy in helpers.each_strategy() do assert(helpers.start_kong({ database = strategy, - nginx_conf = "spec/fixtures/custom_nginx.template", - legacy_dns_client = "off", + status_listen = "127.0.0.1:" .. tcp_status_port, + legacy_dns_client = false, })) - client = helpers.admin_client() + client = helpers.http_client("127.0.0.1", tcp_status_port, 20000) end) teardown(function() @@ -65,7 +66,7 @@ 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() @@ -73,11 +74,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 = true, })) - client = helpers.admin_client() + client = helpers.http_client("127.0.0.1", tcp_status_port, 20000) end) teardown(function() @@ -100,3 +101,61 @@ 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() + 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