-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pdk) support HTTP/2 on Admin API server by adding new PDK functi…
…on `nginx.get_statistics()` for fetching Nginx statistics Retired the `/nginx_status` location block and use LuaJIT FFI to fetch the counters directly instead. Co-authored-by: Datong Sun <datong.sun@konghq.com>
- Loading branch information
Showing
9 changed files
with
298 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
local helpers = require "spec.helpers" -- hard dependency | ||
|
||
|
||
local ngx = ngx | ||
|
||
local fixtures = { | ||
dns_mock = helpers.dns_mock.new({ | ||
mocks_only = true | ||
}), | ||
http_mock = {}, | ||
stream_mock = {} | ||
} | ||
|
||
fixtures.dns_mock:A{ | ||
name = "mock.example.com", | ||
address = "127.0.0.1" | ||
} | ||
|
||
fixtures.dns_mock:A{ | ||
name = "status.example.com", | ||
address = "127.0.0.1" | ||
} | ||
|
||
local status_api_port = helpers.get_available_port() | ||
|
||
|
||
for _, strategy in helpers.each_strategy() do | ||
describe("Plugin: prometheus (metrics)", function() | ||
local bp | ||
local admin_ssl_client -- admin_ssl_client (lua-resty-http) does not support h2 | ||
local proxy_ssl_client -- proxy_ssl_client (lua-resty-http) does not support h2 | ||
|
||
setup(function() | ||
bp = helpers.get_db_utils(strategy, {"services", "routes", "plugins"}) | ||
|
||
local mock_ssl_service = bp.services:insert{ | ||
name = "mock-ssl-service", | ||
host = helpers.mock_upstream_ssl_host, | ||
port = helpers.mock_upstream_ssl_port, | ||
protocol = helpers.mock_upstream_ssl_protocol | ||
} | ||
bp.routes:insert{ | ||
name = "mock-ssl-route", | ||
protocols = {"https"}, | ||
hosts = {"mock.example.com"}, | ||
paths = {"/"}, | ||
service = { | ||
id = mock_ssl_service.id | ||
} | ||
} | ||
|
||
local status_api_ssl_service = bp.services:insert{ | ||
name = "status-api-ssl-service", | ||
url = "https://127.0.0.1:" .. status_api_port .. "/metrics" | ||
} | ||
bp.routes:insert{ | ||
name = "status-api-ssl-route", | ||
protocols = {"https"}, | ||
hosts = {"status.example.com"}, | ||
paths = {"/metrics"}, | ||
service = { | ||
id = status_api_ssl_service.id | ||
} | ||
} | ||
|
||
bp.plugins:insert{ | ||
name = "prometheus" -- globally enabled | ||
} | ||
|
||
assert(helpers.start_kong({ | ||
nginx_conf = "spec/fixtures/custom_nginx.template", | ||
plugins = "bundled,prometheus", | ||
status_listen = '127.0.0.1:' .. status_api_port .. ' ssl', -- status api does not support h2 | ||
status_access_log = "logs/status_access.log", | ||
status_error_log = "logs/status_error.log" | ||
}, nil, nil, fixtures)) | ||
|
||
end) | ||
|
||
teardown(function() | ||
if admin_ssl_client then | ||
admin_ssl_client:close() | ||
end | ||
if proxy_ssl_client then | ||
proxy_ssl_client:close() | ||
end | ||
|
||
helpers.stop_kong() | ||
end) | ||
|
||
before_each(function() | ||
admin_ssl_client = helpers.admin_client() | ||
proxy_ssl_client = helpers.proxy_ssl_client() | ||
end) | ||
|
||
after_each(function() | ||
if admin_ssl_client then | ||
admin_ssl_client:close() | ||
end | ||
if proxy_ssl_client then | ||
proxy_ssl_client:close() | ||
end | ||
end) | ||
|
||
it("expose Nginx connection metrics by admin API #a1.1", function() | ||
local res = assert(admin_ssl_client:send{ | ||
method = "GET", | ||
path = "/metrics" | ||
}) | ||
local body = assert.res_status(200, res) | ||
|
||
assert.matches('kong_nginx_metric_errors_total 0', body, nil, true) | ||
assert.matches('kong_nginx_' .. ngx.config.subsystem .. '_current_connections{state="%w+"} %d+', body) | ||
end) | ||
|
||
it("increments the count of proxied requests #p1.1", function() | ||
local res = assert(proxy_ssl_client:send{ | ||
method = "GET", | ||
path = "/status/400", | ||
headers = { | ||
["Host"] = "mock.example.com" | ||
} | ||
}) | ||
assert.res_status(400, res) | ||
|
||
helpers.wait_until(function() | ||
local res = assert(admin_ssl_client:send{ | ||
method = "GET", | ||
path = "/metrics" | ||
}) | ||
local body = assert.res_status(200, res) | ||
|
||
assert.matches('kong_nginx_metric_errors_total 0', body, nil, true) | ||
|
||
return body:find('kong_http_status{service="mock-ssl-service",route="mock-ssl-route",code="400"} 1', | ||
nil, true) | ||
end) | ||
end) | ||
|
||
it("expose Nginx connection metrics by status API #s1.1", function() | ||
local res = assert(proxy_ssl_client:send{ | ||
method = "GET", | ||
path = "/metrics", | ||
headers = { | ||
["Host"] = "status.example.com" | ||
} | ||
}) | ||
local body = assert.res_status(200, res) | ||
|
||
assert.matches('kong_nginx_metric_errors_total 0', body, nil, true) | ||
assert.matches('kong_nginx_' .. ngx.config.subsystem .. '_current_connections{state="%w+"} %d+', body) | ||
end) | ||
|
||
end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,4 @@ server { | |
} | ||
} | ||
|
||
location /nginx_status { | ||
internal; | ||
access_log off; | ||
stub_status; | ||
} | ||
} |
Oops, something went wrong.