vector
vector copied to clipboard
Timezone of path template
Problem
Maybe I just need to update my vector
version, but using 0.16.1 when I want to use templated path
settings for a file sink (https://vector.dev/docs/reference/configuration/sinks/file/#path) then it uses UTC instead of the local timezone.
I don't have a workaround yet, I didn't see VRL like timezone = .t as Asia/Seoul
where t
is the timestamp in the message (but I would prefer using the local system time+date, at least the possibility of timezone = now() as Asia/Seoul
if you don't want to change the default behavior).
Version
vector 0.16.1 unknown linux gnu
References
- https://github.com/vectordotdev/vector/issues/14160
Additional Context
Running vector in non-UTC environment, using template variables (date %Y%m%d)
Have you tried setting https://vector.dev/docs/reference/configuration/global-options/#timezone?
Isn't the local timezone the default? I'll try it regardless
Should take local 👍, curious if it makes a difference though.
https://github.com/vectordotdev/vector/issues/14160#issuecomment-1231615711
this doesn't take affect , facing same issue the path is always set to UTC regardless of what the local TZ is
https://github.com/vectordotdev/vector/issues/14160#issuecomment-1231615711
0.25.1 facing the same issue. global option timezone
not take effect for path template of sinks/file
even if I set specific Asia/Singapore
instead default local
any update on this , it stops us from migrating fully from fluentd to vector
您是否尝试过设置https://vector.dev/docs/reference/configuration/global-options/#timezone?
set timezone: Asia/Shanghai but it does not work .time also is UTC.
timezone: Asia/Shanghai
sources:
kubernetes_logs:
type: kubernetes_logs
timezone: Asia/Shanghai
您是否尝试过设置https://vector.dev/docs/reference/configuration/global-options/#timezone?
设置时区:亚洲/上海 但它不起作用。时间也是UTC。
timezone: Asia/Shanghai sources: kubernetes_logs: type: kubernetes_logs timezone: Asia/Shanghai
my_sink_id:
type: clickhouse
inputs:
- kubernetes_logs
database: ***
endpoint: ***
table: ***
compression: gzip
skip_unknown_fields: true
auth:
user: ***
password: ***
strategy: basic
encoding:
timestamp_format: unix
change the setting ,i got the right time. but the time is 2023-01-11 11:15:38.0
Anyone working on this ? At least workaround should help.
I wrote workaround like this to get local date(%Y-%m-%d) from unix timestamp
.date_utc_seconds, err = .timestamp / 1000
.date_utc, err = to_timestamp(.date_utc_seconds) # convert to UTC string
.date_local, err = format_timestamp(.date_utc, "%Y-%m-%d %H:%M:%S") # remove the timezone info 'Z' from string
.date_local, err = to_timestamp(.date_local) # convert to UTC timezone string with local timezone offset applied
.date_local = to_unix_timestamp(.date_local)
.offset = .date_local - .date_utc_seconds
.date, err = to_timestamp(.date_utc_seconds - .offset)
.date, err = format_timestamp(.date, "%Y-%m-%d")
So you can write your own workaround like this (tested on vector 0.27.0)
.ts_utc = now()
.ts_local, err = format_timestamp(.ts_utc, "%Y-%m-%d %H:%M:%S")
.ts_local, err = to_timestamp(.ts_local)
.ts_local = to_unix_timestamp(.ts_local)
.offset = .ts_local - to_unix_timestamp(.ts_utc)
.ts_local, err = to_timestamp(to_unix_timestamp(.ts_utc) - .offset)
.ts_local, err = format_timestamp(.ts_local, "%Y-%m-%d %H:%M:%S")
It will follow your timezone setting or follow machine timezone if you don't set explicit timezone