vectordotdev / vrl

Vector Remap Language
Mozilla Public License 2.0
115 stars 52 forks source link

from_unix_timestamp float support #823

Open jpds opened 2 months ago

jpds commented 2 months ago

A note for the community

Use Cases

Caddy logs timestamps as floats: "ts":1714987958.264331 - however the from_unix_timestamp only takes integers.

Attempted Solutions

I've worked around this by calling to_int!(.ts), however it'd be nice to keep the sub-second accuracy for request order sorting.

Proposal

No response

References

No response

Version

0.37.1

jpds commented 2 months ago

Looks like this was not intended to support floats: https://github.com/vectordotdev/vrl/blob/4581a47148cef81e9232cb5e72355b5010723371/src/stdlib/from_unix_timestamp.rs#L219-L229

I've worked around this for now by doing:

.tmp_timestamp, err = .ts * 1000
if err != null {
  log("Unable to parse ts value: " + err, level: "error")
} else {
  .timestamp = from_unix_timestamp!(to_int!(.tmp_timestamp), unit: "milliseconds")
  del(.tmp_timestamp)
}
jszwedko commented 2 months ago

👍 it makes sense to me for from_unixtimestamp to support floats. The workaround you discovered is what I would have recommended for now.