Skip to content

Commit

Permalink
Revert "wip: Size depleted vs. size exceeded"
Browse files Browse the repository at this point in the history
This reverts commit e6d2282.
  • Loading branch information
jjbayer committed Jun 4, 2024
1 parent e6d2282 commit 1136f76
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions relay-event-normalization/src/trimming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use relay_protocol::{Annotated, Array, Empty, Meta, Object, RemarkType, Value};
struct SizeState {
max_depth: Option<usize>,
encountered_at_depth: usize,
size_remaining: Option<isize>,
size_remaining: Option<usize>,
}

/// Limits properties to a maximum size and depth.
Expand Down Expand Up @@ -48,20 +48,12 @@ impl TrimmingProcessor {
}

#[inline]
fn remaining_size(&self) -> Option<isize> {
fn remaining_size(&self) -> Option<usize> {
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 {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -175,16 +167,16 @@ 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;
}

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;
}
Expand Down Expand Up @@ -227,16 +219,16 @@ 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;
}

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;
}
Expand Down Expand Up @@ -722,7 +714,6 @@ mod tests {
.len(),
5000
);
dbg!(i);
assert_eq!(
other
.get("foo")
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 1136f76

Please sign in to comment.