-
Notifications
You must be signed in to change notification settings - Fork 117
feat(upload): Add metadata support #6028
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
+353
−54
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9d937ac
initial logic
tobias-wilfert 2736e6c
remove unused length field from
tobias-wilfert 4d80608
rename to
tobias-wilfert 64a3457
rename Error variants
tobias-wilfert 5a3d9dd
import serde
tobias-wilfert 874c1a0
bubble up tus header errors
tobias-wilfert 5e25d06
split up upload_metadata
tobias-wilfert 4bf2efd
avoid relay_with_processing in test
tobias-wilfert 677231e
move logic from integration to unit tests
tobias-wilfert 242eb73
Merge branch 'master' into tobias-wilfert/feat/upload-metadata
tobias-wilfert ae8beac
add changelog entry
tobias-wilfert e9dae6c
Merge branch 'tobias-wilfert/feat/upload-metadata' of github.com:gets…
tobias-wilfert 55213a0
rename functions
tobias-wilfert 55d5eaf
Merge branch 'master' into tobias-wilfert/feat/upload-metadata
tobias-wilfert 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ use tokio_util::io::{ReaderStream, StreamReader}; | |
| #[cfg(feature = "processing")] | ||
| use uuid::Uuid; | ||
|
|
||
| use crate::envelope::AttachmentType; | ||
| use crate::http::{HttpError, RequestBuilder, Response}; | ||
|
|
||
| #[cfg(feature = "processing")] | ||
|
|
@@ -114,6 +115,8 @@ pub struct Create { | |
| /// | ||
| /// Trusted clients (i.e. PoP Relays) are allowed to omit the length (see `Upload-Defer-Length: 1`). | ||
| pub length: Option<usize>, | ||
| /// The attachment type of the upload. | ||
| pub attachment_type: Option<AttachmentType>, | ||
| } | ||
|
|
||
| /// The type used to stream a request body. | ||
|
|
@@ -241,11 +244,15 @@ enum Backend { | |
| impl Service { | ||
| async fn create( | ||
| &self, | ||
| Create { scoping, length }: Create, | ||
| Create { | ||
| scoping, | ||
| length, | ||
| attachment_type, | ||
| }: Create, | ||
| ) -> Result<SignedLocation<Provisional>, Error> { | ||
| match &self.backend { | ||
| Backend::Upstream { addr } => { | ||
| let (request, rx) = UploadRequest::create(scoping, length); | ||
| let (request, rx) = UploadRequest::create(scoping, length, attachment_type); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not directly related to this PR, but here we are destructuring the |
||
| addr.send(SendRequest(request)); | ||
| let response = rx.await??; | ||
| SignedLocation::try_from_response(response) | ||
|
|
@@ -354,7 +361,7 @@ pub trait UploadLength: for<'de> Deserialize<'de> { | |
|
|
||
| /// A provisional upload length which may or may not yet be known. | ||
| /// | ||
| /// /// See also [`Final`]. | ||
| /// See also [`Final`]. | ||
| #[derive(Debug, Clone, Copy, Deserialize)] | ||
| #[serde(transparent)] | ||
| pub struct Provisional(Option<usize>); | ||
|
|
@@ -561,11 +568,11 @@ where | |
| enum RequestKind { | ||
| Create { | ||
| length: Option<usize>, | ||
| attachment_type: Option<AttachmentType>, | ||
| }, | ||
| Upload { | ||
| location: SignedLocation<Provisional>, | ||
| stream: TakeOnce<BoundedStream<MeteredStream<ByteStream>>>, | ||
| length: Option<usize>, | ||
| encoding: HttpEncoding, | ||
| }, | ||
| } | ||
|
|
@@ -581,6 +588,7 @@ impl UploadRequest { | |
| fn create( | ||
| scoping: Scoping, | ||
| length: Option<usize>, | ||
| attachment_type: Option<AttachmentType>, | ||
| ) -> ( | ||
| Self, | ||
| oneshot::Receiver<Result<Response, UpstreamRequestError>>, | ||
|
|
@@ -590,7 +598,10 @@ impl UploadRequest { | |
| ( | ||
| Self { | ||
| scoping, | ||
| kind: RequestKind::Create { length }, | ||
| kind: RequestKind::Create { | ||
| length, | ||
| attachment_type, | ||
| }, | ||
| sender, | ||
| }, | ||
| rx, | ||
|
|
@@ -610,29 +621,20 @@ impl UploadRequest { | |
| location, | ||
| stream, | ||
| } = stream; | ||
| let length = stream.length(); | ||
|
|
||
| ( | ||
| Self { | ||
| scoping, | ||
| kind: RequestKind::Upload { | ||
| location, | ||
| stream: TakeOnce::new(stream), | ||
| length, | ||
| encoding: HttpEncoding::Zstd, // just a default, will be overwritten by .configure() | ||
| }, | ||
| sender, | ||
| }, | ||
| rx, | ||
| ) | ||
| } | ||
|
|
||
| /// Returns the length of the upload, if known. | ||
| fn length(&self) -> Option<usize> { | ||
| match &self.kind { | ||
| RequestKind::Create { length } | RequestKind::Upload { length, .. } => *length, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Debug for UploadRequest { | ||
|
|
@@ -690,24 +692,30 @@ impl UpstreamRequest for UploadRequest { | |
| } | ||
|
|
||
| fn build(&mut self, builder: &mut RequestBuilder) -> Result<(), HttpError> { | ||
| let upload_length = self.length(); | ||
| if let RequestKind::Upload { | ||
| stream, encoding, .. | ||
| } = &mut self.kind | ||
| { | ||
| let Some(body) = RetryableStream::new(stream.clone()) else { | ||
| relay_log::error!("upload request stream was already consumed"); | ||
| return Err(HttpError::Misconfigured); | ||
| }; | ||
| tus::add_upload_headers(builder); | ||
|
|
||
| let body = encode_body(body, *encoding); | ||
| builder.content_encoding(*encoding); | ||
|
|
||
| builder.body(reqwest::Body::wrap_stream(body)); | ||
| } else { | ||
| tus::add_creation_headers(upload_length, builder); | ||
| } | ||
| match &mut self.kind { | ||
| RequestKind::Create { | ||
| length, | ||
| attachment_type, | ||
| } => { | ||
| tus::add_creation_headers(*length, *attachment_type, builder)?; | ||
| } | ||
| RequestKind::Upload { | ||
| location: _, | ||
| stream, | ||
| encoding, | ||
| } => { | ||
| let Some(body) = RetryableStream::new(stream.clone()) else { | ||
| relay_log::error!("upload request stream was already consumed"); | ||
| return Err(HttpError::Misconfigured); | ||
| }; | ||
| tus::add_upload_headers(builder); | ||
|
|
||
| let body = encode_body(body, *encoding); | ||
| builder.content_encoding(*encoding); | ||
|
|
||
| builder.body(reqwest::Body::wrap_stream(body)); | ||
| } | ||
| }; | ||
|
|
||
| let project_key = self.scoping.project_key; | ||
| builder.header("X-Sentry-Auth", format!("Sentry sentry_key={project_key}")); | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.