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

Update log4j rollover to configure time retention #16179

Merged
merged 9 commits into from
Jun 5, 2024

Conversation

andsel
Copy link
Contributor

@andsel andsel commented May 24, 2024

Docs PREVIEW: https://logstash_bk_16179.docs-preview.app.elstc.co/guide/en/logstash/master/logging.html#log4j2

Release notes

Update logging configuration to remove rolled files older than seven days.

What does this PR do?

Updates the plain, json and pipeline appenders in default config/log4j2.properties to define a delete rule executed during the rollover strategy, which deletes compressed log archives older than 7 days.
Updates the documentation that the describe the logging configuration to explain how the rollover file works, how to configure the strategy in particular how also update to have space limitation condition on the rollover.

Why is it important/What is the impact to the user?

With this commit the user doesn't have anymore problems of disk space exhaustion due to aged log files.

Checklist

  • My code follows the style guidelines of this project
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files (and/or docker env variables)
  • [ ] I have added tests that prove my fix is effective or that my feature works

Author's Checklist

  • test locally.

How to test this PR locally

Change the rollover strategy to use a space limitation (for example 5MB) and use a pipeline that generates log lines, then check that during Logstash execution the files are properly deleted.

Log strategy definition

In log4j2.properties replace

appender.rolling.strategy.action.condition.nested_condition.type = IfLastModified
appender.rolling.strategy.action.condition.nested_condition.age = 7D

with:

appender.routing.pipeline.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize
appender.routing.pipeline.strategy.action.condition.nested_condition.exceeds = 5MB

Pipeline to generate logs

Launch Logstash with following pipeline:

input {
  generator {
    message => '{"name": "John", "surname": "Doe"}'
    codec => json
  }
}

filter {
  ruby {
    code => 'logger.info "This is ia very long line logger by the ruby filter, there is one log line for each event and the only  goal is to generate log lines in the log file to test the log4j2 rollover startegy. In particular the size limit."'
  }	
}

output {
  sink {}
}

Then check the content of logs folder.

Related issues

Use cases

As a user I don't want the archive log files clutter the local filesystem.

@andsel andsel changed the title Fix/log4j time retention config Update log4j rollover to configure time retention. May 24, 2024
@andsel andsel changed the title Update log4j rollover to configure time retention. Update log4j rollover to configure time retention May 24, 2024
Removed grammatical errors and improved readability.

Co-authored-by: João Duarte <jsvd@users.noreply.github.com>
@andsel andsel requested a review from jsvd June 3, 2024 13:20
Copy link
Member

@jsvd jsvd left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@karenzone karenzone left a comment

Choose a reason for hiding this comment

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

@andsel, thanks for your work on this. Nice explanations.

I left some suggestions inline to break up the text a bit to make it easier to skim and parse. Please let me know what you think.

Co-authored-by: Karen Metts <35154725+karenzone@users.noreply.github.com>
@andsel
Copy link
Contributor Author

andsel commented Jun 4, 2024

@karenzone thank's for all your suggestion, accepted in batch 🥇

@andsel andsel requested a review from karenzone June 4, 2024 07:13
Copy link
Contributor

@karenzone karenzone left a comment

Choose a reason for hiding this comment

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

This is looking great. I left some questions about clarifying exactly what we're demonstrating to users here. When I'm clear on what we're doing, I can make some minor tweaks, and we should be able to wrap this up quickly.

Comment on lines +71 to +74
When the limit of 30 files has been reached, the first (oldest) file is removed to create space for the new file.
Subsequent files are renumbered accordingly.

Each file has a date, and files older than 7 days (default) are removed during rollover.
Copy link
Contributor

Choose a reason for hiding this comment

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

@andsel If I'm understanding we're saying that we're showing users how to override default settings, but in the example, we're showing default settings. Is that correct?

Can we offer any guidelines on appropriate settings other than recommending that people don't change them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intention is to describe what the default settings are and what they accomplish. The second example demonstrates how to switch the strategy to be size-based (the overall file sizes) instead of time-based (the default configuration that roll over after 7 days).

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. Thank you.

Copy link
Contributor

@karenzone karenzone left a comment

Choose a reason for hiding this comment

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

Please consider implementing the suggestion in https://github.com/elastic/logstash/pull/16179/files#r1626121129 to emphasize "maximum number of files." Otherwise, LGTM.

Thanks for your work on this.

Co-authored-by: Karen Metts <35154725+karenzone@users.noreply.github.com>
Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @andsel

@andsel andsel merged commit 5c7d416 into elastic:main Jun 5, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Docs] Document log4j2.properties default rolling strategy Rotate & Delete Logstash logs by default
5 participants