Repository navigation
Record one correctly tagged Data Streams consume per Kafka Streams hop - #13587
arjunguhaswe wants to merge 5 commits into
Conversation
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
Kafka / consumer-benchmarkParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics. See unchanged results
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2172489306
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| * id is no longer a StreamTask constructor argument, and the kafka-clients-3.8 record collections | ||
| * used to escape the unwrapping done by the streams instrumentation, adding consume checkpoints. | ||
| */ | ||
| class KafkaStreams38DataStreamsTest extends InstrumentationSpecification { |
There was a problem hiding this comment.
Write the new Streams regression test in Java/JUnit 5
This adds a new Groovy/Spock test, whereas the repository requires Java/JUnit 5 for new tests, including instrumentation tests, unless an explicit exception is granted. Keeping it beside existing Spock tests, as the commit message explains, does not itself grant that exception. Without the tag: override groovy enforcement label, .github/workflows/enforce-groovy-migration.yaml rejects this added file. Port the regression test to Java/JUnit 5 or obtain the explicit override.
AGENTS.md reference: AGENTS.md:L64-L64
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Kafka Streams consumers on kafka-clients 3.8+ lose configured DSM transaction tracking because record unwrapping bypasses consume-header extraction without replacing it in the Streams processing advice.
🤖 Bits Code Review · Commit 2172489
| // Expecting a TracingList because TaskManager.addRecordsToTasks calls records(partition). | ||
| if (records instanceof TracingIterableDelegator) { | ||
| records = ((TracingIterableDelegator) records).getDelegate(); | ||
| TracingIterableDelegator delegator = (TracingIterableDelegator) records; |
There was a problem hiding this comment.
Preserve DSM transaction extraction when unwrapping Streams records
For Kafka Streams using kafka-clients ≥3.8 with a configured KAFKA_CONSUME_HEADERS transaction extractor, unwrapping now bypasses TracingIterator.startNewRecordSpan() and its trackTransaction() call. Neither Streams processing advice replaces that extraction, so matching consumed records lose transaction tracking events and DSM transaction span tags. Preserve transaction extraction in the Streams processing path, including version-specific header access, while removing the duplicate consume checkpoints.
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
The streams task instrumentation built its consume checkpoint tags with createWithGroup(type, direction, applicationId, topic), but the signature is (type, direction, topic, group): the application id became the topic and the source topic the group. With kafka-clients >= 3.8 the streams instrumentation did not recognize the kafka_clients38 TracingList, so Kafka Streams records also went through the kafka-clients TracingIterator, which set a second consume checkpoint (and wrote it into the headers) for source topics. The streams consume then chained off that one, giving several consumes per hop. - Pass the topic and the application id in the right order. - Move TracingIterableDelegator to kafka-common so the streams instrumentation unwraps the record collections of both kafka-clients instrumentations. The streams task now owns the single consume checkpoint per record per hop. - The streams task always writes the resulting pathway into the record headers, so the downstream produce (which extracts from the forwarded headers) chains to that consume, even when no topology was registered. - Plain kafka-clients consumers and producers only skip topics internal to a topology (repartition, changelog); before, they also skipped source/sink topics of a topology running in the same JVM. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow-up to the previous commit, for Kafka Streams >= 3.2 and kafka-clients >= 3.8: - From Kafka Streams 3.2 on StreamsConfig is no longer a StreamTask constructor argument, so the application id was never captured and the consume checkpoint had no group. Read it from the processor context, the 12th constructor argument from 2.6 on. - Take the kafka_cluster_id for the streams consume checkpoint from the kafka-clients record collection that UnwrapIterableAdvice unwraps, so it matches the plain kafka-clients consume. - kafka-clients-3.8 consumer constructor advice called groupMetadata(), which throws for consumers without a group (Streams restore and global consumers), aborting the advice: no consumer info, no cluster id. - Add a kafka38Test suite (Kafka Streams + kafka-clients 3.8.1) asserting one consume checkpoint per record per hop, group = application id, cluster id, and parentage produce -> consume -> produce -> consume. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…SM2-797) From Kafka Streams 3.0 on, StreamThread.pollPhase() reads every polled record (records(partition).stream().max(...), to track end offsets) before it hands the records to the tasks. That read went through the kafka-clients TracingIterator, which set a second consume checkpoint with the same hash as the streams one, so the streams consume node counted every record twice, and opened a kafka-clients consume span. - A StreamThread advice marks the poll phase (StreamsPollPhase in kafka-common). While it runs, the kafka-clients record collections of both kafka-clients modules hand out untraced iterators. - The streams consume advice tracks the DSM transaction of each record (KAFKA_CONSUME_HEADERS) itself, as the kafka-clients TracingIterator no longer sees these records. - Port the kafka38Test suite to Java/JUnit 5 (KafkaStreams38DataStreamsForkedTest). It also asserts one checkpoint per record on every pathway node, and that one span tracks the transaction. Both fail without the StreamThread advice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow-ups from the SDK review of the previous commits: - The Kafka Streams consume advices only build the DSM tags, payload size and context when DSM is on. The propagator injects nothing otherwise, and the kafka-clients paths already check first. - StreamingContext keeps only the set of topology-internal topics, the one thing isInternalTopic reads since the source/sink checks went away. - Correct the TracingIterator comment: the records of the Kafka Streams restore and global consumers still go through it. - Test cleanups: config key constant, static imports, NoOpSink, named constants, and no redundant wait in the latestDepTest DSM test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2172489 to
e0f1386
Compare
There was a problem hiding this comment.
More details
No reportable issue emerged in the checkpoint handoff between Kafka client iteration and Streams processing. This conclusion is limited to source inspection; runtime behavior was not exercised.
🤖 Bits Code Review · Commit e0f1386
Kafka / producer-benchmarkParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics. See unchanged results
|
What Does This Do
Data Streams Monitoring (DSM) records consumes from a Kafka Streams app more than once per hop, and with the wrong tags. This PR records exactly one consume checkpoint per record per hop, tagged with the right topic, group (the application id) and
kafka_cluster_id, and chained to the upstream produce.Before, with released 1.69.0, each Streams stage emitted:
queue:in the map), and no cluster id.The downstream produce then chained off the swapped node.
Motivation
In an internal investigation of high DSM cardinality, this pattern was a common contributor wherever Kafka Streams is used. On Streams consume edges it adds about 1.3–2× pairs, so pathways get dropped by the per-service hash quota. It also corrupts the map: topics show up as consumer groups, and every Streams consume collapses into one topic-less node.
How it works
KafkaStreamTaskInstrumentationcalledcreateWithGroup(type, direction, applicationId, topic), but the signature is(type, direction, topic, group). Fix swapped topic and group tags on Kafka Streams Data Streams metrics #13671 fixed the order on master; this PR keeps it and adds the cluster id (6).TracingIterator, which set a checkpoint and injected it into the headers. The Streams consume then chained off that injected header.TracingIterableDelegatormoves tokafka-common, so both kafka-clients modules are unwrapped. The Streams task now owns the single consume checkpoint.StreamThread.pollPhase()also reads every polled record (records(partition).stream().max(...), to track end offsets) before the tasks get them, whatever the kafka-clients version. That read set a second checkpoint with the same hash, so the Streams consume node counted every record twice. A newStreamThreadadvice marks the poll phase, and the kafka-clients record collections hand out untraced iterators while it runs.StreamsConfigis no longer aStreamTaskconstructor argument, so the application id was never captured. It is now read from theProcessorContextconstructor argument (Streams 2.6 and later).kafka_cluster_idfrom the unwrapped kafka-clients collection, so it matches the plain consume.groupMetadata(), which throwsInvalidGroupIdExceptionfor consumers without a group (Streams restore and global consumers). That aborted the advice, leaving those consumers with no consumer info and no cluster id. It is now only a guarded fallback.KAFKA_CONSUME_HEADERStransactions itself.Testing
kafka38Testsuite in kafka-streams-0.11 (Streams + kafka-clients 3.8.1, JUnit 5KafkaStreams38DataStreamsForkedTest, run bykafka38ForkedTest). It asserts:StreamThreadadvice, both new tests fail: the Streams consume node has 6 checkpoints for 3 records, and two spans carry the transaction.KafkaStreamsTest"produce and consume with streams in-between" fails here and on master. It is already@Flaky(KafkaStreamsTest(s) in kafka-streams-0.11 fails with wrong parent span #3865).pollPhasechange, which doesn't change the node count.)Verification
Verification done with A/B Test Apps run before the fix and after the fix.

Pathway Cardinality Shown to Be Reduced
Additional Notes
StreamingContextis JVM-global. Two Streams apps in one JVM that are chained through a topic still treat that topic as internal, so that hop is skipped.kafka.consumespans no longer appear for the records of a Streams app's main consumer. Before, they did on Streams 3.0 and later (frompollPhase) and on kafka-clients ≥ 3.8. The restore and global consumers are unchanged.Jira ticket: DSM2-797
🤖 Generated with Claude Code