Skip to content

Commit

Permalink
fix(metadata): merge 'source_event_id's (#21287)
Browse files Browse the repository at this point in the history
  • Loading branch information
pront authored Sep 12, 2024
1 parent bd65b76 commit 9f56d46
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/vector-core/src/event/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,17 @@ impl EventMetadata {
pub fn merge(&mut self, other: Self) {
self.finalizers.merge(other.finalizers);
self.secrets.merge(other.secrets);

// Update `source_event_id` if necessary.
match (self.source_event_id, other.source_event_id) {
(None, Some(id)) => {
self.source_event_id = Some(id);
}
(Some(uuid1), Some(uuid2)) if uuid2 < uuid1 => {
self.source_event_id = Some(uuid2);
}
_ => {} // Keep the existing value.
};
}

/// Update the finalizer(s) status.
Expand Down Expand Up @@ -523,4 +534,22 @@ mod test {
assert_eq!(a.get("key-b").unwrap().as_ref(), "value-b1");
assert_eq!(a.get("key-c").unwrap().as_ref(), "value-c2");
}

#[test]
fn metadata_source_event_id_merging() {
let m1 = EventMetadata::default();
let m2 = EventMetadata::default();

{
let mut merged = m1.clone();
merged.merge(m2.clone());
assert_eq!(merged.source_event_id, m1.source_event_id);
}

{
let mut merged = m2.clone();
merged.merge(m1.clone());
assert_eq!(merged.source_event_id, m1.source_event_id);
}
}
}

0 comments on commit 9f56d46

Please sign in to comment.