Skip to content

Commit 628904d

Browse files
authored
fix: aws_ec2_metadata transform when using log namespacing (#17819)
closes: #17193 This keeps the same runtime behavior (if the even is not an object, it is converted to an object), but fixes the schema definition calculation to not panic. The behavior might not be optimal since it may result in data loss. Users can remap before hand and convert to an object if needed, and longer term this functionality should be made available in VRL for more flexibility.
1 parent 77ac63c commit 628904d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/transforms/aws_ec2_metadata.rs

+38
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use tokio::time::{sleep, Duration, Instant};
1616
use tracing::Instrument;
1717
use vector_config::configurable_component;
1818
use vector_core::config::LogNamespace;
19+
use vrl::value::kind::Collection;
1920
use vrl::value::Kind;
2021

2122
use crate::config::OutputId;
@@ -274,6 +275,11 @@ impl TransformConfig for Ec2Metadata {
274275
.map(|(output, definition)| {
275276
let mut schema_definition = definition.clone();
276277

278+
// If the event is not an object, it will be converted to an object in this transform
279+
if !schema_definition.event_kind().contains_object() {
280+
*schema_definition.event_kind_mut() = Kind::object(Collection::empty());
281+
}
282+
277283
for path in paths {
278284
schema_definition =
279285
schema_definition.with_field(path, Kind::bytes().or_undefined(), None);
@@ -708,6 +714,38 @@ enum Ec2MetadataError {
708714
},
709715
}
710716

717+
#[cfg(test)]
718+
mod test {
719+
use crate::config::schema::Definition;
720+
use crate::config::{LogNamespace, OutputId, TransformConfig};
721+
use crate::transforms::aws_ec2_metadata::Ec2Metadata;
722+
use enrichment::TableRegistry;
723+
use lookup::OwnedTargetPath;
724+
use vrl::owned_value_path;
725+
use vrl::value::Kind;
726+
727+
#[tokio::test]
728+
async fn schema_def_with_string_input() {
729+
let transform_config = Ec2Metadata {
730+
namespace: Some(OwnedTargetPath::event(owned_value_path!("ec2", "metadata")).into()),
731+
..Default::default()
732+
};
733+
734+
let input_definition =
735+
Definition::new(Kind::bytes(), Kind::any_object(), [LogNamespace::Vector]);
736+
737+
let mut outputs = transform_config.outputs(
738+
TableRegistry::default(),
739+
&[(OutputId::dummy(), input_definition)],
740+
LogNamespace::Vector,
741+
);
742+
assert_eq!(outputs.len(), 1);
743+
let output = outputs.pop().unwrap();
744+
let actual_schema_def = output.schema_definitions(true)[&OutputId::dummy()].clone();
745+
assert!(actual_schema_def.event_kind().is_object());
746+
}
747+
}
748+
711749
#[cfg(feature = "aws-ec2-metadata-integration-tests")]
712750
#[cfg(test)]
713751
mod integration_tests {

0 commit comments

Comments
 (0)