datalust / seq-input-gelf

Ingest GELF payloads into Seq
https://datalust.co/seq
Apache License 2.0
15 stars 8 forks source link

Use rust_decimal for GELF timestamp so sub-second precision is not lost #84

Closed mjstrasser closed 3 years ago

mjstrasser commented 3 years ago

I had noticed that timestamp sub-second precision was being lost when importing GELF data into Seq. When GELF events with microsecond resolution were imported, events in Seq were truncated or rounded to millisecond resolution.

In Timestamp::from_float method the code truncates or rounds to milliseconds. I assume that is to avoid rounding errors from floating-point calculations using f64. It is better to use a decimal type that can preserve precision.

This proposal is to use the rust_decimal type. This type makes it straightforward to extract the whole-number part of the decimal and to adjust the scale of the fractional part so it represents nanoseconds.

mjstrasser commented 3 years ago

Hey @KodrAus 👋

Thanks for your help with the Rust! I appreciate you taking the time to help.

I had searched for idiomatic rust option and similar but didn’t find the ? operator. It makes the code way cleaner.

Cheers Michael