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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

from_unix_timestamp float support #823

Open
jpds opened this issue May 6, 2024 · 2 comments
Open

from_unix_timestamp float support #823

jpds opened this issue May 6, 2024 · 2 comments
Labels
type: feature A value-adding code addition that introduce new functionality. vrl: stdlib Changes to the standard library

Comments

@jpds
Copy link

jpds commented May 6, 2024

A note for the community

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

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 jpds added the type: feature A value-adding code addition that introduce new functionality. label May 6, 2024
@jpds
Copy link
Author

jpds commented May 6, 2024

Looks like this was not intended to support floats:

float_type_invalid {
args: func_args![value: 5.123],
want: Err("unable to coerce float into timestamp"),
tdef: TypeDef::timestamp().fallible(),
}
float_type_invalid_milliseconds {
args: func_args![value: 5.123, unit: "milliseconds"],
want: Err("unable to coerce float into timestamp"),
tdef: TypeDef::timestamp().fallible(),
}

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 jszwedko transferred this issue from vectordotdev/vector May 6, 2024
@jszwedko jszwedko added the vrl: stdlib Changes to the standard library label May 6, 2024
@jszwedko
Copy link
Member

jszwedko commented May 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A value-adding code addition that introduce new functionality. vrl: stdlib Changes to the standard library
Projects
None yet
Development

No branches or pull requests

2 participants