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

fix: Compression in log-rotate plugin exceeds the default timeout of shell.run #8620

Merged
merged 7 commits into from
Nov 3, 2023

Conversation

alptugay
Copy link
Contributor

@alptugay alptugay commented Jan 5, 2023

  • fix Compression in log-rotate plugin exceeds the default timeout of shell.run

Description

This issue fixes the bug: "Compression in log-rotate plugin exceeds the default timeout of shell.run" #8619
The interval parameter is passed to shell.run() function

Fixes #8619

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)

alptugay and others added 3 commits January 5, 2023 16:03
Fixes: Compression in log-rotate plugin exceeds the default timeout of shell.run
…shell.run

Fixes: Compression in log-rotate plugin exceeds the default timeout of shell.run
@alptugay alptugay changed the title Update log-rotate.lua fix: Compression in log-rotate plugin exceeds the default timeout of shell.run Jan 5, 2023
@juzhiyuan juzhiyuan requested a review from bzp2010 January 6, 2023 00:46
@@ -277,6 +277,7 @@ local function rotate()
max_size = attr.max_size or max_size
enable_compression = attr.enable_compression or enable_compression
end
local timeout = interval * 100 -- Timeout for compression is interval in milliseconds
Copy link
Member

Choose a reason for hiding this comment

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

We'd better add a new configuration item to control the timeout parameter.

image

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 don't agree that timeout should be a user defined parameter. Because, setting a timeout greater than interval may cause undefined behaviour (eg. second rotation starts but first compression is still running), and setting the value too low also causes the mentioned undesired behaviour (so doesn't fix the issue in the first place). So, this value should be automatically set based on interval and shoud not be user defined imho.

Copy link
Contributor

Choose a reason for hiding this comment

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

@alptugay, I agree with you, however setting a fixed timeout is inappropriate. What if the compression starts just before the next rotation?

The correct way would be to provide a timeout such that timeout occurs before the next log-rotation. And if the compression still gets a timeout, we can reschedule the compression later using ngx_timer. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What if the compression starts just before the next rotation?
Rotation is done in intervals. Execution step is like below in simple terms:

  1. Rename current log file to logfile.date
  2. Send signal to process so new file opens
  3. compress logfile.date with a timeout that is not bigger than the interval,
    So I don't think step 3 will start just before next rotation.

But your second argument is valid, compression can still get a timeout if it can't be finished in the specified interval. We can schedule it with ngx_timer but this means those timers will add up. Assume the interval is 5 minutes and compression takes 10 minutes, after 1 hour we will have done 12 intervals jobs but only 6 compression will be completed and 6 will be waiting. So this will add up and probably make the system unresponsive

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. LGTM.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest adding a configuration to control the timeout parameter, the default timeout is 10s, it's enough for most people, if you use interval as timeout, it could be 1min or 1 hour, maybe someone don't need such long time.

@github-actions
Copy link

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the [email protected] list. Thank you for your contributions.

@github-actions github-actions bot added the stale label May 20, 2023
@github-actions
Copy link

This pull request/issue has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

Copy link
Contributor

@shreemaan-abhishek shreemaan-abhishek left a comment

Choose a reason for hiding this comment

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

@lingsamuel, @monkeyDluffy6017, this PR LGTM. Please review and approve.

@monkeyDluffy6017 monkeyDluffy6017 added the wait for update wait for the author's response in this issue/PR label Sep 22, 2023
@moonming
Copy link
Member

moonming commented Oct 9, 2023

@shreemaan-abhishek please fix #8620 (comment) if it's a typo, then merge this PR, thanks

@monkeyDluffy6017
Copy link
Contributor

@shreemaan-abhishek Pay attention to this comment: #8620 (comment)

@shreemaan-abhishek
Copy link
Contributor

@alptugay can I take over this PR? You can invite me to collaborate on your forked repo.

@Revolyssup
Copy link
Contributor

@alptugay are you still on it?

@Revolyssup Revolyssup self-assigned this Nov 1, 2023
@Revolyssup
Copy link
Contributor

I will take over from here.

@Revolyssup Revolyssup removed the wait for update wait for the author's response in this issue/PR label Nov 1, 2023
@monkeyDluffy6017
Copy link
Contributor

monkeyDluffy6017 commented Nov 2, 2023

@Revolyssup Could you add this attribute in config-default.yaml and add some comments

@monkeyDluffy6017 monkeyDluffy6017 added the wait for update wait for the author's response in this issue/PR label Nov 2, 2023
Signed-off-by: Ashish Tiwari <[email protected]>
@Revolyssup Revolyssup removed the wait for update wait for the author's response in this issue/PR label Nov 2, 2023
@Revolyssup
Copy link
Contributor

@monkeyDluffy6017 Added in the config-default.yaml

@monkeyDluffy6017 monkeyDluffy6017 merged commit 7edf661 into apache:master Nov 3, 2023
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

bug: Compression in log-rotate plugin exceeds the default timeout of shell.run
8 participants