Commit d57108c6 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
......@@ -193,6 +193,19 @@ class _XLogger:
def _xlog1(xl, conn):
# emit config_get after attach
_, cfg_raw = conn.req_('config_get', {})
δutc = 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.
cfg["utc"] = _ = time.now()
δutc = _ - cfg["time"]
cfg_raw = json.dumps(cfg)
xl.emit(cfg_raw)
......@@ -233,6 +246,13 @@ class _XLogger:
time.sleep(δtsleep)
_, resp_raw = conn.req_(logspec.query, opts)
if δutc:
# inject best effort approximation of utc into the message.
_ = json.loads(resp_raw)
_["utc"] = δutc + _["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