Repository navigation
Feature heartbeat module - #151
Conversation
DIReview Summary0 critical | 7 warning(s) | 1 suggestion(s)
Suggestions
|
DI-Dexter
left a comment
There was a problem hiding this comment.
Test suites looks good, just a couple points for consideration
Requires fixing
heartbeat.q:112 registers the segmented TP's cleanup, not pubsub's.
register[`.z.pc;`;`hbpubsub;0j;.stpps.closesub];
.stpps.closesub clears .stpps.t, but heartbeats go out through .ps.publish, whose subscribers are in reqalldict, which this leaves alone. A disconnected heartbeat subscriber is never removed, in every process this PR turns into a publisher. Line 108's use di.pubsub; drops the handle, which is why pubsub's own closesub isn't reachable:
.z.m.ps:use`di.pubsub;
register[`.z.pc;`;`hbpubsub;0j;.z.m.ps`closesub];
Smaller points that aren't blockers
- Only init / version are exported, with callers pointed at
.m.di.0torq.0heartbeat.*. TorQ's apidetails.q makes six of these public and monitor.q uses two, addprocs has no other route. Worth exporting them. - init throws on a second call (duplicate timer job). Worth a
registeredguard, as di.subscriptions and di.permissions have. - heartbeat.md: note that
processwarning/processerrordefault to no-ops where TorQ called .html.pub.
Publishes heartbeats and, on a subscriber, flags processes whose heartbeats stop arriving in time. Faithful to TorQ; changes only where the module system or TOML forces them, plus an init error on an interval that does not convert. Exports addprocs, storeheartbeat, warningperiod and errorperiod alongside init and version, as TorQ's apidetails.q makes them public. A registered guard means a second init applies the settings but adds no timer jobs, wraps or .z.pc handlers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
initheartbeat always calls init, after the app code and before .ps.initialise; init gates publishing and subscribing itself. Settings are the flat heartbeat* keys in di/torq/settings/default.q; tickerplant, segmentedtp and chainedtp set heartbeatenabled:0b, as TorQ does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5f8d547 to
794697b
Compare
DIReview Summary0 critical | 5 warning(s) | 1 suggestion(s)
Suggestions
|
Thanks Dexter, I've pushed 794697b (tests: di.torq.heartbeat 81/81, di.torq 94/94, di.pubsub 133/133, di.timer 179/179).
Smaller points, all done:
Ready for another look when you have time. |
DI-Dexter
left a comment
There was a problem hiding this comment.
Thanks Aaron, you're right on .z.pc, my mistake. I'd checked reqalldict directly, but heartbeat subscribers come in through root .ps.subscribe (.u.sub) and sit in .stpps.subrequestall, which .stpps.closesub clears. Good to have the regression test with real handlers. The other three look good, and the suite passes here too. Approving.
di.torq.heartbeat
Port of TorQ's
code/common/heartbeat.qas a KDB-X module, wired into every di.torq process.Every process publishes a
heartbeatrow on a timer. A process configured as a subscriber keeps the latest heartbeat per process, and flags any process whose heartbeats stop arriving in time: first a warning, then an error. Both flags clear when heartbeats resume. This is the liveness signal a monitor process will consume. The monitor itself is out of scope.Commits
di.torq.heartbeat: port TorQ's heartbeat.q: the module only (di/torq/heartbeat/):heartbeat.q,init.q,VERSION(0.1.0),deps.toml,heartbeat.md,test.csv,test.q.di.torq: wire di.torq.heartbeat into every process:torq.q: newinitheartbeat[config;deps], guarded so it wires once, likeinitclients.initcalls it after the app code and before.ps.initialise.settings/default.q: the flatheartbeat*keys with TorQ's defaults (table below).settings/tickerplant.q,segmentedtp.q,chainedtp.q:heartbeatenabled:0b, so tickerplants publish no heartbeats, as in TorQ.test.csv: one row confirming di.torq wires the module and.ps.initialiseregisters theheartbeattable.Settings
heartbeatenabled1bheartbeatsubscribeenabled0bheartbeatdebug1bheartbeatpublishinterval0D00:00:30heartbeatcheckinterval0D00:00:10heartbeatwarningtolerance1.5heartbeaterrortolerance2fheartbeatsubscribetypes`symbol$()ALLfor allOptional
processwarningandprocesserrorcallbacks can be passed in config. Each receives the flagged rows, and both default to no-ops.Behaviour
heartbeatenabledadds two di.timer jobs:publishheartbeat, which publishes through.ps.publishonce pubsub is initialised, andcheckheartbeat.heartbeatsubscribeenabledindependently turns on the subscriber side:updis wrapped to storeheartbeatrows and pass everything else through;.z.pcobserver forgets closed handles;.servers.connectcustomis wrapped so a newly connected process is subscribed immediately.CONNECTIONSandSTARTUP..m.di.0torq.0heartbeat.hb, keyed onsym(proctype) andprocname, withwarninganderrorflags.initloadsdi.pubsub, so di.torq's.ps.initialise[]now runs on every process.Deviations from TorQ
init[config;deps]: module state replaces.hb, calls use bracket indexing, root names are written with@[`.;..]orset.heartbeat*settings keys..hb.CONNECTIONSbecomesheartbeatsubscribetypes.processwarningandprocesserrorcome from config and default to{[x]}. The.html.pubcalls are dropped.warningperiodanderrorperiodcan't be overridden from outside the module..proc.cp[]becomes.z.p..proc.proctypeand.proc.procnamecome from config..timer.enabledand.pschecks are dropped. Timer jobs have ids, and the modes map 2h→3h and 0h→1h..dotz.setbecomes the handlers dep, which also registers.stpps.closesubon.z.pc.totimespanon the intervals. Forced by TOML, which has no timespan type.heartbeatsubscribetypesis converted from strings to symbols. Forced by TOML.initerrors if an interval doesn't convert. The only addition that isn't forced.Dependencies
log,timer,handlers;initerrors if any is missing.deps.toml:di.pubsub0.4.0 anddi.torq.servers0.7.0.serversis not injected: the subscriber side calls the root.servers.getserversand wraps.servers.connectcustom, which di.torq.servers defines, and depcheck reports it if they're missing.Testing
Run on the branch tip
5f8d547. The new suite covers:init: required deps and settings, bad intervals, string subscribe types, and the typed default;updandconnectcustomwraps;TorqX-POC. Booted the full stack on this branch, with permissions on:
The TorqX-POC
feature-heartbeatbranch depends on this module, so merge this PR first.di.torq.config. It shows 68/76 on current
main(489726d) and on the previous base, so it's not caused by this branch. The 8 failures arekx.logrows, andkx.logisn't installed in my KDB-X.