Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for custom named log file names for log-rotate plugin #9619

Closed
wants to merge 12 commits into from

Conversation

Revolyssup
Copy link
Contributor

@Revolyssup Revolyssup commented Jun 7, 2023

Description

Supersedes #9210
Fixes #9061
Prior to this PR, the path to access and error log passed in config is not respected and path is hardcoded to logs/error.log and logs/access.log. This PR fixes that as well.

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

…in(supersedes 9210)

Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
@monkeyDluffy6017
Copy link
Contributor

Please fix the ci

@monkeyDluffy6017 monkeyDluffy6017 added the wait for update wait for the author's response in this issue/PR label Jun 7, 2023
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
@Revolyssup
Copy link
Contributor Author

Please fix the ci

approve ci

Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
@Revolyssup
Copy link
Contributor Author

@monkeyDluffy6017 Please approve CI

@monkeyDluffy6017
Copy link
Contributor

Could you add Fixes https://github.com/apache/apisix/issues/9061 to the description?

Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
apisix/core/config_local.lua Show resolved Hide resolved
max_kept: 1
enable_compression: true
--- config
location /t {
content_by_lua_block {
ngx.sleep(3.5)
ngx.sleep(2.5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this change needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are flaky and fail intermittently and with this timeout configuration they stopped failing.

@@ -105,6 +106,7 @@ start xxxxxx
--- config
location /t {
content_by_lua_block {
local io = require("io")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you will have to revert these changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fails lint check when I try to use global "io"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have imported "io" but haven't used it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used it below in the for loop

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, I don't see any other additions except importing "io" module in to this file 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
@monkeyDluffy6017
Copy link
Contributor

@Revolyssup please make the ci happy

Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
@Revolyssup
Copy link
Contributor Author

@Revolyssup please make the ci happy

The failing tests are unrelated to this change :(

local ok, err = os_rename(log.file, new_file)
local filename = log.file
-- create the file if it does not exist
local exists = lfs.attributes(filename, "mode") == "file"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a funciton file_exists already

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Revolyssup please check this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay I'll replace it with that function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@monkeyDluffy6017 made the change

Comment on lines 163 to 168
if not exists then
local file = io_open(filename, "w")
if file then
file:close()
end
end
Copy link
Contributor

@monkeyDluffy6017 monkeyDluffy6017 Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you create a new file here, i think it's better to record an error log and exit the function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not desirable to automatically create the log file if it does not exist? @monkeyDluffy6017

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Revolyssup please check this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@monkeyDluffy6017 So should I error out when the file doesn't exist or create the file as a fallback?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessay to add this check?
The original logic looked fine, os.rename would log when it failed and then skip

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@monkeyDluffy6017 removed this check

Comment on lines 49 to 50
local DEFAULT_ACCESS_LOG_FILENAME = "access.log"
local DEFAULT_ERROR_LOG_FILENAME = "error.log"
local DEFAULT_ACCESS_LOG_FILENAME = "logs/access.log"
local DEFAULT_ERROR_LOG_FILENAME = "logs/error.log"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better not to change this, the variable name is FILENAME, it should not include the file path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I think we can change the variable name because we do require a path which currently is hardcoded to logs/access.log with hardcoding at two different places. I am changing the variable name to more appropriate DEFAULT_*_LOG_PATH @monkeyDluffy6017

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I had changed the variable name.

Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
@monkeyDluffy6017
Copy link
Contributor

Please make the ci pass

@monkeyDluffy6017
Copy link
Contributor

I will close this pr becase it's fixed by #9749

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wait for update wait for the author's response in this issue/PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: log-rotate max_kept doesn't work
3 participants