-
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.
Browse files
Browse the repository at this point in the history
* feat(wasm): add support for wasmtime cache This adds support for Wasmtime's module caching. See also: * Kong/ngx_wasm_module#540 * https://github.com/Kong/ngx_wasm_module/blob/b19d405403ca6765c548e571010aea3af1accaea/docs/DIRECTIVES.md?plain=1#L136-L149 * https://docs.wasmtime.dev/cli-cache.html * tests(wasm): add start/restart test for wasmtime cache
- Loading branch information
Showing
10 changed files
with
263 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
message: Configure Wasmtime module cache when Wasm is enabled | ||
type: feature | ||
scope: Configuration |
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,17 @@ | ||
-- This software is copyright Kong Inc. and its licensors. | ||
-- Use of the software is subject to the agreement between your organization | ||
-- and Kong Inc. If there is no such agreement, use is governed by and | ||
-- subject to the terms of the Kong Master Software License Agreement found | ||
-- at https://konghq.com/enterprisesoftwarelicense/. | ||
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ] | ||
|
||
return [[ | ||
# ************************* | ||
# * DO NOT EDIT THIS FILE * | ||
# ************************* | ||
# This configuration file is auto-generated. | ||
# Any modifications made here will be lost. | ||
[cache] | ||
enabled = true | ||
directory = $(quote(wasmtime_cache_directory)) | ||
]] |
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,176 @@ | ||
-- This software is copyright Kong Inc. and its licensors. | ||
-- Use of the software is subject to the agreement between your organization | ||
-- and Kong Inc. If there is no such agreement, use is governed by and | ||
-- subject to the terms of the Kong Master Software License Agreement found | ||
-- at https://konghq.com/enterprisesoftwarelicense/. | ||
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ] | ||
|
||
local helpers = require "spec.helpers" | ||
local fmt = string.format | ||
|
||
for _, role in ipairs({"traditional", "control_plane", "data_plane"}) do | ||
|
||
describe("#wasm wasmtime (role: " .. role .. ")", function() | ||
describe("kong prepare", function() | ||
local conf | ||
local prefix = "./wasm" | ||
|
||
lazy_setup(function() | ||
helpers.clean_prefix(prefix) | ||
assert(helpers.kong_exec("prepare", { | ||
database = role == "data_plane" and "off" or "postgres", | ||
nginx_conf = "spec/fixtures/custom_nginx.template", | ||
wasm = true, | ||
prefix = prefix, | ||
role = role, | ||
cluster_cert = "spec/fixtures/kong_clustering.crt", | ||
cluster_cert_key = "spec/fixtures/kong_clustering.key", | ||
})) | ||
|
||
conf = assert(helpers.get_running_conf(prefix)) | ||
end) | ||
|
||
lazy_teardown(function() | ||
helpers.clean_prefix(prefix) | ||
end) | ||
|
||
if role == "control_plane" then | ||
it("does not populate wasmtime config values", function() | ||
assert.is_nil(conf.wasmtime_cache_directory, | ||
"wasmtime_cache_directory should not be set") | ||
assert.is_nil(conf.wasmtime_cache_config_file, | ||
"wasmtime_cache_config_file should not be set") | ||
end) | ||
|
||
else | ||
it("populates wasmtime config values", function() | ||
assert.is_string(conf.wasmtime_cache_directory, | ||
"wasmtime_cache_directory was not set") | ||
assert.is_string(conf.wasmtime_cache_config_file, | ||
"wasmtime_cache_config_file was not set") | ||
end) | ||
|
||
it("creates the cache directory", function() | ||
assert(helpers.path.isdir(conf.wasmtime_cache_directory), | ||
fmt("expected cache directory (%s) to exist", | ||
conf.wasmtime_cache_directory)) | ||
end) | ||
|
||
it("creates the cache config file", function() | ||
assert(helpers.path.isfile(conf.wasmtime_cache_config_file), | ||
fmt("expected cache config file (%s) to exist", | ||
conf.wasmtime_cache_config_file)) | ||
|
||
local cache_config = assert(helpers.file.read(conf.wasmtime_cache_config_file)) | ||
assert.matches(conf.wasmtime_cache_directory, cache_config, nil, true, | ||
"expected cache config file to reference the cache directory") | ||
end) | ||
end | ||
end) -- kong prepare | ||
|
||
describe("kong stop/start/restart", function() | ||
local conf | ||
local prefix = "./wasm" | ||
local log = prefix .. "/logs/error.log" | ||
local status_port | ||
local client | ||
local cp_prefix = "./wasm-cp" | ||
|
||
lazy_setup(function() | ||
if role == "traditional" then | ||
helpers.get_db_utils("postgres") | ||
end | ||
|
||
helpers.clean_prefix(prefix) | ||
status_port = helpers.get_available_port() | ||
|
||
assert(helpers.kong_exec("prepare", { | ||
database = role == "data_plane" and "off" or "postgres", | ||
nginx_conf = "spec/fixtures/custom_nginx.template", | ||
wasm = true, | ||
prefix = prefix, | ||
role = role, | ||
--wasm_filters_path = helpers.test_conf.wasm_filters_path, | ||
wasm_filters = "tests,response_transformer", | ||
cluster_cert = "spec/fixtures/kong_clustering.crt", | ||
cluster_cert_key = "spec/fixtures/kong_clustering.key", | ||
|
||
status_listen = "127.0.0.1:" .. status_port, | ||
nginx_main_worker_processes = 2, | ||
})) | ||
|
||
conf = assert(helpers.get_running_conf(prefix)) | ||
|
||
-- we need to briefly spin up a control plane, or else we will get | ||
-- error.log entries when our data plane tries to connect | ||
if role == "data_plane" then | ||
helpers.get_db_utils("postgres") | ||
|
||
assert(helpers.start_kong({ | ||
database = "postgres", | ||
nginx_conf = "spec/fixtures/custom_nginx.template", | ||
wasm = true, | ||
prefix = cp_prefix, | ||
role = "control_plane", | ||
wasm_filters = "tests,response_transformer", | ||
cluster_cert = "spec/fixtures/kong_clustering.crt", | ||
cluster_cert_key = "spec/fixtures/kong_clustering.key", | ||
status_listen = "off", | ||
nginx_main_worker_processes = 2, | ||
})) | ||
end | ||
end) | ||
|
||
lazy_teardown(function() | ||
if client then | ||
client:close() | ||
end | ||
|
||
helpers.stop_kong(prefix) | ||
|
||
if role == "data_plane" then | ||
helpers.stop_kong(cp_prefix) | ||
end | ||
end) | ||
|
||
it("does not introduce any errors", function() | ||
local function assert_no_errors() | ||
assert.logfile(log).has.no.line("[error]", true, 0) | ||
assert.logfile(log).has.no.line("[alert]", true, 0) | ||
assert.logfile(log).has.no.line("[emerg]", true, 0) | ||
assert.logfile(log).has.no.line("[crit]", true, 0) | ||
end | ||
|
||
local function assert_kong_status(context) | ||
if not client then | ||
client = helpers.proxy_client(1000, status_port) | ||
client.reopen = true | ||
end | ||
|
||
assert.eventually(function() | ||
local res, err = client:send({ path = "/status", method = "GET" }) | ||
if res and res.status == 200 then | ||
return true | ||
end | ||
|
||
return nil, err or "non-200 status" | ||
end) | ||
.is_truthy("failed waiting for kong status " .. context) | ||
end | ||
|
||
assert(helpers.start_kong(conf, nil, true)) | ||
assert_no_errors() | ||
|
||
assert_kong_status("after fresh startup") | ||
assert_no_errors() | ||
|
||
assert(helpers.restart_kong(conf)) | ||
assert_no_errors() | ||
|
||
assert_kong_status("after restart") | ||
assert_no_errors() | ||
end) | ||
end) -- kong stop/start/restart | ||
|
||
end) -- wasmtime | ||
end -- each role |
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