Skip to content

Commit

Permalink
Merge branch 'master' into ODIC_redirect_after_logout
Browse files Browse the repository at this point in the history
  • Loading branch information
luoluoyuyu authored Dec 22, 2023
2 parents 5f1e5af + c7d406d commit c985bfb
Show file tree
Hide file tree
Showing 41 changed files with 968 additions and 84 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
- ubuntu-20.04
os_name:
- linux_openresty
events_module:
- lua-resty-worker-events
- lua-resty-events
test_dir:
- t/plugin/[a-k]*
- t/plugin/[l-z]*
Expand Down Expand Up @@ -169,6 +172,7 @@ jobs:
- name: Linux Script
env:
TEST_FILE_SUB_DIR: ${{ matrix.test_dir }}
TEST_EVENTS_MODULE: ${{ matrix.events_module }}
run: sudo -E ./ci/${{ matrix.os_name }}_runner.sh script

- if: ${{ steps.cache-images.outputs.cache-hit != 'true' }}
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/centos7-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
strategy:
fail-fast: false
matrix:
events_module:
- lua-resty-worker-events
- lua-resty-events
test_dir:
- t/plugin/[a-k]*
- t/plugin/[l-z]*
Expand Down Expand Up @@ -111,8 +114,9 @@ jobs:
- name: Run centos7 docker and mapping apisix into container
env:
TEST_FILE_SUB_DIR: ${{ matrix.test_dir }}
TEST_EVENTS_MODULE: ${{ matrix.events_module }}
run: |
docker run -itd -v ${{ github.workspace }}:/apisix --env TEST_FILE_SUB_DIR="$TEST_FILE_SUB_DIR" --name centos7Instance --net="host" --dns 8.8.8.8 --dns-search apache.org docker.io/centos:7 /bin/bash
docker run -itd -v ${{ github.workspace }}:/apisix --env TEST_FILE_SUB_DIR="$TEST_FILE_SUB_DIR" --env TEST_EVENTS_MODULE="$TEST_EVENTS_MODULE" --name centos7Instance --net="host" --dns 8.8.8.8 --dns-search apache.org docker.io/centos:7 /bin/bash
# docker exec centos7Instance bash -c "cp -r /tmp/apisix ./"
- name: Cache images
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/doc-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: 🚀 Use Node.js
uses: actions/setup-node@v4.0.0
uses: actions/setup-node@v4.0.1
with:
node-version: "12.x"
- run: npm install -g markdownlint-cli@0.25.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Nodejs env
uses: actions/setup-node@v4.0.0
uses: actions/setup-node@v4.0.1
with:
node-version: '12'

Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/redhat-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
strategy:
fail-fast: false
matrix:
events_module:
- lua-resty-worker-events
- lua-resty-events
test_dir:
- t/plugin/[a-k]*
- t/plugin/[l-z]*
Expand Down Expand Up @@ -107,8 +110,9 @@ jobs:
- name: Run redhat docker and mapping apisix into container
env:
TEST_FILE_SUB_DIR: ${{ matrix.test_dir }}
TEST_EVENTS_MODULE: ${{ matrix.events_module }}
run: |
docker run -itd -v ${{ github.workspace }}:/apisix --env TEST_FILE_SUB_DIR="$TEST_FILE_SUB_DIR" --name ubiInstance --net="host" --dns 8.8.8.8 --dns-search apache.org registry.access.redhat.com/ubi8/ubi:8.6 /bin/bash
docker run -itd -v ${{ github.workspace }}:/apisix --env TEST_FILE_SUB_DIR="$TEST_FILE_SUB_DIR" --env TEST_EVENTS_MODULE="$TEST_EVENTS_MODULE" --name ubiInstance --net="host" --dns 8.8.8.8 --dns-search apache.org registry.access.redhat.com/ubi8/ubi:8.6 /bin/bash
- name: Cache images
id: cache-images
Expand Down
24 changes: 24 additions & 0 deletions apisix/cli/ngx_tpl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ stream {
apisix.stream_init_worker()
}
{% if (events.module or "") == "lua-resty-events" then %}
# the server block for lua-resty-events
server {
listen unix:{*apisix_lua_home*}/logs/stream_worker_events.sock;
access_log off;
content_by_lua_block {
require("resty.events.compat").run()
}
}
{% end %}
server {
{% for _, item in ipairs(stream_proxy.tcp or {}) do %}
listen {*item.addr*} {% if item.tls then %} ssl {% end %} {% if enable_reuseport then %} reuseport {% end %} {% if proxy_protocol and proxy_protocol.enable_tcp_pp then %} proxy_protocol {% end %};
Expand Down Expand Up @@ -483,6 +494,19 @@ http {
apisix.http_exit_worker()
}
{% if (events.module or "") == "lua-resty-events" then %}
# the server block for lua-resty-events
server {
listen unix:{*apisix_lua_home*}/logs/worker_events.sock;
access_log off;
location / {
content_by_lua_block {
require("resty.events.compat").run()
}
}
}
{% end %}
{% if enable_control then %}
server {
listen {* control_server_addr *};
Expand Down
2 changes: 1 addition & 1 deletion apisix/control/v1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ local HTML_TEMPLATE = [[
{% for _, stat in ipairs(stats) do %}
{% for _, node in ipairs(stat.nodes) do %}
{% i = i + 1 %}
{% if node.status == "healthy" then %}
{% if node.status == "healthy" or node.status == "mostly_healthy" then %}
<tr>
{% else %}
<tr bgcolor="#FF0000">
Expand Down
72 changes: 38 additions & 34 deletions apisix/core/config_etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,53 +132,57 @@ local function do_run_watch(premature)
return
end

local local_conf, err = config_local.local_conf()
if not local_conf then
error("no local conf: " .. err)
end
watch_ctx.prefix = local_conf.etcd.prefix .. "/"
-- the main watcher first start
if watch_ctx.started == false then
local local_conf, err = config_local.local_conf()
if not local_conf then
error("no local conf: " .. err)
end
watch_ctx.prefix = local_conf.etcd.prefix .. "/"
watch_ctx.timeout = local_conf.etcd.watch_timeout

watch_ctx.cli, err = get_etcd()
if not watch_ctx.cli then
error("failed to create etcd instance: " .. string(err))
end
watch_ctx.cli, err = get_etcd()
if not watch_ctx.cli then
error("failed to create etcd instance: " .. string(err))
end

local rev = 0
if loaded_configuration then
local _, res = next(loaded_configuration)
if res then
rev = tonumber(res.headers["X-Etcd-Index"])
assert(rev > 0, 'invalid res.headers["X-Etcd-Index"]')
local rev = 0
if loaded_configuration then
local _, res = next(loaded_configuration)
if res then
rev = tonumber(res.headers["X-Etcd-Index"])
assert(rev > 0, 'invalid res.headers["X-Etcd-Index"]')
end
end
end

if rev == 0 then
while true do
local res, err = watch_ctx.cli:get(watch_ctx.prefix)
if not res then
log.error("etcd get: ", err)
ngx_sleep(3)
else
rev = tonumber(res.body.header.revision)
break
if rev == 0 then
while true do
local res, err = watch_ctx.cli:get(watch_ctx.prefix)
if not res then
log.error("etcd get: ", err)
ngx_sleep(3)
else
rev = tonumber(res.body.header.revision)
break
end
end
end
end

watch_ctx.rev = rev + 1
watch_ctx.started = true
watch_ctx.rev = rev + 1
watch_ctx.started = true

log.info("main etcd watcher started, revision=", watch_ctx.rev)
log.info("main etcd watcher initialised, revision=", watch_ctx.rev)

if watch_ctx.wait_init then
for _, sema in pairs(watch_ctx.wait_init) do
sema:post()
if watch_ctx.wait_init then
for _, sema in pairs(watch_ctx.wait_init) do
sema:post()
end
watch_ctx.wait_init = nil
end
watch_ctx.wait_init = nil
end

local opts = {}
opts.timeout = 50 -- second
opts.timeout = watch_ctx.timeout or 50 -- second
opts.need_cancel = true
opts.start_revision = watch_ctx.rev

Expand Down
93 changes: 81 additions & 12 deletions apisix/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,27 @@
-- limitations under the License.
--

local require = require
local error = error
local ngx = ngx

local _M = {}
local require = require
local error = error
local assert = assert
local tostring = tostring
local pairs = pairs
local setmetatable = setmetatable
local ngx = ngx
local core = require("apisix.core")

local _M = {
events_module = nil,
}

_M.EVENTS_MODULE_LUA_RESTY_WORKER_EVENTS = 'lua-resty-worker-events'
_M.EVENTS_MODULE_LUA_RESTY_EVENTS = 'lua-resty-events'


-- use lua-resty-worker-events
local function init_worker_events()
local function init_resty_worker_events()
_M.events_module = _M.EVENTS_MODULE_LUA_RESTY_WORKER_EVENTS

local we = require("resty.worker.events")
local shm = ngx.config.subsystem == "http" and "worker-events" or "worker-events-stream"
local ok, err = we.configure({shm = shm, interval = 0.1})
Expand All @@ -38,17 +47,53 @@ local function init_worker_events()
end


-- use lua-resty-events
local function init_resty_events()
_M.events_module = _M.EVENTS_MODULE_LUA_RESTY_EVENTS

local listening = "unix:" .. ngx.config.prefix() .. "logs/"
if ngx.config.subsystem == "http" then
listening = listening .. "worker_events.sock"
else
listening = listening .. "stream_worker_events.sock"
end
core.log.info("subsystem: " .. ngx.config.subsystem .. " listening sock: " .. listening)

local opts = {
unique_timeout = 5, -- life time of unique event data in lrucache
broker_id = 0, -- broker server runs in nginx worker #0
listening = listening, -- unix socket for broker listening
}

local we = require("resty.events.compat")
assert(we.configure(opts))
assert(we.configured())

return we
end


function _M.init_worker()
if _M.inited then
-- Prevent duplicate initializations in the same worker to
-- avoid potentially unanticipated behavior
-- prevent duplicate initializations in the same worker to
-- avoid potentially unexpected behavior
return
end

_M.inited = true

-- use lua-resty-worker-events default now
_M.worker_events = init_worker_events()
local conf = core.config.local_conf()
local module_name = core.table.try_read_attr(conf, "apisix", "events", "module")
or _M.EVENTS_MODULE_LUA_RESTY_WORKER_EVENTS

if module_name == _M.EVENTS_MODULE_LUA_RESTY_EVENTS then
-- use lua-resty-events as an event module via the apisix.events.module
-- key in the configuration file
_M.worker_events = init_resty_events()
else
-- use lua-resty-worker-events default now
_M.worker_events = init_resty_worker_events()
end
end


Expand All @@ -57,8 +102,23 @@ function _M.register(self, ...)
end


function _M.event_list(self, ...)
return self.worker_events.event_list(...)
function _M.event_list(self, source, ...)
-- a patch for the lua-resty-events to support event_list
-- this snippet is copied from the lua-resty-worker-events lib
if self.events_module == _M.EVENTS_MODULE_LUA_RESTY_EVENTS then
local events = { _source = source }
for _, event in pairs({...}) do
events[event] = event
end
return setmetatable(events, {
__index = function(_, key)
error("event '"..tostring(key).."' is an unknown event", 2)
end
})
end

-- the lua-resty-worker-events has a built-in event_list implementation
return self.worker_events.event_list(source, ...)
end


Expand All @@ -67,4 +127,13 @@ function _M.post(self, ...)
end


function _M.get_healthcheck_events_modele(self)
if self.events_module == _M.EVENTS_MODULE_LUA_RESTY_EVENTS then
return "resty.events"
else
return "resty.worker.events"
end
end


return _M
1 change: 1 addition & 0 deletions apisix/plugins/client-control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local schema = {
max_body_size = {
type = "integer",
minimum = 0,
description = "Maximum message body size in bytes. No restriction when set to 0."
},
},
}
Expand Down
2 changes: 2 additions & 0 deletions apisix/plugins/limit-count.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
local fetch_secrets = require("apisix.secret").fetch_secrets
local limit_count = require("apisix.plugins.limit-count.init")

local plugin_name = "limit-count"
Expand All @@ -31,6 +32,7 @@ end


function _M.access(conf, ctx)
conf = fetch_secrets(conf)
return limit_count.rate_limit(conf, ctx, plugin_name, 1)
end

Expand Down
Loading

0 comments on commit c985bfb

Please sign in to comment.