Skip to content

fix(splunk_hec source): insert fields as event_path so names aren't parsed as a path #17943

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

Merged
merged 1 commit into from
Jul 11, 2023
Merged
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
26 changes: 24 additions & 2 deletions src/sources/splunk_hec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use chrono::{DateTime, TimeZone, Utc};
use flate2::read::MultiGzDecoder;
use futures::FutureExt;
use http::StatusCode;
use lookup::owned_value_path;
use lookup::{event_path, owned_value_path};
use serde::Serialize;
use serde_json::{de::Read as JsonRead, Deserializer, Value as JsonValue};
use snafu::Snafu;
Expand Down Expand Up @@ -818,7 +818,7 @@ impl<'de, R: JsonRead<'de>> EventIterator<'de, R> {
}

for (key, value) in object {
log.insert(key.as_str(), value);
log.insert(event_path!(key.as_str()), value);
}
}
_ => return Err(ApiError::InvalidDataFormat { event: self.events }.into()),
Expand Down Expand Up @@ -1571,6 +1571,28 @@ mod tests {
assert!(event.metadata().splunk_hec_token().is_none());
}

#[tokio::test]
async fn json_invalid_path_event() {
let (sink, source) = start(
JsonSerializerConfig::default().into(),
Compression::gzip_default(),
None,
)
.await;

let mut log = LogEvent::default();
// Test with a field that would be considered an invalid path if it were to
// be treated as a path and not a simple field name.
log.insert(event_path!("(greeting | thing"), "hello");
sink.run_events(vec![log.into()]).await.unwrap();

let event = collect_n(source, 1).await.remove(0).into_log();
assert_eq!(
event.get(event_path!("(greeting | thing")),
Some(&Value::from("hello"))
);
}

#[tokio::test]
async fn line_to_message() {
let (sink, source) = start(
Expand Down