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

log: Log File size limit and Log rotation for fluent-bit logs #1890

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

phiremande
Copy link
Contributor

Currently fluent-bit logs can be redirected to a file using Log_File.
But there is no configuration option to limit the size of the file. Additionally, there is no log rotation that can be enabled for fluent-bit logs.
These might be useful when we want to collect fluent-bit process logs itself and also to debug.

Added new configuration parameters:
Log_File_Size - Size limit in MB for the file specified by Log_File.
Log_File_History - Max number of backups to be kept.
These backups are kept as <Log_File>.1, <Log_File>.2 etc.

Sample configuration.
[SERVICE]
Flush 1
Daemon Off
Log_Level debug
Log_File ./fb_log.log
Log_File_Size 1
Log_File_History 2

This PR has the corresponding changes.

src/flb_log.c Outdated Show resolved Hide resolved
src/flb_log.c Outdated
int ret = -1;

if (log->max_history == 0) {
//no backups.
Copy link
Member

Choose a reason for hiding this comment

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

use /* ... */ for comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

src/flb_log.c Outdated Show resolved Hide resolved
src/flb_log.c Outdated
}

//max 2 digits for backup name suffix and 1 each for '.' and '\0'.
backup_file_name = flb_malloc(strlen(log->out) + 4);
Copy link
Member

Choose a reason for hiding this comment

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

set the malloc size in a variable before malloc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

src/flb_log.c Outdated Show resolved Hide resolved
src/flb_log.c Outdated
}
src_file_name = flb_malloc(strlen(log->out) + 4);
if (!src_file_name) {
perror("malloc");
Copy link
Member

Choose a reason for hiding this comment

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

flb_errno();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

src/flb_log.c Outdated Show resolved Hide resolved
src/flb_log.c Outdated
}

for (int l = log->max_history; l > 1; l--) {
sprintf(backup_file_name, "%s.%d", log->out, l);
Copy link
Member

Choose a reason for hiding this comment

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

use snprintf instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

src/flb_log.c Outdated Show resolved Hide resolved
@phiremande phiremande force-pushed the log-rotate branch 2 times, most recently from 157f164 to b09402c Compare July 1, 2020 13:05
@phiremande phiremande requested a review from edsiper July 2, 2020 05:10
@phiremande phiremande force-pushed the log-rotate branch 2 times, most recently from 1cbd281 to 1b8bcc8 Compare July 23, 2020 08:37
@phiremande
Copy link
Contributor Author

@edsiper , kindly let me know if you have any further suggestions.

@phiremande
Copy link
Contributor Author

@edsiper , please let me know if this PR still makes sense and are there any plans to merge this.

@lecaros lecaros added docs-required waiting-for-user Waiting for more information, tests or requested changes labels Jan 20, 2022
Copy link
Member

@edsiper edsiper left a comment

Choose a reason for hiding this comment

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

thanks for this PR.

I added some minor change requests before to get this merged we need to sort out two things:

  • rebase on top of GIT master
  • all I/O functions must work on Linux and Windows, .eg: remove(3) is not valid on windows

src/flb_log.c Outdated Show resolved Hide resolved
src/flb_log.c Show resolved Hide resolved
src/flb_log.c Outdated Show resolved Hide resolved
@phiremande
Copy link
Contributor Author

thanks for this PR.

I added some minor change requests before to get this merged we need to sort out two things:

* rebase on top of GIT master

* all I/O functions must work on Linux and Windows, .eg: remove(3) is not valid on windows

Kindly let me know if the changes look fine now. If you have any more suggestions please do let me know. Also should I use "log" or "engine" in the commit message?

@phiremande phiremande requested a review from edsiper February 1, 2022 05:43
@patrick-stephens
Copy link
Contributor

You may need a rebase to solve the fuzzing failures but the unit tests also need resolving. There seems to be quite a few failures which will prevent merging.

@phiremande phiremande force-pushed the log-rotate branch 2 times, most recently from 5bc5fb3 to a202f2c Compare April 8, 2022 19:08
@phiremande
Copy link
Contributor Author

phiremande commented Apr 9, 2022

You may need a rebase to solve the fuzzing failures but the unit tests also need resolving. There seems to be quite a few failures which will prevent merging.

@patrick-stephens , I have rebased and fixed UT failures. Can you please let me know what should be the commit message? I guess the 1 failure is due to component missing in commit message.

@patrick-stephens
Copy link
Contributor

Yeah you need it in the format: component: message

@edsiper
Copy link
Member

edsiper commented Aug 26, 2022

@patrick-stephens both ideally

@qihonggang
Copy link

@patrick-stephens When will this PR merge into the master branch?

@patrick-stephens
Copy link
Contributor

Apologies I've had little time to look at this so far but will endeavour to soon.
It can't be merged right now anyway as it has a conflict.

@said1995
Copy link

Hi Team,
Any update on this request?
This would be very helpful.

@patrick-stephens
Copy link
Contributor

Apologies, I've still not tested this yet.

@lecaros lecaros removed this from the Fluent Bit v1.9.11 milestone Jun 1, 2023
@ustndagsemih
Copy link

Hi team,
Any thoughts on when would this be merged?

@robert-heinzmann-logmein

Any update on this one, I think it would be very valuable to have predictable log sizes for fluent bit itself.

@wojciechtobis
Copy link

Hey @phiremande, are you going to finish this PR? I can continue to work on it as I really need these changes.

@hcdmonitor
Copy link

Hey everyone, I'm grateful for the work that has already been carried out on this issue.
The log file size limit and rotation would be very useful to us to prevent disk utilisation issues caused by fluent-bit.

Is there an update as to when the changes will be merged?

@patrick-stephens
Copy link
Contributor

Hey everyone, I'm grateful for the work that has already been carried out on this issue. The log file size limit and rotation would be very useful to us to prevent disk utilisation issues caused by fluent-bit.

Is there an update as to when the changes will be merged?

It needs rebasing and updating so if you pick it up @hcdmonitor it may speed things up.

}

/* max 2 digits for backup name suffix and 1 each for '.' and '\0' */
size_t filename_len = strlen(log->out) + 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this expected here?

Suggested change
size_t filename_len = strlen(log->out) + 4;
size_t filename_len = snprintf(NULL, 0, "%"PRIu64, log->out);

}
src_file_name = flb_malloc(filename_len);
if (!src_file_name) {
flb_errno();
Copy link
Contributor

Choose a reason for hiding this comment

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

is this expected here?

Suggested change
flb_errno();
flb_free(backup_file_name);
flb_errno();

@etolbakov
Copy link
Contributor

Hello everyone,
I'm also interested in this feature!
Am I correct assuming that the only way of rebasing here is to open a new PR @patrick-stephens @hcdmonitor ?
I don't think anyone except @phiremande has permissions to push to phiremande:log-rotate branch.
Please let me know if I'm wrong.

@ashraf133
Copy link

Hello, any news about this feature ? it is fundamental

@alanbrito
Copy link

This is a very basic feature. We cannot go live with a component that will almost guarantee and outage eventually, due to filling the disk.

Is there any progress?

@patrick-stephens
Copy link
Contributor

Hello everyone, I'm also interested in this feature! Am I correct assuming that the only way of rebasing here is to open a new PR @patrick-stephens @hcdmonitor ? I don't think anyone except @phiremande has permissions to push to phiremande:log-rotate branch. Please let me know if I'm wrong.

It may be easier with a new PR, you can generate the patch for this one by just adding a .diff or .patch to this one.

For everyone asking about log rotate, typically I would do this separately via logrotate or something central to the OS rather than relying on each individual process to do it with all the associated configs to then manage too.

@klee-it
Copy link

klee-it commented Jan 2, 2025

Hello, any news about this feature? I really need that (on my Windows machines) :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-required waiting-for-user Waiting for more information, tests or requested changes work-in-process
Projects
None yet
Development

Successfully merging this pull request may close these issues.