Skip to content

Commit 610f74a

Browse files
committed
Insert fields as event_path so names aren't parsed as a path
Signed-off-by: Stephen Wakely <[email protected]>
1 parent 5b1219f commit 610f74a

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/sources/splunk_hec/mod.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use chrono::{DateTime, TimeZone, Utc};
1010
use flate2::read::MultiGzDecoder;
1111
use futures::FutureExt;
1212
use http::StatusCode;
13-
use lookup::owned_value_path;
13+
use lookup::{event_path, owned_value_path};
1414
use serde::Serialize;
1515
use serde_json::{de::Read as JsonRead, Deserializer, Value as JsonValue};
1616
use snafu::Snafu;
@@ -818,7 +818,7 @@ impl<'de, R: JsonRead<'de>> EventIterator<'de, R> {
818818
}
819819

820820
for (key, value) in object {
821-
log.insert(key.as_str(), value);
821+
log.insert(event_path!(key.as_str()), value);
822822
}
823823
}
824824
_ => return Err(ApiError::InvalidDataFormat { event: self.events }.into()),
@@ -1571,6 +1571,28 @@ mod tests {
15711571
assert!(event.metadata().splunk_hec_token().is_none());
15721572
}
15731573

1574+
#[tokio::test]
1575+
async fn json_invalid_path_event() {
1576+
let (sink, source) = start(
1577+
JsonSerializerConfig::default().into(),
1578+
Compression::gzip_default(),
1579+
None,
1580+
)
1581+
.await;
1582+
1583+
let mut log = LogEvent::default();
1584+
// Test with a field that would be considered an invalid path if it were to
1585+
// be treated as a path and not a simple field name.
1586+
log.insert(event_path!("(greeting | thing"), "hello");
1587+
sink.run_events(vec![log.into()]).await.unwrap();
1588+
1589+
let event = collect_n(source, 1).await.remove(0).into_log();
1590+
assert_eq!(
1591+
event.get(event_path!("(greeting | thing")),
1592+
Some(&Value::from("hello"))
1593+
);
1594+
}
1595+
15741596
#[tokio::test]
15751597
async fn line_to_message() {
15761598
let (sink, source) = start(

0 commit comments

Comments
 (0)