Skip to content

Commit c70444d

Browse files
committed
Allow manual IANA-compliant specification of DB timezone
1 parent 1c3618a commit c70444d

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

k8s-deploy.yml

Whitespace-only changes.

plan_monitor/collect.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import time
77
from datetime import datetime, timedelta
88
from typing import Dict, Any
9+
from zoneinfo import ZoneInfo
910

1011
from . import config, queries, message_schemas, common
1112

@@ -20,6 +21,10 @@ def poll_db(db_identifier: str, odbc_conn_string: str, stop_event: mp.Event,
2021

2122
try:
2223
conn, db_tz = common.get_db_conn_with_failover(odbc_conn_string)
24+
if config.DB_TIMEZONE:
25+
db_tz = ZoneInfo(config.DB_TIMEZONE)
26+
logger.info('Ignoring TZ offset queried from DB to use IANA TZ "%s" specified in config',
27+
config.DB_TIMEZONE)
2328
next_poll_due = datetime.utcnow()
2429
read_executions_from = (datetime.now(db_tz) -
2530
timedelta(minutes=config.REFRESH_INTERVAL_MINUTES)).replace(tzinfo=None)

plan_monitor/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
ODBC_CONN_STRINGS = json.loads(os.environ.get('ODBC_CONN_STRINGS', '''
1919
{"LOCAL": "DRIVER=FreeTDS; Server=localhost; Database=MyDB; UID=sa; PWD=1Password; Port=1433; App=plan_monitor;"}'''))
2020

21+
# Allows specifying an IANA timezone name which will be used to interpret all timestamps returned by the DB queries
22+
# this tool makes. Note that this value will be used for ALL DBs specified in ODBC_CONN_STRINGS. If left unspecified,
23+
# each DB will instead be queried for its current numeric UTC offset at process start, and that will be used instead.
24+
# Using a numeric offset can be problematic for DBs whose clocks may change (e.g. due to Daylight Savings Time),
25+
# though, hence this option:
26+
DB_TIMEZONE = os.environ.get('DB_TIMEZONE') # IANA-compliant; for example 'America/Los_Angeles'
2127

2228
# Configuration with sane defaults for most deployments but that you can change if you wish:
2329
# ------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)