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 10, 2024
1 parent d38961a commit b16e850
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/22003-gelf-semantic-meaning.enhancement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set the semantic meaning for `host`, `service` & `timestamp` when decoding gelf messages.
9 changes: 6 additions & 3 deletions lib/codecs/src/decoding/format/gelf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ 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!(HOST), Kind::bytes(), Some("host"))
.with_event_field(&owned_value_path!(SHORT_MESSAGE), Kind::bytes(), None)
.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!(FACILITY), Kind::bytes(), Some("service"))
.optional_field(&owned_value_path!(LINE), Kind::integer(), None)
.optional_field(&owned_value_path!(FILE), Kind::bytes(), None)
// Every field with an underscore (_) prefix will be treated as an additional field.
Expand Down Expand Up @@ -287,6 +287,7 @@ 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(
Expand All @@ -301,11 +302,13 @@ 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),
Some(&Value::Bytes(Bytes::from_static(b"foo")))
);
assert_eq!(log.get_by_meaning("service"), Some(&Value::Bytes(Bytes::from_static(b"foo"))));
assert_eq!(
log.get(LINE),
Some(&Value::Float(ordered_float::NotNan::new(42.0).unwrap()))
Expand Down

0 comments on commit b16e850

Please sign in to comment.