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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_float can't convert time to unixstamp. #18688

Closed
FengZh61 opened this issue Sep 27, 2023 · 2 comments
Closed

to_float can't convert time to unixstamp. #18688

FengZh61 opened this issue Sep 27, 2023 · 2 comments
Labels
type: bug A code related bug.

Comments

@FengZh61
Copy link

FengZh61 commented Sep 27, 2023

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

Problem

"log_timestamp":"2023-09-27T02:42:40.672720190Z"
.a,err = to_float(.log_timestamp) return 0.0

but .b = to_float(t'2023-09-27T02:42:40.672720190Z') return 1695782560.6727202

Configuration

[sources.file]
type = "file"
include = [ "/opt/file.log" ]
data_dir = "/opt/vector"
# Parse Syslog logs
# See the Vector Remap Language reference for more info: https://vrl.dev
[transforms.parse_logs]
type = "remap"
inputs = ["file"]
source = '''
. = parse_json!(string!(.message))
.a,err = to_float(.log_timestamp)
.b = to_float(t'2023-09-27T02:42:40.672720190Z')
'''

# Print parsed logs to stdout
[sinks.print]
type = "console"
inputs = ["parse_logs"]
encoding.codec = "json"

Version

vector 0.32.2 (x86_64-unknown-linux-musl beb74c1 2023-09-20 19:46:02.271601143)

Debug Output

No response

Example Data

{"log_timestamp":"2023-09-27T02:42:40.672720190Z","source":"localhost"}

Additional Context

No response

References

No response

Tasks

Preview Give feedback
No tasks being tracked yet.
@FengZh61 FengZh61 added the type: bug A code related bug. label Sep 27, 2023
@jszwedko
Copy link
Member

Hi @FengZh61 !

This is expected behavior as to_float can only convert actual timestamps and not string timestamps. For your first example where you have a string timestamp you can use:

.a,err = to_float(parse_timestamp!(.log_timestamp, "%+"))

To parse the timestamp string first and then convert it to a float.

Hope this helps!

@jszwedko jszwedko closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2023
@FengZh61
Copy link
Author

Hi @FengZh61 !

This is expected behavior as to_float can only convert actual timestamps and not string timestamps. For your first example where you have a string timestamp you can use:

.a,err = to_float(parse_timestamp!(.log_timestamp, "%+"))

To parse the timestamp string first and then convert it to a float.

Hope this helps!

It worked! Thank you~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A code related bug.
Projects
None yet
Development

No branches or pull requests

2 participants