Skip to content

fix(humio_logs sink): Set host key correctly #4229

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 2 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion .meta/sinks/humio_logs.toml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,14 @@ description = "The optional endpoint to send Humio logs to."
namespace: "sinks.humio_logs.options",
encodings: ["json", "text"],
default: "json"
) %>
) %>

[sinks.humio_logs.options.host_key]
type = "string"
common = true
examples = ["hostname"]
required = false
description = """\
The name of the log field to be used as the hostname sent to Humio. This \
overrides the [global `host_key` option][docs.reference.global-options#host_key].\
"""
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ ifeq ($(AUTOSPAWN), true)
$(MAKE) start-integration-humio
sleep 10 # Many services are very slow... Give them a sec..
endif
${MAYBE_ENVIRONMENT_EXEC} cargo test --no-fail-fast --no-default-features --features humio-integration-tests --lib ::humio:: -- --nocapture
${MAYBE_ENVIRONMENT_EXEC} cargo test --no-fail-fast --no-default-features --features humio-integration-tests --lib ::humio_logs::integration_tests:: -- --nocapture
ifeq ($(AUTODESPAWN), true)
$(MAKE) -k stop-integration-humio
endif
Expand Down
21 changes: 19 additions & 2 deletions src/sinks/humio_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
template::Template,
};
use serde::{Deserialize, Serialize};
use string_cache::DefaultAtom as Atom;

const HOST: &str = "https://cloud.humio.com";

Expand All @@ -25,6 +26,9 @@ pub struct HumioLogsConfig {

event_type: Option<Template>,

#[serde(default = "default_host_key")]
pub host_key: Atom,

#[serde(default)]
pub compression: Compression,

Expand All @@ -35,6 +39,10 @@ pub struct HumioLogsConfig {
batch: BatchConfig,
}

fn default_host_key() -> Atom {
crate::config::LogSchema::default().host_key().clone()
}

inventory::submit! {
SinkDescription::new_without_default::<HumioLogsConfig>("humio_logs")
}
Expand Down Expand Up @@ -85,6 +93,7 @@ impl HumioLogsConfig {
compression: self.compression,
batch: self.batch,
request: self.request,
host_key: self.host_key.clone(),
..Default::default()
}
}
Expand Down Expand Up @@ -133,7 +142,7 @@ mod tests {
mod integration_tests {
use super::*;
use crate::{
config::{SinkConfig, SinkContext},
config::{log_schema, SinkConfig, SinkContext},
sinks::util::Compression,
test_util::random_string,
Event,
Expand All @@ -157,7 +166,10 @@ mod integration_tests {
let (sink, _) = config.build(cx).unwrap();

let message = random_string(100);
let event = Event::from(message.clone());
let host = "192.168.1.1".to_string();
let mut event = Event::from(message.clone());
let log = event.as_mut_log();
log.insert(log_schema().host_key(), host.clone());

sink.run(stream::once(future::ready(event))).await.unwrap();

Expand All @@ -179,6 +191,7 @@ mod integration_tests {
.error_msg
.unwrap_or_else(|| "no error message".to_string())
);
assert_eq!(Some(host), entry.host);
}

#[tokio::test]
Expand Down Expand Up @@ -269,6 +282,7 @@ mod integration_tests {
max_events: Some(1),
..Default::default()
},
host_key: log_schema().host_key().clone(),
..Default::default()
}
}
Expand Down Expand Up @@ -391,6 +405,9 @@ mutation {{
#[serde(rename = "@source")]
source: Option<String>,

#[serde(rename = "@host")]
host: Option<String>,

// fields parsed from ingested log
#[serde(flatten)]
fields: HashMap<String, JsonValue>,
Expand Down