docker image does not recognise timezone appropriately
instantdreams opened this issue · comments
Host operating system: output of uname -a
Linux id-media 6.1.0-18-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.76-1 (2024-02-01) x86_64 GNU/Linux
node_exporter version: output of node_exporter --version
$ docker exec node-exporter node_exporter --version
node_exporter, version 1.7.0 (branch: HEAD, revision: 7333465abf9efba81876303bb57e6fadb946041b)
build user: root@35918982f6d8
build date: 20231112-23:53:35
go version: go1.21.4
platform: linux/amd64
tags: netgo osusergo static_build
node_exporter command line flags
From compose.yaml:
command:
- '--path.procfs=/host/proc'
- '--path.rootfs=/rootfs'
- '--path.sysfs=/host/sys'
- '--path.udev.data=/host/run/udev/data'
- '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
- '--collector.cgroups'
- '--collector.processes'
node_exporter log output
node-exporter | ts=2024-03-19T18:56:08.004Z caller=tls_config.go:274 level=info msg="Listening on" address=[::]:9100
node-exporter | ts=2024-03-19T18:56:08.005Z caller=tls_config.go:277 level=info msg="TLS is disabled." http2=false address=[::]:9100
Are you running node_exporter in Docker?
Yes
What did you do that produced an error?
My compose.yaml file includes the following:
services:
node_exporter:
image: quay.io/prometheus/node-exporter:latest
container_name: node-exporter
hostname: node-exporter
command:
- '--path.procfs=/host/proc'
- '--path.rootfs=/rootfs'
- '--path.sysfs=/host/sys'
- '--path.udev.data=/host/run/udev/data'
- '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
- '--collector.cgroups'
- '--collector.processes'
ports:
- 9100:9100 # web ui
environment:
- TZ=America/Edmonton
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /run/udev/data:/host/run/udev/data:ro
- /:/rootfs:ro
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
restart: unless-stopped
All logs have UTC times rather than host timezone times.
What did you expect to see?
I expect the timezone in the docker container to match the host.
What did you see instead?
The following commands:
$ docker exec node-exporter-5 cat /etc/timezone
cat: can't open '/etc/timezone': No such file or directory
$ docker exec node-exporter-5 date
Mon Apr 15 16:49:03 UTC 2024
It appears the docker container does not have tzdata loaded. Can this be added?
Not oppose to this in general but I feel @beorn7 might have opinions on this 😬
This is not actually a Docker container issue, nor even a node_exporter issue. The log timestamp control is hard coded to UTC in common/promlog.
If you want logs in a local timestamp, docker logs -t
or journalctl -u
will print local timestamps.
This is an issue with the docker image - tzdata is not being passed for timezone support. Of all the other containers I have, there are a small number (node_reporter, loki, prometheus, one or two others) that fail to do this.
It is not about the local timestamps either. Here's some test results.
First, using docker:
$ docker logs node-exporter-1
ts=2024-04-17T17:37:05.228Z caller=tls_config.go:274 level=info msg="Listening on" address=[::]:9100
ts=2024-04-17T17:37:05.228Z caller=tls_config.go:277 level=info msg="TLS is disabled." http2=false address=[::]:9100
$ docker logs node-exporter-1 -t
2024-04-17T17:37:05.228790493Z ts=2024-04-17T17:37:05.228Z caller=tls_config.go:274 level=info msg="Listening on" address=[::]:9100
2024-04-17T17:37:05.229047084Z ts=2024-04-17T17:37:05.228Z caller=tls_config.go:277 level=info msg="TLS is disabled." http2=false address=[::]:9100
Second, using docker compose:
$ docker compose logs
node-exporter-1 | ts=2024-04-17T17:37:05.228Z caller=tls_config.go:274 level=info msg="Listening on" address=[::]:9100
node-exporter-1 | ts=2024-04-17T17:37:05.228Z caller=tls_config.go:277 level=info msg="TLS is disabled." http2=false address=[::]:9100
$ docker compose logs --timestamps
node-exporter-1 | 2024-04-17T17:37:05.228790493Z ts=2024-04-17T17:37:05.228Z caller=tls_config.go:274 level=info msg="Listening on" address=[::]:9100
node-exporter-1 | 2024-04-17T17:37:05.229047084Z ts=2024-04-17T17:37:05.228Z caller=tls_config.go:277 level=info msg="TLS is disabled." http2=false address=[::]:9100
Can this please be reopened and the timezone support be considered?
Thank you
Like I said, it does not matter what we do here. The code will ignore it no matter what. This is an issue with the promlog package.
Excellent. Where can I raise an issue for the promlog package team to update the docker container to include tzdata to support timezone?
@instantdreams https://github.com/prometheus/common - but it's somewhat of a philosophical decision: https://prometheus.io/docs/introduction/faq/#can-i-change-the-timezone-why-is-everything-in-utc