mirror of
https://github.com/healthchecks/healthchecks.git
synced 2026-04-26 07:25:51 +03:00
[GH-ISSUE #657] [Bug] Timezone issue when using DB=postgres #473
Labels
No labels
bug
bug
bug
feature
good-first-issue
new integration
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/healthchecks#473
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @RaphMad on GitHub (May 27, 2022).
Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/657
When running a dockerized healthchecks instance set to a timezone different than UTC, using
DB=postgreswith the DB instance running in the same non-UTC timezone and setting the monitored jobs to that same timezone:last_pingare consistently off "in the direction" of that timezoneGMT+2in the case described above, manually performing a ping will register as2 hours from now(so they register "in the future", and all grace timeout handling etc. seems to be also based on that future value)Observations
DB=sqliteorDB=mysqlthe problem does not occurlast_pingvalues within theapi_checktable in postgres shows a correct valueapi_check.last_pingvalue is off compared to the other supported DB types (maybe a problem related to postgres'timestamptztype?)(I hope the above makes sense, interpreting timezone issues just is soo confusing...)
@cuu508 commented on GitHub (May 28, 2022):
How and where are you setting the timezone?
Where do you see this? In the web UI, for example, in the ping log?
Can you show a specific example (wall clock time of making a ping, contents of the database row, screenshot of the web UI with the wrong time displayed)?
@RaphMad commented on GitHub (May 28, 2022):
How and where are you setting the timezone?
By mounting
/etc/localtimeand/etc/timezonein the respective containers.Output inside both the healtchecks and the DB container (no
timedatectl, sodateseems like the next best thing):_Where do you see this? In the web UI, for example, in the ping log?
Can you show a specific example (wall clock time of making a ping, contents of the database row, screenshot of the web UI with the wrong time displayed)?_
Scenario:
What strikes me so odd about this problem is that it will not occur in the exact same setup when switching to sqlite or mysql!
@cuu508 commented on GitHub (May 30, 2022):
To investigate this, I'd like to be able to reproduce the issue myself. Can you please show me the steps (a Dockerfile, a docker-compose.yml?) on how you're setting it up. Specifically, how do you mount the
/etc/localtimeand/etc/timezone, and do you do it on the web container, on the database container or on both?I wonder if it's a Healthchecks-specific issue. One thing I'd like to check would be to make a minimal Django project with a single model with a datetime field, and see if the problem can be reproduced there too.
@RaphMad commented on GitHub (May 30, 2022):
I prepared 2 somewhat minimal compose files:
hc_mariadb
hc_postgres
Preparation
docker-compose up(no-dto see log output and potential errors)depends_onthe auto DB init can be finicky, on first start DBs may not get recognized and healthchecks stops retrying the DB connect, CTRL-C and run again in that case -https://github.com/vishnubob/wait-for-itor just programmatically waiting for DBs to become ready is the preferred solution for this)docker exec -it hc_mariadb /opt/healthchecks/manage.py createsuperuser+docker exec -it hc_postgres /opt/healthchecks/manage.py createsuperuserto set up an initial user:8000,:9000to see the different behaviourProcedure
cat /etc/timezoneon docker host:Europe/Vienna(this may be crucial, but unfortunately also the only part not easily reproducable even with docker compose):8000:9000last_pingis interpreted as UTC (it is 16:47 in Vienna at the point of time of this screenshot):@cuu508 commented on GitHub (May 30, 2022):
Thanks for the detailed instructions! I can reproduce the issue and will see if I can track down what's going on.
My timezone is
Europe/Riga, and I made a ping request at 18:14 local time. psql shows it (I think) correctly:Django, somehow, gets it wrong:
@cuu508 commented on GitHub (May 30, 2022):
Here's one observation. Postgres running directly on host:
And Postgres running inside the container:
Notice how it returns a timestamp with the same timezone both times.
When Django opens a database connection, the first thing it runs is
SET TIME ZONE 'UTC'. I'm guessing after that point it assumes the datetimes will be in UTC, but they are not, and hence the problems.@cuu508 commented on GitHub (May 30, 2022):
In
docker-compose.yml, if I comment out/etc/localtimeand/etc/timezonemounts for the postgres container, thenSET TIMEZONEcalls work correctly, and Healthchecks indeed show the correct datetimes in the UI. To me it looks like the issue is with the database container being confused about what timezone to use.I'd either ask for help at https://github.com/docker-library/postgres/ or stick with UTC and call it a day :-)
@RaphMad commented on GitHub (May 31, 2022):
I now found it to also work when when setting
TZ=Europe/Viennafor the environment of the postgres container (and removing/etc/localtime//etc/timezone).This fixes the mentioned bug and allows things like
dateoutput, log timestamps etc. to still have the local timezone in the postgres container.Mounting
/etc/localtime//etc/timezoneusually is my default approach over theTZenv var because it automatically adapts to the docker host it is running on, it also is the first time I see different behaviour between the 2 approaches.Anyway I think this can be closed because the problem was identified to be caused the the interpretation of timezones by
postgresitself.