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

Channel: Logging output #178

Open
oxzi opened this issue Apr 17, 2024 · 2 comments
Open

Channel: Logging output #178

oxzi opened this issue Apr 17, 2024 · 2 comments

Comments

@oxzi
Copy link
Member

oxzi commented Apr 17, 2024

Currently the channels are not able to log anything, which makes debugging unnecessarily difficult1.

Due to the strict request-response API logic, a new "Log" method should be introduced, which just got consumed from the RPC,
wrapping the message and logging it to icinga-notification's logger. On the channel's side, a specially configured zap logger is needed.

Footnotes

  1. I just stumbled about Channel Form: Unexpected default value behavior as placeholder icinga-notifications-web#154 again, even as I filled this issue back then..

@julianbrost
Copy link
Collaborator

Currently the channels are not able to log anything

Their stderr should be forwarded to the daemon logs:

logRead, logWrite, err := os.Pipe()
if err != nil {
return nil, fmt.Errorf("failed to create logRead/logWrite pipe: %w", err)
}
cmd.Stderr = logWrite
childIOPipes = append(childIOPipes, logWrite)
parentIOPipes = append(parentIOPipes, logRead)

go forwardLogs(logRead, l)

func forwardLogs(errPipe io.Reader, logger *zap.SugaredLogger) {
scanner := bufio.NewScanner(errPipe)
for scanner.Scan() {
logger.Info(scanner.Text())
}
if err := scanner.Err(); err != nil {
logger.Errorw("Failed to scan stderr line", zap.Error(err))
}
}

While not perfect (in particular, this doesn't allow to convey the severity of a message at the moment), this should be enough for debugging purposes.

@oxzi
Copy link
Member Author

oxzi commented Apr 17, 2024

Thanks, I wasn't aware of this as I mostly looked into pkg/plugin and only briefly into internal/channel. Then I would suggest documenting the stderr behavior somewhere in pkg/plugin and furthermore initialize a custom zap logger in RunPlugin to allow writing same logging code as everywhere else.

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

No branches or pull requests

2 participants