From a5324bf66e8f565ea9dcd09c90cfff8fa64bee14 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Wed, 31 May 2023 10:02:37 +0100 Subject: [PATCH] Stream stderr to logs for streaming fork mode This mode is not expected to be used by any customers in production, however we received a message from a customer who had decided to use this mode. They reported not being able to log to stderr, I was able to reproduce the problem and have added bindLoggingPipe to stderr as per the other modes in the of-watchdog. After testing with a simple Python program, the logging is now available. We only recommend HTTP mode for production use. Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- executor/logging.go | 1 - executor/serializing_fork_runner.go | 9 +++++++-- main.go | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/executor/logging.go b/executor/logging.go index eb9575d1..b6d435a1 100644 --- a/executor/logging.go +++ b/executor/logging.go @@ -10,7 +10,6 @@ import ( ) // bindLoggingPipe spawns a goroutine for passing through logging of the given output pipe. -// func bindLoggingPipe(name string, pipe io.Reader, output io.Writer, logPrefix bool, maxBufferSize int) { log.Printf("Started logging: %s from function.", name) diff --git a/executor/serializing_fork_runner.go b/executor/serializing_fork_runner.go index ed96f29b..92c07d77 100644 --- a/executor/serializing_fork_runner.go +++ b/executor/serializing_fork_runner.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "io/ioutil" + "os" units "github.com/docker/go-units" @@ -21,8 +22,9 @@ import ( // SerializingForkFunctionRunner forks a process for each invocation type SerializingForkFunctionRunner struct { - ExecTimeout time.Duration - LogPrefix bool + ExecTimeout time.Duration + LogPrefix bool + LogBufferSize int } // Run run a fork for each invocation @@ -99,11 +101,14 @@ func serializeFunction(req FunctionRequest, f *SerializingForkFunctionRunner) (* stdout, _ := cmd.StdoutPipe() stdin, _ := cmd.StdinPipe() + stderr, _ := cmd.StderrPipe() if err := cmd.Start(); err != nil { return nil, err } + bindLoggingPipe("stderr", stderr, os.Stderr, f.LogPrefix, f.LogBufferSize) + functionRes, errors := pipeToProcess(stdin, stdout, &data) if len(errors) > 0 { return nil, errors[0] diff --git a/main.go b/main.go index 0e8602e8..279db892 100644 --- a/main.go +++ b/main.go @@ -233,8 +233,9 @@ func createLockFile() (string, error) { func makeSerializingForkRequestHandler(watchdogConfig config.WatchdogConfig, logPrefix bool) func(http.ResponseWriter, *http.Request) { functionInvoker := executor.SerializingForkFunctionRunner{ - ExecTimeout: watchdogConfig.ExecTimeout, - LogPrefix: logPrefix, + ExecTimeout: watchdogConfig.ExecTimeout, + LogPrefix: logPrefix, + LogBufferSize: watchdogConfig.LogBufferSize, } return func(w http.ResponseWriter, r *http.Request) {