-
Notifications
You must be signed in to change notification settings - Fork 154
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
Add in-memory logger and use it on install and uninstall #4485
Conversation
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.
Code looks good, I just wish we would inject a configuration struct to instantate the logger rather than hardcoding values within logp.NewInMemory
pkg/core/logger/logger.go
Outdated
func NewInMemory(selector string) (*Logger, *bytes.Buffer) { | ||
buff := bytes.Buffer{} | ||
|
||
encoderConfig := ecszap.ECSCompatibleEncoderConfig(logp.ConsoleEncoderConfig()) |
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 we inject the logp.ConsoleEncoderConfig()
configuration as parameter? Just in case this needs to be changed depending on the call location/ additional usages
Even better we could receive our log configuration, minus the output part
internal/pkg/agent/cmd/uninstall.go
Outdated
for _, oLog := range oLogs { | ||
fmt.Fprintf(os.Stderr, "%v\n", oLog.Entry) | ||
} | ||
fmt.Fprintf(os.Stderr, logBuff.String()) |
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.
As per the static check this should be (same for install.go):
fmt.Fprintf(os.Stderr, logBuff.String()) | |
fmt.Fprint(os.Stderr, logBuff.String()) |
|
@AndersonQ would it be possible to migrate this to logp package? A cleaner in-memory logger could be useful in other places. |
|
What does this PR do?
It adds an in memory logger to the
pkg/core/logger
package and replaces the observer used during install and uninstall by the new in memory loggerWhy is it important?
The zap observer isn't intended to be logged, it's an feature designed for tests and when printed without any processing it is just raw Go structs, making it hard to read and understand the logs.
Those logs are printed on install or uninstall failures, where the clarity of the logs are rather important for us or the user trying to understand what went wrong.
Checklist
[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration files[ ] I have added tests that prove my fix is effective or that my feature works[ ] I have added an entry in./changelog/fragments
using the changelog tool[ ] I have added an integration test or an E2E testHow to test this PR locally
Related issues
Logs
as a side note, the absence of the
Error fetching PID
are unrelated to this change. It was fixed by another PR.Questions to ask yourself