Skip to content

Commit 15a63b4

Browse files
authored
fix(remap transform): log namespace should be used when splitting events from arrays (#18372)
fix remap array return values when using the Vector namespace
1 parent eac3cd0 commit 15a63b4

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

lib/vector-core/src/event/vrl_target.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub struct TargetIter<T> {
5050
iter: std::vec::IntoIter<Value>,
5151
metadata: EventMetadata,
5252
_marker: PhantomData<T>,
53+
log_namespace: LogNamespace,
5354
}
5455

5556
fn create_log_event(value: Value, metadata: EventMetadata) -> LogEvent {
@@ -63,9 +64,12 @@ impl Iterator for TargetIter<LogEvent> {
6364

6465
fn next(&mut self) -> Option<Self::Item> {
6566
self.iter.next().map(|v| {
66-
match v {
67-
value @ Value::Object(_) => LogEvent::from_parts(value, self.metadata.clone()),
68-
value => create_log_event(value, self.metadata.clone()),
67+
match self.log_namespace {
68+
LogNamespace::Legacy => match v {
69+
value @ Value::Object(_) => LogEvent::from_parts(value, self.metadata.clone()),
70+
value => create_log_event(value, self.metadata.clone()),
71+
},
72+
LogNamespace::Vector => LogEvent::from_parts(v, self.metadata.clone()),
6973
}
7074
.into()
7175
})
@@ -142,6 +146,7 @@ impl VrlTarget {
142146
iter: values.into_iter(),
143147
metadata,
144148
_marker: PhantomData,
149+
log_namespace,
145150
}),
146151

147152
v => match log_namespace {
@@ -161,6 +166,7 @@ impl VrlTarget {
161166
iter: values.into_iter(),
162167
metadata,
163168
_marker: PhantomData,
169+
log_namespace,
164170
}),
165171

166172
v => TargetEvents::One(create_log_event(v, metadata).into()),

src/transforms/remap.rs

+51
Original file line numberDiff line numberDiff line change
@@ -1890,4 +1890,55 @@ mod tests {
18901890
outputs1[0].schema_definitions(true),
18911891
);
18921892
}
1893+
1894+
#[test]
1895+
fn check_remap_array_vector_namespace() {
1896+
let event = {
1897+
let mut event = LogEvent::from("input");
1898+
// mark the event as a "Vector" namespaced log
1899+
event
1900+
.metadata_mut()
1901+
.value_mut()
1902+
.insert("vector", BTreeMap::new());
1903+
Event::from(event)
1904+
};
1905+
1906+
let conf = RemapConfig {
1907+
source: Some(
1908+
r#". = [null]
1909+
"#
1910+
.to_string(),
1911+
),
1912+
file: None,
1913+
drop_on_error: true,
1914+
drop_on_abort: false,
1915+
..Default::default()
1916+
};
1917+
let mut tform = remap(conf.clone()).unwrap();
1918+
let result = transform_one(&mut tform, event).unwrap();
1919+
1920+
// Legacy namespace nests this under "message", Vector should set it as the root
1921+
assert_eq!(result.as_log().get("."), Some(&Value::Null));
1922+
1923+
let enrichment_tables = enrichment::TableRegistry::default();
1924+
let outputs1 = conf.outputs(
1925+
enrichment_tables,
1926+
&[(
1927+
"in".into(),
1928+
schema::Definition::new_with_default_metadata(
1929+
Kind::any_object(),
1930+
[LogNamespace::Vector],
1931+
),
1932+
)],
1933+
LogNamespace::Vector,
1934+
);
1935+
1936+
let wanted =
1937+
schema::Definition::new_with_default_metadata(Kind::null(), [LogNamespace::Vector]);
1938+
1939+
assert_eq!(
1940+
HashMap::from([(OutputId::from("in"), wanted)]),
1941+
outputs1[0].schema_definitions(true),
1942+
);
1943+
}
18931944
}

0 commit comments

Comments
 (0)