Repository navigation
Conversation
Port `TorQ/code/processes/monitor.q` and `TorQ/code/monitor/checkmonitor.q` to a built-in TorqX process type. The monitor runs checks from a pipe-delimited csv against named processes on a schedule, judges each result with a named result checker, and keeps status and history in root tables that clients query over IPC. It also subscribes to `logmsg` on every process. Heartbeats are left to `di.torq.heartbeat`, which the monitor's settings switch to subscribe to every process. ## New module: `di/torq/proc/monitor/` - `init.q`, `monitor.q`: `init[config;deps]` with injected `log`, `timer`, `handlers` and `servers`; `use`s `di.util.cfg` and `di.asyncutil`. `init` is idempotent. - Exports `init`, `addcheck`, `copyconfig`, `enablecheck`, `disablecheck`, `updateconfig`, `forceconfig`, `updateconfigfammet`, `currentstatus`, `statusbyfam`, `timecheck` and `version`. - The API, `checkresulthandler`, the result checkers (`checkcount`, `queuecheck`, `truefalse`, `resulttrue`) and the `checkconfig`/`checkstatus`/`checktracker`/`logmsg` tables are published at root under TorQ's names, so TorQ clients and check csvs work unchanged. - `test.q`, `test.csv`: 158 k4unit tests, including an end-to-end check against a spawned peer. - `monitor.md`, `VERSION` (0.1.0), `deps.toml`. ## Framework changes - `di/torq/torq.q`, `torq.md`: `monitor` is a built-in proctype; `di.torq` 0.9.0. - `di/torq/settings/monitor.q`: defaults, plus heartbeat subscription to every process. - `di/torq/permissions/default.q`: grant `checkresulthandler` to `systemuser`, as checked processes post results back with a null user. ## Differences from TorQ - A check on a process with no connection is recorded at once and retried after `lagtime`; it is not sent, marked running or tracked. - `copyconfig` copies the check it names (TorQ's `where checkid=checkid` always copied the last). - A missing check csv is logged and the monitor starts with no checks. - Not ported: the web UI (separate PR), the Datadog result checker, and `.checks.*` from `monitoringchecks.q`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ogmsgsubscriber di.torq.servers 0.8.1: `register` skips this process's own row (its proctype and procname). process.csv with `connections:`ALL` and discovery's getservices both list the caller, so every such process dialled itself during init and waited out hopentimeout. 0.3.0 excluded it; #138's port of TorQ's trackservers.q dropped the exclusion to match legacy. The servers suite gains a row that fails without the fix. di.torq.proc.monitor: new `logmsgsubscriber` setting, `0b` by default. Nothing publishes `logmsg` yet, so subscribing only made every process reject the unknown table and the monitor log an error per process. The monitor now declares di.torq.servers 0.8.1 in its deps.toml. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comments that restated a name are gone; the rest say the why in one line. No code changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… work Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- init: a second call returns before reading settings, so it changes nothing; the logger is set last, so a failed init leaves the init guard in place. - checkresulthandler ignores a result whose run is no longer tracked, instead of adding a null checkstatus row (as TorQ did). - monitor.md: list both, and that checks use live handles only (TorQ re-dialled on every run). - Tests: the before-init tests assert the guard's message, timecheck is checked against known times, and the stored-config read restores a deleted check. The new tests fail on the old code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| / --- init ------------------------------------------------------------------------------------ | ||
|
|
||
| / called by name over IPC, as in TorQ | ||
| rootapi:`addcheck`copyconfig`disablecheck`enablecheck`updateconfig`forceconfig`updateconfigfammet, |
There was a problem hiding this comment.
init sets .z.m.registered:1b (line 356) and .z.m.log (line 355) before calling inittables[], publishroot[], registerjobs deps, and initcheck[]. If any of those calls signal (e.g. a timer or handler registration error), registered is already 1b and log is already set, so the idempotency guard (if[registered;:…]) will treat the partially-initialised state as fully initialised on the next call, silently skipping re-registration. The fix is to set .z.m.registered:1b and .z.m.log only after all setup steps succeed, or use a separate initialising flag.
| totaltime:`timespan$(); / execution plus network and queue time | ||
| timerstatus:`short$(); / 1 if it ran within runtime | ||
| running:`short$(); | ||
| result:()); / error message |
There was a problem hiding this comment.
inittables inserts a placeholder row into checktracker with a null checkid (0Ni) so that result stays a general list. This row has runid=0Ni. If a postback ever arrives with runid=0Ni (e.g. a malformed message), checkresulthandler will find it in checktracker, look up checkid=0Ni in checkconfig, and then attempt (getcheckconfig) 0Ni— which returns a row of nulls includingresultchecker:""andparams:()!(), producing a confusing error rather than the "ignoring result" warning. The placeholder row should use a sentinel that can never be a real runid, or the guard in checkresulthandlershould exclude0Ni` explicitly.
There was a problem hiding this comment.
Fixed in eedc7b3: checkresulthandler now ignores a null runid along with untracked ones, so a malformed postback can't match the placeholder row. Tests added and updated PR description
DIReview Summary0 critical | 2 warning(s) | 4 suggestion(s)
Suggestions
|
checkresulthandler's untracked-run guard matched checktracker's placeholder row, whose runid is 0Ni, so a malformed postback with a null runid added a null row to checkstatus. Null runids are now ignored with the same warning. From review on #168. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| }; | ||
|
|
||
| / the postback target | ||
| checkresulthandler:{[x] |
There was a problem hiding this comment.
The or operand not r in exec runid from \checktrackeris evaluated unconditionally even whennull ris true, because q'soris not short-circuit. Ifchecktracker doesn't exist or is otherwise problematic this will still execute. More critically, a null integer (0Ni) will match any null integer already present in the runidcolumn ofchecktrackerviain— so the guardnull ris necessary to prevent the fallthrough, butorevaluates both sides regardless. The intent is correct only because thenull rcheck comes first and its result of1bORed with the second expression still gives1b, so the early-exit (:) fires. However, the right-hand side still executes a full table scan every time null ris true. This is a minor inefficiency/robustness issue; use$[null r;...;not r in ...]or sequentialif` guards to truly short-circuit.
DIReview Summary0 critical | 1 warning(s) | 0 suggestion(s)
|
@[value;`x;{[c]}] applies the handler to the error and returns ::; it needs {{[c]}},
as .servers.addprocscustom already has.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- requireinit checks registered; drop initialised[], which always agreed with it - enablecheck/disablecheck name themselves in the init guard error, not togglecheck - nohandle comment: TorQ retried every checkinginterval after the first timeout - init.q header and deps.toml comment match what the module does - monitor.md: where heartbeats are, configstored needed to keep IPC-added checks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
||
| / set one params value; the key must exist and the type must match | ||
| updateconfig:{[cid;paramkey;newval] | ||
| requireinit[`updateconfig]; |
There was a problem hiding this comment.
togglecheck no longer calls requireinit, but disablecheck and enablecheck now wrap it and each call requireinit individually. Any direct caller of togglecheck (e.g. internal code or IPC clients that call it by name) will bypass the requireinit guard entirely. If togglecheck is meant to be an internal helper that is always reached through disablecheck/enablecheck, mark it private or rename it; if it is part of the public API, restore the requireinit call inside it.
DIReview Summary0 critical | 1 warning(s) | 2 suggestion(s)
Suggestions
|
Port
TorQ/code/processes/monitor.qandTorQ/code/monitor/checkmonitor.qto a built-in TorqXprocess type. The monitor runs checks from a csv against named processes on a schedule, judges each
result with a named result checker, and keeps status and history in root tables that clients query
over IPC. Heartbeats are left to
di.torq.heartbeat, which the monitor's settings switch tosubscribe to every process.
New module:
di/torq/proc/monitor/init.q,monitor.q: the process.init[config;deps]follows the process-module convention.test.q,test.csv: k4unit suite with mocklog,timer,handlersandserversdeps, and aspawned peer for the end-to-end check path.
monitor.md,VERSION(0.1.0),deps.toml(di.util.cfg0.2.0,di.torq.servers0.8.1).API
init[config;deps]addcheck[dict]addcheckcopyconfig[checkid;procname]copyconfigenablecheck[checkid]/disablecheck[checkid]enablecheck/disablecheckupdateconfig[checkid;key;value]updateconfigforceconfig[checkid;dict]forceconfigupdateconfigfammet[family;metric;key;value]updateconfigfammetcurrentstatus[checkids]currentstatusstatusbyfam[families]statusbyfamtimecheck[timespan]timecheckversionUnlike filealerter, the API is also published at root under TorQ's bare names, with
checkresulthandler(the postback target), the four result checkers (checkcount,queuecheck,truefalse,resulttrue) and the tablescheckconfig,checkstatus,checktrackerandlogmsg.TorQ clients call these by name over IPC, and check csvs name result checkers by string, resolved at
root.
Dependencies
log,timer,handlers,servers.initerrors naming any that is missing.used:di.util.cfgfor settings coercion and path roots, anddi.asyncutilforpostback.initregisters its timer jobs, handlers and root names only once; a secondinitchanges nothing.Config
Defaults live in
di/torq/settings/monitor.q. Each key is also read with a presence check and anequal code default.
configcsvappconfig/monitorconfig.csv, underTORQXAPPHOMEconfigstored""(none); saved on exit and read instead of the csv, underTORQXDATAHOMEruncheckinterval0D00:00:05checkinginterval0D00:00:07lagtime0D00:01:00cleartrackinterval0D01:00:00agecheck0D12:00:00connections`ALLlogmsgsubscriber0bThe settings file also sets
heartbeatsubscribeenabled:1bandheartbeatsubscribetypes:`ALLfordi.torq.heartbeat. The three timer jobs use di.timer mode 2, which matches TorQ's.timer.repeatdefault.
Differences from TorQ
"no handle connection"and is retried afterlagtime. TorQ recorded the same status but still sent to the null handle, leaving the check"running" and an unanswered
checktrackerrow until thelagtimetimeout. The status is the same.TorQ timed out the first attempt after lagtime and then retried on every checkruntime tick (~7s), because
nextrun never moved. The monitor now retries every lagtime
di.torq.serversreconnects it. TorQ re-dialled a dead process on every check run, which could block.
copyconfigcopies the check it is given. TorQ'swhere checkid=checkidcompared the column withitself, so it always copied the last check.
logmsgsubscription is behindlogmsgsubscriber, off by default: nothing publisheslogmsgyet,so subscribing only made each process reject the unknown table.
Not ported: the web UI (a separate PR to be made if decision to add is made), the Datadog result checker, and
.checks.*frommonitoringchecks.q(nothing in TorQ uses it, and its HTML output suits the reporter more than themonitor). Segmented tickerplants send no heartbeats, as in TorQ. Duplicate checks and retries to
processes that are not running are left as in TorQ and listed as future work in
monitor.md.di.torq.servers 0.8.1
registerskips this process's own row (its proctype and procname). process.csv withconnections:`ALLand discovery'sgetservicesboth list the caller, so every such processdialled itself during init and waited out
hopentimeout. 0.3.0 excluded it; Feature rediscovery #138's port of TorQ'strackservers.qdropped the exclusion to match legacy.servers.mdrecords the change.di.torq 0.9.0
torq.q: registermonitor->di.torq.proc.monitorin the built-in registry.settings/monitor.q: the shipped defaults.permissions/default.q: grantcheckresulthandlertosystemuser. Checked processes post resultsback on the monitor's own handle with a null user, so without it every result was refused.
torq.md: listmonitoramong the built-ins.Testing
k4unit:
k4unit.moduletestwas run in its own q process for each module, from the repo root.di.torq.proc.monitor: 179 tests, all passed. They cover:initinitrejecting missing or malformed deps and unreadable settings, keeping the guard after afailed
init, and a secondinitchanging nothingstartupcopyconfigcopying thenamed check
lagtime, nothing sent or trackederror, a checker that is missing or returns a non-dictionary, and a result for a cleared run or with a null runid
checkruntime,cleartracker,currentstatus,statusbyfamandtimecheckagainst knownvalues
logmsg: stored by theupdwrapper, not subscribed whilelogmsgsubscriberis off, subscribedonce when on, and dropped on
.z.pc.z.exitdi.torq.servers: 82 tests, all passed, including a new one that fails without theregisterfix.di.torq(110),di.torq.heartbeat(83),di.torq.proc.discovery(30) anddi.permissions(58):all passed.
di.torq.End to end on TorqX-POC (the full stack of 14 processes, with monitor1 started straight after
discovery1 so it learned every other process from discovery):
checkresulthandlergrant, every result was refused by permissions; that run is what led to it.itself.
and gateway1). monitor1's checks kept running and passing throughout, none stuck running, and no
heartbeat went to warning.
"Table heartbeat not in list of stp pub/sub tables", present before and after end of day.
In a separate scratch stack, a check against a peer that was then killed failed with
"no handle connection", andaddcheckover IPC added a check that ran against it.The POC changes are in TorqX-POC's
feature-monitorbranch.