feat: add cursor attribution via comment stamping and tests for reactive and imperative streams - #70
Merged
cedricclausPro merged 2 commits intoAug 20, 2026
Conversation
…ive and imperative streams - Introduced `CursorCommentStamping` to add identifiable comments (e.g., `flowwarden:<streamName>`) on MongoDB change stream cursors for operational attribution. - Enhanced `ReactiveStreamManager` and `ImperativeStreamManager` to use stamped cursors for main streams, heartbeats, and token validation. - Added integration and unit tests to verify comment propagation in reactive and imperative stream modes. - Updated test utilities with support for stamped cursor assertions. Signed-off-by: cedricclausPro <62853718+cedricclausPro@users.noreply.github.com>
…comment-for-cursor-attribution
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.
Closes #52.
Every change stream cursor FlowWarden opens now carries an identifying
comment, visible in$currentOp(cursor.originatingCommand.comment, withidleCursors: true), server logs and the profiler, and propagated togetMores(server ≥ 4.4). A cursor on a deployment becomes attributable to its declaring
stream at a glance, and FlowWarden cursors are distinguishable from any other
change stream consumer.
Three comment families, all built from one internal helper and matchable via
the new public
FlowWarden.CURSOR_COMMENT_PREFIXconstant:flowwarden:<streamName>— the stream's main cursor (both modes)flowwarden:heartbeat:<streamName>— heartbeat probe cursors (pre-existing,now built from the same source of truth)
flowwarden:resume-validation:<streamName>— the ephemeral resume-tokenvalidation cursors of the startup/restart resume cascade
Ordinary query cursors (checkpoint, DLQ, lock reads) are not stamped — the
documented contract covers change stream cursors only.
The interesting part is the how: Spring Data (through 4.2.x) exposes no
commentoption onChangeStreamOptions, while the driver does. Both SpringData cursor-creation paths obtain their
MongoDatabasefrom the template'sdatabase factory and call
watch(...)on it — so each stream's cursor iscreated through a template whose factory is decorated with a reflective proxy
that stamps
commentonwatch(...)results, re-proxiesgetCollection/withXxxso the stamp survives reconfiguration, and delegates everything elseuntouched (driver exceptions surface unwrapped, converter unchanged so mapping
is untouched). Metadata only, no behavioral change; if Spring Data ever exposes
the option natively the decoration collapses into a builder call.
Tests:
exception unwrapping) and of the three produced comment values;
isTokenValidimplementations actually putthe validation comment on the driver cursor (the reactive one exercises the
real
ReactiveMongoTemplate.changeStreamthrough the stamping proxy);in
$currentOpon the right namespace.