From 6094482a001d30f9b0734944ad94dd170e347b79 Mon Sep 17 00:00:00 2001 From: Murillo <103451714+gruceo@users.noreply.github.com> Date: Wed, 18 Jan 2023 12:54:33 -0300 Subject: [PATCH 1/6] fix(loop) only use set_log_level API on http subsystem --- lib/resty/timerng/thread/loop.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/resty/timerng/thread/loop.lua b/lib/resty/timerng/thread/loop.lua index 664f6557..2a8c2646 100644 --- a/lib/resty/timerng/thread/loop.lua +++ b/lib/resty/timerng/thread/loop.lua @@ -1,5 +1,12 @@ local get_sys_filter_level = require("ngx.errlog").get_sys_filter_level -local set_log_level = require("resty.kong.log").set_log_level + +local is_http_module = ngx.config.subsystem == "http" + +local set_log_level + +if is_http_module then + set_log_level = require("resty.kong.log").set_log_level +end local ngx_log = ngx.log local ngx_EMERG = ngx.EMERG @@ -171,7 +178,7 @@ local function loop_wrapper(premature, self) while not ngx_worker_exiting() and not self._kill do local global_level = _G.log_level - if global_level then + if global_level and is_http_module then local sys_filter_level = get_sys_filter_level() if sys_filter_level ~= global_level then From 158f553b133b4696e8c37b066736fee0b1f30db3 Mon Sep 17 00:00:00 2001 From: Murillo <103451714+gruceo@users.noreply.github.com> Date: Wed, 18 Jan 2023 12:57:12 -0300 Subject: [PATCH 2/6] chore(rockspec) release 0.2.2 --- ...ng-0.2.1-1.rockspec => lua-resty-timer-ng-0.2.2-1.rockspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename lua-resty-timer-ng-0.2.1-1.rockspec => lua-resty-timer-ng-0.2.2-1.rockspec (96%) diff --git a/lua-resty-timer-ng-0.2.1-1.rockspec b/lua-resty-timer-ng-0.2.2-1.rockspec similarity index 96% rename from lua-resty-timer-ng-0.2.1-1.rockspec rename to lua-resty-timer-ng-0.2.2-1.rockspec index eebd0547..1224c372 100644 --- a/lua-resty-timer-ng-0.2.1-1.rockspec +++ b/lua-resty-timer-ng-0.2.2-1.rockspec @@ -1,8 +1,8 @@ package = "lua-resty-timer-ng" -version = "0.2.1-1" +version = "0.2.2-1" source = { url = "git://github.com/kong/lua-resty-timer-ng", - tag = "0.2.1" + tag = "0.2.2" } description = { summary = "A scalable timer library for OpenResty.", From e6e8d1d61f41e5b62f0ece21002386c2b9363976 Mon Sep 17 00:00:00 2001 From: Murillo <103451714+gruceo@users.noreply.github.com> Date: Mon, 23 Jan 2023 11:07:21 -0300 Subject: [PATCH 3/6] tests(loop) add tests for using set_log_level API on http subsystem --- lib/resty/timerng/thread/loop.lua | 6 ++-- spec/07-bugs_spec.lua | 58 +++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/lib/resty/timerng/thread/loop.lua b/lib/resty/timerng/thread/loop.lua index 2a8c2646..08175e2a 100644 --- a/lib/resty/timerng/thread/loop.lua +++ b/lib/resty/timerng/thread/loop.lua @@ -1,10 +1,8 @@ local get_sys_filter_level = require("ngx.errlog").get_sys_filter_level -local is_http_module = ngx.config.subsystem == "http" - local set_log_level -if is_http_module then +if ngx.config.subsystem == "http" then set_log_level = require("resty.kong.log").set_log_level end @@ -178,7 +176,7 @@ local function loop_wrapper(premature, self) while not ngx_worker_exiting() and not self._kill do local global_level = _G.log_level - if global_level and is_http_module then + if global_level and ngx.config.subsystem == "http" then local sys_filter_level = get_sys_filter_level() if sys_filter_level ~= global_level then diff --git a/spec/07-bugs_spec.lua b/spec/07-bugs_spec.lua index 40368768..e96a95d6 100644 --- a/spec/07-bugs_spec.lua +++ b/spec/07-bugs_spec.lua @@ -90,10 +90,42 @@ insulate("bugs of every timer | ", function () assert.is_false(flag) end) +end) + +insulate("dynamic log levels bugs | ", function () + local timer = { } + + randomize(false) + + lazy_setup(function () + timer = timer_module.new({ + min_threads = 16, + max_threads = 32, + }) + + assert(timer:start()) + end) + + lazy_teardown(function () + timer:freeze() + timer:destroy() + + helper.wait_until(function () + assert.same(1, timer_running_count()) + return true + end) + + end) + + before_each(function () + update_time() + end) it("dynamically sets log level", function() local sys_filter_level + _G.ngx.config.subsystem = "http" + _G.log_level = ngx.DEBUG -- Simulate a log level change from Kong timer:named_at(nil, 0.3, function() sys_filter_level = get_sys_filter_level() @@ -102,12 +134,34 @@ insulate("bugs of every timer | ", function () ngx.sleep((0.3 + 1) * 10) assert.is_equal(sys_filter_level, ngx.DEBUG) - _G.log_level = ngx.CRIT -- Simulate a log level change from Kong + _G.log_level = ngx.WARN -- Simulate a log level change from Kong + timer:named_every(nil, 0.3, function() + sys_filter_level = get_sys_filter_level() + end) + + ngx.sleep((0.3 + 1) * 10) + assert.is_equal(sys_filter_level, ngx.WARN) + end) + + it("only use set_log_level API on http subsystem", function() + local sys_filter_level + + _G.ngx.config.subsystem = "stream" + + _G.log_level = ngx.DEBUG -- Simulate a log level change from Kong + timer:named_at(nil, 0.3, function() + sys_filter_level = get_sys_filter_level() + end) + + ngx.sleep((0.3 + 1) * 10) + assert.is_equal(sys_filter_level, ngx.WARN) -- not changed + + _G.log_level = ngx.DEBUG -- Simulate a log level change from Kong timer:named_every(nil, 0.3, function() sys_filter_level = get_sys_filter_level() end) ngx.sleep((0.3 + 1) * 10) - assert.is_equal(sys_filter_level, ngx.CRIT) + assert.is_equal(sys_filter_level, ngx.WARN) -- not changed end) end) From 4a496b16d3d5b96ebf6e9243bdf891c8c9f543cb Mon Sep 17 00:00:00 2001 From: Qi Date: Sat, 28 Jan 2023 17:00:46 +0800 Subject: [PATCH 4/6] bump lua-kong-nginx-module & remove old openresty --- .github/workflows/coverage.yml | 6 ++++-- .github/workflows/test.yml | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 420efca6..90521ff3 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -19,11 +19,13 @@ jobs: strategy: matrix: openresty_version: - - "1.19.9.1" - "1.21.4.1" + lua_kong_nginx_module_version: + - "0.5.1" env: OPENRESTY_VERSION: ${{ matrix.openresty_version }} + LUA_KONG_NGINX_MODULE_VERSION: ${{ matrix.lua_kong_nginx_module_version }} steps: - name: Set environment variables @@ -43,7 +45,7 @@ jobs: - name: Download Nginx module lua-kong-nginx-module if: steps.cache-openresty.outputs.cache-hit != 'true' run: | - wget https://github.com/Kong/lua-kong-nginx-module/archive/refs/tags/0.5.0.tar.gz -O lua-kong-nginx-module.tar.gz + wget https://github.com/Kong/lua-kong-nginx-module/archive/refs/tags/${LUA_KONG_NGINX_MODULE_VERSION}.tar.gz -O lua-kong-nginx-module.tar.gz mkdir lua-kong-nginx-module tar zxf lua-kong-nginx-module.tar.gz --directory lua-kong-nginx-module --strip-components=1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7c98b698..b2bc3a27 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,11 +9,13 @@ jobs: strategy: matrix: openresty_version: - - "1.19.9.1" - "1.21.4.1" + lua_kong_nginx_module_version: + - "0.5.1" env: OPENRESTY_VERSION: ${{ matrix.openresty_version }} + LUA_KONG_NGINX_MODULE_VERSION: ${{ matrix.lua_kong_nginx_module_version }} steps: - name: Set environment variables @@ -40,7 +42,7 @@ jobs: - name: Download Nginx module lua-kong-nginx-module if: steps.cache-openresty.outputs.cache-hit != 'true' run: | - wget https://github.com/Kong/lua-kong-nginx-module/archive/refs/tags/0.5.0.tar.gz -O lua-kong-nginx-module.tar.gz + wget https://github.com/Kong/lua-kong-nginx-module/archive/refs/tags/${LUA_KONG_NGINX_MODULE_VERSION}.tar.gz -O lua-kong-nginx-module.tar.gz mkdir lua-kong-nginx-module tar zxf lua-kong-nginx-module.tar.gz --directory lua-kong-nginx-module --strip-components=1 From b3c50e8f67d70c1c764cab3aecb04810381dbf64 Mon Sep 17 00:00:00 2001 From: Qi Date: Sat, 28 Jan 2023 17:07:33 +0800 Subject: [PATCH 5/6] fix ci --- .github/workflows/coverage.yml | 1 - .github/workflows/test.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 90521ff3..9f665571 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -82,7 +82,6 @@ jobs: strategy: matrix: openresty_version: - - "1.19.9.1" - "1.21.4.1" env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b2bc3a27..52094fa2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -70,7 +70,6 @@ jobs: - "spec/03*.lua" openresty_version: - - "1.19.9.1" - "1.21.4.1" env: From 8cb5f77c42bae1f1aa528d46aa52cc2b544c88f4 Mon Sep 17 00:00:00 2001 From: Qi Date: Sat, 28 Jan 2023 17:40:07 +0800 Subject: [PATCH 6/6] fix ci --- spec/07-bugs_spec.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/07-bugs_spec.lua b/spec/07-bugs_spec.lua index e96a95d6..873ddfcc 100644 --- a/spec/07-bugs_spec.lua +++ b/spec/07-bugs_spec.lua @@ -94,6 +94,7 @@ end) insulate("dynamic log levels bugs | ", function () local timer = { } + local old_ngx_config_subsystem randomize(false) @@ -104,9 +105,13 @@ insulate("dynamic log levels bugs | ", function () }) assert(timer:start()) + + old_ngx_config_subsystem = _G.ngx.config.subsystem end) lazy_teardown(function () + _G.ngx.config.subsystem = old_ngx_config_subsystem + timer:freeze() timer:destroy() @@ -114,7 +119,6 @@ insulate("dynamic log levels bugs | ", function () assert.same(1, timer_running_count()) return true end) - end) before_each(function ()