Skip to content

feat(logger): allowed network policy logs retention customization #393

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

Conversation

m00lecule
Copy link
Contributor

@m00lecule m00lecule commented Apr 22, 2025

#392

Description of changes:

Why we need this changes
Currently /var/log/aws-routed-eni/network-policy-agent.log are rotated every 100 mb and only 5 rotated files are kept, resulting in ~500 mb networkpolicy logs kept locally. And what is worse, those parameters are hardcoded.

During a long debugging sessions or while working on large EKS clusters we would benefit from keeping more data locally, especially given the fact they will be included in eks-log-collector archive - https://github.com/awslabs/amazon-eks-ami/blob/main/log-collector-script/linux/README.md.

Therefore the goal is to allow logs rotation configuration by adding arguments, which will override the defaults: --log-file-max-size and --log-file-max-backups.

Testing
Pass either --log-file-max-size or log-file-max-backups and observe if networkpolicy logs (/var/log/aws-routed-eni/network-policy-agent.log) are rotated accordingly.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@m00lecule m00lecule requested a review from a team as a code owner April 22, 2025 14:11
@m00lecule
Copy link
Contributor Author

@Pavani-Panakanti may I ask for a review?

@m00lecule m00lecule changed the title feat(logger): allowed network policy logs retention configuration feat(logger): allowed network policy logs retention customization Apr 22, 2025
@m00lecule m00lecule force-pushed the feat-allow-network-policy-logs-custom-retention branch 5 times, most recently from de857ee to b01d275 Compare April 23, 2025 14:38
@Pavani-Panakanti
Copy link
Contributor

@m00lecule Can you add more details in the PR description ? Thanks
Changes made
Why we need these changes and how it will help users
Testing details

@m00lecule
Copy link
Contributor Author

@m00lecule Can you add more details in the PR description ? Thanks Changes made Why we need these changes and how it will help users Testing details

Description has been updated with more details.

@m00lecule m00lecule force-pushed the feat-allow-network-policy-logs-custom-retention branch from 97f2981 to e0133cd Compare May 23, 2025 11:49
@m00lecule m00lecule force-pushed the feat-allow-network-policy-logs-custom-retention branch from e0133cd to 5e99c1c Compare May 23, 2025 11:51
@jayanthvn jayanthvn requested a review from Copilot May 31, 2025 18:20
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables customization of network policy log retention by exposing new parameters for log file rotation to the logger.

  • Adds new configuration fields and flag options for log file max size, max backups, max age, and compression.
  • Updates logger implementation to pass these new parameters to the lumberjack logger.
  • Modifies the main application initialization and controller configuration to incorporate the new logging options.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pkg/logger/zaplogger.go Passes new log rotation parameters to lumberjack.Logger and updates helper methods.
pkg/logger/logger.go Introduces new default constants and updates logger constructors with additional parameters.
pkg/config/controller_config.go Adds flag bindings and default values for the new log rotation parameters.
main.go Updates logger initialization calls to include the log rotation parameters.

main.go Outdated
@@ -53,15 +53,16 @@ func init() {
}

func main() {
initLogger := logger.New("info", "")
initLogger := logger.New("info", "", 0, 0, 0, false)
Copy link
Preview

Copilot AI May 31, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider using the defined default constants instead of literal zero values when initializing the logger to ensure consistency with later default logger instantiation.

Suggested change
initLogger := logger.New("info", "", 0, 0, 0, false)
initLogger := logger.New("info", "", logger.DefaultLogFileMaxSize, logger.DefaultLogFileMaxBackups, logger.DefaultLogFileMaxAge, false)

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

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

@m00lecule Can we also address this one ? Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Pavani-Panakanti requested change has been implemented

flagLogFileMaxSize = "log-file-max-size"
flagLogFileMaxBackups = "log-file-max-backups"
flagLogFileMaxAge = "log-file-max-age"
flagLogFileCompress = "log-file-compress"
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the contribution and these enhancements!

While supporting log-file-max-size and log-file-max-backups is helpful — especially for high-load environments with frequent pod churn, I don't think other two flags provide much benefit here

log-file-max-age: We could safely hardcode this to 30 days, as it's a reasonable retention window for local logs.
log-file-compress: Disabling compression seems rarely useful in practice. We can remove this flag and always default to allow compression

Let us know if you have any use case for overriding these two flags

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, I just wanted to not leave those values hardcoded as somebody in future might want to tweat those also.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. We would prefer to keep the config to minimal unless there’s a strong use case today. If there's use case in the future, we can always add these back. We can remove log-file-max-age and log-file-compress for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Pavani-Panakanti requested change has been implemented

defaultLogFileMaxSize = 200
defaultLogFileMaxBackups = 8
defaultLogFileMaxAge = 30
defaultLogFileCompress = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Default logger values are added in two places here and in logger.go file. We can keep them in one place. We can move all logger defaults to logger.go and use them here

defaultLogFileMaxSize = logger.DEFAULT_LOG_FILE_MAX_SIZE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Pavani-Panakanti requested change has been implemented

Copy link
Contributor

@viveksb007 viveksb007 left a comment

Choose a reason for hiding this comment

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

lgtm

@Pavani-Panakanti Pavani-Panakanti merged commit fdae2eb into aws:main Jun 16, 2025
4 checks passed
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.

4 participants