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

CBG-3925: Add FileLogger RotationInterval #6835

Merged
merged 19 commits into from
Jun 5, 2024
Merged

CBG-3925: Add FileLogger RotationInterval #6835

merged 19 commits into from
Jun 5, 2024

Conversation

bbrks
Copy link
Member

@bbrks bbrks commented May 20, 2024

CBG-3925

  • Add FileLogger RotationInterval option to force a periodic log rotation.
  • Interval is opt-in and can be set anywhere between 15 minutes and 7 days.
  • Logs will rotate even if no log lines have been written, producing an empty file. This makes it very obvious that log coverage is present and empty, rather than just missing.

Integration Tests

@bbrks

This comment was marked as outdated.

@bbrks bbrks removed their assignment May 29, 2024
Copy link

github-actions bot commented May 30, 2024

Redocly previews

Copy link
Collaborator

@torcolvin torcolvin left a comment

Choose a reason for hiding this comment

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

LGTM, just minor comments.

err := runLogDeletion(ctx, logFilePath, level.String(), int(float64(*lfc.Rotation.RotatedLogsSizeLimit)*rotatedLogsLowWatermarkMultiplier), *lfc.Rotation.RotatedLogsSizeLimit)
if err != nil {
WarnfCtx(ctx, "%s", err)
}
case <-rotationTickerCh:
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I think this reads just a bit easier to see rotationTicker.C since I had to look a back to see if this was a normal ticker.

Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up writing it this way because rotationTicker can be nil if you haven't enabled a rotation interval. The select panics trying to access C on a nil ticker.

You can however, safely select over a nil channel, and this avoids having to write a separate conditional select if you have log rotation enabled.

docs/api/components/schemas.yaml Outdated Show resolved Hide resolved
rest/config_flags.go Show resolved Hide resolved
require.NoError(t, err)
t.Cleanup(func() {
if err := os.RemoveAll(logPath); err != nil {
// log instead of error because it's likely this is going to fail on Windows for this test.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// log instead of error because it's likely this is going to fail on Windows for this test.
// log instead of error because it's likely this is going to fail on Windows for this test if lumberjack has not finished rotation. The `time.Sleep` at the end of the tests tries to mitigate this.

I wonder if the windows build machines are set up to clear temporary files, this could end up filing up the disks on the machine. We could consider writing to cwd if the builds do a fresh checkpoint of sync_gateway or do a git clean -fdx

Any reason here to use os.MkdirTemp instead of t.TempDir ?

Copy link
Member Author

@bbrks bbrks Jun 5, 2024

Choose a reason for hiding this comment

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

t.TempDir fails because it asserts there was no error from RemoveAll. I originally wrote it like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I battled with this for a day and ended up on this solution. The sleep doesn't prevent this error, because Lumberjack keeps the current file handle open for some reason, even after calling Close()

On *nix this doesn't matter because the OS will still let us remove the file/directory.

@torcolvin torcolvin assigned bbrks and unassigned adamcfraser Jun 4, 2024
@bbrks bbrks merged commit f95497b into main Jun 5, 2024
39 checks passed
@bbrks bbrks deleted the CBG-3925 branch June 5, 2024 14:38
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