Feature di.kafka#112
Open
alowrydi wants to merge 10 commits into
Open
Conversation
…ing following the injected dependency pattern observed in other developed modules and suite of k4unit test added (25/25 pass)
…ingle-arg log functions (22/22 tests pass)
…n initial team review. Required log dep, kx.log ergonomics, full test coverage
…ct init, required log dep, kx.log normalisation
…ative function dispatch, enforce deps naming convention, apply agreed documentation template, add portable integration tests using standard TorQ environment
DIReview Summary2 critical | 8 warning(s) | 0 suggestion(s)
|
DIReview Summary0 critical | 1 warning(s) | 0 suggestion(s)
|
DIReview Summary1 critical | 0 warning(s) | 0 suggestion(s)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Kafka producer/consumer module, di.kafka
Extracts
code/common/kafka.qfrom TorQ and packages it as a standalone kdb-x module. Wraps thekafkaqnative shared library, providing consumer and producer lifecycle management and a configurable message callback for kdb-x processes that need to produce or consume Kafka messages.Trello ticket - https://trello.com/c/eDFHYhSx/103-kdb-x-kafka-module
Files created
di/kafka/init.qkafka.q, defines export of 8 functionsdi/kafka/kafka.qdi/kafka/kafka.mddi/kafka/test.csvdi/kafka/test_integration.csvKDBLIBHow to test
Unit tests:
Integration tests (requires
KDBLIBset, e.g.source setenv.shin a TorQ checkout, orexport KDBLIB=/path/to/your/kafkaq/libon a non-TorQ system):Unit test coverage includes: dependency validation (all four failure modes plus error prefix),
enabled:0bplatform skip, stub behaviour for all six native functions,setkupdand the.kupdforwarder pattern (replacement, delegation, immediate reflection),kx.loginstance normalisation vianormlog, and log call verification under the binary{[c;m]}contract.Integration test coverage confirms
kafka.initloads a realkafkaqlibrary and that all six native function bindings are type112h(C function) in module state - proving the forwarder pattern reaches genuine C code after init, not the "not initialised" stub.Bug fix
The kdbx module system snapshots exported function values at
usetime. The original implementation overwrote the exported native functions directly insidebindfunctions, so the C bindings were unreachable via the public API - every call tokafka.initconsumeretc. after a successfulinitwould have hit the "not initialised" stub regardless of whether the library loaded. Fixed by renaming the six stubs tonative*internal targets and adding thin exported forwarders that delegate by bare name dynamically, the same pattern already used for the.kupdcallback. Verified via the integration tests'112htype assertions, which confirm the C bindings are reachable through the exported functions afterinit.Design decisions
1. Required log dependency, all three keys - Unlike
di.eodtime, this module callsinfo,warn, anderror, soinitvalidates and requires all three. Errors immediately with adi.kafka:prefixed message if absent or malformed.2.
normlogforkx.lognormalisation - The internalnormlogfunction detects akx.loginstance by the presence ofgetlvl,sinks,fmtskeys and wraps its monadic functions into the binary{[c;m]}contract automatically, embedding context as"kafka: message". Callers can pass akx.loginstance directly without manual wrapping.3.
enabledflag for graceful degradation - Defaults to1bonl64,0belsewhere. When disabled,initsucceeds without requiringlibpath, logs a warning rather than an error, and all six native functions remain as stubs. This is the basis of the entire unit test suite - all 34 unit tests run withenabled:0b, so they execute on any kdb-x machine with no native library required.4.
KDBLIBfallback forlibpath- Iflibpathis omitted, the module falls back to the standard TorQKDBLIBenvironment variable. This is not a strict TorQ requirement - any user with their ownkafkaq.sobuild can exportKDBLIBthemselves to point at it. The integration test guard checks only forKDBLIBand the resolved library file, not for TorQ itself.5. Stubs distinguish "not initialised" from genuine errors - All six native functions throw a descriptive
di.kafka:prefixed error beforeinit, rather than failing with an obscure type error or silently returning nothing.6. Single
depsdict - Config values (libpath,enabled,kupd) and the log dependency are passed together in a singledepsdict toinit, consistent with the project dependency injection guidelines. All config keys are optional with sensible defaults; onlylogis required.7. Root namespace side effect for
.kupd- The nativekafkaqlibrary is compiled to call.kupdin the root namespace on message receipt; this is unavoidable given the C library's design.initinstalls a forwarder at.kupdthat delegates to module-local state, sosetkupdcan replace the actual callback at runtime without re-initialising or re-registering with the C library.8. Export list reviewed against the public API criterion - All eight exports (
init,initconsumer,initproducer,cleanupconsumer,cleanupproducer,subscribe,publish,setkupd) are genuine consumer-facing functions. No testing hooks or internal helpers are present ininit.q.Checklist
consistency.mdandstyle.mdDocumentation
See
kafka.mdfor full reference including dependency table, configuration options with defaults, exported function documentation with examples, usage example, and notes.