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

improvement: Automatically rotate log files per Palantir convention #560

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

splucs
Copy link
Contributor

@splucs splucs commented Dec 12, 2022

Summary

Per Palantir convention, we should be rotating and compressing log files on a cadence. Audit logs rotate hourly while the rest rotate daily.

Testing

Tested locally by running the server with a shorter rotation interval and can attest log files are rotated correctly.

Changelog

==COMMIT_MSG==
Automatically rotate log files per Palantir convention
==COMMIT_MSG==


This change is Reviewable

@splucs splucs requested review from nmiyake and tabboud December 12, 2022 20:27
changelog/@unreleased/pr-560.v2.yml Outdated Show resolved Hide resolved
witchcraft/loggers.go Outdated Show resolved Hide resolved
defer ticker.Stop()
for {
// Rotate once at start. If there is no file, it is no op.
if err := logger.Rotate(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess there's no way to restart the timer when the file is rotated due to MaxSize? We're going to end up with smaller-than-desired files if we have two uncoordinated thresholds

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no way unfortunately. The lumberjack logger doesn't expose the current file size nor when was it last rotated.

@@ -679,6 +683,11 @@ func (s *Server) Start() (rErr error) {
}
}

// initialize log flushers
for _, logFlusher := range s.logFlushers {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why bother accumulating these and launching them in *Server? Couldn't this just go periodicallyRotateLogFiles(ctx, logger, slsFilename) in newDefaultLogOutputWriter?

Copy link
Contributor Author

@splucs splucs Feb 8, 2023

Choose a reason for hiding this comment

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

The rotation function stops if the context is cancelled and we only have a context in the main server function after all loggers are initialized. Basically we want the go routine to exit when the server is stopped.

Lucas França de Oliveira added 2 commits February 8, 2023 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants