Skip to content

Commit

Permalink
refactor(core) integrate new events library (#8890)
Browse files Browse the repository at this point in the history
* Modify `init_worker_events` in `global.lua`, switch to new events library.
* Modify `templates/nginx_kong.lua`, add unix listening
* Modify `templates/kong_defaults.lua`, add config `legacy_worker_events`
* Add a temporary `kong/resty/healthcheck.lua` to use `resty.events.compat`
* Modify test cases to pass ci, wrap them with `wait_until()`
* events library version is `0.1.0`

### Notice

* Temporary `kong/resty/healthcheck.lua` should be replaced by a formal version.
* Flaky test `02-integration/05-proxy/10-balancer/01-healthchecks_spec.lua` now is fixed.
  • Loading branch information
chronolaw authored Jun 8, 2022
1 parent 69be376 commit 740bad7
Show file tree
Hide file tree
Showing 32 changed files with 2,362 additions and 352 deletions.
2 changes: 2 additions & 0 deletions .ci/setup_env_github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ LUAROCKS=$(dep_version RESTY_LUAROCKS_VERSION)
OPENSSL=$(dep_version RESTY_OPENSSL_VERSION)
PCRE=$(dep_version RESTY_PCRE_VERSION)
RESTY_LMDB=$(dep_version RESTY_LMDB_VERSION)
RESTY_EVENTS=$(dep_version RESTY_EVENTS_VERSION)


#---------
Expand All @@ -34,6 +35,7 @@ kong-ngx-build \
--luarocks $LUAROCKS \
--openssl $OPENSSL \
--resty-lmdb $RESTY_LMDB \
--resty-events $RESTY_EVENTS \
--pcre $PCRE \
--debug

Expand Down
1 change: 1 addition & 0 deletions .requirements
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RESTY_LUAROCKS_VERSION=3.9.0
RESTY_OPENSSL_VERSION=1.1.1o
RESTY_PCRE_VERSION=8.45
RESTY_LMDB_VERSION=master
RESTY_EVENTS_VERSION=0.1.0
LIBYAML_VERSION=0.2.5
KONG_BUILD_TOOLS_VERSION=4.30.0
KONG_NGINX_MODULE_BRANCH=0.2.1
2 changes: 2 additions & 0 deletions kong-2.8.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ build = {
["kong.plugins.request-transformer.access"] = "kong/plugins/request-transformer/access.lua",
["kong.plugins.request-transformer.schema"] = "kong/plugins/request-transformer/schema.lua",

["kong.resty.healthcheck"] = "kong/resty/healthcheck.lua",

["kong.plugins.azure-functions.handler"] = "kong/plugins/azure-functions/handler.lua",
["kong.plugins.azure-functions.schema"] = "kong/plugins/azure-functions/schema.lua",

Expand Down
2 changes: 2 additions & 0 deletions kong/conf_loader/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ local CONF_INFERENCES = {
untrusted_lua_sandbox_requires = { typ = "array" },
untrusted_lua_sandbox_environment = { typ = "array" },

legacy_worker_events = { typ = "boolean" },

lmdb_environment_path = { typ = "string" },
lmdb_map_size = { typ = "string" },

Expand Down
42 changes: 34 additions & 8 deletions kong/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,42 @@ end
function _GLOBAL.init_worker_events()
-- Note: worker_events will not work correctly if required at the top of the file.
-- It must be required right here, inside the init function
local worker_events = require "resty.worker.events"
local worker_events
local opts

local ok, err = worker_events.configure {
shm = "kong_process_events", -- defined by "lua_shared_dict"
timeout = 5, -- life time of event data in shm
interval = 1, -- poll interval (seconds)
local configuration = kong.configuration

wait_interval = 0.010, -- wait before retry fetching event data
wait_max = 0.5, -- max wait time before discarding event
}
if configuration and configuration.legacy_worker_events then

opts = {
shm = "kong_process_events", -- defined by "lua_shared_dict"
timeout = 5, -- life time of event data in shm
interval = 1, -- poll interval (seconds)

wait_interval = 0.010, -- wait before retry fetching event data
wait_max = 0.5, -- max wait time before discarding event
}

worker_events = require "resty.worker.events"

else
local sock_name = "worker_events.sock"
if ngx.config.subsystem == "stream" then
sock_name = "stream_" .. sock_name
end

opts = {
unique_timeout = 5, -- life time of unique event data in lrucache
broker_id = 0, -- broker server runs in nginx worker #0
listening = "unix:" .. -- unix socket for broker listening
ngx.config.prefix() .. sock_name,
}

--worker_events = require "resty.events"
worker_events = require "resty.events.compat"
end

local ok, err = worker_events.configure(opts)
if not ok then
return nil, err
end
Expand Down
Loading

0 comments on commit 740bad7

Please sign in to comment.