Skip to content

Commit

Permalink
Add semantic meaning to gelf decoded data.
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo13 committed Dec 11, 2024
1 parent d38961a commit 0545b71
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
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 `host` & `timestamp` when decoding gelf messages.

authors: apollo13
25 changes: 22 additions & 3 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 @@ -287,12 +295,22 @@ mod tests {
log.get(HOST),
Some(&Value::Bytes(Bytes::from_static(b"example.org")))
);
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 +319,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

0 comments on commit 0545b71

Please sign in to comment.