Skip to content
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

enhancement(codecs): Add semantic meaning to gelf decoded data. #22003

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions changelog.d/22003-gelf-semantic-meaning.enhancement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Set the semantic meaning for `message`, `host` & `timestamp` when decoding gelf messages.

authors: apollo13
38 changes: 34 additions & 4 deletions lib/codecs/src/decoding/format/gelf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,18 @@ impl GelfDeserializerConfig {
[log_namespace],
)
.with_event_field(&owned_value_path!(VERSION), Kind::bytes(), None)
.with_event_field(&owned_value_path!(HOST), Kind::bytes(), None)
.with_event_field(&owned_value_path!(SHORT_MESSAGE), Kind::bytes(), None)
.with_event_field(&owned_value_path!(HOST), Kind::bytes(), Some("host"))
.with_event_field(
&owned_value_path!(SHORT_MESSAGE),
Kind::bytes(),
Some("message"),
)
.optional_field(&owned_value_path!(FULL_MESSAGE), Kind::bytes(), None)
.optional_field(&owned_value_path!(TIMESTAMP), Kind::timestamp(), None)
.optional_field(
&owned_value_path!(TIMESTAMP),
Kind::timestamp(),
Some("timestamp"),
)
.optional_field(&owned_value_path!(LEVEL), Kind::integer(), None)
.optional_field(&owned_value_path!(FACILITY), Kind::bytes(), None)
.optional_field(&owned_value_path!(LINE), Kind::integer(), None)
Expand Down Expand Up @@ -241,6 +249,7 @@ mod tests {
use serde_json::json;
use similar_asserts::assert_eq;
use smallvec::SmallVec;
use std::sync::Arc;
use vector_core::{config::log_schema, event::Event};
use vrl::value::Value;

Expand All @@ -250,7 +259,16 @@ mod tests {
let config = GelfDeserializerConfig::default();
let deserializer = config.build();
let buffer = Bytes::from(serde_json::to_vec(&input).unwrap());
deserializer.parse(buffer, LogNamespace::Legacy)
Ok(deserializer
.parse(buffer, LogNamespace::Legacy)?
.into_iter()
.map(|mut event| {
event.metadata_mut().set_schema_definition(&Arc::new(
config.schema_definition(LogNamespace::Legacy),
));
event
})
.collect())
}

/// Validates all the spec'd fields of GELF are deserialized correctly.
Expand Down Expand Up @@ -287,12 +305,23 @@ mod tests {
log.get(HOST),
Some(&Value::Bytes(Bytes::from_static(b"example.org")))
);
dbg!(&log);
assert_eq!(
log.get_by_meaning("host"),
Some(&Value::Bytes(Bytes::from_static(b"example.org")))
);
assert_eq!(
log.get(log_schema().message_key_target_path().unwrap()),
Some(&Value::Bytes(Bytes::from_static(
b"A short message that helps you identify what is going on"
)))
);
assert_eq!(
log.get_by_meaning("message"),
Some(&Value::Bytes(Bytes::from_static(
b"A short message that helps you identify what is going on"
)))
);
assert_eq!(
log.get(FULL_MESSAGE),
Some(&Value::Bytes(Bytes::from_static(
Expand All @@ -301,6 +330,7 @@ mod tests {
);
let dt = DateTime::from_timestamp(1385053862, 307_200_000).expect("invalid timestamp");
assert_eq!(log.get(TIMESTAMP), Some(&Value::Timestamp(dt)));
assert_eq!(log.get_by_meaning("timestamp"), Some(&Value::Timestamp(dt)));
assert_eq!(log.get(LEVEL), Some(&Value::Integer(1)));
assert_eq!(
log.get(FACILITY),
Expand Down