You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "AlinsRan (via GitHub)" <gi...@apache.org> on 2026/07/07 09:14:36 UTC

Re: [PR] fix(log-rotate): reopen logs after partial rotation [apisix]

AlinsRan commented on code in PR #13375:
URL: https://github.com/apache/apisix/pull/13375#discussion_r3535093072


##########
t/plugin/log-rotate.t:
##########
@@ -216,3 +222,116 @@ true
     }
 --- response_body
 passed
+
+
+
+=== TEST 6: reopen plugin and access logs even if one configured log file is missing
+# Log-phase plugins run after the response is sent to the client. Keep the
+# rotation setup, request trigger, and assertions in separate requests so the
+# previous request's log-phase output is flushed before checking the log files.
+--- timeout: 30
+--- config
+    location /setup {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local prefix = ngx.config.prefix()
+            local access_log = prefix .. "/logs/access.log"
+            local function fail(msg)
+                ngx.status = 500
+                ngx.say(msg)
+                ngx.exit(ngx.HTTP_OK)
+            end
+
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                    "plugins": {
+                        "serverless-post-function": {
+                            "phase": "log",
+                            "functions" : ["return function(conf, ctx) require('apisix.core').log.info('serverless post-rotation marker') end"]
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uri": "/hello"
+                }]]
+                )
+
+            if code >= 300 then
+                fail(body)
+            end
+
+            os.remove(access_log)
+
+            ngx.sleep(2.5)
+
+            local data = [[
+apisix:
+  node_listen: 1984
+  admin_key: null
+plugins:
+  - serverless-post-function
+nginx_config:
+  error_log_level: info
+  http:
+    access_log_buffer: 1
+            ]]
+            require("lib.test_admin").set_config_yaml(data)
+            code, _, body = t('/apisix/admin/plugins/reload',

Review Comment:
   Fixed. /setup now waits until rotation has provably stopped before returning: it counts __error.log files and only returns once that count stays unchanged for two full intervals, so a stray tick can't land between /hello and /verify anymore. Confirmed stable across repeated local runs.



##########
t/plugin/log-rotate.t:
##########
@@ -28,6 +28,12 @@ add_block_preprocessor(sub {
     my $extra_yaml_config = <<_EOC_;
 plugins:                          # plugin list
   - log-rotate
+  - serverless-post-function
+
+nginx_config:

Review Comment:
   Dropped both here and in the /setup payload. You're right — t/APISIX.pm hardcodes log_level(info) and an unbuffered access_log, and config.yaml's nginx_config only feeds the CLI template which the test framework bypasses, so these keys never took effect.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org