Commit be7458e7 authored by Daniele Venzano's avatar Daniele Venzano

Try to make sure all timestamps in Zoe are processed in UTC

parent bca40957
......@@ -5,6 +5,8 @@
<h2>{{ service.name }} console output</h2>
<p>Note: timestamps in logs are recorded in the UTC timezone.</p>
<textarea class="logoutput" id="logoutput" readonly>
</textarea>
......
......@@ -17,7 +17,7 @@
This module contains the entrypoint for the commandline Zoe client
"""
import datetime
from datetime import datetime, timezone
import json
import logging
import os
......@@ -164,17 +164,17 @@ def exec_get_cmd(auth, args):
if execution['status'] == 'error':
print('Last error: {}'.format(execution['error_message']))
print()
print('Time submit: {}'.format(datetime.datetime.fromtimestamp(execution['time_submit'])))
print('Time submit: {}'.format(datetime.fromtimestamp(execution['time_submit'], timezone.utc).astimezone()))
if execution['time_start'] is None:
print('Time start: {}'.format('not yet'))
else:
print('Time start: {}'.format(datetime.datetime.fromtimestamp(execution['time_start'])))
print('Time start: {}'.format(datetime.fromtimestamp(execution['time_start'], timezone.utc).astimezone()))
if execution['time_end'] is None:
print('Time end: {}'.format('not yet'))
else:
print('Time end: {}'.format(datetime.datetime.fromtimestamp(execution['time_end'])))
print('Time end: {}'.format(datetime.fromtimestamp(execution['time_end'], timezone.utc).astimezone()))
print()
endpoints = exec_api.endpoints(execution['id'])
......
......@@ -17,7 +17,7 @@
This module contains the entrypoint for the commandline Zoe client
"""
import datetime
from datetime import datetime, timezone
import json
import logging
import os
......@@ -96,17 +96,17 @@ def exec_get_cmd(auth, args):
if execution['status'] == 'error':
print('Last error: {}'.format(execution['error_message']))
print()
print('Time submit: {}'.format(datetime.datetime.fromtimestamp(execution['time_submit'])))
print('Time submit: {}'.format(datetime.fromtimestamp(execution['time_submit'], timezone.utc).astimezone()))
if execution['time_start'] is None:
print('Time start: {}'.format('not yet'))
else:
print('Time start: {}'.format(datetime.datetime.fromtimestamp(execution['time_start'])))
print('Time start: {}'.format(datetime.fromtimestamp(execution['time_start'], timezone.utc).astimezone()))
if execution['time_end'] is None:
print('Time end: {}'.format('not yet'))
else:
print('Time end: {}'.format(datetime.datetime.fromtimestamp(execution['time_end'])))
print('Time end: {}'.format(datetime.fromtimestamp(execution['time_end'], timezone.utc).astimezone()))
print()
endpoints = exec_api.endpoints(execution['id'])
......
......@@ -51,17 +51,17 @@ class Execution:
if isinstance(d['time_submit'], datetime.datetime):
self.time_submit = d['time_submit']
else:
self.time_submit = datetime.datetime.fromtimestamp(d['time_submit'])
self.time_submit = datetime.datetime.utcfromtimestamp(d['time_submit'])
if isinstance(d['time_submit'], datetime.datetime):
self.time_start = d['time_start']
else:
self.time_start = datetime.datetime.fromtimestamp(d['time_start'])
self.time_start = datetime.datetime.utcfromtimestamp(d['time_start'])
if isinstance(d['time_submit'], datetime.datetime):
self.time_end = d['time_end']
else:
self.time_submit = datetime.datetime.fromtimestamp(d['time_start'])
self.time_submit = datetime.datetime.utcfromtimestamp(d['time_start'])
self._status = d['status']
self.error_message = d['error_message']
......@@ -104,7 +104,7 @@ class Execution:
def set_running(self):
"""The execution is running and producing useful work."""
self._status = self.RUNNING_STATUS
self.time_start = datetime.datetime.now()
self.time_start = datetime.datetime.utcnow()
self.sql_manager.execution_update(self.id, status=self._status, time_start=self.time_start)
def set_cleaning_up(self):
......@@ -115,13 +115,13 @@ class Execution:
def set_terminated(self):
"""The execution is not running."""
self._status = self.TERMINATED_STATUS
self.time_end = datetime.datetime.now()
self.time_end = datetime.datetime.utcnow()
self.sql_manager.execution_update(self.id, status=self._status, time_end=self.time_end)
def set_error(self):
"""The scheduler encountered an error starting or running the execution."""
self._status = self.ERROR_STATUS
self.time_end = datetime.datetime.now()
self.time_end = datetime.datetime.utcnow()
self.sql_manager.execution_update(self.id, status=self._status, time_end=self.time_end)
def set_error_message(self, message):
......
......@@ -130,7 +130,7 @@ class SQLManager:
"""Create a new execution in the state."""
cur = self._cursor()
status = Execution.SUBMIT_STATUS
time_submit = datetime.datetime.now()
time_submit = datetime.datetime.utcnow()
query = cur.mogrify('INSERT INTO execution (id, name, user_id, description, status, time_submit) VALUES (DEFAULT, %s,%s,%s,%s,%s) RETURNING id', (name, user_id, description, status, time_submit))
cur.execute(query)
self.conn.commit()
......@@ -304,11 +304,11 @@ class SQLManager:
def save_token(self, client_id, grant_type, token, data, expires_at, refresh_token, refresh_expires_at, scopes, user_id): #pylint: disable=too-many-arguments
""" save token to db """
cur = self._cursor()
expires_at = datetime.datetime.fromtimestamp(expires_at)
expires_at = datetime.datetime.utcfromtimestamp(expires_at)
if refresh_expires_at is None:
query = cur.mogrify('UPDATE oauth_token SET token = %s, expires_at = %s WHERE client_id=%s', (token, expires_at, client_id))
else:
refresh_token_expires_at = datetime.datetime.fromtimestamp(refresh_expires_at)
refresh_token_expires_at = datetime.datetime.utcfromtimestamp(refresh_expires_at)
query = cur.mogrify('INSERT INTO oauth_token (client_id, grant_type, token, data, expires_at, refresh_token, refresh_token_expires_at, scopes, user_id) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s) ON CONFLICT (client_id) DO UPDATE SET token = %s, expires_at = %s, refresh_token = %s, refresh_token_expires_at = %s', (client_id, grant_type, token, data, expires_at, refresh_token, refresh_token_expires_at, scopes, user_id, token, expires_at, refresh_token, refresh_token_expires_at))
cur.execute(query)
......
......@@ -44,7 +44,7 @@ class GELFUDPHandler(socketserver.DatagramRequestHandler):
execution_id = data['_zoe_execution_id']
service_name = data['_zoe_service_name']
host = data['host']
timestamp = datetime.datetime.fromtimestamp(data['timestamp']).strftime('%Y-%m-%d %H:%M:%S')
timestamp = datetime.datetime.utcfromtimestamp(data['timestamp']).strftime('%Y-%m-%d %H:%M:%S')
message = data['short_message']
log_file_path = os.path.join(get_conf().service_logs_base_path, get_conf().deployment_name, str(execution_id), service_name + '.txt')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment