-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Handle discard all logfiles properly #6945
Conversation
Fixes #6892. The [docs](https://www.consul.io/docs/agent/options.html#_log_rotate_max_files) are stating: > -log-rotate-max-files - to specify the maximum number of older log > file archives to keep. Defaults to 0 (no files are ever deleted). Set to > -1 to disable rotation and discard all log files. But the `-1` case was not implemented and led to a panic when being used.
2be0a9c
to
640717d
Compare
logger/logfile.go
Outdated
// Prune if there are more files stored than the configured max | ||
stale := len(matches) - l.MaxFiles | ||
var stale int | ||
if l.MaxFiles == -1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering now whether we should just make this check if l.MaxFiles <= -1
, so that we handle the edge cases of setting this to -2
, -10000
. etc. Not really expecting anyone to seriously do that, but better safe than sorry perhaps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed!
I feel like the docs could be updated here. This sentence feels misleading:
If we were discarding all log files then we wouldn't log to files at all. But with the current implementation we keep a file with the latest logs and what we discard are old log files. So maybe it should read instead:
That would be more in line with the logrotate docs:
Let me know what you think @i0rek and @crhino. |
I agree, it is ambiguous about what the current docs mean. In fact, I am now questioning what it means to "disable rotation" in this instance. This PR as it currently stands will prune all old log files, but will still "rotate" the singular log file being written to. What is the intended use case for this feature? Perhaps an operator has a large cluster of agents and wants to set this configuration and roll it out in order to remove all old log files to free up space? If we decide this is the correct action to take on a
|
Thank you for your reviews @crhino and @freddygv!
If you don't setup log rotation, the active log file will keep growing. And the fact that you can be confident that your server never runs out of space is the usecase in my mind.
I agree that the docs are unclear. I tried to be even more verbose:
What do you think? |
Codecov Report
@@ Coverage Diff @@
## master #6945 +/- ##
==========================================
- Coverage 65.63% 65.57% -0.07%
==========================================
Files 443 443
Lines 53292 53296 +4
==========================================
- Hits 34978 34948 -30
- Misses 14092 14115 +23
- Partials 4222 4233 +11
Continue to review full report at Codecov.
|
Co-Authored-By: Freddy <[email protected]>
Hey there, This issue has been automatically locked because it is closed and there hasn't been any activity for at least 30 days. If you are still experiencing problems, or still have questions, feel free to open a new one 👍. |
Fixes #6892.
The docs are stating:
But the
-1
case was not implemented and led to a panic when beingused.