Skip to content

Commit

Permalink
ref: Update code due to dropped Copy implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-auer committed Apr 27, 2022
1 parent fd68966 commit baed735
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 deletions.
28 changes: 14 additions & 14 deletions relay-server/src/actors/envelopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ impl EnvelopeProcessor {
/// is written back into the item.
fn process_user_reports(&self, state: &mut ProcessEnvelopeState) {
state.envelope.retain_items(|item| {
if item.ty() != ItemType::UserReport {
if item.ty() != &ItemType::UserReport {
return true;
};

Expand Down Expand Up @@ -831,7 +831,7 @@ impl EnvelopeProcessor {
if self.config.processing_enabled() {
state
.envelope
.retain_items(|item| item.ty() != ItemType::ClientReport);
.retain_items(|item| item.ty() != &ItemType::ClientReport);
}
return;
}
Expand All @@ -846,7 +846,7 @@ impl EnvelopeProcessor {
// we're going through all client reports but we're effectively just merging
// them into the first one.
state.envelope.retain_items(|item| {
if item.ty() != ItemType::ClientReport {
if item.ty() != &ItemType::ClientReport {
return true;
};
match ClientReport::parse(&item.payload()) {
Expand Down Expand Up @@ -1038,7 +1038,7 @@ impl EnvelopeProcessor {
fn expand_unreal(&self, state: &mut ProcessEnvelopeState) -> Result<(), ProcessingError> {
let envelope = &mut state.envelope;

if let Some(item) = envelope.take_item_by(|item| item.ty() == ItemType::UnrealReport) {
if let Some(item) = envelope.take_item_by(|item| item.ty() == &ItemType::UnrealReport) {
utils::expand_unreal_envelope(item, envelope, &self.config)?;
}

Expand Down Expand Up @@ -1302,11 +1302,11 @@ impl EnvelopeProcessor {
// Remove all items first, and then process them. After this function returns, only
// attachments can remain in the envelope. The event will be added again at the end of
// `process_event`.
let event_item = envelope.take_item_by(|item| item.ty() == ItemType::Event);
let transaction_item = envelope.take_item_by(|item| item.ty() == ItemType::Transaction);
let security_item = envelope.take_item_by(|item| item.ty() == ItemType::Security);
let raw_security_item = envelope.take_item_by(|item| item.ty() == ItemType::RawSecurity);
let form_item = envelope.take_item_by(|item| item.ty() == ItemType::FormData);
let event_item = envelope.take_item_by(|item| item.ty() == &ItemType::Event);
let transaction_item = envelope.take_item_by(|item| item.ty() == &ItemType::Transaction);
let security_item = envelope.take_item_by(|item| item.ty() == &ItemType::Security);
let raw_security_item = envelope.take_item_by(|item| item.ty() == &ItemType::RawSecurity);
let form_item = envelope.take_item_by(|item| item.ty() == &ItemType::FormData);
let attachment_item = envelope
.take_item_by(|item| item.attachment_type() == Some(AttachmentType::EventPayload));
let breadcrumbs1 = envelope
Expand All @@ -1316,7 +1316,7 @@ impl EnvelopeProcessor {

// Event items can never occur twice in an envelope.
if let Some(duplicate) = envelope.get_item_by(|item| self.is_duplicate(item)) {
return Err(ProcessingError::DuplicateItem(duplicate.ty()));
return Err(ProcessingError::DuplicateItem(duplicate.ty().clone()));
}

let (event, event_len) = if let Some(mut item) = event_item.or(security_item) {
Expand Down Expand Up @@ -2010,7 +2010,7 @@ impl Handler<ProcessMetrics> for EnvelopeProcessor {

for item in items {
let payload = item.payload();
if item.ty() == ItemType::Metrics {
if item.ty() == &ItemType::Metrics {
let mut timestamp = item.timestamp().unwrap_or(received_timestamp);
clock_drift_processor.process_timestamp(&mut timestamp);

Expand All @@ -2027,7 +2027,7 @@ impl Handler<ProcessMetrics> for EnvelopeProcessor {
relay_log::trace!("inserting metrics into project cache");
project_cache.do_send(InsertMetrics::new(public_key, metrics));
}
} else if item.ty() == ItemType::MetricBuckets {
} else if item.ty() == &ItemType::MetricBuckets {
match Bucket::parse_all(&payload) {
Ok(mut buckets) => {
for bucket in &mut buckets {
Expand Down Expand Up @@ -3040,7 +3040,7 @@ mod tests {
let new_envelope = envelope_response.envelope.unwrap();

assert_eq!(new_envelope.len(), 1);
assert_eq!(new_envelope.items().next().unwrap().ty(), ItemType::Event);
assert_eq!(new_envelope.items().next().unwrap().ty(), &ItemType::Event);
}

#[test]
Expand Down Expand Up @@ -3153,7 +3153,7 @@ mod tests {

let envelope = envelope_response.envelope.unwrap();
let item = envelope.items().next().unwrap();
assert_eq!(item.ty(), ItemType::ClientReport);
assert_eq!(item.ty(), &ItemType::ClientReport);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions relay-server/src/actors/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ impl Message for StoreEnvelope {
///
/// Slow items must be routed to the `Attachments` topic.
fn is_slow_item(item: &Item) -> bool {
item.ty() == ItemType::Attachment || item.ty() == ItemType::UserReport
item.ty() == &ItemType::Attachment || item.ty() == &ItemType::UserReport
}

impl Handler<StoreEnvelope> for StoreForwarder {
Expand All @@ -712,7 +712,7 @@ impl Handler<StoreEnvelope> for StoreForwarder {

let topic = if envelope.get_item_by(is_slow_item).is_some() {
KafkaTopic::Attachments
} else if event_item.map(|x| x.ty()) == Some(ItemType::Transaction) {
} else if event_item.map(|x| x.ty()) == Some(&ItemType::Transaction) {
KafkaTopic::Transactions
} else {
KafkaTopic::Events
Expand Down
4 changes: 2 additions & 2 deletions relay-server/src/endpoints/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub fn event_id_from_formdata(data: &[u8]) -> Result<Option<EventId>, BadStoreRe
/// Extracting the event id from chunked formdata fields on the Minidump endpoint (`sentry__1`,
/// `sentry__2`, ...) is not supported. In this case, `None` is returned.
pub fn event_id_from_items(items: &Items) -> Result<Option<EventId>, BadStoreRequest> {
if let Some(item) = items.iter().find(|item| item.ty() == ItemType::Event) {
if let Some(item) = items.iter().find(|item| item.ty() == &ItemType::Event) {
if let Some(event_id) = event_id_from_json(&item.payload())? {
return Ok(Some(event_id));
}
Expand All @@ -262,7 +262,7 @@ pub fn event_id_from_items(items: &Items) -> Result<Option<EventId>, BadStoreReq
}
}

if let Some(item) = items.iter().find(|item| item.ty() == ItemType::FormData) {
if let Some(item) = items.iter().find(|item| item.ty() == &ItemType::FormData) {
// Swallow all other errors here since it is quite common to receive invalid secondary
// payloads. `EnvelopeProcessor` also retains events in such cases.
if let Ok(Some(event_id)) = event_id_from_formdata(&item.payload()) {
Expand Down
26 changes: 13 additions & 13 deletions relay-server/src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl ItemType {

impl fmt::Display for ItemType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
match self {
Self::Event => write!(f, "event"),
Self::Transaction => write!(f, "transaction"),
Self::Security => write!(f, "security report"),
Expand Down Expand Up @@ -454,8 +454,8 @@ impl Item {
}

/// Returns the `ItemType` of this item.
pub fn ty(&self) -> ItemType {
self.headers.ty
pub fn ty(&self) -> &ItemType {
&self.headers.ty
}

/// Returns the length of this item's payload.
Expand Down Expand Up @@ -1140,7 +1140,7 @@ mod tests {

let items: Vec<_> = envelope.items().collect();
assert_eq!(items.len(), 1);
assert_eq!(items[0].ty(), ItemType::Attachment);
assert_eq!(items[0].ty(), &ItemType::Attachment);
}

#[test]
Expand All @@ -1157,13 +1157,13 @@ mod tests {
envelope.add_item(item2);

let taken = envelope
.take_item_by(|item| item.ty() == ItemType::Attachment)
.take_item_by(|item| item.ty() == &ItemType::Attachment)
.expect("should return some item");

assert_eq!(taken.filename(), Some("item1"));

assert!(envelope
.take_item_by(|item| item.ty() == ItemType::Event)
.take_item_by(|item| item.ty() == &ItemType::Event)
.is_none());
}

Expand Down Expand Up @@ -1319,15 +1319,15 @@ mod tests {
assert_eq!(envelope.len(), 2);
let items: Vec<_> = envelope.items().collect();

assert_eq!(items[0].ty(), ItemType::Attachment);
assert_eq!(items[0].ty(), &ItemType::Attachment);
assert_eq!(items[0].len(), 10);
assert_eq!(
items[0].payload(),
Bytes::from(&b"\xef\xbb\xbfHello\r\n"[..])
);
assert_eq!(items[0].content_type(), Some(&ContentType::Text));

assert_eq!(items[1].ty(), ItemType::Event);
assert_eq!(items[1].ty(), &ItemType::Event);
assert_eq!(items[1].len(), 41);
assert_eq!(
items[1].payload(),
Expand Down Expand Up @@ -1492,7 +1492,7 @@ mod tests {
envelope.add_item(Item::new(ItemType::Attachment));

// Does not split when no item matches.
let split_opt = envelope.split_by(|item| item.ty() == ItemType::Session);
let split_opt = envelope.split_by(|item| item.ty() == &ItemType::Session);
assert!(split_opt.is_none());
}

Expand All @@ -1503,7 +1503,7 @@ mod tests {
envelope.add_item(Item::new(ItemType::Session));

// Does not split when all items match.
let split_opt = envelope.split_by(|item| item.ty() == ItemType::Session);
let split_opt = envelope.split_by(|item| item.ty() == &ItemType::Session);
assert!(split_opt.is_none());
}

Expand All @@ -1513,19 +1513,19 @@ mod tests {
envelope.add_item(Item::new(ItemType::Session));
envelope.add_item(Item::new(ItemType::Attachment));

let split_opt = envelope.split_by(|item| item.ty() == ItemType::Session);
let split_opt = envelope.split_by(|item| item.ty() == &ItemType::Session);
let split_envelope = split_opt.expect("split_by returns an Envelope");

assert_eq!(split_envelope.len(), 1);
assert_eq!(split_envelope.event_id(), envelope.event_id());

// Matching items have moved into the split envelope.
for item in split_envelope.items() {
assert_eq!(item.ty(), ItemType::Session);
assert_eq!(item.ty(), &ItemType::Session);
}

for item in envelope.items() {
assert_eq!(item.ty(), ItemType::Attachment);
assert_eq!(item.ty(), &ItemType::Attachment);
}
}
}
6 changes: 3 additions & 3 deletions relay-server/src/utils/dynamic_sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn sample_transaction_internal(
}

let trace_context = envelope.trace_context();
let transaction_item = envelope.get_item_by(|item| item.ty() == ItemType::Transaction);
let transaction_item = envelope.get_item_by(|item| item.ty() == &ItemType::Transaction);

let trace_context = match (trace_context, transaction_item) {
// we don't have what we need, can't sample the transactions in this envelope
Expand All @@ -93,7 +93,7 @@ fn sample_transaction_internal(
if let SamplingResult::Drop(rule_id) = trace_context.should_keep(client_ip, sampling_config) {
// remove transaction and dependent items
if envelope
.take_item_by(|item| item.ty() == ItemType::Transaction)
.take_item_by(|item| item.ty() == &ItemType::Transaction)
.is_some()
{
// we have removed the transaction from the envelope
Expand Down Expand Up @@ -134,7 +134,7 @@ pub fn sample_trace(
Some(project) => project,
};
let trace_context = envelope.trace_context();
let transaction_item = envelope.get_item_by(|item| item.ty() == ItemType::Transaction);
let transaction_item = envelope.get_item_by(|item| item.ty() == &ItemType::Transaction);

// if there is no trace context or there are no transactions to sample return here
if trace_context.is_none() || transaction_item.is_none() {
Expand Down
2 changes: 1 addition & 1 deletion relay-server/src/utils/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ mod tests {
writer.append("blub", "blub");

let item = writer.into_item();
assert_eq!(item.ty(), ItemType::FormData);
assert_eq!(item.ty(), &ItemType::FormData);

let payload = item.payload();
let iter = FormDataIter::new(&payload);
Expand Down
6 changes: 3 additions & 3 deletions relay-server/src/utils/rate_limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl EnvelopeSummary {
for item in envelope.items() {
if item.creates_event() {
summary.infer_category(item);
} else if item.ty() == ItemType::Attachment {
} else if item.ty() == &ItemType::Attachment {
// Plain attachments do not create events.
summary.has_plain_attachments = true;
}
Expand Down Expand Up @@ -412,7 +412,7 @@ where
}

// Remove attachments, except those required for processing
if enforcement.attachments.is_active() && item.ty() == ItemType::Attachment {
if enforcement.attachments.is_active() && item.ty() == &ItemType::Attachment {
if item.creates_event() {
item.set_rate_limited(true);
return true;
Expand All @@ -422,7 +422,7 @@ where
}

// Remove sessions independently of events
if enforcement.sessions.is_active() && item.ty() == ItemType::Session {
if enforcement.sessions.is_active() && item.ty() == &ItemType::Session {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion relay-server/src/utils/unreal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn expand_unreal_envelope(
let crash = Unreal4Crash::parse_with_limit(&payload, config.max_envelope_size())?;

let mut has_event = envelope
.get_item_by(|item| item.ty() == ItemType::Event)
.get_item_by(|item| item.ty() == &ItemType::Event)
.is_some();

for file in crash.files() {
Expand Down

0 comments on commit baed735

Please sign in to comment.