Skip to content

Commit

Permalink
fix(proto): Remove error log when source_event_id is not present (#21257
Browse files Browse the repository at this point in the history
)

* remove error log

* make source_event_id optional + add error log when failing to parse empty field

* update tag number

* undo proto changes, remove error log, and make source_event_id optional in EventMetadata

* cargo fmt

* fix test + re-add error logic for certain cases
  • Loading branch information
ArunPiduguDD authored and jszwedko committed Sep 10, 2024
1 parent 97952b5 commit 702b221
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
5 changes: 4 additions & 1 deletion lib/vector-core/src/event/log_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,10 @@ mod test {
// Check if event id is UUID v7
let log1 = LogEvent::default();
assert_eq!(
log1.metadata().source_event_id().get_version(),
log1.metadata()
.source_event_id()
.expect("source_event_id should be auto-generated for new events")
.get_version(),
Some(Version::SortRand)
);

Expand Down
8 changes: 4 additions & 4 deletions lib/vector-core/src/event/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub struct EventMetadata {

/// An internal vector id that can be used to identify this event across all components.
#[derivative(PartialEq = "ignore")]
pub(crate) source_event_id: Uuid,
pub(crate) source_event_id: Option<Uuid>,
}

/// Metric Origin metadata for submission to Datadog.
Expand Down Expand Up @@ -223,7 +223,7 @@ impl EventMetadata {
}

/// Returns a reference to the event id.
pub fn source_event_id(&self) -> Uuid {
pub fn source_event_id(&self) -> Option<Uuid> {
self.source_event_id
}
}
Expand All @@ -240,7 +240,7 @@ impl Default for EventMetadata {
upstream_id: None,
dropped_fields: ObjectMap::new(),
datadog_origin_metadata: None,
source_event_id: Uuid::now_v7(),
source_event_id: Some(Uuid::now_v7()),
}
}
}
Expand Down Expand Up @@ -314,7 +314,7 @@ impl EventMetadata {

/// Replaces the existing `source_event_id` with the given one.
#[must_use]
pub fn with_source_event_id(mut self, source_event_id: Uuid) -> Self {
pub fn with_source_event_id(mut self, source_event_id: Option<Uuid>) -> Self {
self.source_event_id = source_event_id;
self
}
Expand Down
21 changes: 16 additions & 5 deletions lib/vector-core/src/event/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ impl From<EventMetadata> for Metadata {
source_type: source_type.map(|s| s.to_string()),
upstream_id: upstream_id.map(|id| id.as_ref().clone()).map(Into::into),
secrets,
source_event_id: source_event_id.into(),
source_event_id: source_event_id.map_or(vec![], std::convert::Into::into),
}
}
}
Expand Down Expand Up @@ -675,11 +675,22 @@ impl From<Metadata> for EventMetadata {
metadata = metadata.with_origin_metadata(origin_metadata.into());
}

if let Ok(uuid) = Uuid::from_slice(&value.source_event_id) {
metadata = metadata.with_source_event_id(uuid);
let maybe_source_event_id = if value.source_event_id.is_empty() {
None
} else {
error!("Invalid source_event_id in metadata");
}
match Uuid::from_slice(&value.source_event_id) {
Ok(id) => Some(id),
Err(error) => {
error!(
message = "Failed to parse source_event_id: {}",
%error,
internal_log_rate_limit = true
);
None
}
}
};
metadata = metadata.with_source_event_id(maybe_source_event_id);

metadata
}
Expand Down

0 comments on commit 702b221

Please sign in to comment.