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

perf(dbless): load declarative schema during init() (#10932) [backport] #10945

Merged
merged 1 commit into from May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Expand Up @@ -359,6 +359,13 @@ now encoded as `"[]"` to comply with standard.
- Support for `upstream_status` field in log serializer.
[#10296](https://github.com/Kong/kong/pull/10296)

#### Performance

- In dbless mode, the declarative schema is now fully initialized at startup
instead of on-demand in the request path. This is most evident in decreased
response latency when updating configuration via the `/config` API endpoint.
[#10932](https://github.com/Kong/kong/pull/10932)

### Fixes

#### Core
Expand Down
8 changes: 7 additions & 1 deletion kong/api/routes/config.lua
Expand Up @@ -118,7 +118,13 @@ return {
local opts = parse_config_post_opts(self.params)

local old_hash = opts.check_hash and declarative.get_current_hash()
local dc = declarative.new_config(kong.configuration)

local dc = kong.db.declarative_config
if not dc then
kong.log.crit("received POST request to /config endpoint, but ",
"kong.db.declarative_config was not initialized")
return kong.response.exit(500, { message = "An unexpected error occurred" })
end

local dc_table, new_hash = hydrate_config_from_request(self.params, dc)

Expand Down
5 changes: 4 additions & 1 deletion kong/clustering/data_plane.lua
Expand Up @@ -59,8 +59,11 @@ function _M.new(clustering)
assert(type(clustering.cert_key) == "cdata",
"kong.clustering did not provide the cluster certificate private key")

assert(kong.db.declarative_config,
"kong.db.declarative_config was not initialized")

local self = {
declarative_config = assert(declarative.new_config(clustering.conf)),
declarative_config = kong.db.declarative_config,
conf = clustering.conf,
cert = clustering.cert,
cert_key = clustering.cert_key,
Expand Down
17 changes: 12 additions & 5 deletions kong/init.lua
Expand Up @@ -448,9 +448,7 @@ local function has_declarative_config(kong_config)
end


local function parse_declarative_config(kong_config)
local dc = declarative.new_config(kong_config)

local function parse_declarative_config(kong_config, dc)
local declarative_config, is_file, is_string = has_declarative_config(kong_config)

local entities, err, _, meta, hash
Expand Down Expand Up @@ -625,13 +623,22 @@ function Kong.init()
end

if is_dbless(config) then
local dc, err = declarative.new_config(config)
if not dc then
error(err)
end

kong.db.declarative_config = dc


if is_http_module or
(#config.proxy_listeners == 0 and
#config.admin_listeners == 0 and
#config.status_listeners == 0)
then
local err
declarative_entities, err, declarative_meta, declarative_hash = parse_declarative_config(kong.configuration)
declarative_entities, err, declarative_meta, declarative_hash =
parse_declarative_config(kong.configuration, dc)

if not declarative_entities then
error(err)
end
Expand Down