vector icon indicating copy to clipboard operation
vector copied to clipboard

Timezone of path template

Open alippai opened this issue 2 years ago • 8 comments

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)

alippai avatar Aug 30 '22 03:08 alippai

Have you tried setting https://vector.dev/docs/reference/configuration/global-options/#timezone?

spencergilbert avatar Aug 30 '22 12:08 spencergilbert

Isn't the local timezone the default? I'll try it regardless

alippai avatar Aug 30 '22 12:08 alippai

Should take local 👍, curious if it makes a difference though.

spencergilbert avatar Aug 30 '22 12:08 spencergilbert

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

ahsandar avatar Oct 10 '22 06:10 ahsandar

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

Jazznight avatar Nov 17 '22 10:11 Jazznight

any update on this , it stops us from migrating fully from fluentd to vector

ahsandar avatar Dec 06 '22 06:12 ahsandar

您是否尝试过设置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

easayliu avatar Jan 11 '23 02:01 easayliu

您是否尝试过设置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

easayliu avatar Jan 11 '23 03:01 easayliu

Anyone working on this ? At least workaround should help.

madan-wego avatar Mar 18 '23 13:03 madan-wego

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

sae-bom avatar Jun 26 '23 03:06 sae-bom