-
Notifications
You must be signed in to change notification settings - Fork 260
feat: adding log rotation to Azure-IPAM Zap logger via lumberjack #1523
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
azure-ipam/logger/logger.go
Outdated
| if cfg.Filename == "" { | ||
| err := errors.New("no Filename is provided") |
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.
no filename should not be an error, it just means don't log to a file
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.
Lumberjack log in <processname>-lumberjack.log within os.TempDir() if filename is empty.
I decided to avoid such scenario. If we make this package universal, then we can address this better.
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 think you misunderstood what I meant - if I don't specify a log file, you should not log to a file at all
azure-ipam/logger/logger.go
Outdated
| Filename string | ||
| MaxSize int // megabytes | ||
| MaxBackups int // # of backups, no limitation by default | ||
| MaxAge int // days, no limitation by default |
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.
can remove MaxAge. Lets add if needed
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.
Will address in the new commit
azure-ipam/main.go
Outdated
| ErrorOutputPaths: "var/log/azure-ipam.log", | ||
| Level: "debug", | ||
| Filename: "var/log/azure-ipam.log", | ||
| MaxSize: 10, //MB |
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.
lets have 40 MB and 5 MB per file and 8 files in total
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.
Will address in the new commit
|
@nddq do you mind giving this a look? |
tamilmani1989
left a comment
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.
lgtm
|
@rbtr Can you plz review the new commit? |
|
have you addressed my request that not setting a file name not be an error? |
|
|
Seems lumberjack don't support os.Stderr which is the default zap has when output path is empty. Do you want to log there? |
|
So don't load lumberjack. If I don't specify a log file, I don't need log file rotation. |
|
I was not suggesting that we start logging on stderr; I'm not even sure if that is okay. I know that we can't log on stdout because that's how the CNI plugins communicate. Does the invoker expect request responses on stderr as well as stdout, or does it ignore it? |
Stderr is the default output of Zap if you don't specify any file. This is how the Azure-IPAM behave right now even before my PR. |
I believe the invoker copies stderr to This is what the CNI spec has to say:
|
Do we have any specification for info and debug logs? Do we need to send them to stdout? @rbtr We have the option to set the outputpath to stdout and errorpath to stderr. |
@wedaly Another thing that concerns me is that according to CNI spec Do we need to always have the delegated plugin Errors passed to the stderr even if we are writing all the logs to a file? |
|
Thanks @wedaly |
We may need to always write the errors to stderr. For the info and debug log, we may need to decide to have a default path as before. |
Just trying to make sure that I get your point here: |
|
I do not like lumberjack's random filename default. I could be convinced that a hardcoded default filepath is okay, but you are correct that my initial suggestion was that if the caller does not specify a path, we do not log to a file (and this does not imply anything about any other behavior, only that no path => no log file). |
Based on today's meeting I will put |
…mments addressed.
…dressed the empty filepath comment.
2ef33de to
df583a1
Compare
|
@rbtr Can you review this please? The merge is blocked because of the change request. |
rbtr
left a comment
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.
nothing blocking, lgtm
| ) | ||
|
|
||
| const ( | ||
| Filepath = "/var/log/azure-ipam.log" |
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.
nit: DefaultFilepath
| logger := zap.New(core) | ||
| return logger |
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.
nit: i think it's clear enough to return zap.New(core) and save the line. vertical space is valuable
| MaxSizeInMB: 5, // MegaBytes | ||
| MaxBackups: 8, |
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.
wondering if you did any testing to arrive at these values? I want to make sure we are not rotating the logs too aggressively - it would hard to troubleshoot if that was accidentally like, 10 minutes of logs in a decently sized cluster
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 did test that. We don't log much into this file for now. It took alot of time for me with an script to reach to 5 MB. It was @tamilmani1989 suggestion to go with these numbers for now.
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.
keeping same as cni log files
…into behzad/IPAMLogRotation
…iner-networking into behzad/IPAMLogRotation
Since Zap logger does not have a native rotation support. I added lumberjack filewriter that can rotate based on a given file size.