mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Send Unix timestamps to database in pgjsonb
The pgjsonb returner wants a database with a timestamp column using the type TIMESTAMP WITH TIME ZONE. Despite this, it's inserted its timestamps as a date-time-zone string. This means that the minion has needed to waste time formatting the timetamp, and then PostgreSQL has wasted even more time parsing it back into a Unix timestamp for storage. Also, the code has been buggy on Python 2, which doesn't properly support the %z format specifier to strftime() and has therefore sent timestamps using the wrong time zone. Solve both these problems by having the minion retrieve a Unix timestamp by calling time.time(), sending it unmolested to PostgreSQL, and using the PostgreSQL function to_timestamp() to store it. Closes #44544.
This commit is contained in:
parent
91d46d4cfc
commit
15c445e6b9
1 changed files with 4 additions and 4 deletions
|
@ -254,14 +254,14 @@ def returner(ret):
|
|||
with _get_serv(ret, commit=True) as cur:
|
||||
sql = '''INSERT INTO salt_returns
|
||||
(fun, jid, return, id, success, full_ret, alter_time)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s)'''
|
||||
VALUES (%s, %s, %s, %s, %s, %s, to_timestamp(%s))'''
|
||||
|
||||
cur.execute(sql, (ret['fun'], ret['jid'],
|
||||
psycopg2.extras.Json(ret['return']),
|
||||
ret['id'],
|
||||
ret.get('success', False),
|
||||
psycopg2.extras.Json(ret),
|
||||
time.strftime('%Y-%m-%d %H:%M:%S %z', time.localtime())))
|
||||
time.time()))
|
||||
except salt.exceptions.SaltMasterError:
|
||||
log.critical('Could not store return with pgjsonb returner. PostgreSQL server unavailable.')
|
||||
|
||||
|
@ -278,9 +278,9 @@ def event_return(events):
|
|||
tag = event.get('tag', '')
|
||||
data = event.get('data', '')
|
||||
sql = '''INSERT INTO salt_events (tag, data, master_id, alter_time)
|
||||
VALUES (%s, %s, %s, %s)'''
|
||||
VALUES (%s, %s, %s, to_timestamp(%s))'''
|
||||
cur.execute(sql, (tag, psycopg2.extras.Json(data),
|
||||
__opts__['id'], time.strftime('%Y-%m-%d %H:%M:%S %z', time.localtime())))
|
||||
__opts__['id'], time.time()))
|
||||
|
||||
|
||||
def save_load(jid, load, minions=None):
|
||||
|
|
Loading…
Add table
Reference in a new issue