Description
There have been a few recent issues and PRs around the ways stdio is managed for WASI modules:
- Follow logs #431
- stdio in spin #438
- Support processing guest stdout/stderr through
tracing
#449 - Implement CustomLogPipes for Spin Logging/IO: The Return #482
- Triggers refactor #513 (includes changes to "follow logs" config)
The current state of the code is somewhat confusing, requiring coordination between the configuration passed in ExecutionContextConfiguration
and the trigger executor implementation. Also, the options for stdio handling are limited to capturing to memory, capturing to files, and a follow
flag that only works with the "capturing to memory" path.
There a few interrelated requirements to detangle here:
- Some trigger executors need mandatory control over some of stdio (e.g. stdin/stdout for WAGI)
- Some spin embedders want to intercept stdio (stdio in spin #438 (comment))
- Where stdout/err aren't processed by a trigger executor or intercepted by an embedding, we (usually?) want the default behavior to log them to files and/or the console
I think we can restructure to simplify the code while maintaining these features:
-
Collapse the
ExecutionContextConfiguration
IO-related fields into a singleio
field typed like:struct IoDefaults { stdout: IoOutputBehavior, stderr: IoOutputBehavior, } enum IoOutputBehavior { Null, Log, Pipe(WritePipe), }
-
Update
ExecutionContext::prepare_component
'sio
arg to take a type something like:struct IoOverrides { stdin: Option<ReadPipe>, stdout: Option<WritePipe>, stderr: Option<WritePipe>, }
-
Update existing
redirect_to_mem_buffer
usage to use WritePipe::new_in_memory