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

Add another chrono format to convert timestamp to string #867

Closed
xcaptain opened this issue Sep 16, 2019 · 3 comments

Comments

@xcaptain
Copy link

@xcaptain xcaptain commented Sep 16, 2019

The current https://docs.vector.dev/usage/configuration/transforms/coercer support to convert string to timestamp, would be better if we can add a second option to convert string to timestamp like:

localtime = "timestamp|%+|%F"

this situation is common like nginx produces iso 8601 timestamp but the storage(like clickhouse) would prefer a local time, so would be better to format timestamp to string again

@xcaptain

This comment has been minimized.

Copy link
Author

@xcaptain xcaptain commented Sep 16, 2019

This should be easy to implement, if you want I can make a pull request

@binarylogic

This comment has been minimized.

Copy link
Member

@binarylogic binarylogic commented Sep 16, 2019

Interesting, thanks for reporting. That makes sense and we would welcome a pull request for this.

@binarylogic binarylogic added this to the Improve data processing milestone Sep 17, 2019
@xcaptain

This comment has been minimized.

Copy link
Author

@xcaptain xcaptain commented Sep 26, 2019

Using lua script solved this problem

function convertIso8601(s)
  local p='(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)'
  local year,month,day,hour,min,sec,tz=s:match(p)
  return os.date("%Y-%m-%d %T",os.time({day=day,month=month,year=year,hour=hour,min=min,sec=sec}))
end
event['localtime'] = convertIso8601(event['localtime'])
@xcaptain xcaptain closed this Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.