Skip to content

Commit

Permalink
fix(amqp source): fix crash when handling metrics (vectordotdev#21141)
Browse files Browse the repository at this point in the history
* fix(amqp source): fix crash with metrics using native codec

* Add changelog

Signed-off-by: Zang MingJie <[email protected]>

* Fix format

Signed-off-by: Zang MingJie <[email protected]>

* Update changelog.d/21141_fix_crash_when_handling_metrics.fix.md

---------

Signed-off-by: Zang MingJie <[email protected]>
Co-authored-by: Jesse Szwedko <[email protected]>
  • Loading branch information
kghost and jszwedko authored Aug 27, 2024
1 parent c3c0ec0 commit cade0d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 3 additions & 0 deletions changelog.d/21141_fix_crash_when_handling_metrics.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The `amqp` source no longer panics when deserializing metrics (e.g. via the `native_json` codec).

authors: kghost
18 changes: 9 additions & 9 deletions src/sources/amqp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use vector_lib::configurable::configurable_component;
use vector_lib::lookup::{lookup_v2::OptionalValuePath, metadata_path, owned_value_path, path};
use vector_lib::{
config::{log_schema, LegacyKey, LogNamespace, SourceAcknowledgementsConfig},
event::Event,
event::{Event, LogEvent},
EstimatedJsonEncodedSizeOf,
};
use vector_lib::{
Expand Down Expand Up @@ -236,14 +236,12 @@ struct Keys<'a> {
}

/// Populates the decoded event with extra metadata.
fn populate_event(
event: &mut Event,
fn populate_log_event(
log: &mut LogEvent,
timestamp: Option<chrono::DateTime<Utc>>,
keys: &Keys<'_>,
log_namespace: LogNamespace,
) {
let log = event.as_mut_log();

log_namespace.insert_source_metadata(
AmqpSourceConfig::NAME,
log,
Expand Down Expand Up @@ -348,10 +346,12 @@ async fn receive_event(
));

for mut event in events {
populate_event(&mut event,
timestamp,
&keys,
log_namespace);
if let Event::Log(ref mut log) = event {
populate_log_event(log,
timestamp,
&keys,
log_namespace);
}

yield event;
}
Expand Down

0 comments on commit cade0d2

Please sign in to comment.