fix(log-rotate): reopen logs after partial rotation#13375
Draft
juzhiyuan wants to merge 2 commits into
Draft
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #13368.
This updates
log-rotateso a partial rotation failure does not prevent Nginx from reopening the log files that were rotated successfully. The regression test covers the reported behavior where a custom plugin writes throughcore.log.infoafter rotation and access logs should continue landing in the currentaccess.log.Root cause
rotate_file()iterates over the configured log files inapisix/plugins/log-rotate.lua. Before this patch, ifrename_file()returnednilfor any configured file,rotate_file()returned immediately from the loop before reaching the USR1 reopen step.That means this sequence could happen:
error.logis renamed to a timestamped file.access.logis missing, sorename_file()returnsnil.rotate_file()returns before sending USR1 to the master process.Fix
Tests
t/plugin/log-rotate.tusing three pipelined requests:/setup: configure a log-phaseserverless-post-function, removeaccess.log, wait for partial rotation, then disablelog-rotateto stabilize assertions./hello: trigger both plugin error-log output and access-log output./verify: assert the currenterror.logcontains the plugin marker and currentaccess.logcontains the request.Validation run:
PATH=/usr/local/openresty/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/luajit/bin:$PATH \ FLUSH_ETCD=1 prove -Itest-nginx/lib -I. t/plugin/log-rotate.tResult after the fix:
Additional manual check:
error.logwhile leavingaccess.logpresent; the same command passed all 23 tests after the fix.