-
Notifications
You must be signed in to change notification settings - Fork 176
[Driver] Stream the auction JSON body to S3 + solvers #4575
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ed8210a
Streaming JSON
jmg-duarte ec3682b
[driver] Address review on streamed /solve body
jmg-duarte 5703c60
[observe] Add Measured body stream; reuse for driver and autopilot
jmg-duarte 1eecefa
minimize comments
jmg-duarte 6e061c6
rollback the bytestream change
jmg-duarte 5bdd45f
finalize for tee
jmg-duarte f478b5f
clean up
jmg-duarte b4aef68
fmt
jmg-duarte 779134f
BestEffortSink to swallow errors, avoiding tee from failing
jmg-duarte 760cd19
Handle serialize_request metrics
jmg-duarte dc888a3
Merge branch 'main' into jmgd/stream-solve-body
jmg-duarte dead209
address comments
jmg-duarte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
crates/driver/src/infra/solver/streaming/best_effort_sink.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| use {super::Finalize, std::io::Write}; | ||
|
|
||
| /// A [`Write`] adapter that makes its inner writer best-effort: on the first | ||
| /// error it logs once and drops the inner, after which writes are accepted as | ||
| /// no-ops. Lets a non-critical sink fall out of a tee without aborting the | ||
| /// sinks that must finish. | ||
| pub(super) struct BestEffortSink<W>(Option<W>); | ||
|
|
||
| impl<W> BestEffortSink<W> { | ||
| pub(super) fn new(inner: W) -> Self { | ||
| Self(Some(inner)) | ||
| } | ||
| } | ||
|
|
||
| impl<W: Write> Write for BestEffortSink<W> { | ||
| fn write(&mut self, data: &[u8]) -> std::io::Result<usize> { | ||
| if let Some(inner) = &mut self.0 | ||
| && let Err(err) = inner.write_all(data) | ||
| { | ||
| // The sink was declared best-effort, so its failure is non-critical: | ||
| // log it, stop writing to it, and let the remaining sinks carry on. | ||
| tracing::debug!(?err, "best-effort sink failed; dropping it"); | ||
| self.0 = None; | ||
| } | ||
| Ok(data.len()) | ||
| } | ||
|
|
||
| fn flush(&mut self) -> std::io::Result<()> { | ||
| if let Some(inner) = &mut self.0 { | ||
| let _ = inner.flush(); | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl<W: Finalize> Finalize for BestEffortSink<W> { | ||
| fn finalize(self) { | ||
| if let Some(inner) = self.0 { | ||
| inner.finalize(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| /// A failing inner must not surface as an error to the caller. | ||
| #[test] | ||
| fn swallows_inner_failure() { | ||
| struct Failing; | ||
| impl Write for Failing { | ||
| fn write(&mut self, _: &[u8]) -> std::io::Result<usize> { | ||
| Err(std::io::Error::new(std::io::ErrorKind::BrokenPipe, "gone")) | ||
| } | ||
|
|
||
| fn flush(&mut self) -> std::io::Result<()> { | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| let mut writer = BestEffortSink::new(Failing); | ||
| assert_eq!(writer.write(b"hello").unwrap(), 5); | ||
| assert_eq!(writer.write(b"world").unwrap(), 5); | ||
| writer.flush().unwrap(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Behavior change worth a second look: S3 archival is now coupled to the solver request streaming successfully to completion.
On
main, the auction was serialized eagerly intoBytesandarchive_auctionuploaded that buffer independently of the solver request outcome. Here, the gzipped bytes only reacharchive_auction_gzippedwhenfinalize()runs, which only happens ifserde_json::to_writercompletes — and that requires reqwest to pull the entire body. If the solver connection drops or times out mid-upload,ChannelWriter::blocking_senderrors → serialization aborts early →GzipCaptureis dropped withoutfinalize()→ the oneshot sender is dropped → the archive is silently skipped.Net effect: auctions whose solver request fails partway through transmission no longer get archived — which may be exactly the auctions you'd want to inspect later. Is dropping the archive in that case intended? If not, consider decoupling the archive from the request stream (e.g. tee into an independent buffer rather than gating finalize on full request consumption).
Secondary note: the
spawn_blockingthread is now held for the full duration of the body upload (it blocks onblocking_senduntil reqwest drains each chunk), rather than being released right after producing the buffer. Per-solve that's a blocking-pool thread occupied for the whole solver round-trip.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 solved this with the TeeWriter and the BestEffortSink, which will allow the TeeWriter to continue uploading to S3 when this scenarion happens