Skip to content

Commit

Permalink
enhancement(demo_logs source): Add host to emitted logs (#20754)
Browse files Browse the repository at this point in the history
I think it's reasonable for this field to be set by default.

Closes: #20726

Signed-off-by: Jesse Szwedko <[email protected]>
  • Loading branch information
jszwedko authored Jun 28, 2024
1 parent 476016b commit 3de6f0b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelog.d/demo_logs_host.enhancement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The `demo_logs` source now adds `host` (or the configured `log_schema.host_key`) with the value of
`localhost` to emitted logs.
25 changes: 25 additions & 0 deletions src/sources/demo_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ async fn demo_logs_source(
path!("service"),
"vector",
);
log_namespace.insert_source_metadata(
DemoLogsConfig::NAME,
log,
Some(LegacyKey::InsertIfEmpty(path!("host"))),
path!("host"),
"localhost",
);

event
});
Expand Down Expand Up @@ -483,6 +490,24 @@ mod tests {
assert!(duration >= Duration::from_secs(2));
}

#[tokio::test]
async fn host_is_set() {
let host_key = log_schema().host_key().unwrap().to_string();
let mut rx = runit(
r#"format = "syslog"
count = 5"#,
)
.await;

let event = match poll!(rx.next()) {
Poll::Ready(event) => event.unwrap(),
_ => unreachable!(),
};
let log = event.as_log();
let host = log[&host_key].to_string_lossy();
assert_eq!("localhost", host);
}

#[tokio::test]
async fn apache_common_format_generates_output() {
let mut rx = runit(
Expand Down

0 comments on commit 3de6f0b

Please sign in to comment.