Conversation
|
Can one of the admins verify this patch? |
1 similar comment
|
Can one of the admins verify this patch? |
|
Thank you for your contribution! The syslog-ng team will review your code as soon as it finds a bit of time. Note that daily, weekly, but even hourly rotations are already supported by syslog-ng: you just have to use the time macros in the file names. |
872aa24 to
5689d19
Compare
|
I updated the branch since the pipeline failed previously. Could you restart the checks? |
|
Hi! |
|
Will this patch be included in future versions of syslog-ng? |
|
@azike I've re-targeted the PR to the |
|
Alright! Thank you. |
This Pull Request introduces config grammar changessyslog-ng/1f8286d25722ba0fa45a5d3ae613e8d6c9dbcc5b -> azike/syslog-ng-logrotation Details--- a/destination
+++ b/destination
file(
+ logrotate(
+ <empty>
+ enable(<yesno>)
+ rotations(<positive-integer>)
+ size(<positive-integer>)
+ )
)
|
5cef81b to
5e8a1ef
Compare
|
I updated the last commit message since the |
1e45907 to
307c3d1
Compare
307c3d1 to
cd4f602
Compare
|
I added the changes you suggested, but as I already stated we should somehow limit the number of logrotate checks. Doing it for every message could cost performance and in the end logs. If I run my functional-test with |
yepp, plz see my comment above, I guess a size caching can solve this too |
|
I just checked it briefly but what I found out is that the I am away for three weeks now so, you will not hear any updates from me in that time. |
I'd stay away from using stat counters that require costly locking. I'd vote for a local counter instead. |
|
Hi! I am back now and pushed two ideas I had within the last two commits. Because of the layering that is going it is a little trickier than thought because directly reporting to other layers is not that straightforward.
In both cases logrotation only checks against this in-memory Again there are some subtle points that need attention and there I guess I need some help regarding how to deal with them and to not interfere with the design choices of the project. I will discuess them in the comments below. |
Logrotation is performed in the function do_logrotate and for now implements a simple size based rotation. There is no in-memory storage or list to keep track of rotated files. With each rotation the number of log files is established through the filenames and their rotation suffixes. The log files are first scanned starting with the main log file until the first roation is found that is not yet 'used'. Then the files are rotated up to that index. If there are 'holes' in the sequence of log files (e.g. file.log, file.log.1, file.log.3 --> file.log.2 is missing) the files that come after that missing one are not rotated. This should prevent the deletion of logfiles in case a reopen attempt fails. Signed-off-by: Alexander Zikulnig <[email protected]>
Add new keywords to affile-grammar to enable the specification of logrotate-settings in the syslog-ng config file. The settings are stored in the current AFFileDestDriver object and are available to all its writer objects through the field logrotate_options. Currently the following keywords are supported: - 'enable' -> turn on/off logrotation - 'size' -> set max file size - 'rotations' -> number of rotations Signed-off-by: Alexander Zikulnig <[email protected]>
Split up reopen function of AFFileDestWriter to handle the logwriter reopen separately. Signed-off-by: Alexander Zikulnig <[email protected]>
Whenever the log file is reopened its current size is read and cached as part of the AFFileDestwriter object. Signed-off-by: Alexander Zikulnig <[email protected]>
Signed-off-by: Alexander Zikulnig <[email protected]>
Signed-off-by: Alexander Zikulnig <[email protected]>
React to log_pipe_notify with code NC_LOGROTATE for AFFileDestWriter objects. Upon notification it is checked if logrotation should be performed based on the settings stored in logrotate_options and the current cached filesize. The function is intended to be called by the current logwriter worker thread when flushing log messages. If logrotation and reopen of the log file were successful the caller is informed trough log_pipe_notify return codes. Note that affile_dw_reopen can not be called from within log_writer_work_perform as it would result in a deadlock (worker waits on itself to finish). Signed-off-by: Alexander Zikulnig <[email protected]>
37c938a to
a0ad786
Compare
|
Hi! I pushed the changes. Please check if those are resolved now. |
I forked the repo and started to add the documentation, but I was wondering what I should write for |
@azike you can follow the schema that can be seen in the final, rendered version like |
If logrotation has been performed before but the log file could not be reopened then rotation should not be done again on a subsequent logrotate call. Signed-off-by: Alexander Zikulnig <[email protected]>
Signed-off-by: Alexander Zikulnig <[email protected]>
The logwriter instance notifies its DestWriter object after each log message written. The call contains the length of the log message to keep track of the current filesize. In case logrotation fails the logwriter instance is notified and the ongoing flush is canceled. Signed-off-by: Alexander Zikulnig <[email protected]>
- test_logrotate_all_messages_received: Verify all messages that are sent are received and files are rotated. - test_logrotate_deleting_log_file: Delete main log file and verify it is reopened. - test_logrotate_rotation_failure: Delete first rotated log file and trigger rotation again. Verify oldest log file is not deleted. Signed-off-by: Alexander Zikulnig <[email protected]>
Signed-off-by: Alexander Zikulnig <[email protected]>
a0ad786 to
c80128a
Compare
|
Do you also need tests for the config parser? Like here https://github.com/syslog-ng/syslog-ng/blob/develop/modules/affile/tests/test_wildcard_source.c? |
Add description of `logrotate` feature introduced in syslog-ng/syslog-ng#5191.
@azike it would be nice and useful EDIT: I suggest moving that to the next iteration. I'll merge this now, thanks. |
|
Cool! Thanks guys. |
|
@azike Thanks for your work! Unfortunately, some errors occur now in our Kira tests that should have happened in the earlier runs here. I investigate how earlier the Kira runs did not find the problem, and what the reason is of the failures. |
Description
This pull-requests adds support for filesize-based logrotation (inspired by #4145) to counter problems with constraints on logfile partition sizes.
Limits on file size and number of rotations (history) are defined in the conf file and the destination driver makes sure to rotate logfiles after they reached the defined size.
Overview
The implementation is added directly to the
affilemodule, as it is only effecting file destinations using regular-files. Keywords to allow setting logrotation options, like the maximum file size and number of rotations, are added toaffile-grammar.The
AFFileDestDriverobjects of the file destination holds a new field containing the logrotation settings (defined inmodules/affile/logrotate.h), which are valid for all its writers of typeAFFileDestWriter.After the writer worker-thread performed its task (
log_writer_work_perform) and flushed the incoming messages (log_writer_flush_finalize) it notifies its controllingAFFileDestWriterinstance vialog_pipe_notify. The actual checks, if rotation is to be performed, and the rotation itself are done inaffile-dest.cand triggered through the notification.During rotation the current logfile is renamed, therefore it has to be opened again. As the rotation is triggered from withing the worker-thread, a call to
affile_dw_reopenwould lead to a deadlock (thread waits on itself). The reopen is done by simply updating thefdof theLogProtoClient(no other thread modifies theLogProtoClientwhile it is still at work).Alternatively a blocking main-thread call to open the file is possible, but I don't think it is necessary.
The main-thread watches are again registered afterwards in
log_writer_work_finished.Usage
Below is an example conf file which uses an
example_msg_generatorsource to emit 1000 messages. The file destinations are annotated with thelogrotate(...)keyword specifying its rotation settings. Macros in the filename are still possible:TODO's and ideas
example_msg_generatorsource set tofreq(0.0001), which lead to message loss. However, I am not sure it that frequency is realistic or how other type of source behave when being suspended.Related topics
Resolves #2964
Documentation PR syslog-ng/syslog-ng.github.io#240