Skip to content

fix(multipart): Use correct discard reasons#5950

Merged
elramen merged 8 commits into
masterfrom
elramen-minidump-outcomes
May 8, 2026
Merged

fix(multipart): Use correct discard reasons#5950
elramen merged 8 commits into
masterfrom
elramen-minidump-outcomes

Conversation

@elramen
Copy link
Copy Markdown
Member

@elramen elramen commented May 6, 2026

Use correct discard reasons for outcomes across multipart endpoints. Also refactor from Vec<Managed<Item>> to Managed<Items> to simplify "all-item"-operations; albeit with a tradeoff of less ergonomic operations on individual items (see the indexing used to access and modify the minidump and proserpodump).

@elramen elramen force-pushed the elramen-minidump-outcomes branch 2 times, most recently from bab71e8 to 3ba99b0 Compare May 6, 2026 15:29
@elramen elramen force-pushed the elramen-minidump-outcomes branch from 3ba99b0 to c055532 Compare May 6, 2026 15:32
@elramen elramen marked this pull request as ready for review May 6, 2026 15:40
@elramen elramen requested a review from a team as a code owner May 6, 2026 15:40
elramen

This comment was marked as off-topic.

@elramen elramen force-pushed the elramen-minidump-outcomes branch from ae96e45 to d4025f1 Compare May 6, 2026 15:52
Comment thread relay-server/src/endpoints/minidump.rs
Comment thread relay-server/src/endpoints/playstation.rs Outdated
Comment on lines +56 to +60
let envelope = items.map(|items, records| {
if items.iter().any(|i| i.creates_event()) {
records.modify_by(DataCategory::Error, 1);
}
Box::new(Envelope::from_request(Some(path.event_id), meta).with_items(items))
Copy link
Copy Markdown
Member Author

@elramen elramen May 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Steered away from a common envelope-creation function because of the complexity of keeping records correct in all cases. Opened #5949 to address this

Comment thread relay-server/src/endpoints/minidump.rs Outdated
Comment thread relay-server/src/endpoints/minidump.rs Outdated
Comment thread relay-server/src/endpoints/minidump.rs
Comment thread relay-server/src/endpoints/common.rs
Comment thread relay-server/src/endpoints/common.rs
@elramen elramen requested a review from Dav1dde May 7, 2026 12:38
Comment thread relay-server/src/utils/multipart.rs
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit eeb45a7. Configure here.

Comment thread relay-server/src/endpoints/minidump.rs
@elramen elramen requested a review from jjbayer May 7, 2026 12:58
Copy link
Copy Markdown
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +127 to +142
impl BadStoreRequest {
pub fn to_outcome(&self) -> Option<Outcome> {
let discard_reason = match self {
Self::InvalidCompressionContainer(_) => DiscardReason::InvalidCompression,
Self::InvalidMinidump => DiscardReason::InvalidMinidump,
#[cfg(sentry)]
Self::InvalidProsperodump => DiscardReason::InvalidProsperodump,
Self::MissingMinidump => DiscardReason::MissingMinidumpUpload,
#[cfg(sentry)]
Self::MissingProsperodump => DiscardReason::MissingProsperodumpUpload,
Self::Overflow(item_type) => DiscardReason::TooLarge(*item_type),
_ => DiscardReason::Internal,
};
Some(Outcome::Invalid(discard_reason))
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but converting BadStoreRequest to a DiscardReason seems backward to me. It would be better to make the functions that currently return BadStoreRequest return a DiscardReason instead, and make that to a BadStoreRequest only if we reject the entire request.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, and maybe we don't need BadStoreRequest at all. But changing all the functions that return BadStoreRequest seems out of scope for this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we have proper scoped errors for these cases.

Also not really happy about:

impl From<Rejected<BadStoreRequest>> for BadStoreRequest {
    fn from(rejected: Rejected<BadStoreRequest>) -> Self {
        rejected.into_inner()
    }
}

This also seems like a workaround rather than a solution and if it was explicit Rejected::into_inner it'd be more visible where there can be improvements.

That being said, this shouldn't block an overall improvement.

inner.set_filename(remove_container_extension(minidump_filename).to_owned())
items.try_modify(|items, records| -> Result<(), BadStoreRequest> {
let minidump_item = &mut items[minidump_idx];
minidump_item.set_payload(Minidump, payload);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR, but I noticed it: we always qualify enum variants:

Suggested change
minidump_item.set_payload(Minidump, payload);
minidump_item.set_payload(ContentType::Minidump, payload);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused, is qualifying something we should or shouldn't do?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our convention is to always use the qualified path, that is MyEnum::MyVariant.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix in another PR

Comment thread relay-server/src/endpoints/minidump.rs
// Doing these operations does not make sense if we already streamed the minidump to objectstore.
if !minidump_item.is_attachment_ref() {
let payload = minidump_item.payload();
if !items[minidump_idx].is_attachment_ref() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit nitpicky, but we do have a guideline to avoid slice syntax as it introduces a place where things can panic, see: https://develop.sentry.dev/engineering-practices/rust/#use-get-instead-of-slice-syntax

This policy while at times may seem useless, it did serve us well so far.

Something like this should do:

Suggested change
if !items[minidump_idx].is_attachment_ref() {
if !items.get(minidump_idx).is_some_and(|item| item.is_attachment_ref()) {

Or some variant of if let Some(x) = _.get() && x.foo()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix in another PR

Comment on lines +127 to +142
impl BadStoreRequest {
pub fn to_outcome(&self) -> Option<Outcome> {
let discard_reason = match self {
Self::InvalidCompressionContainer(_) => DiscardReason::InvalidCompression,
Self::InvalidMinidump => DiscardReason::InvalidMinidump,
#[cfg(sentry)]
Self::InvalidProsperodump => DiscardReason::InvalidProsperodump,
Self::MissingMinidump => DiscardReason::MissingMinidumpUpload,
#[cfg(sentry)]
Self::MissingProsperodump => DiscardReason::MissingProsperodumpUpload,
Self::Overflow(item_type) => DiscardReason::TooLarge(*item_type),
_ => DiscardReason::Internal,
};
Some(Outcome::Invalid(discard_reason))
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we have proper scoped errors for these cases.

Also not really happy about:

impl From<Rejected<BadStoreRequest>> for BadStoreRequest {
    fn from(rejected: Rejected<BadStoreRequest>) -> Self {
        rejected.into_inner()
    }
}

This also seems like a workaround rather than a solution and if it was explicit Rejected::into_inner it'd be more visible where there can be improvements.

That being said, this shouldn't block an overall improvement.

@elramen elramen force-pushed the elramen-minidump-outcomes branch from c0efc1c to ffe03f2 Compare May 8, 2026 10:10
@elramen elramen force-pushed the elramen-minidump-outcomes branch from ffe03f2 to 0176978 Compare May 8, 2026 10:18
Comment thread relay-server/src/utils/multipart.rs
@elramen elramen enabled auto-merge May 8, 2026 10:24
@elramen elramen added this pull request to the merge queue May 8, 2026
Merged via the queue into master with commit 4b2a159 May 8, 2026
30 checks passed
@elramen elramen deleted the elramen-minidump-outcomes branch May 8, 2026 10:56
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

Successfully merging this pull request may close these issues.

3 participants