Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(proto): Remove error log when source_event_id is not present #21257

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
ArunPiduguDD marked this conversation as resolved.
Show resolved Hide resolved
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
Loading