From 1136f76d983422fa2f4ae240197d7e43ef2b6435 Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Tue, 4 Jun 2024 09:02:48 +0200 Subject: [PATCH] Revert "wip: Size depleted vs. size exceeded" This reverts commit e6d228208c57de3c67c095cd58e72a0e2cd44fa5. --- relay-event-normalization/src/trimming.rs | 35 +++++++++-------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/relay-event-normalization/src/trimming.rs b/relay-event-normalization/src/trimming.rs index c4ed933de6..e83b88f31b 100644 --- a/relay-event-normalization/src/trimming.rs +++ b/relay-event-normalization/src/trimming.rs @@ -11,7 +11,7 @@ use relay_protocol::{Annotated, Array, Empty, Meta, Object, RemarkType, Value}; struct SizeState { max_depth: Option, encountered_at_depth: usize, - size_remaining: Option, + size_remaining: Option, } /// Limits properties to a maximum size and depth. @@ -48,20 +48,12 @@ impl TrimmingProcessor { } #[inline] - fn remaining_size(&self) -> Option { + fn remaining_size(&self) -> Option { self.size_state .iter() .filter_map(|x| x.size_remaining) .min() } - - fn size_depleted(&self) -> bool { - matches!(self.remaining_size(), Some(n) if n <= 0) - } - - fn size_exceeded(&self) -> bool { - matches!(dbg!(self.remaining_size()), Some(n) if n < 0) - } } impl Processor for TrimmingProcessor { @@ -76,14 +68,14 @@ impl Processor for TrimmingProcessor { // XXX(iker): test setting only one of the two attributes. if state.attrs().max_bytes.is_some() || state.attrs().max_depth.is_some() { self.size_state.push(SizeState { - size_remaining: state.attrs().max_bytes.map(|s| s as isize), + size_remaining: state.attrs().max_bytes, encountered_at_depth: state.depth(), max_depth: state.attrs().max_depth, }); } if state.attrs().trim { - if self.size_depleted() { + if self.remaining_size() == Some(0) { // TODO: Create remarks (ensure they do not bloat event) return Err(ProcessingAction::DeleteValueHard); } @@ -123,7 +115,7 @@ impl Processor for TrimmingProcessor { let item_length = relay_protocol::estimate_size_flat(value) + 1; size_state.size_remaining = size_state .size_remaining - .map(|size| size.saturating_sub_unsigned(item_length)); + .map(|size| size.saturating_sub(item_length)); } } @@ -145,7 +137,7 @@ impl Processor for TrimmingProcessor { if let Some(size_state) = self.size_state.last() { if let Some(size_remaining) = size_state.size_remaining { - trim_string(value, meta, size_remaining.try_into().unwrap_or(0), 0); + trim_string(value, meta, size_remaining, 0); } } @@ -175,7 +167,7 @@ impl Processor for TrimmingProcessor { let mut split_index = None; for (index, item) in value.iter_mut().enumerate() { - if self.size_depleted() { + if self.remaining_size().unwrap() == 0 { split_index = Some(index); break; } @@ -183,8 +175,8 @@ impl Processor for TrimmingProcessor { let item_state = state.enter_index(index, None, ValueType::for_field(item)); processor::process_value(item, self, &item_state)?; - // Remaining size might now be negative because of `trim = "false"`. - if self.size_exceeded() { + // Remaining size might now be zero because of `trim = "false"`. + if self.remaining_size().unwrap() == 0 { split_index = Some(index); break; } @@ -227,7 +219,7 @@ impl Processor for TrimmingProcessor { let mut split_key = None; for (key, item) in value.iter_mut() { - if dbg!(self.size_depleted()) { + if self.remaining_size().unwrap() == 0 { split_key = Some(key.to_owned()); break; } @@ -235,8 +227,8 @@ impl Processor for TrimmingProcessor { let item_state = state.enter_borrowed(key, None, ValueType::for_field(item)); processor::process_value(item, self, &item_state)?; - // Remaining size might now be negative because of `trim = "false"`. - if dbg!(self.size_exceeded()) { + // Remaining size might now be zero because of `trim = "false"`. + if self.remaining_size().unwrap() == 0 { split_key = Some(key.to_owned()); break; } @@ -722,7 +714,6 @@ mod tests { .len(), 5000 ); - dbg!(i); assert_eq!( other .get("foo") @@ -970,7 +961,7 @@ mod tests { let mut processor = TrimmingProcessor::new(); processor::process_value(&mut event, &mut processor, ProcessingState::root()).unwrap(); - assert_eq!(event.0.unwrap().spans.0.unwrap().len(), 7); + assert_eq!(event.0.unwrap().spans.0.unwrap().len(), 8); } #[test]