Commit bdbd2b1c authored by Xavier Thompson's avatar Xavier Thompson

amari.xlog: Approximate utc timestamp

Older versions of lteenb do not implement .utc field in remote API
reponses, only .time which is relative to the start of the process.
For such versions, inject an approximation of .utc into each logged
message.

Without this, KPI computation fails because .utc is missing.

Take `utc0 = time.now()` as an approximation of the .utc time when
receiving the first message after (re)connecting, and then for each
subsequent message compute `utc = utc0 - time0 + time`.

This preserves the relative time interval between each message.
parent e1a5ceea
......@@ -195,6 +195,16 @@ class _XLogger:
_, cfg_raw = conn.req_('config_get', {})
xl.emit(cfg_raw)
utc0 = None
cfg = json.loads(cfg_raw)
if cfg["version"] < "2022-12-01":
# .utc field is not implemented - see support.amarisoft.com/issues/21934
#
# approximate the offset between .time field and utc time.
#
# this is apparently more precise than finding the lteenb process start time.
utc0 = time.now() - cfg["time"]
# loop emitting requested logspecs
t0 = time.now()
......@@ -233,6 +243,13 @@ class _XLogger:
time.sleep(δtsleep)
_, resp_raw = conn.req_(logspec.query, opts)
if utc0:
# inject best effort approximation of utc into the message.
_ = json.loads(resp_raw)
_["utc"] = utc0 + _["time"]
resp_raw = json.dumps(_)
xl.emit(resp_raw)
......
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